blob: 5ce1b75f0130ec955a297ebea5c0a83e07337bc6 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
60#include "DWARFDIECollection.h"
61#include "DWARFFormValue.h"
62#include "DWARFLocationList.h"
63#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000064#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
66#include <map>
67
Greg Clayton62742b12010-11-11 01:09:45 +000068//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000069
70#ifdef ENABLE_DEBUG_PRINTF
71#include <stdio.h>
72#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
73#else
74#define DEBUG_PRINTF(fmt, ...)
75#endif
76
Greg Clayton594e5ed2010-09-27 21:07:38 +000077#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
79using namespace lldb;
80using namespace lldb_private;
81
Greg Clayton219cf312012-03-30 00:51:13 +000082//static inline bool
83//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
84//{
85// switch (tag)
86// {
87// default:
88// break;
89// case DW_TAG_subprogram:
90// case DW_TAG_inlined_subroutine:
91// case DW_TAG_class_type:
92// case DW_TAG_structure_type:
93// case DW_TAG_union_type:
94// return true;
95// }
96// return false;
97//}
98//
Sean Callananc7fbf732010-08-06 00:32:49 +000099static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000100DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101{
102 switch (dwarf_accessibility)
103 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000104 case DW_ACCESS_public: return eAccessPublic;
105 case DW_ACCESS_private: return eAccessPrivate;
106 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000107 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000109 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
Greg Clayton1fba87112012-02-09 20:03:49 +0000112#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
113
114class DIEStack
115{
116public:
117
118 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
119 {
120 m_dies.push_back (DIEInfo(cu, die));
121 }
122
123
124 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
125 {
126 StreamString log_strm;
127 const size_t n = m_dies.size();
128 log_strm.Printf("DIEStack[%zu]:\n", n);
129 for (size_t i=0; i<n; i++)
130 {
131 DWARFCompileUnit *cu = m_dies[i].cu;
132 const DWARFDebugInfoEntry *die = m_dies[i].die;
133 std::string qualified_name;
134 die->GetQualifiedName(dwarf, cu, qualified_name);
135 log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n",
136 i,
137 die->GetOffset(),
138 DW_TAG_value_to_name(die->Tag()),
139 qualified_name.c_str());
140 }
141 log->PutCString(log_strm.GetData());
142 }
143 void Pop ()
144 {
145 m_dies.pop_back();
146 }
147
148 class ScopedPopper
149 {
150 public:
151 ScopedPopper (DIEStack &die_stack) :
152 m_die_stack (die_stack),
153 m_valid (false)
154 {
155 }
156
157 void
158 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
159 {
160 m_valid = true;
161 m_die_stack.Push (cu, die);
162 }
163
164 ~ScopedPopper ()
165 {
166 if (m_valid)
167 m_die_stack.Pop();
168 }
169
170
171
172 protected:
173 DIEStack &m_die_stack;
174 bool m_valid;
175 };
176
177protected:
178 struct DIEInfo {
179 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
180 cu(c),
181 die(d)
182 {
183 }
184 DWARFCompileUnit *cu;
185 const DWARFDebugInfoEntry *die;
186 };
187 typedef std::vector<DIEInfo> Stack;
188 Stack m_dies;
189};
190#endif
191
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192void
193SymbolFileDWARF::Initialize()
194{
195 LogChannelDWARF::Initialize();
196 PluginManager::RegisterPlugin (GetPluginNameStatic(),
197 GetPluginDescriptionStatic(),
198 CreateInstance);
199}
200
201void
202SymbolFileDWARF::Terminate()
203{
204 PluginManager::UnregisterPlugin (CreateInstance);
205 LogChannelDWARF::Initialize();
206}
207
208
209const char *
210SymbolFileDWARF::GetPluginNameStatic()
211{
Greg Claytond4a2b372011-09-12 23:21:58 +0000212 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213}
214
215const char *
216SymbolFileDWARF::GetPluginDescriptionStatic()
217{
218 return "DWARF and DWARF3 debug symbol file reader.";
219}
220
221
222SymbolFile*
223SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
224{
225 return new SymbolFileDWARF(obj_file);
226}
227
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000228TypeList *
229SymbolFileDWARF::GetTypeList ()
230{
231 if (m_debug_map_symfile)
232 return m_debug_map_symfile->GetTypeList();
233 return m_obj_file->GetModule()->GetTypeList();
234
235}
236
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237//----------------------------------------------------------------------
238// Gets the first parent that is a lexical block, function or inlined
239// subroutine, or compile unit.
240//----------------------------------------------------------------------
241static const DWARFDebugInfoEntry *
242GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
243{
244 const DWARFDebugInfoEntry *die;
245 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
246 {
247 dw_tag_t tag = die->Tag();
248
249 switch (tag)
250 {
251 case DW_TAG_compile_unit:
252 case DW_TAG_subprogram:
253 case DW_TAG_inlined_subroutine:
254 case DW_TAG_lexical_block:
255 return die;
256 }
257 }
258 return NULL;
259}
260
261
Greg Clayton450e3f32010-10-12 02:24:53 +0000262SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
263 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000264 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton450e3f32010-10-12 02:24:53 +0000265 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000266 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000268 m_data_debug_abbrev (),
269 m_data_debug_aranges (),
270 m_data_debug_frame (),
271 m_data_debug_info (),
272 m_data_debug_line (),
273 m_data_debug_loc (),
274 m_data_debug_ranges (),
275 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000276 m_data_apple_names (),
277 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000278 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 m_info(),
281 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000282 m_apple_names_ap (),
283 m_apple_types_ap (),
284 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000285 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000286 m_function_basename_index(),
287 m_function_fullname_index(),
288 m_function_method_index(),
289 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000290 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000291 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000292 m_type_index(),
293 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000294 m_indexed (false),
295 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000296 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000297 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000298 m_ranges(),
299 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300{
301}
302
303SymbolFileDWARF::~SymbolFileDWARF()
304{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000305 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000306 {
307 ModuleSP module_sp (m_obj_file->GetModule());
308 if (module_sp)
309 module_sp->GetClangASTContext().RemoveExternalSource ();
310 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000311}
312
313static const ConstString &
314GetDWARFMachOSegmentName ()
315{
316 static ConstString g_dwarf_section_name ("__DWARF");
317 return g_dwarf_section_name;
318}
319
Greg Claytone576ab22011-02-15 00:19:15 +0000320UniqueDWARFASTTypeMap &
321SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
322{
323 if (m_debug_map_symfile)
324 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
325 return m_unique_ast_type_map;
326}
327
Greg Clayton6beaaa62011-01-17 03:46:26 +0000328ClangASTContext &
329SymbolFileDWARF::GetClangASTContext ()
330{
331 if (m_debug_map_symfile)
332 return m_debug_map_symfile->GetClangASTContext ();
333
334 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
335 if (!m_is_external_ast_source)
336 {
337 m_is_external_ast_source = true;
338 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
339 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
340 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000341 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000342 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000343 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000344 ast.SetExternalSource (ast_source_ap);
345 }
346 return ast;
347}
348
349void
350SymbolFileDWARF::InitializeObject()
351{
352 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000353 ModuleSP module_sp (m_obj_file->GetModule());
354 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000355 {
356 const SectionList *section_list = m_obj_file->GetSectionList();
357
358 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
359
360 // Memory map the DWARF mach-o segment so we have everything mmap'ed
361 // to keep our heap memory usage down.
362 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000363 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000364 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000365 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000366 if (m_data_apple_names.GetByteSize() > 0)
367 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000368 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
369 if (m_apple_names_ap->IsValid())
370 m_using_apple_tables = true;
371 else
Greg Clayton7f995132011-10-04 22:41:51 +0000372 m_apple_names_ap.reset();
373 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000374 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000375 if (m_data_apple_types.GetByteSize() > 0)
376 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000377 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
378 if (m_apple_types_ap->IsValid())
379 m_using_apple_tables = true;
380 else
Greg Clayton7f995132011-10-04 22:41:51 +0000381 m_apple_types_ap.reset();
382 }
383
384 get_apple_namespaces_data();
385 if (m_data_apple_namespaces.GetByteSize() > 0)
386 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000387 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
388 if (m_apple_namespaces_ap->IsValid())
389 m_using_apple_tables = true;
390 else
Greg Clayton7f995132011-10-04 22:41:51 +0000391 m_apple_namespaces_ap.reset();
392 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000393
Greg Clayton5009f9d2011-10-27 17:55:14 +0000394 get_apple_objc_data();
395 if (m_data_apple_objc.GetByteSize() > 0)
396 {
397 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
398 if (m_apple_objc_ap->IsValid())
399 m_using_apple_tables = true;
400 else
401 m_apple_objc_ap.reset();
402 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403}
404
405bool
406SymbolFileDWARF::SupportedVersion(uint16_t version)
407{
408 return version == 2 || version == 3;
409}
410
411uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000412SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413{
414 uint32_t abilities = 0;
415 if (m_obj_file != NULL)
416 {
417 const Section* section = NULL;
418 const SectionList *section_list = m_obj_file->GetSectionList();
419 if (section_list == NULL)
420 return 0;
421
422 uint64_t debug_abbrev_file_size = 0;
423 uint64_t debug_aranges_file_size = 0;
424 uint64_t debug_frame_file_size = 0;
425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
427 uint64_t debug_loc_file_size = 0;
428 uint64_t debug_macinfo_file_size = 0;
429 uint64_t debug_pubnames_file_size = 0;
430 uint64_t debug_pubtypes_file_size = 0;
431 uint64_t debug_ranges_file_size = 0;
432 uint64_t debug_str_file_size = 0;
433
Greg Clayton6beaaa62011-01-17 03:46:26 +0000434 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435
436 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000437 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438
Greg Clayton4ceb9982010-07-21 22:54:26 +0000439 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 if (section != NULL)
441 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000442 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000446 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447 else
448 m_flags.Set (flagsGotDebugAbbrevData);
449
Greg Clayton4ceb9982010-07-21 22:54:26 +0000450 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000452 debug_aranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 else
454 m_flags.Set (flagsGotDebugArangesData);
455
Greg Clayton4ceb9982010-07-21 22:54:26 +0000456 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000458 debug_frame_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 else
460 m_flags.Set (flagsGotDebugFrameData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000464 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 else
466 m_flags.Set (flagsGotDebugLineData);
467
Greg Clayton4ceb9982010-07-21 22:54:26 +0000468 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000470 debug_loc_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 else
472 m_flags.Set (flagsGotDebugLocData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000476 debug_macinfo_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 else
478 m_flags.Set (flagsGotDebugMacInfoData);
479
Greg Clayton4ceb9982010-07-21 22:54:26 +0000480 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000482 debug_pubnames_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 else
484 m_flags.Set (flagsGotDebugPubNamesData);
485
Greg Clayton4ceb9982010-07-21 22:54:26 +0000486 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000488 debug_pubtypes_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489 else
490 m_flags.Set (flagsGotDebugPubTypesData);
491
Greg Clayton4ceb9982010-07-21 22:54:26 +0000492 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000494 debug_ranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 else
496 m_flags.Set (flagsGotDebugRangesData);
497
Greg Clayton4ceb9982010-07-21 22:54:26 +0000498 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000500 debug_str_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 else
502 m_flags.Set (flagsGotDebugStrData);
503 }
504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
510
511 if (debug_aranges_file_size > 0)
512 abilities |= AddressAcceleratorTable;
513
514 if (debug_pubnames_file_size > 0)
515 abilities |= FunctionAcceleratorTable;
516
517 if (debug_pubtypes_file_size > 0)
518 abilities |= TypeAcceleratorTable;
519
520 if (debug_macinfo_file_size > 0)
521 abilities |= MacroInformation;
522
523 if (debug_frame_file_size > 0)
524 abilities |= CallFrameInformation;
525 }
526 return abilities;
527}
528
529const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000530SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531{
532 if (m_flags.IsClear (got_flag))
533 {
534 m_flags.Set (got_flag);
535 const SectionList *section_list = m_obj_file->GetSectionList();
536 if (section_list)
537 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000538 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
539 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 {
541 // See if we memory mapped the DWARF segment?
542 if (m_dwarf_data.GetByteSize())
543 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000544 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545 }
546 else
547 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000548 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 data.Clear();
550 }
551 }
552 }
553 }
554 return data;
555}
556
557const DataExtractor&
558SymbolFileDWARF::get_debug_abbrev_data()
559{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000560 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561}
562
563const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000564SymbolFileDWARF::get_debug_aranges_data()
565{
566 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
567}
568
569const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570SymbolFileDWARF::get_debug_frame_data()
571{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000572 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574
575const DataExtractor&
576SymbolFileDWARF::get_debug_info_data()
577{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000578 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579}
580
581const DataExtractor&
582SymbolFileDWARF::get_debug_line_data()
583{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000584 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585}
586
587const DataExtractor&
588SymbolFileDWARF::get_debug_loc_data()
589{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000590 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591}
592
593const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594SymbolFileDWARF::get_debug_ranges_data()
595{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000596 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000597}
598
599const DataExtractor&
600SymbolFileDWARF::get_debug_str_data()
601{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000602 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603}
604
Greg Claytonf9eec202011-09-01 23:16:13 +0000605const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000606SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000607{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000608 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000609}
610
611const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000612SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000613{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000614 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000615}
616
Greg Clayton7f995132011-10-04 22:41:51 +0000617const DataExtractor&
618SymbolFileDWARF::get_apple_namespaces_data()
619{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000620 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
621}
622
623const DataExtractor&
624SymbolFileDWARF::get_apple_objc_data()
625{
626 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000627}
628
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629
630DWARFDebugAbbrev*
631SymbolFileDWARF::DebugAbbrev()
632{
633 if (m_abbr.get() == NULL)
634 {
635 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
636 if (debug_abbrev_data.GetByteSize() > 0)
637 {
638 m_abbr.reset(new DWARFDebugAbbrev());
639 if (m_abbr.get())
640 m_abbr->Parse(debug_abbrev_data);
641 }
642 }
643 return m_abbr.get();
644}
645
646const DWARFDebugAbbrev*
647SymbolFileDWARF::DebugAbbrev() const
648{
649 return m_abbr.get();
650}
651
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652
653DWARFDebugInfo*
654SymbolFileDWARF::DebugInfo()
655{
656 if (m_info.get() == NULL)
657 {
658 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
659 if (get_debug_info_data().GetByteSize() > 0)
660 {
661 m_info.reset(new DWARFDebugInfo());
662 if (m_info.get())
663 {
664 m_info->SetDwarfData(this);
665 }
666 }
667 }
668 return m_info.get();
669}
670
671const DWARFDebugInfo*
672SymbolFileDWARF::DebugInfo() const
673{
674 return m_info.get();
675}
676
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677DWARFCompileUnit*
678SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
679{
680 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000681 if (info && UserIDMatches(cu_uid))
682 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 return NULL;
684}
685
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686
687DWARFDebugRanges*
688SymbolFileDWARF::DebugRanges()
689{
690 if (m_ranges.get() == NULL)
691 {
692 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
693 if (get_debug_ranges_data().GetByteSize() > 0)
694 {
695 m_ranges.reset(new DWARFDebugRanges());
696 if (m_ranges.get())
697 m_ranges->Extract(this);
698 }
699 }
700 return m_ranges.get();
701}
702
703const DWARFDebugRanges*
704SymbolFileDWARF::DebugRanges() const
705{
706 return m_ranges.get();
707}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708
Greg Clayton53eb1c22012-04-02 22:59:12 +0000709lldb::CompUnitSP
710SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000712 CompUnitSP cu_sp;
713 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000715 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
716 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000717 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000718 // We already parsed this compile unit, had out a shared pointer to it
719 cu_sp = comp_unit->shared_from_this();
720 }
721 else
722 {
723 ModuleSP module_sp (m_obj_file->GetModule());
724 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000726 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
727 if (cu_die)
728 {
729 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
730 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
731 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
732 if (cu_die_name)
733 {
734 std::string ramapped_file;
735 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000736
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
738 {
739 // If we have a full path to the compile unit, we don't need to resolve
740 // the file. This can be expensive e.g. when the source files are NFS mounted.
741 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
742 cu_file_spec.SetFile (ramapped_file.c_str(), false);
743 else
744 cu_file_spec.SetFile (cu_die_name, false);
745 }
746 else
747 {
748 std::string fullpath(cu_comp_dir);
749 if (*fullpath.rbegin() != '/')
750 fullpath += '/';
751 fullpath += cu_die_name;
752 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
753 cu_file_spec.SetFile (ramapped_file.c_str(), false);
754 else
755 cu_file_spec.SetFile (fullpath.c_str(), false);
756 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757
Greg Clayton53eb1c22012-04-02 22:59:12 +0000758 cu_sp.reset(new CompileUnit (module_sp,
759 dwarf_cu,
760 cu_file_spec,
761 MakeUserID(dwarf_cu->GetOffset()),
762 cu_language));
763 if (cu_sp)
764 {
765 dwarf_cu->SetUserData(cu_sp.get());
766
767 if (m_debug_map_symfile)
768 {
769 // Let the symbol file register the compile unit with
770 // the symbol vendor using its compile unit index
771 // when we are doing DWARF in .o files + debug map
772 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
773 }
774 else
775 {
776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
878 func_name.SetValue(mangled, true);
879 else if (name)
880 func_name.SetValue(name, false);
881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
894 func_range.GetBaseAddress().ResolveLinkedAddress();
895
Greg Clayton81c22f62011-10-19 18:09:39 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000898 func_user_id, // UserID is the DIE offset
899 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
911 }
912 }
913 return NULL;
914}
915
916size_t
917SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
918{
919 assert (sc.comp_unit);
920 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000921 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 if (dwarf_cu)
923 {
924 DWARFDIECollection function_dies;
925 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
926 size_t func_idx;
927 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
928 {
929 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000930 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 {
932 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
933 ++functions_added;
934 }
935 }
936 //FixupTypes();
937 }
938 return functions_added;
939}
940
941bool
942SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
943{
944 assert (sc.comp_unit);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000945 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
946 assert (dwarf_cu);
947 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948
949 if (cu_die)
950 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000951 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
952 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000953
954 // All file indexes in DWARF are one based and a file of index zero is
955 // supposed to be the compile unit itself.
956 support_files.Append (*sc.comp_unit);
957
Greg Claytond804d282012-03-15 21:01:31 +0000958 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000959 }
960 return false;
961}
962
963struct ParseDWARFLineTableCallbackInfo
964{
965 LineTable* line_table;
966 const SectionList *section_list;
967 lldb::addr_t prev_sect_file_base_addr;
968 lldb::addr_t curr_sect_file_base_addr;
969 bool is_oso_for_debug_map;
970 bool prev_in_final_executable;
971 DWARFDebugLine::Row prev_row;
972 SectionSP prev_section_sp;
973 SectionSP curr_section_sp;
974};
975
976//----------------------------------------------------------------------
977// ParseStatementTableCallback
978//----------------------------------------------------------------------
979static void
980ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
981{
982 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
983 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
984 {
985 // Just started parsing the line table
986 }
987 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
988 {
989 // Done parsing line table, nothing to do for the cleanup
990 }
991 else
992 {
993 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
994 // We have a new row, lets append it
995
996 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
997 {
998 info->prev_section_sp = info->curr_section_sp;
999 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1000 // If this is an end sequence entry, then we subtract one from the
1001 // address to make sure we get an address that is not the end of
1002 // a section.
1003 if (state.end_sequence && state.address != 0)
1004 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1005 else
1006 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1007
1008 if (info->curr_section_sp.get())
1009 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1010 else
1011 info->curr_sect_file_base_addr = 0;
1012 }
1013 if (info->curr_section_sp.get())
1014 {
1015 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1016 // Check for the fancy section magic to determine if we
1017
1018 if (info->is_oso_for_debug_map)
1019 {
1020 // When this is a debug map object file that contains DWARF
1021 // (referenced from an N_OSO debug map nlist entry) we will have
1022 // a file address in the file range for our section from the
1023 // original .o file, and a load address in the executable that
1024 // contains the debug map.
1025 //
1026 // If the sections for the file range and load range are
1027 // different, we have a remapped section for the function and
1028 // this address is resolved. If they are the same, then the
1029 // function for this address didn't make it into the final
1030 // executable.
1031 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1032
1033 // If we are doing DWARF with debug map, then we need to carefully
1034 // add each line table entry as there may be gaps as functions
1035 // get moved around or removed.
1036 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1037 {
1038 if (info->prev_in_final_executable)
1039 {
1040 bool terminate_previous_entry = false;
1041 if (!curr_in_final_executable)
1042 {
1043 // Check for the case where the previous line entry
1044 // in a function made it into the final executable,
1045 // yet the current line entry falls in a function
1046 // that didn't. The line table used to be contiguous
1047 // through this address range but now it isn't. We
1048 // need to terminate the previous line entry so
1049 // that we can reconstruct the line range correctly
1050 // for it and to keep the line table correct.
1051 terminate_previous_entry = true;
1052 }
1053 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1054 {
1055 // Check for cases where the line entries used to be
1056 // contiguous address ranges, but now they aren't.
1057 // This can happen when order files specify the
1058 // ordering of the functions.
1059 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1060 Section *curr_sect = info->curr_section_sp.get();
1061 Section *prev_sect = info->prev_section_sp.get();
1062 assert (curr_sect->GetLinkedSection());
1063 assert (prev_sect->GetLinkedSection());
1064 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1065 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1066 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1067 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1068 if (object_file_addr_delta != linked_file_addr_delta)
1069 terminate_previous_entry = true;
1070 }
1071
1072 if (terminate_previous_entry)
1073 {
1074 line_table->InsertLineEntry (info->prev_section_sp,
1075 state.address - info->prev_sect_file_base_addr,
1076 info->prev_row.line,
1077 info->prev_row.column,
1078 info->prev_row.file,
1079 false, // is_stmt
1080 false, // basic_block
1081 false, // state.prologue_end
1082 false, // state.epilogue_begin
1083 true); // end_sequence);
1084 }
1085 }
1086 }
1087
1088 if (curr_in_final_executable)
1089 {
1090 line_table->InsertLineEntry (info->curr_section_sp,
1091 curr_line_section_offset,
1092 state.line,
1093 state.column,
1094 state.file,
1095 state.is_stmt,
1096 state.basic_block,
1097 state.prologue_end,
1098 state.epilogue_begin,
1099 state.end_sequence);
1100 info->prev_section_sp = info->curr_section_sp;
1101 }
1102 else
1103 {
1104 // If the current address didn't make it into the final
1105 // executable, the current section will be the __text
1106 // segment in the .o file, so we need to clear this so
1107 // we can catch the next function that did make it into
1108 // the final executable.
1109 info->prev_section_sp.reset();
1110 info->curr_section_sp.reset();
1111 }
1112
1113 info->prev_in_final_executable = curr_in_final_executable;
1114 }
1115 else
1116 {
1117 // We are not in an object file that contains DWARF for an
1118 // N_OSO, this is just a normal DWARF file. The DWARF spec
1119 // guarantees that the addresses will be in increasing order
1120 // so, since we store line tables in file address order, we
1121 // can always just append the line entry without needing to
1122 // search for the correct insertion point (we don't need to
1123 // use LineEntry::InsertLineEntry()).
1124 line_table->AppendLineEntry (info->curr_section_sp,
1125 curr_line_section_offset,
1126 state.line,
1127 state.column,
1128 state.file,
1129 state.is_stmt,
1130 state.basic_block,
1131 state.prologue_end,
1132 state.epilogue_begin,
1133 state.end_sequence);
1134 }
1135 }
1136
1137 info->prev_row = state;
1138 }
1139}
1140
1141bool
1142SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1143{
1144 assert (sc.comp_unit);
1145 if (sc.comp_unit->GetLineTable() != NULL)
1146 return true;
1147
1148 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1149 if (dwarf_cu)
1150 {
1151 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001152 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001154 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1155 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001157 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1158 if (line_table_ap.get())
1159 {
1160 ParseDWARFLineTableCallbackInfo info = {
1161 line_table_ap.get(),
1162 m_obj_file->GetSectionList(),
1163 0,
1164 0,
1165 m_debug_map_symfile != NULL,
1166 false,
1167 DWARFDebugLine::Row(),
1168 SectionSP(),
1169 SectionSP()
1170 };
1171 uint32_t offset = cu_line_offset;
1172 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1173 sc.comp_unit->SetLineTable(line_table_ap.release());
1174 return true;
1175 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 }
1177 }
1178 }
1179 return false;
1180}
1181
1182size_t
1183SymbolFileDWARF::ParseFunctionBlocks
1184(
1185 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001186 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001187 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 const DWARFDebugInfoEntry *die,
1189 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001190 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191)
1192{
1193 size_t blocks_added = 0;
1194 while (die != NULL)
1195 {
1196 dw_tag_t tag = die->Tag();
1197
1198 switch (tag)
1199 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001200 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001201 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 case DW_TAG_lexical_block:
1203 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001204 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001205 if (tag == DW_TAG_subprogram)
1206 {
1207 // Skip any DW_TAG_subprogram DIEs that are inside
1208 // of a normal or inlined functions. These will be
1209 // parsed on their own as separate entities.
1210
1211 if (depth > 0)
1212 break;
1213
1214 block = parent_block;
1215 }
1216 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001217 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001218 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001219 parent_block->AddChild(block_sp);
1220 block = block_sp.get();
1221 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001222 DWARFDebugRanges::RangeList ranges;
1223 const char *name = NULL;
1224 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 int decl_file = 0;
1227 int decl_line = 0;
1228 int decl_column = 0;
1229 int call_file = 0;
1230 int call_line = 0;
1231 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001232 if (die->GetDIENamesAndRanges (this,
1233 dwarf_cu,
1234 name,
1235 mangled_name,
1236 ranges,
1237 decl_file, decl_line, decl_column,
1238 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239 {
1240 if (tag == DW_TAG_subprogram)
1241 {
1242 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001243 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001245 else if (tag == DW_TAG_inlined_subroutine)
1246 {
1247 // We get called here for inlined subroutines in two ways.
1248 // The first time is when we are making the Function object
1249 // for this inlined concrete instance. Since we're creating a top level block at
1250 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1251 // adjust the containing address.
1252 // The second time is when we are parsing the blocks inside the function that contains
1253 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1254 // function the offset will be for that function.
1255 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1256 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001257 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001258 }
1259 }
1260
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001261 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262
1263 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1264 {
1265 std::auto_ptr<Declaration> decl_ap;
1266 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001267 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1268 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269
1270 std::auto_ptr<Declaration> call_ap;
1271 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001272 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1273 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001275 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276 }
1277
1278 ++blocks_added;
1279
Greg Claytondd7feaf2011-08-12 17:54:33 +00001280 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001282 blocks_added += ParseFunctionBlocks (sc,
1283 block,
1284 dwarf_cu,
1285 die->GetFirstChild(),
1286 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001287 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 }
1289 }
1290 }
1291 break;
1292 default:
1293 break;
1294 }
1295
Greg Claytondd7feaf2011-08-12 17:54:33 +00001296 // Only parse siblings of the block if we are not at depth zero. A depth
1297 // of zero indicates we are currently parsing the top level
1298 // DW_TAG_subprogram DIE
1299
1300 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001302 else
1303 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 }
1305 return blocks_added;
1306}
1307
Greg Claytonf0705c82011-10-22 03:33:13 +00001308bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001309SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1310 const DWARFDebugInfoEntry *die,
1311 ClangASTContext::TemplateParameterInfos &template_param_infos)
1312{
1313 const dw_tag_t tag = die->Tag();
1314
1315 switch (tag)
1316 {
1317 case DW_TAG_template_type_parameter:
1318 case DW_TAG_template_value_parameter:
1319 {
1320 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1321
1322 DWARFDebugInfoEntry::Attributes attributes;
1323 const size_t num_attributes = die->GetAttributes (this,
1324 dwarf_cu,
1325 fixed_form_sizes,
1326 attributes);
1327 const char *name = NULL;
1328 Type *lldb_type = NULL;
1329 clang_type_t clang_type = NULL;
1330 uint64_t uval64 = 0;
1331 bool uval64_valid = false;
1332 if (num_attributes > 0)
1333 {
1334 DWARFFormValue form_value;
1335 for (size_t i=0; i<num_attributes; ++i)
1336 {
1337 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1338
1339 switch (attr)
1340 {
1341 case DW_AT_name:
1342 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1343 name = form_value.AsCString(&get_debug_str_data());
1344 break;
1345
1346 case DW_AT_type:
1347 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1348 {
1349 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1350 lldb_type = ResolveTypeUID(type_die_offset);
1351 if (lldb_type)
1352 clang_type = lldb_type->GetClangForwardType();
1353 }
1354 break;
1355
1356 case DW_AT_const_value:
1357 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1358 {
1359 uval64_valid = true;
1360 uval64 = form_value.Unsigned();
1361 }
1362 break;
1363 default:
1364 break;
1365 }
1366 }
1367
1368 if (name && lldb_type && clang_type)
1369 {
1370 bool is_signed = false;
1371 template_param_infos.names.push_back(name);
1372 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1373 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1374 {
1375 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1376 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1377 }
1378 else
1379 {
1380 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1381 }
1382 }
1383 else
1384 {
1385 return false;
1386 }
1387
1388 }
1389 }
1390 return true;
1391
1392 default:
1393 break;
1394 }
1395 return false;
1396}
1397
1398bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001399SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1400 const DWARFDebugInfoEntry *parent_die,
1401 ClangASTContext::TemplateParameterInfos &template_param_infos)
1402{
1403
1404 if (parent_die == NULL)
1405 return NULL;
1406
Greg Claytonf0705c82011-10-22 03:33:13 +00001407 Args template_parameter_names;
1408 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1409 die != NULL;
1410 die = die->GetSibling())
1411 {
1412 const dw_tag_t tag = die->Tag();
1413
1414 switch (tag)
1415 {
1416 case DW_TAG_template_type_parameter:
1417 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001418 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001419 break;
1420
1421 default:
1422 break;
1423 }
1424 }
1425 if (template_param_infos.args.empty())
1426 return false;
1427 return template_param_infos.args.size() == template_param_infos.names.size();
1428}
1429
1430clang::ClassTemplateDecl *
1431SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001432 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001433 const char *parent_name,
1434 int tag_decl_kind,
1435 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1436{
1437 if (template_param_infos.IsValid())
1438 {
1439 std::string template_basename(parent_name);
1440 template_basename.erase (template_basename.find('<'));
1441 ClangASTContext &ast = GetClangASTContext();
1442
1443 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001444 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001445 template_basename.c_str(),
1446 tag_decl_kind,
1447 template_param_infos);
1448 }
1449 return NULL;
1450}
1451
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452size_t
1453SymbolFileDWARF::ParseChildMembers
1454(
1455 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001456 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001458 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001459 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1461 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001462 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001463 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001464 bool &is_a_class,
1465 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466)
1467{
1468 if (parent_die == NULL)
1469 return 0;
1470
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 size_t count = 0;
1472 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001473 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001474 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001475
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1477 {
1478 dw_tag_t tag = die->Tag();
1479
1480 switch (tag)
1481 {
1482 case DW_TAG_member:
Sean Callanan751aac62012-03-29 19:07:06 +00001483 case DW_TAG_APPLE_Property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 {
1485 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001486 const size_t num_attributes = die->GetAttributes (this,
1487 dwarf_cu,
1488 fixed_form_sizes,
1489 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 if (num_attributes > 0)
1491 {
1492 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001493 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001495 const char *prop_name = NULL;
1496 const char *prop_getter_name = NULL;
1497 const char *prop_setter_name = NULL;
1498 uint32_t prop_attributes = 0;
1499
1500
Greg Clayton24739922010-10-13 03:15:28 +00001501 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001503 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001504 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505 size_t byte_size = 0;
1506 size_t bit_offset = 0;
1507 size_t bit_size = 0;
1508 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001509 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 {
1511 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1512 DWARFFormValue form_value;
1513 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1514 {
1515 switch (attr)
1516 {
1517 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1518 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1519 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1520 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1521 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1522 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1523 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1524 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1525 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001526 if (form_value.BlockData())
1527 {
1528 Value initialValue(0);
1529 Value memberOffset(0);
1530 const DataExtractor& debug_info_data = get_debug_info_data();
1531 uint32_t block_length = form_value.Unsigned();
1532 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1533 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1534 NULL, // clang::ASTContext *
1535 NULL, // ClangExpressionVariableList *
1536 NULL, // ClangExpressionDeclMap *
1537 NULL, // RegisterContext *
1538 debug_info_data,
1539 block_offset,
1540 block_length,
1541 eRegisterKindDWARF,
1542 &initialValue,
1543 memberOffset,
1544 NULL))
1545 {
1546 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1547 }
1548 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549 break;
1550
Greg Clayton8cf05932010-07-22 18:30:50 +00001551 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001552 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001553 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1554 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1555 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1556 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1557
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001558 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001559 case DW_AT_declaration:
1560 case DW_AT_description:
1561 case DW_AT_mutable:
1562 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563 case DW_AT_sibling:
1564 break;
1565 }
1566 }
1567 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001568
Sean Callanan751aac62012-03-29 19:07:06 +00001569 ConstString fixed_getter;
1570 ConstString fixed_setter;
1571
1572 if (prop_getter_name && prop_getter_name[0] == '-')
1573 {
1574 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1575 NULL,
1576 &fixed_getter,
1577 NULL,
1578 NULL);
1579 prop_getter_name = fixed_getter.GetCString();
1580 }
1581
1582 if (prop_setter_name && prop_setter_name[0] == '-')
1583 {
1584 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1585 NULL,
1586 &fixed_setter,
1587 NULL,
1588 NULL);
1589 prop_setter_name = fixed_setter.GetCString();
1590 }
1591
1592 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001593 // represents fields that are references with bad byte size
1594 // and bit size/offset information such as:
1595 //
1596 // DW_AT_byte_size( 0x00 )
1597 // DW_AT_bit_size( 0x40 )
1598 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1599 //
1600 // So check the bit offset to make sure it is sane, and if
1601 // the values are not sane, remove them. If we don't do this
1602 // then we will end up with a crash if we try to use this
1603 // type in an expression when clang becomes unhappy with its
1604 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001605
Greg Clayton44953932011-10-25 01:25:35 +00001606 if (bit_offset > 128)
1607 {
1608 bit_size = 0;
1609 bit_offset = 0;
1610 }
1611
1612 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001613 if (class_language == eLanguageTypeObjC ||
1614 class_language == eLanguageTypeObjC_plus_plus)
1615 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001616
1617 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1618 {
1619 // Not all compilers will mark the vtable pointer
1620 // member as artificial (llvm-gcc). We can't have
1621 // the virtual members in our classes otherwise it
1622 // throws off all child offsets since we end up
1623 // having and extra pointer sized member in our
1624 // class layouts.
1625 is_artificial = true;
1626 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001627
Greg Clayton24739922010-10-13 03:15:28 +00001628 if (is_artificial == false)
1629 {
1630 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001631 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001632 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001633 {
Sean Callanan751aac62012-03-29 19:07:06 +00001634 if (member_type)
1635 {
1636 if (accessibility == eAccessNone)
1637 accessibility = default_accessibility;
1638 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001639
Sean Callanan751aac62012-03-29 19:07:06 +00001640 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1641 name,
1642 member_type->GetClangLayoutType(),
1643 accessibility,
1644 bit_size);
Sean Callanan5b26f272012-02-04 08:49:35 +00001645 }
1646 else
1647 {
Sean Callanan751aac62012-03-29 19:07:06 +00001648 if (name)
1649 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1650 MakeUserID(die->GetOffset()),
1651 name,
1652 encoding_uid);
1653 else
1654 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1655 MakeUserID(die->GetOffset()),
1656 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001657 }
Sean Callanan751aac62012-03-29 19:07:06 +00001658
1659 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1660 {
1661 /////////////////////////////////////////////////////////////
1662 // How to locate a field given the DWARF debug information
1663 //
1664 // AT_byte_size indicates the size of the word in which the
1665 // bit offset must be interpreted.
1666 //
1667 // AT_data_member_location indicates the byte offset of the
1668 // word from the base address of the structure.
1669 //
1670 // AT_bit_offset indicates how many bits into the word
1671 // (according to the host endianness) the low-order bit of
1672 // the field starts. AT_bit_offset can be negative.
1673 //
1674 // AT_bit_size indicates the size of the field in bits.
1675 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001676
Sean Callanan751aac62012-03-29 19:07:06 +00001677 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1678
1679 uint64_t total_bit_offset = 0;
1680
1681 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1682
1683 if (object_endian == eByteOrderLittle)
1684 {
1685 total_bit_offset += byte_size * 8;
1686 total_bit_offset -= (bit_offset + bit_size);
1687 }
1688 else
1689 {
1690 total_bit_offset += bit_offset;
1691 }
1692
1693 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1694 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001695 }
Sean Callanan751aac62012-03-29 19:07:06 +00001696
Jim Inghame3ae82a2011-11-12 01:36:43 +00001697 if (prop_name != NULL)
1698 {
Sean Callanan751aac62012-03-29 19:07:06 +00001699 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001700
Sean Callanan751aac62012-03-29 19:07:06 +00001701 if (field_decl)
1702 {
1703 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1704 assert (ivar_decl != NULL);
1705 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001706
Jim Inghame3ae82a2011-11-12 01:36:43 +00001707 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1708 prop_name,
Sean Callanan751aac62012-03-29 19:07:06 +00001709 member_type->GetClangLayoutType(),
Jim Inghame3ae82a2011-11-12 01:36:43 +00001710 ivar_decl,
1711 prop_setter_name,
1712 prop_getter_name,
1713 prop_attributes);
1714 }
Greg Clayton24739922010-10-13 03:15:28 +00001715 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001717 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001718 }
1719 break;
1720
1721 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001722 // Let the type parsing code handle this one for us.
1723 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 break;
1725
1726 case DW_TAG_inheritance:
1727 {
1728 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001729 if (default_accessibility == eAccessNone)
1730 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731 // TODO: implement DW_TAG_inheritance type parsing
1732 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001733 const size_t num_attributes = die->GetAttributes (this,
1734 dwarf_cu,
1735 fixed_form_sizes,
1736 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737 if (num_attributes > 0)
1738 {
1739 Declaration decl;
1740 DWARFExpression location;
1741 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001742 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001743 bool is_virtual = false;
1744 bool is_base_of_class = true;
1745 off_t member_offset = 0;
1746 uint32_t i;
1747 for (i=0; i<num_attributes; ++i)
1748 {
1749 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1750 DWARFFormValue form_value;
1751 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1752 {
1753 switch (attr)
1754 {
1755 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1756 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1757 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1758 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1759 case DW_AT_data_member_location:
1760 if (form_value.BlockData())
1761 {
1762 Value initialValue(0);
1763 Value memberOffset(0);
1764 const DataExtractor& debug_info_data = get_debug_info_data();
1765 uint32_t block_length = form_value.Unsigned();
1766 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001767 if (DWARFExpression::Evaluate (NULL,
1768 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001769 NULL,
1770 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001771 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001772 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001773 block_offset,
1774 block_length,
1775 eRegisterKindDWARF,
1776 &initialValue,
1777 memberOffset,
1778 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001779 {
1780 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1781 }
1782 }
1783 break;
1784
1785 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001786 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001787 break;
1788
1789 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1790 default:
1791 case DW_AT_sibling:
1792 break;
1793 }
1794 }
1795 }
1796
Greg Clayton526e5af2010-11-13 03:52:47 +00001797 Type *base_class_type = ResolveTypeUID(encoding_uid);
1798 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001799
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001800 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1801 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001802 if (class_language == eLanguageTypeObjC)
1803 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001804 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001805 }
1806 else
1807 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001808 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001809 accessibility,
1810 is_virtual,
1811 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001812 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001813 }
1814 }
1815 break;
1816
1817 default:
1818 break;
1819 }
1820 }
1821 return count;
1822}
1823
1824
1825clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001826SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001827{
1828 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001829 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 {
1831 DWARFCompileUnitSP cu_sp;
1832 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1833 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001834 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001835 }
1836 return NULL;
1837}
1838
1839clang::DeclContext*
1840SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1841{
Greg Clayton81c22f62011-10-19 18:09:39 +00001842 if (UserIDMatches(type_uid))
1843 return GetClangDeclContextForDIEOffset (sc, type_uid);
1844 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001845}
1846
1847Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001848SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849{
Greg Clayton81c22f62011-10-19 18:09:39 +00001850 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001852 DWARFDebugInfo* debug_info = DebugInfo();
1853 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001854 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001855 DWARFCompileUnitSP cu_sp;
1856 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001857 const bool assert_not_being_parsed = true;
1858 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001859 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860 }
1861 return NULL;
1862}
1863
Greg Claytoncab36a32011-12-08 05:16:30 +00001864Type*
1865SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001866{
Greg Claytoncab36a32011-12-08 05:16:30 +00001867 if (die != NULL)
1868 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001869 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1870 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001871 GetObjectFile()->GetModule()->LogMessage (log.get(),
1872 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1873 die->GetOffset(),
1874 DW_TAG_value_to_name(die->Tag()),
1875 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001876
Greg Claytoncab36a32011-12-08 05:16:30 +00001877 // We might be coming in in the middle of a type tree (a class
1878 // withing a class, an enum within a class), so parse any needed
1879 // parent DIEs before we get to this one...
1880 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1881 switch (decl_ctx_die->Tag())
1882 {
1883 case DW_TAG_structure_type:
1884 case DW_TAG_union_type:
1885 case DW_TAG_class_type:
1886 {
1887 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001888 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001889 GetObjectFile()->GetModule()->LogMessage (log.get(),
1890 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1891 die->GetOffset(),
1892 DW_TAG_value_to_name(die->Tag()),
1893 die->GetName(this, cu),
1894 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001895//
1896// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1897// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1898// {
1899// if (log)
1900// GetObjectFile()->GetModule()->LogMessage (log.get(),
1901// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1902// die->GetOffset(),
1903// DW_TAG_value_to_name(die->Tag()),
1904// die->GetName(this, cu),
1905// decl_ctx_die->GetOffset());
1906// // Ask the type to complete itself if it already hasn't since if we
1907// // want a function (method or static) from a class, the class must
1908// // create itself and add it's own methods and class functions.
1909// if (parent_type)
1910// parent_type->GetClangFullType();
1911// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001912 }
1913 break;
1914
1915 default:
1916 break;
1917 }
1918 return ResolveType (cu, die);
1919 }
1920 return NULL;
1921}
1922
Greg Clayton6beaaa62011-01-17 03:46:26 +00001923// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1924// SymbolFileDWARF objects to detect if this DWARF file is the one that
1925// can resolve a clang_type.
1926bool
1927SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1928{
1929 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1930 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1931 return die != NULL;
1932}
1933
1934
Greg Clayton1be10fc2010-09-29 01:12:09 +00001935lldb::clang_type_t
1936SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1937{
1938 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001939 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1940 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001941 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001942 {
1943 // We have already resolved this type...
1944 return clang_type;
1945 }
1946 // Once we start resolving this type, remove it from the forward declaration
1947 // map in case anyone child members or other types require this type to get resolved.
1948 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1949 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001950 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001951
Greg Clayton1be10fc2010-09-29 01:12:09 +00001952
Greg Clayton85ae2e12011-10-18 23:36:41 +00001953 // Disable external storage for this type so we don't get anymore
1954 // clang::ExternalASTSource queries for this type.
1955 ClangASTContext::SetHasExternalStorage (clang_type, false);
1956
Greg Clayton450e3f32010-10-12 02:24:53 +00001957 DWARFDebugInfo* debug_info = DebugInfo();
1958
Greg Clayton53eb1c22012-04-02 22:59:12 +00001959 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001960 Type *type = m_die_to_type.lookup (die);
1961
1962 const dw_tag_t tag = die->Tag();
1963
Greg Claytonbaf95da2012-03-30 23:50:54 +00001964 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001965 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00001966 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00001967 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Claytonbaf95da2012-03-30 23:50:54 +00001968 "0x%8.8llx: %s '%s' resolving forward declaration...",
Greg Claytone38a5ed2012-01-05 03:57:59 +00001969 MakeUserID(die->GetOffset()),
1970 DW_TAG_value_to_name(tag),
1971 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00001972
1973 if (log->GetVerbose())
1974 {
1975 StreamString strm;
1976 Host::Backtrace (strm, 1024);
1977 if (strm.GetData())
1978 log->PutCString(strm.GetData());
1979 }
1980 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00001981 assert (clang_type);
1982 DWARFDebugInfoEntry::Attributes attributes;
1983
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001984 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001985
1986 switch (tag)
1987 {
1988 case DW_TAG_structure_type:
1989 case DW_TAG_union_type:
1990 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00001991 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001992 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00001993
Greg Clayton1be10fc2010-09-29 01:12:09 +00001994 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00001995 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00001996 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001997
Sean Callanan77a1fd32012-02-27 20:07:01 +00001998 LanguageType class_language = eLanguageTypeUnknown;
1999 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2000 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002001 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002002 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002003 // For objective C we don't start the definition when
2004 // the class is created.
2005 ast.StartTagDeclarationDefinition (clang_type);
2006 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002007
2008 int tag_decl_kind = -1;
2009 AccessType default_accessibility = eAccessNone;
2010 if (tag == DW_TAG_structure_type)
2011 {
2012 tag_decl_kind = clang::TTK_Struct;
2013 default_accessibility = eAccessPublic;
2014 }
2015 else if (tag == DW_TAG_union_type)
2016 {
2017 tag_decl_kind = clang::TTK_Union;
2018 default_accessibility = eAccessPublic;
2019 }
2020 else if (tag == DW_TAG_class_type)
2021 {
2022 tag_decl_kind = clang::TTK_Class;
2023 default_accessibility = eAccessPrivate;
2024 }
2025
Greg Clayton53eb1c22012-04-02 22:59:12 +00002026 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002027 std::vector<clang::CXXBaseSpecifier *> base_classes;
2028 std::vector<int> member_accessibilities;
2029 bool is_a_class = false;
2030 // Parse members and base classes first
2031 DWARFDIECollection member_function_dies;
2032
2033 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002034 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002035 die,
2036 clang_type,
2037 class_language,
2038 base_classes,
2039 member_accessibilities,
2040 member_function_dies,
2041 default_accessibility,
2042 is_a_class,
2043 layout_info);
2044
2045 // Now parse any methods if there were any...
2046 size_t num_functions = member_function_dies.Size();
2047 if (num_functions > 0)
2048 {
2049 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002050 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002051 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002052 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002053 }
2054
2055 if (class_language == eLanguageTypeObjC)
2056 {
Greg Clayton84db9102012-03-26 23:03:23 +00002057 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002058 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002059 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002060
Sean Callanan77a1fd32012-02-27 20:07:01 +00002061 DIEArray method_die_offsets;
2062 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002063 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002064 if (m_apple_objc_ap.get())
2065 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2066 }
2067 else
2068 {
2069 if (!m_indexed)
2070 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002071
Sean Callanan77a1fd32012-02-27 20:07:01 +00002072 ConstString class_name (class_str.c_str());
2073 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2074 }
2075
2076 if (!method_die_offsets.empty())
2077 {
2078 DWARFDebugInfo* debug_info = DebugInfo();
2079
2080 DWARFCompileUnit* method_cu = NULL;
2081 const size_t num_matches = method_die_offsets.size();
2082 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002083 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002084 const dw_offset_t die_offset = method_die_offsets[i];
2085 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2086
2087 if (method_die)
2088 ResolveType (method_cu, method_die);
2089 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002090 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002091 if (m_using_apple_tables)
2092 {
2093 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2094 die_offset, class_str.c_str());
2095 }
2096 }
2097 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002098 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002099 }
2100 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002101
2102 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2103 // need to tell the clang type it is actually a class.
2104 if (class_language != eLanguageTypeObjC)
2105 {
2106 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2107 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2108 }
2109
2110 // Since DW_TAG_structure_type gets used for both classes
2111 // and structures, we may need to set any DW_TAG_member
2112 // fields to have a "private" access if none was specified.
2113 // When we parsed the child members we tracked that actual
2114 // accessibility value for each DW_TAG_member in the
2115 // "member_accessibilities" array. If the value for the
2116 // member is zero, then it was set to the "default_accessibility"
2117 // which for structs was "public". Below we correct this
2118 // by setting any fields to "private" that weren't correctly
2119 // set.
2120 if (is_a_class && !member_accessibilities.empty())
2121 {
2122 // This is a class and all members that didn't have
2123 // their access specified are private.
2124 ast.SetDefaultAccessForRecordFields (clang_type,
2125 eAccessPrivate,
2126 &member_accessibilities.front(),
2127 member_accessibilities.size());
2128 }
2129
2130 if (!base_classes.empty())
2131 {
2132 ast.SetBaseClassesForClassType (clang_type,
2133 &base_classes.front(),
2134 base_classes.size());
2135
2136 // Clang will copy each CXXBaseSpecifier in "base_classes"
2137 // so we have to free them all.
2138 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2139 base_classes.size());
2140 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002141 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002142 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002143
2144 ast.BuildIndirectFields (clang_type);
2145
Sean Callanan77a1fd32012-02-27 20:07:01 +00002146 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002147
Greg Claytoncaab74e2012-01-28 00:48:57 +00002148 if (!layout_info.field_offsets.empty())
2149 {
2150 if (type)
2151 layout_info.bit_size = type->GetByteSize() * 8;
2152 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002153 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Claytoncaab74e2012-01-28 00:48:57 +00002154 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2155 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2156 if (record_type)
2157 {
2158 const clang::RecordDecl *record_decl = record_type->getDecl();
2159
2160 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002161 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002162 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002163 "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 +00002164 clang_type,
2165 record_decl,
2166 layout_info.bit_size,
2167 layout_info.alignment,
2168 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002169
Greg Clayton821ac6d2012-01-28 02:22:27 +00002170 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2171 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2172 {
2173 GetObjectFile()->GetModule()->LogMessage (log.get(),
2174 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2175 clang_type,
2176 (uint32_t)pos->second,
2177 pos->first->getNameAsString().c_str());
2178 }
2179 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002180 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2181 }
2182 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002183 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002184
Greg Claytonc93237c2010-10-01 20:48:32 +00002185 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002186
2187 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002188 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002189 if (die->HasChildren())
2190 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002191 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2192 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002193 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002194 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002195 return clang_type;
2196
2197 default:
2198 assert(false && "not a forward clang type decl!");
2199 break;
2200 }
2201 return NULL;
2202}
2203
Greg Claytonc685f8e2010-09-15 04:15:46 +00002204Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002205SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002206{
2207 if (type_die != NULL)
2208 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002209 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002210
Greg Claytonc685f8e2010-09-15 04:15:46 +00002211 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002212 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002213
Greg Clayton24739922010-10-13 03:15:28 +00002214 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002215 {
2216 if (type != DIE_IS_BEING_PARSED)
2217 return type;
2218
2219 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002220 type_die->GetOffset(),
2221 DW_TAG_value_to_name(type_die->Tag()),
2222 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002223
2224 }
2225 else
2226 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002227 }
2228 return NULL;
2229}
2230
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002231CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002232SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002233{
2234 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002235 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002236 {
2237 // The symbol vendor doesn't know about this compile unit, we
2238 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002239 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002240 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002241 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002242}
2243
2244bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002245SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002246{
2247 sc.Clear();
2248 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002249 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002250
Greg Clayton81c22f62011-10-19 18:09:39 +00002251 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002252 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002253 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002254
2255 if (sc.function)
2256 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002257 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002258 return true;
2259 }
2260
2261 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262}
2263
2264uint32_t
2265SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2266{
2267 Timer scoped_timer(__PRETTY_FUNCTION__,
2268 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002269 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002270 so_addr.GetOffset(),
2271 resolve_scope);
2272 uint32_t resolved = 0;
2273 if (resolve_scope & ( eSymbolContextCompUnit |
2274 eSymbolContextFunction |
2275 eSymbolContextBlock |
2276 eSymbolContextLineEntry))
2277 {
2278 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2279
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002281 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002282 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002283 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002284 if (cu_offset != DW_INVALID_OFFSET)
2285 {
2286 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002287 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2288 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002289 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002290 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002291 assert(sc.comp_unit != NULL);
2292 resolved |= eSymbolContextCompUnit;
2293
2294 if (resolve_scope & eSymbolContextLineEntry)
2295 {
2296 LineTable *line_table = sc.comp_unit->GetLineTable();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002297 if (line_table != NULL)
2298 {
2299 if (so_addr.IsLinkedAddress())
2300 {
2301 Address linked_addr (so_addr);
2302 linked_addr.ResolveLinkedAddress();
2303 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2304 {
2305 resolved |= eSymbolContextLineEntry;
2306 }
2307 }
2308 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2309 {
2310 resolved |= eSymbolContextLineEntry;
2311 }
2312 }
2313 }
2314
2315 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2316 {
2317 DWARFDebugInfoEntry *function_die = NULL;
2318 DWARFDebugInfoEntry *block_die = NULL;
2319 if (resolve_scope & eSymbolContextBlock)
2320 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002321 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002322 }
2323 else
2324 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002325 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002326 }
2327
2328 if (function_die != NULL)
2329 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002330 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002332 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002333 }
Greg Clayton12b834d2012-03-29 21:43:25 +00002334 else
2335 {
2336 // We might have had a compile unit that had discontiguous
2337 // address ranges where the gaps are symbols that don't have
2338 // any debug info. Discontiguous compile unit address ranges
2339 // should only happen when there aren't other functions from
2340 // other compile units in these gaps. This helps keep the size
2341 // of the aranges down.
2342 sc.comp_unit = NULL;
2343 resolved &= ~eSymbolContextCompUnit;
2344 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002345
2346 if (sc.function != NULL)
2347 {
2348 resolved |= eSymbolContextFunction;
2349
2350 if (resolve_scope & eSymbolContextBlock)
2351 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002352 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353
2354 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002355 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002356 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002357 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002358 if (sc.block)
2359 resolved |= eSymbolContextBlock;
2360 }
2361 }
2362 }
2363 }
2364 }
2365 }
2366 }
2367 return resolved;
2368}
2369
2370
2371
2372uint32_t
2373SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2374{
2375 const uint32_t prev_size = sc_list.GetSize();
2376 if (resolve_scope & eSymbolContextCompUnit)
2377 {
2378 DWARFDebugInfo* debug_info = DebugInfo();
2379 if (debug_info)
2380 {
2381 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002382 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002383
Greg Clayton53eb1c22012-04-02 22:59:12 +00002384 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002385 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002386 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002387 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2388 if (check_inlines || file_spec_matches_cu_file_spec)
2389 {
2390 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002391 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002392 assert(sc.comp_unit != NULL);
2393
2394 uint32_t file_idx = UINT32_MAX;
2395
2396 // If we are looking for inline functions only and we don't
2397 // find it in the support files, we are done.
2398 if (check_inlines)
2399 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002400 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002401 if (file_idx == UINT32_MAX)
2402 continue;
2403 }
2404
2405 if (line != 0)
2406 {
2407 LineTable *line_table = sc.comp_unit->GetLineTable();
2408
2409 if (line_table != NULL && line != 0)
2410 {
2411 // We will have already looked up the file index if
2412 // we are searching for inline entries.
2413 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002414 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002415
2416 if (file_idx != UINT32_MAX)
2417 {
2418 uint32_t found_line;
2419 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2420 found_line = sc.line_entry.line;
2421
Greg Clayton016a95e2010-09-14 02:20:48 +00002422 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423 {
2424 sc.function = NULL;
2425 sc.block = NULL;
2426 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2427 {
2428 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2429 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2430 {
2431 DWARFDebugInfoEntry *function_die = NULL;
2432 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002433 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002434
2435 if (function_die != NULL)
2436 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002437 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002438 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002439 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002440 }
2441
2442 if (sc.function != NULL)
2443 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002444 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002445
2446 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002447 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002448 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002449 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002450 }
2451 }
2452 }
2453
2454 sc_list.Append(sc);
2455 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2456 }
2457 }
2458 }
2459 else if (file_spec_matches_cu_file_spec && !check_inlines)
2460 {
2461 // only append the context if we aren't looking for inline call sites
2462 // by file and line and if the file spec matches that of the compile unit
2463 sc_list.Append(sc);
2464 }
2465 }
2466 else if (file_spec_matches_cu_file_spec && !check_inlines)
2467 {
2468 // only append the context if we aren't looking for inline call sites
2469 // by file and line and if the file spec matches that of the compile unit
2470 sc_list.Append(sc);
2471 }
2472
2473 if (!check_inlines)
2474 break;
2475 }
2476 }
2477 }
2478 }
2479 return sc_list.GetSize() - prev_size;
2480}
2481
2482void
2483SymbolFileDWARF::Index ()
2484{
2485 if (m_indexed)
2486 return;
2487 m_indexed = true;
2488 Timer scoped_timer (__PRETTY_FUNCTION__,
2489 "SymbolFileDWARF::Index (%s)",
2490 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2491
2492 DWARFDebugInfo* debug_info = DebugInfo();
2493 if (debug_info)
2494 {
2495 uint32_t cu_idx = 0;
2496 const uint32_t num_compile_units = GetNumCompileUnits();
2497 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2498 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002499 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002500
Greg Clayton53eb1c22012-04-02 22:59:12 +00002501 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502
Greg Clayton53eb1c22012-04-02 22:59:12 +00002503 dwarf_cu->Index (cu_idx,
2504 m_function_basename_index,
2505 m_function_fullname_index,
2506 m_function_method_index,
2507 m_function_selector_index,
2508 m_objc_class_selectors_index,
2509 m_global_index,
2510 m_type_index,
2511 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512
2513 // Keep memory down by clearing DIEs if this generate function
2514 // caused them to be parsed
2515 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002516 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002517 }
2518
Greg Claytond4a2b372011-09-12 23:21:58 +00002519 m_function_basename_index.Finalize();
2520 m_function_fullname_index.Finalize();
2521 m_function_method_index.Finalize();
2522 m_function_selector_index.Finalize();
2523 m_objc_class_selectors_index.Finalize();
2524 m_global_index.Finalize();
2525 m_type_index.Finalize();
2526 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002527
Greg Clayton24739922010-10-13 03:15:28 +00002528#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002529 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002530 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002531 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2532 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002533 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2534 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2535 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2536 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2537 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2538 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002539 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002540 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002541#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002542 }
2543}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002544
2545bool
2546SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2547{
2548 if (namespace_decl == NULL)
2549 {
2550 // Invalid namespace decl which means we aren't matching only things
2551 // in this symbol file, so return true to indicate it matches this
2552 // symbol file.
2553 return true;
2554 }
2555
2556 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2557
2558 if (namespace_ast == NULL)
2559 return true; // No AST in the "namespace_decl", return true since it
2560 // could then match any symbol file, including this one
2561
2562 if (namespace_ast == GetClangASTContext().getASTContext())
2563 return true; // The ASTs match, return true
2564
2565 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002566 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2567
2568 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002569 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002570
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002571 return false;
2572}
2573
Greg Clayton2506a7a2011-10-12 23:34:26 +00002574bool
2575SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2576 DWARFCompileUnit* cu,
2577 const DWARFDebugInfoEntry* die)
2578{
2579 // No namespace specified, so the answesr i
2580 if (namespace_decl == NULL)
2581 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002582
2583 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002584
Greg Clayton2506a7a2011-10-12 23:34:26 +00002585 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2586 if (decl_ctx_die)
2587 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002588
Greg Clayton2506a7a2011-10-12 23:34:26 +00002589 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2590 if (clang_namespace_decl)
2591 {
2592 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002593 {
2594 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002595 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002596 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002597 }
2598
Greg Clayton2506a7a2011-10-12 23:34:26 +00002599 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2600
2601 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002602 {
2603 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002604 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 +00002605
Greg Clayton2506a7a2011-10-12 23:34:26 +00002606 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002607 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002608
Greg Claytoncb5860a2011-10-13 23:49:28 +00002609 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002610 }
2611 else
2612 {
2613 // We have a namespace_decl that was not NULL but it contained
2614 // a NULL "clang::NamespaceDecl", so this means the global namespace
2615 // So as long the the contained decl context DIE isn't a namespace
2616 // we should be ok.
2617 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2618 return true;
2619 }
2620 }
Sean Callananebe60672011-10-13 21:50:33 +00002621
2622 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002623 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002624
Greg Clayton2506a7a2011-10-12 23:34:26 +00002625 return false;
2626}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002627uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002628SymbolFileDWARF::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 +00002629{
Greg Clayton21f2a492011-10-06 00:09:08 +00002630 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2631
2632 if (log)
2633 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002634 GetObjectFile()->GetModule()->LogMessage (log.get(),
2635 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2636 name.GetCString(),
2637 namespace_decl,
2638 append,
2639 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002640 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002641
2642 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2643 return 0;
2644
Greg Claytonc685f8e2010-09-15 04:15:46 +00002645 DWARFDebugInfo* info = DebugInfo();
2646 if (info == NULL)
2647 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002648
2649 // If we aren't appending the results to this list, then clear the list
2650 if (!append)
2651 variables.Clear();
2652
2653 // Remember how many variables are in the list before we search in case
2654 // we are appending the results to a variable list.
2655 const uint32_t original_size = variables.GetSize();
2656
Greg Claytond4a2b372011-09-12 23:21:58 +00002657 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002658
Greg Clayton97fbc342011-10-20 22:30:33 +00002659 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002660 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002661 if (m_apple_names_ap.get())
2662 {
2663 const char *name_cstr = name.GetCString();
2664 const char *base_name_start;
2665 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002666
Greg Clayton97fbc342011-10-20 22:30:33 +00002667 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2668 base_name_start = name_cstr;
2669
2670 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2671 }
Greg Clayton7f995132011-10-04 22:41:51 +00002672 }
2673 else
2674 {
2675 // Index the DWARF if we haven't already
2676 if (!m_indexed)
2677 Index ();
2678
2679 m_global_index.Find (name, die_offsets);
2680 }
2681
2682 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002683 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002684 {
Greg Clayton7f995132011-10-04 22:41:51 +00002685 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002686 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002687 assert (sc.module_sp);
2688
Greg Claytond4a2b372011-09-12 23:21:58 +00002689 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002690 DWARFCompileUnit* dwarf_cu = NULL;
2691 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002692 for (size_t i=0; i<num_matches; ++i)
2693 {
2694 const dw_offset_t die_offset = die_offsets[i];
2695 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002696
Greg Clayton95d87902011-11-11 03:16:25 +00002697 if (die)
2698 {
2699 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2700 assert(sc.comp_unit != NULL);
2701
2702 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2703 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002704
Greg Clayton95d87902011-11-11 03:16:25 +00002705 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706
Greg Clayton95d87902011-11-11 03:16:25 +00002707 if (variables.GetSize() - original_size >= max_matches)
2708 break;
2709 }
2710 else
2711 {
2712 if (m_using_apple_tables)
2713 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002714 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2715 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002716 }
2717 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002718 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002719 }
2720
2721 // Return the number of variable that were appended to the list
2722 return variables.GetSize() - original_size;
2723}
2724
2725uint32_t
2726SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2727{
Greg Clayton21f2a492011-10-06 00:09:08 +00002728 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2729
2730 if (log)
2731 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002732 GetObjectFile()->GetModule()->LogMessage (log.get(),
2733 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2734 regex.GetText(),
2735 append,
2736 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002737 }
2738
Greg Claytonc685f8e2010-09-15 04:15:46 +00002739 DWARFDebugInfo* info = DebugInfo();
2740 if (info == NULL)
2741 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002742
2743 // If we aren't appending the results to this list, then clear the list
2744 if (!append)
2745 variables.Clear();
2746
2747 // Remember how many variables are in the list before we search in case
2748 // we are appending the results to a variable list.
2749 const uint32_t original_size = variables.GetSize();
2750
Greg Clayton7f995132011-10-04 22:41:51 +00002751 DIEArray die_offsets;
2752
Greg Clayton97fbc342011-10-20 22:30:33 +00002753 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002754 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002755 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002756 {
2757 DWARFMappedHash::DIEInfoArray hash_data_array;
2758 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2759 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2760 }
Greg Clayton7f995132011-10-04 22:41:51 +00002761 }
2762 else
2763 {
2764 // Index the DWARF if we haven't already
2765 if (!m_indexed)
2766 Index ();
2767
2768 m_global_index.Find (regex, die_offsets);
2769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002770
Greg Claytonc685f8e2010-09-15 04:15:46 +00002771 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002772 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002773 assert (sc.module_sp);
2774
Greg Claytond4a2b372011-09-12 23:21:58 +00002775 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002776 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002777 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002778 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002779 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002780 DWARFDebugInfo* debug_info = DebugInfo();
2781 for (size_t i=0; i<num_matches; ++i)
2782 {
2783 const dw_offset_t die_offset = die_offsets[i];
2784 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002785
2786 if (die)
2787 {
2788 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002789
Greg Clayton95d87902011-11-11 03:16:25 +00002790 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002791
Greg Clayton95d87902011-11-11 03:16:25 +00002792 if (variables.GetSize() - original_size >= max_matches)
2793 break;
2794 }
2795 else
2796 {
2797 if (m_using_apple_tables)
2798 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002799 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2800 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002801 }
2802 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002803 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002804 }
2805
2806 // Return the number of variable that were appended to the list
2807 return variables.GetSize() - original_size;
2808}
2809
Greg Claytonaa044962011-10-13 00:59:38 +00002810
Jim Ingham4cda6e02011-10-07 22:23:45 +00002811bool
2812SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2813 DWARFCompileUnit *&dwarf_cu,
2814 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002815{
Greg Claytonaa044962011-10-13 00:59:38 +00002816 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2817 return ResolveFunction (dwarf_cu, die, sc_list);
2818}
2819
2820
2821bool
2822SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2823 const DWARFDebugInfoEntry *die,
2824 SymbolContextList& sc_list)
2825{
Greg Clayton9e315582011-09-02 04:03:59 +00002826 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002827
2828 if (die == NULL)
2829 return false;
2830
Jim Ingham4cda6e02011-10-07 22:23:45 +00002831 // If we were passed a die that is not a function, just return false...
2832 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2833 return false;
2834
2835 const DWARFDebugInfoEntry* inlined_die = NULL;
2836 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002837 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002838 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002839
Jim Ingham4cda6e02011-10-07 22:23:45 +00002840 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002841 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002842 if (die->Tag() == DW_TAG_subprogram)
2843 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002844 }
2845 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002846 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002847 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002848 {
2849 Address addr;
2850 // Parse all blocks if needed
2851 if (inlined_die)
2852 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002853 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002854 assert (sc.block != NULL);
2855 if (sc.block->GetStartAddress (addr) == false)
2856 addr.Clear();
2857 }
2858 else
2859 {
2860 sc.block = NULL;
2861 addr = sc.function->GetAddressRange().GetBaseAddress();
2862 }
2863
2864 if (addr.IsValid())
2865 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002866 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002867 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002868 }
2869 }
2870
Greg Claytonaa044962011-10-13 00:59:38 +00002871 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002872}
2873
Greg Clayton7f995132011-10-04 22:41:51 +00002874void
2875SymbolFileDWARF::FindFunctions (const ConstString &name,
2876 const NameToDIE &name_to_die,
2877 SymbolContextList& sc_list)
2878{
Greg Claytond4a2b372011-09-12 23:21:58 +00002879 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002880 if (name_to_die.Find (name, die_offsets))
2881 {
2882 ParseFunctions (die_offsets, sc_list);
2883 }
2884}
2885
2886
2887void
2888SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2889 const NameToDIE &name_to_die,
2890 SymbolContextList& sc_list)
2891{
2892 DIEArray die_offsets;
2893 if (name_to_die.Find (regex, die_offsets))
2894 {
2895 ParseFunctions (die_offsets, sc_list);
2896 }
2897}
2898
2899
2900void
2901SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2902 const DWARFMappedHash::MemoryTable &memory_table,
2903 SymbolContextList& sc_list)
2904{
2905 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002906 DWARFMappedHash::DIEInfoArray hash_data_array;
2907 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002908 {
Greg Claytond1767f02011-12-08 02:13:16 +00002909 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002910 ParseFunctions (die_offsets, sc_list);
2911 }
2912}
2913
2914void
2915SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2916 SymbolContextList& sc_list)
2917{
2918 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002919 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002920 {
Greg Clayton7f995132011-10-04 22:41:51 +00002921 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002922
2923 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002924 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002925 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002926 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002927 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002928 }
2929 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002930}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002931
Jim Ingham4cda6e02011-10-07 22:23:45 +00002932bool
2933SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2934 const DWARFCompileUnit *dwarf_cu,
2935 uint32_t name_type_mask,
2936 const char *partial_name,
2937 const char *base_name_start,
2938 const char *base_name_end)
2939{
2940 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2941 if (name_type_mask == eFunctionNameTypeMethod
2942 || name_type_mask == eFunctionNameTypeBase)
2943 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002944 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2945 if (!containing_decl_ctx)
2946 return false;
2947
2948 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2949
2950 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2951 return false;
2952 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2953 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002954 }
2955
2956 // Now we need to check whether the name we got back for this type matches the extra specifications
2957 // that were in the name we're looking up:
2958 if (base_name_start != partial_name || *base_name_end != '\0')
2959 {
2960 // First see if the stuff to the left matches the full name. To do that let's see if
2961 // we can pull out the mips linkage name attribute:
2962
2963 Mangled best_name;
2964
2965 DWARFDebugInfoEntry::Attributes attributes;
2966 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2967 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2968 if (idx != UINT32_MAX)
2969 {
2970 DWARFFormValue form_value;
2971 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2972 {
2973 const char *name = form_value.AsCString(&get_debug_str_data());
2974 best_name.SetValue (name, true);
2975 }
2976 }
2977 if (best_name)
2978 {
2979 const char *demangled = best_name.GetDemangledName().GetCString();
2980 if (demangled)
2981 {
2982 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00002983 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
2984 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002985 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00002986 else
2987 {
2988 // Sort out the case where our name is something like "Process::Destroy" and the match is
2989 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
2990 // namespace boundaries...
2991
2992 if (partial_name[0] == ':' && partial_name[1] == ':')
2993 {
2994 // The partial name was already on a namespace boundary so all matches are good.
2995 return true;
2996 }
2997 else if (partial_in_demangled == demangled)
2998 {
2999 // They both start the same, so this is an good match.
3000 return true;
3001 }
3002 else
3003 {
3004 if (partial_in_demangled - demangled == 1)
3005 {
3006 // Only one character difference, can't be a namespace boundary...
3007 return false;
3008 }
3009 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3010 {
3011 // We are on a namespace boundary, so this is also good.
3012 return true;
3013 }
3014 else
3015 return false;
3016 }
3017 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003018 }
3019 }
3020 }
3021
3022 return true;
3023}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003024
Greg Clayton0c5cd902010-06-28 21:30:43 +00003025uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003026SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003027 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003028 uint32_t name_type_mask,
3029 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003030 bool append,
3031 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003032{
3033 Timer scoped_timer (__PRETTY_FUNCTION__,
3034 "SymbolFileDWARF::FindFunctions (name = '%s')",
3035 name.AsCString());
3036
Greg Clayton21f2a492011-10-06 00:09:08 +00003037 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3038
3039 if (log)
3040 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003041 GetObjectFile()->GetModule()->LogMessage (log.get(),
3042 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3043 name.GetCString(),
3044 name_type_mask,
3045 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003046 }
3047
Greg Clayton0c5cd902010-06-28 21:30:43 +00003048 // If we aren't appending the results to this list, then clear the list
3049 if (!append)
3050 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003051
3052 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3053 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003054
3055 // If name is empty then we won't find anything.
3056 if (name.IsEmpty())
3057 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003058
3059 // Remember how many sc_list are in the list before we search in case
3060 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003061
Greg Clayton9e315582011-09-02 04:03:59 +00003062 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003063
Jim Ingham4cda6e02011-10-07 22:23:45 +00003064 const char *name_cstr = name.GetCString();
3065 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3066 const char *base_name_start = name_cstr;
3067 const char *base_name_end = name_cstr + strlen(name_cstr);
3068
3069 if (name_type_mask & eFunctionNameTypeAuto)
3070 {
3071 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3072 effective_name_type_mask = eFunctionNameTypeFull;
3073 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3074 effective_name_type_mask = eFunctionNameTypeFull;
3075 else
3076 {
3077 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3078 effective_name_type_mask |= eFunctionNameTypeSelector;
3079
3080 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3081 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3082 }
3083 }
3084 else
3085 {
3086 effective_name_type_mask = name_type_mask;
3087 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3088 {
3089 // If they've asked for a CPP method or function name and it can't be that, we don't
3090 // even need to search for CPP methods or names.
3091 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3092 {
3093 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3094 if (effective_name_type_mask == eFunctionNameTypeNone)
3095 return 0;
3096 }
3097 }
3098
3099 if (effective_name_type_mask & eFunctionNameTypeSelector)
3100 {
3101 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3102 {
3103 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3104 if (effective_name_type_mask == eFunctionNameTypeNone)
3105 return 0;
3106 }
3107 }
3108 }
3109
3110 DWARFDebugInfo* info = DebugInfo();
3111 if (info == NULL)
3112 return 0;
3113
Greg Claytonaa044962011-10-13 00:59:38 +00003114 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003115 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003116 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003117 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003118 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003119
3120 DIEArray die_offsets;
3121
3122 uint32_t num_matches = 0;
3123
3124 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003125 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003126 // If they asked for the full name, match what they typed. At some point we may
3127 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3128 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003129 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003130 for (uint32_t i = 0; i < num_matches; i++)
3131 {
Greg Clayton95d87902011-11-11 03:16:25 +00003132 const dw_offset_t die_offset = die_offsets[i];
3133 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003134 if (die)
3135 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003136 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3137 continue;
3138
Sean Callanan9df05fb2012-02-10 22:52:19 +00003139 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3140 continue;
3141
Greg Claytonaa044962011-10-13 00:59:38 +00003142 ResolveFunction (dwarf_cu, die, sc_list);
3143 }
Greg Clayton95d87902011-11-11 03:16:25 +00003144 else
3145 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003146 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3147 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003148 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003149 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003150 }
3151 else
3152 {
3153 if (effective_name_type_mask & eFunctionNameTypeSelector)
3154 {
3155 if (namespace_decl && *namespace_decl)
3156 return 0; // no selectors in namespaces
3157
3158 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3159 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3160 // and if it is an ObjC method name, we're good.
3161
3162 for (uint32_t i = 0; i < num_matches; i++)
3163 {
Greg Clayton95d87902011-11-11 03:16:25 +00003164 const dw_offset_t die_offset = die_offsets[i];
3165 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003166 if (die)
3167 {
3168 const char *die_name = die->GetName(this, dwarf_cu);
3169 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003170 {
3171 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3172 continue;
3173
Greg Clayton97fbc342011-10-20 22:30:33 +00003174 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003175 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003176 }
Greg Clayton95d87902011-11-11 03:16:25 +00003177 else
3178 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003179 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3180 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003181 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003182 }
3183 die_offsets.clear();
3184 }
3185
3186 if (effective_name_type_mask & eFunctionNameTypeMethod
3187 || effective_name_type_mask & eFunctionNameTypeBase)
3188 {
3189 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3190 (namespace_decl && *namespace_decl))
3191 return 0; // no methods in namespaces
3192
3193 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3194 // extract the base name, look that up, and if there is any other information in the name we were
3195 // passed in we have to post-filter based on that.
3196
3197 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3198 std::string base_name(base_name_start, base_name_end - base_name_start);
3199 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3200
3201 for (uint32_t i = 0; i < num_matches; i++)
3202 {
Greg Clayton95d87902011-11-11 03:16:25 +00003203 const dw_offset_t die_offset = die_offsets[i];
3204 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003205 if (die)
3206 {
3207 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3208 continue;
3209
3210 if (!FunctionDieMatchesPartialName(die,
3211 dwarf_cu,
3212 effective_name_type_mask,
3213 name_cstr,
3214 base_name_start,
3215 base_name_end))
3216 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003217
3218 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3219 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003220
3221 // If we get to here, the die is good, and we should add it:
3222 ResolveFunction (dwarf_cu, die, sc_list);
3223 }
Greg Clayton95d87902011-11-11 03:16:25 +00003224 else
3225 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003226 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3227 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003228 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003229 }
3230 die_offsets.clear();
3231 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003232 }
3233 }
Greg Clayton7f995132011-10-04 22:41:51 +00003234 }
3235 else
3236 {
3237
3238 // Index the DWARF if we haven't already
3239 if (!m_indexed)
3240 Index ();
3241
Greg Clayton7f995132011-10-04 22:41:51 +00003242 if (name_type_mask & eFunctionNameTypeFull)
3243 FindFunctions (name, m_function_fullname_index, sc_list);
3244
Jim Ingham4cda6e02011-10-07 22:23:45 +00003245 std::string base_name(base_name_start, base_name_end - base_name_start);
3246 ConstString base_name_const(base_name.c_str());
3247 DIEArray die_offsets;
3248 DWARFCompileUnit *dwarf_cu = NULL;
3249
3250 if (effective_name_type_mask & eFunctionNameTypeBase)
3251 {
3252 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003253 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003254 {
Greg Claytonaa044962011-10-13 00:59:38 +00003255 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3256 if (die)
3257 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003258 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3259 continue;
3260
Greg Claytonaa044962011-10-13 00:59:38 +00003261 if (!FunctionDieMatchesPartialName(die,
3262 dwarf_cu,
3263 effective_name_type_mask,
3264 name_cstr,
3265 base_name_start,
3266 base_name_end))
3267 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003268
Sean Callanan9df05fb2012-02-10 22:52:19 +00003269 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3270 continue;
3271
Greg Claytonaa044962011-10-13 00:59:38 +00003272 // If we get to here, the die is good, and we should add it:
3273 ResolveFunction (dwarf_cu, die, sc_list);
3274 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003275 }
3276 die_offsets.clear();
3277 }
3278
Jim Inghamea8005a2011-10-11 01:18:11 +00003279 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003280 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003281 if (namespace_decl && *namespace_decl)
3282 return 0; // no methods in namespaces
3283
Jim Ingham4cda6e02011-10-07 22:23:45 +00003284 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3285 {
Greg Claytonaa044962011-10-13 00:59:38 +00003286 for (uint32_t i = 0; i < num_base; i++)
3287 {
3288 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3289 if (die)
3290 {
3291 if (!FunctionDieMatchesPartialName(die,
3292 dwarf_cu,
3293 effective_name_type_mask,
3294 name_cstr,
3295 base_name_start,
3296 base_name_end))
3297 continue;
3298
Sean Callanan9df05fb2012-02-10 22:52:19 +00003299 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3300 continue;
3301
Greg Claytonaa044962011-10-13 00:59:38 +00003302 // If we get to here, the die is good, and we should add it:
3303 ResolveFunction (dwarf_cu, die, sc_list);
3304 }
3305 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003306 }
3307 die_offsets.clear();
3308 }
Greg Clayton7f995132011-10-04 22:41:51 +00003309
Sean Callanan213fdb82011-10-13 01:49:10 +00003310 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003311 {
Greg Clayton7f995132011-10-04 22:41:51 +00003312 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003313 }
3314
Greg Clayton4d01ace2011-09-29 16:58:15 +00003315 }
3316
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003317 // Return the number of variable that were appended to the list
3318 return sc_list.GetSize() - original_size;
3319}
3320
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003321uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003322SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003323{
3324 Timer scoped_timer (__PRETTY_FUNCTION__,
3325 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3326 regex.GetText());
3327
Greg Clayton21f2a492011-10-06 00:09:08 +00003328 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3329
3330 if (log)
3331 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003332 GetObjectFile()->GetModule()->LogMessage (log.get(),
3333 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3334 regex.GetText(),
3335 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003336 }
3337
3338
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003339 // If we aren't appending the results to this list, then clear the list
3340 if (!append)
3341 sc_list.Clear();
3342
3343 // Remember how many sc_list are in the list before we search in case
3344 // we are appending the results to a variable list.
3345 uint32_t original_size = sc_list.GetSize();
3346
Greg Clayton97fbc342011-10-20 22:30:33 +00003347 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003348 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003349 if (m_apple_names_ap.get())
3350 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003351 }
3352 else
3353 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003354 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003355 if (!m_indexed)
3356 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003357
Greg Clayton7f995132011-10-04 22:41:51 +00003358 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003359
Greg Clayton7f995132011-10-04 22:41:51 +00003360 FindFunctions (regex, m_function_fullname_index, sc_list);
3361 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003362
3363 // Return the number of variable that were appended to the list
3364 return sc_list.GetSize() - original_size;
3365}
Jim Ingham318c9f22011-08-26 19:44:13 +00003366
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003367uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003368SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3369 const ConstString &name,
3370 const lldb_private::ClangNamespaceDecl *namespace_decl,
3371 bool append,
3372 uint32_t max_matches,
3373 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003374{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003375 DWARFDebugInfo* info = DebugInfo();
3376 if (info == NULL)
3377 return 0;
3378
Greg Clayton21f2a492011-10-06 00:09:08 +00003379 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3380
3381 if (log)
3382 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003383 GetObjectFile()->GetModule()->LogMessage (log.get(),
3384 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
3385 name.GetCString(),
3386 append,
3387 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003388 }
3389
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003390 // If we aren't appending the results to this list, then clear the list
3391 if (!append)
3392 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003393
3394 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3395 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003396
Greg Claytond4a2b372011-09-12 23:21:58 +00003397 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003398
Greg Clayton97fbc342011-10-20 22:30:33 +00003399 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003400 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003401 if (m_apple_types_ap.get())
3402 {
3403 const char *name_cstr = name.GetCString();
3404 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3405 }
Greg Clayton7f995132011-10-04 22:41:51 +00003406 }
3407 else
3408 {
3409 if (!m_indexed)
3410 Index ();
3411
3412 m_type_index.Find (name, die_offsets);
3413 }
3414
Greg Clayton7f995132011-10-04 22:41:51 +00003415 const size_t num_matches = die_offsets.size();
3416
Greg Claytond4a2b372011-09-12 23:21:58 +00003417 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003418 {
Greg Clayton7f995132011-10-04 22:41:51 +00003419 const uint32_t initial_types_size = types.GetSize();
3420 DWARFCompileUnit* dwarf_cu = NULL;
3421 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003422 DWARFDebugInfo* debug_info = DebugInfo();
3423 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003424 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003425 const dw_offset_t die_offset = die_offsets[i];
3426 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3427
Greg Clayton95d87902011-11-11 03:16:25 +00003428 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003429 {
Greg Clayton95d87902011-11-11 03:16:25 +00003430 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3431 continue;
3432
3433 Type *matching_type = ResolveType (dwarf_cu, die);
3434 if (matching_type)
3435 {
3436 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003437 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003438 if (types.GetSize() >= max_matches)
3439 break;
3440 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003441 }
Greg Clayton95d87902011-11-11 03:16:25 +00003442 else
3443 {
3444 if (m_using_apple_tables)
3445 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003446 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3447 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003448 }
3449 }
3450
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003451 }
Greg Clayton7f995132011-10-04 22:41:51 +00003452 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003453 }
Greg Clayton7f995132011-10-04 22:41:51 +00003454 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003455}
3456
3457
Greg Clayton526e5af2010-11-13 03:52:47 +00003458ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003459SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003460 const ConstString &name,
3461 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003462{
Greg Clayton21f2a492011-10-06 00:09:08 +00003463 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3464
3465 if (log)
3466 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003467 GetObjectFile()->GetModule()->LogMessage (log.get(),
3468 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3469 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003470 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003471
3472 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3473 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003474
Greg Clayton526e5af2010-11-13 03:52:47 +00003475 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003476 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003477 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003478 {
Greg Clayton7f995132011-10-04 22:41:51 +00003479 DIEArray die_offsets;
3480
Greg Clayton526e5af2010-11-13 03:52:47 +00003481 // Index if we already haven't to make sure the compile units
3482 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003483 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003484 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003485 if (m_apple_namespaces_ap.get())
3486 {
3487 const char *name_cstr = name.GetCString();
3488 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3489 }
Greg Clayton7f995132011-10-04 22:41:51 +00003490 }
3491 else
3492 {
3493 if (!m_indexed)
3494 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003495
Greg Clayton7f995132011-10-04 22:41:51 +00003496 m_namespace_index.Find (name, die_offsets);
3497 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003498
3499 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003500 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003501 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003502 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003503 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003504 DWARFDebugInfo* debug_info = DebugInfo();
3505 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003506 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003507 const dw_offset_t die_offset = die_offsets[i];
3508 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003509
Greg Clayton95d87902011-11-11 03:16:25 +00003510 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003511 {
Greg Clayton95d87902011-11-11 03:16:25 +00003512 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3513 continue;
3514
3515 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3516 if (clang_namespace_decl)
3517 {
3518 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3519 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003520 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003521 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003522 }
Greg Clayton95d87902011-11-11 03:16:25 +00003523 else
3524 {
3525 if (m_using_apple_tables)
3526 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003527 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3528 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003529 }
3530 }
3531
Greg Clayton526e5af2010-11-13 03:52:47 +00003532 }
3533 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003534 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003535 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003536}
3537
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003538uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003539SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003540{
3541 // Remember how many sc_list are in the list before we search in case
3542 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003543 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003544
3545 const uint32_t num_die_offsets = die_offsets.size();
3546 // Parse all of the types we found from the pubtypes matches
3547 uint32_t i;
3548 uint32_t num_matches = 0;
3549 for (i = 0; i < num_die_offsets; ++i)
3550 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003551 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3552 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003553 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003554 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003555 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003556 ++num_matches;
3557 if (num_matches >= max_matches)
3558 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003559 }
3560 }
3561
3562 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003563 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003564}
3565
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003566
3567size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003568SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3569 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003570 DWARFCompileUnit* dwarf_cu,
3571 const DWARFDebugInfoEntry *parent_die,
3572 bool skip_artificial,
3573 bool &is_static,
3574 TypeList* type_list,
3575 std::vector<clang_type_t>& function_param_types,
3576 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003577 unsigned &type_quals,
3578 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003579{
3580 if (parent_die == NULL)
3581 return 0;
3582
Greg Claytond88d7592010-09-15 08:33:30 +00003583 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3584
Greg Clayton7fedea22010-11-16 02:10:54 +00003585 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003586 const DWARFDebugInfoEntry *die;
3587 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3588 {
3589 dw_tag_t tag = die->Tag();
3590 switch (tag)
3591 {
3592 case DW_TAG_formal_parameter:
3593 {
3594 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003595 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003596 if (num_attributes > 0)
3597 {
3598 const char *name = NULL;
3599 Declaration decl;
3600 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003601 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003602 // one of None, Auto, Register, Extern, Static, PrivateExtern
3603
Sean Callanane2ef6e32010-09-23 03:01:22 +00003604 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003605 uint32_t i;
3606 for (i=0; i<num_attributes; ++i)
3607 {
3608 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3609 DWARFFormValue form_value;
3610 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3611 {
3612 switch (attr)
3613 {
3614 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3615 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3616 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3617 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3618 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003619 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003620 case DW_AT_location:
3621 // if (form_value.BlockData())
3622 // {
3623 // const DataExtractor& debug_info_data = debug_info();
3624 // uint32_t block_length = form_value.Unsigned();
3625 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3626 // }
3627 // else
3628 // {
3629 // }
3630 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003631 case DW_AT_const_value:
3632 case DW_AT_default_value:
3633 case DW_AT_description:
3634 case DW_AT_endianity:
3635 case DW_AT_is_optional:
3636 case DW_AT_segment:
3637 case DW_AT_variable_parameter:
3638 default:
3639 case DW_AT_abstract_origin:
3640 case DW_AT_sibling:
3641 break;
3642 }
3643 }
3644 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003645
Greg Clayton0fffff52010-09-24 05:15:53 +00003646 bool skip = false;
3647 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003648 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003649 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003650 {
3651 // In order to determine if a C++ member function is
3652 // "const" we have to look at the const-ness of "this"...
3653 // Ugly, but that
3654 if (arg_idx == 0)
3655 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003656 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003657 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003658 // Often times compilers omit the "this" name for the
3659 // specification DIEs, so we can't rely upon the name
3660 // being in the formal parameter DIE...
3661 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003662 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003663 Type *this_type = ResolveTypeUID (param_type_die_offset);
3664 if (this_type)
3665 {
3666 uint32_t encoding_mask = this_type->GetEncodingMask();
3667 if (encoding_mask & Type::eEncodingIsPointerUID)
3668 {
3669 is_static = false;
3670
3671 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3672 type_quals |= clang::Qualifiers::Const;
3673 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3674 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003675 }
3676 }
3677 }
3678 }
3679 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003680 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003681 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003682 else
3683 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003684
Greg Clayton0fffff52010-09-24 05:15:53 +00003685 // HACK: Objective C formal parameters "self" and "_cmd"
3686 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00003687 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3688 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00003689 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003690 switch (comp_unit->GetLanguage())
3691 {
3692 case eLanguageTypeObjC:
3693 case eLanguageTypeObjC_plus_plus:
3694 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3695 skip = true;
3696 break;
3697 default:
3698 break;
3699 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003700 }
3701 }
3702 }
3703
3704 if (!skip)
3705 {
3706 Type *type = ResolveTypeUID(param_type_die_offset);
3707 if (type)
3708 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003709 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003710
Greg Clayton42ce2f32011-12-12 21:50:19 +00003711 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3712 type->GetClangForwardType(),
3713 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003714 assert(param_var_decl);
3715 function_param_decls.push_back(param_var_decl);
3716 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003717 }
3718 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003719 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003720 }
3721 break;
3722
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003723 case DW_TAG_template_type_parameter:
3724 case DW_TAG_template_value_parameter:
3725 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3726 break;
3727
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003728 default:
3729 break;
3730 }
3731 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003732 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003733}
3734
3735size_t
3736SymbolFileDWARF::ParseChildEnumerators
3737(
3738 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003739 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003741 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003742 const DWARFDebugInfoEntry *parent_die
3743)
3744{
3745 if (parent_die == NULL)
3746 return 0;
3747
3748 size_t enumerators_added = 0;
3749 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003750 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3751
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003752 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3753 {
3754 const dw_tag_t tag = die->Tag();
3755 if (tag == DW_TAG_enumerator)
3756 {
3757 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003758 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759 if (num_child_attributes > 0)
3760 {
3761 const char *name = NULL;
3762 bool got_value = false;
3763 int64_t enum_value = 0;
3764 Declaration decl;
3765
3766 uint32_t i;
3767 for (i=0; i<num_child_attributes; ++i)
3768 {
3769 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3770 DWARFFormValue form_value;
3771 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3772 {
3773 switch (attr)
3774 {
3775 case DW_AT_const_value:
3776 got_value = true;
3777 enum_value = form_value.Unsigned();
3778 break;
3779
3780 case DW_AT_name:
3781 name = form_value.AsCString(&get_debug_str_data());
3782 break;
3783
3784 case DW_AT_description:
3785 default:
3786 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3787 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3788 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3789 case DW_AT_sibling:
3790 break;
3791 }
3792 }
3793 }
3794
3795 if (name && name[0] && got_value)
3796 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003797 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3798 enumerator_clang_type,
3799 decl,
3800 name,
3801 enum_value,
3802 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003803 ++enumerators_added;
3804 }
3805 }
3806 }
3807 }
3808 return enumerators_added;
3809}
3810
3811void
3812SymbolFileDWARF::ParseChildArrayInfo
3813(
3814 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003815 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003816 const DWARFDebugInfoEntry *parent_die,
3817 int64_t& first_index,
3818 std::vector<uint64_t>& element_orders,
3819 uint32_t& byte_stride,
3820 uint32_t& bit_stride
3821)
3822{
3823 if (parent_die == NULL)
3824 return;
3825
3826 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003827 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003828 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3829 {
3830 const dw_tag_t tag = die->Tag();
3831 switch (tag)
3832 {
3833 case DW_TAG_enumerator:
3834 {
3835 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003836 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003837 if (num_child_attributes > 0)
3838 {
3839 const char *name = NULL;
3840 bool got_value = false;
3841 int64_t enum_value = 0;
3842
3843 uint32_t i;
3844 for (i=0; i<num_child_attributes; ++i)
3845 {
3846 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3847 DWARFFormValue form_value;
3848 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3849 {
3850 switch (attr)
3851 {
3852 case DW_AT_const_value:
3853 got_value = true;
3854 enum_value = form_value.Unsigned();
3855 break;
3856
3857 case DW_AT_name:
3858 name = form_value.AsCString(&get_debug_str_data());
3859 break;
3860
3861 case DW_AT_description:
3862 default:
3863 case DW_AT_decl_file:
3864 case DW_AT_decl_line:
3865 case DW_AT_decl_column:
3866 case DW_AT_sibling:
3867 break;
3868 }
3869 }
3870 }
3871 }
3872 }
3873 break;
3874
3875 case DW_TAG_subrange_type:
3876 {
3877 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003878 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003879 if (num_child_attributes > 0)
3880 {
3881 const char *name = NULL;
3882 bool got_value = false;
3883 uint64_t byte_size = 0;
3884 int64_t enum_value = 0;
3885 uint64_t num_elements = 0;
3886 uint64_t lower_bound = 0;
3887 uint64_t upper_bound = 0;
3888 uint32_t i;
3889 for (i=0; i<num_child_attributes; ++i)
3890 {
3891 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3892 DWARFFormValue form_value;
3893 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3894 {
3895 switch (attr)
3896 {
3897 case DW_AT_const_value:
3898 got_value = true;
3899 enum_value = form_value.Unsigned();
3900 break;
3901
3902 case DW_AT_name:
3903 name = form_value.AsCString(&get_debug_str_data());
3904 break;
3905
3906 case DW_AT_count:
3907 num_elements = form_value.Unsigned();
3908 break;
3909
3910 case DW_AT_bit_stride:
3911 bit_stride = form_value.Unsigned();
3912 break;
3913
3914 case DW_AT_byte_stride:
3915 byte_stride = form_value.Unsigned();
3916 break;
3917
3918 case DW_AT_byte_size:
3919 byte_size = form_value.Unsigned();
3920 break;
3921
3922 case DW_AT_lower_bound:
3923 lower_bound = form_value.Unsigned();
3924 break;
3925
3926 case DW_AT_upper_bound:
3927 upper_bound = form_value.Unsigned();
3928 break;
3929
3930 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003931 case DW_AT_abstract_origin:
3932 case DW_AT_accessibility:
3933 case DW_AT_allocated:
3934 case DW_AT_associated:
3935 case DW_AT_data_location:
3936 case DW_AT_declaration:
3937 case DW_AT_description:
3938 case DW_AT_sibling:
3939 case DW_AT_threads_scaled:
3940 case DW_AT_type:
3941 case DW_AT_visibility:
3942 break;
3943 }
3944 }
3945 }
3946
3947 if (upper_bound > lower_bound)
3948 num_elements = upper_bound - lower_bound + 1;
3949
3950 if (num_elements > 0)
3951 element_orders.push_back (num_elements);
3952 }
3953 }
3954 break;
3955 }
3956 }
3957}
3958
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003959TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00003960SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003961{
3962 TypeSP type_sp;
3963 if (die != NULL)
3964 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003965 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003966 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003967 if (type_ptr == NULL)
3968 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003969 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00003970 assert (lldb_cu);
3971 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00003972 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003973 }
3974 else if (type_ptr != DIE_IS_BEING_PARSED)
3975 {
3976 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003977 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003978 }
3979
3980 }
3981 return type_sp;
3982}
3983
3984clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003985SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003986{
3987 if (die_offset != DW_INVALID_OFFSET)
3988 {
3989 DWARFCompileUnitSP cu_sp;
3990 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003991 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003992 }
3993 return NULL;
3994}
3995
Sean Callanan72e49402011-08-05 23:43:37 +00003996clang::DeclContext *
3997SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3998{
3999 if (die_offset != DW_INVALID_OFFSET)
4000 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004001 DWARFDebugInfo* debug_info = DebugInfo();
4002 if (debug_info)
4003 {
4004 DWARFCompileUnitSP cu_sp;
4005 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4006 if (die)
4007 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4008 }
Sean Callanan72e49402011-08-05 23:43:37 +00004009 }
4010 return NULL;
4011}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004012
Greg Clayton96d7d742010-11-10 23:42:09 +00004013clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004014SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004015{
Greg Clayton030a2042011-10-14 21:34:45 +00004016 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004017 {
Greg Clayton030a2042011-10-14 21:34:45 +00004018 // See if we already parsed this namespace DIE and associated it with a
4019 // uniqued namespace declaration
4020 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4021 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004022 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004023 else
4024 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004025 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4026 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004027 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4028 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4029 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004030 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004031 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004032 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004033 GetObjectFile()->GetModule()->LogMessage (log.get(),
4034 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4035 GetClangASTContext().getASTContext(),
4036 MakeUserID(die->GetOffset()),
4037 namespace_name,
4038 namespace_decl,
4039 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004040 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004041 else
4042 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004043 GetObjectFile()->GetModule()->LogMessage (log.get(),
4044 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4045 GetClangASTContext().getASTContext(),
4046 MakeUserID(die->GetOffset()),
4047 namespace_decl,
4048 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004049 }
Greg Clayton030a2042011-10-14 21:34:45 +00004050 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004051
4052 if (namespace_decl)
4053 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4054 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004055 }
4056 }
4057 return NULL;
4058}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004059
4060clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004061SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004062{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004063 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4064 if (clang_decl_ctx)
4065 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004066 // If this DIE has a specification, or an abstract origin, then trace to those.
4067
Greg Claytoncab36a32011-12-08 05:16:30 +00004068 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004069 if (die_offset != DW_INVALID_OFFSET)
4070 return GetClangDeclContextForDIEOffset (sc, die_offset);
4071
Greg Claytoncab36a32011-12-08 05:16:30 +00004072 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004073 if (die_offset != DW_INVALID_OFFSET)
4074 return GetClangDeclContextForDIEOffset (sc, die_offset);
4075
Greg Clayton3bffb082011-12-10 02:15:28 +00004076 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4077 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004078 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 +00004079 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004080 bool assert_not_being_parsed = true;
4081 ResolveTypeUID (cu, die, assert_not_being_parsed);
4082
Greg Clayton5cf58b92011-10-05 22:22:08 +00004083 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4084
4085 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004086}
4087
4088clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004089SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004090{
Greg Claytonca512b32011-01-14 04:54:56 +00004091 if (m_clang_tu_decl == NULL)
4092 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004093
Greg Clayton2bc22f82011-09-30 03:20:47 +00004094 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004095
4096 if (decl_ctx_die_copy)
4097 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004098
4099 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004100 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004101
Greg Clayton2bc22f82011-09-30 03:20:47 +00004102 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4103 if (pos != m_die_to_decl_ctx.end())
4104 return pos->second;
4105
4106 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004107 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004108 case DW_TAG_compile_unit:
4109 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004110
Greg Clayton2bc22f82011-09-30 03:20:47 +00004111 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004112 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004113 break;
4114
4115 case DW_TAG_structure_type:
4116 case DW_TAG_union_type:
4117 case DW_TAG_class_type:
4118 {
4119 Type* type = ResolveType (cu, decl_ctx_die);
4120 if (type)
4121 {
4122 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4123 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004124 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004125 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4126 if (decl_ctx)
4127 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004128 }
4129 }
Greg Claytonca512b32011-01-14 04:54:56 +00004130 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004131 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004132
Greg Clayton2bc22f82011-09-30 03:20:47 +00004133 default:
4134 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004135 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004136 }
Greg Clayton7a345282010-11-09 23:46:37 +00004137 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004138}
4139
Greg Clayton2bc22f82011-09-30 03:20:47 +00004140
4141const DWARFDebugInfoEntry *
4142SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4143{
4144 if (cu && die)
4145 {
4146 const DWARFDebugInfoEntry * const decl_die = die;
4147
4148 while (die != NULL)
4149 {
4150 // If this is the original DIE that we are searching for a declaration
4151 // for, then don't look in the cache as we don't want our own decl
4152 // context to be our decl context...
4153 if (decl_die != die)
4154 {
4155 switch (die->Tag())
4156 {
4157 case DW_TAG_compile_unit:
4158 case DW_TAG_namespace:
4159 case DW_TAG_structure_type:
4160 case DW_TAG_union_type:
4161 case DW_TAG_class_type:
4162 return die;
4163
4164 default:
4165 break;
4166 }
4167 }
4168
4169 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4170 if (die_offset != DW_INVALID_OFFSET)
4171 {
4172 DWARFCompileUnit *spec_cu = cu;
4173 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4174 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4175 if (spec_die_decl_ctx_die)
4176 return spec_die_decl_ctx_die;
4177 }
4178
4179 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4180 if (die_offset != DW_INVALID_OFFSET)
4181 {
4182 DWARFCompileUnit *abs_cu = cu;
4183 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4184 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4185 if (abs_die_decl_ctx_die)
4186 return abs_die_decl_ctx_die;
4187 }
4188
4189 die = die->GetParent();
4190 }
4191 }
4192 return NULL;
4193}
4194
4195
Greg Clayton901c5ca2011-12-03 04:40:03 +00004196Symbol *
4197SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4198{
4199 Symbol *objc_class_symbol = NULL;
4200 if (m_obj_file)
4201 {
4202 Symtab *symtab = m_obj_file->GetSymtab();
4203 if (symtab)
4204 {
4205 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4206 eSymbolTypeObjCClass,
4207 Symtab::eDebugNo,
4208 Symtab::eVisibilityAny);
4209 }
4210 }
4211 return objc_class_symbol;
4212}
4213
Greg Claytonc7f03b62012-01-12 04:33:28 +00004214// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4215// then we can end up looking through all class types for a complete type and never find
4216// the full definition. We need to know if this attribute is supported, so we determine
4217// this here and cache th result. We also need to worry about the debug map DWARF file
4218// if we are doing darwin DWARF in .o file debugging.
4219bool
4220SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4221{
4222 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4223 {
4224 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4225 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4226 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4227 else
4228 {
4229 DWARFDebugInfo* debug_info = DebugInfo();
4230 const uint32_t num_compile_units = GetNumCompileUnits();
4231 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4232 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004233 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4234 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004235 {
4236 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4237 break;
4238 }
4239 }
4240 }
4241 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4242 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4243 }
4244 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4245}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004246
4247// This function can be used when a DIE is found that is a forward declaration
4248// DIE and we want to try and find a type that has the complete definition.
4249TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004250SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4251 const ConstString &type_name,
4252 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004253{
4254
4255 TypeSP type_sp;
4256
Greg Claytonc7f03b62012-01-12 04:33:28 +00004257 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004258 return type_sp;
4259
4260 DIEArray die_offsets;
4261
4262 if (m_using_apple_tables)
4263 {
4264 if (m_apple_types_ap.get())
4265 {
4266 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004267 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004268 }
4269 }
4270 else
4271 {
4272 if (!m_indexed)
4273 Index ();
4274
4275 m_type_index.Find (type_name, die_offsets);
4276 }
4277
Greg Clayton901c5ca2011-12-03 04:40:03 +00004278 const size_t num_matches = die_offsets.size();
4279
Greg Clayton901c5ca2011-12-03 04:40:03 +00004280 DWARFCompileUnit* type_cu = NULL;
4281 const DWARFDebugInfoEntry* type_die = NULL;
4282 if (num_matches)
4283 {
4284 DWARFDebugInfo* debug_info = DebugInfo();
4285 for (size_t i=0; i<num_matches; ++i)
4286 {
4287 const dw_offset_t die_offset = die_offsets[i];
4288 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4289
4290 if (type_die)
4291 {
4292 bool try_resolving_type = false;
4293
4294 // Don't try and resolve the DIE we are looking for with the DIE itself!
4295 if (type_die != die)
4296 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004297 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004298 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004299 case DW_TAG_class_type:
4300 case DW_TAG_structure_type:
4301 try_resolving_type = true;
4302 break;
4303 default:
4304 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004305 }
4306 }
4307
4308 if (try_resolving_type)
4309 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004310 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004311 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004312
4313 if (try_resolving_type)
4314 {
4315 Type *resolved_type = ResolveType (type_cu, type_die, false);
4316 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4317 {
4318 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4319 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004320 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004321 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4322 MakeUserID(type_die->GetOffset()),
4323 MakeUserID(type_cu->GetOffset()));
4324
Greg Claytonc7f03b62012-01-12 04:33:28 +00004325 if (die)
4326 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004327 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004328 break;
4329 }
4330 }
4331 }
4332 }
4333 else
4334 {
4335 if (m_using_apple_tables)
4336 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004337 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4338 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004339 }
4340 }
4341
4342 }
4343 }
4344 return type_sp;
4345}
4346
Greg Clayton80c26302012-02-05 06:12:47 +00004347//----------------------------------------------------------------------
4348// This function helps to ensure that the declaration contexts match for
4349// two different DIEs. Often times debug information will refer to a
4350// forward declaration of a type (the equivalent of "struct my_struct;".
4351// There will often be a declaration of that type elsewhere that has the
4352// full definition. When we go looking for the full type "my_struct", we
4353// will find one or more matches in the accelerator tables and we will
4354// then need to make sure the type was in the same declaration context
4355// as the original DIE. This function can efficiently compare two DIEs
4356// and will return true when the declaration context matches, and false
4357// when they don't.
4358//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004359bool
4360SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4361 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4362{
4363 assert (die1 != die2);
4364 DWARFDIECollection decl_ctx_1;
4365 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004366 //The declaration DIE stack is a stack of the declaration context
4367 // DIEs all the way back to the compile unit. If a type "T" is
4368 // declared inside a class "B", and class "B" is declared inside
4369 // a class "A" and class "A" is in a namespace "lldb", and the
4370 // namespace is in a compile unit, there will be a stack of DIEs:
4371 //
4372 // [0] DW_TAG_class_type for "B"
4373 // [1] DW_TAG_class_type for "A"
4374 // [2] DW_TAG_namespace for "lldb"
4375 // [3] DW_TAG_compile_unit for the source file.
4376 //
4377 // We grab both contexts and make sure that everything matches
4378 // all the way back to the compiler unit.
4379
4380 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004381 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004382 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004383 // Make sure the context arrays have the same size, otherwise
4384 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004385 const size_t count1 = decl_ctx_1.Size();
4386 const size_t count2 = decl_ctx_2.Size();
4387 if (count1 != count2)
4388 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004389
4390 // Make sure the DW_TAG values match all the way back up the the
4391 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004392 const DWARFDebugInfoEntry *decl_ctx_die1;
4393 const DWARFDebugInfoEntry *decl_ctx_die2;
4394 size_t i;
4395 for (i=0; i<count1; i++)
4396 {
4397 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4398 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4399 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4400 return false;
4401 }
Greg Clayton890ff562012-02-02 05:48:16 +00004402#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004403
4404 // Make sure the top item in the decl context die array is always
4405 // DW_TAG_compile_unit. If it isn't then something went wrong in
4406 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004407 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004408
Greg Clayton890ff562012-02-02 05:48:16 +00004409#endif
4410 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004411 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004412 for (i=0; i<count1 - 1; i++)
4413 {
4414 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4415 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4416 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004417 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004418 // If the string was from a DW_FORM_strp, then the pointer will often
4419 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004420 if (name1 == name2)
4421 continue;
4422
4423 // Name pointers are not equal, so only compare the strings
4424 // if both are not NULL.
4425 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004426 {
Greg Clayton5569e642012-02-06 01:44:54 +00004427 // If the strings don't compare, we are done...
4428 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004429 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004430 }
4431 else
4432 {
4433 // One name was NULL while the other wasn't
4434 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004435 }
4436 }
Greg Clayton80c26302012-02-05 06:12:47 +00004437 // We made it through all of the checks and the declaration contexts
4438 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004439 return true;
4440}
Greg Clayton220a0072011-12-09 08:48:30 +00004441
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004442// This function can be used when a DIE is found that is a forward declaration
4443// DIE and we want to try and find a type that has the complete definition.
4444TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00004445SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4446 const DWARFDebugInfoEntry *die,
4447 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004448{
4449 TypeSP type_sp;
4450
Greg Clayton1a65ae12011-01-25 23:55:37 +00004451 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004452 return type_sp;
4453
Greg Clayton7f995132011-10-04 22:41:51 +00004454 DIEArray die_offsets;
4455
Greg Clayton97fbc342011-10-20 22:30:33 +00004456 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004457 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004458 if (m_apple_types_ap.get())
4459 {
Greg Claytond1767f02011-12-08 02:13:16 +00004460 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4461 {
Greg Claytonae920b62012-01-06 00:17:16 +00004462 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004463 }
4464 else
4465 {
4466 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4467 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004468 }
Greg Clayton7f995132011-10-04 22:41:51 +00004469 }
4470 else
4471 {
4472 if (!m_indexed)
4473 Index ();
4474
4475 m_type_index.Find (type_name, die_offsets);
4476 }
Greg Clayton7f995132011-10-04 22:41:51 +00004477
4478 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004479
Greg Clayton934cb052011-12-03 00:27:05 +00004480 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004481
4482 DWARFCompileUnit* type_cu = NULL;
4483 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004484 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004485 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004486 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004487 for (size_t i=0; i<num_matches; ++i)
4488 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004489 const dw_offset_t die_offset = die_offsets[i];
4490 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004491
Greg Clayton95d87902011-11-11 03:16:25 +00004492 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004493 {
Greg Clayton934cb052011-12-03 00:27:05 +00004494 bool try_resolving_type = false;
4495
4496 // Don't try and resolve the DIE we are looking for with the DIE itself!
4497 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004498 {
Greg Clayton934cb052011-12-03 00:27:05 +00004499 const dw_tag_t type_die_tag = type_die->Tag();
4500 // Make sure the tags match
4501 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004502 {
Greg Clayton934cb052011-12-03 00:27:05 +00004503 // The tags match, lets try resolving this type
4504 try_resolving_type = true;
4505 }
4506 else
4507 {
4508 // The tags don't match, but we need to watch our for a
4509 // forward declaration for a struct and ("struct foo")
4510 // ends up being a class ("class foo { ... };") or
4511 // vice versa.
4512 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004513 {
Greg Clayton934cb052011-12-03 00:27:05 +00004514 case DW_TAG_class_type:
4515 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4516 try_resolving_type = (die_tag == DW_TAG_structure_type);
4517 break;
4518 case DW_TAG_structure_type:
4519 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4520 try_resolving_type = (die_tag == DW_TAG_class_type);
4521 break;
4522 default:
4523 // Tags don't match, don't event try to resolve
4524 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004525 break;
4526 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004527 }
4528 }
Greg Clayton934cb052011-12-03 00:27:05 +00004529
4530 if (try_resolving_type)
4531 {
Greg Clayton890ff562012-02-02 05:48:16 +00004532 // Make sure the decl contexts match all the way up
4533 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004534 {
Greg Clayton890ff562012-02-02 05:48:16 +00004535 Type *resolved_type = ResolveType (type_cu, type_die, false);
4536 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4537 {
4538 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4539 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004540 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004541 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4542 MakeUserID(type_die->GetOffset()),
4543 MakeUserID(type_cu->GetOffset()));
4544
4545 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004546 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004547 break;
4548 }
Greg Clayton934cb052011-12-03 00:27:05 +00004549 }
4550 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004551 }
Greg Clayton95d87902011-11-11 03:16:25 +00004552 else
4553 {
4554 if (m_using_apple_tables)
4555 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004556 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4557 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004558 }
4559 }
4560
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004561 }
4562 }
4563 return type_sp;
4564}
4565
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004566TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004567SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004568{
4569 TypeSP type_sp;
4570
Greg Clayton1be10fc2010-09-29 01:12:09 +00004571 if (type_is_new_ptr)
4572 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00004573
4574#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4575 static DIEStack g_die_stack;
4576 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
4577#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00004578
Sean Callananc7fbf732010-08-06 00:32:49 +00004579 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004580 if (die != NULL)
4581 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004582 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004583 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00004584 {
4585 const DWARFDebugInfoEntry *context_die;
4586 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4587
Greg Clayton1fba87112012-02-09 20:03:49 +00004588 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 +00004589 die->GetOffset(),
4590 context,
4591 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00004592 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00004593 die->GetName(this, dwarf_cu));
4594
4595#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4596 scoped_die_logger.Push (dwarf_cu, die);
4597 g_die_stack.LogDIEs(log.get(), this);
4598#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00004599 }
Greg Clayton3bffb082011-12-10 02:15:28 +00004600//
4601// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4602// if (log && dwarf_cu)
4603// {
4604// StreamString s;
4605// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00004606// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00004607//
4608// }
Jim Ingham16746d12011-08-25 23:21:43 +00004609
Greg Clayton594e5ed2010-09-27 21:07:38 +00004610 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004611 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004612 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004613 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004614 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004615 if (type_is_new_ptr)
4616 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004617
Greg Clayton594e5ed2010-09-27 21:07:38 +00004618 const dw_tag_t tag = die->Tag();
4619
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004620 bool is_forward_declaration = false;
4621 DWARFDebugInfoEntry::Attributes attributes;
4622 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004623 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004624 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4625 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004626 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004627 Declaration decl;
4628
Greg Clayton4957bf62010-09-30 21:49:03 +00004629 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004630 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004631
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004632 dw_attr_t attr;
4633
4634 switch (tag)
4635 {
4636 case DW_TAG_base_type:
4637 case DW_TAG_pointer_type:
4638 case DW_TAG_reference_type:
4639 case DW_TAG_typedef:
4640 case DW_TAG_const_type:
4641 case DW_TAG_restrict_type:
4642 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004643 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004644 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004645 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004646 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004647
Greg Claytond88d7592010-09-15 08:33:30 +00004648 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004649 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004650 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4651
4652 if (num_attributes > 0)
4653 {
4654 uint32_t i;
4655 for (i=0; i<num_attributes; ++i)
4656 {
4657 attr = attributes.AttributeAtIndex(i);
4658 DWARFFormValue form_value;
4659 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4660 {
4661 switch (attr)
4662 {
4663 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4664 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4665 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4666 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004667
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004668 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004669 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4670 // include the "&"...
4671 if (tag == DW_TAG_reference_type)
4672 {
4673 if (strchr (type_name_cstr, '&') == NULL)
4674 type_name_cstr = NULL;
4675 }
4676 if (type_name_cstr)
4677 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004678 break;
Greg Clayton36909642011-03-15 04:38:20 +00004679 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004680 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4681 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4682 default:
4683 case DW_AT_sibling:
4684 break;
4685 }
4686 }
4687 }
4688 }
4689
Greg Clayton81c22f62011-10-19 18:09:39 +00004690 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 +00004691
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004692 switch (tag)
4693 {
4694 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004695 break;
4696
Greg Claytond4436412011-10-28 21:00:00 +00004697 case DW_TAG_unspecified_type:
4698 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4699 {
4700 resolve_state = Type::eResolveStateFull;
4701 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4702 break;
4703 }
4704 // Fall through to base type below in case we can handle the type there...
4705
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004706 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004707 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004708 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4709 encoding,
4710 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004711 break;
4712
Greg Clayton526e5af2010-11-13 03:52:47 +00004713 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4714 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4715 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4716 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4717 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4718 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004719 }
4720
Greg Claytonc7f03b62012-01-12 04:33:28 +00004721 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004722 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004723 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4724 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004725 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004726 static ConstString g_objc_type_name_id("id");
4727 static ConstString g_objc_type_name_Class("Class");
4728 static ConstString g_objc_type_name_selector("SEL");
4729
4730 if (type_name_const_str == g_objc_type_name_id)
4731 {
4732 if (log)
4733 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4734 die->GetOffset(),
4735 DW_TAG_value_to_name(die->Tag()),
4736 die->GetName(this, dwarf_cu));
4737 clang_type = ast.GetBuiltInType_objc_id();
4738 encoding_data_type = Type::eEncodingIsUID;
4739 encoding_uid = LLDB_INVALID_UID;
4740 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00004741
Greg Claytonc7f03b62012-01-12 04:33:28 +00004742 }
4743 else if (type_name_const_str == g_objc_type_name_Class)
4744 {
4745 if (log)
4746 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4747 die->GetOffset(),
4748 DW_TAG_value_to_name(die->Tag()),
4749 die->GetName(this, dwarf_cu));
4750 clang_type = ast.GetBuiltInType_objc_Class();
4751 encoding_data_type = Type::eEncodingIsUID;
4752 encoding_uid = LLDB_INVALID_UID;
4753 resolve_state = Type::eResolveStateFull;
4754 }
4755 else if (type_name_const_str == g_objc_type_name_selector)
4756 {
4757 if (log)
4758 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4759 die->GetOffset(),
4760 DW_TAG_value_to_name(die->Tag()),
4761 die->GetName(this, dwarf_cu));
4762 clang_type = ast.GetBuiltInType_objc_selector();
4763 encoding_data_type = Type::eEncodingIsUID;
4764 encoding_uid = LLDB_INVALID_UID;
4765 resolve_state = Type::eResolveStateFull;
4766 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004767 }
4768 }
4769
Greg Clayton81c22f62011-10-19 18:09:39 +00004770 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004771 this,
4772 type_name_const_str,
4773 byte_size,
4774 NULL,
4775 encoding_uid,
4776 encoding_data_type,
4777 &decl,
4778 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004779 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004780
Greg Clayton594e5ed2010-09-27 21:07:38 +00004781 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004782
4783// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4784// if (encoding_type != NULL)
4785// {
4786// if (encoding_type != DIE_IS_BEING_PARSED)
4787// type_sp->SetEncodingType(encoding_type);
4788// else
4789// m_indirect_fixups.push_back(type_sp.get());
4790// }
4791 }
4792 break;
4793
4794 case DW_TAG_structure_type:
4795 case DW_TAG_union_type:
4796 case DW_TAG_class_type:
4797 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004798 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004799 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004800
Greg Clayton9e409562010-07-28 02:04:09 +00004801 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004802 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004803 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004804 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004805 if (num_attributes > 0)
4806 {
4807 uint32_t i;
4808 for (i=0; i<num_attributes; ++i)
4809 {
4810 attr = attributes.AttributeAtIndex(i);
4811 DWARFFormValue form_value;
4812 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4813 {
4814 switch (attr)
4815 {
Greg Clayton9e409562010-07-28 02:04:09 +00004816 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00004817 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4818 {
4819 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4820 // point to the compile unit file, so we clear this invalid value
4821 // so that we can still unique types efficiently.
4822 decl.SetFile(FileSpec ("<invalid>", false));
4823 }
4824 else
4825 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00004826 break;
4827
4828 case DW_AT_decl_line:
4829 decl.SetLine(form_value.Unsigned());
4830 break;
4831
4832 case DW_AT_decl_column:
4833 decl.SetColumn(form_value.Unsigned());
4834 break;
4835
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004836 case DW_AT_name:
4837 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004838 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004839 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004840
4841 case DW_AT_byte_size:
4842 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004843 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004844 break;
4845
4846 case DW_AT_accessibility:
4847 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4848 break;
4849
4850 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004851 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004852 break;
4853
4854 case DW_AT_APPLE_runtime_class:
4855 class_language = (LanguageType)form_value.Signed();
4856 break;
4857
Greg Clayton18774842011-11-29 23:40:34 +00004858 case DW_AT_APPLE_objc_complete_type:
4859 is_complete_objc_class = form_value.Signed();
4860 break;
4861
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004862 case DW_AT_allocated:
4863 case DW_AT_associated:
4864 case DW_AT_data_location:
4865 case DW_AT_description:
4866 case DW_AT_start_scope:
4867 case DW_AT_visibility:
4868 default:
4869 case DW_AT_sibling:
4870 break;
4871 }
4872 }
4873 }
4874 }
4875
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004876 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00004877
Greg Clayton123edca2012-03-02 00:07:15 +00004878 // Only try and unique the type if it has a name.
4879 if (type_name_const_str &&
4880 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00004881 this,
4882 dwarf_cu,
4883 die,
4884 decl,
4885 byte_size_valid ? byte_size : -1,
4886 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004887 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004888 // We have already parsed this type or from another
4889 // compile unit. GCC loves to use the "one definition
4890 // rule" which can result in multiple definitions
4891 // of the same class over and over in each compile
4892 // unit.
4893 type_sp = unique_ast_entry.m_type_sp;
4894 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00004895 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004896 m_die_to_type[die] = type_sp.get();
4897 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004898 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004899 }
4900
Greg Clayton81c22f62011-10-19 18:09:39 +00004901 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 +00004902
4903 int tag_decl_kind = -1;
4904 AccessType default_accessibility = eAccessNone;
4905 if (tag == DW_TAG_structure_type)
4906 {
4907 tag_decl_kind = clang::TTK_Struct;
4908 default_accessibility = eAccessPublic;
4909 }
4910 else if (tag == DW_TAG_union_type)
4911 {
4912 tag_decl_kind = clang::TTK_Union;
4913 default_accessibility = eAccessPublic;
4914 }
4915 else if (tag == DW_TAG_class_type)
4916 {
4917 tag_decl_kind = clang::TTK_Class;
4918 default_accessibility = eAccessPrivate;
4919 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00004920
4921 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4922 die->HasChildren() == false &&
4923 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4924 {
4925 // Work around an issue with clang at the moment where
4926 // forward declarations for objective C classes are emitted
4927 // as:
4928 // DW_TAG_structure_type [2]
4929 // DW_AT_name( "ForwardObjcClass" )
4930 // DW_AT_byte_size( 0x00 )
4931 // DW_AT_decl_file( "..." )
4932 // DW_AT_decl_line( 1 )
4933 //
4934 // Note that there is no DW_AT_declaration and there are
4935 // no children, and the byte size is zero.
4936 is_forward_declaration = true;
4937 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004938
Greg Clayton18774842011-11-29 23:40:34 +00004939 if (class_language == eLanguageTypeObjC)
4940 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004941 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004942 {
4943 // We have a valid eSymbolTypeObjCClass class symbol whose
4944 // name matches the current objective C class that we
4945 // are trying to find and this DIE isn't the complete
4946 // definition (we checked is_complete_objc_class above and
4947 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00004948 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004949
Greg Clayton901c5ca2011-12-03 04:40:03 +00004950 if (!type_sp && m_debug_map_symfile)
4951 {
4952 // We weren't able to find a full declaration in
4953 // this DWARF, see if we have a declaration anywhere
4954 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00004955 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004956 }
4957
4958 if (type_sp)
4959 {
4960 if (log)
4961 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004962 GetObjectFile()->GetModule()->LogMessage (log.get(),
4963 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4964 this,
4965 die->GetOffset(),
4966 DW_TAG_value_to_name(tag),
4967 type_name_cstr,
4968 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004969 }
4970
4971 // We found a real definition for this type elsewhere
4972 // so lets use it and cache the fact that we found
4973 // a complete type for this die
4974 m_die_to_type[die] = type_sp.get();
4975 return type_sp;
4976 }
4977 }
4978 }
4979
4980
4981 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004982 {
4983 // We have a forward declaration to a type and we need
4984 // to try and find a full declaration. We look in the
4985 // current type index just in case we have a forward
4986 // declaration followed by an actual declarations in the
4987 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00004988 if (log)
4989 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004990 GetObjectFile()->GetModule()->LogMessage (log.get(),
4991 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
4992 this,
4993 die->GetOffset(),
4994 DW_TAG_value_to_name(tag),
4995 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00004996 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004997
4998 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4999
5000 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00005001 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005002 // We weren't able to find a full declaration in
5003 // this DWARF, see if we have a declaration anywhere
5004 // else...
5005 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00005006 }
5007
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005008 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005009 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005010 if (log)
5011 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005012 GetObjectFile()->GetModule()->LogMessage (log.get(),
5013 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5014 this,
5015 die->GetOffset(),
5016 DW_TAG_value_to_name(tag),
5017 type_name_cstr,
5018 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005019 }
5020
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005021 // We found a real definition for this type elsewhere
5022 // so lets use it and cache the fact that we found
5023 // a complete type for this die
5024 m_die_to_type[die] = type_sp.get();
5025 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005026 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005027 }
5028 assert (tag_decl_kind != -1);
5029 bool clang_type_was_created = false;
5030 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5031 if (clang_type == NULL)
5032 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005033 const DWARFDebugInfoEntry *decl_ctx_die;
5034
5035 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005036 if (accessibility == eAccessNone && decl_ctx)
5037 {
5038 // Check the decl context that contains this class/struct/union.
5039 // If it is a class we must give it an accessability.
5040 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5041 if (DeclKindIsCXXClass (containing_decl_kind))
5042 accessibility = default_accessibility;
5043 }
5044
Greg Claytonf0705c82011-10-22 03:33:13 +00005045 if (type_name_cstr && strchr (type_name_cstr, '<'))
5046 {
5047 ClangASTContext::TemplateParameterInfos template_param_infos;
5048 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5049 {
5050 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005051 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005052 type_name_cstr,
5053 tag_decl_kind,
5054 template_param_infos);
5055
5056 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5057 class_template_decl,
5058 tag_decl_kind,
5059 template_param_infos);
5060 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5061 clang_type_was_created = true;
5062 }
5063 }
5064
5065 if (!clang_type_was_created)
5066 {
5067 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005068 clang_type = ast.CreateRecordType (decl_ctx,
5069 accessibility,
5070 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005071 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00005072 class_language);
5073 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005074 }
5075
5076 // Store a forward declaration to this class type in case any
5077 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005078 // types for function prototypes.
5079 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005080 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005081 this,
5082 type_name_const_str,
5083 byte_size,
5084 NULL,
5085 LLDB_INVALID_UID,
5086 Type::eEncodingIsUID,
5087 &decl,
5088 clang_type,
5089 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005090
5091 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005092
5093
5094 // Add our type to the unique type map so we don't
5095 // end up creating many copies of the same type over
5096 // and over in the ASTContext for our module
5097 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005098 unique_ast_entry.m_symfile = this;
5099 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005100 unique_ast_entry.m_die = die;
5101 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005102 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005103 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5104 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005105
Sean Callanan12014a02011-12-08 23:45:45 +00005106 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005107 {
5108 // Always start the definition for a class type so that
5109 // if the class has child classes or types that require
5110 // the class to be created for use as their decl contexts
5111 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005112 if (die->HasChildren() == false)
5113 {
5114 // No children for this struct/union/class, lets finish it
5115 ast.StartTagDeclarationDefinition (clang_type);
5116 ast.CompleteTagDeclarationDefinition (clang_type);
5117 }
5118 else if (clang_type_was_created)
5119 {
Greg Clayton219cf312012-03-30 00:51:13 +00005120 // Start the definition if the class is not objective C since
5121 // the underlying decls respond to isCompleteDefinition(). Objective
5122 // C decls dont' respond to isCompleteDefinition() so we can't
5123 // start the declaration definition right away. For C++ classs/union/structs
5124 // we want to start the definition in case the class is needed as the
5125 // declaration context for a contained class or type without the need
5126 // to complete that type..
5127
5128 if (class_language != eLanguageTypeObjC)
5129 ast.StartTagDeclarationDefinition (clang_type);
5130
Sean Callanan12014a02011-12-08 23:45:45 +00005131 // Leave this as a forward declaration until we need
5132 // to know the details of the type. lldb_private::Type
5133 // will automatically call the SymbolFile virtual function
5134 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5135 // When the definition needs to be defined.
5136 m_forward_decl_die_to_clang_type[die] = clang_type;
5137 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5138 ClangASTContext::SetHasExternalStorage (clang_type, true);
5139 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005140 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005141
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005142 }
5143 break;
5144
5145 case DW_TAG_enumeration_type:
5146 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005147 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005148 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005149
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005150 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005151
Greg Claytond88d7592010-09-15 08:33:30 +00005152 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005153 if (num_attributes > 0)
5154 {
5155 uint32_t i;
5156
5157 for (i=0; i<num_attributes; ++i)
5158 {
5159 attr = attributes.AttributeAtIndex(i);
5160 DWARFFormValue form_value;
5161 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5162 {
5163 switch (attr)
5164 {
Greg Clayton7a345282010-11-09 23:46:37 +00005165 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5166 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5167 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005168 case DW_AT_name:
5169 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005170 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005171 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005172 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005173 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00005174 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5175 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005176 case DW_AT_allocated:
5177 case DW_AT_associated:
5178 case DW_AT_bit_stride:
5179 case DW_AT_byte_stride:
5180 case DW_AT_data_location:
5181 case DW_AT_description:
5182 case DW_AT_start_scope:
5183 case DW_AT_visibility:
5184 case DW_AT_specification:
5185 case DW_AT_abstract_origin:
5186 case DW_AT_sibling:
5187 break;
5188 }
5189 }
5190 }
5191
Greg Clayton81c22f62011-10-19 18:09:39 +00005192 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 +00005193
Greg Clayton1be10fc2010-09-29 01:12:09 +00005194 clang_type_t enumerator_clang_type = NULL;
5195 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5196 if (clang_type == NULL)
5197 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005198 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5199 DW_ATE_signed,
5200 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005201 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005202 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005203 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005204 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005205 }
5206 else
5207 {
5208 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5209 assert (enumerator_clang_type != NULL);
5210 }
5211
Greg Claytona2721472011-06-25 00:44:06 +00005212 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5213
Greg Clayton81c22f62011-10-19 18:09:39 +00005214 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005215 this,
5216 type_name_const_str,
5217 byte_size,
5218 NULL,
5219 encoding_uid,
5220 Type::eEncodingIsUID,
5221 &decl,
5222 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005223 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005224
Greg Clayton6beaaa62011-01-17 03:46:26 +00005225 ast.StartTagDeclarationDefinition (clang_type);
5226 if (die->HasChildren())
5227 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005228 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5229 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005230 }
5231 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005232 }
5233 }
5234 break;
5235
Jim Inghamb0be4422010-08-12 01:20:14 +00005236 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005237 case DW_TAG_subprogram:
5238 case DW_TAG_subroutine_type:
5239 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005240 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005241 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005242
5243 const char *mangled = NULL;
5244 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005245 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005246 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005247 bool is_static = false;
5248 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005249 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005250 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005251 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5252 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005253
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005254 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005255 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005256
5257
Greg Claytond88d7592010-09-15 08:33:30 +00005258 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005259 if (num_attributes > 0)
5260 {
5261 uint32_t i;
5262 for (i=0; i<num_attributes; ++i)
5263 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005264 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005265 DWARFFormValue form_value;
5266 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5267 {
5268 switch (attr)
5269 {
5270 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5271 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5272 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5273 case DW_AT_name:
5274 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005275 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005276 break;
5277
5278 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5279 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005280 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005281 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005282 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5283 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005284 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005285 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5286
Greg Claytonf51de672010-10-01 02:31:07 +00005287
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005288 case DW_AT_external:
5289 if (form_value.Unsigned())
5290 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005291 if (storage == clang::SC_None)
5292 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005293 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005294 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005295 }
5296 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005297
Greg Clayton72da3972011-08-16 18:40:23 +00005298 case DW_AT_specification:
5299 specification_die_offset = form_value.Reference(dwarf_cu);
5300 break;
5301
5302 case DW_AT_abstract_origin:
5303 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5304 break;
5305
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005306 case DW_AT_allocated:
5307 case DW_AT_associated:
5308 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005309 case DW_AT_calling_convention:
5310 case DW_AT_data_location:
5311 case DW_AT_elemental:
5312 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005313 case DW_AT_frame_base:
5314 case DW_AT_high_pc:
5315 case DW_AT_low_pc:
5316 case DW_AT_object_pointer:
5317 case DW_AT_prototyped:
5318 case DW_AT_pure:
5319 case DW_AT_ranges:
5320 case DW_AT_recursive:
5321 case DW_AT_return_addr:
5322 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005323 case DW_AT_start_scope:
5324 case DW_AT_static_link:
5325 case DW_AT_trampoline:
5326 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005327 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005328 case DW_AT_description:
5329 case DW_AT_sibling:
5330 break;
5331 }
5332 }
5333 }
Greg Clayton24739922010-10-13 03:15:28 +00005334 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005335
Greg Clayton81c22f62011-10-19 18:09:39 +00005336 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 +00005337
Greg Clayton24739922010-10-13 03:15:28 +00005338 clang_type_t return_clang_type = NULL;
5339 Type *func_type = NULL;
5340
5341 if (type_die_offset != DW_INVALID_OFFSET)
5342 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005343
Greg Clayton24739922010-10-13 03:15:28 +00005344 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005345 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005346 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005347 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005348
Greg Claytonf51de672010-10-01 02:31:07 +00005349
Greg Clayton24739922010-10-13 03:15:28 +00005350 std::vector<clang_type_t> function_param_types;
5351 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005352
Greg Clayton24739922010-10-13 03:15:28 +00005353 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005354
Greg Claytoncb5860a2011-10-13 23:49:28 +00005355 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5356 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005357 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5358
Greg Claytonf0705c82011-10-22 03:33:13 +00005359 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005360 // Start off static. This will be set to false in ParseChildParameters(...)
5361 // if we find a "this" paramters as the first parameter
5362 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005363 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005364 ClangASTContext::TemplateParameterInfos template_param_infos;
5365
Greg Clayton24739922010-10-13 03:15:28 +00005366 if (die->HasChildren())
5367 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005368 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005369 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005370 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005371 dwarf_cu,
5372 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005373 skip_artificial,
5374 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005375 type_list,
5376 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005377 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005378 type_quals,
5379 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005380 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005381
Greg Clayton24739922010-10-13 03:15:28 +00005382 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005383 clang_type = ast.CreateFunctionType (return_clang_type,
5384 &function_param_types[0],
5385 function_param_types.size(),
5386 is_variadic,
5387 type_quals);
5388
Greg Clayton24739922010-10-13 03:15:28 +00005389 if (type_name_cstr)
5390 {
5391 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005392 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005393 {
Greg Clayton7c810422012-01-18 23:40:49 +00005394 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005395 ConstString class_name_no_category;
5396 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005397 {
Greg Claytone42ae842012-01-19 03:24:53 +00005398 // Use the class name with no category if there is one
5399 if (class_name_no_category)
5400 class_name = class_name_no_category;
5401
Greg Clayton24739922010-10-13 03:15:28 +00005402 SymbolContext empty_sc;
5403 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005404 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005405 {
Greg Clayton24739922010-10-13 03:15:28 +00005406 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005407 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005408
5409 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005410 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005411 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5412 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5413 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005414 }
Greg Clayton24739922010-10-13 03:15:28 +00005415 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005416
Greg Clayton24739922010-10-13 03:15:28 +00005417 if (class_opaque_type)
5418 {
5419 // If accessibility isn't set to anything valid, assume public for
5420 // now...
5421 if (accessibility == eAccessNone)
5422 accessibility = eAccessPublic;
5423
5424 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005425 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5426 type_name_cstr,
5427 clang_type,
5428 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005429 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005430 type_handled = objc_method_decl != NULL;
5431 }
5432 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005433 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005434 {
5435 // Look at the parent of this DIE and see if is is
5436 // a class or struct and see if this is actually a
5437 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005438 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005439 if (class_type)
5440 {
Greg Clayton72da3972011-08-16 18:40:23 +00005441 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005442 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005443 // We have a specification which we are going to base our function
5444 // prototype off of, so we need this type to be completed so that the
5445 // m_die_to_decl_ctx for the method in the specification has a valid
5446 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005447 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005448 // If we have a specification, then the function type should have been
5449 // made with the specification and not with this die.
5450 DWARFCompileUnitSP spec_cu_sp;
5451 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005452 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005453 if (spec_clang_decl_ctx)
5454 {
5455 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5456 }
5457 else
Jim Inghamc1663042011-09-29 22:12:35 +00005458 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005459 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5460 MakeUserID(die->GetOffset()),
5461 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005462 }
Greg Clayton72da3972011-08-16 18:40:23 +00005463 type_handled = true;
5464 }
5465 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5466 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005467 // We have a specification which we are going to base our function
5468 // prototype off of, so we need this type to be completed so that the
5469 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5470 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005471 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005472
Greg Clayton72da3972011-08-16 18:40:23 +00005473 DWARFCompileUnitSP abs_cu_sp;
5474 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005475 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005476 if (abs_clang_decl_ctx)
5477 {
5478 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5479 }
5480 else
Jim Inghamc1663042011-09-29 22:12:35 +00005481 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005482 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5483 MakeUserID(die->GetOffset()),
5484 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005485 }
Greg Clayton72da3972011-08-16 18:40:23 +00005486 type_handled = true;
5487 }
5488 else
5489 {
5490 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5491 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005492 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005493 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005494 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005495 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5496 // in the DWARF for C++ methods... Default to public for now...
5497 if (accessibility == eAccessNone)
5498 accessibility = eAccessPublic;
5499
5500 if (!is_static && !die->HasChildren())
5501 {
5502 // We have a C++ member function with no children (this pointer!)
5503 // and clang will get mad if we try and make a function that isn't
5504 // well formed in the DWARF, so we will just skip it...
5505 type_handled = true;
5506 }
5507 else
5508 {
5509 clang::CXXMethodDecl *cxx_method_decl;
5510 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005511 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 +00005512 type_name_cstr,
5513 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005514 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005515 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5516 m_obj_file->GetFileSpec().GetFilename().GetCString());
5517
Sean Callananc1b732d2011-11-01 18:07:13 +00005518 const bool is_attr_used = false;
5519
Greg Clayton20568dd2011-10-13 23:13:20 +00005520 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5521 type_name_cstr,
5522 clang_type,
5523 accessibility,
5524 is_virtual,
5525 is_static,
5526 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005527 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005528 is_attr_used,
5529 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005530 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5531
Greg Claytonf49e65a2011-11-10 18:31:53 +00005532 Host::SetCrashDescription (NULL);
5533
Greg Clayton20568dd2011-10-13 23:13:20 +00005534 type_handled = cxx_method_decl != NULL;
5535 }
Greg Clayton72da3972011-08-16 18:40:23 +00005536 }
5537 else
5538 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005539 // We were asked to parse the type for a method in a class, yet the
5540 // class hasn't been asked to complete itself through the
5541 // clang::ExternalASTSource protocol, so we need to just have the
5542 // class complete itself and do things the right way, then our
5543 // DIE should then have an entry in the m_die_to_type map. First
5544 // we need to modify the m_die_to_type so it doesn't think we are
5545 // trying to parse this DIE anymore...
5546 m_die_to_type[die] = NULL;
5547
5548 // Now we get the full type to force our class type to complete itself
5549 // using the clang::ExternalASTSource protocol which will parse all
5550 // base classes and all methods (including the method for this DIE).
5551 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005552
Greg Clayton20568dd2011-10-13 23:13:20 +00005553 // The type for this DIE should have been filled in the function call above
5554 type_ptr = m_die_to_type[die];
5555 if (type_ptr)
5556 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005557 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00005558 break;
5559 }
Greg Clayton72da3972011-08-16 18:40:23 +00005560 }
Greg Clayton931180e2011-01-27 06:44:37 +00005561 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005562 }
5563 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005564 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005565 }
Greg Clayton24739922010-10-13 03:15:28 +00005566
5567 if (!type_handled)
5568 {
5569 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00005570 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5571 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005572 clang_type,
5573 storage,
5574 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005575
5576// if (template_param_infos.GetSize() > 0)
5577// {
5578// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5579// function_decl,
5580// type_name_cstr,
5581// template_param_infos);
5582//
5583// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5584// func_template_decl,
5585// template_param_infos);
5586// }
Greg Clayton24739922010-10-13 03:15:28 +00005587 // Add the decl to our DIE to decl context map
5588 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00005589 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00005590 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005591 ast.SetFunctionParameters (function_decl,
5592 &function_param_decls.front(),
5593 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00005594 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005595 }
Greg Clayton81c22f62011-10-19 18:09:39 +00005596 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005597 this,
5598 type_name_const_str,
5599 0,
5600 NULL,
5601 LLDB_INVALID_UID,
5602 Type::eEncodingIsUID,
5603 &decl,
5604 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005605 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00005606 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005607 }
5608 break;
5609
5610 case DW_TAG_array_type:
5611 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005612 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005613 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005614
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005615 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005616 int64_t first_index = 0;
5617 uint32_t byte_stride = 0;
5618 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00005619 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005620
5621 if (num_attributes > 0)
5622 {
5623 uint32_t i;
5624 for (i=0; i<num_attributes; ++i)
5625 {
5626 attr = attributes.AttributeAtIndex(i);
5627 DWARFFormValue form_value;
5628 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5629 {
5630 switch (attr)
5631 {
5632 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5633 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5634 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5635 case DW_AT_name:
5636 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005637 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005638 break;
5639
5640 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005641 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005642 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5643 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005644 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005645 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005646 case DW_AT_allocated:
5647 case DW_AT_associated:
5648 case DW_AT_data_location:
5649 case DW_AT_description:
5650 case DW_AT_ordering:
5651 case DW_AT_start_scope:
5652 case DW_AT_visibility:
5653 case DW_AT_specification:
5654 case DW_AT_abstract_origin:
5655 case DW_AT_sibling:
5656 break;
5657 }
5658 }
5659 }
5660
Greg Clayton81c22f62011-10-19 18:09:39 +00005661 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 +00005662
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005663 Type *element_type = ResolveTypeUID(type_die_offset);
5664
5665 if (element_type)
5666 {
5667 std::vector<uint64_t> element_orders;
5668 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005669 // We have an array that claims to have no members, lets give it at least one member...
5670 if (element_orders.empty())
5671 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005672 if (byte_stride == 0 && bit_stride == 0)
5673 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00005674 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005675 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5676 uint64_t num_elements = 0;
5677 std::vector<uint64_t>::const_reverse_iterator pos;
5678 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5679 for (pos = element_orders.rbegin(); pos != end; ++pos)
5680 {
5681 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005682 clang_type = ast.CreateArrayType (array_element_type,
5683 num_elements,
5684 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005685 array_element_type = clang_type;
5686 array_element_bit_stride = array_element_bit_stride * num_elements;
5687 }
5688 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005689 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005690 this,
5691 empty_name,
5692 array_element_bit_stride / 8,
5693 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005694 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005695 Type::eEncodingIsUID,
5696 &decl,
5697 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005698 Type::eResolveStateFull));
5699 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005700 }
5701 }
5702 }
5703 break;
5704
Greg Clayton9b81a312010-06-12 01:20:30 +00005705 case DW_TAG_ptr_to_member_type:
5706 {
5707 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5708 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5709
Greg Claytond88d7592010-09-15 08:33:30 +00005710 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005711
5712 if (num_attributes > 0) {
5713 uint32_t i;
5714 for (i=0; i<num_attributes; ++i)
5715 {
5716 attr = attributes.AttributeAtIndex(i);
5717 DWARFFormValue form_value;
5718 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5719 {
5720 switch (attr)
5721 {
5722 case DW_AT_type:
5723 type_die_offset = form_value.Reference(dwarf_cu); break;
5724 case DW_AT_containing_type:
5725 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5726 }
5727 }
5728 }
5729
5730 Type *pointee_type = ResolveTypeUID(type_die_offset);
5731 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5732
Greg Clayton526e5af2010-11-13 03:52:47 +00005733 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5734 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005735
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005736 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5737 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005738
Greg Clayton526e5af2010-11-13 03:52:47 +00005739 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5740 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005741
Greg Clayton81c22f62011-10-19 18:09:39 +00005742 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005743 this,
5744 type_name_const_str,
5745 byte_size,
5746 NULL,
5747 LLDB_INVALID_UID,
5748 Type::eEncodingIsUID,
5749 NULL,
5750 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005751 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005752 }
5753
5754 break;
5755 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005756 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005757 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005758 break;
5759 }
5760
5761 if (type_sp.get())
5762 {
5763 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5764 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5765
5766 SymbolContextScope * symbol_context_scope = NULL;
5767 if (sc_parent_tag == DW_TAG_compile_unit)
5768 {
5769 symbol_context_scope = sc.comp_unit;
5770 }
5771 else if (sc.function != NULL)
5772 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005773 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005774 if (symbol_context_scope == NULL)
5775 symbol_context_scope = sc.function;
5776 }
5777
5778 if (symbol_context_scope != NULL)
5779 {
5780 type_sp->SetSymbolContextScope(symbol_context_scope);
5781 }
5782
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005783 // We are ready to put this type into the uniqued list up at the module level
5784 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005785
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005786 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005787 }
5788 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005789 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005790 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005791 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005792 }
5793 }
5794 return type_sp;
5795}
5796
5797size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005798SymbolFileDWARF::ParseTypes
5799(
5800 const SymbolContext& sc,
5801 DWARFCompileUnit* dwarf_cu,
5802 const DWARFDebugInfoEntry *die,
5803 bool parse_siblings,
5804 bool parse_children
5805)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005806{
5807 size_t types_added = 0;
5808 while (die != NULL)
5809 {
5810 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005811 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005812 {
5813 if (type_is_new)
5814 ++types_added;
5815 }
5816
5817 if (parse_children && die->HasChildren())
5818 {
5819 if (die->Tag() == DW_TAG_subprogram)
5820 {
5821 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005822 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005823 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5824 }
5825 else
5826 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5827 }
5828
5829 if (parse_siblings)
5830 die = die->GetSibling();
5831 else
5832 die = NULL;
5833 }
5834 return types_added;
5835}
5836
5837
5838size_t
5839SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5840{
5841 assert(sc.comp_unit && sc.function);
5842 size_t functions_added = 0;
5843 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5844 if (dwarf_cu)
5845 {
5846 dw_offset_t function_die_offset = sc.function->GetID();
5847 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5848 if (function_die)
5849 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005850 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005851 }
5852 }
5853
5854 return functions_added;
5855}
5856
5857
5858size_t
5859SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5860{
5861 // At least a compile unit must be valid
5862 assert(sc.comp_unit);
5863 size_t types_added = 0;
5864 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5865 if (dwarf_cu)
5866 {
5867 if (sc.function)
5868 {
5869 dw_offset_t function_die_offset = sc.function->GetID();
5870 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5871 if (func_die && func_die->HasChildren())
5872 {
5873 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5874 }
5875 }
5876 else
5877 {
5878 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5879 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5880 {
5881 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5882 }
5883 }
5884 }
5885
5886 return types_added;
5887}
5888
5889size_t
5890SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5891{
5892 if (sc.comp_unit != NULL)
5893 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005894 DWARFDebugInfo* info = DebugInfo();
5895 if (info == NULL)
5896 return 0;
5897
5898 uint32_t cu_idx = UINT32_MAX;
5899 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005900
5901 if (dwarf_cu == NULL)
5902 return 0;
5903
5904 if (sc.function)
5905 {
5906 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00005907
5908 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 +00005909 if (func_lo_pc != DW_INVALID_ADDRESS)
5910 {
5911 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00005912
Greg Claytone38a5ed2012-01-05 03:57:59 +00005913 // Let all blocks know they have parse all their variables
5914 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5915 return num_variables;
5916 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005917 }
5918 else if (sc.comp_unit)
5919 {
5920 uint32_t vars_added = 0;
5921 VariableListSP variables (sc.comp_unit->GetVariableList(false));
5922
5923 if (variables.get() == NULL)
5924 {
5925 variables.reset(new VariableList());
5926 sc.comp_unit->SetVariableList(variables);
5927
Greg Claytond4a2b372011-09-12 23:21:58 +00005928 DWARFCompileUnit* match_dwarf_cu = NULL;
5929 const DWARFDebugInfoEntry* die = NULL;
5930 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00005931 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005932 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005933 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00005934 {
5935 DWARFMappedHash::DIEInfoArray hash_data_array;
5936 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5937 dwarf_cu->GetNextCompileUnitOffset(),
5938 hash_data_array))
5939 {
5940 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
5941 }
5942 }
Greg Clayton7f995132011-10-04 22:41:51 +00005943 }
5944 else
5945 {
5946 // Index if we already haven't to make sure the compile units
5947 // get indexed and make their global DIE index list
5948 if (!m_indexed)
5949 Index ();
5950
5951 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5952 dwarf_cu->GetNextCompileUnitOffset(),
5953 die_offsets);
5954 }
5955
5956 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00005957 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005958 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005959 DWARFDebugInfo* debug_info = DebugInfo();
5960 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005961 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005962 const dw_offset_t die_offset = die_offsets[i];
5963 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00005964 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00005965 {
Greg Clayton95d87902011-11-11 03:16:25 +00005966 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5967 if (var_sp)
5968 {
5969 variables->AddVariableIfUnique (var_sp);
5970 ++vars_added;
5971 }
Greg Claytond4a2b372011-09-12 23:21:58 +00005972 }
Greg Clayton95d87902011-11-11 03:16:25 +00005973 else
5974 {
5975 if (m_using_apple_tables)
5976 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005977 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 +00005978 }
5979 }
5980
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005981 }
5982 }
5983 }
5984 return vars_added;
5985 }
5986 }
5987 return 0;
5988}
5989
5990
5991VariableSP
5992SymbolFileDWARF::ParseVariableDIE
5993(
5994 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005995 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005996 const DWARFDebugInfoEntry *die,
5997 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005998)
5999{
6000
Greg Clayton83c5cd92010-11-14 22:13:40 +00006001 VariableSP var_sp (m_die_to_variable_sp[die]);
6002 if (var_sp)
6003 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006004
6005 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006006
6007 if ((tag == DW_TAG_variable) ||
6008 (tag == DW_TAG_constant) ||
6009 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006010 {
Greg Clayton7f995132011-10-04 22:41:51 +00006011 DWARFDebugInfoEntry::Attributes attributes;
6012 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6013 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006014 {
Greg Clayton7f995132011-10-04 22:41:51 +00006015 const char *name = NULL;
6016 const char *mangled = NULL;
6017 Declaration decl;
6018 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006019 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006020 DWARFExpression location;
6021 bool is_external = false;
6022 bool is_artificial = false;
6023 bool location_is_const_value_data = false;
6024 AccessType accessibility = eAccessNone;
6025
6026 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006027 {
Greg Clayton7f995132011-10-04 22:41:51 +00006028 dw_attr_t attr = attributes.AttributeAtIndex(i);
6029 DWARFFormValue form_value;
6030 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006031 {
Greg Clayton7f995132011-10-04 22:41:51 +00006032 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006033 {
Greg Clayton7f995132011-10-04 22:41:51 +00006034 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6035 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6036 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6037 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6038 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006039 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006040 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6041 case DW_AT_const_value:
6042 location_is_const_value_data = true;
6043 // Fall through...
6044 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006045 {
Greg Clayton7f995132011-10-04 22:41:51 +00006046 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006047 {
Greg Clayton7f995132011-10-04 22:41:51 +00006048 const DataExtractor& debug_info_data = get_debug_info_data();
6049
6050 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6051 uint32_t block_length = form_value.Unsigned();
6052 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6053 }
6054 else
6055 {
6056 const DataExtractor& debug_loc_data = get_debug_loc_data();
6057 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6058
6059 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6060 if (loc_list_length > 0)
6061 {
6062 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6063 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6064 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6065 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006066 }
6067 }
Greg Clayton7f995132011-10-04 22:41:51 +00006068 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006069
Greg Clayton7f995132011-10-04 22:41:51 +00006070 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6071 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6072 case DW_AT_declaration:
6073 case DW_AT_description:
6074 case DW_AT_endianity:
6075 case DW_AT_segment:
6076 case DW_AT_start_scope:
6077 case DW_AT_visibility:
6078 default:
6079 case DW_AT_abstract_origin:
6080 case DW_AT_sibling:
6081 case DW_AT_specification:
6082 break;
6083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006084 }
6085 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006086
Greg Clayton7f995132011-10-04 22:41:51 +00006087 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006088 {
Greg Clayton7f995132011-10-04 22:41:51 +00006089 ValueType scope = eValueTypeInvalid;
6090
6091 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6092 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006093 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006094
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006095 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6096 // or static variable, so we have to do a little digging by
6097 // looking at the location of a varaible to see if it contains
6098 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6099 // somewhere because clang likes to combine small global variables
6100 // into the same symbol and have locations like:
6101 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6102 // So if we don't have a DW_TAG_formal_parameter, we can look at
6103 // the location to see if it contains a DW_OP_addr opcode, and
6104 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006105 if (tag == DW_TAG_formal_parameter)
6106 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006107 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006108 {
Greg Clayton96c09682012-01-04 22:56:43 +00006109 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006110 // Check if the location has a DW_OP_addr with any address value...
6111 addr_t location_has_op_addr = false;
6112 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006113 {
6114 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6115 if (op_error)
6116 {
6117 StreamString strm;
6118 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006119 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 +00006120 }
6121 }
Greg Claytond1767f02011-12-08 02:13:16 +00006122
6123 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006124 {
Greg Claytond1767f02011-12-08 02:13:16 +00006125 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006126 {
Greg Claytond1767f02011-12-08 02:13:16 +00006127 scope = eValueTypeVariableGlobal;
6128
6129 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006130 {
Greg Claytond1767f02011-12-08 02:13:16 +00006131 // When leaving the DWARF in the .o files on darwin,
6132 // when we have a global variable that wasn't initialized,
6133 // the .o file might not have allocated a virtual
6134 // address for the global variable. In this case it will
6135 // have created a symbol for the global variable
6136 // that is undefined and external and the value will
6137 // be the byte size of the variable. When we do the
6138 // address map in SymbolFileDWARFDebugMap we rely on
6139 // having an address, we need to do some magic here
6140 // so we can get the correct address for our global
6141 // variable. The address for all of these entries
6142 // will be zero, and there will be an undefined symbol
6143 // in this object file, and the executable will have
6144 // a matching symbol with a good address. So here we
6145 // dig up the correct address and replace it in the
6146 // location for the variable, and set the variable's
6147 // symbol context scope to be that of the main executable
6148 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006149 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006150 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006151
Greg Claytond1767f02011-12-08 02:13:16 +00006152 // we have a possible uninitialized extern global
6153 Symtab *symtab = m_obj_file->GetSymtab();
6154 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006155 {
Greg Claytond1767f02011-12-08 02:13:16 +00006156 ConstString const_name(name);
6157 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6158 eSymbolTypeUndefined,
6159 Symtab::eDebugNo,
6160 Symtab::eVisibilityExtern);
6161
6162 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006163 {
Greg Claytond1767f02011-12-08 02:13:16 +00006164 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6165 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006166 {
Greg Claytond1767f02011-12-08 02:13:16 +00006167 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6168 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6169 eSymbolTypeData,
6170 Symtab::eDebugYes,
6171 Symtab::eVisibilityExtern);
6172 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006173 {
Greg Claytone7612132012-03-07 21:03:09 +00006174 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006175 {
Greg Claytone7612132012-03-07 21:03:09 +00006176 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006177 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006178 {
Greg Claytond1767f02011-12-08 02:13:16 +00006179 if (location.Update_DW_OP_addr (defined_addr))
6180 {
6181 symbol_context_scope = defined_symbol;
6182 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006183 }
6184 }
6185 }
6186 }
6187 }
6188 }
6189 }
6190 }
6191 }
Greg Claytond1767f02011-12-08 02:13:16 +00006192 else
6193 {
6194 scope = eValueTypeVariableStatic;
6195 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006196 }
6197 else
Greg Claytond1767f02011-12-08 02:13:16 +00006198 {
6199 scope = eValueTypeVariableLocal;
6200 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006201 }
Greg Clayton7f995132011-10-04 22:41:51 +00006202
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006203 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006204 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006205 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006206 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006207 case DW_TAG_subprogram:
6208 case DW_TAG_inlined_subroutine:
6209 case DW_TAG_lexical_block:
6210 if (sc.function)
6211 {
6212 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6213 if (symbol_context_scope == NULL)
6214 symbol_context_scope = sc.function;
6215 }
6216 break;
6217
6218 default:
6219 symbol_context_scope = sc.comp_unit;
6220 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006221 }
Greg Clayton7f995132011-10-04 22:41:51 +00006222 }
6223
Greg Clayton5cf58b92011-10-05 22:22:08 +00006224 if (symbol_context_scope)
6225 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006226 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6227 name,
6228 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006229 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006230 scope,
6231 symbol_context_scope,
6232 &decl,
6233 location,
6234 is_external,
6235 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006236
6237 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6238 }
6239 else
6240 {
6241 // Not ready to parse this variable yet. It might be a global
6242 // or static variable that is in a function scope and the function
6243 // in the symbol context wasn't filled in yet
6244 return var_sp;
6245 }
Greg Clayton7f995132011-10-04 22:41:51 +00006246 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006247 }
Greg Clayton7f995132011-10-04 22:41:51 +00006248 // Cache var_sp even if NULL (the variable was just a specification or
6249 // was missing vital information to be able to be displayed in the debugger
6250 // (missing location due to optimization, etc)) so we don't re-parse
6251 // this DIE over and over later...
6252 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006253 }
6254 return var_sp;
6255}
6256
Greg Claytonc662ec82011-06-17 22:10:16 +00006257
6258const DWARFDebugInfoEntry *
6259SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6260 dw_offset_t spec_block_die_offset,
6261 DWARFCompileUnit **result_die_cu_handle)
6262{
6263 // Give the concrete function die specified by "func_die_offset", find the
6264 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6265 // to "spec_block_die_offset"
6266 DWARFDebugInfo* info = DebugInfo();
6267
6268 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6269 if (die)
6270 {
6271 assert (*result_die_cu_handle);
6272 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6273 }
6274 return NULL;
6275}
6276
6277
6278const DWARFDebugInfoEntry *
6279SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6280 const DWARFDebugInfoEntry *die,
6281 dw_offset_t spec_block_die_offset,
6282 DWARFCompileUnit **result_die_cu_handle)
6283{
6284 if (die)
6285 {
6286 switch (die->Tag())
6287 {
6288 case DW_TAG_subprogram:
6289 case DW_TAG_inlined_subroutine:
6290 case DW_TAG_lexical_block:
6291 {
6292 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6293 {
6294 *result_die_cu_handle = dwarf_cu;
6295 return die;
6296 }
6297
6298 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6299 {
6300 *result_die_cu_handle = dwarf_cu;
6301 return die;
6302 }
6303 }
6304 break;
6305 }
6306
6307 // Give the concrete function die specified by "func_die_offset", find the
6308 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6309 // to "spec_block_die_offset"
6310 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6311 {
6312 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6313 child_die,
6314 spec_block_die_offset,
6315 result_die_cu_handle);
6316 if (result_die)
6317 return result_die;
6318 }
6319 }
6320
6321 *result_die_cu_handle = NULL;
6322 return NULL;
6323}
6324
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006325size_t
6326SymbolFileDWARF::ParseVariables
6327(
6328 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006329 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006330 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006331 const DWARFDebugInfoEntry *orig_die,
6332 bool parse_siblings,
6333 bool parse_children,
6334 VariableList* cc_variable_list
6335)
6336{
6337 if (orig_die == NULL)
6338 return 0;
6339
Greg Claytonc662ec82011-06-17 22:10:16 +00006340 VariableListSP variable_list_sp;
6341
6342 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006343 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006344 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006345 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006346 dw_tag_t tag = die->Tag();
6347
6348 // Check to see if we have already parsed this variable or constant?
6349 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006350 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006351 if (cc_variable_list)
6352 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006353 }
6354 else
6355 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006356 // We haven't already parsed it, lets do that now.
6357 if ((tag == DW_TAG_variable) ||
6358 (tag == DW_TAG_constant) ||
6359 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006360 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006361 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006362 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006363 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6364 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6365 switch (parent_tag)
6366 {
6367 case DW_TAG_compile_unit:
6368 if (sc.comp_unit != NULL)
6369 {
6370 variable_list_sp = sc.comp_unit->GetVariableList(false);
6371 if (variable_list_sp.get() == NULL)
6372 {
6373 variable_list_sp.reset(new VariableList());
6374 sc.comp_unit->SetVariableList(variable_list_sp);
6375 }
6376 }
6377 else
6378 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006379 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6380 MakeUserID(sc_parent_die->GetOffset()),
6381 DW_TAG_value_to_name (parent_tag),
6382 MakeUserID(orig_die->GetOffset()),
6383 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006384 }
6385 break;
6386
6387 case DW_TAG_subprogram:
6388 case DW_TAG_inlined_subroutine:
6389 case DW_TAG_lexical_block:
6390 if (sc.function != NULL)
6391 {
6392 // Check to see if we already have parsed the variables for the given scope
6393
Greg Clayton81c22f62011-10-19 18:09:39 +00006394 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006395 if (block == NULL)
6396 {
6397 // This must be a specification or abstract origin with
6398 // a concrete block couterpart in the current function. We need
6399 // to find the concrete block so we can correctly add the
6400 // variable to it
6401 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6402 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6403 sc_parent_die->GetOffset(),
6404 &concrete_block_die_cu);
6405 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006406 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006407 }
6408
6409 if (block != NULL)
6410 {
6411 const bool can_create = false;
6412 variable_list_sp = block->GetBlockVariableList (can_create);
6413 if (variable_list_sp.get() == NULL)
6414 {
6415 variable_list_sp.reset(new VariableList());
6416 block->SetVariableList(variable_list_sp);
6417 }
6418 }
6419 }
6420 break;
6421
6422 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006423 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6424 MakeUserID(orig_die->GetOffset()),
6425 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006426 break;
6427 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006428 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006429
6430 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006431 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006432 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6433 if (var_sp)
6434 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006435 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006436 if (cc_variable_list)
6437 cc_variable_list->AddVariableIfUnique (var_sp);
6438 ++vars_added;
6439 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006440 }
6441 }
6442 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006443
6444 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6445
6446 if (!skip_children && parse_children && die->HasChildren())
6447 {
6448 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6449 }
6450
6451 if (parse_siblings)
6452 die = die->GetSibling();
6453 else
6454 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006455 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006456 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006457}
6458
6459//------------------------------------------------------------------
6460// PluginInterface protocol
6461//------------------------------------------------------------------
6462const char *
6463SymbolFileDWARF::GetPluginName()
6464{
6465 return "SymbolFileDWARF";
6466}
6467
6468const char *
6469SymbolFileDWARF::GetShortPluginName()
6470{
6471 return GetPluginNameStatic();
6472}
6473
6474uint32_t
6475SymbolFileDWARF::GetPluginVersion()
6476{
6477 return 1;
6478}
6479
6480void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006481SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6482{
6483 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6484 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6485 if (clang_type)
6486 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6487}
6488
6489void
6490SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6491{
6492 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6493 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6494 if (clang_type)
6495 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6496}
6497
Greg Claytona2721472011-06-25 00:44:06 +00006498void
Sean Callanancc427fa2011-07-30 02:42:06 +00006499SymbolFileDWARF::DumpIndexes ()
6500{
6501 StreamFile s(stdout, false);
6502
6503 s.Printf ("DWARF index for (%s) '%s/%s':",
6504 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6505 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6506 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6507 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6508 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6509 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6510 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6511 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6512 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6513 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6514 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6515}
6516
6517void
6518SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6519 const char *name,
6520 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006521{
Sean Callanancc427fa2011-07-30 02:42:06 +00006522 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00006523
6524 if (iter == m_decl_ctx_to_die.end())
6525 return;
6526
Greg Claytoncb5860a2011-10-13 23:49:28 +00006527 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00006528 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006529 const DWARFDebugInfoEntry *context_die = *pos;
6530
6531 if (!results)
6532 return;
6533
6534 DWARFDebugInfo* info = DebugInfo();
6535
6536 DIEArray die_offsets;
6537
6538 DWARFCompileUnit* dwarf_cu = NULL;
6539 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00006540
6541 if (m_using_apple_tables)
6542 {
6543 if (m_apple_types_ap.get())
6544 m_apple_types_ap->FindByName (name, die_offsets);
6545 }
6546 else
6547 {
6548 if (!m_indexed)
6549 Index ();
6550
6551 m_type_index.Find (ConstString(name), die_offsets);
6552 }
6553
Greg Clayton220a0072011-12-09 08:48:30 +00006554 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006555
6556 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00006557 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006558 for (size_t i = 0; i < num_matches; ++i)
6559 {
6560 const dw_offset_t die_offset = die_offsets[i];
6561 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00006562
Greg Claytoncb5860a2011-10-13 23:49:28 +00006563 if (die->GetParent() != context_die)
6564 continue;
6565
6566 Type *matching_type = ResolveType (dwarf_cu, die);
6567
Greg Clayton42ce2f32011-12-12 21:50:19 +00006568 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006569 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6570
6571 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6572 {
6573 clang::TagDecl *tag_decl = tag_type->getDecl();
6574 results->push_back(tag_decl);
6575 }
6576 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6577 {
6578 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6579 results->push_back(typedef_decl);
6580 }
Greg Claytona2721472011-06-25 00:44:06 +00006581 }
6582 }
6583 }
6584}
6585
6586void
6587SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00006588 const clang::DeclContext *decl_context,
6589 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00006590 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6591{
Greg Clayton85ae2e12011-10-18 23:36:41 +00006592
6593 switch (decl_context->getDeclKind())
6594 {
6595 case clang::Decl::Namespace:
6596 case clang::Decl::TranslationUnit:
6597 {
6598 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6599 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6600 }
6601 break;
6602 default:
6603 break;
6604 }
Greg Claytona2721472011-06-25 00:44:06 +00006605}
Greg Claytoncaab74e2012-01-28 00:48:57 +00006606
6607bool
6608SymbolFileDWARF::LayoutRecordType (void *baton,
6609 const clang::RecordDecl *record_decl,
6610 uint64_t &size,
6611 uint64_t &alignment,
6612 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6613 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6614 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6615{
6616 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6617 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6618}
6619
6620
6621bool
6622SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6623 uint64_t &bit_size,
6624 uint64_t &alignment,
6625 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6626 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6627 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6628{
6629 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6630 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6631 bool success = false;
6632 base_offsets.clear();
6633 vbase_offsets.clear();
6634 if (pos != m_record_decl_to_layout_map.end())
6635 {
6636 bit_size = pos->second.bit_size;
6637 alignment = pos->second.alignment;
6638 field_offsets.swap(pos->second.field_offsets);
6639 m_record_decl_to_layout_map.erase(pos);
6640 success = true;
6641 }
6642 else
6643 {
6644 bit_size = 0;
6645 alignment = 0;
6646 field_offsets.clear();
6647 }
6648
6649 if (log)
6650 GetObjectFile()->GetModule()->LogMessage (log.get(),
6651 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6652 record_decl,
6653 bit_size,
6654 alignment,
6655 (uint32_t)field_offsets.size(),
6656 (uint32_t)base_offsets.size(),
6657 (uint32_t)vbase_offsets.size(),
6658 success);
6659 return success;
6660}
6661
6662
6663