blob: 81c1d9182768e0d6c5a667aea4e40304791fb06f [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
Greg Clayton1f746072012-08-29 21:13:06 +0000232 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000266 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000267 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000268 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 m_data_debug_abbrev (),
271 m_data_debug_aranges (),
272 m_data_debug_frame (),
273 m_data_debug_info (),
274 m_data_debug_line (),
275 m_data_debug_loc (),
276 m_data_debug_ranges (),
277 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000278 m_data_apple_names (),
279 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000280 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_info(),
283 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000284 m_apple_names_ap (),
285 m_apple_types_ap (),
286 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000287 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000288 m_function_basename_index(),
289 m_function_fullname_index(),
290 m_function_method_index(),
291 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000292 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000293 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000294 m_type_index(),
295 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000296 m_indexed (false),
297 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000298 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000299 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000300 m_ranges(),
301 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
303}
304
305SymbolFileDWARF::~SymbolFileDWARF()
306{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000307 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000308 {
309 ModuleSP module_sp (m_obj_file->GetModule());
310 if (module_sp)
311 module_sp->GetClangASTContext().RemoveExternalSource ();
312 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000313}
314
315static const ConstString &
316GetDWARFMachOSegmentName ()
317{
318 static ConstString g_dwarf_section_name ("__DWARF");
319 return g_dwarf_section_name;
320}
321
Greg Claytone576ab22011-02-15 00:19:15 +0000322UniqueDWARFASTTypeMap &
323SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
324{
Greg Clayton1f746072012-08-29 21:13:06 +0000325 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000326 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
327 return m_unique_ast_type_map;
328}
329
Greg Clayton6beaaa62011-01-17 03:46:26 +0000330ClangASTContext &
331SymbolFileDWARF::GetClangASTContext ()
332{
Greg Clayton1f746072012-08-29 21:13:06 +0000333 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000334 return m_debug_map_symfile->GetClangASTContext ();
335
336 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
337 if (!m_is_external_ast_source)
338 {
339 m_is_external_ast_source = true;
340 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
341 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
342 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000343 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000344 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 ast.SetExternalSource (ast_source_ap);
347 }
348 return ast;
349}
350
351void
352SymbolFileDWARF::InitializeObject()
353{
354 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000355 ModuleSP module_sp (m_obj_file->GetModule());
356 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000357 {
358 const SectionList *section_list = m_obj_file->GetSectionList();
359
360 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
361
362 // Memory map the DWARF mach-o segment so we have everything mmap'ed
363 // to keep our heap memory usage down.
364 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000365 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000366 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000367 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000368 if (m_data_apple_names.GetByteSize() > 0)
369 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000370 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
371 if (m_apple_names_ap->IsValid())
372 m_using_apple_tables = true;
373 else
Greg Clayton7f995132011-10-04 22:41:51 +0000374 m_apple_names_ap.reset();
375 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000376 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000377 if (m_data_apple_types.GetByteSize() > 0)
378 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000379 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
380 if (m_apple_types_ap->IsValid())
381 m_using_apple_tables = true;
382 else
Greg Clayton7f995132011-10-04 22:41:51 +0000383 m_apple_types_ap.reset();
384 }
385
386 get_apple_namespaces_data();
387 if (m_data_apple_namespaces.GetByteSize() > 0)
388 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000389 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
390 if (m_apple_namespaces_ap->IsValid())
391 m_using_apple_tables = true;
392 else
Greg Clayton7f995132011-10-04 22:41:51 +0000393 m_apple_namespaces_ap.reset();
394 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000395
Greg Clayton5009f9d2011-10-27 17:55:14 +0000396 get_apple_objc_data();
397 if (m_data_apple_objc.GetByteSize() > 0)
398 {
399 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
400 if (m_apple_objc_ap->IsValid())
401 m_using_apple_tables = true;
402 else
403 m_apple_objc_ap.reset();
404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407bool
408SymbolFileDWARF::SupportedVersion(uint16_t version)
409{
410 return version == 2 || version == 3;
411}
412
413uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000414SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
416 uint32_t abilities = 0;
417 if (m_obj_file != NULL)
418 {
419 const Section* section = NULL;
420 const SectionList *section_list = m_obj_file->GetSectionList();
421 if (section_list == NULL)
422 return 0;
423
424 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
430 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
Greg Clayton4ceb9982010-07-21 22:54:26 +0000433 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 if (section != NULL)
435 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000436 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000440 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 else
442 m_flags.Set (flagsGotDebugAbbrevData);
443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000445 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_flags.Set (flagsGotDebugArangesData);
447
Greg Clayton4ceb9982010-07-21 22:54:26 +0000448 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000449 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_flags.Set (flagsGotDebugFrameData);
451
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000454 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 else
456 m_flags.Set (flagsGotDebugLineData);
457
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000459 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 m_flags.Set (flagsGotDebugLocData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000463 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_flags.Set (flagsGotDebugMacInfoData);
465
Greg Clayton4ceb9982010-07-21 22:54:26 +0000466 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000467 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 m_flags.Set (flagsGotDebugPubNamesData);
469
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000471 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 m_flags.Set (flagsGotDebugPubTypesData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000475 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_flags.Set (flagsGotDebugRangesData);
477
Greg Clayton4ceb9982010-07-21 22:54:26 +0000478 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000479 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 m_flags.Set (flagsGotDebugStrData);
481 }
Greg Clayton6c596612012-05-18 21:47:20 +0000482 else
483 {
484 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
485 if (symfile_dir_cstr)
486 {
487 if (strcasestr(symfile_dir_cstr, ".dsym"))
488 {
489 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
490 {
491 // We have a dSYM file that didn't have a any debug info.
492 // If the string table has a size of 1, then it was made from
493 // an executable with no debug info, or from an executable that
494 // was stripped.
495 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
496 if (section && section->GetFileSize() == 1)
497 {
498 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
499 }
500 }
501 }
502 }
503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 return abilities;
512}
513
514const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000515SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
517 if (m_flags.IsClear (got_flag))
518 {
519 m_flags.Set (got_flag);
520 const SectionList *section_list = m_obj_file->GetSectionList();
521 if (section_list)
522 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000523 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
524 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 {
526 // See if we memory mapped the DWARF segment?
527 if (m_dwarf_data.GetByteSize())
528 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000529 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531 else
532 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 data.Clear();
535 }
536 }
537 }
538 }
539 return data;
540}
541
542const DataExtractor&
543SymbolFileDWARF::get_debug_abbrev_data()
544{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000545 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000549SymbolFileDWARF::get_debug_aranges_data()
550{
551 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
552}
553
554const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555SymbolFileDWARF::get_debug_frame_data()
556{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000557 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560const DataExtractor&
561SymbolFileDWARF::get_debug_info_data()
562{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000563 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566const DataExtractor&
567SymbolFileDWARF::get_debug_line_data()
568{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000569 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570}
571
572const DataExtractor&
573SymbolFileDWARF::get_debug_loc_data()
574{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000575 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576}
577
578const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SymbolFileDWARF::get_debug_ranges_data()
580{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000581 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582}
583
584const DataExtractor&
585SymbolFileDWARF::get_debug_str_data()
586{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000587 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Greg Claytonf9eec202011-09-01 23:16:13 +0000590const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000591SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000592{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000593 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000594}
595
596const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000597SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000598{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000599 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000600}
601
Greg Clayton7f995132011-10-04 22:41:51 +0000602const DataExtractor&
603SymbolFileDWARF::get_apple_namespaces_data()
604{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000605 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
606}
607
608const DataExtractor&
609SymbolFileDWARF::get_apple_objc_data()
610{
611 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000612}
613
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615DWARFDebugAbbrev*
616SymbolFileDWARF::DebugAbbrev()
617{
618 if (m_abbr.get() == NULL)
619 {
620 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
621 if (debug_abbrev_data.GetByteSize() > 0)
622 {
623 m_abbr.reset(new DWARFDebugAbbrev());
624 if (m_abbr.get())
625 m_abbr->Parse(debug_abbrev_data);
626 }
627 }
628 return m_abbr.get();
629}
630
631const DWARFDebugAbbrev*
632SymbolFileDWARF::DebugAbbrev() const
633{
634 return m_abbr.get();
635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugInfo*
639SymbolFileDWARF::DebugInfo()
640{
641 if (m_info.get() == NULL)
642 {
643 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
644 if (get_debug_info_data().GetByteSize() > 0)
645 {
646 m_info.reset(new DWARFDebugInfo());
647 if (m_info.get())
648 {
649 m_info->SetDwarfData(this);
650 }
651 }
652 }
653 return m_info.get();
654}
655
656const DWARFDebugInfo*
657SymbolFileDWARF::DebugInfo() const
658{
659 return m_info.get();
660}
661
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000663SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000666 if (info)
667 {
668 if (GetDebugMapSymfile ())
669 {
670 // The debug map symbol file made the compile units for this DWARF
671 // file which is .o file with DWARF in it, and we should have
672 // only 1 compile unit which is at offset zero in the DWARF.
673 // TODO: modify to support LTO .o files where each .o file might
674 // have multiple DW_TAG_compile_unit tags.
675 return info->GetCompileUnit(0).get();
676 }
677 else
678 {
679 // Just a normal DWARF file whose user ID for the compile unit is
680 // the DWARF offset itself
681 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
682 }
683 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 return NULL;
685}
686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
688DWARFDebugRanges*
689SymbolFileDWARF::DebugRanges()
690{
691 if (m_ranges.get() == NULL)
692 {
693 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
694 if (get_debug_ranges_data().GetByteSize() > 0)
695 {
696 m_ranges.reset(new DWARFDebugRanges());
697 if (m_ranges.get())
698 m_ranges->Extract(this);
699 }
700 }
701 return m_ranges.get();
702}
703
704const DWARFDebugRanges*
705SymbolFileDWARF::DebugRanges() const
706{
707 return m_ranges.get();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710lldb::CompUnitSP
711SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000713 CompUnitSP cu_sp;
714 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000716 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
717 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000719 // We already parsed this compile unit, had out a shared pointer to it
720 cu_sp = comp_unit->shared_from_this();
721 }
722 else
723 {
Greg Clayton1f746072012-08-29 21:13:06 +0000724 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton1f746072012-08-29 21:13:06 +0000726 // Let the debug map create the compile unit
727 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
728 dwarf_cu->SetUserData(cu_sp.get());
729 }
730 else
731 {
732 ModuleSP module_sp (m_obj_file->GetModule());
733 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 {
Greg Clayton1f746072012-08-29 21:13:06 +0000735 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
736 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 {
Greg Clayton1f746072012-08-29 21:13:06 +0000738 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
739 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
740 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
741 if (cu_die_name)
742 {
743 std::string ramapped_file;
744 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000745
Greg Clayton1f746072012-08-29 21:13:06 +0000746 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000747 {
Greg Clayton1f746072012-08-29 21:13:06 +0000748 // If we have a full path to the compile unit, we don't need to resolve
749 // the file. This can be expensive e.g. when the source files are NFS mounted.
750 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
751 cu_file_spec.SetFile (ramapped_file.c_str(), false);
752 else
753 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000754 }
755 else
756 {
Greg Clayton1f746072012-08-29 21:13:06 +0000757 std::string fullpath(cu_comp_dir);
758 if (*fullpath.rbegin() != '/')
759 fullpath += '/';
760 fullpath += cu_die_name;
761 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
762 cu_file_spec.SetFile (ramapped_file.c_str(), false);
763 else
764 cu_file_spec.SetFile (fullpath.c_str(), false);
765 }
766
767 cu_sp.reset(new CompileUnit (module_sp,
768 dwarf_cu,
769 cu_file_spec,
770 MakeUserID(dwarf_cu->GetOffset()),
771 cu_language));
772 if (cu_sp)
773 {
774 dwarf_cu->SetUserData(cu_sp.get());
775
Greg Clayton53eb1c22012-04-02 22:59:12 +0000776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000878 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000880 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
894 func_range.GetBaseAddress().ResolveLinkedAddress();
895
Greg Clayton81c22f62011-10-19 18:09:39 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000898 func_user_id, // UserID is the DIE offset
899 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
911 }
912 }
913 return NULL;
914}
915
Greg Clayton1f746072012-08-29 21:13:06 +0000916lldb::LanguageType
917SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
918{
919 assert (sc.comp_unit);
920 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
921 if (dwarf_cu)
922 {
923 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000924 if (die)
925 {
926 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
927 if (language)
928 return (lldb::LanguageType)language;
929 }
Greg Clayton1f746072012-08-29 21:13:06 +0000930 }
931 return eLanguageTypeUnknown;
932}
933
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000934size_t
935SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
936{
937 assert (sc.comp_unit);
938 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000939 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000940 if (dwarf_cu)
941 {
942 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000943 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000944 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000945 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946 {
947 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000948 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949 {
950 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
951 ++functions_added;
952 }
953 }
954 //FixupTypes();
955 }
956 return functions_added;
957}
958
959bool
960SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
961{
962 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000963 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000964 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000966 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967
Greg Claytonda2455b2012-11-01 17:28:37 +0000968 if (cu_die)
969 {
970 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
971 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 +0000972
Greg Claytonda2455b2012-11-01 17:28:37 +0000973 // All file indexes in DWARF are one based and a file of index zero is
974 // supposed to be the compile unit itself.
975 support_files.Append (*sc.comp_unit);
976
977 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 }
980 return false;
981}
982
983struct ParseDWARFLineTableCallbackInfo
984{
985 LineTable* line_table;
986 const SectionList *section_list;
987 lldb::addr_t prev_sect_file_base_addr;
988 lldb::addr_t curr_sect_file_base_addr;
989 bool is_oso_for_debug_map;
990 bool prev_in_final_executable;
991 DWARFDebugLine::Row prev_row;
992 SectionSP prev_section_sp;
993 SectionSP curr_section_sp;
Andrew Kaylorc7401502013-01-04 22:57:56 +0000994 llvm::OwningPtr<LineSequence> curr_sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995};
996
997//----------------------------------------------------------------------
998// ParseStatementTableCallback
999//----------------------------------------------------------------------
1000static void
1001ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1002{
1003 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
1004 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1005 {
1006 // Just started parsing the line table
1007 }
1008 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1009 {
1010 // Done parsing line table, nothing to do for the cleanup
1011 }
1012 else
1013 {
1014 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1015 // We have a new row, lets append it
1016
1017 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
1018 {
1019 info->prev_section_sp = info->curr_section_sp;
1020 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1021 // If this is an end sequence entry, then we subtract one from the
1022 // address to make sure we get an address that is not the end of
1023 // a section.
1024 if (state.end_sequence && state.address != 0)
1025 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1026 else
1027 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1028
1029 if (info->curr_section_sp.get())
1030 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1031 else
1032 info->curr_sect_file_base_addr = 0;
1033 }
1034 if (info->curr_section_sp.get())
1035 {
1036 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1037 // Check for the fancy section magic to determine if we
1038
1039 if (info->is_oso_for_debug_map)
1040 {
1041 // When this is a debug map object file that contains DWARF
1042 // (referenced from an N_OSO debug map nlist entry) we will have
1043 // a file address in the file range for our section from the
1044 // original .o file, and a load address in the executable that
1045 // contains the debug map.
1046 //
1047 // If the sections for the file range and load range are
1048 // different, we have a remapped section for the function and
1049 // this address is resolved. If they are the same, then the
1050 // function for this address didn't make it into the final
1051 // executable.
Jim Inghamf94e1792012-08-11 00:35:26 +00001052 bool curr_in_final_executable = (bool) info->curr_section_sp->GetLinkedSection ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053
1054 // If we are doing DWARF with debug map, then we need to carefully
1055 // add each line table entry as there may be gaps as functions
1056 // get moved around or removed.
1057 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1058 {
1059 if (info->prev_in_final_executable)
1060 {
1061 bool terminate_previous_entry = false;
1062 if (!curr_in_final_executable)
1063 {
1064 // Check for the case where the previous line entry
1065 // in a function made it into the final executable,
1066 // yet the current line entry falls in a function
1067 // that didn't. The line table used to be contiguous
1068 // through this address range but now it isn't. We
1069 // need to terminate the previous line entry so
1070 // that we can reconstruct the line range correctly
1071 // for it and to keep the line table correct.
1072 terminate_previous_entry = true;
1073 }
1074 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1075 {
1076 // Check for cases where the line entries used to be
1077 // contiguous address ranges, but now they aren't.
1078 // This can happen when order files specify the
1079 // ordering of the functions.
1080 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1081 Section *curr_sect = info->curr_section_sp.get();
1082 Section *prev_sect = info->prev_section_sp.get();
1083 assert (curr_sect->GetLinkedSection());
1084 assert (prev_sect->GetLinkedSection());
1085 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1086 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1087 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1088 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1089 if (object_file_addr_delta != linked_file_addr_delta)
1090 terminate_previous_entry = true;
1091 }
1092
1093 if (terminate_previous_entry)
1094 {
1095 line_table->InsertLineEntry (info->prev_section_sp,
1096 state.address - info->prev_sect_file_base_addr,
1097 info->prev_row.line,
1098 info->prev_row.column,
1099 info->prev_row.file,
1100 false, // is_stmt
1101 false, // basic_block
1102 false, // state.prologue_end
1103 false, // state.epilogue_begin
1104 true); // end_sequence);
1105 }
1106 }
1107 }
1108
1109 if (curr_in_final_executable)
1110 {
1111 line_table->InsertLineEntry (info->curr_section_sp,
1112 curr_line_section_offset,
1113 state.line,
1114 state.column,
1115 state.file,
1116 state.is_stmt,
1117 state.basic_block,
1118 state.prologue_end,
1119 state.epilogue_begin,
1120 state.end_sequence);
1121 info->prev_section_sp = info->curr_section_sp;
1122 }
1123 else
1124 {
1125 // If the current address didn't make it into the final
1126 // executable, the current section will be the __text
1127 // segment in the .o file, so we need to clear this so
1128 // we can catch the next function that did make it into
1129 // the final executable.
1130 info->prev_section_sp.reset();
1131 info->curr_section_sp.reset();
1132 }
1133
1134 info->prev_in_final_executable = curr_in_final_executable;
1135 }
1136 else
1137 {
1138 // We are not in an object file that contains DWARF for an
1139 // N_OSO, this is just a normal DWARF file. The DWARF spec
1140 // guarantees that the addresses will be in increasing order
Andrew Kaylorc7401502013-01-04 22:57:56 +00001141 // for a sequence, but the line table for a single compile unit
1142 // may contain multiple sequences so we append entries to the
1143 // current sequence until we find its end, then we merge the
1144 // sequence into the main line table collection.
1145
1146 // If this is our first time here, we need to create a
1147 // sequence container.
1148 if (!info->curr_sequence_ap)
1149 {
1150 info->curr_sequence_ap.reset(line_table->CreateLineSequenceContainer());
1151 assert(info->curr_sequence_ap);
1152 }
1153 line_table->AppendLineEntryToSequence(info->curr_sequence_ap.get(),
1154 info->curr_section_sp,
1155 curr_line_section_offset,
1156 state.line,
1157 state.column,
1158 state.file,
1159 state.is_stmt,
1160 state.basic_block,
1161 state.prologue_end,
1162 state.epilogue_begin,
1163 state.end_sequence);
1164 if (state.end_sequence)
1165 {
1166 // First, put the current sequence into the line table.
1167 line_table->InsertSequence(info->curr_sequence_ap.get());
1168 // Then, empty it to prepare for the next sequence.
1169 info->curr_sequence_ap->Clear();
1170 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 }
1172 }
1173
1174 info->prev_row = state;
1175 }
1176}
1177
1178bool
1179SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1180{
1181 assert (sc.comp_unit);
1182 if (sc.comp_unit->GetLineTable() != NULL)
1183 return true;
1184
Greg Clayton1f746072012-08-29 21:13:06 +00001185 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 if (dwarf_cu)
1187 {
1188 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001189 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001191 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1192 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001194 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1195 if (line_table_ap.get())
1196 {
1197 ParseDWARFLineTableCallbackInfo info = {
1198 line_table_ap.get(),
1199 m_obj_file->GetSectionList(),
1200 0,
1201 0,
Greg Clayton1f746072012-08-29 21:13:06 +00001202 GetDebugMapSymfile () != NULL,
Greg Clayton129d12c2011-11-28 03:29:03 +00001203 false,
1204 DWARFDebugLine::Row(),
1205 SectionSP(),
Andrew Kaylorc7401502013-01-04 22:57:56 +00001206 SectionSP(),
1207 llvm::OwningPtr<LineSequence>()
Greg Clayton129d12c2011-11-28 03:29:03 +00001208 };
Greg Claytonc7bece562013-01-25 18:06:21 +00001209 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001210 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1211 sc.comp_unit->SetLineTable(line_table_ap.release());
1212 return true;
1213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 }
1215 }
1216 }
1217 return false;
1218}
1219
1220size_t
1221SymbolFileDWARF::ParseFunctionBlocks
1222(
1223 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001224 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001225 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 const DWARFDebugInfoEntry *die,
1227 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001228 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229)
1230{
1231 size_t blocks_added = 0;
1232 while (die != NULL)
1233 {
1234 dw_tag_t tag = die->Tag();
1235
1236 switch (tag)
1237 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001239 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 case DW_TAG_lexical_block:
1241 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001242 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001243 if (tag == DW_TAG_subprogram)
1244 {
1245 // Skip any DW_TAG_subprogram DIEs that are inside
1246 // of a normal or inlined functions. These will be
1247 // parsed on their own as separate entities.
1248
1249 if (depth > 0)
1250 break;
1251
1252 block = parent_block;
1253 }
1254 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001255 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001256 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001257 parent_block->AddChild(block_sp);
1258 block = block_sp.get();
1259 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001260 DWARFDebugRanges::RangeList ranges;
1261 const char *name = NULL;
1262 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 int decl_file = 0;
1265 int decl_line = 0;
1266 int decl_column = 0;
1267 int call_file = 0;
1268 int call_line = 0;
1269 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001270 if (die->GetDIENamesAndRanges (this,
1271 dwarf_cu,
1272 name,
1273 mangled_name,
1274 ranges,
1275 decl_file, decl_line, decl_column,
1276 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 {
1278 if (tag == DW_TAG_subprogram)
1279 {
1280 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001281 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001283 else if (tag == DW_TAG_inlined_subroutine)
1284 {
1285 // We get called here for inlined subroutines in two ways.
1286 // The first time is when we are making the Function object
1287 // for this inlined concrete instance. Since we're creating a top level block at
1288 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1289 // adjust the containing address.
1290 // The second time is when we are parsing the blocks inside the function that contains
1291 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1292 // function the offset will be for that function.
1293 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1294 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001295 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001296 }
1297 }
1298
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001299 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300
1301 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1302 {
1303 std::auto_ptr<Declaration> decl_ap;
1304 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001305 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1306 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307
1308 std::auto_ptr<Declaration> call_ap;
1309 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001310 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1311 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001313 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 }
1315
1316 ++blocks_added;
1317
Greg Claytondd7feaf2011-08-12 17:54:33 +00001318 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001320 blocks_added += ParseFunctionBlocks (sc,
1321 block,
1322 dwarf_cu,
1323 die->GetFirstChild(),
1324 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001325 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 }
1327 }
1328 }
1329 break;
1330 default:
1331 break;
1332 }
1333
Greg Claytondd7feaf2011-08-12 17:54:33 +00001334 // Only parse siblings of the block if we are not at depth zero. A depth
1335 // of zero indicates we are currently parsing the top level
1336 // DW_TAG_subprogram DIE
1337
1338 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001340 else
1341 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 }
1343 return blocks_added;
1344}
1345
Greg Claytonf0705c82011-10-22 03:33:13 +00001346bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001347SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1348 const DWARFDebugInfoEntry *die,
1349 ClangASTContext::TemplateParameterInfos &template_param_infos)
1350{
1351 const dw_tag_t tag = die->Tag();
1352
1353 switch (tag)
1354 {
1355 case DW_TAG_template_type_parameter:
1356 case DW_TAG_template_value_parameter:
1357 {
1358 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1359
1360 DWARFDebugInfoEntry::Attributes attributes;
1361 const size_t num_attributes = die->GetAttributes (this,
1362 dwarf_cu,
1363 fixed_form_sizes,
1364 attributes);
1365 const char *name = NULL;
1366 Type *lldb_type = NULL;
1367 clang_type_t clang_type = NULL;
1368 uint64_t uval64 = 0;
1369 bool uval64_valid = false;
1370 if (num_attributes > 0)
1371 {
1372 DWARFFormValue form_value;
1373 for (size_t i=0; i<num_attributes; ++i)
1374 {
1375 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1376
1377 switch (attr)
1378 {
1379 case DW_AT_name:
1380 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1381 name = form_value.AsCString(&get_debug_str_data());
1382 break;
1383
1384 case DW_AT_type:
1385 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1386 {
1387 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1388 lldb_type = ResolveTypeUID(type_die_offset);
1389 if (lldb_type)
1390 clang_type = lldb_type->GetClangForwardType();
1391 }
1392 break;
1393
1394 case DW_AT_const_value:
1395 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1396 {
1397 uval64_valid = true;
1398 uval64 = form_value.Unsigned();
1399 }
1400 break;
1401 default:
1402 break;
1403 }
1404 }
1405
1406 if (name && lldb_type && clang_type)
1407 {
1408 bool is_signed = false;
1409 template_param_infos.names.push_back(name);
1410 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1411 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1412 {
1413 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001414 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1415 llvm::APSInt(apint),
1416 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001417 }
1418 else
1419 {
1420 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1421 }
1422 }
1423 else
1424 {
1425 return false;
1426 }
1427
1428 }
1429 }
1430 return true;
1431
1432 default:
1433 break;
1434 }
1435 return false;
1436}
1437
1438bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001439SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1440 const DWARFDebugInfoEntry *parent_die,
1441 ClangASTContext::TemplateParameterInfos &template_param_infos)
1442{
1443
1444 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001445 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001446
Greg Claytonf0705c82011-10-22 03:33:13 +00001447 Args template_parameter_names;
1448 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1449 die != NULL;
1450 die = die->GetSibling())
1451 {
1452 const dw_tag_t tag = die->Tag();
1453
1454 switch (tag)
1455 {
1456 case DW_TAG_template_type_parameter:
1457 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001458 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001459 break;
1460
1461 default:
1462 break;
1463 }
1464 }
1465 if (template_param_infos.args.empty())
1466 return false;
1467 return template_param_infos.args.size() == template_param_infos.names.size();
1468}
1469
1470clang::ClassTemplateDecl *
1471SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001472 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001473 const char *parent_name,
1474 int tag_decl_kind,
1475 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1476{
1477 if (template_param_infos.IsValid())
1478 {
1479 std::string template_basename(parent_name);
1480 template_basename.erase (template_basename.find('<'));
1481 ClangASTContext &ast = GetClangASTContext();
1482
1483 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001484 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001485 template_basename.c_str(),
1486 tag_decl_kind,
1487 template_param_infos);
1488 }
1489 return NULL;
1490}
1491
Sean Callanana0b80ab2012-06-04 22:28:05 +00001492class SymbolFileDWARF::DelayedAddObjCClassProperty
1493{
1494public:
1495 DelayedAddObjCClassProperty
1496 (
1497 clang::ASTContext *ast,
1498 lldb::clang_type_t class_opaque_type,
1499 const char *property_name,
1500 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1501 clang::ObjCIvarDecl *ivar_decl,
1502 const char *property_setter_name,
1503 const char *property_getter_name,
1504 uint32_t property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001505 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001506 ) :
1507 m_ast (ast),
1508 m_class_opaque_type (class_opaque_type),
1509 m_property_name (property_name),
1510 m_property_opaque_type (property_opaque_type),
1511 m_ivar_decl (ivar_decl),
1512 m_property_setter_name (property_setter_name),
1513 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001514 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001515 {
Jim Ingham379397632012-10-27 02:54:13 +00001516 if (metadata != NULL)
1517 {
1518 m_metadata_ap.reset(new ClangASTMetadata());
1519 *(m_metadata_ap.get()) = *metadata;
1520 }
1521 }
1522
1523 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1524 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001525 *this = rhs;
1526 }
1527
1528 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1529 {
Jim Ingham379397632012-10-27 02:54:13 +00001530 m_ast = rhs.m_ast;
1531 m_class_opaque_type = rhs.m_class_opaque_type;
1532 m_property_name = rhs.m_property_name;
1533 m_property_opaque_type = rhs.m_property_opaque_type;
1534 m_ivar_decl = rhs.m_ivar_decl;
1535 m_property_setter_name = rhs.m_property_setter_name;
1536 m_property_getter_name = rhs.m_property_getter_name;
1537 m_property_attributes = rhs.m_property_attributes;
1538
1539 if (rhs.m_metadata_ap.get())
1540 {
1541 m_metadata_ap.reset (new ClangASTMetadata());
1542 *(m_metadata_ap.get()) = *(rhs.m_metadata_ap.get());
1543 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001544 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001545 }
1546
1547 bool Finalize() const
1548 {
1549 return ClangASTContext::AddObjCClassProperty(m_ast,
1550 m_class_opaque_type,
1551 m_property_name,
1552 m_property_opaque_type,
1553 m_ivar_decl,
1554 m_property_setter_name,
1555 m_property_getter_name,
1556 m_property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001557 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001558 }
1559private:
1560 clang::ASTContext *m_ast;
1561 lldb::clang_type_t m_class_opaque_type;
1562 const char *m_property_name;
1563 lldb::clang_type_t m_property_opaque_type;
1564 clang::ObjCIvarDecl *m_ivar_decl;
1565 const char *m_property_setter_name;
1566 const char *m_property_getter_name;
1567 uint32_t m_property_attributes;
Jim Ingham379397632012-10-27 02:54:13 +00001568 std::auto_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001569};
1570
Sean Callananfaa0bb32012-12-05 23:37:14 +00001571struct BitfieldInfo
1572{
1573 uint64_t bit_size;
1574 uint64_t bit_offset;
1575
1576 BitfieldInfo () :
1577 bit_size (LLDB_INVALID_ADDRESS),
1578 bit_offset (LLDB_INVALID_ADDRESS)
1579 {
1580 }
1581
1582 bool IsValid ()
1583 {
1584 return (bit_size != LLDB_INVALID_ADDRESS) &&
1585 (bit_offset != LLDB_INVALID_ADDRESS);
1586 }
1587};
1588
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589size_t
1590SymbolFileDWARF::ParseChildMembers
1591(
1592 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001593 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001594 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001595 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001596 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1598 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001599 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001600 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001601 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001602 bool &is_a_class,
1603 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604)
1605{
1606 if (parent_die == NULL)
1607 return 0;
1608
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609 size_t count = 0;
1610 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001611 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001612 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001613 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001614
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1616 {
1617 dw_tag_t tag = die->Tag();
1618
1619 switch (tag)
1620 {
1621 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001622 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623 {
1624 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001625 const size_t num_attributes = die->GetAttributes (this,
1626 dwarf_cu,
1627 fixed_form_sizes,
1628 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001629 if (num_attributes > 0)
1630 {
1631 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001632 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001633 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001634 const char *prop_name = NULL;
1635 const char *prop_getter_name = NULL;
1636 const char *prop_setter_name = NULL;
1637 uint32_t prop_attributes = 0;
1638
1639
Greg Clayton24739922010-10-13 03:15:28 +00001640 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001641 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001642 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001643 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 size_t byte_size = 0;
1645 size_t bit_offset = 0;
1646 size_t bit_size = 0;
1647 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001648 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001649 {
1650 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1651 DWARFFormValue form_value;
1652 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1653 {
1654 switch (attr)
1655 {
1656 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1657 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1658 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1659 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1660 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1661 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1662 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1663 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1664 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001665 if (form_value.BlockData())
1666 {
1667 Value initialValue(0);
1668 Value memberOffset(0);
1669 const DataExtractor& debug_info_data = get_debug_info_data();
1670 uint32_t block_length = form_value.Unsigned();
1671 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1672 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1673 NULL, // clang::ASTContext *
1674 NULL, // ClangExpressionVariableList *
1675 NULL, // ClangExpressionDeclMap *
1676 NULL, // RegisterContext *
1677 debug_info_data,
1678 block_offset,
1679 block_length,
1680 eRegisterKindDWARF,
1681 &initialValue,
1682 memberOffset,
1683 NULL))
1684 {
1685 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1686 }
1687 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688 break;
1689
Greg Clayton8cf05932010-07-22 18:30:50 +00001690 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001691 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001692 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1693 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1694 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1695 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1696
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001697 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001698 case DW_AT_declaration:
1699 case DW_AT_description:
1700 case DW_AT_mutable:
1701 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702 case DW_AT_sibling:
1703 break;
1704 }
1705 }
1706 }
Sean Callanana6582262012-04-05 00:12:52 +00001707
1708 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001709 {
Sean Callanana6582262012-04-05 00:12:52 +00001710 ConstString fixed_getter;
1711 ConstString fixed_setter;
1712
1713 // Check if the property getter/setter were provided as full
1714 // names. We want basenames, so we extract them.
1715
1716 if (prop_getter_name && prop_getter_name[0] == '-')
1717 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001718 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1719 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001720 }
1721
1722 if (prop_setter_name && prop_setter_name[0] == '-')
1723 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001724 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1725 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001726 }
1727
1728 // If the names haven't been provided, they need to be
1729 // filled in.
1730
1731 if (!prop_getter_name)
1732 {
1733 prop_getter_name = prop_name;
1734 }
1735 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1736 {
1737 StreamString ss;
1738
1739 ss.Printf("set%c%s:",
1740 toupper(prop_name[0]),
1741 &prop_name[1]);
1742
1743 fixed_setter.SetCString(ss.GetData());
1744 prop_setter_name = fixed_setter.GetCString();
1745 }
Sean Callanan751aac62012-03-29 19:07:06 +00001746 }
1747
1748 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001749 // represents fields that are references with bad byte size
1750 // and bit size/offset information such as:
1751 //
1752 // DW_AT_byte_size( 0x00 )
1753 // DW_AT_bit_size( 0x40 )
1754 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1755 //
1756 // So check the bit offset to make sure it is sane, and if
1757 // the values are not sane, remove them. If we don't do this
1758 // then we will end up with a crash if we try to use this
1759 // type in an expression when clang becomes unhappy with its
1760 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001761
Greg Clayton44953932011-10-25 01:25:35 +00001762 if (bit_offset > 128)
1763 {
1764 bit_size = 0;
1765 bit_offset = 0;
1766 }
1767
1768 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001769 if (class_language == eLanguageTypeObjC ||
1770 class_language == eLanguageTypeObjC_plus_plus)
1771 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001772
1773 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1774 {
1775 // Not all compilers will mark the vtable pointer
1776 // member as artificial (llvm-gcc). We can't have
1777 // the virtual members in our classes otherwise it
1778 // throws off all child offsets since we end up
1779 // having and extra pointer sized member in our
1780 // class layouts.
1781 is_artificial = true;
1782 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001783
Greg Clayton24739922010-10-13 03:15:28 +00001784 if (is_artificial == false)
1785 {
1786 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001787
Jim Inghame3ae82a2011-11-12 01:36:43 +00001788 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001789 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001790 {
Sean Callanan751aac62012-03-29 19:07:06 +00001791 if (member_type)
1792 {
1793 if (accessibility == eAccessNone)
1794 accessibility = default_accessibility;
1795 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001796
1797 BitfieldInfo this_field_info;
1798
1799 this_field_info.bit_size = bit_size;
1800
1801 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001802 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001803 /////////////////////////////////////////////////////////////
1804 // How to locate a field given the DWARF debug information
1805 //
1806 // AT_byte_size indicates the size of the word in which the
1807 // bit offset must be interpreted.
1808 //
1809 // AT_data_member_location indicates the byte offset of the
1810 // word from the base address of the structure.
1811 //
1812 // AT_bit_offset indicates how many bits into the word
1813 // (according to the host endianness) the low-order bit of
1814 // the field starts. AT_bit_offset can be negative.
1815 //
1816 // AT_bit_size indicates the size of the field in bits.
1817 /////////////////////////////////////////////////////////////
1818
1819 this_field_info.bit_offset = 0;
1820
1821 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1822
1823 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1824 {
1825 this_field_info.bit_offset += byte_size * 8;
1826 this_field_info.bit_offset -= (bit_offset + bit_size);
1827 }
1828 else
1829 {
1830 this_field_info.bit_offset += bit_offset;
1831 }
1832 }
1833
1834 // If the member to be emitted did not start on a character boundary and there is
1835 // empty space between the last field and this one, then we need to emit an
1836 // anonymous member filling up the space up to its start. There are three cases
1837 // here:
1838 //
1839 // 1 If the previous member ended on a character boundary, then we can emit an
1840 // anonymous member starting at the most recent character boundary.
1841 //
1842 // 2 If the previous member did not end on a character boundary and the distance
1843 // from the end of the previous member to the current member is less than a
1844 // word width, then we can emit an anonymous member starting right after the
1845 // previous member and right before this member.
1846 //
1847 // 3 If the previous member did not end on a character boundary and the distance
1848 // from the end of the previous member to the current member is greater than
1849 // or equal a word width, then we act as in Case 1.
1850
1851 const uint64_t character_width = 8;
1852 const uint64_t word_width = 32;
1853
1854 if (this_field_info.IsValid())
1855 {
1856 // Objective-C has invalid DW_AT_bit_offset values in older versions
1857 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001858 // if we have a new enough clang.
1859 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001860
Greg Clayton37c36e42012-11-27 00:59:26 +00001861 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1862 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1863
1864 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001865 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001866 BitfieldInfo anon_field_info;
1867
1868 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001869 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001870 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001871
Sean Callananfaa0bb32012-12-05 23:37:14 +00001872 if (last_field_info.IsValid())
1873 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001874
Sean Callananfaa0bb32012-12-05 23:37:14 +00001875 if (this_field_info.bit_offset != last_field_end)
1876 {
1877 if (((last_field_end % character_width) == 0) || // case 1
1878 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1879 {
1880 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1881 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1882 }
1883 else // case 2
1884 {
1885 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1886 anon_field_info.bit_offset = last_field_end;
1887 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001888 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001889 }
1890
Sean Callananfaa0bb32012-12-05 23:37:14 +00001891 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001892 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001893 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1894 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001895 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001896 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001897 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001898
Sean Callananfaa0bb32012-12-05 23:37:14 +00001899 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001900 }
1901 }
1902 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001903
Sean Callananfa3ab452012-12-14 00:54:13 +00001904 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1905
1906 {
1907 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1908 // If the current field is at the end of the structure, then there is definitely no room for extra
1909 // elements and we override the type to array[0].
1910
1911 clang_type_t member_array_element_type;
1912 uint64_t member_array_size;
1913 bool member_array_is_incomplete;
1914
1915 if (GetClangASTContext().IsArrayType(member_clang_type,
1916 &member_array_element_type,
1917 &member_array_size,
1918 &member_array_is_incomplete) &&
1919 !member_array_is_incomplete)
1920 {
1921 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1922
1923 if (member_byte_offset >= parent_byte_size)
1924 {
1925 if (member_array_size != 1)
1926 {
1927 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64,
1928 MakeUserID(die->GetOffset()),
1929 name,
1930 encoding_uid,
1931 MakeUserID(parent_die->GetOffset()));
1932 }
1933
1934 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0);
1935 }
1936 }
1937 }
1938
Greg Clayton88bc7f32012-11-06 00:20:41 +00001939 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001940 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001941 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001942 accessibility,
1943 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001944
Jim Ingham379397632012-10-27 02:54:13 +00001945 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001946
1947 if (this_field_info.IsValid())
1948 {
1949 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1950 last_field_info = this_field_info;
1951 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001952 }
1953 else
1954 {
Sean Callanan751aac62012-03-29 19:07:06 +00001955 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001956 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00001957 MakeUserID(die->GetOffset()),
1958 name,
1959 encoding_uid);
1960 else
Daniel Malead01b2952012-11-29 21:49:15 +00001961 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00001962 MakeUserID(die->GetOffset()),
1963 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001964 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001965 }
Sean Callanan751aac62012-03-29 19:07:06 +00001966
Jim Inghame3ae82a2011-11-12 01:36:43 +00001967 if (prop_name != NULL)
1968 {
Sean Callanan751aac62012-03-29 19:07:06 +00001969 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001970
Sean Callanan751aac62012-03-29 19:07:06 +00001971 if (field_decl)
1972 {
1973 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1974 assert (ivar_decl != NULL);
1975 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001976
Jim Ingham379397632012-10-27 02:54:13 +00001977 ClangASTMetadata metadata;
1978 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001979 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1980 class_clang_type,
1981 prop_name,
1982 member_type->GetClangLayoutType(),
1983 ivar_decl,
1984 prop_setter_name,
1985 prop_getter_name,
1986 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001987 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001988
Sean Callananad880762012-04-18 01:06:17 +00001989 if (ivar_decl)
Jim Ingham379397632012-10-27 02:54:13 +00001990 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001991 }
Greg Clayton24739922010-10-13 03:15:28 +00001992 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001994 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995 }
1996 break;
1997
1998 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001999 // Let the type parsing code handle this one for us.
2000 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001 break;
2002
2003 case DW_TAG_inheritance:
2004 {
2005 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002006 if (default_accessibility == eAccessNone)
2007 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008 // TODO: implement DW_TAG_inheritance type parsing
2009 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002010 const size_t num_attributes = die->GetAttributes (this,
2011 dwarf_cu,
2012 fixed_form_sizes,
2013 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 if (num_attributes > 0)
2015 {
2016 Declaration decl;
2017 DWARFExpression location;
2018 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002019 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020 bool is_virtual = false;
2021 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002022 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 uint32_t i;
2024 for (i=0; i<num_attributes; ++i)
2025 {
2026 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2027 DWARFFormValue form_value;
2028 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2029 {
2030 switch (attr)
2031 {
2032 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2033 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2034 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2035 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002036 case DW_AT_data_member_location:
2037 if (form_value.BlockData())
2038 {
2039 Value initialValue(0);
2040 Value memberOffset(0);
2041 const DataExtractor& debug_info_data = get_debug_info_data();
2042 uint32_t block_length = form_value.Unsigned();
2043 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2044 if (DWARFExpression::Evaluate (NULL,
2045 NULL,
2046 NULL,
2047 NULL,
2048 NULL,
2049 debug_info_data,
2050 block_offset,
2051 block_length,
2052 eRegisterKindDWARF,
2053 &initialValue,
2054 memberOffset,
2055 NULL))
2056 {
2057 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
2058 }
2059 }
2060 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002061
2062 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002063 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002064 break;
2065
2066 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
2067 default:
2068 case DW_AT_sibling:
2069 break;
2070 }
2071 }
2072 }
2073
Greg Clayton526e5af2010-11-13 03:52:47 +00002074 Type *base_class_type = ResolveTypeUID(encoding_uid);
2075 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002076
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002077 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2078 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002079 if (class_language == eLanguageTypeObjC)
2080 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002081 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002082 }
2083 else
2084 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002085 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002086 accessibility,
2087 is_virtual,
2088 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002089
2090 if (is_virtual)
2091 {
2092 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2093 clang::CharUnits::fromQuantity(member_byte_offset)));
2094 }
2095 else
2096 {
2097 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2098 clang::CharUnits::fromQuantity(member_byte_offset)));
2099 }
Greg Clayton9e409562010-07-28 02:04:09 +00002100 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002101 }
2102 }
2103 break;
2104
2105 default:
2106 break;
2107 }
2108 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002109
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002110 return count;
2111}
2112
2113
2114clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002115SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116{
2117 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002118 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002119 {
2120 DWARFCompileUnitSP cu_sp;
2121 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2122 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002123 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002124 }
2125 return NULL;
2126}
2127
2128clang::DeclContext*
2129SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2130{
Greg Clayton81c22f62011-10-19 18:09:39 +00002131 if (UserIDMatches(type_uid))
2132 return GetClangDeclContextForDIEOffset (sc, type_uid);
2133 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002134}
2135
2136Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002137SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002138{
Greg Clayton81c22f62011-10-19 18:09:39 +00002139 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002140 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002141 DWARFDebugInfo* debug_info = DebugInfo();
2142 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002143 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002144 DWARFCompileUnitSP cu_sp;
2145 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002146 const bool assert_not_being_parsed = true;
2147 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002148 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002149 }
2150 return NULL;
2151}
2152
Greg Claytoncab36a32011-12-08 05:16:30 +00002153Type*
2154SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002155{
Greg Claytoncab36a32011-12-08 05:16:30 +00002156 if (die != NULL)
2157 {
Greg Clayton3bffb082011-12-10 02:15:28 +00002158 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
2159 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002160 GetObjectFile()->GetModule()->LogMessage (log.get(),
2161 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2162 die->GetOffset(),
2163 DW_TAG_value_to_name(die->Tag()),
2164 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002165
Greg Claytoncab36a32011-12-08 05:16:30 +00002166 // We might be coming in in the middle of a type tree (a class
2167 // withing a class, an enum within a class), so parse any needed
2168 // parent DIEs before we get to this one...
2169 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2170 switch (decl_ctx_die->Tag())
2171 {
2172 case DW_TAG_structure_type:
2173 case DW_TAG_union_type:
2174 case DW_TAG_class_type:
2175 {
2176 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002177 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002178 GetObjectFile()->GetModule()->LogMessage (log.get(),
2179 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2180 die->GetOffset(),
2181 DW_TAG_value_to_name(die->Tag()),
2182 die->GetName(this, cu),
2183 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002184//
2185// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2186// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2187// {
2188// if (log)
2189// GetObjectFile()->GetModule()->LogMessage (log.get(),
2190// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2191// die->GetOffset(),
2192// DW_TAG_value_to_name(die->Tag()),
2193// die->GetName(this, cu),
2194// decl_ctx_die->GetOffset());
2195// // Ask the type to complete itself if it already hasn't since if we
2196// // want a function (method or static) from a class, the class must
2197// // create itself and add it's own methods and class functions.
2198// if (parent_type)
2199// parent_type->GetClangFullType();
2200// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002201 }
2202 break;
2203
2204 default:
2205 break;
2206 }
2207 return ResolveType (cu, die);
2208 }
2209 return NULL;
2210}
2211
Greg Clayton6beaaa62011-01-17 03:46:26 +00002212// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2213// SymbolFileDWARF objects to detect if this DWARF file is the one that
2214// can resolve a clang_type.
2215bool
2216SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2217{
2218 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2219 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2220 return die != NULL;
2221}
2222
2223
Greg Clayton1be10fc2010-09-29 01:12:09 +00002224lldb::clang_type_t
2225SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2226{
2227 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002228 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2229 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002230 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002231 {
2232 // We have already resolved this type...
2233 return clang_type;
2234 }
2235 // Once we start resolving this type, remove it from the forward declaration
2236 // map in case anyone child members or other types require this type to get resolved.
2237 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2238 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002239 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002240
Greg Clayton1be10fc2010-09-29 01:12:09 +00002241
Greg Clayton85ae2e12011-10-18 23:36:41 +00002242 // Disable external storage for this type so we don't get anymore
2243 // clang::ExternalASTSource queries for this type.
2244 ClangASTContext::SetHasExternalStorage (clang_type, false);
2245
Greg Clayton450e3f32010-10-12 02:24:53 +00002246 DWARFDebugInfo* debug_info = DebugInfo();
2247
Greg Clayton53eb1c22012-04-02 22:59:12 +00002248 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002249 Type *type = m_die_to_type.lookup (die);
2250
2251 const dw_tag_t tag = die->Tag();
2252
Greg Claytonbaf95da2012-03-30 23:50:54 +00002253 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002254 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002255 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002256 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002257 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002258 MakeUserID(die->GetOffset()),
2259 DW_TAG_value_to_name(tag),
2260 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002261
Greg Claytonbaf95da2012-03-30 23:50:54 +00002262 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002263 assert (clang_type);
2264 DWARFDebugInfoEntry::Attributes attributes;
2265
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002266 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002267
2268 switch (tag)
2269 {
2270 case DW_TAG_structure_type:
2271 case DW_TAG_union_type:
2272 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002273 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002274 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002275
Greg Clayton1be10fc2010-09-29 01:12:09 +00002276 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002277 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002278 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002279
Sean Callanan77a1fd32012-02-27 20:07:01 +00002280 LanguageType class_language = eLanguageTypeUnknown;
2281 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2282 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002283 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002284 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002285 // For objective C we don't start the definition when
2286 // the class is created.
2287 ast.StartTagDeclarationDefinition (clang_type);
2288 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002289
2290 int tag_decl_kind = -1;
2291 AccessType default_accessibility = eAccessNone;
2292 if (tag == DW_TAG_structure_type)
2293 {
2294 tag_decl_kind = clang::TTK_Struct;
2295 default_accessibility = eAccessPublic;
2296 }
2297 else if (tag == DW_TAG_union_type)
2298 {
2299 tag_decl_kind = clang::TTK_Union;
2300 default_accessibility = eAccessPublic;
2301 }
2302 else if (tag == DW_TAG_class_type)
2303 {
2304 tag_decl_kind = clang::TTK_Class;
2305 default_accessibility = eAccessPrivate;
2306 }
2307
Greg Clayton53eb1c22012-04-02 22:59:12 +00002308 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002309 std::vector<clang::CXXBaseSpecifier *> base_classes;
2310 std::vector<int> member_accessibilities;
2311 bool is_a_class = false;
2312 // Parse members and base classes first
2313 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002314
2315 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002316 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002317 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002318 die,
2319 clang_type,
2320 class_language,
2321 base_classes,
2322 member_accessibilities,
2323 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002324 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002325 default_accessibility,
2326 is_a_class,
2327 layout_info);
2328
2329 // Now parse any methods if there were any...
2330 size_t num_functions = member_function_dies.Size();
2331 if (num_functions > 0)
2332 {
2333 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002334 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002335 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002336 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002337 }
2338
2339 if (class_language == eLanguageTypeObjC)
2340 {
Greg Clayton84db9102012-03-26 23:03:23 +00002341 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002342 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002343 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002344
Sean Callanan77a1fd32012-02-27 20:07:01 +00002345 DIEArray method_die_offsets;
2346 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002347 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002348 if (m_apple_objc_ap.get())
2349 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2350 }
2351 else
2352 {
2353 if (!m_indexed)
2354 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002355
Sean Callanan77a1fd32012-02-27 20:07:01 +00002356 ConstString class_name (class_str.c_str());
2357 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2358 }
2359
2360 if (!method_die_offsets.empty())
2361 {
2362 DWARFDebugInfo* debug_info = DebugInfo();
2363
2364 DWARFCompileUnit* method_cu = NULL;
2365 const size_t num_matches = method_die_offsets.size();
2366 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002367 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002368 const dw_offset_t die_offset = method_die_offsets[i];
2369 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2370
2371 if (method_die)
2372 ResolveType (method_cu, method_die);
2373 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002374 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002375 if (m_using_apple_tables)
2376 {
2377 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2378 die_offset, class_str.c_str());
2379 }
2380 }
2381 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002382 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002383
2384 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2385 pi != pe;
2386 ++pi)
2387 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002388 }
2389 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002390
2391 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2392 // need to tell the clang type it is actually a class.
2393 if (class_language != eLanguageTypeObjC)
2394 {
2395 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2396 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2397 }
2398
2399 // Since DW_TAG_structure_type gets used for both classes
2400 // and structures, we may need to set any DW_TAG_member
2401 // fields to have a "private" access if none was specified.
2402 // When we parsed the child members we tracked that actual
2403 // accessibility value for each DW_TAG_member in the
2404 // "member_accessibilities" array. If the value for the
2405 // member is zero, then it was set to the "default_accessibility"
2406 // which for structs was "public". Below we correct this
2407 // by setting any fields to "private" that weren't correctly
2408 // set.
2409 if (is_a_class && !member_accessibilities.empty())
2410 {
2411 // This is a class and all members that didn't have
2412 // their access specified are private.
2413 ast.SetDefaultAccessForRecordFields (clang_type,
2414 eAccessPrivate,
2415 &member_accessibilities.front(),
2416 member_accessibilities.size());
2417 }
2418
2419 if (!base_classes.empty())
2420 {
2421 ast.SetBaseClassesForClassType (clang_type,
2422 &base_classes.front(),
2423 base_classes.size());
2424
2425 // Clang will copy each CXXBaseSpecifier in "base_classes"
2426 // so we have to free them all.
2427 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2428 base_classes.size());
2429 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002430 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002431 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002432
2433 ast.BuildIndirectFields (clang_type);
2434
Sean Callanan77a1fd32012-02-27 20:07:01 +00002435 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002436
Greg Clayton2508b9b2012-11-01 23:20:02 +00002437 if (!layout_info.field_offsets.empty() ||
2438 !layout_info.base_offsets.empty() ||
2439 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002440 {
2441 if (type)
2442 layout_info.bit_size = type->GetByteSize() * 8;
2443 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002444 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002445
2446 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2447 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002448 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002449 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002450 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002451 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002452 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002453 clang_type,
2454 record_decl,
2455 layout_info.bit_size,
2456 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002457 (uint32_t)layout_info.field_offsets.size(),
2458 (uint32_t)layout_info.base_offsets.size(),
2459 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002460
Greg Clayton2508b9b2012-11-01 23:20:02 +00002461 uint32_t idx;
2462 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002463 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002464 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002465 {
2466 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002467 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002468 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002469 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002470 (uint32_t)pos->second,
2471 pos->first->getNameAsString().c_str());
2472 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002473 }
2474
2475 {
2476 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2477 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2478 {
2479 GetObjectFile()->GetModule()->LogMessage (log.get(),
2480 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2481 clang_type,
2482 idx,
2483 (uint32_t)base_pos->second.getQuantity(),
2484 base_pos->first->getNameAsString().c_str());
2485 }
2486 }
2487 {
2488 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2489 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2490 {
2491 GetObjectFile()->GetModule()->LogMessage (log.get(),
2492 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2493 clang_type,
2494 idx,
2495 (uint32_t)vbase_pos->second.getQuantity(),
2496 vbase_pos->first->getNameAsString().c_str());
2497 }
2498 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002499 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002500 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2501 }
2502 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002503 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002504
Greg Claytonc93237c2010-10-01 20:48:32 +00002505 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002506
2507 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002508 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002509 if (die->HasChildren())
2510 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002511 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2512 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002513 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002514 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002515 return clang_type;
2516
2517 default:
2518 assert(false && "not a forward clang type decl!");
2519 break;
2520 }
2521 return NULL;
2522}
2523
Greg Claytonc685f8e2010-09-15 04:15:46 +00002524Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002525SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002526{
2527 if (type_die != NULL)
2528 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002529 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002530
Greg Claytonc685f8e2010-09-15 04:15:46 +00002531 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002532 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002533
Greg Clayton24739922010-10-13 03:15:28 +00002534 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002535 {
2536 if (type != DIE_IS_BEING_PARSED)
2537 return type;
2538
2539 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002540 type_die->GetOffset(),
2541 DW_TAG_value_to_name(type_die->Tag()),
2542 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002543
2544 }
2545 else
2546 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002547 }
2548 return NULL;
2549}
2550
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002551CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002552SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002553{
2554 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002555 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002556 {
2557 // The symbol vendor doesn't know about this compile unit, we
2558 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002559 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002560 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002561 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002562}
2563
2564bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002565SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002566{
Greg Clayton72310352013-02-23 04:12:47 +00002567 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002568 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002569 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002570
Greg Clayton81c22f62011-10-19 18:09:39 +00002571 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002572 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002573 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002574
2575 if (sc.function)
2576 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002577 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002578 return true;
2579 }
2580
2581 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002582}
2583
2584uint32_t
2585SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2586{
2587 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002588 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002589 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002590 so_addr.GetOffset(),
2591 resolve_scope);
2592 uint32_t resolved = 0;
2593 if (resolve_scope & ( eSymbolContextCompUnit |
2594 eSymbolContextFunction |
2595 eSymbolContextBlock |
2596 eSymbolContextLineEntry))
2597 {
2598 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2599
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002600 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002601 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002602 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002603 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002604 if (cu_offset != DW_INVALID_OFFSET)
2605 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002606 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002607 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2608 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002609 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002610 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002611 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002612 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002613 resolved |= eSymbolContextCompUnit;
2614
Greg Clayton6ab80132012-12-12 17:30:52 +00002615 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002616 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2617 {
2618 DWARFDebugInfoEntry *function_die = NULL;
2619 DWARFDebugInfoEntry *block_die = NULL;
2620 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002621 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002622 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2623 }
2624 else
2625 {
2626 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2627 }
2628
2629 if (function_die != NULL)
2630 {
2631 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2632 if (sc.function == NULL)
2633 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2634 }
2635 else
2636 {
2637 // We might have had a compile unit that had discontiguous
2638 // address ranges where the gaps are symbols that don't have
2639 // any debug info. Discontiguous compile unit address ranges
2640 // should only happen when there aren't other functions from
2641 // other compile units in these gaps. This helps keep the size
2642 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002643 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002644 }
2645
2646 if (sc.function != NULL)
2647 {
2648 resolved |= eSymbolContextFunction;
2649
2650 if (resolve_scope & eSymbolContextBlock)
2651 {
2652 Block& block = sc.function->GetBlock (true);
2653
2654 if (block_die != NULL)
2655 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2656 else
2657 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2658 if (sc.block)
2659 resolved |= eSymbolContextBlock;
2660 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002661 }
2662 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002663
2664 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2665 {
2666 LineTable *line_table = sc.comp_unit->GetLineTable();
2667 if (line_table != NULL)
2668 {
2669 if (so_addr.IsLinkedAddress())
2670 {
2671 Address linked_addr (so_addr);
2672 linked_addr.ResolveLinkedAddress();
2673 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2674 {
2675 resolved |= eSymbolContextLineEntry;
2676 }
2677 }
2678 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2679 {
2680 resolved |= eSymbolContextLineEntry;
2681 }
2682 }
2683 }
2684
2685 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2686 {
2687 // We might have had a compile unit that had discontiguous
2688 // address ranges where the gaps are symbols that don't have
2689 // any debug info. Discontiguous compile unit address ranges
2690 // should only happen when there aren't other functions from
2691 // other compile units in these gaps. This helps keep the size
2692 // of the aranges down.
2693 sc.comp_unit = NULL;
2694 resolved &= ~eSymbolContextCompUnit;
2695 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002696 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002697 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002698 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002699 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2700 cu_offset,
2701 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702 }
2703 }
2704 }
2705 }
2706 }
2707 return resolved;
2708}
2709
2710
2711
2712uint32_t
2713SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2714{
2715 const uint32_t prev_size = sc_list.GetSize();
2716 if (resolve_scope & eSymbolContextCompUnit)
2717 {
2718 DWARFDebugInfo* debug_info = DebugInfo();
2719 if (debug_info)
2720 {
2721 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002722 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002723
Greg Clayton53eb1c22012-04-02 22:59:12 +00002724 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002726 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002727 const bool full_match = file_spec.GetDirectory();
2728 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002729 if (check_inlines || file_spec_matches_cu_file_spec)
2730 {
2731 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002732 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002733 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002734 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002735 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002736
Greg Clayton526a4ae2012-05-16 22:09:01 +00002737 // If we are looking for inline functions only and we don't
2738 // find it in the support files, we are done.
2739 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002740 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002741 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2742 if (file_idx == UINT32_MAX)
2743 continue;
2744 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002745
Greg Clayton526a4ae2012-05-16 22:09:01 +00002746 if (line != 0)
2747 {
2748 LineTable *line_table = sc.comp_unit->GetLineTable();
2749
2750 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002751 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002752 // We will have already looked up the file index if
2753 // we are searching for inline entries.
2754 if (!check_inlines)
2755 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002756
Greg Clayton526a4ae2012-05-16 22:09:01 +00002757 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002758 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002759 uint32_t found_line;
2760 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2761 found_line = sc.line_entry.line;
2762
2763 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002764 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002765 sc.function = NULL;
2766 sc.block = NULL;
2767 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002769 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2770 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002771 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002772 DWARFDebugInfoEntry *function_die = NULL;
2773 DWARFDebugInfoEntry *block_die = NULL;
2774 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002775
Greg Clayton526a4ae2012-05-16 22:09:01 +00002776 if (function_die != NULL)
2777 {
2778 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2779 if (sc.function == NULL)
2780 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2781 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002782
Greg Clayton526a4ae2012-05-16 22:09:01 +00002783 if (sc.function != NULL)
2784 {
2785 Block& block = sc.function->GetBlock (true);
2786
2787 if (block_die != NULL)
2788 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2789 else
2790 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2791 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002792 }
2793 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002794
Greg Clayton526a4ae2012-05-16 22:09:01 +00002795 sc_list.Append(sc);
2796 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2797 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002798 }
2799 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002800 else if (file_spec_matches_cu_file_spec && !check_inlines)
2801 {
2802 // only append the context if we aren't looking for inline call sites
2803 // by file and line and if the file spec matches that of the compile unit
2804 sc_list.Append(sc);
2805 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002806 }
2807 else if (file_spec_matches_cu_file_spec && !check_inlines)
2808 {
2809 // only append the context if we aren't looking for inline call sites
2810 // by file and line and if the file spec matches that of the compile unit
2811 sc_list.Append(sc);
2812 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002813
Greg Clayton526a4ae2012-05-16 22:09:01 +00002814 if (!check_inlines)
2815 break;
2816 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002817 }
2818 }
2819 }
2820 }
2821 return sc_list.GetSize() - prev_size;
2822}
2823
2824void
2825SymbolFileDWARF::Index ()
2826{
2827 if (m_indexed)
2828 return;
2829 m_indexed = true;
2830 Timer scoped_timer (__PRETTY_FUNCTION__,
2831 "SymbolFileDWARF::Index (%s)",
2832 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2833
2834 DWARFDebugInfo* debug_info = DebugInfo();
2835 if (debug_info)
2836 {
2837 uint32_t cu_idx = 0;
2838 const uint32_t num_compile_units = GetNumCompileUnits();
2839 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2840 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002841 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002842
Greg Clayton53eb1c22012-04-02 22:59:12 +00002843 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002844
Greg Clayton53eb1c22012-04-02 22:59:12 +00002845 dwarf_cu->Index (cu_idx,
2846 m_function_basename_index,
2847 m_function_fullname_index,
2848 m_function_method_index,
2849 m_function_selector_index,
2850 m_objc_class_selectors_index,
2851 m_global_index,
2852 m_type_index,
2853 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854
2855 // Keep memory down by clearing DIEs if this generate function
2856 // caused them to be parsed
2857 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002858 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002859 }
2860
Greg Claytond4a2b372011-09-12 23:21:58 +00002861 m_function_basename_index.Finalize();
2862 m_function_fullname_index.Finalize();
2863 m_function_method_index.Finalize();
2864 m_function_selector_index.Finalize();
2865 m_objc_class_selectors_index.Finalize();
2866 m_global_index.Finalize();
2867 m_type_index.Finalize();
2868 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002869
Greg Clayton24739922010-10-13 03:15:28 +00002870#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002871 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002872 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002873 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2874 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002875 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2876 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2877 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2878 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2879 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2880 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002881 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002882 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002883#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002884 }
2885}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002886
2887bool
2888SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2889{
2890 if (namespace_decl == NULL)
2891 {
2892 // Invalid namespace decl which means we aren't matching only things
2893 // in this symbol file, so return true to indicate it matches this
2894 // symbol file.
2895 return true;
2896 }
2897
2898 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2899
2900 if (namespace_ast == NULL)
2901 return true; // No AST in the "namespace_decl", return true since it
2902 // could then match any symbol file, including this one
2903
2904 if (namespace_ast == GetClangASTContext().getASTContext())
2905 return true; // The ASTs match, return true
2906
2907 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002908 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2909
2910 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002911 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002912
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002913 return false;
2914}
2915
Greg Clayton2506a7a2011-10-12 23:34:26 +00002916bool
2917SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2918 DWARFCompileUnit* cu,
2919 const DWARFDebugInfoEntry* die)
2920{
2921 // No namespace specified, so the answesr i
2922 if (namespace_decl == NULL)
2923 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002924
2925 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002926
Greg Clayton437a1352012-04-09 22:43:43 +00002927 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2928 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002929 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002930 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002931 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002932
Greg Clayton2506a7a2011-10-12 23:34:26 +00002933 if (clang_namespace_decl)
2934 {
2935 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002936 {
2937 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002938 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002939 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002940 }
2941
Greg Clayton437a1352012-04-09 22:43:43 +00002942 if (clang_namespace_decl == die_clang_decl_ctx)
2943 return true;
2944 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002945 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002946 }
2947 else
2948 {
2949 // We have a namespace_decl that was not NULL but it contained
2950 // a NULL "clang::NamespaceDecl", so this means the global namespace
2951 // So as long the the contained decl context DIE isn't a namespace
2952 // we should be ok.
2953 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2954 return true;
2955 }
2956 }
Sean Callananebe60672011-10-13 21:50:33 +00002957
2958 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002959 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002960
Greg Clayton2506a7a2011-10-12 23:34:26 +00002961 return false;
2962}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002963uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002964SymbolFileDWARF::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 +00002965{
Greg Clayton21f2a492011-10-06 00:09:08 +00002966 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2967
2968 if (log)
2969 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002970 GetObjectFile()->GetModule()->LogMessage (log.get(),
2971 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2972 name.GetCString(),
2973 namespace_decl,
2974 append,
2975 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002976 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002977
2978 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2979 return 0;
2980
Greg Claytonc685f8e2010-09-15 04:15:46 +00002981 DWARFDebugInfo* info = DebugInfo();
2982 if (info == NULL)
2983 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002984
2985 // If we aren't appending the results to this list, then clear the list
2986 if (!append)
2987 variables.Clear();
2988
2989 // Remember how many variables are in the list before we search in case
2990 // we are appending the results to a variable list.
2991 const uint32_t original_size = variables.GetSize();
2992
Greg Claytond4a2b372011-09-12 23:21:58 +00002993 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002994
Greg Clayton97fbc342011-10-20 22:30:33 +00002995 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002996 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002997 if (m_apple_names_ap.get())
2998 {
2999 const char *name_cstr = name.GetCString();
3000 const char *base_name_start;
3001 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003002
Greg Clayton97fbc342011-10-20 22:30:33 +00003003 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3004 base_name_start = name_cstr;
3005
3006 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3007 }
Greg Clayton7f995132011-10-04 22:41:51 +00003008 }
3009 else
3010 {
3011 // Index the DWARF if we haven't already
3012 if (!m_indexed)
3013 Index ();
3014
3015 m_global_index.Find (name, die_offsets);
3016 }
3017
Greg Clayton437a1352012-04-09 22:43:43 +00003018 const size_t num_die_matches = die_offsets.size();
3019 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003020 {
Greg Clayton7f995132011-10-04 22:41:51 +00003021 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003022 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003023 assert (sc.module_sp);
3024
Greg Claytond4a2b372011-09-12 23:21:58 +00003025 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003026 DWARFCompileUnit* dwarf_cu = NULL;
3027 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003028 bool done = false;
3029 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003030 {
3031 const dw_offset_t die_offset = die_offsets[i];
3032 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003033
Greg Clayton95d87902011-11-11 03:16:25 +00003034 if (die)
3035 {
Greg Clayton437a1352012-04-09 22:43:43 +00003036 switch (die->Tag())
3037 {
3038 default:
3039 case DW_TAG_subprogram:
3040 case DW_TAG_inlined_subroutine:
3041 case DW_TAG_try_block:
3042 case DW_TAG_catch_block:
3043 break;
3044
3045 case DW_TAG_variable:
3046 {
3047 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00003048
3049 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3050 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003051
Greg Clayton437a1352012-04-09 22:43:43 +00003052 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003053
Greg Clayton437a1352012-04-09 22:43:43 +00003054 if (variables.GetSize() - original_size >= max_matches)
3055 done = true;
3056 }
3057 break;
3058 }
Greg Clayton95d87902011-11-11 03:16:25 +00003059 }
3060 else
3061 {
3062 if (m_using_apple_tables)
3063 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003064 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3065 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003066 }
3067 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003068 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003069 }
3070
3071 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003072 const uint32_t num_matches = variables.GetSize() - original_size;
3073 if (log && num_matches > 0)
3074 {
3075 GetObjectFile()->GetModule()->LogMessage (log.get(),
3076 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3077 name.GetCString(),
3078 namespace_decl,
3079 append,
3080 max_matches,
3081 num_matches);
3082 }
3083 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003084}
3085
3086uint32_t
3087SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3088{
Greg Clayton21f2a492011-10-06 00:09:08 +00003089 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3090
3091 if (log)
3092 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003093 GetObjectFile()->GetModule()->LogMessage (log.get(),
3094 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3095 regex.GetText(),
3096 append,
3097 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003098 }
3099
Greg Claytonc685f8e2010-09-15 04:15:46 +00003100 DWARFDebugInfo* info = DebugInfo();
3101 if (info == NULL)
3102 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003103
3104 // If we aren't appending the results to this list, then clear the list
3105 if (!append)
3106 variables.Clear();
3107
3108 // Remember how many variables are in the list before we search in case
3109 // we are appending the results to a variable list.
3110 const uint32_t original_size = variables.GetSize();
3111
Greg Clayton7f995132011-10-04 22:41:51 +00003112 DIEArray die_offsets;
3113
Greg Clayton97fbc342011-10-20 22:30:33 +00003114 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003115 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003116 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003117 {
3118 DWARFMappedHash::DIEInfoArray hash_data_array;
3119 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3120 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3121 }
Greg Clayton7f995132011-10-04 22:41:51 +00003122 }
3123 else
3124 {
3125 // Index the DWARF if we haven't already
3126 if (!m_indexed)
3127 Index ();
3128
3129 m_global_index.Find (regex, die_offsets);
3130 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003131
Greg Claytonc685f8e2010-09-15 04:15:46 +00003132 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003133 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003134 assert (sc.module_sp);
3135
Greg Claytond4a2b372011-09-12 23:21:58 +00003136 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003137 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003138 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003139 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003140 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003141 DWARFDebugInfo* debug_info = DebugInfo();
3142 for (size_t i=0; i<num_matches; ++i)
3143 {
3144 const dw_offset_t die_offset = die_offsets[i];
3145 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003146
3147 if (die)
3148 {
3149 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003150
Greg Clayton95d87902011-11-11 03:16:25 +00003151 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003152
Greg Clayton95d87902011-11-11 03:16:25 +00003153 if (variables.GetSize() - original_size >= max_matches)
3154 break;
3155 }
3156 else
3157 {
3158 if (m_using_apple_tables)
3159 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003160 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3161 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003162 }
3163 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003164 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003165 }
3166
3167 // Return the number of variable that were appended to the list
3168 return variables.GetSize() - original_size;
3169}
3170
Greg Claytonaa044962011-10-13 00:59:38 +00003171
Jim Ingham4cda6e02011-10-07 22:23:45 +00003172bool
3173SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3174 DWARFCompileUnit *&dwarf_cu,
3175 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003176{
Greg Claytonaa044962011-10-13 00:59:38 +00003177 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3178 return ResolveFunction (dwarf_cu, die, sc_list);
3179}
3180
3181
3182bool
3183SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3184 const DWARFDebugInfoEntry *die,
3185 SymbolContextList& sc_list)
3186{
Greg Clayton9e315582011-09-02 04:03:59 +00003187 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003188
3189 if (die == NULL)
3190 return false;
3191
Jim Ingham4cda6e02011-10-07 22:23:45 +00003192 // If we were passed a die that is not a function, just return false...
3193 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3194 return false;
3195
3196 const DWARFDebugInfoEntry* inlined_die = NULL;
3197 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003198 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003199 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003200
Jim Ingham4cda6e02011-10-07 22:23:45 +00003201 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003202 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003203 if (die->Tag() == DW_TAG_subprogram)
3204 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003205 }
3206 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003207 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003208 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003209 {
3210 Address addr;
3211 // Parse all blocks if needed
3212 if (inlined_die)
3213 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003214 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003215 assert (sc.block != NULL);
3216 if (sc.block->GetStartAddress (addr) == false)
3217 addr.Clear();
3218 }
3219 else
3220 {
3221 sc.block = NULL;
3222 addr = sc.function->GetAddressRange().GetBaseAddress();
3223 }
3224
3225 if (addr.IsValid())
3226 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003227 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003228 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003229 }
3230 }
3231
Greg Claytonaa044962011-10-13 00:59:38 +00003232 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003233}
3234
Greg Clayton7f995132011-10-04 22:41:51 +00003235void
3236SymbolFileDWARF::FindFunctions (const ConstString &name,
3237 const NameToDIE &name_to_die,
3238 SymbolContextList& sc_list)
3239{
Greg Claytond4a2b372011-09-12 23:21:58 +00003240 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003241 if (name_to_die.Find (name, die_offsets))
3242 {
3243 ParseFunctions (die_offsets, sc_list);
3244 }
3245}
3246
3247
3248void
3249SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3250 const NameToDIE &name_to_die,
3251 SymbolContextList& sc_list)
3252{
3253 DIEArray die_offsets;
3254 if (name_to_die.Find (regex, die_offsets))
3255 {
3256 ParseFunctions (die_offsets, sc_list);
3257 }
3258}
3259
3260
3261void
3262SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3263 const DWARFMappedHash::MemoryTable &memory_table,
3264 SymbolContextList& sc_list)
3265{
3266 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003267 DWARFMappedHash::DIEInfoArray hash_data_array;
3268 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003269 {
Greg Claytond1767f02011-12-08 02:13:16 +00003270 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003271 ParseFunctions (die_offsets, sc_list);
3272 }
3273}
3274
3275void
3276SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3277 SymbolContextList& sc_list)
3278{
3279 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003280 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003281 {
Greg Clayton7f995132011-10-04 22:41:51 +00003282 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003283
3284 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003285 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003286 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003287 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003288 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003289 }
3290 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003291}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003292
Jim Ingham4cda6e02011-10-07 22:23:45 +00003293bool
3294SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3295 const DWARFCompileUnit *dwarf_cu,
3296 uint32_t name_type_mask,
3297 const char *partial_name,
3298 const char *base_name_start,
3299 const char *base_name_end)
3300{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003301 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3302 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003303 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003304 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3305 if (!containing_decl_ctx)
3306 return false;
3307
3308 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3309
Greg Claytonfbea0f62012-11-15 18:05:43 +00003310 if (name_type_mask == eFunctionNameTypeMethod)
3311 {
3312 if (is_cxx_method == false)
3313 return false;
3314 }
3315
3316 if (name_type_mask == eFunctionNameTypeBase)
3317 {
3318 if (is_cxx_method == true)
3319 return false;
3320 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003321 }
3322
3323 // Now we need to check whether the name we got back for this type matches the extra specifications
3324 // that were in the name we're looking up:
3325 if (base_name_start != partial_name || *base_name_end != '\0')
3326 {
3327 // First see if the stuff to the left matches the full name. To do that let's see if
3328 // we can pull out the mips linkage name attribute:
3329
3330 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003331 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003332 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003333 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3334 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003335 if (idx == UINT32_MAX)
3336 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003337 if (idx != UINT32_MAX)
3338 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003339 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3340 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003341 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3342 if (mangled_name)
3343 best_name.SetValue (ConstString(mangled_name), true);
3344 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003345 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003346
3347 if (!best_name)
3348 {
3349 idx = attributes.FindAttributeIndex(DW_AT_name);
3350 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3351 {
3352 const char *name = form_value.AsCString(&get_debug_str_data());
3353 best_name.SetValue (ConstString(name), false);
3354 }
3355 }
3356
3357 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003358 {
3359 const char *demangled = best_name.GetDemangledName().GetCString();
3360 if (demangled)
3361 {
3362 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003363 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3364 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003365 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003366 else
3367 {
3368 // Sort out the case where our name is something like "Process::Destroy" and the match is
3369 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3370 // namespace boundaries...
3371
3372 if (partial_name[0] == ':' && partial_name[1] == ':')
3373 {
3374 // The partial name was already on a namespace boundary so all matches are good.
3375 return true;
3376 }
3377 else if (partial_in_demangled == demangled)
3378 {
3379 // They both start the same, so this is an good match.
3380 return true;
3381 }
3382 else
3383 {
3384 if (partial_in_demangled - demangled == 1)
3385 {
3386 // Only one character difference, can't be a namespace boundary...
3387 return false;
3388 }
3389 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3390 {
3391 // We are on a namespace boundary, so this is also good.
3392 return true;
3393 }
3394 else
3395 return false;
3396 }
3397 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003398 }
3399 }
3400 }
3401
3402 return true;
3403}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003404
Greg Clayton0c5cd902010-06-28 21:30:43 +00003405uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003406SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003407 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003408 uint32_t name_type_mask,
3409 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003410 bool append,
3411 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003412{
3413 Timer scoped_timer (__PRETTY_FUNCTION__,
3414 "SymbolFileDWARF::FindFunctions (name = '%s')",
3415 name.AsCString());
3416
Greg Clayton21f2a492011-10-06 00:09:08 +00003417 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3418
3419 if (log)
3420 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003421 GetObjectFile()->GetModule()->LogMessage (log.get(),
3422 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3423 name.GetCString(),
3424 name_type_mask,
3425 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003426 }
3427
Greg Clayton0c5cd902010-06-28 21:30:43 +00003428 // If we aren't appending the results to this list, then clear the list
3429 if (!append)
3430 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003431
3432 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3433 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003434
3435 // If name is empty then we won't find anything.
3436 if (name.IsEmpty())
3437 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003438
3439 // Remember how many sc_list are in the list before we search in case
3440 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003441
Greg Clayton9e315582011-09-02 04:03:59 +00003442 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003443
Jim Ingham4cda6e02011-10-07 22:23:45 +00003444 const char *name_cstr = name.GetCString();
3445 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3446 const char *base_name_start = name_cstr;
3447 const char *base_name_end = name_cstr + strlen(name_cstr);
3448
3449 if (name_type_mask & eFunctionNameTypeAuto)
3450 {
3451 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3452 effective_name_type_mask = eFunctionNameTypeFull;
3453 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3454 effective_name_type_mask = eFunctionNameTypeFull;
3455 else
3456 {
3457 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3458 effective_name_type_mask |= eFunctionNameTypeSelector;
3459
3460 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3461 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3462 }
3463 }
3464 else
3465 {
3466 effective_name_type_mask = name_type_mask;
3467 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3468 {
3469 // If they've asked for a CPP method or function name and it can't be that, we don't
3470 // even need to search for CPP methods or names.
3471 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3472 {
3473 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3474 if (effective_name_type_mask == eFunctionNameTypeNone)
3475 return 0;
3476 }
3477 }
3478
3479 if (effective_name_type_mask & eFunctionNameTypeSelector)
3480 {
3481 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3482 {
3483 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3484 if (effective_name_type_mask == eFunctionNameTypeNone)
3485 return 0;
3486 }
3487 }
3488 }
3489
3490 DWARFDebugInfo* info = DebugInfo();
3491 if (info == NULL)
3492 return 0;
3493
Greg Claytonaa044962011-10-13 00:59:38 +00003494 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003495 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003496 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003497 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003498 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003499
3500 DIEArray die_offsets;
3501
3502 uint32_t num_matches = 0;
3503
3504 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003505 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003506 // If they asked for the full name, match what they typed. At some point we may
3507 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3508 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003509 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003510 for (uint32_t i = 0; i < num_matches; i++)
3511 {
Greg Clayton95d87902011-11-11 03:16:25 +00003512 const dw_offset_t die_offset = die_offsets[i];
3513 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003514 if (die)
3515 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003516 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3517 continue;
3518
Sean Callanan9df05fb2012-02-10 22:52:19 +00003519 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3520 continue;
3521
Greg Claytonaa044962011-10-13 00:59:38 +00003522 ResolveFunction (dwarf_cu, die, sc_list);
3523 }
Greg Clayton95d87902011-11-11 03:16:25 +00003524 else
3525 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003526 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3527 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003528 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003529 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003530 }
3531 else
3532 {
3533 if (effective_name_type_mask & eFunctionNameTypeSelector)
3534 {
3535 if (namespace_decl && *namespace_decl)
3536 return 0; // no selectors in namespaces
3537
3538 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3539 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3540 // and if it is an ObjC method name, we're good.
3541
3542 for (uint32_t i = 0; i < num_matches; i++)
3543 {
Greg Clayton95d87902011-11-11 03:16:25 +00003544 const dw_offset_t die_offset = die_offsets[i];
3545 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003546 if (die)
3547 {
3548 const char *die_name = die->GetName(this, dwarf_cu);
3549 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003550 {
3551 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3552 continue;
3553
Greg Clayton97fbc342011-10-20 22:30:33 +00003554 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003555 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003556 }
Greg Clayton95d87902011-11-11 03:16:25 +00003557 else
3558 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003559 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3560 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003561 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003562 }
3563 die_offsets.clear();
3564 }
3565
3566 if (effective_name_type_mask & eFunctionNameTypeMethod
3567 || effective_name_type_mask & eFunctionNameTypeBase)
3568 {
3569 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3570 (namespace_decl && *namespace_decl))
3571 return 0; // no methods in namespaces
3572
3573 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3574 // extract the base name, look that up, and if there is any other information in the name we were
3575 // passed in we have to post-filter based on that.
3576
3577 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3578 std::string base_name(base_name_start, base_name_end - base_name_start);
3579 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3580
3581 for (uint32_t i = 0; i < num_matches; i++)
3582 {
Greg Clayton95d87902011-11-11 03:16:25 +00003583 const dw_offset_t die_offset = die_offsets[i];
3584 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003585 if (die)
3586 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003587 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3588 continue;
3589
Greg Clayton97fbc342011-10-20 22:30:33 +00003590 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3591 continue;
3592
Greg Claytonfbea0f62012-11-15 18:05:43 +00003593 if (!FunctionDieMatchesPartialName(die,
Greg Clayton97fbc342011-10-20 22:30:33 +00003594 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003595 effective_name_type_mask,
Greg Clayton97fbc342011-10-20 22:30:33 +00003596 name_cstr,
3597 base_name_start,
3598 base_name_end))
3599 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003600
Greg Clayton97fbc342011-10-20 22:30:33 +00003601 // If we get to here, the die is good, and we should add it:
3602 ResolveFunction (dwarf_cu, die, sc_list);
3603 }
Greg Clayton95d87902011-11-11 03:16:25 +00003604 else
3605 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003606 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3607 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003608 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003609 }
3610 die_offsets.clear();
3611 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003612 }
3613 }
Greg Clayton7f995132011-10-04 22:41:51 +00003614 }
3615 else
3616 {
3617
3618 // Index the DWARF if we haven't already
3619 if (!m_indexed)
3620 Index ();
3621
Greg Clayton7f995132011-10-04 22:41:51 +00003622 if (name_type_mask & eFunctionNameTypeFull)
3623 FindFunctions (name, m_function_fullname_index, sc_list);
3624
Jim Ingham4cda6e02011-10-07 22:23:45 +00003625 std::string base_name(base_name_start, base_name_end - base_name_start);
3626 ConstString base_name_const(base_name.c_str());
3627 DIEArray die_offsets;
3628 DWARFCompileUnit *dwarf_cu = NULL;
3629
3630 if (effective_name_type_mask & eFunctionNameTypeBase)
3631 {
3632 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003633 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003634 {
Greg Claytonaa044962011-10-13 00:59:38 +00003635 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3636 if (die)
3637 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003638 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3639 continue;
3640
Sean Callanan213fdb82011-10-13 01:49:10 +00003641 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3642 continue;
3643
Greg Claytonaa044962011-10-13 00:59:38 +00003644 if (!FunctionDieMatchesPartialName(die,
3645 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003646 eFunctionNameTypeBase,
Greg Claytonaa044962011-10-13 00:59:38 +00003647 name_cstr,
3648 base_name_start,
3649 base_name_end))
3650 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003651
Greg Claytonaa044962011-10-13 00:59:38 +00003652 // If we get to here, the die is good, and we should add it:
3653 ResolveFunction (dwarf_cu, die, sc_list);
3654 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003655 }
3656 die_offsets.clear();
3657 }
3658
Jim Inghamea8005a2011-10-11 01:18:11 +00003659 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003660 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003661 if (namespace_decl && *namespace_decl)
3662 return 0; // no methods in namespaces
3663
Jim Ingham4cda6e02011-10-07 22:23:45 +00003664 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3665 {
Greg Claytonaa044962011-10-13 00:59:38 +00003666 for (uint32_t i = 0; i < num_base; i++)
3667 {
3668 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3669 if (die)
3670 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003671 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3672 continue;
3673
3674 if (!FunctionDieMatchesPartialName(die,
Greg Claytonaa044962011-10-13 00:59:38 +00003675 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003676 eFunctionNameTypeMethod,
Greg Claytonaa044962011-10-13 00:59:38 +00003677 name_cstr,
3678 base_name_start,
3679 base_name_end))
3680 continue;
3681
3682 // If we get to here, the die is good, and we should add it:
3683 ResolveFunction (dwarf_cu, die, sc_list);
3684 }
3685 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003686 }
3687 die_offsets.clear();
3688 }
Greg Clayton7f995132011-10-04 22:41:51 +00003689
Sean Callanan213fdb82011-10-13 01:49:10 +00003690 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003691 {
Greg Clayton7f995132011-10-04 22:41:51 +00003692 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003693 }
3694
Greg Clayton4d01ace2011-09-29 16:58:15 +00003695 }
3696
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003697 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003698 const uint32_t num_matches = sc_list.GetSize() - original_size;
3699
3700 if (log && num_matches > 0)
3701 {
3702 GetObjectFile()->GetModule()->LogMessage (log.get(),
3703 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3704 name.GetCString(),
3705 name_type_mask,
3706 append,
3707 num_matches);
3708 }
3709 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003710}
3711
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003712uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003713SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003714{
3715 Timer scoped_timer (__PRETTY_FUNCTION__,
3716 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3717 regex.GetText());
3718
Greg Clayton21f2a492011-10-06 00:09:08 +00003719 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3720
3721 if (log)
3722 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003723 GetObjectFile()->GetModule()->LogMessage (log.get(),
3724 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3725 regex.GetText(),
3726 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003727 }
3728
3729
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003730 // If we aren't appending the results to this list, then clear the list
3731 if (!append)
3732 sc_list.Clear();
3733
3734 // Remember how many sc_list are in the list before we search in case
3735 // we are appending the results to a variable list.
3736 uint32_t original_size = sc_list.GetSize();
3737
Greg Clayton97fbc342011-10-20 22:30:33 +00003738 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003739 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003740 if (m_apple_names_ap.get())
3741 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003742 }
3743 else
3744 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003745 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003746 if (!m_indexed)
3747 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003748
Greg Clayton7f995132011-10-04 22:41:51 +00003749 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003750
Greg Clayton7f995132011-10-04 22:41:51 +00003751 FindFunctions (regex, m_function_fullname_index, sc_list);
3752 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003753
3754 // Return the number of variable that were appended to the list
3755 return sc_list.GetSize() - original_size;
3756}
Jim Ingham318c9f22011-08-26 19:44:13 +00003757
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003758uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003759SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3760 const ConstString &name,
3761 const lldb_private::ClangNamespaceDecl *namespace_decl,
3762 bool append,
3763 uint32_t max_matches,
3764 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003765{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003766 DWARFDebugInfo* info = DebugInfo();
3767 if (info == NULL)
3768 return 0;
3769
Greg Clayton21f2a492011-10-06 00:09:08 +00003770 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3771
3772 if (log)
3773 {
Greg Clayton437a1352012-04-09 22:43:43 +00003774 if (namespace_decl)
3775 {
3776 GetObjectFile()->GetModule()->LogMessage (log.get(),
3777 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3778 name.GetCString(),
3779 namespace_decl->GetNamespaceDecl(),
3780 namespace_decl->GetQualifiedName().c_str(),
3781 append,
3782 max_matches);
3783 }
3784 else
3785 {
3786 GetObjectFile()->GetModule()->LogMessage (log.get(),
3787 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3788 name.GetCString(),
3789 append,
3790 max_matches);
3791 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003792 }
3793
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003794 // If we aren't appending the results to this list, then clear the list
3795 if (!append)
3796 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003797
3798 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3799 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003800
Greg Claytond4a2b372011-09-12 23:21:58 +00003801 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003802
Greg Clayton97fbc342011-10-20 22:30:33 +00003803 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003804 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003805 if (m_apple_types_ap.get())
3806 {
3807 const char *name_cstr = name.GetCString();
3808 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3809 }
Greg Clayton7f995132011-10-04 22:41:51 +00003810 }
3811 else
3812 {
3813 if (!m_indexed)
3814 Index ();
3815
3816 m_type_index.Find (name, die_offsets);
3817 }
3818
Greg Clayton437a1352012-04-09 22:43:43 +00003819 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003820
Greg Clayton437a1352012-04-09 22:43:43 +00003821 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003822 {
Greg Clayton7f995132011-10-04 22:41:51 +00003823 const uint32_t initial_types_size = types.GetSize();
3824 DWARFCompileUnit* dwarf_cu = NULL;
3825 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003826 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003827 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003828 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003829 const dw_offset_t die_offset = die_offsets[i];
3830 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3831
Greg Clayton95d87902011-11-11 03:16:25 +00003832 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003833 {
Greg Clayton95d87902011-11-11 03:16:25 +00003834 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3835 continue;
3836
3837 Type *matching_type = ResolveType (dwarf_cu, die);
3838 if (matching_type)
3839 {
3840 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003841 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003842 if (types.GetSize() >= max_matches)
3843 break;
3844 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003845 }
Greg Clayton95d87902011-11-11 03:16:25 +00003846 else
3847 {
3848 if (m_using_apple_tables)
3849 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003850 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3851 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003852 }
3853 }
3854
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003855 }
Greg Clayton437a1352012-04-09 22:43:43 +00003856 const uint32_t num_matches = types.GetSize() - initial_types_size;
3857 if (log && num_matches)
3858 {
3859 if (namespace_decl)
3860 {
3861 GetObjectFile()->GetModule()->LogMessage (log.get(),
3862 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3863 name.GetCString(),
3864 namespace_decl->GetNamespaceDecl(),
3865 namespace_decl->GetQualifiedName().c_str(),
3866 append,
3867 max_matches,
3868 num_matches);
3869 }
3870 else
3871 {
3872 GetObjectFile()->GetModule()->LogMessage (log.get(),
3873 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3874 name.GetCString(),
3875 append,
3876 max_matches,
3877 num_matches);
3878 }
3879 }
3880 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003881 }
Greg Clayton7f995132011-10-04 22:41:51 +00003882 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883}
3884
3885
Greg Clayton526e5af2010-11-13 03:52:47 +00003886ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003887SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003888 const ConstString &name,
3889 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003890{
Greg Clayton21f2a492011-10-06 00:09:08 +00003891 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3892
3893 if (log)
3894 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003895 GetObjectFile()->GetModule()->LogMessage (log.get(),
3896 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3897 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003898 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003899
3900 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3901 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003902
Greg Clayton526e5af2010-11-13 03:52:47 +00003903 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003904 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003905 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003906 {
Greg Clayton7f995132011-10-04 22:41:51 +00003907 DIEArray die_offsets;
3908
Greg Clayton526e5af2010-11-13 03:52:47 +00003909 // Index if we already haven't to make sure the compile units
3910 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003911 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003912 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003913 if (m_apple_namespaces_ap.get())
3914 {
3915 const char *name_cstr = name.GetCString();
3916 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3917 }
Greg Clayton7f995132011-10-04 22:41:51 +00003918 }
3919 else
3920 {
3921 if (!m_indexed)
3922 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003923
Greg Clayton7f995132011-10-04 22:41:51 +00003924 m_namespace_index.Find (name, die_offsets);
3925 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003926
3927 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003928 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003929 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003930 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003931 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003932 DWARFDebugInfo* debug_info = DebugInfo();
3933 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003934 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003935 const dw_offset_t die_offset = die_offsets[i];
3936 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003937
Greg Clayton95d87902011-11-11 03:16:25 +00003938 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003939 {
Greg Clayton95d87902011-11-11 03:16:25 +00003940 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3941 continue;
3942
3943 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3944 if (clang_namespace_decl)
3945 {
3946 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3947 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003948 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003949 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003950 }
Greg Clayton95d87902011-11-11 03:16:25 +00003951 else
3952 {
3953 if (m_using_apple_tables)
3954 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003955 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3956 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003957 }
3958 }
3959
Greg Clayton526e5af2010-11-13 03:52:47 +00003960 }
3961 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003962 }
Greg Clayton437a1352012-04-09 22:43:43 +00003963 if (log && namespace_decl.GetNamespaceDecl())
3964 {
3965 GetObjectFile()->GetModule()->LogMessage (log.get(),
3966 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3967 name.GetCString(),
3968 namespace_decl.GetNamespaceDecl(),
3969 namespace_decl.GetQualifiedName().c_str());
3970 }
3971
Greg Clayton526e5af2010-11-13 03:52:47 +00003972 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003973}
3974
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003975uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003976SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003977{
3978 // Remember how many sc_list are in the list before we search in case
3979 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003980 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003981
3982 const uint32_t num_die_offsets = die_offsets.size();
3983 // Parse all of the types we found from the pubtypes matches
3984 uint32_t i;
3985 uint32_t num_matches = 0;
3986 for (i = 0; i < num_die_offsets; ++i)
3987 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003988 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3989 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003990 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003991 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003992 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003993 ++num_matches;
3994 if (num_matches >= max_matches)
3995 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003996 }
3997 }
3998
3999 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004000 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004001}
4002
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004003
4004size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004005SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4006 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004007 DWARFCompileUnit* dwarf_cu,
4008 const DWARFDebugInfoEntry *parent_die,
4009 bool skip_artificial,
4010 bool &is_static,
4011 TypeList* type_list,
4012 std::vector<clang_type_t>& function_param_types,
4013 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004014 unsigned &type_quals,
4015 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016{
4017 if (parent_die == NULL)
4018 return 0;
4019
Greg Claytond88d7592010-09-15 08:33:30 +00004020 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4021
Greg Clayton7fedea22010-11-16 02:10:54 +00004022 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004023 const DWARFDebugInfoEntry *die;
4024 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4025 {
4026 dw_tag_t tag = die->Tag();
4027 switch (tag)
4028 {
4029 case DW_TAG_formal_parameter:
4030 {
4031 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004032 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004033 if (num_attributes > 0)
4034 {
4035 const char *name = NULL;
4036 Declaration decl;
4037 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004038 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004039 // one of None, Auto, Register, Extern, Static, PrivateExtern
4040
Sean Callanane2ef6e32010-09-23 03:01:22 +00004041 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004042 uint32_t i;
4043 for (i=0; i<num_attributes; ++i)
4044 {
4045 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4046 DWARFFormValue form_value;
4047 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4048 {
4049 switch (attr)
4050 {
4051 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4052 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4053 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4054 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4055 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004056 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004057 case DW_AT_location:
4058 // if (form_value.BlockData())
4059 // {
4060 // const DataExtractor& debug_info_data = debug_info();
4061 // uint32_t block_length = form_value.Unsigned();
4062 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
4063 // }
4064 // else
4065 // {
4066 // }
4067 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004068 case DW_AT_const_value:
4069 case DW_AT_default_value:
4070 case DW_AT_description:
4071 case DW_AT_endianity:
4072 case DW_AT_is_optional:
4073 case DW_AT_segment:
4074 case DW_AT_variable_parameter:
4075 default:
4076 case DW_AT_abstract_origin:
4077 case DW_AT_sibling:
4078 break;
4079 }
4080 }
4081 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004082
Greg Clayton0fffff52010-09-24 05:15:53 +00004083 bool skip = false;
4084 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004085 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004086 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004087 {
4088 // In order to determine if a C++ member function is
4089 // "const" we have to look at the const-ness of "this"...
4090 // Ugly, but that
4091 if (arg_idx == 0)
4092 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004093 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004094 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004095 // Often times compilers omit the "this" name for the
4096 // specification DIEs, so we can't rely upon the name
4097 // being in the formal parameter DIE...
4098 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004099 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004100 Type *this_type = ResolveTypeUID (param_type_die_offset);
4101 if (this_type)
4102 {
4103 uint32_t encoding_mask = this_type->GetEncodingMask();
4104 if (encoding_mask & Type::eEncodingIsPointerUID)
4105 {
4106 is_static = false;
4107
4108 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4109 type_quals |= clang::Qualifiers::Const;
4110 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4111 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004112 }
4113 }
4114 }
4115 }
4116 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004117 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004118 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004119 else
4120 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004121
Greg Clayton0fffff52010-09-24 05:15:53 +00004122 // HACK: Objective C formal parameters "self" and "_cmd"
4123 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004124 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4125 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004126 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004127 switch (comp_unit->GetLanguage())
4128 {
4129 case eLanguageTypeObjC:
4130 case eLanguageTypeObjC_plus_plus:
4131 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4132 skip = true;
4133 break;
4134 default:
4135 break;
4136 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004137 }
4138 }
4139 }
4140
4141 if (!skip)
4142 {
4143 Type *type = ResolveTypeUID(param_type_die_offset);
4144 if (type)
4145 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004146 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004147
Greg Clayton42ce2f32011-12-12 21:50:19 +00004148 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4149 type->GetClangForwardType(),
4150 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004151 assert(param_var_decl);
4152 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004153
Jim Ingham379397632012-10-27 02:54:13 +00004154 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004155 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 }
4157 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004158 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004159 }
4160 break;
4161
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004162 case DW_TAG_template_type_parameter:
4163 case DW_TAG_template_value_parameter:
4164 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4165 break;
4166
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004167 default:
4168 break;
4169 }
4170 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004171 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004172}
4173
4174size_t
4175SymbolFileDWARF::ParseChildEnumerators
4176(
4177 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00004178 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004179 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004180 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004181 const DWARFDebugInfoEntry *parent_die
4182)
4183{
4184 if (parent_die == NULL)
4185 return 0;
4186
4187 size_t enumerators_added = 0;
4188 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004189 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4190
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004191 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4192 {
4193 const dw_tag_t tag = die->Tag();
4194 if (tag == DW_TAG_enumerator)
4195 {
4196 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004197 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004198 if (num_child_attributes > 0)
4199 {
4200 const char *name = NULL;
4201 bool got_value = false;
4202 int64_t enum_value = 0;
4203 Declaration decl;
4204
4205 uint32_t i;
4206 for (i=0; i<num_child_attributes; ++i)
4207 {
4208 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4209 DWARFFormValue form_value;
4210 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4211 {
4212 switch (attr)
4213 {
4214 case DW_AT_const_value:
4215 got_value = true;
4216 enum_value = form_value.Unsigned();
4217 break;
4218
4219 case DW_AT_name:
4220 name = form_value.AsCString(&get_debug_str_data());
4221 break;
4222
4223 case DW_AT_description:
4224 default:
4225 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4226 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4227 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4228 case DW_AT_sibling:
4229 break;
4230 }
4231 }
4232 }
4233
4234 if (name && name[0] && got_value)
4235 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004236 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4237 enumerator_clang_type,
4238 decl,
4239 name,
4240 enum_value,
4241 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242 ++enumerators_added;
4243 }
4244 }
4245 }
4246 }
4247 return enumerators_added;
4248}
4249
4250void
4251SymbolFileDWARF::ParseChildArrayInfo
4252(
4253 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004254 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004255 const DWARFDebugInfoEntry *parent_die,
4256 int64_t& first_index,
4257 std::vector<uint64_t>& element_orders,
4258 uint32_t& byte_stride,
4259 uint32_t& bit_stride
4260)
4261{
4262 if (parent_die == NULL)
4263 return;
4264
4265 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004266 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004267 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4268 {
4269 const dw_tag_t tag = die->Tag();
4270 switch (tag)
4271 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004272 case DW_TAG_subrange_type:
4273 {
4274 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004275 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004276 if (num_child_attributes > 0)
4277 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004278 uint64_t num_elements = 0;
4279 uint64_t lower_bound = 0;
4280 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004281 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004282 uint32_t i;
4283 for (i=0; i<num_child_attributes; ++i)
4284 {
4285 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4286 DWARFFormValue form_value;
4287 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4288 {
4289 switch (attr)
4290 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004291 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004292 break;
4293
4294 case DW_AT_count:
4295 num_elements = form_value.Unsigned();
4296 break;
4297
4298 case DW_AT_bit_stride:
4299 bit_stride = form_value.Unsigned();
4300 break;
4301
4302 case DW_AT_byte_stride:
4303 byte_stride = form_value.Unsigned();
4304 break;
4305
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004306 case DW_AT_lower_bound:
4307 lower_bound = form_value.Unsigned();
4308 break;
4309
4310 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004311 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004312 upper_bound = form_value.Unsigned();
4313 break;
4314
4315 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004316 case DW_AT_abstract_origin:
4317 case DW_AT_accessibility:
4318 case DW_AT_allocated:
4319 case DW_AT_associated:
4320 case DW_AT_data_location:
4321 case DW_AT_declaration:
4322 case DW_AT_description:
4323 case DW_AT_sibling:
4324 case DW_AT_threads_scaled:
4325 case DW_AT_type:
4326 case DW_AT_visibility:
4327 break;
4328 }
4329 }
4330 }
4331
Greg Claytone6a07792012-12-05 21:59:39 +00004332 if (num_elements == 0)
4333 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004334 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004335 num_elements = upper_bound - lower_bound + 1;
4336 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004337
Sean Callananec979ba2012-10-22 23:56:48 +00004338 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004339 }
4340 }
4341 break;
4342 }
4343 }
4344}
4345
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004346TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004347SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004348{
4349 TypeSP type_sp;
4350 if (die != NULL)
4351 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004352 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004353 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004354 if (type_ptr == NULL)
4355 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004356 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004357 assert (lldb_cu);
4358 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004359 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004360 }
4361 else if (type_ptr != DIE_IS_BEING_PARSED)
4362 {
4363 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004364 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004365 }
4366
4367 }
4368 return type_sp;
4369}
4370
4371clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004372SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004373{
4374 if (die_offset != DW_INVALID_OFFSET)
4375 {
4376 DWARFCompileUnitSP cu_sp;
4377 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004378 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004379 }
4380 return NULL;
4381}
4382
Sean Callanan72e49402011-08-05 23:43:37 +00004383clang::DeclContext *
4384SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4385{
4386 if (die_offset != DW_INVALID_OFFSET)
4387 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004388 DWARFDebugInfo* debug_info = DebugInfo();
4389 if (debug_info)
4390 {
4391 DWARFCompileUnitSP cu_sp;
4392 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4393 if (die)
4394 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4395 }
Sean Callanan72e49402011-08-05 23:43:37 +00004396 }
4397 return NULL;
4398}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004399
Greg Clayton96d7d742010-11-10 23:42:09 +00004400clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004401SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004402{
Greg Clayton030a2042011-10-14 21:34:45 +00004403 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004404 {
Greg Clayton030a2042011-10-14 21:34:45 +00004405 // See if we already parsed this namespace DIE and associated it with a
4406 // uniqued namespace declaration
4407 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4408 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004409 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004410 else
4411 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004412 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4413 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004414 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4415 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4416 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004417 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004418 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004419 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004420 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004421 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004422 GetClangASTContext().getASTContext(),
4423 MakeUserID(die->GetOffset()),
4424 namespace_name,
4425 namespace_decl,
4426 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004427 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004428 else
4429 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004430 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004431 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004432 GetClangASTContext().getASTContext(),
4433 MakeUserID(die->GetOffset()),
4434 namespace_decl,
4435 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004436 }
Greg Clayton030a2042011-10-14 21:34:45 +00004437 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004438
4439 if (namespace_decl)
4440 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4441 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004442 }
4443 }
4444 return NULL;
4445}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004446
4447clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004448SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004449{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004450 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4451 if (clang_decl_ctx)
4452 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004453 // If this DIE has a specification, or an abstract origin, then trace to those.
4454
Greg Claytoncab36a32011-12-08 05:16:30 +00004455 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004456 if (die_offset != DW_INVALID_OFFSET)
4457 return GetClangDeclContextForDIEOffset (sc, die_offset);
4458
Greg Claytoncab36a32011-12-08 05:16:30 +00004459 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004460 if (die_offset != DW_INVALID_OFFSET)
4461 return GetClangDeclContextForDIEOffset (sc, die_offset);
4462
Greg Clayton3bffb082011-12-10 02:15:28 +00004463 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4464 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004465 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 +00004466 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004467 bool assert_not_being_parsed = true;
4468 ResolveTypeUID (cu, die, assert_not_being_parsed);
4469
Greg Clayton5cf58b92011-10-05 22:22:08 +00004470 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4471
4472 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004473}
4474
4475clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004476SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004477{
Greg Claytonca512b32011-01-14 04:54:56 +00004478 if (m_clang_tu_decl == NULL)
4479 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004480
Greg Clayton2bc22f82011-09-30 03:20:47 +00004481 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004482
4483 if (decl_ctx_die_copy)
4484 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004485
4486 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004487 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004488
Greg Clayton2bc22f82011-09-30 03:20:47 +00004489 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4490 if (pos != m_die_to_decl_ctx.end())
4491 return pos->second;
4492
4493 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004494 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004495 case DW_TAG_compile_unit:
4496 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497
Greg Clayton2bc22f82011-09-30 03:20:47 +00004498 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004499 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004500 break;
4501
4502 case DW_TAG_structure_type:
4503 case DW_TAG_union_type:
4504 case DW_TAG_class_type:
4505 {
4506 Type* type = ResolveType (cu, decl_ctx_die);
4507 if (type)
4508 {
4509 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4510 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004511 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004512 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4513 if (decl_ctx)
4514 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004515 }
4516 }
Greg Claytonca512b32011-01-14 04:54:56 +00004517 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004518 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004519
Greg Clayton2bc22f82011-09-30 03:20:47 +00004520 default:
4521 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004523 }
Greg Clayton7a345282010-11-09 23:46:37 +00004524 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004525}
4526
Greg Clayton2bc22f82011-09-30 03:20:47 +00004527
4528const DWARFDebugInfoEntry *
4529SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4530{
4531 if (cu && die)
4532 {
4533 const DWARFDebugInfoEntry * const decl_die = die;
4534
4535 while (die != NULL)
4536 {
4537 // If this is the original DIE that we are searching for a declaration
4538 // for, then don't look in the cache as we don't want our own decl
4539 // context to be our decl context...
4540 if (decl_die != die)
4541 {
4542 switch (die->Tag())
4543 {
4544 case DW_TAG_compile_unit:
4545 case DW_TAG_namespace:
4546 case DW_TAG_structure_type:
4547 case DW_TAG_union_type:
4548 case DW_TAG_class_type:
4549 return die;
4550
4551 default:
4552 break;
4553 }
4554 }
4555
4556 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4557 if (die_offset != DW_INVALID_OFFSET)
4558 {
4559 DWARFCompileUnit *spec_cu = cu;
4560 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4561 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4562 if (spec_die_decl_ctx_die)
4563 return spec_die_decl_ctx_die;
4564 }
4565
4566 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4567 if (die_offset != DW_INVALID_OFFSET)
4568 {
4569 DWARFCompileUnit *abs_cu = cu;
4570 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4571 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4572 if (abs_die_decl_ctx_die)
4573 return abs_die_decl_ctx_die;
4574 }
4575
4576 die = die->GetParent();
4577 }
4578 }
4579 return NULL;
4580}
4581
4582
Greg Clayton901c5ca2011-12-03 04:40:03 +00004583Symbol *
4584SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4585{
4586 Symbol *objc_class_symbol = NULL;
4587 if (m_obj_file)
4588 {
4589 Symtab *symtab = m_obj_file->GetSymtab();
4590 if (symtab)
4591 {
4592 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4593 eSymbolTypeObjCClass,
4594 Symtab::eDebugNo,
4595 Symtab::eVisibilityAny);
4596 }
4597 }
4598 return objc_class_symbol;
4599}
4600
Greg Claytonc7f03b62012-01-12 04:33:28 +00004601// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4602// then we can end up looking through all class types for a complete type and never find
4603// the full definition. We need to know if this attribute is supported, so we determine
4604// this here and cache th result. We also need to worry about the debug map DWARF file
4605// if we are doing darwin DWARF in .o file debugging.
4606bool
4607SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4608{
4609 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4610 {
4611 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4612 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4613 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4614 else
4615 {
4616 DWARFDebugInfo* debug_info = DebugInfo();
4617 const uint32_t num_compile_units = GetNumCompileUnits();
4618 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4619 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004620 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4621 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004622 {
4623 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4624 break;
4625 }
4626 }
4627 }
Greg Clayton1f746072012-08-29 21:13:06 +00004628 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004629 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4630 }
4631 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4632}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004633
4634// This function can be used when a DIE is found that is a forward declaration
4635// DIE and we want to try and find a type that has the complete definition.
4636TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004637SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4638 const ConstString &type_name,
4639 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004640{
4641
4642 TypeSP type_sp;
4643
Greg Claytonc7f03b62012-01-12 04:33:28 +00004644 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004645 return type_sp;
4646
4647 DIEArray die_offsets;
4648
4649 if (m_using_apple_tables)
4650 {
4651 if (m_apple_types_ap.get())
4652 {
4653 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004654 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004655 }
4656 }
4657 else
4658 {
4659 if (!m_indexed)
4660 Index ();
4661
4662 m_type_index.Find (type_name, die_offsets);
4663 }
4664
Greg Clayton901c5ca2011-12-03 04:40:03 +00004665 const size_t num_matches = die_offsets.size();
4666
Greg Clayton901c5ca2011-12-03 04:40:03 +00004667 DWARFCompileUnit* type_cu = NULL;
4668 const DWARFDebugInfoEntry* type_die = NULL;
4669 if (num_matches)
4670 {
4671 DWARFDebugInfo* debug_info = DebugInfo();
4672 for (size_t i=0; i<num_matches; ++i)
4673 {
4674 const dw_offset_t die_offset = die_offsets[i];
4675 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4676
4677 if (type_die)
4678 {
4679 bool try_resolving_type = false;
4680
4681 // Don't try and resolve the DIE we are looking for with the DIE itself!
4682 if (type_die != die)
4683 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004684 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004685 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004686 case DW_TAG_class_type:
4687 case DW_TAG_structure_type:
4688 try_resolving_type = true;
4689 break;
4690 default:
4691 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004692 }
4693 }
4694
4695 if (try_resolving_type)
4696 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004697 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004698 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004699
4700 if (try_resolving_type)
4701 {
4702 Type *resolved_type = ResolveType (type_cu, type_die, false);
4703 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4704 {
Daniel Malead01b2952012-11-29 21:49:15 +00004705 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton901c5ca2011-12-03 04:40:03 +00004706 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004707 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004708 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4709 MakeUserID(type_die->GetOffset()),
4710 MakeUserID(type_cu->GetOffset()));
4711
Greg Claytonc7f03b62012-01-12 04:33:28 +00004712 if (die)
4713 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004714 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004715 break;
4716 }
4717 }
4718 }
4719 }
4720 else
4721 {
4722 if (m_using_apple_tables)
4723 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004724 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4725 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004726 }
4727 }
4728
4729 }
4730 }
4731 return type_sp;
4732}
4733
Greg Claytona8022fa2012-04-24 21:22:41 +00004734
Greg Clayton80c26302012-02-05 06:12:47 +00004735//----------------------------------------------------------------------
4736// This function helps to ensure that the declaration contexts match for
4737// two different DIEs. Often times debug information will refer to a
4738// forward declaration of a type (the equivalent of "struct my_struct;".
4739// There will often be a declaration of that type elsewhere that has the
4740// full definition. When we go looking for the full type "my_struct", we
4741// will find one or more matches in the accelerator tables and we will
4742// then need to make sure the type was in the same declaration context
4743// as the original DIE. This function can efficiently compare two DIEs
4744// and will return true when the declaration context matches, and false
4745// when they don't.
4746//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004747bool
4748SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4749 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4750{
Greg Claytona8022fa2012-04-24 21:22:41 +00004751 if (die1 == die2)
4752 return true;
4753
4754#if defined (LLDB_CONFIGURATION_DEBUG)
4755 // You can't and shouldn't call this function with a compile unit from
4756 // two different SymbolFileDWARF instances.
4757 assert (DebugInfo()->ContainsCompileUnit (cu1));
4758 assert (DebugInfo()->ContainsCompileUnit (cu2));
4759#endif
4760
Greg Clayton890ff562012-02-02 05:48:16 +00004761 DWARFDIECollection decl_ctx_1;
4762 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004763 //The declaration DIE stack is a stack of the declaration context
4764 // DIEs all the way back to the compile unit. If a type "T" is
4765 // declared inside a class "B", and class "B" is declared inside
4766 // a class "A" and class "A" is in a namespace "lldb", and the
4767 // namespace is in a compile unit, there will be a stack of DIEs:
4768 //
4769 // [0] DW_TAG_class_type for "B"
4770 // [1] DW_TAG_class_type for "A"
4771 // [2] DW_TAG_namespace for "lldb"
4772 // [3] DW_TAG_compile_unit for the source file.
4773 //
4774 // We grab both contexts and make sure that everything matches
4775 // all the way back to the compiler unit.
4776
4777 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004778 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004779 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004780 // Make sure the context arrays have the same size, otherwise
4781 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004782 const size_t count1 = decl_ctx_1.Size();
4783 const size_t count2 = decl_ctx_2.Size();
4784 if (count1 != count2)
4785 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004786
4787 // Make sure the DW_TAG values match all the way back up the the
4788 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004789 const DWARFDebugInfoEntry *decl_ctx_die1;
4790 const DWARFDebugInfoEntry *decl_ctx_die2;
4791 size_t i;
4792 for (i=0; i<count1; i++)
4793 {
4794 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4795 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4796 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4797 return false;
4798 }
Greg Clayton890ff562012-02-02 05:48:16 +00004799#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004800
4801 // Make sure the top item in the decl context die array is always
4802 // DW_TAG_compile_unit. If it isn't then something went wrong in
4803 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004804 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004805
Greg Clayton890ff562012-02-02 05:48:16 +00004806#endif
4807 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004808 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004809 for (i=0; i<count1 - 1; i++)
4810 {
4811 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4812 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4813 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004814 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004815 // If the string was from a DW_FORM_strp, then the pointer will often
4816 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004817 if (name1 == name2)
4818 continue;
4819
4820 // Name pointers are not equal, so only compare the strings
4821 // if both are not NULL.
4822 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004823 {
Greg Clayton5569e642012-02-06 01:44:54 +00004824 // If the strings don't compare, we are done...
4825 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004826 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004827 }
4828 else
4829 {
4830 // One name was NULL while the other wasn't
4831 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004832 }
4833 }
Greg Clayton80c26302012-02-05 06:12:47 +00004834 // We made it through all of the checks and the declaration contexts
4835 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004836 return true;
4837}
Greg Clayton220a0072011-12-09 08:48:30 +00004838
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004839// This function can be used when a DIE is found that is a forward declaration
4840// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004841// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004842TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004843SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004844 const DWARFDebugInfoEntry *die,
4845 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004846{
4847 TypeSP type_sp;
4848
Greg Claytona8022fa2012-04-24 21:22:41 +00004849#if defined (LLDB_CONFIGURATION_DEBUG)
4850 // You can't and shouldn't call this function with a compile unit from
4851 // another SymbolFileDWARF instance.
4852 assert (DebugInfo()->ContainsCompileUnit (cu));
4853#endif
4854
Greg Clayton1a65ae12011-01-25 23:55:37 +00004855 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004856 return type_sp;
4857
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004858 std::string qualified_name;
4859
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004860 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4861 if (log)
4862 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004863 die->GetQualifiedName(this, cu, qualified_name);
4864 GetObjectFile()->GetModule()->LogMessage (log.get(),
4865 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4866 die->GetOffset(),
4867 qualified_name.c_str(),
4868 type_name.GetCString());
4869 }
4870
Greg Clayton7f995132011-10-04 22:41:51 +00004871 DIEArray die_offsets;
4872
Greg Clayton97fbc342011-10-20 22:30:33 +00004873 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004874 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004875 if (m_apple_types_ap.get())
4876 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004877 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4878 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4879 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004880 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004881 if (qualified_name.empty())
4882 die->GetQualifiedName(this, cu, qualified_name);
4883
4884 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4885 if (log)
4886 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
4887 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4888 }
4889 else if (has_tag > 1)
4890 {
4891 if (log)
4892 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004893 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004894 }
4895 else
4896 {
4897 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4898 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004899 }
Greg Clayton7f995132011-10-04 22:41:51 +00004900 }
4901 else
4902 {
4903 if (!m_indexed)
4904 Index ();
4905
4906 m_type_index.Find (type_name, die_offsets);
4907 }
Greg Clayton7f995132011-10-04 22:41:51 +00004908
4909 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004910
Greg Clayton934cb052011-12-03 00:27:05 +00004911 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004912
4913 DWARFCompileUnit* type_cu = NULL;
4914 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004915 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004916 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004917 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004918 for (size_t i=0; i<num_matches; ++i)
4919 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004920 const dw_offset_t die_offset = die_offsets[i];
4921 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004922
Greg Clayton95d87902011-11-11 03:16:25 +00004923 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004924 {
Greg Clayton934cb052011-12-03 00:27:05 +00004925 bool try_resolving_type = false;
4926
4927 // Don't try and resolve the DIE we are looking for with the DIE itself!
4928 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004929 {
Greg Clayton934cb052011-12-03 00:27:05 +00004930 const dw_tag_t type_die_tag = type_die->Tag();
4931 // Make sure the tags match
4932 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004933 {
Greg Clayton934cb052011-12-03 00:27:05 +00004934 // The tags match, lets try resolving this type
4935 try_resolving_type = true;
4936 }
4937 else
4938 {
4939 // The tags don't match, but we need to watch our for a
4940 // forward declaration for a struct and ("struct foo")
4941 // ends up being a class ("class foo { ... };") or
4942 // vice versa.
4943 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004944 {
Greg Clayton934cb052011-12-03 00:27:05 +00004945 case DW_TAG_class_type:
4946 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4947 try_resolving_type = (die_tag == DW_TAG_structure_type);
4948 break;
4949 case DW_TAG_structure_type:
4950 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4951 try_resolving_type = (die_tag == DW_TAG_class_type);
4952 break;
4953 default:
4954 // Tags don't match, don't event try to resolve
4955 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004956 break;
4957 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004958 }
4959 }
Greg Clayton934cb052011-12-03 00:27:05 +00004960
4961 if (try_resolving_type)
4962 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004963 if (log)
4964 {
4965 std::string qualified_name;
4966 type_die->GetQualifiedName(this, cu, qualified_name);
4967 GetObjectFile()->GetModule()->LogMessage (log.get(),
4968 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4969 die->GetOffset(),
4970 type_name.GetCString(),
4971 type_die->GetOffset(),
4972 qualified_name.c_str());
4973 }
4974
Greg Clayton890ff562012-02-02 05:48:16 +00004975 // Make sure the decl contexts match all the way up
4976 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004977 {
Greg Clayton890ff562012-02-02 05:48:16 +00004978 Type *resolved_type = ResolveType (type_cu, type_die, false);
4979 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4980 {
Daniel Malead01b2952012-11-29 21:49:15 +00004981 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton890ff562012-02-02 05:48:16 +00004982 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004983 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004984 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4985 MakeUserID(type_die->GetOffset()),
4986 MakeUserID(type_cu->GetOffset()));
4987
4988 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004989 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004990 break;
4991 }
Greg Clayton934cb052011-12-03 00:27:05 +00004992 }
4993 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004994 else
4995 {
4996 if (log)
4997 {
4998 std::string qualified_name;
4999 type_die->GetQualifiedName(this, cu, qualified_name);
5000 GetObjectFile()->GetModule()->LogMessage (log.get(),
5001 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5002 die->GetOffset(),
5003 type_name.GetCString(),
5004 type_die->GetOffset(),
5005 qualified_name.c_str());
5006 }
5007 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005008 }
Greg Clayton95d87902011-11-11 03:16:25 +00005009 else
5010 {
5011 if (m_using_apple_tables)
5012 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005013 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5014 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005015 }
5016 }
5017
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005018 }
5019 }
5020 return type_sp;
5021}
5022
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005023TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005024SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5025{
5026 TypeSP type_sp;
5027
5028 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5029 if (dwarf_decl_ctx_count > 0)
5030 {
5031 const ConstString type_name(dwarf_decl_ctx[0].name);
5032 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5033
5034 if (type_name)
5035 {
5036 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
5037 if (log)
5038 {
5039 GetObjectFile()->GetModule()->LogMessage (log.get(),
5040 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5041 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5042 dwarf_decl_ctx.GetQualifiedName());
5043 }
5044
5045 DIEArray die_offsets;
5046
5047 if (m_using_apple_tables)
5048 {
5049 if (m_apple_types_ap.get())
5050 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005051 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5052 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5053 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005054 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005055 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5056 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5057 if (log)
5058 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
5059 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5060 }
5061 else if (has_tag)
5062 {
5063 if (log)
5064 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005065 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5066 }
5067 else
5068 {
5069 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5070 }
5071 }
5072 }
5073 else
5074 {
5075 if (!m_indexed)
5076 Index ();
5077
5078 m_type_index.Find (type_name, die_offsets);
5079 }
5080
5081 const size_t num_matches = die_offsets.size();
5082
5083
5084 DWARFCompileUnit* type_cu = NULL;
5085 const DWARFDebugInfoEntry* type_die = NULL;
5086 if (num_matches)
5087 {
5088 DWARFDebugInfo* debug_info = DebugInfo();
5089 for (size_t i=0; i<num_matches; ++i)
5090 {
5091 const dw_offset_t die_offset = die_offsets[i];
5092 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5093
5094 if (type_die)
5095 {
5096 bool try_resolving_type = false;
5097
5098 // Don't try and resolve the DIE we are looking for with the DIE itself!
5099 const dw_tag_t type_tag = type_die->Tag();
5100 // Make sure the tags match
5101 if (type_tag == tag)
5102 {
5103 // The tags match, lets try resolving this type
5104 try_resolving_type = true;
5105 }
5106 else
5107 {
5108 // The tags don't match, but we need to watch our for a
5109 // forward declaration for a struct and ("struct foo")
5110 // ends up being a class ("class foo { ... };") or
5111 // vice versa.
5112 switch (type_tag)
5113 {
5114 case DW_TAG_class_type:
5115 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5116 try_resolving_type = (tag == DW_TAG_structure_type);
5117 break;
5118 case DW_TAG_structure_type:
5119 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5120 try_resolving_type = (tag == DW_TAG_class_type);
5121 break;
5122 default:
5123 // Tags don't match, don't event try to resolve
5124 // using this type whose name matches....
5125 break;
5126 }
5127 }
5128
5129 if (try_resolving_type)
5130 {
5131 DWARFDeclContext type_dwarf_decl_ctx;
5132 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5133
5134 if (log)
5135 {
5136 GetObjectFile()->GetModule()->LogMessage (log.get(),
5137 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5138 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5139 dwarf_decl_ctx.GetQualifiedName(),
5140 type_die->GetOffset(),
5141 type_dwarf_decl_ctx.GetQualifiedName());
5142 }
5143
5144 // Make sure the decl contexts match all the way up
5145 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5146 {
5147 Type *resolved_type = ResolveType (type_cu, type_die, false);
5148 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5149 {
5150 type_sp = resolved_type->shared_from_this();
5151 break;
5152 }
5153 }
5154 }
5155 else
5156 {
5157 if (log)
5158 {
5159 std::string qualified_name;
5160 type_die->GetQualifiedName(this, type_cu, qualified_name);
5161 GetObjectFile()->GetModule()->LogMessage (log.get(),
5162 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5163 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5164 dwarf_decl_ctx.GetQualifiedName(),
5165 type_die->GetOffset(),
5166 qualified_name.c_str());
5167 }
5168 }
5169 }
5170 else
5171 {
5172 if (m_using_apple_tables)
5173 {
5174 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5175 die_offset, type_name.GetCString());
5176 }
5177 }
5178
5179 }
5180 }
5181 }
5182 }
5183 return type_sp;
5184}
5185
Greg Clayton4116e932012-05-15 02:33:01 +00005186bool
Sean Callanan2367f8a2013-02-26 01:12:25 +00005187SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *class_symfile,
5188 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005189 DWARFCompileUnit* src_cu,
5190 const DWARFDebugInfoEntry *src_class_die,
5191 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005192 const DWARFDebugInfoEntry *dst_class_die,
5193 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005194{
5195 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5196 return false;
5197 if (src_class_die->Tag() != dst_class_die->Tag())
5198 return false;
5199
5200 // We need to complete the class type so we can get all of the method types
5201 // parsed so we can then unique those types to their equivalent counterparts
5202 // in "dst_cu" and "dst_class_die"
5203 class_type->GetClangFullType();
5204
5205 const DWARFDebugInfoEntry *src_die;
5206 const DWARFDebugInfoEntry *dst_die;
5207 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5208 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005209 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5210 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005211 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5212 {
5213 if (src_die->Tag() == DW_TAG_subprogram)
5214 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005215 // Make sure this is a declaration and not a concrete instance by looking
5216 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5217 // are placed inside the class definitions and shouldn't be included in
5218 // the list of things are are tracking here.
Sean Callanan2367f8a2013-02-26 01:12:25 +00005219 if (src_die->GetAttributeValueAsUnsigned(class_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005220 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005221 const char *src_name = src_die->GetMangledName (class_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005222 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005223 {
5224 ConstString src_const_name(src_name);
Sean Callanan2367f8a2013-02-26 01:12:25 +00005225 if (src_die->GetAttributeValueAsUnsigned(class_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005226 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5227 else
5228 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5229 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005230 }
Greg Clayton4116e932012-05-15 02:33:01 +00005231 }
5232 }
5233 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5234 {
5235 if (dst_die->Tag() == DW_TAG_subprogram)
5236 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005237 // Make sure this is a declaration and not a concrete instance by looking
5238 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5239 // are placed inside the class definitions and shouldn't be included in
5240 // the list of things are are tracking here.
5241 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5242 {
5243 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5244 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005245 {
5246 ConstString dst_const_name(dst_name);
5247 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5248 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5249 else
5250 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5251 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005252 }
Greg Clayton4116e932012-05-15 02:33:01 +00005253 }
5254 }
5255 const uint32_t src_size = src_name_to_die.GetSize ();
5256 const uint32_t dst_size = dst_name_to_die.GetSize ();
5257 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005258
5259 // Is everything kosher so we can go through the members at top speed?
5260 bool fast_path = true;
5261
5262 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005263 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005264 if (src_size != 0 && dst_size != 0)
5265 {
5266 if (log)
5267 log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)",
5268 src_class_die->GetOffset(),
5269 dst_class_die->GetOffset(),
5270 src_size,
5271 dst_size);
5272 }
5273
5274 fast_path = false;
5275 }
5276
5277 uint32_t idx;
5278
5279 if (fast_path)
5280 {
Greg Clayton4116e932012-05-15 02:33:01 +00005281 for (idx = 0; idx < src_size; ++idx)
5282 {
5283 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5284 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5285
5286 if (src_die->Tag() != dst_die->Tag())
5287 {
5288 if (log)
5289 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)",
5290 src_class_die->GetOffset(),
5291 dst_class_die->GetOffset(),
5292 src_die->GetOffset(),
5293 DW_TAG_value_to_name(src_die->Tag()),
5294 dst_die->GetOffset(),
5295 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005296 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005297 }
5298
Sean Callanan2367f8a2013-02-26 01:12:25 +00005299 const char *src_name = src_die->GetMangledName (class_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005300 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5301
5302 // Make sure the names match
5303 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5304 continue;
5305
5306 if (log)
5307 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)",
5308 src_class_die->GetOffset(),
5309 dst_class_die->GetOffset(),
5310 src_die->GetOffset(),
5311 src_name,
5312 dst_die->GetOffset(),
5313 dst_name);
5314
Sean Callanan2367f8a2013-02-26 01:12:25 +00005315 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005316 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005317 }
Greg Clayton4116e932012-05-15 02:33:01 +00005318
Sean Callanan2367f8a2013-02-26 01:12:25 +00005319 // Now do the work of linking the DeclContexts and Types.
5320 if (fast_path)
5321 {
5322 // We can do this quickly. Just run across the tables index-for-index since
5323 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005324 for (idx = 0; idx < src_size; ++idx)
5325 {
5326 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5327 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5328
Sean Callanan2367f8a2013-02-26 01:12:25 +00005329 clang::DeclContext *src_decl_ctx = class_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005330 if (src_decl_ctx)
5331 {
5332 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005333 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005334 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5335 }
5336 else
5337 {
5338 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005339 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005340 }
5341
5342 Type *src_child_type = m_die_to_type[src_die];
5343 if (src_child_type)
5344 {
5345 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005346 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton4116e932012-05-15 02:33:01 +00005347 m_die_to_type[dst_die] = src_child_type;
5348 }
5349 else
5350 {
5351 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005352 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5353 }
5354 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005355 }
5356 else
5357 {
5358 // We must do this slowly. For each member of the destination, look
5359 // up a member in the source with the same name, check its tag, and
5360 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005361
Sean Callanan2367f8a2013-02-26 01:12:25 +00005362 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5363 {
5364 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005365
Sean Callanan2367f8a2013-02-26 01:12:25 +00005366 for (idx = 0; idx < dst_size; ++idx)
5367 {
5368 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5369 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5370 src_die = src_name_to_die.Find(dst_name, NULL);
5371
5372 if (src_die && (src_die->Tag() == dst_die->Tag()))
5373 {
5374 clang::DeclContext *src_decl_ctx = class_symfile->m_die_to_decl_ctx[src_die];
5375 if (src_decl_ctx)
5376 {
5377 if (log)
5378 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5379 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5380 }
5381 else
5382 {
5383 if (log)
5384 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5385 }
5386
5387 Type *src_child_type = m_die_to_type[src_die];
5388 if (src_child_type)
5389 {
5390 if (log)
5391 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5392 m_die_to_type[dst_die] = src_child_type;
5393 }
5394 else
5395 {
5396 if (log)
5397 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5398 }
5399 }
5400 else
5401 {
5402 if (log)
5403 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005404
Sean Callanan2367f8a2013-02-26 01:12:25 +00005405 failures.push_back(dst_die);
5406 }
5407 }
5408 }
5409 }
5410
5411 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5412 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5413
5414 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5415
5416 if (src_size_artificial && dst_size_artificial)
5417 {
5418 dst_name_to_die_artificial.Sort();
5419
Greg Clayton65ec1032012-11-12 21:27:20 +00005420 for (idx = 0; idx < src_size_artificial; ++idx)
5421 {
5422 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5423 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5424 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5425
5426 if (dst_die)
5427 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005428 // Both classes have the artificial types, link them
5429 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5430 if (src_decl_ctx)
5431 {
5432 if (log)
5433 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5434 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5435 }
5436 else
5437 {
5438 if (log)
5439 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5440 }
5441
5442 Type *src_child_type = m_die_to_type[src_die];
5443 if (src_child_type)
5444 {
5445 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005446 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005447 m_die_to_type[dst_die] = src_child_type;
5448 }
5449 else
5450 {
5451 if (log)
5452 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5453 }
5454 }
5455 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005456 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005457
Sean Callanan2367f8a2013-02-26 01:12:25 +00005458 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005459 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005460 for (idx = 0; idx < dst_size_artificial; ++idx)
5461 {
5462 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5463 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5464 if (log)
5465 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5466
5467 failures.push_back(dst_die);
5468 }
Greg Clayton4116e932012-05-15 02:33:01 +00005469 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005470
5471 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005472}
Greg Claytona8022fa2012-04-24 21:22:41 +00005473
5474TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005475SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005476{
5477 TypeSP type_sp;
5478
Greg Clayton1be10fc2010-09-29 01:12:09 +00005479 if (type_is_new_ptr)
5480 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005481
5482#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5483 static DIEStack g_die_stack;
5484 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5485#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005486
Sean Callananc7fbf732010-08-06 00:32:49 +00005487 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005488 if (die != NULL)
5489 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005490 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005491 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005492 {
5493 const DWARFDebugInfoEntry *context_die;
5494 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5495
Greg Clayton1fba87112012-02-09 20:03:49 +00005496 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 +00005497 die->GetOffset(),
5498 context,
5499 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005500 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005501 die->GetName(this, dwarf_cu));
5502
5503#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5504 scoped_die_logger.Push (dwarf_cu, die);
5505 g_die_stack.LogDIEs(log.get(), this);
5506#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005507 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005508//
5509// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5510// if (log && dwarf_cu)
5511// {
5512// StreamString s;
5513// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005514// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005515//
5516// }
Jim Ingham16746d12011-08-25 23:21:43 +00005517
Greg Clayton594e5ed2010-09-27 21:07:38 +00005518 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005519 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005520 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005521 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005522 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005523 if (type_is_new_ptr)
5524 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005525
Greg Clayton594e5ed2010-09-27 21:07:38 +00005526 const dw_tag_t tag = die->Tag();
5527
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005528 bool is_forward_declaration = false;
5529 DWARFDebugInfoEntry::Attributes attributes;
5530 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005531 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005532 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5533 size_t byte_size = 0;
5534 Declaration decl;
5535
Greg Clayton4957bf62010-09-30 21:49:03 +00005536 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005537 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005538
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005539 dw_attr_t attr;
5540
5541 switch (tag)
5542 {
5543 case DW_TAG_base_type:
5544 case DW_TAG_pointer_type:
5545 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005546 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005547 case DW_TAG_typedef:
5548 case DW_TAG_const_type:
5549 case DW_TAG_restrict_type:
5550 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005551 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005552 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005553 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005554 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005555
Greg Claytond88d7592010-09-15 08:33:30 +00005556 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005557 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005558 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5559
5560 if (num_attributes > 0)
5561 {
5562 uint32_t i;
5563 for (i=0; i<num_attributes; ++i)
5564 {
5565 attr = attributes.AttributeAtIndex(i);
5566 DWARFFormValue form_value;
5567 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5568 {
5569 switch (attr)
5570 {
5571 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5572 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5573 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5574 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005575
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005576 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005577 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5578 // include the "&"...
5579 if (tag == DW_TAG_reference_type)
5580 {
5581 if (strchr (type_name_cstr, '&') == NULL)
5582 type_name_cstr = NULL;
5583 }
5584 if (type_name_cstr)
5585 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005586 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005587 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005588 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5589 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5590 default:
5591 case DW_AT_sibling:
5592 break;
5593 }
5594 }
5595 }
5596 }
5597
Daniel Malead01b2952012-11-29 21:49:15 +00005598 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005599
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005600 switch (tag)
5601 {
5602 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005603 break;
5604
Greg Claytond4436412011-10-28 21:00:00 +00005605 case DW_TAG_unspecified_type:
5606 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5607 {
5608 resolve_state = Type::eResolveStateFull;
5609 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5610 break;
5611 }
5612 // Fall through to base type below in case we can handle the type there...
5613
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005614 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005615 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005616 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5617 encoding,
5618 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005619 break;
5620
Sean Callanance8af862012-05-21 23:31:51 +00005621 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5622 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5623 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5624 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5625 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5626 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5627 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005628 }
5629
Sean Callanan82587052013-01-03 00:05:56 +00005630 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005631 {
Sean Callanan82587052013-01-03 00:05:56 +00005632 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5633
5634 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005635 {
Sean Callanan82587052013-01-03 00:05:56 +00005636 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005637 {
Sean Callanan82587052013-01-03 00:05:56 +00005638 static ConstString g_objc_type_name_id("id");
5639 static ConstString g_objc_type_name_Class("Class");
5640 static ConstString g_objc_type_name_selector("SEL");
5641
5642 if (type_name_const_str == g_objc_type_name_id)
5643 {
5644 if (log)
5645 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5646 die->GetOffset(),
5647 DW_TAG_value_to_name(die->Tag()),
5648 die->GetName(this, dwarf_cu));
5649 clang_type = ast.GetBuiltInType_objc_id();
5650 encoding_data_type = Type::eEncodingIsUID;
5651 encoding_uid = LLDB_INVALID_UID;
5652 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005653
Sean Callanan82587052013-01-03 00:05:56 +00005654 }
5655 else if (type_name_const_str == g_objc_type_name_Class)
5656 {
5657 if (log)
5658 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5659 die->GetOffset(),
5660 DW_TAG_value_to_name(die->Tag()),
5661 die->GetName(this, dwarf_cu));
5662 clang_type = ast.GetBuiltInType_objc_Class();
5663 encoding_data_type = Type::eEncodingIsUID;
5664 encoding_uid = LLDB_INVALID_UID;
5665 resolve_state = Type::eResolveStateFull;
5666 }
5667 else if (type_name_const_str == g_objc_type_name_selector)
5668 {
5669 if (log)
5670 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5671 die->GetOffset(),
5672 DW_TAG_value_to_name(die->Tag()),
5673 die->GetName(this, dwarf_cu));
5674 clang_type = ast.GetBuiltInType_objc_selector();
5675 encoding_data_type = Type::eEncodingIsUID;
5676 encoding_uid = LLDB_INVALID_UID;
5677 resolve_state = Type::eResolveStateFull;
5678 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005679 }
Sean Callanan82587052013-01-03 00:05:56 +00005680 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005681 {
Sean Callanan82587052013-01-03 00:05:56 +00005682 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5683
5684 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5685
5686 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5687 {
5688 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5689 {
5690 if (!strcmp(struct_name, "objc_object"))
5691 {
5692 if (log)
5693 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
5694 die->GetOffset(),
5695 DW_TAG_value_to_name(die->Tag()),
5696 die->GetName(this, dwarf_cu));
5697 clang_type = ast.GetBuiltInType_objc_id();
5698 encoding_data_type = Type::eEncodingIsUID;
5699 encoding_uid = LLDB_INVALID_UID;
5700 resolve_state = Type::eResolveStateFull;
5701 }
5702 }
5703 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005704 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005705 }
5706 }
5707
Greg Clayton81c22f62011-10-19 18:09:39 +00005708 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005709 this,
5710 type_name_const_str,
5711 byte_size,
5712 NULL,
5713 encoding_uid,
5714 encoding_data_type,
5715 &decl,
5716 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005717 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005718
Greg Clayton594e5ed2010-09-27 21:07:38 +00005719 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005720
5721// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5722// if (encoding_type != NULL)
5723// {
5724// if (encoding_type != DIE_IS_BEING_PARSED)
5725// type_sp->SetEncodingType(encoding_type);
5726// else
5727// m_indirect_fixups.push_back(type_sp.get());
5728// }
5729 }
5730 break;
5731
5732 case DW_TAG_structure_type:
5733 case DW_TAG_union_type:
5734 case DW_TAG_class_type:
5735 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005736 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005737 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005738 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005739
Greg Clayton9e409562010-07-28 02:04:09 +00005740 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005741 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005742 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005743 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005744 if (num_attributes > 0)
5745 {
5746 uint32_t i;
5747 for (i=0; i<num_attributes; ++i)
5748 {
5749 attr = attributes.AttributeAtIndex(i);
5750 DWARFFormValue form_value;
5751 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5752 {
5753 switch (attr)
5754 {
Greg Clayton9e409562010-07-28 02:04:09 +00005755 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005756 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5757 {
5758 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5759 // point to the compile unit file, so we clear this invalid value
5760 // so that we can still unique types efficiently.
5761 decl.SetFile(FileSpec ("<invalid>", false));
5762 }
5763 else
5764 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005765 break;
5766
5767 case DW_AT_decl_line:
5768 decl.SetLine(form_value.Unsigned());
5769 break;
5770
5771 case DW_AT_decl_column:
5772 decl.SetColumn(form_value.Unsigned());
5773 break;
5774
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005775 case DW_AT_name:
5776 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005777 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005778 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005779
5780 case DW_AT_byte_size:
5781 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005782 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005783 break;
5784
5785 case DW_AT_accessibility:
5786 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5787 break;
5788
5789 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005790 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005791 break;
5792
5793 case DW_AT_APPLE_runtime_class:
5794 class_language = (LanguageType)form_value.Signed();
5795 break;
5796
Greg Clayton18774842011-11-29 23:40:34 +00005797 case DW_AT_APPLE_objc_complete_type:
5798 is_complete_objc_class = form_value.Signed();
5799 break;
5800
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005801 case DW_AT_allocated:
5802 case DW_AT_associated:
5803 case DW_AT_data_location:
5804 case DW_AT_description:
5805 case DW_AT_start_scope:
5806 case DW_AT_visibility:
5807 default:
5808 case DW_AT_sibling:
5809 break;
5810 }
5811 }
5812 }
5813 }
5814
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005815 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005816
Greg Clayton123edca2012-03-02 00:07:15 +00005817 // Only try and unique the type if it has a name.
5818 if (type_name_const_str &&
5819 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005820 this,
5821 dwarf_cu,
5822 die,
5823 decl,
5824 byte_size_valid ? byte_size : -1,
5825 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005826 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005827 // We have already parsed this type or from another
5828 // compile unit. GCC loves to use the "one definition
5829 // rule" which can result in multiple definitions
5830 // of the same class over and over in each compile
5831 // unit.
5832 type_sp = unique_ast_entry.m_type_sp;
5833 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005834 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005835 m_die_to_type[die] = type_sp.get();
5836 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005837 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005838 }
5839
Daniel Malead01b2952012-11-29 21:49:15 +00005840 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005841
5842 int tag_decl_kind = -1;
5843 AccessType default_accessibility = eAccessNone;
5844 if (tag == DW_TAG_structure_type)
5845 {
5846 tag_decl_kind = clang::TTK_Struct;
5847 default_accessibility = eAccessPublic;
5848 }
5849 else if (tag == DW_TAG_union_type)
5850 {
5851 tag_decl_kind = clang::TTK_Union;
5852 default_accessibility = eAccessPublic;
5853 }
5854 else if (tag == DW_TAG_class_type)
5855 {
5856 tag_decl_kind = clang::TTK_Class;
5857 default_accessibility = eAccessPrivate;
5858 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005859
5860 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5861 die->HasChildren() == false &&
5862 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5863 {
5864 // Work around an issue with clang at the moment where
5865 // forward declarations for objective C classes are emitted
5866 // as:
5867 // DW_TAG_structure_type [2]
5868 // DW_AT_name( "ForwardObjcClass" )
5869 // DW_AT_byte_size( 0x00 )
5870 // DW_AT_decl_file( "..." )
5871 // DW_AT_decl_line( 1 )
5872 //
5873 // Note that there is no DW_AT_declaration and there are
5874 // no children, and the byte size is zero.
5875 is_forward_declaration = true;
5876 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005877
Sean Callanan7457f8d2012-04-25 01:03:57 +00005878 if (class_language == eLanguageTypeObjC ||
5879 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005880 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005881 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005882 {
5883 // We have a valid eSymbolTypeObjCClass class symbol whose
5884 // name matches the current objective C class that we
5885 // are trying to find and this DIE isn't the complete
5886 // definition (we checked is_complete_objc_class above and
5887 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005888 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005889
Greg Clayton1f746072012-08-29 21:13:06 +00005890 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005891 {
5892 // We weren't able to find a full declaration in
5893 // this DWARF, see if we have a declaration anywhere
5894 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005895 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005896 }
5897
5898 if (type_sp)
5899 {
5900 if (log)
5901 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005902 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005903 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005904 this,
5905 die->GetOffset(),
5906 DW_TAG_value_to_name(tag),
5907 type_name_cstr,
5908 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005909 }
5910
5911 // We found a real definition for this type elsewhere
5912 // so lets use it and cache the fact that we found
5913 // a complete type for this die
5914 m_die_to_type[die] = type_sp.get();
5915 return type_sp;
5916 }
5917 }
5918 }
5919
5920
5921 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005922 {
5923 // We have a forward declaration to a type and we need
5924 // to try and find a full declaration. We look in the
5925 // current type index just in case we have a forward
5926 // declaration followed by an actual declarations in the
5927 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005928 if (log)
5929 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005930 GetObjectFile()->GetModule()->LogMessage (log.get(),
5931 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5932 this,
5933 die->GetOffset(),
5934 DW_TAG_value_to_name(tag),
5935 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005936 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005937
Greg Claytona8022fa2012-04-24 21:22:41 +00005938 DWARFDeclContext die_decl_ctx;
5939 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5940
5941 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5942 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005943
Greg Clayton1f746072012-08-29 21:13:06 +00005944 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005945 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005946 // We weren't able to find a full declaration in
5947 // this DWARF, see if we have a declaration anywhere
5948 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005949 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005950 }
5951
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005952 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005953 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005954 if (log)
5955 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005956 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005957 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005958 this,
5959 die->GetOffset(),
5960 DW_TAG_value_to_name(tag),
5961 type_name_cstr,
5962 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005963 }
5964
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005965 // We found a real definition for this type elsewhere
5966 // so lets use it and cache the fact that we found
5967 // a complete type for this die
5968 m_die_to_type[die] = type_sp.get();
5969 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005970 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005971 }
5972 assert (tag_decl_kind != -1);
5973 bool clang_type_was_created = false;
5974 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5975 if (clang_type == NULL)
5976 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005977 const DWARFDebugInfoEntry *decl_ctx_die;
5978
5979 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005980 if (accessibility == eAccessNone && decl_ctx)
5981 {
5982 // Check the decl context that contains this class/struct/union.
5983 // If it is a class we must give it an accessability.
5984 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5985 if (DeclKindIsCXXClass (containing_decl_kind))
5986 accessibility = default_accessibility;
5987 }
5988
Greg Claytonf0705c82011-10-22 03:33:13 +00005989 if (type_name_cstr && strchr (type_name_cstr, '<'))
5990 {
5991 ClangASTContext::TemplateParameterInfos template_param_infos;
5992 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5993 {
5994 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005995 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005996 type_name_cstr,
5997 tag_decl_kind,
5998 template_param_infos);
5999
6000 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6001 class_template_decl,
6002 tag_decl_kind,
6003 template_param_infos);
6004 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6005 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00006006
Jim Ingham379397632012-10-27 02:54:13 +00006007 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
6008 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00006009 }
6010 }
6011
6012 if (!clang_type_was_created)
6013 {
6014 clang_type_was_created = true;
Jim Ingham379397632012-10-27 02:54:13 +00006015 ClangASTMetadata metadata;
6016 metadata.SetUserID(MakeUserID(die->GetOffset()));
Greg Clayton55561e92011-10-26 03:31:36 +00006017 clang_type = ast.CreateRecordType (decl_ctx,
6018 accessibility,
6019 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006020 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006021 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006022 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006023 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006024 }
6025
6026 // Store a forward declaration to this class type in case any
6027 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006028 // types for function prototypes.
6029 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006030 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006031 this,
6032 type_name_const_str,
6033 byte_size,
6034 NULL,
6035 LLDB_INVALID_UID,
6036 Type::eEncodingIsUID,
6037 &decl,
6038 clang_type,
6039 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00006040
6041 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006042
6043
6044 // Add our type to the unique type map so we don't
6045 // end up creating many copies of the same type over
6046 // and over in the ASTContext for our module
6047 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00006048 unique_ast_entry.m_symfile = this;
6049 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006050 unique_ast_entry.m_die = die;
6051 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006052 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006053 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6054 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006055
Sean Callanan12014a02011-12-08 23:45:45 +00006056 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006057 {
6058 // Always start the definition for a class type so that
6059 // if the class has child classes or types that require
6060 // the class to be created for use as their decl contexts
6061 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006062 if (die->HasChildren() == false)
6063 {
6064 // No children for this struct/union/class, lets finish it
6065 ast.StartTagDeclarationDefinition (clang_type);
6066 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00006067
6068 if (tag == DW_TAG_structure_type) // this only applies in C
6069 {
6070 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
6071 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
6072
6073 if (record_type)
6074 {
6075 clang::RecordDecl *record_decl = record_type->getDecl();
6076
6077 if (record_decl)
6078 {
6079 LayoutInfo layout_info;
6080
6081 layout_info.alignment = 0;
6082 layout_info.bit_size = 0;
6083
6084 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6085 }
6086 }
6087 }
Sean Callanan12014a02011-12-08 23:45:45 +00006088 }
6089 else if (clang_type_was_created)
6090 {
Greg Clayton219cf312012-03-30 00:51:13 +00006091 // Start the definition if the class is not objective C since
6092 // the underlying decls respond to isCompleteDefinition(). Objective
6093 // C decls dont' respond to isCompleteDefinition() so we can't
6094 // start the declaration definition right away. For C++ classs/union/structs
6095 // we want to start the definition in case the class is needed as the
6096 // declaration context for a contained class or type without the need
6097 // to complete that type..
6098
Sean Callanan7457f8d2012-04-25 01:03:57 +00006099 if (class_language != eLanguageTypeObjC &&
6100 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006101 ast.StartTagDeclarationDefinition (clang_type);
6102
Sean Callanan12014a02011-12-08 23:45:45 +00006103 // Leave this as a forward declaration until we need
6104 // to know the details of the type. lldb_private::Type
6105 // will automatically call the SymbolFile virtual function
6106 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6107 // When the definition needs to be defined.
6108 m_forward_decl_die_to_clang_type[die] = clang_type;
6109 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6110 ClangASTContext::SetHasExternalStorage (clang_type, true);
6111 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006112 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006113
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006114 }
6115 break;
6116
6117 case DW_TAG_enumeration_type:
6118 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006119 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006120 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006121
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006122 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006123
Greg Claytond88d7592010-09-15 08:33:30 +00006124 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006125 if (num_attributes > 0)
6126 {
6127 uint32_t i;
6128
6129 for (i=0; i<num_attributes; ++i)
6130 {
6131 attr = attributes.AttributeAtIndex(i);
6132 DWARFFormValue form_value;
6133 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6134 {
6135 switch (attr)
6136 {
Greg Clayton7a345282010-11-09 23:46:37 +00006137 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6138 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6139 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006140 case DW_AT_name:
6141 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006142 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006143 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006144 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006145 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6146 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6147 case DW_AT_declaration: break; //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_bit_stride:
6151 case DW_AT_byte_stride:
6152 case DW_AT_data_location:
6153 case DW_AT_description:
6154 case DW_AT_start_scope:
6155 case DW_AT_visibility:
6156 case DW_AT_specification:
6157 case DW_AT_abstract_origin:
6158 case DW_AT_sibling:
6159 break;
6160 }
6161 }
6162 }
6163
Daniel Malead01b2952012-11-29 21:49:15 +00006164 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006165
Greg Clayton1be10fc2010-09-29 01:12:09 +00006166 clang_type_t enumerator_clang_type = NULL;
6167 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6168 if (clang_type == NULL)
6169 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006170 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6171 DW_ATE_signed,
6172 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00006173 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006174 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006175 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006176 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006177 }
6178 else
6179 {
6180 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
6181 assert (enumerator_clang_type != NULL);
6182 }
6183
Greg Claytona2721472011-06-25 00:44:06 +00006184 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6185
Greg Clayton81c22f62011-10-19 18:09:39 +00006186 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006187 this,
6188 type_name_const_str,
6189 byte_size,
6190 NULL,
6191 encoding_uid,
6192 Type::eEncodingIsUID,
6193 &decl,
6194 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006195 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006196
Greg Clayton6beaaa62011-01-17 03:46:26 +00006197 ast.StartTagDeclarationDefinition (clang_type);
6198 if (die->HasChildren())
6199 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006200 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
6201 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006202 }
6203 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006204 }
6205 }
6206 break;
6207
Jim Inghamb0be4422010-08-12 01:20:14 +00006208 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006209 case DW_TAG_subprogram:
6210 case DW_TAG_subroutine_type:
6211 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006213 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006214
Greg Clayton23f59502012-07-17 03:23:13 +00006215 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006216 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006217 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006218 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006219 bool is_static = false;
6220 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006221 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006222 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006223 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6224 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006225 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006226
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006227 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006228 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006229
6230
Greg Claytond88d7592010-09-15 08:33:30 +00006231 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006232 if (num_attributes > 0)
6233 {
6234 uint32_t i;
6235 for (i=0; i<num_attributes; ++i)
6236 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006237 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006238 DWARFFormValue form_value;
6239 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6240 {
6241 switch (attr)
6242 {
6243 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6244 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6245 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6246 case DW_AT_name:
6247 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006248 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006249 break;
6250
Greg Clayton71415542012-12-08 00:24:40 +00006251 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006252 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006253 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006254 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006255 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00006256 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
6257 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00006258 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00006259 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6260
Greg Claytonf51de672010-10-01 02:31:07 +00006261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006262 case DW_AT_external:
6263 if (form_value.Unsigned())
6264 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006265 if (storage == clang::SC_None)
6266 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006267 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006268 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006269 }
6270 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006271
Greg Clayton72da3972011-08-16 18:40:23 +00006272 case DW_AT_specification:
6273 specification_die_offset = form_value.Reference(dwarf_cu);
6274 break;
6275
6276 case DW_AT_abstract_origin:
6277 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6278 break;
6279
Jim Ingham379397632012-10-27 02:54:13 +00006280 case DW_AT_object_pointer:
6281 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6282 break;
6283
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006284 case DW_AT_allocated:
6285 case DW_AT_associated:
6286 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006287 case DW_AT_calling_convention:
6288 case DW_AT_data_location:
6289 case DW_AT_elemental:
6290 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006291 case DW_AT_frame_base:
6292 case DW_AT_high_pc:
6293 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006294 case DW_AT_prototyped:
6295 case DW_AT_pure:
6296 case DW_AT_ranges:
6297 case DW_AT_recursive:
6298 case DW_AT_return_addr:
6299 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006300 case DW_AT_start_scope:
6301 case DW_AT_static_link:
6302 case DW_AT_trampoline:
6303 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006304 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006305 case DW_AT_description:
6306 case DW_AT_sibling:
6307 break;
6308 }
6309 }
6310 }
Greg Clayton24739922010-10-13 03:15:28 +00006311 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006312
Jim Ingham379397632012-10-27 02:54:13 +00006313 std::string object_pointer_name;
6314 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6315 {
6316 // Get the name from the object pointer die
6317 StreamString s;
6318 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6319 {
6320 object_pointer_name.assign(s.GetData());
6321 }
6322 }
6323
Daniel Malead01b2952012-11-29 21:49:15 +00006324 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006325
Greg Clayton24739922010-10-13 03:15:28 +00006326 clang_type_t return_clang_type = NULL;
6327 Type *func_type = NULL;
6328
6329 if (type_die_offset != DW_INVALID_OFFSET)
6330 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006331
Greg Clayton24739922010-10-13 03:15:28 +00006332 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006333 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006334 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006335 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006336
Greg Claytonf51de672010-10-01 02:31:07 +00006337
Greg Clayton24739922010-10-13 03:15:28 +00006338 std::vector<clang_type_t> function_param_types;
6339 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006340
Greg Clayton24739922010-10-13 03:15:28 +00006341 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006342
Greg Claytoncb5860a2011-10-13 23:49:28 +00006343 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6344 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006345 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6346
Greg Claytonf0705c82011-10-22 03:33:13 +00006347 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006348 // Start off static. This will be set to false in ParseChildParameters(...)
6349 // if we find a "this" paramters as the first parameter
6350 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006351 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006352 ClangASTContext::TemplateParameterInfos template_param_infos;
6353
Greg Clayton24739922010-10-13 03:15:28 +00006354 if (die->HasChildren())
6355 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006356 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006357 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006358 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006359 dwarf_cu,
6360 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006361 skip_artificial,
6362 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006363 type_list,
6364 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006365 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006366 type_quals,
6367 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006368 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006369
Greg Clayton24739922010-10-13 03:15:28 +00006370 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006371 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006372 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006373 function_param_types.size(),
6374 is_variadic,
6375 type_quals);
6376
Greg Clayton24739922010-10-13 03:15:28 +00006377 if (type_name_cstr)
6378 {
6379 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006380 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006381 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006382 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6383 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006384 {
Greg Clayton24739922010-10-13 03:15:28 +00006385 SymbolContext empty_sc;
6386 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006387 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006388 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006389 {
Greg Clayton24739922010-10-13 03:15:28 +00006390 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006391 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006392
6393 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006394 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006395 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6396 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6397 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006398 }
Greg Clayton24739922010-10-13 03:15:28 +00006399 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006400
Greg Clayton24739922010-10-13 03:15:28 +00006401 if (class_opaque_type)
6402 {
6403 // If accessibility isn't set to anything valid, assume public for
6404 // now...
6405 if (accessibility == eAccessNone)
6406 accessibility = eAccessPublic;
6407
Sean Callanan464a5b52012-10-04 22:06:29 +00006408 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6409 type_name_cstr,
6410 clang_type,
6411 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00006412 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006413 if (type_handled)
6414 {
6415 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Jim Ingham379397632012-10-27 02:54:13 +00006416 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006417 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006418 else
6419 {
6420 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invaliad Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
6421 die->GetOffset(),
6422 tag,
6423 DW_TAG_value_to_name(tag));
6424 }
Greg Clayton24739922010-10-13 03:15:28 +00006425 }
6426 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006427 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006428 {
6429 // Look at the parent of this DIE and see if is is
6430 // a class or struct and see if this is actually a
6431 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006432 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006433 if (class_type)
6434 {
Greg Clayton4116e932012-05-15 02:33:01 +00006435 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6436 {
6437 // We uniqued the parent class of this function to another class
6438 // so we now need to associate all dies under "decl_ctx_die" to
6439 // DIEs in the DIE for "class_type"...
Sean Callanan2367f8a2013-02-26 01:12:25 +00006440 SymbolFileDWARF *class_symfile;
Greg Clayton4116e932012-05-15 02:33:01 +00006441 DWARFCompileUnitSP class_type_cu_sp;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006442 const DWARFDebugInfoEntry *class_type_die;
6443
6444 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6445 if (debug_map_symfile)
6446 {
6447 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6448 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6449 }
6450 else
6451 {
6452 class_symfile = this;
6453 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6454 }
Greg Clayton4116e932012-05-15 02:33:01 +00006455 if (class_type_die)
6456 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006457 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6458
6459 CopyUniqueClassMethodTypes (class_symfile,
6460 class_type,
6461 class_type_cu_sp.get(),
6462 class_type_die,
6463 dwarf_cu,
6464 decl_ctx_die,
6465 failures);
6466
6467 // FIXME do something with these failures that's smarter than
6468 // just dropping them on the ground. Unfortunately classes don't
6469 // like having stuff added to them after their definitions are
6470 // complete...
6471
6472 type_ptr = m_die_to_type[die];
6473 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006474 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006475 type_sp = type_ptr->shared_from_this();
6476 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006477 }
6478 }
6479 }
6480
Greg Clayton72da3972011-08-16 18:40:23 +00006481 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006482 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006483 // We have a specification which we are going to base our function
6484 // prototype off of, so we need this type to be completed so that the
6485 // m_die_to_decl_ctx for the method in the specification has a valid
6486 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006487 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006488 // If we have a specification, then the function type should have been
6489 // made with the specification and not with this die.
6490 DWARFCompileUnitSP spec_cu_sp;
6491 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006492 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006493 if (spec_clang_decl_ctx)
6494 {
6495 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6496 }
6497 else
Jim Inghamc1663042011-09-29 22:12:35 +00006498 {
Daniel Malead01b2952012-11-29 21:49:15 +00006499 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006500 MakeUserID(die->GetOffset()),
6501 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006502 }
Greg Clayton72da3972011-08-16 18:40:23 +00006503 type_handled = true;
6504 }
6505 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6506 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006507 // We have a specification which we are going to base our function
6508 // prototype off of, so we need this type to be completed so that the
6509 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6510 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006511 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006512
Greg Clayton72da3972011-08-16 18:40:23 +00006513 DWARFCompileUnitSP abs_cu_sp;
6514 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006515 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006516 if (abs_clang_decl_ctx)
6517 {
6518 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6519 }
6520 else
Jim Inghamc1663042011-09-29 22:12:35 +00006521 {
Daniel Malead01b2952012-11-29 21:49:15 +00006522 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006523 MakeUserID(die->GetOffset()),
6524 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006525 }
Greg Clayton72da3972011-08-16 18:40:23 +00006526 type_handled = true;
6527 }
6528 else
6529 {
6530 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6531 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006532 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006533 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006534 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006535 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6536 // in the DWARF for C++ methods... Default to public for now...
6537 if (accessibility == eAccessNone)
6538 accessibility = eAccessPublic;
6539
6540 if (!is_static && !die->HasChildren())
6541 {
6542 // We have a C++ member function with no children (this pointer!)
6543 // and clang will get mad if we try and make a function that isn't
6544 // well formed in the DWARF, so we will just skip it...
6545 type_handled = true;
6546 }
6547 else
6548 {
6549 clang::CXXMethodDecl *cxx_method_decl;
6550 // REMOVE THE CRASH DESCRIPTION BELOW
Daniel Malead01b2952012-11-29 21:49:15 +00006551 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s/%s",
Greg Clayton20568dd2011-10-13 23:13:20 +00006552 type_name_cstr,
6553 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006554 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006555 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6556 m_obj_file->GetFileSpec().GetFilename().GetCString());
6557
Sean Callananc1b732d2011-11-01 18:07:13 +00006558 const bool is_attr_used = false;
6559
Greg Clayton20568dd2011-10-13 23:13:20 +00006560 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6561 type_name_cstr,
6562 clang_type,
6563 accessibility,
6564 is_virtual,
6565 is_static,
6566 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006567 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006568 is_attr_used,
6569 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006570
Greg Clayton20568dd2011-10-13 23:13:20 +00006571 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006572
6573 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006574 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006575 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6576
6577 Host::SetCrashDescription (NULL);
6578
6579
6580 ClangASTMetadata metadata;
6581 metadata.SetUserID(MakeUserID(die->GetOffset()));
6582
6583 if (!object_pointer_name.empty())
6584 {
6585 metadata.SetObjectPtrName(object_pointer_name.c_str());
6586 if (log)
6587 log->Printf ("Setting object pointer name: %s on method object 0x%ld.\n",
6588 object_pointer_name.c_str(),
6589 (uintptr_t) cxx_method_decl);
6590 }
6591 GetClangASTContext().SetMetadata ((uintptr_t)cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006592 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006593 }
Greg Clayton72da3972011-08-16 18:40:23 +00006594 }
6595 else
6596 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006597 // We were asked to parse the type for a method in a class, yet the
6598 // class hasn't been asked to complete itself through the
6599 // clang::ExternalASTSource protocol, so we need to just have the
6600 // class complete itself and do things the right way, then our
6601 // DIE should then have an entry in the m_die_to_type map. First
6602 // we need to modify the m_die_to_type so it doesn't think we are
6603 // trying to parse this DIE anymore...
6604 m_die_to_type[die] = NULL;
6605
6606 // Now we get the full type to force our class type to complete itself
6607 // using the clang::ExternalASTSource protocol which will parse all
6608 // base classes and all methods (including the method for this DIE).
6609 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006610
Greg Clayton20568dd2011-10-13 23:13:20 +00006611 // The type for this DIE should have been filled in the function call above
6612 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006613 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006614 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006615 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006616 break;
6617 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006618
6619 // FIXME This is fixing some even uglier behavior but we really need to
6620 // uniq the methods of each class as well as the class itself.
6621 // <rdar://problem/11240464>
6622 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006623 }
Greg Clayton931180e2011-01-27 06:44:37 +00006624 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006625 }
6626 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006627 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006628 }
Greg Clayton24739922010-10-13 03:15:28 +00006629
6630 if (!type_handled)
6631 {
6632 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006633 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6634 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006635 clang_type,
6636 storage,
6637 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006638
6639// if (template_param_infos.GetSize() > 0)
6640// {
6641// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6642// function_decl,
6643// type_name_cstr,
6644// template_param_infos);
6645//
6646// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6647// func_template_decl,
6648// template_param_infos);
6649// }
Greg Clayton24739922010-10-13 03:15:28 +00006650 // Add the decl to our DIE to decl context map
6651 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006652 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006653 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006654 ast.SetFunctionParameters (function_decl,
6655 &function_param_decls.front(),
6656 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006657
Jim Ingham379397632012-10-27 02:54:13 +00006658 ClangASTMetadata metadata;
6659 metadata.SetUserID(MakeUserID(die->GetOffset()));
6660
6661 if (!object_pointer_name.empty())
6662 {
6663 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006664 if (log)
6665 log->Printf ("Setting object pointer name: %s on function object 0x%ld.\n",
6666 object_pointer_name.c_str(),
6667 (uintptr_t) function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006668 }
6669 GetClangASTContext().SetMetadata ((uintptr_t)function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006670 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006671 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006672 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006673 this,
6674 type_name_const_str,
6675 0,
6676 NULL,
6677 LLDB_INVALID_UID,
6678 Type::eEncodingIsUID,
6679 &decl,
6680 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006681 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006682 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006683 }
6684 break;
6685
6686 case DW_TAG_array_type:
6687 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006688 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006689 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006691 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006692 int64_t first_index = 0;
6693 uint32_t byte_stride = 0;
6694 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006695 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006696
6697 if (num_attributes > 0)
6698 {
6699 uint32_t i;
6700 for (i=0; i<num_attributes; ++i)
6701 {
6702 attr = attributes.AttributeAtIndex(i);
6703 DWARFFormValue form_value;
6704 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6705 {
6706 switch (attr)
6707 {
6708 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6709 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6710 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6711 case DW_AT_name:
6712 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006713 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006714 break;
6715
6716 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006717 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006718 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6719 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006720 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6721 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006722 case DW_AT_allocated:
6723 case DW_AT_associated:
6724 case DW_AT_data_location:
6725 case DW_AT_description:
6726 case DW_AT_ordering:
6727 case DW_AT_start_scope:
6728 case DW_AT_visibility:
6729 case DW_AT_specification:
6730 case DW_AT_abstract_origin:
6731 case DW_AT_sibling:
6732 break;
6733 }
6734 }
6735 }
6736
Daniel Malead01b2952012-11-29 21:49:15 +00006737 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006738
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006739 Type *element_type = ResolveTypeUID(type_die_offset);
6740
6741 if (element_type)
6742 {
6743 std::vector<uint64_t> element_orders;
6744 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6745 if (byte_stride == 0 && bit_stride == 0)
6746 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006747 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006748 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6749 uint64_t num_elements = 0;
6750 std::vector<uint64_t>::const_reverse_iterator pos;
6751 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6752 for (pos = element_orders.rbegin(); pos != end; ++pos)
6753 {
6754 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006755 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton4ef877f2012-12-06 02:33:54 +00006756 num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006757 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006758 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006759 }
6760 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006761 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006762 this,
6763 empty_name,
6764 array_element_bit_stride / 8,
6765 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006766 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006767 Type::eEncodingIsUID,
6768 &decl,
6769 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006770 Type::eResolveStateFull));
6771 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006772 }
6773 }
6774 }
6775 break;
6776
Greg Clayton9b81a312010-06-12 01:20:30 +00006777 case DW_TAG_ptr_to_member_type:
6778 {
6779 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6780 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6781
Greg Claytond88d7592010-09-15 08:33:30 +00006782 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006783
6784 if (num_attributes > 0) {
6785 uint32_t i;
6786 for (i=0; i<num_attributes; ++i)
6787 {
6788 attr = attributes.AttributeAtIndex(i);
6789 DWARFFormValue form_value;
6790 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6791 {
6792 switch (attr)
6793 {
6794 case DW_AT_type:
6795 type_die_offset = form_value.Reference(dwarf_cu); break;
6796 case DW_AT_containing_type:
6797 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6798 }
6799 }
6800 }
6801
6802 Type *pointee_type = ResolveTypeUID(type_die_offset);
6803 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6804
Greg Clayton526e5af2010-11-13 03:52:47 +00006805 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6806 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006807
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006808 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6809 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006810
Greg Clayton526e5af2010-11-13 03:52:47 +00006811 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6812 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006813
Greg Clayton81c22f62011-10-19 18:09:39 +00006814 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006815 this,
6816 type_name_const_str,
6817 byte_size,
6818 NULL,
6819 LLDB_INVALID_UID,
6820 Type::eEncodingIsUID,
6821 NULL,
6822 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006823 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006824 }
6825
6826 break;
6827 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006828 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006829 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
6830 die->GetOffset(),
6831 tag,
6832 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006833 break;
6834 }
6835
6836 if (type_sp.get())
6837 {
6838 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6839 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6840
6841 SymbolContextScope * symbol_context_scope = NULL;
6842 if (sc_parent_tag == DW_TAG_compile_unit)
6843 {
6844 symbol_context_scope = sc.comp_unit;
6845 }
6846 else if (sc.function != NULL)
6847 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006848 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006849 if (symbol_context_scope == NULL)
6850 symbol_context_scope = sc.function;
6851 }
6852
6853 if (symbol_context_scope != NULL)
6854 {
6855 type_sp->SetSymbolContextScope(symbol_context_scope);
6856 }
6857
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006858 // We are ready to put this type into the uniqued list up at the module level
6859 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006860
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006861 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006862 }
6863 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006864 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006865 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006866 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006867 }
6868 }
6869 return type_sp;
6870}
6871
6872size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006873SymbolFileDWARF::ParseTypes
6874(
6875 const SymbolContext& sc,
6876 DWARFCompileUnit* dwarf_cu,
6877 const DWARFDebugInfoEntry *die,
6878 bool parse_siblings,
6879 bool parse_children
6880)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006881{
6882 size_t types_added = 0;
6883 while (die != NULL)
6884 {
6885 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006886 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006887 {
6888 if (type_is_new)
6889 ++types_added;
6890 }
6891
6892 if (parse_children && die->HasChildren())
6893 {
6894 if (die->Tag() == DW_TAG_subprogram)
6895 {
6896 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006897 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006898 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6899 }
6900 else
6901 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6902 }
6903
6904 if (parse_siblings)
6905 die = die->GetSibling();
6906 else
6907 die = NULL;
6908 }
6909 return types_added;
6910}
6911
6912
6913size_t
6914SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6915{
6916 assert(sc.comp_unit && sc.function);
6917 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006918 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006919 if (dwarf_cu)
6920 {
6921 dw_offset_t function_die_offset = sc.function->GetID();
6922 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6923 if (function_die)
6924 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006925 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006926 }
6927 }
6928
6929 return functions_added;
6930}
6931
6932
6933size_t
6934SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6935{
6936 // At least a compile unit must be valid
6937 assert(sc.comp_unit);
6938 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006939 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006940 if (dwarf_cu)
6941 {
6942 if (sc.function)
6943 {
6944 dw_offset_t function_die_offset = sc.function->GetID();
6945 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6946 if (func_die && func_die->HasChildren())
6947 {
6948 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6949 }
6950 }
6951 else
6952 {
6953 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6954 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6955 {
6956 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6957 }
6958 }
6959 }
6960
6961 return types_added;
6962}
6963
6964size_t
6965SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6966{
6967 if (sc.comp_unit != NULL)
6968 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006969 DWARFDebugInfo* info = DebugInfo();
6970 if (info == NULL)
6971 return 0;
6972
6973 uint32_t cu_idx = UINT32_MAX;
6974 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006975
6976 if (dwarf_cu == NULL)
6977 return 0;
6978
6979 if (sc.function)
6980 {
6981 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006982
Greg Claytonc7bece562013-01-25 18:06:21 +00006983 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6984 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006985 {
6986 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006987
Greg Claytone38a5ed2012-01-05 03:57:59 +00006988 // Let all blocks know they have parse all their variables
6989 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6990 return num_variables;
6991 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006992 }
6993 else if (sc.comp_unit)
6994 {
6995 uint32_t vars_added = 0;
6996 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6997
6998 if (variables.get() == NULL)
6999 {
7000 variables.reset(new VariableList());
7001 sc.comp_unit->SetVariableList(variables);
7002
Greg Claytond4a2b372011-09-12 23:21:58 +00007003 DWARFCompileUnit* match_dwarf_cu = NULL;
7004 const DWARFDebugInfoEntry* die = NULL;
7005 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007006 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007007 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007008 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007009 {
7010 DWARFMappedHash::DIEInfoArray hash_data_array;
7011 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7012 dwarf_cu->GetNextCompileUnitOffset(),
7013 hash_data_array))
7014 {
7015 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7016 }
7017 }
Greg Clayton7f995132011-10-04 22:41:51 +00007018 }
7019 else
7020 {
7021 // Index if we already haven't to make sure the compile units
7022 // get indexed and make their global DIE index list
7023 if (!m_indexed)
7024 Index ();
7025
7026 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7027 dwarf_cu->GetNextCompileUnitOffset(),
7028 die_offsets);
7029 }
7030
7031 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007032 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007033 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007034 DWARFDebugInfo* debug_info = DebugInfo();
7035 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007036 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007037 const dw_offset_t die_offset = die_offsets[i];
7038 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007039 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007040 {
Greg Clayton95d87902011-11-11 03:16:25 +00007041 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7042 if (var_sp)
7043 {
7044 variables->AddVariableIfUnique (var_sp);
7045 ++vars_added;
7046 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007047 }
Greg Clayton95d87902011-11-11 03:16:25 +00007048 else
7049 {
7050 if (m_using_apple_tables)
7051 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007052 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 +00007053 }
7054 }
7055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007056 }
7057 }
7058 }
7059 return vars_added;
7060 }
7061 }
7062 return 0;
7063}
7064
7065
7066VariableSP
7067SymbolFileDWARF::ParseVariableDIE
7068(
7069 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007070 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007071 const DWARFDebugInfoEntry *die,
7072 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007073)
7074{
7075
Greg Clayton83c5cd92010-11-14 22:13:40 +00007076 VariableSP var_sp (m_die_to_variable_sp[die]);
7077 if (var_sp)
7078 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007079
7080 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007081
7082 if ((tag == DW_TAG_variable) ||
7083 (tag == DW_TAG_constant) ||
7084 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085 {
Greg Clayton7f995132011-10-04 22:41:51 +00007086 DWARFDebugInfoEntry::Attributes attributes;
7087 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7088 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007089 {
Greg Clayton7f995132011-10-04 22:41:51 +00007090 const char *name = NULL;
7091 const char *mangled = NULL;
7092 Declaration decl;
7093 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007094 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007095 DWARFExpression location;
7096 bool is_external = false;
7097 bool is_artificial = false;
7098 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007099 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007100 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007101
7102 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007103 {
Greg Clayton7f995132011-10-04 22:41:51 +00007104 dw_attr_t attr = attributes.AttributeAtIndex(i);
7105 DWARFFormValue form_value;
7106 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007107 {
Greg Clayton7f995132011-10-04 22:41:51 +00007108 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007109 {
Greg Clayton7f995132011-10-04 22:41:51 +00007110 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7111 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7112 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7113 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007114 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007115 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007116 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007117 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
7118 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007119 // If we have already found a DW_AT_location attribute, ignore this attribute.
7120 if (!has_explicit_location)
7121 {
7122 location_is_const_value_data = true;
7123 // The constant value will be either a block, a data value or a string.
7124 const DataExtractor& debug_info_data = get_debug_info_data();
7125 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7126 {
7127 // Retrieve the value as a block expression.
7128 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7129 uint32_t block_length = form_value.Unsigned();
7130 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7131 }
7132 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7133 {
7134 // Retrieve the value as a data expression.
7135 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7136 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7137 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7138 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7139 }
7140 else
7141 {
7142 // Retrieve the value as a string expression.
7143 if (form_value.Form() == DW_FORM_strp)
7144 {
7145 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7146 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7147 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7148 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7149 }
7150 else
7151 {
7152 const char *str = form_value.AsCString(&debug_info_data);
7153 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7154 uint32_t string_length = strlen(str) + 1;
7155 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7156 }
7157 }
7158 }
7159 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007160 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007161 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007162 location_is_const_value_data = false;
7163 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007164 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007165 {
Greg Clayton7f995132011-10-04 22:41:51 +00007166 const DataExtractor& debug_info_data = get_debug_info_data();
7167
7168 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7169 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007170 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007171 }
7172 else
7173 {
7174 const DataExtractor& debug_loc_data = get_debug_loc_data();
7175 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7176
7177 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7178 if (loc_list_length > 0)
7179 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007180 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007181 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7182 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7183 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007184 }
7185 }
Greg Clayton7f995132011-10-04 22:41:51 +00007186 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007187
Greg Clayton7f995132011-10-04 22:41:51 +00007188 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00007189 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007190 case DW_AT_declaration:
7191 case DW_AT_description:
7192 case DW_AT_endianity:
7193 case DW_AT_segment:
7194 case DW_AT_start_scope:
7195 case DW_AT_visibility:
7196 default:
7197 case DW_AT_abstract_origin:
7198 case DW_AT_sibling:
7199 case DW_AT_specification:
7200 break;
7201 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007202 }
7203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007204
Greg Clayton7f995132011-10-04 22:41:51 +00007205 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007206 {
Greg Clayton7f995132011-10-04 22:41:51 +00007207 ValueType scope = eValueTypeInvalid;
7208
7209 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7210 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007211 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007212
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007213 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7214 // or static variable, so we have to do a little digging by
7215 // looking at the location of a varaible to see if it contains
7216 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7217 // somewhere because clang likes to combine small global variables
7218 // into the same symbol and have locations like:
7219 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7220 // So if we don't have a DW_TAG_formal_parameter, we can look at
7221 // the location to see if it contains a DW_OP_addr opcode, and
7222 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007223 if (tag == DW_TAG_formal_parameter)
7224 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007225 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007226 {
Greg Clayton96c09682012-01-04 22:56:43 +00007227 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007228 // Check if the location has a DW_OP_addr with any address value...
7229 addr_t location_has_op_addr = false;
7230 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007231 {
7232 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
7233 if (op_error)
7234 {
7235 StreamString strm;
7236 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007237 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 +00007238 }
7239 }
Greg Claytond1767f02011-12-08 02:13:16 +00007240
7241 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007242 {
Greg Claytond1767f02011-12-08 02:13:16 +00007243 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007244 {
Greg Claytond1767f02011-12-08 02:13:16 +00007245 scope = eValueTypeVariableGlobal;
7246
Greg Clayton1f746072012-08-29 21:13:06 +00007247 if (GetDebugMapSymfile ())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007248 {
Greg Claytond1767f02011-12-08 02:13:16 +00007249 // When leaving the DWARF in the .o files on darwin,
7250 // when we have a global variable that wasn't initialized,
7251 // the .o file might not have allocated a virtual
7252 // address for the global variable. In this case it will
7253 // have created a symbol for the global variable
Greg Claytonf5fc0842013-02-01 22:08:49 +00007254 // that is undefined/data and external and the value will
Greg Claytond1767f02011-12-08 02:13:16 +00007255 // be the byte size of the variable. When we do the
7256 // address map in SymbolFileDWARFDebugMap we rely on
7257 // having an address, we need to do some magic here
7258 // so we can get the correct address for our global
7259 // variable. The address for all of these entries
7260 // will be zero, and there will be an undefined symbol
7261 // in this object file, and the executable will have
7262 // a matching symbol with a good address. So here we
7263 // dig up the correct address and replace it in the
7264 // location for the variable, and set the variable's
7265 // symbol context scope to be that of the main executable
7266 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00007267 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007268 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007269
Greg Claytond1767f02011-12-08 02:13:16 +00007270 // we have a possible uninitialized extern global
7271 Symtab *symtab = m_obj_file->GetSymtab();
7272 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007273 {
Greg Claytonf5fc0842013-02-01 22:08:49 +00007274 ConstString const_name(mangled ? mangled : name);
7275 Symbol *o_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
7276 eSymbolTypeAny,
7277 Symtab::eDebugNo,
7278 Symtab::eVisibilityExtern);
Greg Claytond1767f02011-12-08 02:13:16 +00007279
Greg Claytonf5fc0842013-02-01 22:08:49 +00007280 if (o_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007281 {
Greg Claytond1767f02011-12-08 02:13:16 +00007282 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
7283 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007284 {
Greg Claytond1767f02011-12-08 02:13:16 +00007285 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7286 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7287 eSymbolTypeData,
7288 Symtab::eDebugYes,
7289 Symtab::eVisibilityExtern);
7290 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007291 {
Greg Claytone7612132012-03-07 21:03:09 +00007292 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007293 {
Greg Claytone7612132012-03-07 21:03:09 +00007294 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00007295 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007296 {
Greg Claytond1767f02011-12-08 02:13:16 +00007297 if (location.Update_DW_OP_addr (defined_addr))
7298 {
7299 symbol_context_scope = defined_symbol;
7300 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007301 }
7302 }
7303 }
7304 }
7305 }
7306 }
7307 }
7308 }
7309 }
Greg Claytond1767f02011-12-08 02:13:16 +00007310 else
7311 {
7312 scope = eValueTypeVariableStatic;
7313 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007314 }
7315 else
Greg Claytond1767f02011-12-08 02:13:16 +00007316 {
7317 scope = eValueTypeVariableLocal;
7318 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007319 }
Greg Clayton7f995132011-10-04 22:41:51 +00007320
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007321 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007322 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007323 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007324 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007325 case DW_TAG_subprogram:
7326 case DW_TAG_inlined_subroutine:
7327 case DW_TAG_lexical_block:
7328 if (sc.function)
7329 {
7330 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7331 if (symbol_context_scope == NULL)
7332 symbol_context_scope = sc.function;
7333 }
7334 break;
7335
7336 default:
7337 symbol_context_scope = sc.comp_unit;
7338 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007339 }
Greg Clayton7f995132011-10-04 22:41:51 +00007340 }
7341
Greg Clayton5cf58b92011-10-05 22:22:08 +00007342 if (symbol_context_scope)
7343 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007344 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7345 name,
7346 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007347 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007348 scope,
7349 symbol_context_scope,
7350 &decl,
7351 location,
7352 is_external,
7353 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007354
7355 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7356 }
7357 else
7358 {
7359 // Not ready to parse this variable yet. It might be a global
7360 // or static variable that is in a function scope and the function
7361 // in the symbol context wasn't filled in yet
7362 return var_sp;
7363 }
Greg Clayton7f995132011-10-04 22:41:51 +00007364 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007365 }
Greg Clayton7f995132011-10-04 22:41:51 +00007366 // Cache var_sp even if NULL (the variable was just a specification or
7367 // was missing vital information to be able to be displayed in the debugger
7368 // (missing location due to optimization, etc)) so we don't re-parse
7369 // this DIE over and over later...
7370 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007371 }
7372 return var_sp;
7373}
7374
Greg Claytonc662ec82011-06-17 22:10:16 +00007375
7376const DWARFDebugInfoEntry *
7377SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7378 dw_offset_t spec_block_die_offset,
7379 DWARFCompileUnit **result_die_cu_handle)
7380{
7381 // Give the concrete function die specified by "func_die_offset", find the
7382 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7383 // to "spec_block_die_offset"
7384 DWARFDebugInfo* info = DebugInfo();
7385
7386 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7387 if (die)
7388 {
7389 assert (*result_die_cu_handle);
7390 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7391 }
7392 return NULL;
7393}
7394
7395
7396const DWARFDebugInfoEntry *
7397SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7398 const DWARFDebugInfoEntry *die,
7399 dw_offset_t spec_block_die_offset,
7400 DWARFCompileUnit **result_die_cu_handle)
7401{
7402 if (die)
7403 {
7404 switch (die->Tag())
7405 {
7406 case DW_TAG_subprogram:
7407 case DW_TAG_inlined_subroutine:
7408 case DW_TAG_lexical_block:
7409 {
7410 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7411 {
7412 *result_die_cu_handle = dwarf_cu;
7413 return die;
7414 }
7415
7416 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7417 {
7418 *result_die_cu_handle = dwarf_cu;
7419 return die;
7420 }
7421 }
7422 break;
7423 }
7424
7425 // Give the concrete function die specified by "func_die_offset", find the
7426 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7427 // to "spec_block_die_offset"
7428 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7429 {
7430 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7431 child_die,
7432 spec_block_die_offset,
7433 result_die_cu_handle);
7434 if (result_die)
7435 return result_die;
7436 }
7437 }
7438
7439 *result_die_cu_handle = NULL;
7440 return NULL;
7441}
7442
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007443size_t
7444SymbolFileDWARF::ParseVariables
7445(
7446 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007447 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007448 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007449 const DWARFDebugInfoEntry *orig_die,
7450 bool parse_siblings,
7451 bool parse_children,
7452 VariableList* cc_variable_list
7453)
7454{
7455 if (orig_die == NULL)
7456 return 0;
7457
Greg Claytonc662ec82011-06-17 22:10:16 +00007458 VariableListSP variable_list_sp;
7459
7460 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007461 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007462 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007463 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007464 dw_tag_t tag = die->Tag();
7465
7466 // Check to see if we have already parsed this variable or constant?
7467 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007468 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007469 if (cc_variable_list)
7470 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007471 }
7472 else
7473 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007474 // We haven't already parsed it, lets do that now.
7475 if ((tag == DW_TAG_variable) ||
7476 (tag == DW_TAG_constant) ||
7477 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007478 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007479 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007480 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007481 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7482 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7483 switch (parent_tag)
7484 {
7485 case DW_TAG_compile_unit:
7486 if (sc.comp_unit != NULL)
7487 {
7488 variable_list_sp = sc.comp_unit->GetVariableList(false);
7489 if (variable_list_sp.get() == NULL)
7490 {
7491 variable_list_sp.reset(new VariableList());
7492 sc.comp_unit->SetVariableList(variable_list_sp);
7493 }
7494 }
7495 else
7496 {
Daniel Malead01b2952012-11-29 21:49:15 +00007497 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00007498 MakeUserID(sc_parent_die->GetOffset()),
7499 DW_TAG_value_to_name (parent_tag),
7500 MakeUserID(orig_die->GetOffset()),
7501 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007502 }
7503 break;
7504
7505 case DW_TAG_subprogram:
7506 case DW_TAG_inlined_subroutine:
7507 case DW_TAG_lexical_block:
7508 if (sc.function != NULL)
7509 {
7510 // Check to see if we already have parsed the variables for the given scope
7511
Greg Clayton81c22f62011-10-19 18:09:39 +00007512 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007513 if (block == NULL)
7514 {
7515 // This must be a specification or abstract origin with
7516 // a concrete block couterpart in the current function. We need
7517 // to find the concrete block so we can correctly add the
7518 // variable to it
7519 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7520 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7521 sc_parent_die->GetOffset(),
7522 &concrete_block_die_cu);
7523 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007524 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007525 }
7526
7527 if (block != NULL)
7528 {
7529 const bool can_create = false;
7530 variable_list_sp = block->GetBlockVariableList (can_create);
7531 if (variable_list_sp.get() == NULL)
7532 {
7533 variable_list_sp.reset(new VariableList());
7534 block->SetVariableList(variable_list_sp);
7535 }
7536 }
7537 }
7538 break;
7539
7540 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007541 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00007542 MakeUserID(orig_die->GetOffset()),
7543 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007544 break;
7545 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007546 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007547
7548 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007549 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007550 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7551 if (var_sp)
7552 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007553 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007554 if (cc_variable_list)
7555 cc_variable_list->AddVariableIfUnique (var_sp);
7556 ++vars_added;
7557 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007558 }
7559 }
7560 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007561
7562 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7563
7564 if (!skip_children && parse_children && die->HasChildren())
7565 {
7566 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7567 }
7568
7569 if (parse_siblings)
7570 die = die->GetSibling();
7571 else
7572 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007573 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007574 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007575}
7576
7577//------------------------------------------------------------------
7578// PluginInterface protocol
7579//------------------------------------------------------------------
7580const char *
7581SymbolFileDWARF::GetPluginName()
7582{
7583 return "SymbolFileDWARF";
7584}
7585
7586const char *
7587SymbolFileDWARF::GetShortPluginName()
7588{
7589 return GetPluginNameStatic();
7590}
7591
7592uint32_t
7593SymbolFileDWARF::GetPluginVersion()
7594{
7595 return 1;
7596}
7597
7598void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007599SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7600{
7601 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7602 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7603 if (clang_type)
7604 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7605}
7606
7607void
7608SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7609{
7610 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7611 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7612 if (clang_type)
7613 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7614}
7615
Greg Claytona2721472011-06-25 00:44:06 +00007616void
Sean Callanancc427fa2011-07-30 02:42:06 +00007617SymbolFileDWARF::DumpIndexes ()
7618{
7619 StreamFile s(stdout, false);
7620
7621 s.Printf ("DWARF index for (%s) '%s/%s':",
7622 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7623 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7624 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7625 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7626 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7627 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7628 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7629 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7630 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7631 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7632 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7633}
7634
7635void
7636SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7637 const char *name,
7638 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007639{
Sean Callanancc427fa2011-07-30 02:42:06 +00007640 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007641
7642 if (iter == m_decl_ctx_to_die.end())
7643 return;
7644
Greg Claytoncb5860a2011-10-13 23:49:28 +00007645 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007646 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007647 const DWARFDebugInfoEntry *context_die = *pos;
7648
7649 if (!results)
7650 return;
7651
7652 DWARFDebugInfo* info = DebugInfo();
7653
7654 DIEArray die_offsets;
7655
7656 DWARFCompileUnit* dwarf_cu = NULL;
7657 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007658
7659 if (m_using_apple_tables)
7660 {
7661 if (m_apple_types_ap.get())
7662 m_apple_types_ap->FindByName (name, die_offsets);
7663 }
7664 else
7665 {
7666 if (!m_indexed)
7667 Index ();
7668
7669 m_type_index.Find (ConstString(name), die_offsets);
7670 }
7671
Greg Clayton220a0072011-12-09 08:48:30 +00007672 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007673
7674 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007675 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007676 for (size_t i = 0; i < num_matches; ++i)
7677 {
7678 const dw_offset_t die_offset = die_offsets[i];
7679 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007680
Greg Claytoncb5860a2011-10-13 23:49:28 +00007681 if (die->GetParent() != context_die)
7682 continue;
7683
7684 Type *matching_type = ResolveType (dwarf_cu, die);
7685
Greg Clayton42ce2f32011-12-12 21:50:19 +00007686 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007687 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7688
7689 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7690 {
7691 clang::TagDecl *tag_decl = tag_type->getDecl();
7692 results->push_back(tag_decl);
7693 }
7694 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7695 {
7696 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7697 results->push_back(typedef_decl);
7698 }
Greg Claytona2721472011-06-25 00:44:06 +00007699 }
7700 }
7701 }
7702}
7703
7704void
7705SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007706 const clang::DeclContext *decl_context,
7707 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007708 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7709{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007710
7711 switch (decl_context->getDeclKind())
7712 {
7713 case clang::Decl::Namespace:
7714 case clang::Decl::TranslationUnit:
7715 {
7716 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7717 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7718 }
7719 break;
7720 default:
7721 break;
7722 }
Greg Claytona2721472011-06-25 00:44:06 +00007723}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007724
7725bool
7726SymbolFileDWARF::LayoutRecordType (void *baton,
7727 const clang::RecordDecl *record_decl,
7728 uint64_t &size,
7729 uint64_t &alignment,
7730 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7731 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7732 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7733{
7734 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7735 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7736}
7737
7738
7739bool
7740SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7741 uint64_t &bit_size,
7742 uint64_t &alignment,
7743 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7744 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7745 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7746{
7747 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7748 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7749 bool success = false;
7750 base_offsets.clear();
7751 vbase_offsets.clear();
7752 if (pos != m_record_decl_to_layout_map.end())
7753 {
7754 bit_size = pos->second.bit_size;
7755 alignment = pos->second.alignment;
7756 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007757 base_offsets.swap (pos->second.base_offsets);
7758 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007759 m_record_decl_to_layout_map.erase(pos);
7760 success = true;
7761 }
7762 else
7763 {
7764 bit_size = 0;
7765 alignment = 0;
7766 field_offsets.clear();
7767 }
7768
7769 if (log)
7770 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00007771 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
Greg Claytoncaab74e2012-01-28 00:48:57 +00007772 record_decl,
7773 bit_size,
7774 alignment,
7775 (uint32_t)field_offsets.size(),
7776 (uint32_t)base_offsets.size(),
7777 (uint32_t)vbase_offsets.size(),
7778 success);
7779 return success;
7780}
7781
7782
Greg Clayton1f746072012-08-29 21:13:06 +00007783SymbolFileDWARFDebugMap *
7784SymbolFileDWARF::GetDebugMapSymfile ()
7785{
7786 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7787 {
7788 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7789 if (module_sp)
7790 {
7791 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7792 if (sym_vendor)
7793 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7794 }
7795 }
7796 return m_debug_map_symfile;
7797}
7798
Greg Claytoncaab74e2012-01-28 00:48:57 +00007799