blob: 4fb4d119232d7c38d89c8545b7c612cb923ba843 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
129 log_strm.Printf("DIEStack[%zu]:\n", n);
130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
136 log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n",
137 i,
138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
232 if (m_debug_map_symfile)
233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton450e3f32010-10-12 02:24:53 +0000266 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000267 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000269 m_data_debug_abbrev (),
270 m_data_debug_aranges (),
271 m_data_debug_frame (),
272 m_data_debug_info (),
273 m_data_debug_line (),
274 m_data_debug_loc (),
275 m_data_debug_ranges (),
276 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000277 m_data_apple_names (),
278 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000279 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_info(),
282 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000283 m_apple_names_ap (),
284 m_apple_types_ap (),
285 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000286 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000287 m_function_basename_index(),
288 m_function_fullname_index(),
289 m_function_method_index(),
290 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000291 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000292 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000293 m_type_index(),
294 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000295 m_indexed (false),
296 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000297 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000298 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000299 m_ranges(),
300 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301{
302}
303
304SymbolFileDWARF::~SymbolFileDWARF()
305{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000306 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000307 {
308 ModuleSP module_sp (m_obj_file->GetModule());
309 if (module_sp)
310 module_sp->GetClangASTContext().RemoveExternalSource ();
311 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000312}
313
314static const ConstString &
315GetDWARFMachOSegmentName ()
316{
317 static ConstString g_dwarf_section_name ("__DWARF");
318 return g_dwarf_section_name;
319}
320
Greg Claytone576ab22011-02-15 00:19:15 +0000321UniqueDWARFASTTypeMap &
322SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
323{
324 if (m_debug_map_symfile)
325 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
326 return m_unique_ast_type_map;
327}
328
Greg Clayton6beaaa62011-01-17 03:46:26 +0000329ClangASTContext &
330SymbolFileDWARF::GetClangASTContext ()
331{
332 if (m_debug_map_symfile)
333 return m_debug_map_symfile->GetClangASTContext ();
334
335 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
336 if (!m_is_external_ast_source)
337 {
338 m_is_external_ast_source = true;
339 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
340 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
341 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000342 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000343 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000344 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 ast.SetExternalSource (ast_source_ap);
346 }
347 return ast;
348}
349
350void
351SymbolFileDWARF::InitializeObject()
352{
353 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000354 ModuleSP module_sp (m_obj_file->GetModule());
355 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000356 {
357 const SectionList *section_list = m_obj_file->GetSectionList();
358
359 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
360
361 // Memory map the DWARF mach-o segment so we have everything mmap'ed
362 // to keep our heap memory usage down.
363 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000364 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000365 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000366 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000367 if (m_data_apple_names.GetByteSize() > 0)
368 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000369 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
370 if (m_apple_names_ap->IsValid())
371 m_using_apple_tables = true;
372 else
Greg Clayton7f995132011-10-04 22:41:51 +0000373 m_apple_names_ap.reset();
374 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000375 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000376 if (m_data_apple_types.GetByteSize() > 0)
377 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000378 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
379 if (m_apple_types_ap->IsValid())
380 m_using_apple_tables = true;
381 else
Greg Clayton7f995132011-10-04 22:41:51 +0000382 m_apple_types_ap.reset();
383 }
384
385 get_apple_namespaces_data();
386 if (m_data_apple_namespaces.GetByteSize() > 0)
387 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000388 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
389 if (m_apple_namespaces_ap->IsValid())
390 m_using_apple_tables = true;
391 else
Greg Clayton7f995132011-10-04 22:41:51 +0000392 m_apple_namespaces_ap.reset();
393 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000394
Greg Clayton5009f9d2011-10-27 17:55:14 +0000395 get_apple_objc_data();
396 if (m_data_apple_objc.GetByteSize() > 0)
397 {
398 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
399 if (m_apple_objc_ap->IsValid())
400 m_using_apple_tables = true;
401 else
402 m_apple_objc_ap.reset();
403 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404}
405
406bool
407SymbolFileDWARF::SupportedVersion(uint16_t version)
408{
409 return version == 2 || version == 3;
410}
411
412uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000413SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414{
415 uint32_t abilities = 0;
416 if (m_obj_file != NULL)
417 {
418 const Section* section = NULL;
419 const SectionList *section_list = m_obj_file->GetSectionList();
420 if (section_list == NULL)
421 return 0;
422
423 uint64_t debug_abbrev_file_size = 0;
424 uint64_t debug_aranges_file_size = 0;
425 uint64_t debug_frame_file_size = 0;
426 uint64_t debug_info_file_size = 0;
427 uint64_t debug_line_file_size = 0;
428 uint64_t debug_loc_file_size = 0;
429 uint64_t debug_macinfo_file_size = 0;
430 uint64_t debug_pubnames_file_size = 0;
431 uint64_t debug_pubtypes_file_size = 0;
432 uint64_t debug_ranges_file_size = 0;
433 uint64_t debug_str_file_size = 0;
434
Greg Clayton6beaaa62011-01-17 03:46:26 +0000435 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436
437 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439
Greg Clayton4ceb9982010-07-21 22:54:26 +0000440 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 if (section != NULL)
442 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000443 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444
Greg Clayton4ceb9982010-07-21 22:54:26 +0000445 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000447 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 else
449 m_flags.Set (flagsGotDebugAbbrevData);
450
Greg Clayton4ceb9982010-07-21 22:54:26 +0000451 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000453 debug_aranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 else
455 m_flags.Set (flagsGotDebugArangesData);
456
Greg Clayton4ceb9982010-07-21 22:54:26 +0000457 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000459 debug_frame_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 else
461 m_flags.Set (flagsGotDebugFrameData);
462
Greg Clayton4ceb9982010-07-21 22:54:26 +0000463 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000465 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 else
467 m_flags.Set (flagsGotDebugLineData);
468
Greg Clayton4ceb9982010-07-21 22:54:26 +0000469 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000471 debug_loc_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 else
473 m_flags.Set (flagsGotDebugLocData);
474
Greg Clayton4ceb9982010-07-21 22:54:26 +0000475 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000477 debug_macinfo_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 else
479 m_flags.Set (flagsGotDebugMacInfoData);
480
Greg Clayton4ceb9982010-07-21 22:54:26 +0000481 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000483 debug_pubnames_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 else
485 m_flags.Set (flagsGotDebugPubNamesData);
486
Greg Clayton4ceb9982010-07-21 22:54:26 +0000487 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000489 debug_pubtypes_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 else
491 m_flags.Set (flagsGotDebugPubTypesData);
492
Greg Clayton4ceb9982010-07-21 22:54:26 +0000493 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000495 debug_ranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496 else
497 m_flags.Set (flagsGotDebugRangesData);
498
Greg Clayton4ceb9982010-07-21 22:54:26 +0000499 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000501 debug_str_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 else
503 m_flags.Set (flagsGotDebugStrData);
504 }
Greg Clayton6c596612012-05-18 21:47:20 +0000505 else
506 {
507 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
508 if (symfile_dir_cstr)
509 {
510 if (strcasestr(symfile_dir_cstr, ".dsym"))
511 {
512 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
513 {
514 // We have a dSYM file that didn't have a any debug info.
515 // If the string table has a size of 1, then it was made from
516 // an executable with no debug info, or from an executable that
517 // was stripped.
518 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
519 if (section && section->GetFileSize() == 1)
520 {
521 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
522 }
523 }
524 }
525 }
526 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527
528 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
529 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
530
531 if (debug_line_file_size > 0)
532 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 }
534 return abilities;
535}
536
537const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000538SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
540 if (m_flags.IsClear (got_flag))
541 {
542 m_flags.Set (got_flag);
543 const SectionList *section_list = m_obj_file->GetSectionList();
544 if (section_list)
545 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000546 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
547 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
549 // See if we memory mapped the DWARF segment?
550 if (m_dwarf_data.GetByteSize())
551 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000552 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553 }
554 else
555 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000556 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 data.Clear();
558 }
559 }
560 }
561 }
562 return data;
563}
564
565const DataExtractor&
566SymbolFileDWARF::get_debug_abbrev_data()
567{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000568 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569}
570
571const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000572SymbolFileDWARF::get_debug_aranges_data()
573{
574 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
575}
576
577const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578SymbolFileDWARF::get_debug_frame_data()
579{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000580 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581}
582
583const DataExtractor&
584SymbolFileDWARF::get_debug_info_data()
585{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000586 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588
589const DataExtractor&
590SymbolFileDWARF::get_debug_line_data()
591{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000592 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593}
594
595const DataExtractor&
596SymbolFileDWARF::get_debug_loc_data()
597{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000598 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599}
600
601const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602SymbolFileDWARF::get_debug_ranges_data()
603{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000604 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605}
606
607const DataExtractor&
608SymbolFileDWARF::get_debug_str_data()
609{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000610 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611}
612
Greg Claytonf9eec202011-09-01 23:16:13 +0000613const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000614SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000615{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000616 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000617}
618
619const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000620SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000621{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000622 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000623}
624
Greg Clayton7f995132011-10-04 22:41:51 +0000625const DataExtractor&
626SymbolFileDWARF::get_apple_namespaces_data()
627{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000628 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
629}
630
631const DataExtractor&
632SymbolFileDWARF::get_apple_objc_data()
633{
634 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugAbbrev*
639SymbolFileDWARF::DebugAbbrev()
640{
641 if (m_abbr.get() == NULL)
642 {
643 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
644 if (debug_abbrev_data.GetByteSize() > 0)
645 {
646 m_abbr.reset(new DWARFDebugAbbrev());
647 if (m_abbr.get())
648 m_abbr->Parse(debug_abbrev_data);
649 }
650 }
651 return m_abbr.get();
652}
653
654const DWARFDebugAbbrev*
655SymbolFileDWARF::DebugAbbrev() const
656{
657 return m_abbr.get();
658}
659
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660
661DWARFDebugInfo*
662SymbolFileDWARF::DebugInfo()
663{
664 if (m_info.get() == NULL)
665 {
666 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
667 if (get_debug_info_data().GetByteSize() > 0)
668 {
669 m_info.reset(new DWARFDebugInfo());
670 if (m_info.get())
671 {
672 m_info->SetDwarfData(this);
673 }
674 }
675 }
676 return m_info.get();
677}
678
679const DWARFDebugInfo*
680SymbolFileDWARF::DebugInfo() const
681{
682 return m_info.get();
683}
684
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685DWARFCompileUnit*
686SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
687{
688 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000689 if (info && UserIDMatches(cu_uid))
690 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 return NULL;
692}
693
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694
695DWARFDebugRanges*
696SymbolFileDWARF::DebugRanges()
697{
698 if (m_ranges.get() == NULL)
699 {
700 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
701 if (get_debug_ranges_data().GetByteSize() > 0)
702 {
703 m_ranges.reset(new DWARFDebugRanges());
704 if (m_ranges.get())
705 m_ranges->Extract(this);
706 }
707 }
708 return m_ranges.get();
709}
710
711const DWARFDebugRanges*
712SymbolFileDWARF::DebugRanges() const
713{
714 return m_ranges.get();
715}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716
Greg Clayton53eb1c22012-04-02 22:59:12 +0000717lldb::CompUnitSP
718SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000720 CompUnitSP cu_sp;
721 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000723 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
724 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000726 // We already parsed this compile unit, had out a shared pointer to it
727 cu_sp = comp_unit->shared_from_this();
728 }
729 else
730 {
731 ModuleSP module_sp (m_obj_file->GetModule());
732 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
735 if (cu_die)
736 {
737 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
738 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
739 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
740 if (cu_die_name)
741 {
742 std::string ramapped_file;
743 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000744
Greg Clayton53eb1c22012-04-02 22:59:12 +0000745 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
746 {
747 // If we have a full path to the compile unit, we don't need to resolve
748 // the file. This can be expensive e.g. when the source files are NFS mounted.
749 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
750 cu_file_spec.SetFile (ramapped_file.c_str(), false);
751 else
752 cu_file_spec.SetFile (cu_die_name, false);
753 }
754 else
755 {
756 std::string fullpath(cu_comp_dir);
757 if (*fullpath.rbegin() != '/')
758 fullpath += '/';
759 fullpath += cu_die_name;
760 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
761 cu_file_spec.SetFile (ramapped_file.c_str(), false);
762 else
763 cu_file_spec.SetFile (fullpath.c_str(), false);
764 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765
Greg Clayton53eb1c22012-04-02 22:59:12 +0000766 cu_sp.reset(new CompileUnit (module_sp,
767 dwarf_cu,
768 cu_file_spec,
769 MakeUserID(dwarf_cu->GetOffset()),
770 cu_language));
771 if (cu_sp)
772 {
773 dwarf_cu->SetUserData(cu_sp.get());
774
775 if (m_debug_map_symfile)
776 {
777 // Let the symbol file register the compile unit with
778 // the symbol vendor using its compile unit index
779 // when we are doing DWARF in .o files + debug map
780 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
781 }
782 else
783 {
784 // Figure out the compile unit index if we weren't given one
785 if (cu_idx == UINT32_MAX)
786 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
787
788 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
789 }
790 }
791 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792 }
793 }
794 }
795 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000796 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797}
798
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799uint32_t
800SymbolFileDWARF::GetNumCompileUnits()
801{
802 DWARFDebugInfo* info = DebugInfo();
803 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805 return 0;
806}
807
808CompUnitSP
809SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
810{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812 DWARFDebugInfo* info = DebugInfo();
813 if (info)
814 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000815 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
816 if (dwarf_cu)
817 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000819 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820}
821
822static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000823AddRangesToBlock (Block& block,
824 DWARFDebugRanges::RangeList& ranges,
825 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 const size_t num_ranges = ranges.GetSize();
828 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000830 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
831 const addr_t range_base = range.GetRangeBase();
832 assert (range_base >= block_base_addr);
833 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000835 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000836}
837
838
839Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000840SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000841{
842 DWARFDebugRanges::RangeList func_ranges;
843 const char *name = NULL;
844 const char *mangled = NULL;
845 int decl_file = 0;
846 int decl_line = 0;
847 int decl_column = 0;
848 int call_file = 0;
849 int call_line = 0;
850 int call_column = 0;
851 DWARFExpression frame_base;
852
Greg Claytonc93237c2010-10-01 20:48:32 +0000853 assert (die->Tag() == DW_TAG_subprogram);
854
855 if (die->Tag() != DW_TAG_subprogram)
856 return NULL;
857
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000858 if (die->GetDIENamesAndRanges (this,
859 dwarf_cu,
860 name,
861 mangled,
862 func_ranges,
863 decl_file,
864 decl_line,
865 decl_column,
866 call_file,
867 call_line,
868 call_column,
869 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
871 // Union of all ranges in the function DIE (if the function is discontiguous)
872 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000873 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
874 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000875 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
876 {
877 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
878 if (func_range.GetBaseAddress().IsValid())
879 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
880 }
881
882 if (func_range.GetBaseAddress().IsValid())
883 {
884 Mangled func_name;
885 if (mangled)
886 func_name.SetValue(mangled, true);
887 else if (name)
888 func_name.SetValue(name, false);
889
890 FunctionSP func_sp;
891 std::auto_ptr<Declaration> decl_ap;
892 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000893 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
894 decl_line,
895 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000897 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000898 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000899
900 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
901
902 func_range.GetBaseAddress().ResolveLinkedAddress();
903
Greg Clayton81c22f62011-10-19 18:09:39 +0000904 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000906 func_user_id, // UserID is the DIE offset
907 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 func_name,
909 func_type,
910 func_range)); // first address range
911
912 if (func_sp.get() != NULL)
913 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000914 if (frame_base.IsValid())
915 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916 sc.comp_unit->AddFunction(func_sp);
917 return func_sp.get();
918 }
919 }
920 }
921 return NULL;
922}
923
924size_t
925SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
926{
927 assert (sc.comp_unit);
928 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000929 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 if (dwarf_cu)
931 {
932 DWARFDIECollection function_dies;
933 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
934 size_t func_idx;
935 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
936 {
937 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000938 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000939 {
940 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
941 ++functions_added;
942 }
943 }
944 //FixupTypes();
945 }
946 return functions_added;
947}
948
949bool
950SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
951{
952 assert (sc.comp_unit);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000953 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
954 assert (dwarf_cu);
955 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956
957 if (cu_die)
958 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000959 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
960 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 +0000961
962 // All file indexes in DWARF are one based and a file of index zero is
963 // supposed to be the compile unit itself.
964 support_files.Append (*sc.comp_unit);
965
Greg Claytond804d282012-03-15 21:01:31 +0000966 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 +0000967 }
968 return false;
969}
970
971struct ParseDWARFLineTableCallbackInfo
972{
973 LineTable* line_table;
974 const SectionList *section_list;
975 lldb::addr_t prev_sect_file_base_addr;
976 lldb::addr_t curr_sect_file_base_addr;
977 bool is_oso_for_debug_map;
978 bool prev_in_final_executable;
979 DWARFDebugLine::Row prev_row;
980 SectionSP prev_section_sp;
981 SectionSP curr_section_sp;
982};
983
984//----------------------------------------------------------------------
985// ParseStatementTableCallback
986//----------------------------------------------------------------------
987static void
988ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
989{
990 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
991 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
992 {
993 // Just started parsing the line table
994 }
995 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
996 {
997 // Done parsing line table, nothing to do for the cleanup
998 }
999 else
1000 {
1001 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1002 // We have a new row, lets append it
1003
1004 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
1005 {
1006 info->prev_section_sp = info->curr_section_sp;
1007 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1008 // If this is an end sequence entry, then we subtract one from the
1009 // address to make sure we get an address that is not the end of
1010 // a section.
1011 if (state.end_sequence && state.address != 0)
1012 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1013 else
1014 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1015
1016 if (info->curr_section_sp.get())
1017 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1018 else
1019 info->curr_sect_file_base_addr = 0;
1020 }
1021 if (info->curr_section_sp.get())
1022 {
1023 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1024 // Check for the fancy section magic to determine if we
1025
1026 if (info->is_oso_for_debug_map)
1027 {
1028 // When this is a debug map object file that contains DWARF
1029 // (referenced from an N_OSO debug map nlist entry) we will have
1030 // a file address in the file range for our section from the
1031 // original .o file, and a load address in the executable that
1032 // contains the debug map.
1033 //
1034 // If the sections for the file range and load range are
1035 // different, we have a remapped section for the function and
1036 // this address is resolved. If they are the same, then the
1037 // function for this address didn't make it into the final
1038 // executable.
1039 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1040
1041 // If we are doing DWARF with debug map, then we need to carefully
1042 // add each line table entry as there may be gaps as functions
1043 // get moved around or removed.
1044 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1045 {
1046 if (info->prev_in_final_executable)
1047 {
1048 bool terminate_previous_entry = false;
1049 if (!curr_in_final_executable)
1050 {
1051 // Check for the case where the previous line entry
1052 // in a function made it into the final executable,
1053 // yet the current line entry falls in a function
1054 // that didn't. The line table used to be contiguous
1055 // through this address range but now it isn't. We
1056 // need to terminate the previous line entry so
1057 // that we can reconstruct the line range correctly
1058 // for it and to keep the line table correct.
1059 terminate_previous_entry = true;
1060 }
1061 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1062 {
1063 // Check for cases where the line entries used to be
1064 // contiguous address ranges, but now they aren't.
1065 // This can happen when order files specify the
1066 // ordering of the functions.
1067 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1068 Section *curr_sect = info->curr_section_sp.get();
1069 Section *prev_sect = info->prev_section_sp.get();
1070 assert (curr_sect->GetLinkedSection());
1071 assert (prev_sect->GetLinkedSection());
1072 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1073 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1074 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1075 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1076 if (object_file_addr_delta != linked_file_addr_delta)
1077 terminate_previous_entry = true;
1078 }
1079
1080 if (terminate_previous_entry)
1081 {
1082 line_table->InsertLineEntry (info->prev_section_sp,
1083 state.address - info->prev_sect_file_base_addr,
1084 info->prev_row.line,
1085 info->prev_row.column,
1086 info->prev_row.file,
1087 false, // is_stmt
1088 false, // basic_block
1089 false, // state.prologue_end
1090 false, // state.epilogue_begin
1091 true); // end_sequence);
1092 }
1093 }
1094 }
1095
1096 if (curr_in_final_executable)
1097 {
1098 line_table->InsertLineEntry (info->curr_section_sp,
1099 curr_line_section_offset,
1100 state.line,
1101 state.column,
1102 state.file,
1103 state.is_stmt,
1104 state.basic_block,
1105 state.prologue_end,
1106 state.epilogue_begin,
1107 state.end_sequence);
1108 info->prev_section_sp = info->curr_section_sp;
1109 }
1110 else
1111 {
1112 // If the current address didn't make it into the final
1113 // executable, the current section will be the __text
1114 // segment in the .o file, so we need to clear this so
1115 // we can catch the next function that did make it into
1116 // the final executable.
1117 info->prev_section_sp.reset();
1118 info->curr_section_sp.reset();
1119 }
1120
1121 info->prev_in_final_executable = curr_in_final_executable;
1122 }
1123 else
1124 {
1125 // We are not in an object file that contains DWARF for an
1126 // N_OSO, this is just a normal DWARF file. The DWARF spec
1127 // guarantees that the addresses will be in increasing order
1128 // so, since we store line tables in file address order, we
1129 // can always just append the line entry without needing to
1130 // search for the correct insertion point (we don't need to
1131 // use LineEntry::InsertLineEntry()).
1132 line_table->AppendLineEntry (info->curr_section_sp,
1133 curr_line_section_offset,
1134 state.line,
1135 state.column,
1136 state.file,
1137 state.is_stmt,
1138 state.basic_block,
1139 state.prologue_end,
1140 state.epilogue_begin,
1141 state.end_sequence);
1142 }
1143 }
1144
1145 info->prev_row = state;
1146 }
1147}
1148
1149bool
1150SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1151{
1152 assert (sc.comp_unit);
1153 if (sc.comp_unit->GetLineTable() != NULL)
1154 return true;
1155
1156 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1157 if (dwarf_cu)
1158 {
1159 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001160 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001162 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1163 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001165 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1166 if (line_table_ap.get())
1167 {
1168 ParseDWARFLineTableCallbackInfo info = {
1169 line_table_ap.get(),
1170 m_obj_file->GetSectionList(),
1171 0,
1172 0,
1173 m_debug_map_symfile != NULL,
1174 false,
1175 DWARFDebugLine::Row(),
1176 SectionSP(),
1177 SectionSP()
1178 };
1179 uint32_t offset = cu_line_offset;
1180 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1181 sc.comp_unit->SetLineTable(line_table_ap.release());
1182 return true;
1183 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 }
1185 }
1186 }
1187 return false;
1188}
1189
1190size_t
1191SymbolFileDWARF::ParseFunctionBlocks
1192(
1193 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001194 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001195 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 const DWARFDebugInfoEntry *die,
1197 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001198 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199)
1200{
1201 size_t blocks_added = 0;
1202 while (die != NULL)
1203 {
1204 dw_tag_t tag = die->Tag();
1205
1206 switch (tag)
1207 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001209 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 case DW_TAG_lexical_block:
1211 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001212 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001213 if (tag == DW_TAG_subprogram)
1214 {
1215 // Skip any DW_TAG_subprogram DIEs that are inside
1216 // of a normal or inlined functions. These will be
1217 // parsed on their own as separate entities.
1218
1219 if (depth > 0)
1220 break;
1221
1222 block = parent_block;
1223 }
1224 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001225 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001226 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001227 parent_block->AddChild(block_sp);
1228 block = block_sp.get();
1229 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001230 DWARFDebugRanges::RangeList ranges;
1231 const char *name = NULL;
1232 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 int decl_file = 0;
1235 int decl_line = 0;
1236 int decl_column = 0;
1237 int call_file = 0;
1238 int call_line = 0;
1239 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001240 if (die->GetDIENamesAndRanges (this,
1241 dwarf_cu,
1242 name,
1243 mangled_name,
1244 ranges,
1245 decl_file, decl_line, decl_column,
1246 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 {
1248 if (tag == DW_TAG_subprogram)
1249 {
1250 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001251 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001253 else if (tag == DW_TAG_inlined_subroutine)
1254 {
1255 // We get called here for inlined subroutines in two ways.
1256 // The first time is when we are making the Function object
1257 // for this inlined concrete instance. Since we're creating a top level block at
1258 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1259 // adjust the containing address.
1260 // The second time is when we are parsing the blocks inside the function that contains
1261 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1262 // function the offset will be for that function.
1263 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1264 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001265 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001266 }
1267 }
1268
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001269 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270
1271 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1272 {
1273 std::auto_ptr<Declaration> decl_ap;
1274 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001275 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1276 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277
1278 std::auto_ptr<Declaration> call_ap;
1279 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001280 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1281 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001283 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 }
1285
1286 ++blocks_added;
1287
Greg Claytondd7feaf2011-08-12 17:54:33 +00001288 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001290 blocks_added += ParseFunctionBlocks (sc,
1291 block,
1292 dwarf_cu,
1293 die->GetFirstChild(),
1294 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001295 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 }
1297 }
1298 }
1299 break;
1300 default:
1301 break;
1302 }
1303
Greg Claytondd7feaf2011-08-12 17:54:33 +00001304 // Only parse siblings of the block if we are not at depth zero. A depth
1305 // of zero indicates we are currently parsing the top level
1306 // DW_TAG_subprogram DIE
1307
1308 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001310 else
1311 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312 }
1313 return blocks_added;
1314}
1315
Greg Claytonf0705c82011-10-22 03:33:13 +00001316bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001317SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1318 const DWARFDebugInfoEntry *die,
1319 ClangASTContext::TemplateParameterInfos &template_param_infos)
1320{
1321 const dw_tag_t tag = die->Tag();
1322
1323 switch (tag)
1324 {
1325 case DW_TAG_template_type_parameter:
1326 case DW_TAG_template_value_parameter:
1327 {
1328 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1329
1330 DWARFDebugInfoEntry::Attributes attributes;
1331 const size_t num_attributes = die->GetAttributes (this,
1332 dwarf_cu,
1333 fixed_form_sizes,
1334 attributes);
1335 const char *name = NULL;
1336 Type *lldb_type = NULL;
1337 clang_type_t clang_type = NULL;
1338 uint64_t uval64 = 0;
1339 bool uval64_valid = false;
1340 if (num_attributes > 0)
1341 {
1342 DWARFFormValue form_value;
1343 for (size_t i=0; i<num_attributes; ++i)
1344 {
1345 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1346
1347 switch (attr)
1348 {
1349 case DW_AT_name:
1350 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1351 name = form_value.AsCString(&get_debug_str_data());
1352 break;
1353
1354 case DW_AT_type:
1355 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1356 {
1357 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1358 lldb_type = ResolveTypeUID(type_die_offset);
1359 if (lldb_type)
1360 clang_type = lldb_type->GetClangForwardType();
1361 }
1362 break;
1363
1364 case DW_AT_const_value:
1365 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1366 {
1367 uval64_valid = true;
1368 uval64 = form_value.Unsigned();
1369 }
1370 break;
1371 default:
1372 break;
1373 }
1374 }
1375
1376 if (name && lldb_type && clang_type)
1377 {
1378 bool is_signed = false;
1379 template_param_infos.names.push_back(name);
1380 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1381 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1382 {
1383 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1384 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1385 }
1386 else
1387 {
1388 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1389 }
1390 }
1391 else
1392 {
1393 return false;
1394 }
1395
1396 }
1397 }
1398 return true;
1399
1400 default:
1401 break;
1402 }
1403 return false;
1404}
1405
1406bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001407SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1408 const DWARFDebugInfoEntry *parent_die,
1409 ClangASTContext::TemplateParameterInfos &template_param_infos)
1410{
1411
1412 if (parent_die == NULL)
1413 return NULL;
1414
Greg Claytonf0705c82011-10-22 03:33:13 +00001415 Args template_parameter_names;
1416 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1417 die != NULL;
1418 die = die->GetSibling())
1419 {
1420 const dw_tag_t tag = die->Tag();
1421
1422 switch (tag)
1423 {
1424 case DW_TAG_template_type_parameter:
1425 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001426 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001427 break;
1428
1429 default:
1430 break;
1431 }
1432 }
1433 if (template_param_infos.args.empty())
1434 return false;
1435 return template_param_infos.args.size() == template_param_infos.names.size();
1436}
1437
1438clang::ClassTemplateDecl *
1439SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001440 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001441 const char *parent_name,
1442 int tag_decl_kind,
1443 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1444{
1445 if (template_param_infos.IsValid())
1446 {
1447 std::string template_basename(parent_name);
1448 template_basename.erase (template_basename.find('<'));
1449 ClangASTContext &ast = GetClangASTContext();
1450
1451 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001452 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001453 template_basename.c_str(),
1454 tag_decl_kind,
1455 template_param_infos);
1456 }
1457 return NULL;
1458}
1459
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460size_t
1461SymbolFileDWARF::ParseChildMembers
1462(
1463 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001464 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001466 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001467 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1469 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001470 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001471 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001472 bool &is_a_class,
1473 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474)
1475{
1476 if (parent_die == NULL)
1477 return 0;
1478
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001479 size_t count = 0;
1480 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001481 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001482 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001483
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1485 {
1486 dw_tag_t tag = die->Tag();
1487
1488 switch (tag)
1489 {
1490 case DW_TAG_member:
Bill Wendling9e5bf872012-04-03 08:45:33 +00001491 case DW_TAG_APPLE_Property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001492 {
1493 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001494 const size_t num_attributes = die->GetAttributes (this,
1495 dwarf_cu,
1496 fixed_form_sizes,
1497 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 if (num_attributes > 0)
1499 {
1500 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001501 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001503 const char *prop_name = NULL;
1504 const char *prop_getter_name = NULL;
1505 const char *prop_setter_name = NULL;
1506 uint32_t prop_attributes = 0;
1507
1508
Greg Clayton24739922010-10-13 03:15:28 +00001509 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001510 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001511 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001512 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001513 size_t byte_size = 0;
1514 size_t bit_offset = 0;
1515 size_t bit_size = 0;
1516 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001517 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001518 {
1519 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1520 DWARFFormValue form_value;
1521 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1522 {
1523 switch (attr)
1524 {
1525 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1526 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1527 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1528 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1529 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1530 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1531 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1532 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1533 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001534 if (form_value.BlockData())
1535 {
1536 Value initialValue(0);
1537 Value memberOffset(0);
1538 const DataExtractor& debug_info_data = get_debug_info_data();
1539 uint32_t block_length = form_value.Unsigned();
1540 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1541 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1542 NULL, // clang::ASTContext *
1543 NULL, // ClangExpressionVariableList *
1544 NULL, // ClangExpressionDeclMap *
1545 NULL, // RegisterContext *
1546 debug_info_data,
1547 block_offset,
1548 block_length,
1549 eRegisterKindDWARF,
1550 &initialValue,
1551 memberOffset,
1552 NULL))
1553 {
1554 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1555 }
1556 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001557 break;
1558
Greg Clayton8cf05932010-07-22 18:30:50 +00001559 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001560 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001561 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1562 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1563 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1564 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1565
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001566 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001567 case DW_AT_declaration:
1568 case DW_AT_description:
1569 case DW_AT_mutable:
1570 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571 case DW_AT_sibling:
1572 break;
1573 }
1574 }
1575 }
Sean Callanana6582262012-04-05 00:12:52 +00001576
1577 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001578 {
Sean Callanana6582262012-04-05 00:12:52 +00001579 ConstString fixed_getter;
1580 ConstString fixed_setter;
1581
1582 // Check if the property getter/setter were provided as full
1583 // names. We want basenames, so we extract them.
1584
1585 if (prop_getter_name && prop_getter_name[0] == '-')
1586 {
1587 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1588 NULL,
1589 &fixed_getter,
1590 NULL,
1591 NULL);
1592 prop_getter_name = fixed_getter.GetCString();
1593 }
1594
1595 if (prop_setter_name && prop_setter_name[0] == '-')
1596 {
1597 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1598 NULL,
1599 &fixed_setter,
1600 NULL,
1601 NULL);
1602 prop_setter_name = fixed_setter.GetCString();
1603 }
1604
1605 // If the names haven't been provided, they need to be
1606 // filled in.
1607
1608 if (!prop_getter_name)
1609 {
1610 prop_getter_name = prop_name;
1611 }
1612 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1613 {
1614 StreamString ss;
1615
1616 ss.Printf("set%c%s:",
1617 toupper(prop_name[0]),
1618 &prop_name[1]);
1619
1620 fixed_setter.SetCString(ss.GetData());
1621 prop_setter_name = fixed_setter.GetCString();
1622 }
Sean Callanan751aac62012-03-29 19:07:06 +00001623 }
1624
1625 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001626 // represents fields that are references with bad byte size
1627 // and bit size/offset information such as:
1628 //
1629 // DW_AT_byte_size( 0x00 )
1630 // DW_AT_bit_size( 0x40 )
1631 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1632 //
1633 // So check the bit offset to make sure it is sane, and if
1634 // the values are not sane, remove them. If we don't do this
1635 // then we will end up with a crash if we try to use this
1636 // type in an expression when clang becomes unhappy with its
1637 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001638
Greg Clayton44953932011-10-25 01:25:35 +00001639 if (bit_offset > 128)
1640 {
1641 bit_size = 0;
1642 bit_offset = 0;
1643 }
1644
1645 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001646 if (class_language == eLanguageTypeObjC ||
1647 class_language == eLanguageTypeObjC_plus_plus)
1648 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001649
1650 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1651 {
1652 // Not all compilers will mark the vtable pointer
1653 // member as artificial (llvm-gcc). We can't have
1654 // the virtual members in our classes otherwise it
1655 // throws off all child offsets since we end up
1656 // having and extra pointer sized member in our
1657 // class layouts.
1658 is_artificial = true;
1659 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001660
Greg Clayton24739922010-10-13 03:15:28 +00001661 if (is_artificial == false)
1662 {
1663 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001664 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001665 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001666 {
Sean Callanan751aac62012-03-29 19:07:06 +00001667 if (member_type)
1668 {
1669 if (accessibility == eAccessNone)
1670 accessibility = default_accessibility;
1671 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672
Sean Callanan751aac62012-03-29 19:07:06 +00001673 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1674 name,
1675 member_type->GetClangLayoutType(),
1676 accessibility,
1677 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001678
1679 GetClangASTContext().SetMetadata((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callanan5b26f272012-02-04 08:49:35 +00001680 }
1681 else
1682 {
Sean Callanan751aac62012-03-29 19:07:06 +00001683 if (name)
1684 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1685 MakeUserID(die->GetOffset()),
1686 name,
1687 encoding_uid);
1688 else
1689 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1690 MakeUserID(die->GetOffset()),
1691 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001692 }
Sean Callanan751aac62012-03-29 19:07:06 +00001693
1694 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1695 {
1696 /////////////////////////////////////////////////////////////
1697 // How to locate a field given the DWARF debug information
1698 //
1699 // AT_byte_size indicates the size of the word in which the
1700 // bit offset must be interpreted.
1701 //
1702 // AT_data_member_location indicates the byte offset of the
1703 // word from the base address of the structure.
1704 //
1705 // AT_bit_offset indicates how many bits into the word
1706 // (according to the host endianness) the low-order bit of
1707 // the field starts. AT_bit_offset can be negative.
1708 //
1709 // AT_bit_size indicates the size of the field in bits.
1710 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001711
Sean Callanan751aac62012-03-29 19:07:06 +00001712 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1713
1714 uint64_t total_bit_offset = 0;
1715
1716 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1717
1718 if (object_endian == eByteOrderLittle)
1719 {
1720 total_bit_offset += byte_size * 8;
1721 total_bit_offset -= (bit_offset + bit_size);
1722 }
1723 else
1724 {
1725 total_bit_offset += bit_offset;
1726 }
1727
1728 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1729 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001730 }
Sean Callanan751aac62012-03-29 19:07:06 +00001731
Jim Inghame3ae82a2011-11-12 01:36:43 +00001732 if (prop_name != NULL)
1733 {
Sean Callanan751aac62012-03-29 19:07:06 +00001734 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001735
Sean Callanan751aac62012-03-29 19:07:06 +00001736 if (field_decl)
1737 {
1738 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1739 assert (ivar_decl != NULL);
1740 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001741
Jim Inghame3ae82a2011-11-12 01:36:43 +00001742 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1743 prop_name,
Sean Callanan751aac62012-03-29 19:07:06 +00001744 member_type->GetClangLayoutType(),
Jim Inghame3ae82a2011-11-12 01:36:43 +00001745 ivar_decl,
1746 prop_setter_name,
1747 prop_getter_name,
Sean Callananad880762012-04-18 01:06:17 +00001748 prop_attributes,
1749 MakeUserID(die->GetOffset()));
Sean Callanan60217122012-04-13 00:10:03 +00001750
Sean Callananad880762012-04-18 01:06:17 +00001751 if (ivar_decl)
1752 GetClangASTContext().SetMetadata((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001753 }
Greg Clayton24739922010-10-13 03:15:28 +00001754 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001755 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001756 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001757 }
1758 break;
1759
1760 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001761 // Let the type parsing code handle this one for us.
1762 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001763 break;
1764
1765 case DW_TAG_inheritance:
1766 {
1767 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001768 if (default_accessibility == eAccessNone)
1769 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770 // TODO: implement DW_TAG_inheritance type parsing
1771 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001772 const size_t num_attributes = die->GetAttributes (this,
1773 dwarf_cu,
1774 fixed_form_sizes,
1775 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776 if (num_attributes > 0)
1777 {
1778 Declaration decl;
1779 DWARFExpression location;
1780 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001781 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001782 bool is_virtual = false;
1783 bool is_base_of_class = true;
1784 off_t member_offset = 0;
1785 uint32_t i;
1786 for (i=0; i<num_attributes; ++i)
1787 {
1788 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1789 DWARFFormValue form_value;
1790 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1791 {
1792 switch (attr)
1793 {
1794 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1795 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1796 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1797 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1798 case DW_AT_data_member_location:
1799 if (form_value.BlockData())
1800 {
1801 Value initialValue(0);
1802 Value memberOffset(0);
1803 const DataExtractor& debug_info_data = get_debug_info_data();
1804 uint32_t block_length = form_value.Unsigned();
1805 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001806 if (DWARFExpression::Evaluate (NULL,
1807 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001808 NULL,
1809 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001810 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001811 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001812 block_offset,
1813 block_length,
1814 eRegisterKindDWARF,
1815 &initialValue,
1816 memberOffset,
1817 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818 {
1819 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1820 }
1821 }
1822 break;
1823
1824 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001825 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826 break;
1827
1828 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1829 default:
1830 case DW_AT_sibling:
1831 break;
1832 }
1833 }
1834 }
1835
Greg Clayton526e5af2010-11-13 03:52:47 +00001836 Type *base_class_type = ResolveTypeUID(encoding_uid);
1837 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001838
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001839 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1840 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001841 if (class_language == eLanguageTypeObjC)
1842 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001843 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001844 }
1845 else
1846 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001847 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001848 accessibility,
1849 is_virtual,
1850 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001851 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852 }
1853 }
1854 break;
1855
1856 default:
1857 break;
1858 }
1859 }
1860 return count;
1861}
1862
1863
1864clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001865SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866{
1867 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001868 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869 {
1870 DWARFCompileUnitSP cu_sp;
1871 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1872 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001873 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001874 }
1875 return NULL;
1876}
1877
1878clang::DeclContext*
1879SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1880{
Greg Clayton81c22f62011-10-19 18:09:39 +00001881 if (UserIDMatches(type_uid))
1882 return GetClangDeclContextForDIEOffset (sc, type_uid);
1883 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884}
1885
1886Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001887SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001888{
Greg Clayton81c22f62011-10-19 18:09:39 +00001889 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001891 DWARFDebugInfo* debug_info = DebugInfo();
1892 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001893 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001894 DWARFCompileUnitSP cu_sp;
1895 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001896 const bool assert_not_being_parsed = true;
1897 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001898 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 }
1900 return NULL;
1901}
1902
Greg Claytoncab36a32011-12-08 05:16:30 +00001903Type*
1904SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001905{
Greg Claytoncab36a32011-12-08 05:16:30 +00001906 if (die != NULL)
1907 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001908 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1909 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001910 GetObjectFile()->GetModule()->LogMessage (log.get(),
1911 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1912 die->GetOffset(),
1913 DW_TAG_value_to_name(die->Tag()),
1914 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001915
Greg Claytoncab36a32011-12-08 05:16:30 +00001916 // We might be coming in in the middle of a type tree (a class
1917 // withing a class, an enum within a class), so parse any needed
1918 // parent DIEs before we get to this one...
1919 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1920 switch (decl_ctx_die->Tag())
1921 {
1922 case DW_TAG_structure_type:
1923 case DW_TAG_union_type:
1924 case DW_TAG_class_type:
1925 {
1926 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001927 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001928 GetObjectFile()->GetModule()->LogMessage (log.get(),
1929 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1930 die->GetOffset(),
1931 DW_TAG_value_to_name(die->Tag()),
1932 die->GetName(this, cu),
1933 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001934//
1935// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1936// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1937// {
1938// if (log)
1939// GetObjectFile()->GetModule()->LogMessage (log.get(),
1940// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1941// die->GetOffset(),
1942// DW_TAG_value_to_name(die->Tag()),
1943// die->GetName(this, cu),
1944// decl_ctx_die->GetOffset());
1945// // Ask the type to complete itself if it already hasn't since if we
1946// // want a function (method or static) from a class, the class must
1947// // create itself and add it's own methods and class functions.
1948// if (parent_type)
1949// parent_type->GetClangFullType();
1950// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001951 }
1952 break;
1953
1954 default:
1955 break;
1956 }
1957 return ResolveType (cu, die);
1958 }
1959 return NULL;
1960}
1961
Greg Clayton6beaaa62011-01-17 03:46:26 +00001962// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1963// SymbolFileDWARF objects to detect if this DWARF file is the one that
1964// can resolve a clang_type.
1965bool
1966SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1967{
1968 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1969 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1970 return die != NULL;
1971}
1972
1973
Greg Clayton1be10fc2010-09-29 01:12:09 +00001974lldb::clang_type_t
1975SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1976{
1977 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001978 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1979 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001980 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001981 {
1982 // We have already resolved this type...
1983 return clang_type;
1984 }
1985 // Once we start resolving this type, remove it from the forward declaration
1986 // map in case anyone child members or other types require this type to get resolved.
1987 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1988 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001989 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001990
Greg Clayton1be10fc2010-09-29 01:12:09 +00001991
Greg Clayton85ae2e12011-10-18 23:36:41 +00001992 // Disable external storage for this type so we don't get anymore
1993 // clang::ExternalASTSource queries for this type.
1994 ClangASTContext::SetHasExternalStorage (clang_type, false);
1995
Greg Clayton450e3f32010-10-12 02:24:53 +00001996 DWARFDebugInfo* debug_info = DebugInfo();
1997
Greg Clayton53eb1c22012-04-02 22:59:12 +00001998 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001999 Type *type = m_die_to_type.lookup (die);
2000
2001 const dw_tag_t tag = die->Tag();
2002
Greg Claytonbaf95da2012-03-30 23:50:54 +00002003 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002004 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002005 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002006 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
2007 "0x%8.8llx: %s '%s' resolving forward declaration...",
2008 MakeUserID(die->GetOffset()),
2009 DW_TAG_value_to_name(tag),
2010 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002011
Greg Claytonbaf95da2012-03-30 23:50:54 +00002012 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002013 assert (clang_type);
2014 DWARFDebugInfoEntry::Attributes attributes;
2015
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002016 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002017
2018 switch (tag)
2019 {
2020 case DW_TAG_structure_type:
2021 case DW_TAG_union_type:
2022 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002023 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002024 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002025
Greg Clayton1be10fc2010-09-29 01:12:09 +00002026 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002027 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002028 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002029
Sean Callanan77a1fd32012-02-27 20:07:01 +00002030 LanguageType class_language = eLanguageTypeUnknown;
2031 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2032 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002033 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002034 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002035 // For objective C we don't start the definition when
2036 // the class is created.
2037 ast.StartTagDeclarationDefinition (clang_type);
2038 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002039
2040 int tag_decl_kind = -1;
2041 AccessType default_accessibility = eAccessNone;
2042 if (tag == DW_TAG_structure_type)
2043 {
2044 tag_decl_kind = clang::TTK_Struct;
2045 default_accessibility = eAccessPublic;
2046 }
2047 else if (tag == DW_TAG_union_type)
2048 {
2049 tag_decl_kind = clang::TTK_Union;
2050 default_accessibility = eAccessPublic;
2051 }
2052 else if (tag == DW_TAG_class_type)
2053 {
2054 tag_decl_kind = clang::TTK_Class;
2055 default_accessibility = eAccessPrivate;
2056 }
2057
Greg Clayton53eb1c22012-04-02 22:59:12 +00002058 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002059 std::vector<clang::CXXBaseSpecifier *> base_classes;
2060 std::vector<int> member_accessibilities;
2061 bool is_a_class = false;
2062 // Parse members and base classes first
2063 DWARFDIECollection member_function_dies;
2064
2065 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002066 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002067 die,
2068 clang_type,
2069 class_language,
2070 base_classes,
2071 member_accessibilities,
2072 member_function_dies,
2073 default_accessibility,
2074 is_a_class,
2075 layout_info);
2076
2077 // Now parse any methods if there were any...
2078 size_t num_functions = member_function_dies.Size();
2079 if (num_functions > 0)
2080 {
2081 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002082 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002083 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002084 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002085 }
2086
2087 if (class_language == eLanguageTypeObjC)
2088 {
Greg Clayton84db9102012-03-26 23:03:23 +00002089 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002090 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002091 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002092
Sean Callanan77a1fd32012-02-27 20:07:01 +00002093 DIEArray method_die_offsets;
2094 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002095 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002096 if (m_apple_objc_ap.get())
2097 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2098 }
2099 else
2100 {
2101 if (!m_indexed)
2102 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002103
Sean Callanan77a1fd32012-02-27 20:07:01 +00002104 ConstString class_name (class_str.c_str());
2105 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2106 }
2107
2108 if (!method_die_offsets.empty())
2109 {
2110 DWARFDebugInfo* debug_info = DebugInfo();
2111
2112 DWARFCompileUnit* method_cu = NULL;
2113 const size_t num_matches = method_die_offsets.size();
2114 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002115 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002116 const dw_offset_t die_offset = method_die_offsets[i];
2117 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2118
2119 if (method_die)
2120 ResolveType (method_cu, method_die);
2121 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002122 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002123 if (m_using_apple_tables)
2124 {
2125 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2126 die_offset, class_str.c_str());
2127 }
2128 }
2129 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002130 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002131 }
2132 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002133
2134 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2135 // need to tell the clang type it is actually a class.
2136 if (class_language != eLanguageTypeObjC)
2137 {
2138 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2139 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2140 }
2141
2142 // Since DW_TAG_structure_type gets used for both classes
2143 // and structures, we may need to set any DW_TAG_member
2144 // fields to have a "private" access if none was specified.
2145 // When we parsed the child members we tracked that actual
2146 // accessibility value for each DW_TAG_member in the
2147 // "member_accessibilities" array. If the value for the
2148 // member is zero, then it was set to the "default_accessibility"
2149 // which for structs was "public". Below we correct this
2150 // by setting any fields to "private" that weren't correctly
2151 // set.
2152 if (is_a_class && !member_accessibilities.empty())
2153 {
2154 // This is a class and all members that didn't have
2155 // their access specified are private.
2156 ast.SetDefaultAccessForRecordFields (clang_type,
2157 eAccessPrivate,
2158 &member_accessibilities.front(),
2159 member_accessibilities.size());
2160 }
2161
2162 if (!base_classes.empty())
2163 {
2164 ast.SetBaseClassesForClassType (clang_type,
2165 &base_classes.front(),
2166 base_classes.size());
2167
2168 // Clang will copy each CXXBaseSpecifier in "base_classes"
2169 // so we have to free them all.
2170 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2171 base_classes.size());
2172 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002173 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002174 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002175
2176 ast.BuildIndirectFields (clang_type);
2177
Sean Callanan77a1fd32012-02-27 20:07:01 +00002178 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002179
Greg Claytoncaab74e2012-01-28 00:48:57 +00002180 if (!layout_info.field_offsets.empty())
2181 {
2182 if (type)
2183 layout_info.bit_size = type->GetByteSize() * 8;
2184 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002185 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Claytoncaab74e2012-01-28 00:48:57 +00002186 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2187 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2188 if (record_type)
2189 {
2190 const clang::RecordDecl *record_decl = record_type->getDecl();
2191
2192 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002193 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002194 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002195 "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 +00002196 clang_type,
2197 record_decl,
2198 layout_info.bit_size,
2199 layout_info.alignment,
2200 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002201
Greg Clayton821ac6d2012-01-28 02:22:27 +00002202 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2203 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2204 {
2205 GetObjectFile()->GetModule()->LogMessage (log.get(),
2206 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2207 clang_type,
2208 (uint32_t)pos->second,
2209 pos->first->getNameAsString().c_str());
2210 }
2211 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002212 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2213 }
2214 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002215 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002216
Greg Claytonc93237c2010-10-01 20:48:32 +00002217 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002218
2219 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002220 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002221 if (die->HasChildren())
2222 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002223 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2224 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002225 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002226 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002227 return clang_type;
2228
2229 default:
2230 assert(false && "not a forward clang type decl!");
2231 break;
2232 }
2233 return NULL;
2234}
2235
Greg Claytonc685f8e2010-09-15 04:15:46 +00002236Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002237SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002238{
2239 if (type_die != NULL)
2240 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002241 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002242
Greg Claytonc685f8e2010-09-15 04:15:46 +00002243 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002244 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002245
Greg Clayton24739922010-10-13 03:15:28 +00002246 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002247 {
2248 if (type != DIE_IS_BEING_PARSED)
2249 return type;
2250
2251 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002252 type_die->GetOffset(),
2253 DW_TAG_value_to_name(type_die->Tag()),
2254 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002255
2256 }
2257 else
2258 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002259 }
2260 return NULL;
2261}
2262
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002263CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002264SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002265{
2266 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002267 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002268 {
2269 // The symbol vendor doesn't know about this compile unit, we
2270 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002271 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002273 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002274}
2275
2276bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002277SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002278{
2279 sc.Clear();
2280 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002281 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002282
Greg Clayton81c22f62011-10-19 18:09:39 +00002283 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002284 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002285 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002286
2287 if (sc.function)
2288 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002289 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002290 return true;
2291 }
2292
2293 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002294}
2295
2296uint32_t
2297SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2298{
2299 Timer scoped_timer(__PRETTY_FUNCTION__,
2300 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002301 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002302 so_addr.GetOffset(),
2303 resolve_scope);
2304 uint32_t resolved = 0;
2305 if (resolve_scope & ( eSymbolContextCompUnit |
2306 eSymbolContextFunction |
2307 eSymbolContextBlock |
2308 eSymbolContextLineEntry))
2309 {
2310 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002312 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002313 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002314 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002315 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002316 if (cu_offset != DW_INVALID_OFFSET)
2317 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002318 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002319 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2320 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002321 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002322 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002323 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002324 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002325 resolved |= eSymbolContextCompUnit;
2326
2327 if (resolve_scope & eSymbolContextLineEntry)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002328 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002329 LineTable *line_table = sc.comp_unit->GetLineTable();
2330 if (line_table != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002332 if (so_addr.IsLinkedAddress())
2333 {
2334 Address linked_addr (so_addr);
2335 linked_addr.ResolveLinkedAddress();
2336 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2337 {
2338 resolved |= eSymbolContextLineEntry;
2339 }
2340 }
2341 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002342 {
2343 resolved |= eSymbolContextLineEntry;
2344 }
2345 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002346 }
2347
2348 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2349 {
2350 DWARFDebugInfoEntry *function_die = NULL;
2351 DWARFDebugInfoEntry *block_die = NULL;
2352 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002354 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2355 }
2356 else
2357 {
2358 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2359 }
2360
2361 if (function_die != NULL)
2362 {
2363 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2364 if (sc.function == NULL)
2365 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2366 }
2367 else
2368 {
2369 // We might have had a compile unit that had discontiguous
2370 // address ranges where the gaps are symbols that don't have
2371 // any debug info. Discontiguous compile unit address ranges
2372 // should only happen when there aren't other functions from
2373 // other compile units in these gaps. This helps keep the size
2374 // of the aranges down.
2375 sc.comp_unit = NULL;
2376 resolved &= ~eSymbolContextCompUnit;
2377 }
2378
2379 if (sc.function != NULL)
2380 {
2381 resolved |= eSymbolContextFunction;
2382
2383 if (resolve_scope & eSymbolContextBlock)
2384 {
2385 Block& block = sc.function->GetBlock (true);
2386
2387 if (block_die != NULL)
2388 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2389 else
2390 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2391 if (sc.block)
2392 resolved |= eSymbolContextBlock;
2393 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002394 }
2395 }
2396 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002397 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002398 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002399 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2400 cu_offset,
2401 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002402 }
2403 }
2404 }
2405 }
2406 }
2407 return resolved;
2408}
2409
2410
2411
2412uint32_t
2413SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2414{
2415 const uint32_t prev_size = sc_list.GetSize();
2416 if (resolve_scope & eSymbolContextCompUnit)
2417 {
2418 DWARFDebugInfo* debug_info = DebugInfo();
2419 if (debug_info)
2420 {
2421 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002422 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423
Greg Clayton53eb1c22012-04-02 22:59:12 +00002424 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002425 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002426 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002427 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2428 if (check_inlines || file_spec_matches_cu_file_spec)
2429 {
2430 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002431 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002432 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002433 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002434 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002435
Greg Clayton526a4ae2012-05-16 22:09:01 +00002436 // If we are looking for inline functions only and we don't
2437 // find it in the support files, we are done.
2438 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002439 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002440 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2441 if (file_idx == UINT32_MAX)
2442 continue;
2443 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002444
Greg Clayton526a4ae2012-05-16 22:09:01 +00002445 if (line != 0)
2446 {
2447 LineTable *line_table = sc.comp_unit->GetLineTable();
2448
2449 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002450 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002451 // We will have already looked up the file index if
2452 // we are searching for inline entries.
2453 if (!check_inlines)
2454 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002455
Greg Clayton526a4ae2012-05-16 22:09:01 +00002456 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002457 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002458 uint32_t found_line;
2459 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2460 found_line = sc.line_entry.line;
2461
2462 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002463 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002464 sc.function = NULL;
2465 sc.block = NULL;
2466 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002467 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002468 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2469 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002471 DWARFDebugInfoEntry *function_die = NULL;
2472 DWARFDebugInfoEntry *block_die = NULL;
2473 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002474
Greg Clayton526a4ae2012-05-16 22:09:01 +00002475 if (function_die != NULL)
2476 {
2477 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2478 if (sc.function == NULL)
2479 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2480 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002481
Greg Clayton526a4ae2012-05-16 22:09:01 +00002482 if (sc.function != NULL)
2483 {
2484 Block& block = sc.function->GetBlock (true);
2485
2486 if (block_die != NULL)
2487 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2488 else
2489 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2490 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002491 }
2492 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002493
Greg Clayton526a4ae2012-05-16 22:09:01 +00002494 sc_list.Append(sc);
2495 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2496 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002497 }
2498 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002499 else if (file_spec_matches_cu_file_spec && !check_inlines)
2500 {
2501 // only append the context if we aren't looking for inline call sites
2502 // by file and line and if the file spec matches that of the compile unit
2503 sc_list.Append(sc);
2504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002505 }
2506 else if (file_spec_matches_cu_file_spec && !check_inlines)
2507 {
2508 // only append the context if we aren't looking for inline call sites
2509 // by file and line and if the file spec matches that of the compile unit
2510 sc_list.Append(sc);
2511 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512
Greg Clayton526a4ae2012-05-16 22:09:01 +00002513 if (!check_inlines)
2514 break;
2515 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002516 }
2517 }
2518 }
2519 }
2520 return sc_list.GetSize() - prev_size;
2521}
2522
2523void
2524SymbolFileDWARF::Index ()
2525{
2526 if (m_indexed)
2527 return;
2528 m_indexed = true;
2529 Timer scoped_timer (__PRETTY_FUNCTION__,
2530 "SymbolFileDWARF::Index (%s)",
2531 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2532
2533 DWARFDebugInfo* debug_info = DebugInfo();
2534 if (debug_info)
2535 {
2536 uint32_t cu_idx = 0;
2537 const uint32_t num_compile_units = GetNumCompileUnits();
2538 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2539 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002540 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002541
Greg Clayton53eb1c22012-04-02 22:59:12 +00002542 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543
Greg Clayton53eb1c22012-04-02 22:59:12 +00002544 dwarf_cu->Index (cu_idx,
2545 m_function_basename_index,
2546 m_function_fullname_index,
2547 m_function_method_index,
2548 m_function_selector_index,
2549 m_objc_class_selectors_index,
2550 m_global_index,
2551 m_type_index,
2552 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002553
2554 // Keep memory down by clearing DIEs if this generate function
2555 // caused them to be parsed
2556 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002557 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002558 }
2559
Greg Claytond4a2b372011-09-12 23:21:58 +00002560 m_function_basename_index.Finalize();
2561 m_function_fullname_index.Finalize();
2562 m_function_method_index.Finalize();
2563 m_function_selector_index.Finalize();
2564 m_objc_class_selectors_index.Finalize();
2565 m_global_index.Finalize();
2566 m_type_index.Finalize();
2567 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002568
Greg Clayton24739922010-10-13 03:15:28 +00002569#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002570 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002571 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002572 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2573 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002574 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2575 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2576 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2577 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2578 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2579 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002580 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002581 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002582#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002583 }
2584}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002585
2586bool
2587SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2588{
2589 if (namespace_decl == NULL)
2590 {
2591 // Invalid namespace decl which means we aren't matching only things
2592 // in this symbol file, so return true to indicate it matches this
2593 // symbol file.
2594 return true;
2595 }
2596
2597 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2598
2599 if (namespace_ast == NULL)
2600 return true; // No AST in the "namespace_decl", return true since it
2601 // could then match any symbol file, including this one
2602
2603 if (namespace_ast == GetClangASTContext().getASTContext())
2604 return true; // The ASTs match, return true
2605
2606 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002607 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2608
2609 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002610 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002611
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002612 return false;
2613}
2614
Greg Clayton2506a7a2011-10-12 23:34:26 +00002615bool
2616SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2617 DWARFCompileUnit* cu,
2618 const DWARFDebugInfoEntry* die)
2619{
2620 // No namespace specified, so the answesr i
2621 if (namespace_decl == NULL)
2622 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002623
2624 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002625
Greg Clayton437a1352012-04-09 22:43:43 +00002626 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2627 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002628 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002629 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002630 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002631
Greg Clayton2506a7a2011-10-12 23:34:26 +00002632 if (clang_namespace_decl)
2633 {
2634 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002635 {
2636 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002637 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002638 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002639 }
2640
Greg Clayton437a1352012-04-09 22:43:43 +00002641 if (clang_namespace_decl == die_clang_decl_ctx)
2642 return true;
2643 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002644 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002645 }
2646 else
2647 {
2648 // We have a namespace_decl that was not NULL but it contained
2649 // a NULL "clang::NamespaceDecl", so this means the global namespace
2650 // So as long the the contained decl context DIE isn't a namespace
2651 // we should be ok.
2652 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2653 return true;
2654 }
2655 }
Sean Callananebe60672011-10-13 21:50:33 +00002656
2657 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002658 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002659
Greg Clayton2506a7a2011-10-12 23:34:26 +00002660 return false;
2661}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002662uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002663SymbolFileDWARF::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 +00002664{
Greg Clayton21f2a492011-10-06 00:09:08 +00002665 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2666
2667 if (log)
2668 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002669 GetObjectFile()->GetModule()->LogMessage (log.get(),
2670 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2671 name.GetCString(),
2672 namespace_decl,
2673 append,
2674 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002675 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002676
2677 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2678 return 0;
2679
Greg Claytonc685f8e2010-09-15 04:15:46 +00002680 DWARFDebugInfo* info = DebugInfo();
2681 if (info == NULL)
2682 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002683
2684 // If we aren't appending the results to this list, then clear the list
2685 if (!append)
2686 variables.Clear();
2687
2688 // Remember how many variables are in the list before we search in case
2689 // we are appending the results to a variable list.
2690 const uint32_t original_size = variables.GetSize();
2691
Greg Claytond4a2b372011-09-12 23:21:58 +00002692 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002693
Greg Clayton97fbc342011-10-20 22:30:33 +00002694 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002695 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002696 if (m_apple_names_ap.get())
2697 {
2698 const char *name_cstr = name.GetCString();
2699 const char *base_name_start;
2700 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002701
Greg Clayton97fbc342011-10-20 22:30:33 +00002702 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2703 base_name_start = name_cstr;
2704
2705 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2706 }
Greg Clayton7f995132011-10-04 22:41:51 +00002707 }
2708 else
2709 {
2710 // Index the DWARF if we haven't already
2711 if (!m_indexed)
2712 Index ();
2713
2714 m_global_index.Find (name, die_offsets);
2715 }
2716
Greg Clayton437a1352012-04-09 22:43:43 +00002717 const size_t num_die_matches = die_offsets.size();
2718 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002719 {
Greg Clayton7f995132011-10-04 22:41:51 +00002720 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002721 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002722 assert (sc.module_sp);
2723
Greg Claytond4a2b372011-09-12 23:21:58 +00002724 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002725 DWARFCompileUnit* dwarf_cu = NULL;
2726 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002727 bool done = false;
2728 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002729 {
2730 const dw_offset_t die_offset = die_offsets[i];
2731 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002732
Greg Clayton95d87902011-11-11 03:16:25 +00002733 if (die)
2734 {
Greg Clayton437a1352012-04-09 22:43:43 +00002735 switch (die->Tag())
2736 {
2737 default:
2738 case DW_TAG_subprogram:
2739 case DW_TAG_inlined_subroutine:
2740 case DW_TAG_try_block:
2741 case DW_TAG_catch_block:
2742 break;
2743
2744 case DW_TAG_variable:
2745 {
2746 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002747
2748 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2749 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002750
Greg Clayton437a1352012-04-09 22:43:43 +00002751 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002752
Greg Clayton437a1352012-04-09 22:43:43 +00002753 if (variables.GetSize() - original_size >= max_matches)
2754 done = true;
2755 }
2756 break;
2757 }
Greg Clayton95d87902011-11-11 03:16:25 +00002758 }
2759 else
2760 {
2761 if (m_using_apple_tables)
2762 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002763 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2764 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002765 }
2766 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002767 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768 }
2769
2770 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002771 const uint32_t num_matches = variables.GetSize() - original_size;
2772 if (log && num_matches > 0)
2773 {
2774 GetObjectFile()->GetModule()->LogMessage (log.get(),
2775 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2776 name.GetCString(),
2777 namespace_decl,
2778 append,
2779 max_matches,
2780 num_matches);
2781 }
2782 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002783}
2784
2785uint32_t
2786SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2787{
Greg Clayton21f2a492011-10-06 00:09:08 +00002788 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2789
2790 if (log)
2791 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002792 GetObjectFile()->GetModule()->LogMessage (log.get(),
2793 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2794 regex.GetText(),
2795 append,
2796 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002797 }
2798
Greg Claytonc685f8e2010-09-15 04:15:46 +00002799 DWARFDebugInfo* info = DebugInfo();
2800 if (info == NULL)
2801 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002802
2803 // If we aren't appending the results to this list, then clear the list
2804 if (!append)
2805 variables.Clear();
2806
2807 // Remember how many variables are in the list before we search in case
2808 // we are appending the results to a variable list.
2809 const uint32_t original_size = variables.GetSize();
2810
Greg Clayton7f995132011-10-04 22:41:51 +00002811 DIEArray die_offsets;
2812
Greg Clayton97fbc342011-10-20 22:30:33 +00002813 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002814 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002815 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002816 {
2817 DWARFMappedHash::DIEInfoArray hash_data_array;
2818 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2819 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2820 }
Greg Clayton7f995132011-10-04 22:41:51 +00002821 }
2822 else
2823 {
2824 // Index the DWARF if we haven't already
2825 if (!m_indexed)
2826 Index ();
2827
2828 m_global_index.Find (regex, die_offsets);
2829 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830
Greg Claytonc685f8e2010-09-15 04:15:46 +00002831 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002832 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002833 assert (sc.module_sp);
2834
Greg Claytond4a2b372011-09-12 23:21:58 +00002835 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002836 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002837 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002838 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002839 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002840 DWARFDebugInfo* debug_info = DebugInfo();
2841 for (size_t i=0; i<num_matches; ++i)
2842 {
2843 const dw_offset_t die_offset = die_offsets[i];
2844 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002845
2846 if (die)
2847 {
2848 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002849
Greg Clayton95d87902011-11-11 03:16:25 +00002850 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851
Greg Clayton95d87902011-11-11 03:16:25 +00002852 if (variables.GetSize() - original_size >= max_matches)
2853 break;
2854 }
2855 else
2856 {
2857 if (m_using_apple_tables)
2858 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002859 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2860 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002861 }
2862 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002863 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002864 }
2865
2866 // Return the number of variable that were appended to the list
2867 return variables.GetSize() - original_size;
2868}
2869
Greg Claytonaa044962011-10-13 00:59:38 +00002870
Jim Ingham4cda6e02011-10-07 22:23:45 +00002871bool
2872SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2873 DWARFCompileUnit *&dwarf_cu,
2874 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002875{
Greg Claytonaa044962011-10-13 00:59:38 +00002876 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2877 return ResolveFunction (dwarf_cu, die, sc_list);
2878}
2879
2880
2881bool
2882SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2883 const DWARFDebugInfoEntry *die,
2884 SymbolContextList& sc_list)
2885{
Greg Clayton9e315582011-09-02 04:03:59 +00002886 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002887
2888 if (die == NULL)
2889 return false;
2890
Jim Ingham4cda6e02011-10-07 22:23:45 +00002891 // If we were passed a die that is not a function, just return false...
2892 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2893 return false;
2894
2895 const DWARFDebugInfoEntry* inlined_die = NULL;
2896 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002897 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002898 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002899
Jim Ingham4cda6e02011-10-07 22:23:45 +00002900 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002901 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002902 if (die->Tag() == DW_TAG_subprogram)
2903 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002904 }
2905 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002906 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002907 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002908 {
2909 Address addr;
2910 // Parse all blocks if needed
2911 if (inlined_die)
2912 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002913 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002914 assert (sc.block != NULL);
2915 if (sc.block->GetStartAddress (addr) == false)
2916 addr.Clear();
2917 }
2918 else
2919 {
2920 sc.block = NULL;
2921 addr = sc.function->GetAddressRange().GetBaseAddress();
2922 }
2923
2924 if (addr.IsValid())
2925 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002926 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002927 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002928 }
2929 }
2930
Greg Claytonaa044962011-10-13 00:59:38 +00002931 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002932}
2933
Greg Clayton7f995132011-10-04 22:41:51 +00002934void
2935SymbolFileDWARF::FindFunctions (const ConstString &name,
2936 const NameToDIE &name_to_die,
2937 SymbolContextList& sc_list)
2938{
Greg Claytond4a2b372011-09-12 23:21:58 +00002939 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002940 if (name_to_die.Find (name, die_offsets))
2941 {
2942 ParseFunctions (die_offsets, sc_list);
2943 }
2944}
2945
2946
2947void
2948SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2949 const NameToDIE &name_to_die,
2950 SymbolContextList& sc_list)
2951{
2952 DIEArray die_offsets;
2953 if (name_to_die.Find (regex, die_offsets))
2954 {
2955 ParseFunctions (die_offsets, sc_list);
2956 }
2957}
2958
2959
2960void
2961SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2962 const DWARFMappedHash::MemoryTable &memory_table,
2963 SymbolContextList& sc_list)
2964{
2965 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002966 DWARFMappedHash::DIEInfoArray hash_data_array;
2967 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002968 {
Greg Claytond1767f02011-12-08 02:13:16 +00002969 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002970 ParseFunctions (die_offsets, sc_list);
2971 }
2972}
2973
2974void
2975SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2976 SymbolContextList& sc_list)
2977{
2978 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002979 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002980 {
Greg Clayton7f995132011-10-04 22:41:51 +00002981 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002982
2983 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002984 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002985 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002986 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002987 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002988 }
2989 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002990}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991
Jim Ingham4cda6e02011-10-07 22:23:45 +00002992bool
2993SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2994 const DWARFCompileUnit *dwarf_cu,
2995 uint32_t name_type_mask,
2996 const char *partial_name,
2997 const char *base_name_start,
2998 const char *base_name_end)
2999{
3000 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
3001 if (name_type_mask == eFunctionNameTypeMethod
3002 || name_type_mask == eFunctionNameTypeBase)
3003 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003004 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3005 if (!containing_decl_ctx)
3006 return false;
3007
3008 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3009
3010 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
3011 return false;
3012 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
3013 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003014 }
3015
3016 // Now we need to check whether the name we got back for this type matches the extra specifications
3017 // that were in the name we're looking up:
3018 if (base_name_start != partial_name || *base_name_end != '\0')
3019 {
3020 // First see if the stuff to the left matches the full name. To do that let's see if
3021 // we can pull out the mips linkage name attribute:
3022
3023 Mangled best_name;
3024
3025 DWARFDebugInfoEntry::Attributes attributes;
3026 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3027 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3028 if (idx != UINT32_MAX)
3029 {
3030 DWARFFormValue form_value;
3031 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3032 {
3033 const char *name = form_value.AsCString(&get_debug_str_data());
3034 best_name.SetValue (name, true);
3035 }
3036 }
3037 if (best_name)
3038 {
3039 const char *demangled = best_name.GetDemangledName().GetCString();
3040 if (demangled)
3041 {
3042 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003043 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3044 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003045 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003046 else
3047 {
3048 // Sort out the case where our name is something like "Process::Destroy" and the match is
3049 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3050 // namespace boundaries...
3051
3052 if (partial_name[0] == ':' && partial_name[1] == ':')
3053 {
3054 // The partial name was already on a namespace boundary so all matches are good.
3055 return true;
3056 }
3057 else if (partial_in_demangled == demangled)
3058 {
3059 // They both start the same, so this is an good match.
3060 return true;
3061 }
3062 else
3063 {
3064 if (partial_in_demangled - demangled == 1)
3065 {
3066 // Only one character difference, can't be a namespace boundary...
3067 return false;
3068 }
3069 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3070 {
3071 // We are on a namespace boundary, so this is also good.
3072 return true;
3073 }
3074 else
3075 return false;
3076 }
3077 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003078 }
3079 }
3080 }
3081
3082 return true;
3083}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003084
Greg Clayton0c5cd902010-06-28 21:30:43 +00003085uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003086SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003087 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003088 uint32_t name_type_mask,
3089 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003090 bool append,
3091 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003092{
3093 Timer scoped_timer (__PRETTY_FUNCTION__,
3094 "SymbolFileDWARF::FindFunctions (name = '%s')",
3095 name.AsCString());
3096
Greg Clayton21f2a492011-10-06 00:09:08 +00003097 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3098
3099 if (log)
3100 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003101 GetObjectFile()->GetModule()->LogMessage (log.get(),
3102 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3103 name.GetCString(),
3104 name_type_mask,
3105 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003106 }
3107
Greg Clayton0c5cd902010-06-28 21:30:43 +00003108 // If we aren't appending the results to this list, then clear the list
3109 if (!append)
3110 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003111
3112 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3113 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003114
3115 // If name is empty then we won't find anything.
3116 if (name.IsEmpty())
3117 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003118
3119 // Remember how many sc_list are in the list before we search in case
3120 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003121
Greg Clayton9e315582011-09-02 04:03:59 +00003122 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003123
Jim Ingham4cda6e02011-10-07 22:23:45 +00003124 const char *name_cstr = name.GetCString();
3125 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3126 const char *base_name_start = name_cstr;
3127 const char *base_name_end = name_cstr + strlen(name_cstr);
3128
3129 if (name_type_mask & eFunctionNameTypeAuto)
3130 {
3131 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3132 effective_name_type_mask = eFunctionNameTypeFull;
3133 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3134 effective_name_type_mask = eFunctionNameTypeFull;
3135 else
3136 {
3137 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3138 effective_name_type_mask |= eFunctionNameTypeSelector;
3139
3140 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3141 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3142 }
3143 }
3144 else
3145 {
3146 effective_name_type_mask = name_type_mask;
3147 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3148 {
3149 // If they've asked for a CPP method or function name and it can't be that, we don't
3150 // even need to search for CPP methods or names.
3151 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3152 {
3153 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3154 if (effective_name_type_mask == eFunctionNameTypeNone)
3155 return 0;
3156 }
3157 }
3158
3159 if (effective_name_type_mask & eFunctionNameTypeSelector)
3160 {
3161 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3162 {
3163 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3164 if (effective_name_type_mask == eFunctionNameTypeNone)
3165 return 0;
3166 }
3167 }
3168 }
3169
3170 DWARFDebugInfo* info = DebugInfo();
3171 if (info == NULL)
3172 return 0;
3173
Greg Claytonaa044962011-10-13 00:59:38 +00003174 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003175 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003176 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003177 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003178 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003179
3180 DIEArray die_offsets;
3181
3182 uint32_t num_matches = 0;
3183
3184 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003185 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003186 // If they asked for the full name, match what they typed. At some point we may
3187 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3188 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003189 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003190 for (uint32_t i = 0; i < num_matches; i++)
3191 {
Greg Clayton95d87902011-11-11 03:16:25 +00003192 const dw_offset_t die_offset = die_offsets[i];
3193 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003194 if (die)
3195 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003196 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3197 continue;
3198
Sean Callanan9df05fb2012-02-10 22:52:19 +00003199 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3200 continue;
3201
Greg Claytonaa044962011-10-13 00:59:38 +00003202 ResolveFunction (dwarf_cu, die, sc_list);
3203 }
Greg Clayton95d87902011-11-11 03:16:25 +00003204 else
3205 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003206 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3207 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003208 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003209 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003210 }
3211 else
3212 {
3213 if (effective_name_type_mask & eFunctionNameTypeSelector)
3214 {
3215 if (namespace_decl && *namespace_decl)
3216 return 0; // no selectors in namespaces
3217
3218 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3219 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3220 // and if it is an ObjC method name, we're good.
3221
3222 for (uint32_t i = 0; i < num_matches; i++)
3223 {
Greg Clayton95d87902011-11-11 03:16:25 +00003224 const dw_offset_t die_offset = die_offsets[i];
3225 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003226 if (die)
3227 {
3228 const char *die_name = die->GetName(this, dwarf_cu);
3229 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003230 {
3231 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3232 continue;
3233
Greg Clayton97fbc342011-10-20 22:30:33 +00003234 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003235 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003236 }
Greg Clayton95d87902011-11-11 03:16:25 +00003237 else
3238 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003239 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3240 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003241 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003242 }
3243 die_offsets.clear();
3244 }
3245
3246 if (effective_name_type_mask & eFunctionNameTypeMethod
3247 || effective_name_type_mask & eFunctionNameTypeBase)
3248 {
3249 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3250 (namespace_decl && *namespace_decl))
3251 return 0; // no methods in namespaces
3252
3253 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3254 // extract the base name, look that up, and if there is any other information in the name we were
3255 // passed in we have to post-filter based on that.
3256
3257 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3258 std::string base_name(base_name_start, base_name_end - base_name_start);
3259 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3260
3261 for (uint32_t i = 0; i < num_matches; i++)
3262 {
Greg Clayton95d87902011-11-11 03:16:25 +00003263 const dw_offset_t die_offset = die_offsets[i];
3264 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003265 if (die)
3266 {
3267 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3268 continue;
3269
3270 if (!FunctionDieMatchesPartialName(die,
3271 dwarf_cu,
3272 effective_name_type_mask,
3273 name_cstr,
3274 base_name_start,
3275 base_name_end))
3276 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003277
3278 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3279 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003280
3281 // If we get to here, the die is good, and we should add it:
3282 ResolveFunction (dwarf_cu, die, sc_list);
3283 }
Greg Clayton95d87902011-11-11 03:16:25 +00003284 else
3285 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003286 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3287 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003288 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003289 }
3290 die_offsets.clear();
3291 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003292 }
3293 }
Greg Clayton7f995132011-10-04 22:41:51 +00003294 }
3295 else
3296 {
3297
3298 // Index the DWARF if we haven't already
3299 if (!m_indexed)
3300 Index ();
3301
Greg Clayton7f995132011-10-04 22:41:51 +00003302 if (name_type_mask & eFunctionNameTypeFull)
3303 FindFunctions (name, m_function_fullname_index, sc_list);
3304
Jim Ingham4cda6e02011-10-07 22:23:45 +00003305 std::string base_name(base_name_start, base_name_end - base_name_start);
3306 ConstString base_name_const(base_name.c_str());
3307 DIEArray die_offsets;
3308 DWARFCompileUnit *dwarf_cu = NULL;
3309
3310 if (effective_name_type_mask & eFunctionNameTypeBase)
3311 {
3312 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003313 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003314 {
Greg Claytonaa044962011-10-13 00:59:38 +00003315 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3316 if (die)
3317 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003318 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3319 continue;
3320
Greg Claytonaa044962011-10-13 00:59:38 +00003321 if (!FunctionDieMatchesPartialName(die,
3322 dwarf_cu,
3323 effective_name_type_mask,
3324 name_cstr,
3325 base_name_start,
3326 base_name_end))
3327 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003328
Sean Callanan9df05fb2012-02-10 22:52:19 +00003329 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3330 continue;
3331
Greg Claytonaa044962011-10-13 00:59:38 +00003332 // If we get to here, the die is good, and we should add it:
3333 ResolveFunction (dwarf_cu, die, sc_list);
3334 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003335 }
3336 die_offsets.clear();
3337 }
3338
Jim Inghamea8005a2011-10-11 01:18:11 +00003339 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003340 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003341 if (namespace_decl && *namespace_decl)
3342 return 0; // no methods in namespaces
3343
Jim Ingham4cda6e02011-10-07 22:23:45 +00003344 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3345 {
Greg Claytonaa044962011-10-13 00:59:38 +00003346 for (uint32_t i = 0; i < num_base; i++)
3347 {
3348 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3349 if (die)
3350 {
3351 if (!FunctionDieMatchesPartialName(die,
3352 dwarf_cu,
3353 effective_name_type_mask,
3354 name_cstr,
3355 base_name_start,
3356 base_name_end))
3357 continue;
3358
Sean Callanan9df05fb2012-02-10 22:52:19 +00003359 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3360 continue;
3361
Greg Claytonaa044962011-10-13 00:59:38 +00003362 // If we get to here, the die is good, and we should add it:
3363 ResolveFunction (dwarf_cu, die, sc_list);
3364 }
3365 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003366 }
3367 die_offsets.clear();
3368 }
Greg Clayton7f995132011-10-04 22:41:51 +00003369
Sean Callanan213fdb82011-10-13 01:49:10 +00003370 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003371 {
Greg Clayton7f995132011-10-04 22:41:51 +00003372 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003373 }
3374
Greg Clayton4d01ace2011-09-29 16:58:15 +00003375 }
3376
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003377 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003378 const uint32_t num_matches = sc_list.GetSize() - original_size;
3379
3380 if (log && num_matches > 0)
3381 {
3382 GetObjectFile()->GetModule()->LogMessage (log.get(),
3383 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3384 name.GetCString(),
3385 name_type_mask,
3386 append,
3387 num_matches);
3388 }
3389 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003390}
3391
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003392uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003393SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003394{
3395 Timer scoped_timer (__PRETTY_FUNCTION__,
3396 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3397 regex.GetText());
3398
Greg Clayton21f2a492011-10-06 00:09:08 +00003399 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3400
3401 if (log)
3402 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003403 GetObjectFile()->GetModule()->LogMessage (log.get(),
3404 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3405 regex.GetText(),
3406 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003407 }
3408
3409
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003410 // If we aren't appending the results to this list, then clear the list
3411 if (!append)
3412 sc_list.Clear();
3413
3414 // Remember how many sc_list are in the list before we search in case
3415 // we are appending the results to a variable list.
3416 uint32_t original_size = sc_list.GetSize();
3417
Greg Clayton97fbc342011-10-20 22:30:33 +00003418 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003419 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003420 if (m_apple_names_ap.get())
3421 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003422 }
3423 else
3424 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003425 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003426 if (!m_indexed)
3427 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003428
Greg Clayton7f995132011-10-04 22:41:51 +00003429 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430
Greg Clayton7f995132011-10-04 22:41:51 +00003431 FindFunctions (regex, m_function_fullname_index, sc_list);
3432 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003433
3434 // Return the number of variable that were appended to the list
3435 return sc_list.GetSize() - original_size;
3436}
Jim Ingham318c9f22011-08-26 19:44:13 +00003437
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003438uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003439SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3440 const ConstString &name,
3441 const lldb_private::ClangNamespaceDecl *namespace_decl,
3442 bool append,
3443 uint32_t max_matches,
3444 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003445{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003446 DWARFDebugInfo* info = DebugInfo();
3447 if (info == NULL)
3448 return 0;
3449
Greg Clayton21f2a492011-10-06 00:09:08 +00003450 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3451
3452 if (log)
3453 {
Greg Clayton437a1352012-04-09 22:43:43 +00003454 if (namespace_decl)
3455 {
3456 GetObjectFile()->GetModule()->LogMessage (log.get(),
3457 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3458 name.GetCString(),
3459 namespace_decl->GetNamespaceDecl(),
3460 namespace_decl->GetQualifiedName().c_str(),
3461 append,
3462 max_matches);
3463 }
3464 else
3465 {
3466 GetObjectFile()->GetModule()->LogMessage (log.get(),
3467 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3468 name.GetCString(),
3469 append,
3470 max_matches);
3471 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003472 }
3473
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003474 // If we aren't appending the results to this list, then clear the list
3475 if (!append)
3476 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003477
3478 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3479 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003480
Greg Claytond4a2b372011-09-12 23:21:58 +00003481 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003482
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_types_ap.get())
3486 {
3487 const char *name_cstr = name.GetCString();
3488 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3489 }
Greg Clayton7f995132011-10-04 22:41:51 +00003490 }
3491 else
3492 {
3493 if (!m_indexed)
3494 Index ();
3495
3496 m_type_index.Find (name, die_offsets);
3497 }
3498
Greg Clayton437a1352012-04-09 22:43:43 +00003499 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003500
Greg Clayton437a1352012-04-09 22:43:43 +00003501 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003502 {
Greg Clayton7f995132011-10-04 22:41:51 +00003503 const uint32_t initial_types_size = types.GetSize();
3504 DWARFCompileUnit* dwarf_cu = NULL;
3505 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003506 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003507 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003508 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003509 const dw_offset_t die_offset = die_offsets[i];
3510 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3511
Greg Clayton95d87902011-11-11 03:16:25 +00003512 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003513 {
Greg Clayton95d87902011-11-11 03:16:25 +00003514 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3515 continue;
3516
3517 Type *matching_type = ResolveType (dwarf_cu, die);
3518 if (matching_type)
3519 {
3520 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003521 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003522 if (types.GetSize() >= max_matches)
3523 break;
3524 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003525 }
Greg Clayton95d87902011-11-11 03:16:25 +00003526 else
3527 {
3528 if (m_using_apple_tables)
3529 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003530 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3531 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003532 }
3533 }
3534
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003535 }
Greg Clayton437a1352012-04-09 22:43:43 +00003536 const uint32_t num_matches = types.GetSize() - initial_types_size;
3537 if (log && num_matches)
3538 {
3539 if (namespace_decl)
3540 {
3541 GetObjectFile()->GetModule()->LogMessage (log.get(),
3542 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3543 name.GetCString(),
3544 namespace_decl->GetNamespaceDecl(),
3545 namespace_decl->GetQualifiedName().c_str(),
3546 append,
3547 max_matches,
3548 num_matches);
3549 }
3550 else
3551 {
3552 GetObjectFile()->GetModule()->LogMessage (log.get(),
3553 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3554 name.GetCString(),
3555 append,
3556 max_matches,
3557 num_matches);
3558 }
3559 }
3560 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003561 }
Greg Clayton7f995132011-10-04 22:41:51 +00003562 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003563}
3564
3565
Greg Clayton526e5af2010-11-13 03:52:47 +00003566ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003567SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003568 const ConstString &name,
3569 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003570{
Greg Clayton21f2a492011-10-06 00:09:08 +00003571 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3572
3573 if (log)
3574 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003575 GetObjectFile()->GetModule()->LogMessage (log.get(),
3576 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3577 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003578 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003579
3580 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3581 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003582
Greg Clayton526e5af2010-11-13 03:52:47 +00003583 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003584 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003585 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003586 {
Greg Clayton7f995132011-10-04 22:41:51 +00003587 DIEArray die_offsets;
3588
Greg Clayton526e5af2010-11-13 03:52:47 +00003589 // Index if we already haven't to make sure the compile units
3590 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003591 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003592 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003593 if (m_apple_namespaces_ap.get())
3594 {
3595 const char *name_cstr = name.GetCString();
3596 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3597 }
Greg Clayton7f995132011-10-04 22:41:51 +00003598 }
3599 else
3600 {
3601 if (!m_indexed)
3602 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003603
Greg Clayton7f995132011-10-04 22:41:51 +00003604 m_namespace_index.Find (name, die_offsets);
3605 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003606
3607 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003608 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003609 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003610 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003611 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003612 DWARFDebugInfo* debug_info = DebugInfo();
3613 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003614 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003615 const dw_offset_t die_offset = die_offsets[i];
3616 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003617
Greg Clayton95d87902011-11-11 03:16:25 +00003618 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003619 {
Greg Clayton95d87902011-11-11 03:16:25 +00003620 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3621 continue;
3622
3623 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3624 if (clang_namespace_decl)
3625 {
3626 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3627 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003628 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003629 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003630 }
Greg Clayton95d87902011-11-11 03:16:25 +00003631 else
3632 {
3633 if (m_using_apple_tables)
3634 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003635 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3636 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003637 }
3638 }
3639
Greg Clayton526e5af2010-11-13 03:52:47 +00003640 }
3641 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003642 }
Greg Clayton437a1352012-04-09 22:43:43 +00003643 if (log && namespace_decl.GetNamespaceDecl())
3644 {
3645 GetObjectFile()->GetModule()->LogMessage (log.get(),
3646 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3647 name.GetCString(),
3648 namespace_decl.GetNamespaceDecl(),
3649 namespace_decl.GetQualifiedName().c_str());
3650 }
3651
Greg Clayton526e5af2010-11-13 03:52:47 +00003652 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003653}
3654
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003655uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003656SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003657{
3658 // Remember how many sc_list are in the list before we search in case
3659 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003660 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661
3662 const uint32_t num_die_offsets = die_offsets.size();
3663 // Parse all of the types we found from the pubtypes matches
3664 uint32_t i;
3665 uint32_t num_matches = 0;
3666 for (i = 0; i < num_die_offsets; ++i)
3667 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003668 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3669 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003670 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003671 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003672 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003673 ++num_matches;
3674 if (num_matches >= max_matches)
3675 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003676 }
3677 }
3678
3679 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003680 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003681}
3682
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003683
3684size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003685SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3686 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003687 DWARFCompileUnit* dwarf_cu,
3688 const DWARFDebugInfoEntry *parent_die,
3689 bool skip_artificial,
3690 bool &is_static,
3691 TypeList* type_list,
3692 std::vector<clang_type_t>& function_param_types,
3693 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003694 unsigned &type_quals,
3695 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003696{
3697 if (parent_die == NULL)
3698 return 0;
3699
Greg Claytond88d7592010-09-15 08:33:30 +00003700 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3701
Greg Clayton7fedea22010-11-16 02:10:54 +00003702 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003703 const DWARFDebugInfoEntry *die;
3704 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3705 {
3706 dw_tag_t tag = die->Tag();
3707 switch (tag)
3708 {
3709 case DW_TAG_formal_parameter:
3710 {
3711 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003712 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003713 if (num_attributes > 0)
3714 {
3715 const char *name = NULL;
3716 Declaration decl;
3717 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003718 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003719 // one of None, Auto, Register, Extern, Static, PrivateExtern
3720
Sean Callanane2ef6e32010-09-23 03:01:22 +00003721 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003722 uint32_t i;
3723 for (i=0; i<num_attributes; ++i)
3724 {
3725 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3726 DWARFFormValue form_value;
3727 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3728 {
3729 switch (attr)
3730 {
3731 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3732 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3733 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3734 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3735 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003736 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003737 case DW_AT_location:
3738 // if (form_value.BlockData())
3739 // {
3740 // const DataExtractor& debug_info_data = debug_info();
3741 // uint32_t block_length = form_value.Unsigned();
3742 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3743 // }
3744 // else
3745 // {
3746 // }
3747 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003748 case DW_AT_const_value:
3749 case DW_AT_default_value:
3750 case DW_AT_description:
3751 case DW_AT_endianity:
3752 case DW_AT_is_optional:
3753 case DW_AT_segment:
3754 case DW_AT_variable_parameter:
3755 default:
3756 case DW_AT_abstract_origin:
3757 case DW_AT_sibling:
3758 break;
3759 }
3760 }
3761 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003762
Greg Clayton0fffff52010-09-24 05:15:53 +00003763 bool skip = false;
3764 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003765 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003766 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003767 {
3768 // In order to determine if a C++ member function is
3769 // "const" we have to look at the const-ness of "this"...
3770 // Ugly, but that
3771 if (arg_idx == 0)
3772 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003773 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003774 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003775 // Often times compilers omit the "this" name for the
3776 // specification DIEs, so we can't rely upon the name
3777 // being in the formal parameter DIE...
3778 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003779 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003780 Type *this_type = ResolveTypeUID (param_type_die_offset);
3781 if (this_type)
3782 {
3783 uint32_t encoding_mask = this_type->GetEncodingMask();
3784 if (encoding_mask & Type::eEncodingIsPointerUID)
3785 {
3786 is_static = false;
3787
3788 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3789 type_quals |= clang::Qualifiers::Const;
3790 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3791 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003792 }
3793 }
3794 }
3795 }
3796 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003797 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003798 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003799 else
3800 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003801
Greg Clayton0fffff52010-09-24 05:15:53 +00003802 // HACK: Objective C formal parameters "self" and "_cmd"
3803 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00003804 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3805 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00003806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003807 switch (comp_unit->GetLanguage())
3808 {
3809 case eLanguageTypeObjC:
3810 case eLanguageTypeObjC_plus_plus:
3811 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3812 skip = true;
3813 break;
3814 default:
3815 break;
3816 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003817 }
3818 }
3819 }
3820
3821 if (!skip)
3822 {
3823 Type *type = ResolveTypeUID(param_type_die_offset);
3824 if (type)
3825 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003826 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003827
Greg Clayton42ce2f32011-12-12 21:50:19 +00003828 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3829 type->GetClangForwardType(),
3830 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003831 assert(param_var_decl);
3832 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00003833
3834 GetClangASTContext().SetMetadata((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00003835 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003836 }
3837 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003838 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003839 }
3840 break;
3841
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003842 case DW_TAG_template_type_parameter:
3843 case DW_TAG_template_value_parameter:
3844 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3845 break;
3846
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003847 default:
3848 break;
3849 }
3850 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003851 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003852}
3853
3854size_t
3855SymbolFileDWARF::ParseChildEnumerators
3856(
3857 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003858 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003859 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003860 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003861 const DWARFDebugInfoEntry *parent_die
3862)
3863{
3864 if (parent_die == NULL)
3865 return 0;
3866
3867 size_t enumerators_added = 0;
3868 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003869 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3870
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003871 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3872 {
3873 const dw_tag_t tag = die->Tag();
3874 if (tag == DW_TAG_enumerator)
3875 {
3876 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003877 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003878 if (num_child_attributes > 0)
3879 {
3880 const char *name = NULL;
3881 bool got_value = false;
3882 int64_t enum_value = 0;
3883 Declaration decl;
3884
3885 uint32_t i;
3886 for (i=0; i<num_child_attributes; ++i)
3887 {
3888 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3889 DWARFFormValue form_value;
3890 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3891 {
3892 switch (attr)
3893 {
3894 case DW_AT_const_value:
3895 got_value = true;
3896 enum_value = form_value.Unsigned();
3897 break;
3898
3899 case DW_AT_name:
3900 name = form_value.AsCString(&get_debug_str_data());
3901 break;
3902
3903 case DW_AT_description:
3904 default:
3905 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3906 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3907 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3908 case DW_AT_sibling:
3909 break;
3910 }
3911 }
3912 }
3913
3914 if (name && name[0] && got_value)
3915 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003916 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3917 enumerator_clang_type,
3918 decl,
3919 name,
3920 enum_value,
3921 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003922 ++enumerators_added;
3923 }
3924 }
3925 }
3926 }
3927 return enumerators_added;
3928}
3929
3930void
3931SymbolFileDWARF::ParseChildArrayInfo
3932(
3933 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003934 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003935 const DWARFDebugInfoEntry *parent_die,
3936 int64_t& first_index,
3937 std::vector<uint64_t>& element_orders,
3938 uint32_t& byte_stride,
3939 uint32_t& bit_stride
3940)
3941{
3942 if (parent_die == NULL)
3943 return;
3944
3945 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003946 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003947 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3948 {
3949 const dw_tag_t tag = die->Tag();
3950 switch (tag)
3951 {
3952 case DW_TAG_enumerator:
3953 {
3954 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003955 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003956 if (num_child_attributes > 0)
3957 {
3958 const char *name = NULL;
3959 bool got_value = false;
3960 int64_t enum_value = 0;
3961
3962 uint32_t i;
3963 for (i=0; i<num_child_attributes; ++i)
3964 {
3965 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3966 DWARFFormValue form_value;
3967 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3968 {
3969 switch (attr)
3970 {
3971 case DW_AT_const_value:
3972 got_value = true;
3973 enum_value = form_value.Unsigned();
3974 break;
3975
3976 case DW_AT_name:
3977 name = form_value.AsCString(&get_debug_str_data());
3978 break;
3979
3980 case DW_AT_description:
3981 default:
3982 case DW_AT_decl_file:
3983 case DW_AT_decl_line:
3984 case DW_AT_decl_column:
3985 case DW_AT_sibling:
3986 break;
3987 }
3988 }
3989 }
3990 }
3991 }
3992 break;
3993
3994 case DW_TAG_subrange_type:
3995 {
3996 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003997 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003998 if (num_child_attributes > 0)
3999 {
4000 const char *name = NULL;
4001 bool got_value = false;
4002 uint64_t byte_size = 0;
4003 int64_t enum_value = 0;
4004 uint64_t num_elements = 0;
4005 uint64_t lower_bound = 0;
4006 uint64_t upper_bound = 0;
4007 uint32_t i;
4008 for (i=0; i<num_child_attributes; ++i)
4009 {
4010 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4011 DWARFFormValue form_value;
4012 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4013 {
4014 switch (attr)
4015 {
4016 case DW_AT_const_value:
4017 got_value = true;
4018 enum_value = form_value.Unsigned();
4019 break;
4020
4021 case DW_AT_name:
4022 name = form_value.AsCString(&get_debug_str_data());
4023 break;
4024
4025 case DW_AT_count:
4026 num_elements = form_value.Unsigned();
4027 break;
4028
4029 case DW_AT_bit_stride:
4030 bit_stride = form_value.Unsigned();
4031 break;
4032
4033 case DW_AT_byte_stride:
4034 byte_stride = form_value.Unsigned();
4035 break;
4036
4037 case DW_AT_byte_size:
4038 byte_size = form_value.Unsigned();
4039 break;
4040
4041 case DW_AT_lower_bound:
4042 lower_bound = form_value.Unsigned();
4043 break;
4044
4045 case DW_AT_upper_bound:
4046 upper_bound = form_value.Unsigned();
4047 break;
4048
4049 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004050 case DW_AT_abstract_origin:
4051 case DW_AT_accessibility:
4052 case DW_AT_allocated:
4053 case DW_AT_associated:
4054 case DW_AT_data_location:
4055 case DW_AT_declaration:
4056 case DW_AT_description:
4057 case DW_AT_sibling:
4058 case DW_AT_threads_scaled:
4059 case DW_AT_type:
4060 case DW_AT_visibility:
4061 break;
4062 }
4063 }
4064 }
4065
4066 if (upper_bound > lower_bound)
4067 num_elements = upper_bound - lower_bound + 1;
4068
4069 if (num_elements > 0)
4070 element_orders.push_back (num_elements);
4071 }
4072 }
4073 break;
4074 }
4075 }
4076}
4077
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004078TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004079SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004080{
4081 TypeSP type_sp;
4082 if (die != NULL)
4083 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004084 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004085 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004086 if (type_ptr == NULL)
4087 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004088 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004089 assert (lldb_cu);
4090 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004091 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004092 }
4093 else if (type_ptr != DIE_IS_BEING_PARSED)
4094 {
4095 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004096 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004097 }
4098
4099 }
4100 return type_sp;
4101}
4102
4103clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004104SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004105{
4106 if (die_offset != DW_INVALID_OFFSET)
4107 {
4108 DWARFCompileUnitSP cu_sp;
4109 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004110 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004111 }
4112 return NULL;
4113}
4114
Sean Callanan72e49402011-08-05 23:43:37 +00004115clang::DeclContext *
4116SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4117{
4118 if (die_offset != DW_INVALID_OFFSET)
4119 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004120 DWARFDebugInfo* debug_info = DebugInfo();
4121 if (debug_info)
4122 {
4123 DWARFCompileUnitSP cu_sp;
4124 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4125 if (die)
4126 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4127 }
Sean Callanan72e49402011-08-05 23:43:37 +00004128 }
4129 return NULL;
4130}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004131
Greg Clayton96d7d742010-11-10 23:42:09 +00004132clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004133SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004134{
Greg Clayton030a2042011-10-14 21:34:45 +00004135 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004136 {
Greg Clayton030a2042011-10-14 21:34:45 +00004137 // See if we already parsed this namespace DIE and associated it with a
4138 // uniqued namespace declaration
4139 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4140 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004141 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004142 else
4143 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004144 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4145 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004146 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4147 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4148 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004149 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004150 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004151 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004152 GetObjectFile()->GetModule()->LogMessage (log.get(),
4153 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4154 GetClangASTContext().getASTContext(),
4155 MakeUserID(die->GetOffset()),
4156 namespace_name,
4157 namespace_decl,
4158 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004159 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004160 else
4161 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004162 GetObjectFile()->GetModule()->LogMessage (log.get(),
4163 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4164 GetClangASTContext().getASTContext(),
4165 MakeUserID(die->GetOffset()),
4166 namespace_decl,
4167 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004168 }
Greg Clayton030a2042011-10-14 21:34:45 +00004169 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004170
4171 if (namespace_decl)
4172 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4173 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004174 }
4175 }
4176 return NULL;
4177}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004178
4179clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004180SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004181{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004182 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4183 if (clang_decl_ctx)
4184 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004185 // If this DIE has a specification, or an abstract origin, then trace to those.
4186
Greg Claytoncab36a32011-12-08 05:16:30 +00004187 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004188 if (die_offset != DW_INVALID_OFFSET)
4189 return GetClangDeclContextForDIEOffset (sc, die_offset);
4190
Greg Claytoncab36a32011-12-08 05:16:30 +00004191 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004192 if (die_offset != DW_INVALID_OFFSET)
4193 return GetClangDeclContextForDIEOffset (sc, die_offset);
4194
Greg Clayton3bffb082011-12-10 02:15:28 +00004195 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4196 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004197 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 +00004198 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004199 bool assert_not_being_parsed = true;
4200 ResolveTypeUID (cu, die, assert_not_being_parsed);
4201
Greg Clayton5cf58b92011-10-05 22:22:08 +00004202 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4203
4204 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004205}
4206
4207clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004208SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004209{
Greg Claytonca512b32011-01-14 04:54:56 +00004210 if (m_clang_tu_decl == NULL)
4211 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004212
Greg Clayton2bc22f82011-09-30 03:20:47 +00004213 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004214
4215 if (decl_ctx_die_copy)
4216 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004217
4218 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004219 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004220
Greg Clayton2bc22f82011-09-30 03:20:47 +00004221 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4222 if (pos != m_die_to_decl_ctx.end())
4223 return pos->second;
4224
4225 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004226 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004227 case DW_TAG_compile_unit:
4228 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004229
Greg Clayton2bc22f82011-09-30 03:20:47 +00004230 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004231 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004232 break;
4233
4234 case DW_TAG_structure_type:
4235 case DW_TAG_union_type:
4236 case DW_TAG_class_type:
4237 {
4238 Type* type = ResolveType (cu, decl_ctx_die);
4239 if (type)
4240 {
4241 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4242 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004243 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004244 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4245 if (decl_ctx)
4246 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004247 }
4248 }
Greg Claytonca512b32011-01-14 04:54:56 +00004249 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004250 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004251
Greg Clayton2bc22f82011-09-30 03:20:47 +00004252 default:
4253 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004254 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004255 }
Greg Clayton7a345282010-11-09 23:46:37 +00004256 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004257}
4258
Greg Clayton2bc22f82011-09-30 03:20:47 +00004259
4260const DWARFDebugInfoEntry *
4261SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4262{
4263 if (cu && die)
4264 {
4265 const DWARFDebugInfoEntry * const decl_die = die;
4266
4267 while (die != NULL)
4268 {
4269 // If this is the original DIE that we are searching for a declaration
4270 // for, then don't look in the cache as we don't want our own decl
4271 // context to be our decl context...
4272 if (decl_die != die)
4273 {
4274 switch (die->Tag())
4275 {
4276 case DW_TAG_compile_unit:
4277 case DW_TAG_namespace:
4278 case DW_TAG_structure_type:
4279 case DW_TAG_union_type:
4280 case DW_TAG_class_type:
4281 return die;
4282
4283 default:
4284 break;
4285 }
4286 }
4287
4288 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4289 if (die_offset != DW_INVALID_OFFSET)
4290 {
4291 DWARFCompileUnit *spec_cu = cu;
4292 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4293 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4294 if (spec_die_decl_ctx_die)
4295 return spec_die_decl_ctx_die;
4296 }
4297
4298 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4299 if (die_offset != DW_INVALID_OFFSET)
4300 {
4301 DWARFCompileUnit *abs_cu = cu;
4302 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4303 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4304 if (abs_die_decl_ctx_die)
4305 return abs_die_decl_ctx_die;
4306 }
4307
4308 die = die->GetParent();
4309 }
4310 }
4311 return NULL;
4312}
4313
4314
Greg Clayton901c5ca2011-12-03 04:40:03 +00004315Symbol *
4316SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4317{
4318 Symbol *objc_class_symbol = NULL;
4319 if (m_obj_file)
4320 {
4321 Symtab *symtab = m_obj_file->GetSymtab();
4322 if (symtab)
4323 {
4324 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4325 eSymbolTypeObjCClass,
4326 Symtab::eDebugNo,
4327 Symtab::eVisibilityAny);
4328 }
4329 }
4330 return objc_class_symbol;
4331}
4332
Greg Claytonc7f03b62012-01-12 04:33:28 +00004333// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4334// then we can end up looking through all class types for a complete type and never find
4335// the full definition. We need to know if this attribute is supported, so we determine
4336// this here and cache th result. We also need to worry about the debug map DWARF file
4337// if we are doing darwin DWARF in .o file debugging.
4338bool
4339SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4340{
4341 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4342 {
4343 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4344 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4345 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4346 else
4347 {
4348 DWARFDebugInfo* debug_info = DebugInfo();
4349 const uint32_t num_compile_units = GetNumCompileUnits();
4350 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4351 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004352 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4353 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004354 {
4355 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4356 break;
4357 }
4358 }
4359 }
4360 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4361 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4362 }
4363 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4364}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004365
4366// This function can be used when a DIE is found that is a forward declaration
4367// DIE and we want to try and find a type that has the complete definition.
4368TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004369SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4370 const ConstString &type_name,
4371 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004372{
4373
4374 TypeSP type_sp;
4375
Greg Claytonc7f03b62012-01-12 04:33:28 +00004376 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004377 return type_sp;
4378
4379 DIEArray die_offsets;
4380
4381 if (m_using_apple_tables)
4382 {
4383 if (m_apple_types_ap.get())
4384 {
4385 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004386 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004387 }
4388 }
4389 else
4390 {
4391 if (!m_indexed)
4392 Index ();
4393
4394 m_type_index.Find (type_name, die_offsets);
4395 }
4396
Greg Clayton901c5ca2011-12-03 04:40:03 +00004397 const size_t num_matches = die_offsets.size();
4398
Greg Clayton901c5ca2011-12-03 04:40:03 +00004399 DWARFCompileUnit* type_cu = NULL;
4400 const DWARFDebugInfoEntry* type_die = NULL;
4401 if (num_matches)
4402 {
4403 DWARFDebugInfo* debug_info = DebugInfo();
4404 for (size_t i=0; i<num_matches; ++i)
4405 {
4406 const dw_offset_t die_offset = die_offsets[i];
4407 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4408
4409 if (type_die)
4410 {
4411 bool try_resolving_type = false;
4412
4413 // Don't try and resolve the DIE we are looking for with the DIE itself!
4414 if (type_die != die)
4415 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004416 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004417 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004418 case DW_TAG_class_type:
4419 case DW_TAG_structure_type:
4420 try_resolving_type = true;
4421 break;
4422 default:
4423 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004424 }
4425 }
4426
4427 if (try_resolving_type)
4428 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004429 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004430 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004431
4432 if (try_resolving_type)
4433 {
4434 Type *resolved_type = ResolveType (type_cu, type_die, false);
4435 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4436 {
4437 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4438 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004439 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004440 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4441 MakeUserID(type_die->GetOffset()),
4442 MakeUserID(type_cu->GetOffset()));
4443
Greg Claytonc7f03b62012-01-12 04:33:28 +00004444 if (die)
4445 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004446 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004447 break;
4448 }
4449 }
4450 }
4451 }
4452 else
4453 {
4454 if (m_using_apple_tables)
4455 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004456 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4457 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004458 }
4459 }
4460
4461 }
4462 }
4463 return type_sp;
4464}
4465
Greg Claytona8022fa2012-04-24 21:22:41 +00004466
Greg Clayton80c26302012-02-05 06:12:47 +00004467//----------------------------------------------------------------------
4468// This function helps to ensure that the declaration contexts match for
4469// two different DIEs. Often times debug information will refer to a
4470// forward declaration of a type (the equivalent of "struct my_struct;".
4471// There will often be a declaration of that type elsewhere that has the
4472// full definition. When we go looking for the full type "my_struct", we
4473// will find one or more matches in the accelerator tables and we will
4474// then need to make sure the type was in the same declaration context
4475// as the original DIE. This function can efficiently compare two DIEs
4476// and will return true when the declaration context matches, and false
4477// when they don't.
4478//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004479bool
4480SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4481 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4482{
Greg Claytona8022fa2012-04-24 21:22:41 +00004483 if (die1 == die2)
4484 return true;
4485
4486#if defined (LLDB_CONFIGURATION_DEBUG)
4487 // You can't and shouldn't call this function with a compile unit from
4488 // two different SymbolFileDWARF instances.
4489 assert (DebugInfo()->ContainsCompileUnit (cu1));
4490 assert (DebugInfo()->ContainsCompileUnit (cu2));
4491#endif
4492
Greg Clayton890ff562012-02-02 05:48:16 +00004493 DWARFDIECollection decl_ctx_1;
4494 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004495 //The declaration DIE stack is a stack of the declaration context
4496 // DIEs all the way back to the compile unit. If a type "T" is
4497 // declared inside a class "B", and class "B" is declared inside
4498 // a class "A" and class "A" is in a namespace "lldb", and the
4499 // namespace is in a compile unit, there will be a stack of DIEs:
4500 //
4501 // [0] DW_TAG_class_type for "B"
4502 // [1] DW_TAG_class_type for "A"
4503 // [2] DW_TAG_namespace for "lldb"
4504 // [3] DW_TAG_compile_unit for the source file.
4505 //
4506 // We grab both contexts and make sure that everything matches
4507 // all the way back to the compiler unit.
4508
4509 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004510 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004511 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004512 // Make sure the context arrays have the same size, otherwise
4513 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004514 const size_t count1 = decl_ctx_1.Size();
4515 const size_t count2 = decl_ctx_2.Size();
4516 if (count1 != count2)
4517 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004518
4519 // Make sure the DW_TAG values match all the way back up the the
4520 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004521 const DWARFDebugInfoEntry *decl_ctx_die1;
4522 const DWARFDebugInfoEntry *decl_ctx_die2;
4523 size_t i;
4524 for (i=0; i<count1; i++)
4525 {
4526 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4527 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4528 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4529 return false;
4530 }
Greg Clayton890ff562012-02-02 05:48:16 +00004531#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004532
4533 // Make sure the top item in the decl context die array is always
4534 // DW_TAG_compile_unit. If it isn't then something went wrong in
4535 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004536 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004537
Greg Clayton890ff562012-02-02 05:48:16 +00004538#endif
4539 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004540 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004541 for (i=0; i<count1 - 1; i++)
4542 {
4543 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4544 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4545 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004546 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004547 // If the string was from a DW_FORM_strp, then the pointer will often
4548 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004549 if (name1 == name2)
4550 continue;
4551
4552 // Name pointers are not equal, so only compare the strings
4553 // if both are not NULL.
4554 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004555 {
Greg Clayton5569e642012-02-06 01:44:54 +00004556 // If the strings don't compare, we are done...
4557 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004558 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004559 }
4560 else
4561 {
4562 // One name was NULL while the other wasn't
4563 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004564 }
4565 }
Greg Clayton80c26302012-02-05 06:12:47 +00004566 // We made it through all of the checks and the declaration contexts
4567 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004568 return true;
4569}
Greg Clayton220a0072011-12-09 08:48:30 +00004570
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004571// This function can be used when a DIE is found that is a forward declaration
4572// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004573// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004574TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004575SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004576 const DWARFDebugInfoEntry *die,
4577 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004578{
4579 TypeSP type_sp;
4580
Greg Claytona8022fa2012-04-24 21:22:41 +00004581#if defined (LLDB_CONFIGURATION_DEBUG)
4582 // You can't and shouldn't call this function with a compile unit from
4583 // another SymbolFileDWARF instance.
4584 assert (DebugInfo()->ContainsCompileUnit (cu));
4585#endif
4586
Greg Clayton1a65ae12011-01-25 23:55:37 +00004587 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004588 return type_sp;
4589
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004590 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4591 if (log)
4592 {
4593 std::string qualified_name;
4594 die->GetQualifiedName(this, cu, qualified_name);
4595 GetObjectFile()->GetModule()->LogMessage (log.get(),
4596 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4597 die->GetOffset(),
4598 qualified_name.c_str(),
4599 type_name.GetCString());
4600 }
4601
Greg Clayton7f995132011-10-04 22:41:51 +00004602 DIEArray die_offsets;
4603
Greg Clayton97fbc342011-10-20 22:30:33 +00004604 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004605 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004606 if (m_apple_types_ap.get())
4607 {
Greg Claytond1767f02011-12-08 02:13:16 +00004608 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4609 {
Greg Claytonae920b62012-01-06 00:17:16 +00004610 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004611 }
4612 else
4613 {
4614 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4615 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004616 }
Greg Clayton7f995132011-10-04 22:41:51 +00004617 }
4618 else
4619 {
4620 if (!m_indexed)
4621 Index ();
4622
4623 m_type_index.Find (type_name, die_offsets);
4624 }
Greg Clayton7f995132011-10-04 22:41:51 +00004625
4626 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004627
Greg Clayton934cb052011-12-03 00:27:05 +00004628 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004629
4630 DWARFCompileUnit* type_cu = NULL;
4631 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004632 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004633 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004634 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004635 for (size_t i=0; i<num_matches; ++i)
4636 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004637 const dw_offset_t die_offset = die_offsets[i];
4638 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004639
Greg Clayton95d87902011-11-11 03:16:25 +00004640 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004641 {
Greg Clayton934cb052011-12-03 00:27:05 +00004642 bool try_resolving_type = false;
4643
4644 // Don't try and resolve the DIE we are looking for with the DIE itself!
4645 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004646 {
Greg Clayton934cb052011-12-03 00:27:05 +00004647 const dw_tag_t type_die_tag = type_die->Tag();
4648 // Make sure the tags match
4649 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004650 {
Greg Clayton934cb052011-12-03 00:27:05 +00004651 // The tags match, lets try resolving this type
4652 try_resolving_type = true;
4653 }
4654 else
4655 {
4656 // The tags don't match, but we need to watch our for a
4657 // forward declaration for a struct and ("struct foo")
4658 // ends up being a class ("class foo { ... };") or
4659 // vice versa.
4660 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004661 {
Greg Clayton934cb052011-12-03 00:27:05 +00004662 case DW_TAG_class_type:
4663 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4664 try_resolving_type = (die_tag == DW_TAG_structure_type);
4665 break;
4666 case DW_TAG_structure_type:
4667 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4668 try_resolving_type = (die_tag == DW_TAG_class_type);
4669 break;
4670 default:
4671 // Tags don't match, don't event try to resolve
4672 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004673 break;
4674 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004675 }
4676 }
Greg Clayton934cb052011-12-03 00:27:05 +00004677
4678 if (try_resolving_type)
4679 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004680 if (log)
4681 {
4682 std::string qualified_name;
4683 type_die->GetQualifiedName(this, cu, qualified_name);
4684 GetObjectFile()->GetModule()->LogMessage (log.get(),
4685 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4686 die->GetOffset(),
4687 type_name.GetCString(),
4688 type_die->GetOffset(),
4689 qualified_name.c_str());
4690 }
4691
Greg Clayton890ff562012-02-02 05:48:16 +00004692 // Make sure the decl contexts match all the way up
4693 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004694 {
Greg Clayton890ff562012-02-02 05:48:16 +00004695 Type *resolved_type = ResolveType (type_cu, type_die, false);
4696 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4697 {
4698 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4699 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004700 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004701 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4702 MakeUserID(type_die->GetOffset()),
4703 MakeUserID(type_cu->GetOffset()));
4704
4705 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004706 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004707 break;
4708 }
Greg Clayton934cb052011-12-03 00:27:05 +00004709 }
4710 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004711 else
4712 {
4713 if (log)
4714 {
4715 std::string qualified_name;
4716 type_die->GetQualifiedName(this, cu, qualified_name);
4717 GetObjectFile()->GetModule()->LogMessage (log.get(),
4718 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4719 die->GetOffset(),
4720 type_name.GetCString(),
4721 type_die->GetOffset(),
4722 qualified_name.c_str());
4723 }
4724 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004725 }
Greg Clayton95d87902011-11-11 03:16:25 +00004726 else
4727 {
4728 if (m_using_apple_tables)
4729 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004730 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4731 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004732 }
4733 }
4734
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004735 }
4736 }
4737 return type_sp;
4738}
4739
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004740TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004741SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4742{
4743 TypeSP type_sp;
4744
4745 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4746 if (dwarf_decl_ctx_count > 0)
4747 {
4748 const ConstString type_name(dwarf_decl_ctx[0].name);
4749 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4750
4751 if (type_name)
4752 {
4753 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4754 if (log)
4755 {
4756 GetObjectFile()->GetModule()->LogMessage (log.get(),
4757 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4758 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4759 dwarf_decl_ctx.GetQualifiedName());
4760 }
4761
4762 DIEArray die_offsets;
4763
4764 if (m_using_apple_tables)
4765 {
4766 if (m_apple_types_ap.get())
4767 {
4768 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4769 {
4770 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4771 }
4772 else
4773 {
4774 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4775 }
4776 }
4777 }
4778 else
4779 {
4780 if (!m_indexed)
4781 Index ();
4782
4783 m_type_index.Find (type_name, die_offsets);
4784 }
4785
4786 const size_t num_matches = die_offsets.size();
4787
4788
4789 DWARFCompileUnit* type_cu = NULL;
4790 const DWARFDebugInfoEntry* type_die = NULL;
4791 if (num_matches)
4792 {
4793 DWARFDebugInfo* debug_info = DebugInfo();
4794 for (size_t i=0; i<num_matches; ++i)
4795 {
4796 const dw_offset_t die_offset = die_offsets[i];
4797 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4798
4799 if (type_die)
4800 {
4801 bool try_resolving_type = false;
4802
4803 // Don't try and resolve the DIE we are looking for with the DIE itself!
4804 const dw_tag_t type_tag = type_die->Tag();
4805 // Make sure the tags match
4806 if (type_tag == tag)
4807 {
4808 // The tags match, lets try resolving this type
4809 try_resolving_type = true;
4810 }
4811 else
4812 {
4813 // The tags don't match, but we need to watch our for a
4814 // forward declaration for a struct and ("struct foo")
4815 // ends up being a class ("class foo { ... };") or
4816 // vice versa.
4817 switch (type_tag)
4818 {
4819 case DW_TAG_class_type:
4820 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4821 try_resolving_type = (tag == DW_TAG_structure_type);
4822 break;
4823 case DW_TAG_structure_type:
4824 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4825 try_resolving_type = (tag == DW_TAG_class_type);
4826 break;
4827 default:
4828 // Tags don't match, don't event try to resolve
4829 // using this type whose name matches....
4830 break;
4831 }
4832 }
4833
4834 if (try_resolving_type)
4835 {
4836 DWARFDeclContext type_dwarf_decl_ctx;
4837 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
4838
4839 if (log)
4840 {
4841 GetObjectFile()->GetModule()->LogMessage (log.get(),
4842 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
4843 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4844 dwarf_decl_ctx.GetQualifiedName(),
4845 type_die->GetOffset(),
4846 type_dwarf_decl_ctx.GetQualifiedName());
4847 }
4848
4849 // Make sure the decl contexts match all the way up
4850 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
4851 {
4852 Type *resolved_type = ResolveType (type_cu, type_die, false);
4853 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4854 {
4855 type_sp = resolved_type->shared_from_this();
4856 break;
4857 }
4858 }
4859 }
4860 else
4861 {
4862 if (log)
4863 {
4864 std::string qualified_name;
4865 type_die->GetQualifiedName(this, type_cu, qualified_name);
4866 GetObjectFile()->GetModule()->LogMessage (log.get(),
4867 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
4868 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4869 dwarf_decl_ctx.GetQualifiedName(),
4870 type_die->GetOffset(),
4871 qualified_name.c_str());
4872 }
4873 }
4874 }
4875 else
4876 {
4877 if (m_using_apple_tables)
4878 {
4879 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4880 die_offset, type_name.GetCString());
4881 }
4882 }
4883
4884 }
4885 }
4886 }
4887 }
4888 return type_sp;
4889}
4890
Greg Clayton4116e932012-05-15 02:33:01 +00004891bool
4892SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type,
4893 DWARFCompileUnit* src_cu,
4894 const DWARFDebugInfoEntry *src_class_die,
4895 DWARFCompileUnit* dst_cu,
4896 const DWARFDebugInfoEntry *dst_class_die)
4897{
4898 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
4899 return false;
4900 if (src_class_die->Tag() != dst_class_die->Tag())
4901 return false;
4902
4903 // We need to complete the class type so we can get all of the method types
4904 // parsed so we can then unique those types to their equivalent counterparts
4905 // in "dst_cu" and "dst_class_die"
4906 class_type->GetClangFullType();
4907
4908 const DWARFDebugInfoEntry *src_die;
4909 const DWARFDebugInfoEntry *dst_die;
4910 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
4911 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
4912 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
4913 {
4914 if (src_die->Tag() == DW_TAG_subprogram)
4915 {
4916 const char *src_name = src_die->GetMangledName (this, src_cu);
4917 if (src_name)
4918 src_name_to_die.Append(ConstString(src_name).GetCString(), src_die);
4919 }
4920 }
4921 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
4922 {
4923 if (dst_die->Tag() == DW_TAG_subprogram)
4924 {
4925 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4926 if (dst_name)
4927 dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die);
4928 }
4929 }
4930 const uint32_t src_size = src_name_to_die.GetSize ();
4931 const uint32_t dst_size = dst_name_to_die.GetSize ();
4932 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
4933
4934 if (src_size && dst_size)
4935 {
4936 uint32_t idx;
4937 for (idx = 0; idx < src_size; ++idx)
4938 {
4939 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4940 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4941
4942 if (src_die->Tag() != dst_die->Tag())
4943 {
4944 if (log)
4945 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)",
4946 src_class_die->GetOffset(),
4947 dst_class_die->GetOffset(),
4948 src_die->GetOffset(),
4949 DW_TAG_value_to_name(src_die->Tag()),
4950 dst_die->GetOffset(),
4951 DW_TAG_value_to_name(src_die->Tag()));
4952 return false;
4953 }
4954
4955 const char *src_name = src_die->GetMangledName (this, src_cu);
4956 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4957
4958 // Make sure the names match
4959 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
4960 continue;
4961
4962 if (log)
4963 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)",
4964 src_class_die->GetOffset(),
4965 dst_class_die->GetOffset(),
4966 src_die->GetOffset(),
4967 src_name,
4968 dst_die->GetOffset(),
4969 dst_name);
4970
4971 return false;
4972 }
4973
4974 for (idx = 0; idx < src_size; ++idx)
4975 {
4976 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4977 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4978
4979 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
4980 if (src_decl_ctx)
4981 {
4982 if (log)
4983 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
4984 LinkDeclContextToDIE (src_decl_ctx, dst_die);
4985 }
4986 else
4987 {
4988 if (log)
4989 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset());
4990 }
4991
4992 Type *src_child_type = m_die_to_type[src_die];
4993 if (src_child_type)
4994 {
4995 if (log)
4996 log->Printf ("uniquing type %p (uid=0x%llx) from 0x%8.8x for 0x%8.8x\n", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
4997 m_die_to_type[dst_die] = src_child_type;
4998 }
4999 else
5000 {
5001 if (log)
5002 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset());
5003 }
5004 }
5005 return true;
5006 }
5007 else
5008 {
5009 if (log)
5010 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x has %u methods and 0x%8.8x has %u",
5011 src_class_die->GetOffset(),
5012 dst_class_die->GetOffset(),
5013 src_die->GetOffset(),
5014 src_size,
5015 dst_die->GetOffset(),
5016 dst_size);
5017 }
5018 return false;
5019}
Greg Claytona8022fa2012-04-24 21:22:41 +00005020
5021TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005022SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005023{
5024 TypeSP type_sp;
5025
Greg Clayton1be10fc2010-09-29 01:12:09 +00005026 if (type_is_new_ptr)
5027 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005028
5029#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5030 static DIEStack g_die_stack;
5031 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5032#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005033
Sean Callananc7fbf732010-08-06 00:32:49 +00005034 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005035 if (die != NULL)
5036 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005037 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005038 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005039 {
5040 const DWARFDebugInfoEntry *context_die;
5041 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5042
Greg Clayton1fba87112012-02-09 20:03:49 +00005043 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 +00005044 die->GetOffset(),
5045 context,
5046 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005047 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005048 die->GetName(this, dwarf_cu));
5049
5050#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5051 scoped_die_logger.Push (dwarf_cu, die);
5052 g_die_stack.LogDIEs(log.get(), this);
5053#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005054 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005055//
5056// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5057// if (log && dwarf_cu)
5058// {
5059// StreamString s;
5060// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005061// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005062//
5063// }
Jim Ingham16746d12011-08-25 23:21:43 +00005064
Greg Clayton594e5ed2010-09-27 21:07:38 +00005065 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005066 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005067 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005068 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005069 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005070 if (type_is_new_ptr)
5071 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005072
Greg Clayton594e5ed2010-09-27 21:07:38 +00005073 const dw_tag_t tag = die->Tag();
5074
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005075 bool is_forward_declaration = false;
5076 DWARFDebugInfoEntry::Attributes attributes;
5077 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005078 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005079 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5080 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00005081 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00005082 Declaration decl;
5083
Greg Clayton4957bf62010-09-30 21:49:03 +00005084 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005085 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005086
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005087 dw_attr_t attr;
5088
5089 switch (tag)
5090 {
5091 case DW_TAG_base_type:
5092 case DW_TAG_pointer_type:
5093 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005094 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005095 case DW_TAG_typedef:
5096 case DW_TAG_const_type:
5097 case DW_TAG_restrict_type:
5098 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005099 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005100 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005101 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005102 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005103
Greg Claytond88d7592010-09-15 08:33:30 +00005104 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005105 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005106 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5107
5108 if (num_attributes > 0)
5109 {
5110 uint32_t i;
5111 for (i=0; i<num_attributes; ++i)
5112 {
5113 attr = attributes.AttributeAtIndex(i);
5114 DWARFFormValue form_value;
5115 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5116 {
5117 switch (attr)
5118 {
5119 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5120 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5121 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5122 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005123
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005124 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005125 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5126 // include the "&"...
5127 if (tag == DW_TAG_reference_type)
5128 {
5129 if (strchr (type_name_cstr, '&') == NULL)
5130 type_name_cstr = NULL;
5131 }
5132 if (type_name_cstr)
5133 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005134 break;
Greg Clayton36909642011-03-15 04:38:20 +00005135 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005136 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5137 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5138 default:
5139 case DW_AT_sibling:
5140 break;
5141 }
5142 }
5143 }
5144 }
5145
Greg Clayton81c22f62011-10-19 18:09:39 +00005146 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 +00005147
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005148 switch (tag)
5149 {
5150 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005151 break;
5152
Greg Claytond4436412011-10-28 21:00:00 +00005153 case DW_TAG_unspecified_type:
5154 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5155 {
5156 resolve_state = Type::eResolveStateFull;
5157 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5158 break;
5159 }
5160 // Fall through to base type below in case we can handle the type there...
5161
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005162 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005163 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005164 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5165 encoding,
5166 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005167 break;
5168
Sean Callanance8af862012-05-21 23:31:51 +00005169 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5170 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5171 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5172 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5173 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5174 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5175 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005176 }
5177
Greg Claytonc7f03b62012-01-12 04:33:28 +00005178 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005179 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005180 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
5181 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005182 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005183 static ConstString g_objc_type_name_id("id");
5184 static ConstString g_objc_type_name_Class("Class");
5185 static ConstString g_objc_type_name_selector("SEL");
5186
5187 if (type_name_const_str == g_objc_type_name_id)
5188 {
5189 if (log)
5190 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5191 die->GetOffset(),
5192 DW_TAG_value_to_name(die->Tag()),
5193 die->GetName(this, dwarf_cu));
5194 clang_type = ast.GetBuiltInType_objc_id();
5195 encoding_data_type = Type::eEncodingIsUID;
5196 encoding_uid = LLDB_INVALID_UID;
5197 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005198
Greg Claytonc7f03b62012-01-12 04:33:28 +00005199 }
5200 else if (type_name_const_str == g_objc_type_name_Class)
5201 {
5202 if (log)
5203 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5204 die->GetOffset(),
5205 DW_TAG_value_to_name(die->Tag()),
5206 die->GetName(this, dwarf_cu));
5207 clang_type = ast.GetBuiltInType_objc_Class();
5208 encoding_data_type = Type::eEncodingIsUID;
5209 encoding_uid = LLDB_INVALID_UID;
5210 resolve_state = Type::eResolveStateFull;
5211 }
5212 else if (type_name_const_str == g_objc_type_name_selector)
5213 {
5214 if (log)
5215 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5216 die->GetOffset(),
5217 DW_TAG_value_to_name(die->Tag()),
5218 die->GetName(this, dwarf_cu));
5219 clang_type = ast.GetBuiltInType_objc_selector();
5220 encoding_data_type = Type::eEncodingIsUID;
5221 encoding_uid = LLDB_INVALID_UID;
5222 resolve_state = Type::eResolveStateFull;
5223 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005224 }
5225 }
5226
Greg Clayton81c22f62011-10-19 18:09:39 +00005227 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005228 this,
5229 type_name_const_str,
5230 byte_size,
5231 NULL,
5232 encoding_uid,
5233 encoding_data_type,
5234 &decl,
5235 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005236 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005237
Greg Clayton594e5ed2010-09-27 21:07:38 +00005238 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005239
5240// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5241// if (encoding_type != NULL)
5242// {
5243// if (encoding_type != DIE_IS_BEING_PARSED)
5244// type_sp->SetEncodingType(encoding_type);
5245// else
5246// m_indirect_fixups.push_back(type_sp.get());
5247// }
5248 }
5249 break;
5250
5251 case DW_TAG_structure_type:
5252 case DW_TAG_union_type:
5253 case DW_TAG_class_type:
5254 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005255 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005256 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005257
Greg Clayton9e409562010-07-28 02:04:09 +00005258 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005259 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005260 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005261 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005262 if (num_attributes > 0)
5263 {
5264 uint32_t i;
5265 for (i=0; i<num_attributes; ++i)
5266 {
5267 attr = attributes.AttributeAtIndex(i);
5268 DWARFFormValue form_value;
5269 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5270 {
5271 switch (attr)
5272 {
Greg Clayton9e409562010-07-28 02:04:09 +00005273 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005274 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5275 {
5276 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5277 // point to the compile unit file, so we clear this invalid value
5278 // so that we can still unique types efficiently.
5279 decl.SetFile(FileSpec ("<invalid>", false));
5280 }
5281 else
5282 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005283 break;
5284
5285 case DW_AT_decl_line:
5286 decl.SetLine(form_value.Unsigned());
5287 break;
5288
5289 case DW_AT_decl_column:
5290 decl.SetColumn(form_value.Unsigned());
5291 break;
5292
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005293 case DW_AT_name:
5294 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005295 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005296 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005297
5298 case DW_AT_byte_size:
5299 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005300 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005301 break;
5302
5303 case DW_AT_accessibility:
5304 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5305 break;
5306
5307 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005308 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005309 break;
5310
5311 case DW_AT_APPLE_runtime_class:
5312 class_language = (LanguageType)form_value.Signed();
5313 break;
5314
Greg Clayton18774842011-11-29 23:40:34 +00005315 case DW_AT_APPLE_objc_complete_type:
5316 is_complete_objc_class = form_value.Signed();
5317 break;
5318
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005319 case DW_AT_allocated:
5320 case DW_AT_associated:
5321 case DW_AT_data_location:
5322 case DW_AT_description:
5323 case DW_AT_start_scope:
5324 case DW_AT_visibility:
5325 default:
5326 case DW_AT_sibling:
5327 break;
5328 }
5329 }
5330 }
5331 }
5332
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005333 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005334
Greg Clayton123edca2012-03-02 00:07:15 +00005335 // Only try and unique the type if it has a name.
5336 if (type_name_const_str &&
5337 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005338 this,
5339 dwarf_cu,
5340 die,
5341 decl,
5342 byte_size_valid ? byte_size : -1,
5343 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005344 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005345 // We have already parsed this type or from another
5346 // compile unit. GCC loves to use the "one definition
5347 // rule" which can result in multiple definitions
5348 // of the same class over and over in each compile
5349 // unit.
5350 type_sp = unique_ast_entry.m_type_sp;
5351 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005352 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005353 m_die_to_type[die] = type_sp.get();
5354 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005355 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005356 }
5357
Greg Clayton81c22f62011-10-19 18:09:39 +00005358 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 +00005359
5360 int tag_decl_kind = -1;
5361 AccessType default_accessibility = eAccessNone;
5362 if (tag == DW_TAG_structure_type)
5363 {
5364 tag_decl_kind = clang::TTK_Struct;
5365 default_accessibility = eAccessPublic;
5366 }
5367 else if (tag == DW_TAG_union_type)
5368 {
5369 tag_decl_kind = clang::TTK_Union;
5370 default_accessibility = eAccessPublic;
5371 }
5372 else if (tag == DW_TAG_class_type)
5373 {
5374 tag_decl_kind = clang::TTK_Class;
5375 default_accessibility = eAccessPrivate;
5376 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005377
5378 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5379 die->HasChildren() == false &&
5380 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5381 {
5382 // Work around an issue with clang at the moment where
5383 // forward declarations for objective C classes are emitted
5384 // as:
5385 // DW_TAG_structure_type [2]
5386 // DW_AT_name( "ForwardObjcClass" )
5387 // DW_AT_byte_size( 0x00 )
5388 // DW_AT_decl_file( "..." )
5389 // DW_AT_decl_line( 1 )
5390 //
5391 // Note that there is no DW_AT_declaration and there are
5392 // no children, and the byte size is zero.
5393 is_forward_declaration = true;
5394 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005395
Sean Callanan7457f8d2012-04-25 01:03:57 +00005396 if (class_language == eLanguageTypeObjC ||
5397 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005398 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005399 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005400 {
5401 // We have a valid eSymbolTypeObjCClass class symbol whose
5402 // name matches the current objective C class that we
5403 // are trying to find and this DIE isn't the complete
5404 // definition (we checked is_complete_objc_class above and
5405 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005406 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005407
Greg Clayton901c5ca2011-12-03 04:40:03 +00005408 if (!type_sp && m_debug_map_symfile)
5409 {
5410 // We weren't able to find a full declaration in
5411 // this DWARF, see if we have a declaration anywhere
5412 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005413 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005414 }
5415
5416 if (type_sp)
5417 {
5418 if (log)
5419 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005420 GetObjectFile()->GetModule()->LogMessage (log.get(),
5421 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
5422 this,
5423 die->GetOffset(),
5424 DW_TAG_value_to_name(tag),
5425 type_name_cstr,
5426 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005427 }
5428
5429 // We found a real definition for this type elsewhere
5430 // so lets use it and cache the fact that we found
5431 // a complete type for this die
5432 m_die_to_type[die] = type_sp.get();
5433 return type_sp;
5434 }
5435 }
5436 }
5437
5438
5439 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005440 {
5441 // We have a forward declaration to a type and we need
5442 // to try and find a full declaration. We look in the
5443 // current type index just in case we have a forward
5444 // declaration followed by an actual declarations in the
5445 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005446 if (log)
5447 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005448 GetObjectFile()->GetModule()->LogMessage (log.get(),
5449 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5450 this,
5451 die->GetOffset(),
5452 DW_TAG_value_to_name(tag),
5453 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005454 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005455
Greg Claytona8022fa2012-04-24 21:22:41 +00005456 DWARFDeclContext die_decl_ctx;
5457 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5458
5459 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5460 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005461
5462 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00005463 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005464 // We weren't able to find a full declaration in
5465 // this DWARF, see if we have a declaration anywhere
5466 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005467 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005468 }
5469
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005470 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005471 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005472 if (log)
5473 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005474 GetObjectFile()->GetModule()->LogMessage (log.get(),
5475 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5476 this,
5477 die->GetOffset(),
5478 DW_TAG_value_to_name(tag),
5479 type_name_cstr,
5480 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005481 }
5482
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005483 // We found a real definition for this type elsewhere
5484 // so lets use it and cache the fact that we found
5485 // a complete type for this die
5486 m_die_to_type[die] = type_sp.get();
5487 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005488 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005489 }
5490 assert (tag_decl_kind != -1);
5491 bool clang_type_was_created = false;
5492 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5493 if (clang_type == NULL)
5494 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005495 const DWARFDebugInfoEntry *decl_ctx_die;
5496
5497 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005498 if (accessibility == eAccessNone && decl_ctx)
5499 {
5500 // Check the decl context that contains this class/struct/union.
5501 // If it is a class we must give it an accessability.
5502 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5503 if (DeclKindIsCXXClass (containing_decl_kind))
5504 accessibility = default_accessibility;
5505 }
5506
Greg Claytonf0705c82011-10-22 03:33:13 +00005507 if (type_name_cstr && strchr (type_name_cstr, '<'))
5508 {
5509 ClangASTContext::TemplateParameterInfos template_param_infos;
5510 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5511 {
5512 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005513 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005514 type_name_cstr,
5515 tag_decl_kind,
5516 template_param_infos);
5517
5518 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5519 class_template_decl,
5520 tag_decl_kind,
5521 template_param_infos);
5522 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5523 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005524
5525 GetClangASTContext().SetMetadata((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
5526 GetClangASTContext().SetMetadata((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005527 }
5528 }
5529
5530 if (!clang_type_was_created)
5531 {
5532 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005533 clang_type = ast.CreateRecordType (decl_ctx,
5534 accessibility,
5535 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005536 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005537 class_language,
Sean Callananad880762012-04-18 01:06:17 +00005538 MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005539 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005540 }
5541
5542 // Store a forward declaration to this class type in case any
5543 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005544 // types for function prototypes.
5545 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005546 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005547 this,
5548 type_name_const_str,
5549 byte_size,
5550 NULL,
5551 LLDB_INVALID_UID,
5552 Type::eEncodingIsUID,
5553 &decl,
5554 clang_type,
5555 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005556
5557 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005558
5559
5560 // Add our type to the unique type map so we don't
5561 // end up creating many copies of the same type over
5562 // and over in the ASTContext for our module
5563 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005564 unique_ast_entry.m_symfile = this;
5565 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005566 unique_ast_entry.m_die = die;
5567 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005568 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005569 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5570 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005571
Sean Callanan12014a02011-12-08 23:45:45 +00005572 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005573 {
5574 // Always start the definition for a class type so that
5575 // if the class has child classes or types that require
5576 // the class to be created for use as their decl contexts
5577 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005578 if (die->HasChildren() == false)
5579 {
5580 // No children for this struct/union/class, lets finish it
5581 ast.StartTagDeclarationDefinition (clang_type);
5582 ast.CompleteTagDeclarationDefinition (clang_type);
5583 }
5584 else if (clang_type_was_created)
5585 {
Greg Clayton219cf312012-03-30 00:51:13 +00005586 // Start the definition if the class is not objective C since
5587 // the underlying decls respond to isCompleteDefinition(). Objective
5588 // C decls dont' respond to isCompleteDefinition() so we can't
5589 // start the declaration definition right away. For C++ classs/union/structs
5590 // we want to start the definition in case the class is needed as the
5591 // declaration context for a contained class or type without the need
5592 // to complete that type..
5593
Sean Callanan7457f8d2012-04-25 01:03:57 +00005594 if (class_language != eLanguageTypeObjC &&
5595 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00005596 ast.StartTagDeclarationDefinition (clang_type);
5597
Sean Callanan12014a02011-12-08 23:45:45 +00005598 // Leave this as a forward declaration until we need
5599 // to know the details of the type. lldb_private::Type
5600 // will automatically call the SymbolFile virtual function
5601 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5602 // When the definition needs to be defined.
5603 m_forward_decl_die_to_clang_type[die] = clang_type;
5604 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5605 ClangASTContext::SetHasExternalStorage (clang_type, true);
5606 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005607 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005608
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005609 }
5610 break;
5611
5612 case DW_TAG_enumeration_type:
5613 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005614 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005615 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005616
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005617 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005618
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 if (num_attributes > 0)
5621 {
5622 uint32_t i;
5623
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 {
Greg Clayton7a345282010-11-09 23:46:37 +00005632 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005635 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;
Greg Clayton7a345282010-11-09 23:46:37 +00005639 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005640 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00005641 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5642 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005643 case DW_AT_allocated:
5644 case DW_AT_associated:
5645 case DW_AT_bit_stride:
5646 case DW_AT_byte_stride:
5647 case DW_AT_data_location:
5648 case DW_AT_description:
5649 case DW_AT_start_scope:
5650 case DW_AT_visibility:
5651 case DW_AT_specification:
5652 case DW_AT_abstract_origin:
5653 case DW_AT_sibling:
5654 break;
5655 }
5656 }
5657 }
5658
Greg Clayton81c22f62011-10-19 18:09:39 +00005659 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 +00005660
Greg Clayton1be10fc2010-09-29 01:12:09 +00005661 clang_type_t enumerator_clang_type = NULL;
5662 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5663 if (clang_type == NULL)
5664 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005665 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5666 DW_ATE_signed,
5667 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005668 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005669 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005670 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005671 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005672 }
5673 else
5674 {
5675 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5676 assert (enumerator_clang_type != NULL);
5677 }
5678
Greg Claytona2721472011-06-25 00:44:06 +00005679 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5680
Greg Clayton81c22f62011-10-19 18:09:39 +00005681 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005682 this,
5683 type_name_const_str,
5684 byte_size,
5685 NULL,
5686 encoding_uid,
5687 Type::eEncodingIsUID,
5688 &decl,
5689 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005690 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005691
Greg Clayton6beaaa62011-01-17 03:46:26 +00005692 ast.StartTagDeclarationDefinition (clang_type);
5693 if (die->HasChildren())
5694 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005695 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5696 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005697 }
5698 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005699 }
5700 }
5701 break;
5702
Jim Inghamb0be4422010-08-12 01:20:14 +00005703 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005704 case DW_TAG_subprogram:
5705 case DW_TAG_subroutine_type:
5706 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005707 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005708 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005709
5710 const char *mangled = NULL;
5711 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005712 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005713 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005714 bool is_static = false;
5715 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005716 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005717 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005718 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5719 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005720
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005721 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005722 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005723
5724
Greg Claytond88d7592010-09-15 08:33:30 +00005725 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005726 if (num_attributes > 0)
5727 {
5728 uint32_t i;
5729 for (i=0; i<num_attributes; ++i)
5730 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005731 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005732 DWARFFormValue form_value;
5733 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5734 {
5735 switch (attr)
5736 {
5737 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5738 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5739 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5740 case DW_AT_name:
5741 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005742 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005743 break;
5744
5745 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5746 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005747 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005748 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005749 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5750 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005751 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005752 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5753
Greg Claytonf51de672010-10-01 02:31:07 +00005754
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005755 case DW_AT_external:
5756 if (form_value.Unsigned())
5757 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005758 if (storage == clang::SC_None)
5759 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005760 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005761 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005762 }
5763 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005764
Greg Clayton72da3972011-08-16 18:40:23 +00005765 case DW_AT_specification:
5766 specification_die_offset = form_value.Reference(dwarf_cu);
5767 break;
5768
5769 case DW_AT_abstract_origin:
5770 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5771 break;
5772
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005773 case DW_AT_allocated:
5774 case DW_AT_associated:
5775 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005776 case DW_AT_calling_convention:
5777 case DW_AT_data_location:
5778 case DW_AT_elemental:
5779 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005780 case DW_AT_frame_base:
5781 case DW_AT_high_pc:
5782 case DW_AT_low_pc:
5783 case DW_AT_object_pointer:
5784 case DW_AT_prototyped:
5785 case DW_AT_pure:
5786 case DW_AT_ranges:
5787 case DW_AT_recursive:
5788 case DW_AT_return_addr:
5789 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005790 case DW_AT_start_scope:
5791 case DW_AT_static_link:
5792 case DW_AT_trampoline:
5793 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005794 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005795 case DW_AT_description:
5796 case DW_AT_sibling:
5797 break;
5798 }
5799 }
5800 }
Greg Clayton24739922010-10-13 03:15:28 +00005801 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005802
Greg Clayton81c22f62011-10-19 18:09:39 +00005803 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 +00005804
Greg Clayton24739922010-10-13 03:15:28 +00005805 clang_type_t return_clang_type = NULL;
5806 Type *func_type = NULL;
5807
5808 if (type_die_offset != DW_INVALID_OFFSET)
5809 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005810
Greg Clayton24739922010-10-13 03:15:28 +00005811 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005812 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005813 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005814 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005815
Greg Claytonf51de672010-10-01 02:31:07 +00005816
Greg Clayton24739922010-10-13 03:15:28 +00005817 std::vector<clang_type_t> function_param_types;
5818 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005819
Greg Clayton24739922010-10-13 03:15:28 +00005820 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005821
Greg Claytoncb5860a2011-10-13 23:49:28 +00005822 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5823 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005824 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5825
Greg Claytonf0705c82011-10-22 03:33:13 +00005826 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005827 // Start off static. This will be set to false in ParseChildParameters(...)
5828 // if we find a "this" paramters as the first parameter
5829 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005830 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005831 ClangASTContext::TemplateParameterInfos template_param_infos;
5832
Greg Clayton24739922010-10-13 03:15:28 +00005833 if (die->HasChildren())
5834 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005835 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005836 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005837 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005838 dwarf_cu,
5839 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005840 skip_artificial,
5841 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005842 type_list,
5843 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005844 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005845 type_quals,
5846 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005847 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005848
Greg Clayton24739922010-10-13 03:15:28 +00005849 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005850 clang_type = ast.CreateFunctionType (return_clang_type,
5851 &function_param_types[0],
5852 function_param_types.size(),
5853 is_variadic,
5854 type_quals);
5855
Greg Clayton24739922010-10-13 03:15:28 +00005856 if (type_name_cstr)
5857 {
5858 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005859 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005860 {
Greg Clayton7c810422012-01-18 23:40:49 +00005861 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005862 ConstString class_name_no_category;
5863 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005864 {
Greg Claytone42ae842012-01-19 03:24:53 +00005865 // Use the class name with no category if there is one
5866 if (class_name_no_category)
5867 class_name = class_name_no_category;
5868
Greg Clayton24739922010-10-13 03:15:28 +00005869 SymbolContext empty_sc;
5870 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005871 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005872 {
Greg Clayton24739922010-10-13 03:15:28 +00005873 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005874 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005875
5876 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005877 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005878 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5879 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5880 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005881 }
Greg Clayton24739922010-10-13 03:15:28 +00005882 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005883
Greg Clayton24739922010-10-13 03:15:28 +00005884 if (class_opaque_type)
5885 {
5886 // If accessibility isn't set to anything valid, assume public for
5887 // now...
5888 if (accessibility == eAccessNone)
5889 accessibility = eAccessPublic;
5890
5891 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005892 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5893 type_name_cstr,
5894 clang_type,
5895 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005896 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005897 type_handled = objc_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00005898 GetClangASTContext().SetMetadata((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00005899 }
5900 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005901 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005902 {
5903 // Look at the parent of this DIE and see if is is
5904 // a class or struct and see if this is actually a
5905 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005906 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005907 if (class_type)
5908 {
Greg Clayton4116e932012-05-15 02:33:01 +00005909 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
5910 {
5911 // We uniqued the parent class of this function to another class
5912 // so we now need to associate all dies under "decl_ctx_die" to
5913 // DIEs in the DIE for "class_type"...
5914 DWARFCompileUnitSP class_type_cu_sp;
5915 const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
5916 if (class_type_die)
5917 {
5918 if (CopyUniqueClassMethodTypes (class_type,
5919 class_type_cu_sp.get(),
5920 class_type_die,
5921 dwarf_cu,
5922 decl_ctx_die))
5923 {
5924 type_ptr = m_die_to_type[die];
5925 if (type_ptr)
5926 {
5927 type_sp = type_ptr->shared_from_this();
5928 break;
5929 }
5930 }
5931 }
5932 }
5933
Greg Clayton72da3972011-08-16 18:40:23 +00005934 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005935 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005936 // We have a specification which we are going to base our function
5937 // prototype off of, so we need this type to be completed so that the
5938 // m_die_to_decl_ctx for the method in the specification has a valid
5939 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005940 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005941 // If we have a specification, then the function type should have been
5942 // made with the specification and not with this die.
5943 DWARFCompileUnitSP spec_cu_sp;
5944 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005945 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005946 if (spec_clang_decl_ctx)
5947 {
5948 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5949 }
5950 else
Jim Inghamc1663042011-09-29 22:12:35 +00005951 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005952 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5953 MakeUserID(die->GetOffset()),
5954 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005955 }
Greg Clayton72da3972011-08-16 18:40:23 +00005956 type_handled = true;
5957 }
5958 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5959 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005960 // We have a specification which we are going to base our function
5961 // prototype off of, so we need this type to be completed so that the
5962 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5963 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005964 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005965
Greg Clayton72da3972011-08-16 18:40:23 +00005966 DWARFCompileUnitSP abs_cu_sp;
5967 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005968 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005969 if (abs_clang_decl_ctx)
5970 {
5971 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5972 }
5973 else
Jim Inghamc1663042011-09-29 22:12:35 +00005974 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005975 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5976 MakeUserID(die->GetOffset()),
5977 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005978 }
Greg Clayton72da3972011-08-16 18:40:23 +00005979 type_handled = true;
5980 }
5981 else
5982 {
5983 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5984 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005985 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005986 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005987 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005988 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5989 // in the DWARF for C++ methods... Default to public for now...
5990 if (accessibility == eAccessNone)
5991 accessibility = eAccessPublic;
5992
5993 if (!is_static && !die->HasChildren())
5994 {
5995 // We have a C++ member function with no children (this pointer!)
5996 // and clang will get mad if we try and make a function that isn't
5997 // well formed in the DWARF, so we will just skip it...
5998 type_handled = true;
5999 }
6000 else
6001 {
6002 clang::CXXMethodDecl *cxx_method_decl;
6003 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00006004 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 +00006005 type_name_cstr,
6006 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006007 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006008 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6009 m_obj_file->GetFileSpec().GetFilename().GetCString());
6010
Sean Callananc1b732d2011-11-01 18:07:13 +00006011 const bool is_attr_used = false;
6012
Greg Clayton20568dd2011-10-13 23:13:20 +00006013 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6014 type_name_cstr,
6015 clang_type,
6016 accessibility,
6017 is_virtual,
6018 is_static,
6019 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006020 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006021 is_attr_used,
6022 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00006023 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6024
Greg Claytonf49e65a2011-11-10 18:31:53 +00006025 Host::SetCrashDescription (NULL);
6026
Greg Clayton20568dd2011-10-13 23:13:20 +00006027 type_handled = cxx_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00006028
6029 GetClangASTContext().SetMetadata((uintptr_t)cxx_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton20568dd2011-10-13 23:13:20 +00006030 }
Greg Clayton72da3972011-08-16 18:40:23 +00006031 }
6032 else
6033 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006034 // We were asked to parse the type for a method in a class, yet the
6035 // class hasn't been asked to complete itself through the
6036 // clang::ExternalASTSource protocol, so we need to just have the
6037 // class complete itself and do things the right way, then our
6038 // DIE should then have an entry in the m_die_to_type map. First
6039 // we need to modify the m_die_to_type so it doesn't think we are
6040 // trying to parse this DIE anymore...
6041 m_die_to_type[die] = NULL;
6042
6043 // Now we get the full type to force our class type to complete itself
6044 // using the clang::ExternalASTSource protocol which will parse all
6045 // base classes and all methods (including the method for this DIE).
6046 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006047
Greg Clayton20568dd2011-10-13 23:13:20 +00006048 // The type for this DIE should have been filled in the function call above
6049 type_ptr = m_die_to_type[die];
6050 if (type_ptr)
6051 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006052 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006053 break;
6054 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006055
6056 // FIXME This is fixing some even uglier behavior but we really need to
6057 // uniq the methods of each class as well as the class itself.
6058 // <rdar://problem/11240464>
6059 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006060 }
Greg Clayton931180e2011-01-27 06:44:37 +00006061 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006062 }
6063 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006064 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006065 }
Greg Clayton24739922010-10-13 03:15:28 +00006066
6067 if (!type_handled)
6068 {
6069 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006070 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6071 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006072 clang_type,
6073 storage,
6074 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006075
6076// if (template_param_infos.GetSize() > 0)
6077// {
6078// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6079// function_decl,
6080// type_name_cstr,
6081// template_param_infos);
6082//
6083// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6084// func_template_decl,
6085// template_param_infos);
6086// }
Greg Clayton24739922010-10-13 03:15:28 +00006087 // Add the decl to our DIE to decl context map
6088 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006089 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006090 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006091 ast.SetFunctionParameters (function_decl,
6092 &function_param_decls.front(),
6093 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006094
6095 GetClangASTContext().SetMetadata((uintptr_t)function_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00006096 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006097 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006098 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006099 this,
6100 type_name_const_str,
6101 0,
6102 NULL,
6103 LLDB_INVALID_UID,
6104 Type::eEncodingIsUID,
6105 &decl,
6106 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006107 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006108 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006109 }
6110 break;
6111
6112 case DW_TAG_array_type:
6113 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006114 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006115 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006116
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006117 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006118 int64_t first_index = 0;
6119 uint32_t byte_stride = 0;
6120 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006121 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006122
6123 if (num_attributes > 0)
6124 {
6125 uint32_t i;
6126 for (i=0; i<num_attributes; ++i)
6127 {
6128 attr = attributes.AttributeAtIndex(i);
6129 DWARFFormValue form_value;
6130 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6131 {
6132 switch (attr)
6133 {
6134 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6135 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6136 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6137 case DW_AT_name:
6138 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006139 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006140 break;
6141
6142 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00006143 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006144 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6145 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006146 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00006147 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006148 case DW_AT_allocated:
6149 case DW_AT_associated:
6150 case DW_AT_data_location:
6151 case DW_AT_description:
6152 case DW_AT_ordering:
6153 case DW_AT_start_scope:
6154 case DW_AT_visibility:
6155 case DW_AT_specification:
6156 case DW_AT_abstract_origin:
6157 case DW_AT_sibling:
6158 break;
6159 }
6160 }
6161 }
6162
Greg Clayton81c22f62011-10-19 18:09:39 +00006163 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 +00006164
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006165 Type *element_type = ResolveTypeUID(type_die_offset);
6166
6167 if (element_type)
6168 {
6169 std::vector<uint64_t> element_orders;
6170 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00006171 // We have an array that claims to have no members, lets give it at least one member...
6172 if (element_orders.empty())
6173 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006174 if (byte_stride == 0 && bit_stride == 0)
6175 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006176 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006177 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6178 uint64_t num_elements = 0;
6179 std::vector<uint64_t>::const_reverse_iterator pos;
6180 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6181 for (pos = element_orders.rbegin(); pos != end; ++pos)
6182 {
6183 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006184 clang_type = ast.CreateArrayType (array_element_type,
6185 num_elements,
6186 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006187 array_element_type = clang_type;
6188 array_element_bit_stride = array_element_bit_stride * num_elements;
6189 }
6190 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006191 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006192 this,
6193 empty_name,
6194 array_element_bit_stride / 8,
6195 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006196 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006197 Type::eEncodingIsUID,
6198 &decl,
6199 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006200 Type::eResolveStateFull));
6201 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006202 }
6203 }
6204 }
6205 break;
6206
Greg Clayton9b81a312010-06-12 01:20:30 +00006207 case DW_TAG_ptr_to_member_type:
6208 {
6209 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6210 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6211
Greg Claytond88d7592010-09-15 08:33:30 +00006212 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006213
6214 if (num_attributes > 0) {
6215 uint32_t i;
6216 for (i=0; i<num_attributes; ++i)
6217 {
6218 attr = attributes.AttributeAtIndex(i);
6219 DWARFFormValue form_value;
6220 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6221 {
6222 switch (attr)
6223 {
6224 case DW_AT_type:
6225 type_die_offset = form_value.Reference(dwarf_cu); break;
6226 case DW_AT_containing_type:
6227 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6228 }
6229 }
6230 }
6231
6232 Type *pointee_type = ResolveTypeUID(type_die_offset);
6233 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6234
Greg Clayton526e5af2010-11-13 03:52:47 +00006235 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6236 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006237
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006238 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6239 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006240
Greg Clayton526e5af2010-11-13 03:52:47 +00006241 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6242 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006243
Greg Clayton81c22f62011-10-19 18:09:39 +00006244 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006245 this,
6246 type_name_const_str,
6247 byte_size,
6248 NULL,
6249 LLDB_INVALID_UID,
6250 Type::eEncodingIsUID,
6251 NULL,
6252 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006253 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006254 }
6255
6256 break;
6257 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006258 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00006259 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006260 break;
6261 }
6262
6263 if (type_sp.get())
6264 {
6265 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6266 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6267
6268 SymbolContextScope * symbol_context_scope = NULL;
6269 if (sc_parent_tag == DW_TAG_compile_unit)
6270 {
6271 symbol_context_scope = sc.comp_unit;
6272 }
6273 else if (sc.function != NULL)
6274 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006275 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006276 if (symbol_context_scope == NULL)
6277 symbol_context_scope = sc.function;
6278 }
6279
6280 if (symbol_context_scope != NULL)
6281 {
6282 type_sp->SetSymbolContextScope(symbol_context_scope);
6283 }
6284
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006285 // We are ready to put this type into the uniqued list up at the module level
6286 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006287
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006288 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006289 }
6290 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006291 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006292 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006293 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006294 }
6295 }
6296 return type_sp;
6297}
6298
6299size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006300SymbolFileDWARF::ParseTypes
6301(
6302 const SymbolContext& sc,
6303 DWARFCompileUnit* dwarf_cu,
6304 const DWARFDebugInfoEntry *die,
6305 bool parse_siblings,
6306 bool parse_children
6307)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006308{
6309 size_t types_added = 0;
6310 while (die != NULL)
6311 {
6312 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006313 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006314 {
6315 if (type_is_new)
6316 ++types_added;
6317 }
6318
6319 if (parse_children && die->HasChildren())
6320 {
6321 if (die->Tag() == DW_TAG_subprogram)
6322 {
6323 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006324 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006325 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6326 }
6327 else
6328 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6329 }
6330
6331 if (parse_siblings)
6332 die = die->GetSibling();
6333 else
6334 die = NULL;
6335 }
6336 return types_added;
6337}
6338
6339
6340size_t
6341SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6342{
6343 assert(sc.comp_unit && sc.function);
6344 size_t functions_added = 0;
6345 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6346 if (dwarf_cu)
6347 {
6348 dw_offset_t function_die_offset = sc.function->GetID();
6349 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6350 if (function_die)
6351 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006352 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006353 }
6354 }
6355
6356 return functions_added;
6357}
6358
6359
6360size_t
6361SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6362{
6363 // At least a compile unit must be valid
6364 assert(sc.comp_unit);
6365 size_t types_added = 0;
6366 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6367 if (dwarf_cu)
6368 {
6369 if (sc.function)
6370 {
6371 dw_offset_t function_die_offset = sc.function->GetID();
6372 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6373 if (func_die && func_die->HasChildren())
6374 {
6375 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6376 }
6377 }
6378 else
6379 {
6380 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6381 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6382 {
6383 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6384 }
6385 }
6386 }
6387
6388 return types_added;
6389}
6390
6391size_t
6392SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6393{
6394 if (sc.comp_unit != NULL)
6395 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006396 DWARFDebugInfo* info = DebugInfo();
6397 if (info == NULL)
6398 return 0;
6399
6400 uint32_t cu_idx = UINT32_MAX;
6401 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006402
6403 if (dwarf_cu == NULL)
6404 return 0;
6405
6406 if (sc.function)
6407 {
6408 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006409
6410 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 +00006411 if (func_lo_pc != DW_INVALID_ADDRESS)
6412 {
6413 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006414
Greg Claytone38a5ed2012-01-05 03:57:59 +00006415 // Let all blocks know they have parse all their variables
6416 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6417 return num_variables;
6418 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006419 }
6420 else if (sc.comp_unit)
6421 {
6422 uint32_t vars_added = 0;
6423 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6424
6425 if (variables.get() == NULL)
6426 {
6427 variables.reset(new VariableList());
6428 sc.comp_unit->SetVariableList(variables);
6429
Greg Claytond4a2b372011-09-12 23:21:58 +00006430 DWARFCompileUnit* match_dwarf_cu = NULL;
6431 const DWARFDebugInfoEntry* die = NULL;
6432 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006433 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006434 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006435 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006436 {
6437 DWARFMappedHash::DIEInfoArray hash_data_array;
6438 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6439 dwarf_cu->GetNextCompileUnitOffset(),
6440 hash_data_array))
6441 {
6442 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6443 }
6444 }
Greg Clayton7f995132011-10-04 22:41:51 +00006445 }
6446 else
6447 {
6448 // Index if we already haven't to make sure the compile units
6449 // get indexed and make their global DIE index list
6450 if (!m_indexed)
6451 Index ();
6452
6453 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6454 dwarf_cu->GetNextCompileUnitOffset(),
6455 die_offsets);
6456 }
6457
6458 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006459 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006460 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006461 DWARFDebugInfo* debug_info = DebugInfo();
6462 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006463 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006464 const dw_offset_t die_offset = die_offsets[i];
6465 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006466 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006467 {
Greg Clayton95d87902011-11-11 03:16:25 +00006468 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6469 if (var_sp)
6470 {
6471 variables->AddVariableIfUnique (var_sp);
6472 ++vars_added;
6473 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006474 }
Greg Clayton95d87902011-11-11 03:16:25 +00006475 else
6476 {
6477 if (m_using_apple_tables)
6478 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006479 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 +00006480 }
6481 }
6482
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006483 }
6484 }
6485 }
6486 return vars_added;
6487 }
6488 }
6489 return 0;
6490}
6491
6492
6493VariableSP
6494SymbolFileDWARF::ParseVariableDIE
6495(
6496 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006497 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006498 const DWARFDebugInfoEntry *die,
6499 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006500)
6501{
6502
Greg Clayton83c5cd92010-11-14 22:13:40 +00006503 VariableSP var_sp (m_die_to_variable_sp[die]);
6504 if (var_sp)
6505 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006506
6507 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006508
6509 if ((tag == DW_TAG_variable) ||
6510 (tag == DW_TAG_constant) ||
6511 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006512 {
Greg Clayton7f995132011-10-04 22:41:51 +00006513 DWARFDebugInfoEntry::Attributes attributes;
6514 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6515 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006516 {
Greg Clayton7f995132011-10-04 22:41:51 +00006517 const char *name = NULL;
6518 const char *mangled = NULL;
6519 Declaration decl;
6520 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006521 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006522 DWARFExpression location;
6523 bool is_external = false;
6524 bool is_artificial = false;
6525 bool location_is_const_value_data = false;
6526 AccessType accessibility = eAccessNone;
6527
6528 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006529 {
Greg Clayton7f995132011-10-04 22:41:51 +00006530 dw_attr_t attr = attributes.AttributeAtIndex(i);
6531 DWARFFormValue form_value;
6532 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006533 {
Greg Clayton7f995132011-10-04 22:41:51 +00006534 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006535 {
Greg Clayton7f995132011-10-04 22:41:51 +00006536 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6537 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6538 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6539 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6540 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006541 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006542 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6543 case DW_AT_const_value:
6544 location_is_const_value_data = true;
6545 // Fall through...
6546 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006547 {
Greg Clayton7f995132011-10-04 22:41:51 +00006548 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006549 {
Greg Clayton7f995132011-10-04 22:41:51 +00006550 const DataExtractor& debug_info_data = get_debug_info_data();
6551
6552 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6553 uint32_t block_length = form_value.Unsigned();
6554 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6555 }
6556 else
6557 {
6558 const DataExtractor& debug_loc_data = get_debug_loc_data();
6559 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6560
6561 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6562 if (loc_list_length > 0)
6563 {
6564 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6565 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6566 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6567 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006568 }
6569 }
Greg Clayton7f995132011-10-04 22:41:51 +00006570 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006571
Greg Clayton7f995132011-10-04 22:41:51 +00006572 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6573 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6574 case DW_AT_declaration:
6575 case DW_AT_description:
6576 case DW_AT_endianity:
6577 case DW_AT_segment:
6578 case DW_AT_start_scope:
6579 case DW_AT_visibility:
6580 default:
6581 case DW_AT_abstract_origin:
6582 case DW_AT_sibling:
6583 case DW_AT_specification:
6584 break;
6585 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006586 }
6587 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006588
Greg Clayton7f995132011-10-04 22:41:51 +00006589 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006590 {
Greg Clayton7f995132011-10-04 22:41:51 +00006591 ValueType scope = eValueTypeInvalid;
6592
6593 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6594 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006595 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006596
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006597 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6598 // or static variable, so we have to do a little digging by
6599 // looking at the location of a varaible to see if it contains
6600 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6601 // somewhere because clang likes to combine small global variables
6602 // into the same symbol and have locations like:
6603 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6604 // So if we don't have a DW_TAG_formal_parameter, we can look at
6605 // the location to see if it contains a DW_OP_addr opcode, and
6606 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006607 if (tag == DW_TAG_formal_parameter)
6608 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006609 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006610 {
Greg Clayton96c09682012-01-04 22:56:43 +00006611 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006612 // Check if the location has a DW_OP_addr with any address value...
6613 addr_t location_has_op_addr = false;
6614 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006615 {
6616 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6617 if (op_error)
6618 {
6619 StreamString strm;
6620 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006621 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 +00006622 }
6623 }
Greg Claytond1767f02011-12-08 02:13:16 +00006624
6625 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006626 {
Greg Claytond1767f02011-12-08 02:13:16 +00006627 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006628 {
Greg Claytond1767f02011-12-08 02:13:16 +00006629 scope = eValueTypeVariableGlobal;
6630
6631 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006632 {
Greg Claytond1767f02011-12-08 02:13:16 +00006633 // When leaving the DWARF in the .o files on darwin,
6634 // when we have a global variable that wasn't initialized,
6635 // the .o file might not have allocated a virtual
6636 // address for the global variable. In this case it will
6637 // have created a symbol for the global variable
6638 // that is undefined and external and the value will
6639 // be the byte size of the variable. When we do the
6640 // address map in SymbolFileDWARFDebugMap we rely on
6641 // having an address, we need to do some magic here
6642 // so we can get the correct address for our global
6643 // variable. The address for all of these entries
6644 // will be zero, and there will be an undefined symbol
6645 // in this object file, and the executable will have
6646 // a matching symbol with a good address. So here we
6647 // dig up the correct address and replace it in the
6648 // location for the variable, and set the variable's
6649 // symbol context scope to be that of the main executable
6650 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006651 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006652 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006653
Greg Claytond1767f02011-12-08 02:13:16 +00006654 // we have a possible uninitialized extern global
6655 Symtab *symtab = m_obj_file->GetSymtab();
6656 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006657 {
Greg Claytond1767f02011-12-08 02:13:16 +00006658 ConstString const_name(name);
6659 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6660 eSymbolTypeUndefined,
6661 Symtab::eDebugNo,
6662 Symtab::eVisibilityExtern);
6663
6664 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006665 {
Greg Claytond1767f02011-12-08 02:13:16 +00006666 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6667 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006668 {
Greg Claytond1767f02011-12-08 02:13:16 +00006669 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6670 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6671 eSymbolTypeData,
6672 Symtab::eDebugYes,
6673 Symtab::eVisibilityExtern);
6674 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006675 {
Greg Claytone7612132012-03-07 21:03:09 +00006676 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006677 {
Greg Claytone7612132012-03-07 21:03:09 +00006678 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006679 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006680 {
Greg Claytond1767f02011-12-08 02:13:16 +00006681 if (location.Update_DW_OP_addr (defined_addr))
6682 {
6683 symbol_context_scope = defined_symbol;
6684 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006685 }
6686 }
6687 }
6688 }
6689 }
6690 }
6691 }
6692 }
6693 }
Greg Claytond1767f02011-12-08 02:13:16 +00006694 else
6695 {
6696 scope = eValueTypeVariableStatic;
6697 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006698 }
6699 else
Greg Claytond1767f02011-12-08 02:13:16 +00006700 {
6701 scope = eValueTypeVariableLocal;
6702 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006703 }
Greg Clayton7f995132011-10-04 22:41:51 +00006704
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006705 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006706 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006707 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006708 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006709 case DW_TAG_subprogram:
6710 case DW_TAG_inlined_subroutine:
6711 case DW_TAG_lexical_block:
6712 if (sc.function)
6713 {
6714 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6715 if (symbol_context_scope == NULL)
6716 symbol_context_scope = sc.function;
6717 }
6718 break;
6719
6720 default:
6721 symbol_context_scope = sc.comp_unit;
6722 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006723 }
Greg Clayton7f995132011-10-04 22:41:51 +00006724 }
6725
Greg Clayton5cf58b92011-10-05 22:22:08 +00006726 if (symbol_context_scope)
6727 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006728 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6729 name,
6730 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006731 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006732 scope,
6733 symbol_context_scope,
6734 &decl,
6735 location,
6736 is_external,
6737 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006738
6739 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6740 }
6741 else
6742 {
6743 // Not ready to parse this variable yet. It might be a global
6744 // or static variable that is in a function scope and the function
6745 // in the symbol context wasn't filled in yet
6746 return var_sp;
6747 }
Greg Clayton7f995132011-10-04 22:41:51 +00006748 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006749 }
Greg Clayton7f995132011-10-04 22:41:51 +00006750 // Cache var_sp even if NULL (the variable was just a specification or
6751 // was missing vital information to be able to be displayed in the debugger
6752 // (missing location due to optimization, etc)) so we don't re-parse
6753 // this DIE over and over later...
6754 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006755 }
6756 return var_sp;
6757}
6758
Greg Claytonc662ec82011-06-17 22:10:16 +00006759
6760const DWARFDebugInfoEntry *
6761SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6762 dw_offset_t spec_block_die_offset,
6763 DWARFCompileUnit **result_die_cu_handle)
6764{
6765 // Give the concrete function die specified by "func_die_offset", find the
6766 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6767 // to "spec_block_die_offset"
6768 DWARFDebugInfo* info = DebugInfo();
6769
6770 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6771 if (die)
6772 {
6773 assert (*result_die_cu_handle);
6774 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6775 }
6776 return NULL;
6777}
6778
6779
6780const DWARFDebugInfoEntry *
6781SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6782 const DWARFDebugInfoEntry *die,
6783 dw_offset_t spec_block_die_offset,
6784 DWARFCompileUnit **result_die_cu_handle)
6785{
6786 if (die)
6787 {
6788 switch (die->Tag())
6789 {
6790 case DW_TAG_subprogram:
6791 case DW_TAG_inlined_subroutine:
6792 case DW_TAG_lexical_block:
6793 {
6794 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6795 {
6796 *result_die_cu_handle = dwarf_cu;
6797 return die;
6798 }
6799
6800 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6801 {
6802 *result_die_cu_handle = dwarf_cu;
6803 return die;
6804 }
6805 }
6806 break;
6807 }
6808
6809 // Give the concrete function die specified by "func_die_offset", find the
6810 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6811 // to "spec_block_die_offset"
6812 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6813 {
6814 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6815 child_die,
6816 spec_block_die_offset,
6817 result_die_cu_handle);
6818 if (result_die)
6819 return result_die;
6820 }
6821 }
6822
6823 *result_die_cu_handle = NULL;
6824 return NULL;
6825}
6826
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006827size_t
6828SymbolFileDWARF::ParseVariables
6829(
6830 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006831 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006832 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006833 const DWARFDebugInfoEntry *orig_die,
6834 bool parse_siblings,
6835 bool parse_children,
6836 VariableList* cc_variable_list
6837)
6838{
6839 if (orig_die == NULL)
6840 return 0;
6841
Greg Claytonc662ec82011-06-17 22:10:16 +00006842 VariableListSP variable_list_sp;
6843
6844 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006845 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006846 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006847 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006848 dw_tag_t tag = die->Tag();
6849
6850 // Check to see if we have already parsed this variable or constant?
6851 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006852 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006853 if (cc_variable_list)
6854 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006855 }
6856 else
6857 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006858 // We haven't already parsed it, lets do that now.
6859 if ((tag == DW_TAG_variable) ||
6860 (tag == DW_TAG_constant) ||
6861 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006862 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006863 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006864 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006865 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6866 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6867 switch (parent_tag)
6868 {
6869 case DW_TAG_compile_unit:
6870 if (sc.comp_unit != NULL)
6871 {
6872 variable_list_sp = sc.comp_unit->GetVariableList(false);
6873 if (variable_list_sp.get() == NULL)
6874 {
6875 variable_list_sp.reset(new VariableList());
6876 sc.comp_unit->SetVariableList(variable_list_sp);
6877 }
6878 }
6879 else
6880 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006881 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6882 MakeUserID(sc_parent_die->GetOffset()),
6883 DW_TAG_value_to_name (parent_tag),
6884 MakeUserID(orig_die->GetOffset()),
6885 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006886 }
6887 break;
6888
6889 case DW_TAG_subprogram:
6890 case DW_TAG_inlined_subroutine:
6891 case DW_TAG_lexical_block:
6892 if (sc.function != NULL)
6893 {
6894 // Check to see if we already have parsed the variables for the given scope
6895
Greg Clayton81c22f62011-10-19 18:09:39 +00006896 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006897 if (block == NULL)
6898 {
6899 // This must be a specification or abstract origin with
6900 // a concrete block couterpart in the current function. We need
6901 // to find the concrete block so we can correctly add the
6902 // variable to it
6903 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6904 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6905 sc_parent_die->GetOffset(),
6906 &concrete_block_die_cu);
6907 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006908 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006909 }
6910
6911 if (block != NULL)
6912 {
6913 const bool can_create = false;
6914 variable_list_sp = block->GetBlockVariableList (can_create);
6915 if (variable_list_sp.get() == NULL)
6916 {
6917 variable_list_sp.reset(new VariableList());
6918 block->SetVariableList(variable_list_sp);
6919 }
6920 }
6921 }
6922 break;
6923
6924 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006925 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6926 MakeUserID(orig_die->GetOffset()),
6927 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006928 break;
6929 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006930 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006931
6932 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006933 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006934 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6935 if (var_sp)
6936 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006937 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006938 if (cc_variable_list)
6939 cc_variable_list->AddVariableIfUnique (var_sp);
6940 ++vars_added;
6941 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006942 }
6943 }
6944 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006945
6946 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6947
6948 if (!skip_children && parse_children && die->HasChildren())
6949 {
6950 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6951 }
6952
6953 if (parse_siblings)
6954 die = die->GetSibling();
6955 else
6956 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006957 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006958 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006959}
6960
6961//------------------------------------------------------------------
6962// PluginInterface protocol
6963//------------------------------------------------------------------
6964const char *
6965SymbolFileDWARF::GetPluginName()
6966{
6967 return "SymbolFileDWARF";
6968}
6969
6970const char *
6971SymbolFileDWARF::GetShortPluginName()
6972{
6973 return GetPluginNameStatic();
6974}
6975
6976uint32_t
6977SymbolFileDWARF::GetPluginVersion()
6978{
6979 return 1;
6980}
6981
6982void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006983SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6984{
6985 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6986 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6987 if (clang_type)
6988 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6989}
6990
6991void
6992SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6993{
6994 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6995 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6996 if (clang_type)
6997 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6998}
6999
Greg Claytona2721472011-06-25 00:44:06 +00007000void
Sean Callanancc427fa2011-07-30 02:42:06 +00007001SymbolFileDWARF::DumpIndexes ()
7002{
7003 StreamFile s(stdout, false);
7004
7005 s.Printf ("DWARF index for (%s) '%s/%s':",
7006 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7007 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7008 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7009 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7010 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7011 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7012 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7013 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7014 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7015 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7016 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7017}
7018
7019void
7020SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7021 const char *name,
7022 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007023{
Sean Callanancc427fa2011-07-30 02:42:06 +00007024 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007025
7026 if (iter == m_decl_ctx_to_die.end())
7027 return;
7028
Greg Claytoncb5860a2011-10-13 23:49:28 +00007029 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007030 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007031 const DWARFDebugInfoEntry *context_die = *pos;
7032
7033 if (!results)
7034 return;
7035
7036 DWARFDebugInfo* info = DebugInfo();
7037
7038 DIEArray die_offsets;
7039
7040 DWARFCompileUnit* dwarf_cu = NULL;
7041 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007042
7043 if (m_using_apple_tables)
7044 {
7045 if (m_apple_types_ap.get())
7046 m_apple_types_ap->FindByName (name, die_offsets);
7047 }
7048 else
7049 {
7050 if (!m_indexed)
7051 Index ();
7052
7053 m_type_index.Find (ConstString(name), die_offsets);
7054 }
7055
Greg Clayton220a0072011-12-09 08:48:30 +00007056 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007057
7058 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007059 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007060 for (size_t i = 0; i < num_matches; ++i)
7061 {
7062 const dw_offset_t die_offset = die_offsets[i];
7063 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007064
Greg Claytoncb5860a2011-10-13 23:49:28 +00007065 if (die->GetParent() != context_die)
7066 continue;
7067
7068 Type *matching_type = ResolveType (dwarf_cu, die);
7069
Greg Clayton42ce2f32011-12-12 21:50:19 +00007070 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007071 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7072
7073 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7074 {
7075 clang::TagDecl *tag_decl = tag_type->getDecl();
7076 results->push_back(tag_decl);
7077 }
7078 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7079 {
7080 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7081 results->push_back(typedef_decl);
7082 }
Greg Claytona2721472011-06-25 00:44:06 +00007083 }
7084 }
7085 }
7086}
7087
7088void
7089SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007090 const clang::DeclContext *decl_context,
7091 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007092 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7093{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007094
7095 switch (decl_context->getDeclKind())
7096 {
7097 case clang::Decl::Namespace:
7098 case clang::Decl::TranslationUnit:
7099 {
7100 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7101 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7102 }
7103 break;
7104 default:
7105 break;
7106 }
Greg Claytona2721472011-06-25 00:44:06 +00007107}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007108
7109bool
7110SymbolFileDWARF::LayoutRecordType (void *baton,
7111 const clang::RecordDecl *record_decl,
7112 uint64_t &size,
7113 uint64_t &alignment,
7114 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7115 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7116 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7117{
7118 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7119 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7120}
7121
7122
7123bool
7124SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7125 uint64_t &bit_size,
7126 uint64_t &alignment,
7127 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7128 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7129 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7130{
7131 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7132 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7133 bool success = false;
7134 base_offsets.clear();
7135 vbase_offsets.clear();
7136 if (pos != m_record_decl_to_layout_map.end())
7137 {
7138 bit_size = pos->second.bit_size;
7139 alignment = pos->second.alignment;
7140 field_offsets.swap(pos->second.field_offsets);
7141 m_record_decl_to_layout_map.erase(pos);
7142 success = true;
7143 }
7144 else
7145 {
7146 bit_size = 0;
7147 alignment = 0;
7148 field_offsets.clear();
7149 }
7150
7151 if (log)
7152 GetObjectFile()->GetModule()->LogMessage (log.get(),
7153 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
7154 record_decl,
7155 bit_size,
7156 alignment,
7157 (uint32_t)field_offsets.size(),
7158 (uint32_t)base_offsets.size(),
7159 (uint32_t)vbase_offsets.size(),
7160 success);
7161 return success;
7162}
7163
7164
7165