blob: 94cc8385ac8b962cf3d40ae6f3f9806183c65f63 [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
Greg Clayton9422dd62013-03-04 21:46:16 +0000894 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
897 func_sp.reset(new Function (sc.comp_unit,
898 MakeUserID(func_user_id), // UserID is the DIE offset
899 MakeUserID(func_user_id),
900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
913 }
914 return NULL;
915}
916
Greg Clayton9422dd62013-03-04 21:46:16 +0000917bool
918SymbolFileDWARF::FixupAddress (Address &addr)
919{
920 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
921 if (debug_map_symfile)
922 {
923 return debug_map_symfile->LinkOSOAddress(addr);
924 }
925 // This is a normal DWARF file, no address fixups need to happen
926 return true;
927}
Greg Clayton1f746072012-08-29 21:13:06 +0000928lldb::LanguageType
929SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
930{
931 assert (sc.comp_unit);
932 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
933 if (dwarf_cu)
934 {
935 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000936 if (die)
937 {
938 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
939 if (language)
940 return (lldb::LanguageType)language;
941 }
Greg Clayton1f746072012-08-29 21:13:06 +0000942 }
943 return eLanguageTypeUnknown;
944}
945
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946size_t
947SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
948{
949 assert (sc.comp_unit);
950 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000951 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000952 if (dwarf_cu)
953 {
954 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000955 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000957 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958 {
959 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000960 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 {
962 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
963 ++functions_added;
964 }
965 }
966 //FixupTypes();
967 }
968 return functions_added;
969}
970
971bool
972SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
973{
974 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000975 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000976 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000978 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979
Greg Claytonda2455b2012-11-01 17:28:37 +0000980 if (cu_die)
981 {
982 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
983 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 +0000984
Greg Claytonda2455b2012-11-01 17:28:37 +0000985 // All file indexes in DWARF are one based and a file of index zero is
986 // supposed to be the compile unit itself.
987 support_files.Append (*sc.comp_unit);
988
989 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
990 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991 }
992 return false;
993}
994
995struct ParseDWARFLineTableCallbackInfo
996{
997 LineTable* line_table;
Greg Clayton9422dd62013-03-04 21:46:16 +0000998 std::auto_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999};
1000
1001//----------------------------------------------------------------------
1002// ParseStatementTableCallback
1003//----------------------------------------------------------------------
1004static void
1005ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1006{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1008 {
1009 // Just started parsing the line table
1010 }
1011 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1012 {
1013 // Done parsing line table, nothing to do for the cleanup
1014 }
1015 else
1016 {
1017 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001018 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019
Greg Clayton9422dd62013-03-04 21:46:16 +00001020 // If this is our first time here, we need to create a
1021 // sequence container.
1022 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001024 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1025 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001027 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1028 state.address,
1029 state.line,
1030 state.column,
1031 state.file,
1032 state.is_stmt,
1033 state.basic_block,
1034 state.prologue_end,
1035 state.epilogue_begin,
1036 state.end_sequence);
1037 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001039 // First, put the current sequence into the line table.
1040 line_table->InsertSequence(info->sequence_ap.get());
1041 // Then, empty it to prepare for the next sequence.
1042 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 }
1045}
1046
1047bool
1048SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1049{
1050 assert (sc.comp_unit);
1051 if (sc.comp_unit->GetLineTable() != NULL)
1052 return true;
1053
Greg Clayton1f746072012-08-29 21:13:06 +00001054 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055 if (dwarf_cu)
1056 {
1057 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001058 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001060 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1061 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001063 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1064 if (line_table_ap.get())
1065 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001066 ParseDWARFLineTableCallbackInfo info;
1067 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001068 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001069 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001070 if (m_debug_map_symfile)
1071 {
1072 // We have an object file that has a line table with addresses
1073 // that are not linked. We need to link the line table and convert
1074 // the addresses that are relative to the .o file into addresses
1075 // for the main executable.
1076 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1077 }
1078 else
1079 {
1080 sc.comp_unit->SetLineTable(line_table_ap.release());
1081 return true;
1082 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 }
1085 }
1086 }
1087 return false;
1088}
1089
1090size_t
1091SymbolFileDWARF::ParseFunctionBlocks
1092(
1093 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001094 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001095 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001096 const DWARFDebugInfoEntry *die,
1097 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001098 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099)
1100{
1101 size_t blocks_added = 0;
1102 while (die != NULL)
1103 {
1104 dw_tag_t tag = die->Tag();
1105
1106 switch (tag)
1107 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001109 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 case DW_TAG_lexical_block:
1111 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001112 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001113 if (tag == DW_TAG_subprogram)
1114 {
1115 // Skip any DW_TAG_subprogram DIEs that are inside
1116 // of a normal or inlined functions. These will be
1117 // parsed on their own as separate entities.
1118
1119 if (depth > 0)
1120 break;
1121
1122 block = parent_block;
1123 }
1124 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001125 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001126 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001127 parent_block->AddChild(block_sp);
1128 block = block_sp.get();
1129 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001130 DWARFDebugRanges::RangeList ranges;
1131 const char *name = NULL;
1132 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 int decl_file = 0;
1135 int decl_line = 0;
1136 int decl_column = 0;
1137 int call_file = 0;
1138 int call_line = 0;
1139 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001140 if (die->GetDIENamesAndRanges (this,
1141 dwarf_cu,
1142 name,
1143 mangled_name,
1144 ranges,
1145 decl_file, decl_line, decl_column,
1146 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 {
1148 if (tag == DW_TAG_subprogram)
1149 {
1150 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001151 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001153 else if (tag == DW_TAG_inlined_subroutine)
1154 {
1155 // We get called here for inlined subroutines in two ways.
1156 // The first time is when we are making the Function object
1157 // for this inlined concrete instance. Since we're creating a top level block at
1158 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1159 // adjust the containing address.
1160 // The second time is when we are parsing the blocks inside the function that contains
1161 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1162 // function the offset will be for that function.
1163 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1164 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001165 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001166 }
1167 }
1168
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001169 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170
1171 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1172 {
1173 std::auto_ptr<Declaration> decl_ap;
1174 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001175 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1176 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177
1178 std::auto_ptr<Declaration> call_ap;
1179 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001180 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1181 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001183 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 }
1185
1186 ++blocks_added;
1187
Greg Claytondd7feaf2011-08-12 17:54:33 +00001188 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001190 blocks_added += ParseFunctionBlocks (sc,
1191 block,
1192 dwarf_cu,
1193 die->GetFirstChild(),
1194 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001195 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 }
1197 }
1198 }
1199 break;
1200 default:
1201 break;
1202 }
1203
Greg Claytondd7feaf2011-08-12 17:54:33 +00001204 // Only parse siblings of the block if we are not at depth zero. A depth
1205 // of zero indicates we are currently parsing the top level
1206 // DW_TAG_subprogram DIE
1207
1208 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001210 else
1211 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 return blocks_added;
1214}
1215
Greg Claytonf0705c82011-10-22 03:33:13 +00001216bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001217SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1218 const DWARFDebugInfoEntry *die,
1219 ClangASTContext::TemplateParameterInfos &template_param_infos)
1220{
1221 const dw_tag_t tag = die->Tag();
1222
1223 switch (tag)
1224 {
1225 case DW_TAG_template_type_parameter:
1226 case DW_TAG_template_value_parameter:
1227 {
1228 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1229
1230 DWARFDebugInfoEntry::Attributes attributes;
1231 const size_t num_attributes = die->GetAttributes (this,
1232 dwarf_cu,
1233 fixed_form_sizes,
1234 attributes);
1235 const char *name = NULL;
1236 Type *lldb_type = NULL;
1237 clang_type_t clang_type = NULL;
1238 uint64_t uval64 = 0;
1239 bool uval64_valid = false;
1240 if (num_attributes > 0)
1241 {
1242 DWARFFormValue form_value;
1243 for (size_t i=0; i<num_attributes; ++i)
1244 {
1245 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1246
1247 switch (attr)
1248 {
1249 case DW_AT_name:
1250 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1251 name = form_value.AsCString(&get_debug_str_data());
1252 break;
1253
1254 case DW_AT_type:
1255 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1256 {
1257 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1258 lldb_type = ResolveTypeUID(type_die_offset);
1259 if (lldb_type)
1260 clang_type = lldb_type->GetClangForwardType();
1261 }
1262 break;
1263
1264 case DW_AT_const_value:
1265 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1266 {
1267 uval64_valid = true;
1268 uval64 = form_value.Unsigned();
1269 }
1270 break;
1271 default:
1272 break;
1273 }
1274 }
1275
1276 if (name && lldb_type && clang_type)
1277 {
1278 bool is_signed = false;
1279 template_param_infos.names.push_back(name);
1280 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1281 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1282 {
1283 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001284 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1285 llvm::APSInt(apint),
1286 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001287 }
1288 else
1289 {
1290 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1291 }
1292 }
1293 else
1294 {
1295 return false;
1296 }
1297
1298 }
1299 }
1300 return true;
1301
1302 default:
1303 break;
1304 }
1305 return false;
1306}
1307
1308bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001309SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1310 const DWARFDebugInfoEntry *parent_die,
1311 ClangASTContext::TemplateParameterInfos &template_param_infos)
1312{
1313
1314 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001315 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001316
Greg Claytonf0705c82011-10-22 03:33:13 +00001317 Args template_parameter_names;
1318 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1319 die != NULL;
1320 die = die->GetSibling())
1321 {
1322 const dw_tag_t tag = die->Tag();
1323
1324 switch (tag)
1325 {
1326 case DW_TAG_template_type_parameter:
1327 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001328 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001329 break;
1330
1331 default:
1332 break;
1333 }
1334 }
1335 if (template_param_infos.args.empty())
1336 return false;
1337 return template_param_infos.args.size() == template_param_infos.names.size();
1338}
1339
1340clang::ClassTemplateDecl *
1341SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001342 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001343 const char *parent_name,
1344 int tag_decl_kind,
1345 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1346{
1347 if (template_param_infos.IsValid())
1348 {
1349 std::string template_basename(parent_name);
1350 template_basename.erase (template_basename.find('<'));
1351 ClangASTContext &ast = GetClangASTContext();
1352
1353 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001354 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001355 template_basename.c_str(),
1356 tag_decl_kind,
1357 template_param_infos);
1358 }
1359 return NULL;
1360}
1361
Sean Callanana0b80ab2012-06-04 22:28:05 +00001362class SymbolFileDWARF::DelayedAddObjCClassProperty
1363{
1364public:
1365 DelayedAddObjCClassProperty
1366 (
1367 clang::ASTContext *ast,
1368 lldb::clang_type_t class_opaque_type,
1369 const char *property_name,
1370 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1371 clang::ObjCIvarDecl *ivar_decl,
1372 const char *property_setter_name,
1373 const char *property_getter_name,
1374 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001375 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001376 ) :
1377 m_ast (ast),
1378 m_class_opaque_type (class_opaque_type),
1379 m_property_name (property_name),
1380 m_property_opaque_type (property_opaque_type),
1381 m_ivar_decl (ivar_decl),
1382 m_property_setter_name (property_setter_name),
1383 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001384 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001385 {
Jim Ingham379397632012-10-27 02:54:13 +00001386 if (metadata != NULL)
1387 {
1388 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001389 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001390 }
1391 }
1392
1393 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1394 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001395 *this = rhs;
1396 }
1397
1398 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1399 {
Jim Ingham379397632012-10-27 02:54:13 +00001400 m_ast = rhs.m_ast;
1401 m_class_opaque_type = rhs.m_class_opaque_type;
1402 m_property_name = rhs.m_property_name;
1403 m_property_opaque_type = rhs.m_property_opaque_type;
1404 m_ivar_decl = rhs.m_ivar_decl;
1405 m_property_setter_name = rhs.m_property_setter_name;
1406 m_property_getter_name = rhs.m_property_getter_name;
1407 m_property_attributes = rhs.m_property_attributes;
1408
1409 if (rhs.m_metadata_ap.get())
1410 {
1411 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001412 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001413 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001414 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001415 }
1416
1417 bool Finalize() const
1418 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001419 return ClangASTContext::AddObjCClassProperty (m_ast,
1420 m_class_opaque_type,
1421 m_property_name,
1422 m_property_opaque_type,
1423 m_ivar_decl,
1424 m_property_setter_name,
1425 m_property_getter_name,
1426 m_property_attributes,
1427 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001428 }
1429private:
1430 clang::ASTContext *m_ast;
1431 lldb::clang_type_t m_class_opaque_type;
1432 const char *m_property_name;
1433 lldb::clang_type_t m_property_opaque_type;
1434 clang::ObjCIvarDecl *m_ivar_decl;
1435 const char *m_property_setter_name;
1436 const char *m_property_getter_name;
1437 uint32_t m_property_attributes;
Greg Claytonc4ffd662013-03-08 01:37:30 +00001438 std::auto_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001439};
1440
Sean Callananfaa0bb32012-12-05 23:37:14 +00001441struct BitfieldInfo
1442{
1443 uint64_t bit_size;
1444 uint64_t bit_offset;
1445
1446 BitfieldInfo () :
1447 bit_size (LLDB_INVALID_ADDRESS),
1448 bit_offset (LLDB_INVALID_ADDRESS)
1449 {
1450 }
1451
1452 bool IsValid ()
1453 {
1454 return (bit_size != LLDB_INVALID_ADDRESS) &&
1455 (bit_offset != LLDB_INVALID_ADDRESS);
1456 }
1457};
1458
Greg Claytonc4ffd662013-03-08 01:37:30 +00001459
1460bool
1461SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1462 const DWARFDebugInfoEntry *parent_die)
1463{
1464 if (parent_die)
1465 {
1466 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1467 {
1468 dw_tag_t tag = die->Tag();
1469 bool check_virtuality = false;
1470 switch (tag)
1471 {
1472 case DW_TAG_inheritance:
1473 case DW_TAG_subprogram:
1474 check_virtuality = true;
1475 break;
1476 default:
1477 break;
1478 }
1479 if (check_virtuality)
1480 {
1481 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1482 return true;
1483 }
1484 }
1485 }
1486 return false;
1487}
1488
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489size_t
1490SymbolFileDWARF::ParseChildMembers
1491(
1492 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001493 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001495 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001496 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1498 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001499 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001500 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001501 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001502 bool &is_a_class,
1503 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504)
1505{
1506 if (parent_die == NULL)
1507 return 0;
1508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 size_t count = 0;
1510 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001511 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001512 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001513 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001514
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1516 {
1517 dw_tag_t tag = die->Tag();
1518
1519 switch (tag)
1520 {
1521 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001522 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 {
1524 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001525 const size_t num_attributes = die->GetAttributes (this,
1526 dwarf_cu,
1527 fixed_form_sizes,
1528 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001529 if (num_attributes > 0)
1530 {
1531 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001532 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001533 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001534 const char *prop_name = NULL;
1535 const char *prop_getter_name = NULL;
1536 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001537 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001538
1539
Greg Clayton24739922010-10-13 03:15:28 +00001540 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001542 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001543 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544 size_t byte_size = 0;
1545 size_t bit_offset = 0;
1546 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001547 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001548 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001549 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001550 {
1551 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1552 DWARFFormValue form_value;
1553 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1554 {
1555 switch (attr)
1556 {
1557 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1558 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1559 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1560 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1561 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1562 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1563 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1564 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1565 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001566 if (form_value.BlockData())
1567 {
1568 Value initialValue(0);
1569 Value memberOffset(0);
1570 const DataExtractor& debug_info_data = get_debug_info_data();
1571 uint32_t block_length = form_value.Unsigned();
1572 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1573 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1574 NULL, // clang::ASTContext *
1575 NULL, // ClangExpressionVariableList *
1576 NULL, // ClangExpressionDeclMap *
1577 NULL, // RegisterContext *
1578 debug_info_data,
1579 block_offset,
1580 block_length,
1581 eRegisterKindDWARF,
1582 &initialValue,
1583 memberOffset,
1584 NULL))
1585 {
1586 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1587 }
1588 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589 break;
1590
Greg Clayton8cf05932010-07-22 18:30:50 +00001591 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001592 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001593 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1594 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1595 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1596 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001597 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001598
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001600 case DW_AT_declaration:
1601 case DW_AT_description:
1602 case DW_AT_mutable:
1603 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604 case DW_AT_sibling:
1605 break;
1606 }
1607 }
1608 }
Sean Callanana6582262012-04-05 00:12:52 +00001609
1610 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001611 {
Sean Callanana6582262012-04-05 00:12:52 +00001612 ConstString fixed_getter;
1613 ConstString fixed_setter;
1614
1615 // Check if the property getter/setter were provided as full
1616 // names. We want basenames, so we extract them.
1617
1618 if (prop_getter_name && prop_getter_name[0] == '-')
1619 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001620 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1621 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001622 }
1623
1624 if (prop_setter_name && prop_setter_name[0] == '-')
1625 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001626 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1627 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001628 }
1629
1630 // If the names haven't been provided, they need to be
1631 // filled in.
1632
1633 if (!prop_getter_name)
1634 {
1635 prop_getter_name = prop_name;
1636 }
1637 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1638 {
1639 StreamString ss;
1640
1641 ss.Printf("set%c%s:",
1642 toupper(prop_name[0]),
1643 &prop_name[1]);
1644
1645 fixed_setter.SetCString(ss.GetData());
1646 prop_setter_name = fixed_setter.GetCString();
1647 }
Sean Callanan751aac62012-03-29 19:07:06 +00001648 }
1649
1650 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001651 // represents fields that are references with bad byte size
1652 // and bit size/offset information such as:
1653 //
1654 // DW_AT_byte_size( 0x00 )
1655 // DW_AT_bit_size( 0x40 )
1656 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1657 //
1658 // So check the bit offset to make sure it is sane, and if
1659 // the values are not sane, remove them. If we don't do this
1660 // then we will end up with a crash if we try to use this
1661 // type in an expression when clang becomes unhappy with its
1662 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001663
Greg Clayton44953932011-10-25 01:25:35 +00001664 if (bit_offset > 128)
1665 {
1666 bit_size = 0;
1667 bit_offset = 0;
1668 }
1669
1670 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001671 if (class_language == eLanguageTypeObjC ||
1672 class_language == eLanguageTypeObjC_plus_plus)
1673 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001674
1675 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1676 {
1677 // Not all compilers will mark the vtable pointer
1678 // member as artificial (llvm-gcc). We can't have
1679 // the virtual members in our classes otherwise it
1680 // throws off all child offsets since we end up
1681 // having and extra pointer sized member in our
1682 // class layouts.
1683 is_artificial = true;
1684 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685
Greg Claytone528efd72013-02-26 23:45:18 +00001686 // Skip static members
1687 if (is_external && member_byte_offset == UINT32_MAX)
1688 break;
1689
Greg Clayton24739922010-10-13 03:15:28 +00001690 if (is_artificial == false)
1691 {
1692 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001693
Jim Inghame3ae82a2011-11-12 01:36:43 +00001694 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001695 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001696 {
Sean Callanan751aac62012-03-29 19:07:06 +00001697 if (member_type)
1698 {
1699 if (accessibility == eAccessNone)
1700 accessibility = default_accessibility;
1701 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001702
1703 BitfieldInfo this_field_info;
1704
1705 this_field_info.bit_size = bit_size;
1706
1707 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001708 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001709 /////////////////////////////////////////////////////////////
1710 // How to locate a field given the DWARF debug information
1711 //
1712 // AT_byte_size indicates the size of the word in which the
1713 // bit offset must be interpreted.
1714 //
1715 // AT_data_member_location indicates the byte offset of the
1716 // word from the base address of the structure.
1717 //
1718 // AT_bit_offset indicates how many bits into the word
1719 // (according to the host endianness) the low-order bit of
1720 // the field starts. AT_bit_offset can be negative.
1721 //
1722 // AT_bit_size indicates the size of the field in bits.
1723 /////////////////////////////////////////////////////////////
1724
1725 this_field_info.bit_offset = 0;
1726
1727 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1728
1729 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1730 {
1731 this_field_info.bit_offset += byte_size * 8;
1732 this_field_info.bit_offset -= (bit_offset + bit_size);
1733 }
1734 else
1735 {
1736 this_field_info.bit_offset += bit_offset;
1737 }
1738 }
1739
1740 // If the member to be emitted did not start on a character boundary and there is
1741 // empty space between the last field and this one, then we need to emit an
1742 // anonymous member filling up the space up to its start. There are three cases
1743 // here:
1744 //
1745 // 1 If the previous member ended on a character boundary, then we can emit an
1746 // anonymous member starting at the most recent character boundary.
1747 //
1748 // 2 If the previous member did not end on a character boundary and the distance
1749 // from the end of the previous member to the current member is less than a
1750 // word width, then we can emit an anonymous member starting right after the
1751 // previous member and right before this member.
1752 //
1753 // 3 If the previous member did not end on a character boundary and the distance
1754 // from the end of the previous member to the current member is greater than
1755 // or equal a word width, then we act as in Case 1.
1756
1757 const uint64_t character_width = 8;
1758 const uint64_t word_width = 32;
1759
1760 if (this_field_info.IsValid())
1761 {
1762 // Objective-C has invalid DW_AT_bit_offset values in older versions
1763 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001764 // if we have a new enough clang.
1765 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001766
Greg Clayton37c36e42012-11-27 00:59:26 +00001767 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1768 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1769
1770 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001771 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001772 BitfieldInfo anon_field_info;
1773
1774 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001775 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001776 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001777
Sean Callananfaa0bb32012-12-05 23:37:14 +00001778 if (last_field_info.IsValid())
1779 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001780
Sean Callananfaa0bb32012-12-05 23:37:14 +00001781 if (this_field_info.bit_offset != last_field_end)
1782 {
1783 if (((last_field_end % character_width) == 0) || // case 1
1784 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1785 {
1786 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1787 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1788 }
1789 else // case 2
1790 {
1791 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1792 anon_field_info.bit_offset = last_field_end;
1793 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001794 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001795 }
1796
Sean Callananfaa0bb32012-12-05 23:37:14 +00001797 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001798 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001799 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1800 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001801 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001802 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001803 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001804
Sean Callananfaa0bb32012-12-05 23:37:14 +00001805 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001806 }
1807 }
1808 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001809
Sean Callananfa3ab452012-12-14 00:54:13 +00001810 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1811
1812 {
1813 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1814 // If the current field is at the end of the structure, then there is definitely no room for extra
1815 // elements and we override the type to array[0].
1816
1817 clang_type_t member_array_element_type;
1818 uint64_t member_array_size;
1819 bool member_array_is_incomplete;
1820
1821 if (GetClangASTContext().IsArrayType(member_clang_type,
1822 &member_array_element_type,
1823 &member_array_size,
1824 &member_array_is_incomplete) &&
1825 !member_array_is_incomplete)
1826 {
1827 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1828
1829 if (member_byte_offset >= parent_byte_size)
1830 {
1831 if (member_array_size != 1)
1832 {
1833 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,
1834 MakeUserID(die->GetOffset()),
1835 name,
1836 encoding_uid,
1837 MakeUserID(parent_die->GetOffset()));
1838 }
1839
1840 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0);
1841 }
1842 }
1843 }
1844
Greg Clayton88bc7f32012-11-06 00:20:41 +00001845 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001846 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001847 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001848 accessibility,
1849 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001850
Jim Ingham379397632012-10-27 02:54:13 +00001851 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001852
1853 if (this_field_info.IsValid())
1854 {
1855 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1856 last_field_info = this_field_info;
1857 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001858 }
1859 else
1860 {
Sean Callanan751aac62012-03-29 19:07:06 +00001861 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001862 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 +00001863 MakeUserID(die->GetOffset()),
1864 name,
1865 encoding_uid);
1866 else
Daniel Malead01b2952012-11-29 21:49:15 +00001867 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 +00001868 MakeUserID(die->GetOffset()),
1869 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001870 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001871 }
Sean Callanan751aac62012-03-29 19:07:06 +00001872
Jim Inghame3ae82a2011-11-12 01:36:43 +00001873 if (prop_name != NULL)
1874 {
Sean Callanan751aac62012-03-29 19:07:06 +00001875 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001876
Sean Callanan751aac62012-03-29 19:07:06 +00001877 if (field_decl)
1878 {
1879 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1880 assert (ivar_decl != NULL);
1881 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001882
Jim Ingham379397632012-10-27 02:54:13 +00001883 ClangASTMetadata metadata;
1884 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001885 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1886 class_clang_type,
1887 prop_name,
1888 member_type->GetClangLayoutType(),
1889 ivar_decl,
1890 prop_setter_name,
1891 prop_getter_name,
1892 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001893 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001894
Sean Callananad880762012-04-18 01:06:17 +00001895 if (ivar_decl)
Jim Ingham379397632012-10-27 02:54:13 +00001896 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001897 }
Greg Clayton24739922010-10-13 03:15:28 +00001898 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001900 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901 }
1902 break;
1903
1904 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001905 // Let the type parsing code handle this one for us.
1906 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 break;
1908
1909 case DW_TAG_inheritance:
1910 {
1911 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001912 if (default_accessibility == eAccessNone)
1913 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001914 // TODO: implement DW_TAG_inheritance type parsing
1915 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001916 const size_t num_attributes = die->GetAttributes (this,
1917 dwarf_cu,
1918 fixed_form_sizes,
1919 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 if (num_attributes > 0)
1921 {
1922 Declaration decl;
1923 DWARFExpression location;
1924 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001925 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926 bool is_virtual = false;
1927 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001928 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 uint32_t i;
1930 for (i=0; i<num_attributes; ++i)
1931 {
1932 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1933 DWARFFormValue form_value;
1934 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1935 {
1936 switch (attr)
1937 {
1938 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1939 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1940 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1941 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001942 case DW_AT_data_member_location:
1943 if (form_value.BlockData())
1944 {
1945 Value initialValue(0);
1946 Value memberOffset(0);
1947 const DataExtractor& debug_info_data = get_debug_info_data();
1948 uint32_t block_length = form_value.Unsigned();
1949 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1950 if (DWARFExpression::Evaluate (NULL,
1951 NULL,
1952 NULL,
1953 NULL,
1954 NULL,
1955 debug_info_data,
1956 block_offset,
1957 block_length,
1958 eRegisterKindDWARF,
1959 &initialValue,
1960 memberOffset,
1961 NULL))
1962 {
1963 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1964 }
1965 }
1966 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001967
1968 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001969 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970 break;
1971
1972 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1973 default:
1974 case DW_AT_sibling:
1975 break;
1976 }
1977 }
1978 }
1979
Greg Clayton526e5af2010-11-13 03:52:47 +00001980 Type *base_class_type = ResolveTypeUID(encoding_uid);
1981 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001982
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001983 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1984 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001985 if (class_language == eLanguageTypeObjC)
1986 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001987 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001988 }
1989 else
1990 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001991 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001992 accessibility,
1993 is_virtual,
1994 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00001995
1996 if (is_virtual)
1997 {
1998 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
1999 clang::CharUnits::fromQuantity(member_byte_offset)));
2000 }
2001 else
2002 {
2003 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2004 clang::CharUnits::fromQuantity(member_byte_offset)));
2005 }
Greg Clayton9e409562010-07-28 02:04:09 +00002006 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007 }
2008 }
2009 break;
2010
2011 default:
2012 break;
2013 }
2014 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002015
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 return count;
2017}
2018
2019
2020clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002021SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022{
2023 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002024 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025 {
2026 DWARFCompileUnitSP cu_sp;
2027 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2028 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002029 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002030 }
2031 return NULL;
2032}
2033
2034clang::DeclContext*
2035SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2036{
Greg Clayton81c22f62011-10-19 18:09:39 +00002037 if (UserIDMatches(type_uid))
2038 return GetClangDeclContextForDIEOffset (sc, type_uid);
2039 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040}
2041
2042Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002043SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002044{
Greg Clayton81c22f62011-10-19 18:09:39 +00002045 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002046 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002047 DWARFDebugInfo* debug_info = DebugInfo();
2048 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002049 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002050 DWARFCompileUnitSP cu_sp;
2051 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002052 const bool assert_not_being_parsed = true;
2053 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055 }
2056 return NULL;
2057}
2058
Greg Claytoncab36a32011-12-08 05:16:30 +00002059Type*
2060SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002061{
Greg Claytoncab36a32011-12-08 05:16:30 +00002062 if (die != NULL)
2063 {
Greg Clayton3bffb082011-12-10 02:15:28 +00002064 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
2065 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002066 GetObjectFile()->GetModule()->LogMessage (log.get(),
2067 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2068 die->GetOffset(),
2069 DW_TAG_value_to_name(die->Tag()),
2070 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002071
Greg Claytoncab36a32011-12-08 05:16:30 +00002072 // We might be coming in in the middle of a type tree (a class
2073 // withing a class, an enum within a class), so parse any needed
2074 // parent DIEs before we get to this one...
2075 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2076 switch (decl_ctx_die->Tag())
2077 {
2078 case DW_TAG_structure_type:
2079 case DW_TAG_union_type:
2080 case DW_TAG_class_type:
2081 {
2082 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002083 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002084 GetObjectFile()->GetModule()->LogMessage (log.get(),
2085 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2086 die->GetOffset(),
2087 DW_TAG_value_to_name(die->Tag()),
2088 die->GetName(this, cu),
2089 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002090//
2091// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2092// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2093// {
2094// if (log)
2095// GetObjectFile()->GetModule()->LogMessage (log.get(),
2096// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2097// die->GetOffset(),
2098// DW_TAG_value_to_name(die->Tag()),
2099// die->GetName(this, cu),
2100// decl_ctx_die->GetOffset());
2101// // Ask the type to complete itself if it already hasn't since if we
2102// // want a function (method or static) from a class, the class must
2103// // create itself and add it's own methods and class functions.
2104// if (parent_type)
2105// parent_type->GetClangFullType();
2106// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002107 }
2108 break;
2109
2110 default:
2111 break;
2112 }
2113 return ResolveType (cu, die);
2114 }
2115 return NULL;
2116}
2117
Greg Clayton6beaaa62011-01-17 03:46:26 +00002118// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2119// SymbolFileDWARF objects to detect if this DWARF file is the one that
2120// can resolve a clang_type.
2121bool
2122SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2123{
2124 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2125 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2126 return die != NULL;
2127}
2128
2129
Greg Clayton1be10fc2010-09-29 01:12:09 +00002130lldb::clang_type_t
2131SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2132{
2133 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002134 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2135 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002136 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002137 {
2138 // We have already resolved this type...
2139 return clang_type;
2140 }
2141 // Once we start resolving this type, remove it from the forward declaration
2142 // map in case anyone child members or other types require this type to get resolved.
2143 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2144 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002145 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002146
Greg Clayton1be10fc2010-09-29 01:12:09 +00002147
Greg Clayton85ae2e12011-10-18 23:36:41 +00002148 // Disable external storage for this type so we don't get anymore
2149 // clang::ExternalASTSource queries for this type.
2150 ClangASTContext::SetHasExternalStorage (clang_type, false);
2151
Greg Clayton450e3f32010-10-12 02:24:53 +00002152 DWARFDebugInfo* debug_info = DebugInfo();
2153
Greg Clayton53eb1c22012-04-02 22:59:12 +00002154 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002155 Type *type = m_die_to_type.lookup (die);
2156
2157 const dw_tag_t tag = die->Tag();
2158
Greg Claytonbaf95da2012-03-30 23:50:54 +00002159 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002160 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002161 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002162 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002163 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002164 MakeUserID(die->GetOffset()),
2165 DW_TAG_value_to_name(tag),
2166 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002167
Greg Claytonbaf95da2012-03-30 23:50:54 +00002168 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002169 assert (clang_type);
2170 DWARFDebugInfoEntry::Attributes attributes;
2171
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002172 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002173
2174 switch (tag)
2175 {
2176 case DW_TAG_structure_type:
2177 case DW_TAG_union_type:
2178 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002179 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002180 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002181
Greg Clayton1be10fc2010-09-29 01:12:09 +00002182 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002183 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002184 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002185
Sean Callanan77a1fd32012-02-27 20:07:01 +00002186 LanguageType class_language = eLanguageTypeUnknown;
2187 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2188 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002189 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002190 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002191 // For objective C we don't start the definition when
2192 // the class is created.
2193 ast.StartTagDeclarationDefinition (clang_type);
2194 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002195
2196 int tag_decl_kind = -1;
2197 AccessType default_accessibility = eAccessNone;
2198 if (tag == DW_TAG_structure_type)
2199 {
2200 tag_decl_kind = clang::TTK_Struct;
2201 default_accessibility = eAccessPublic;
2202 }
2203 else if (tag == DW_TAG_union_type)
2204 {
2205 tag_decl_kind = clang::TTK_Union;
2206 default_accessibility = eAccessPublic;
2207 }
2208 else if (tag == DW_TAG_class_type)
2209 {
2210 tag_decl_kind = clang::TTK_Class;
2211 default_accessibility = eAccessPrivate;
2212 }
2213
Greg Clayton53eb1c22012-04-02 22:59:12 +00002214 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002215 std::vector<clang::CXXBaseSpecifier *> base_classes;
2216 std::vector<int> member_accessibilities;
2217 bool is_a_class = false;
2218 // Parse members and base classes first
2219 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002220
2221 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002222 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002223 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002224 die,
2225 clang_type,
2226 class_language,
2227 base_classes,
2228 member_accessibilities,
2229 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002230 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002231 default_accessibility,
2232 is_a_class,
2233 layout_info);
2234
2235 // Now parse any methods if there were any...
2236 size_t num_functions = member_function_dies.Size();
2237 if (num_functions > 0)
2238 {
2239 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002240 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002241 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002242 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002243 }
2244
2245 if (class_language == eLanguageTypeObjC)
2246 {
Greg Clayton84db9102012-03-26 23:03:23 +00002247 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002248 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002249 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002250
Sean Callanan77a1fd32012-02-27 20:07:01 +00002251 DIEArray method_die_offsets;
2252 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002253 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002254 if (m_apple_objc_ap.get())
2255 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2256 }
2257 else
2258 {
2259 if (!m_indexed)
2260 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002261
Sean Callanan77a1fd32012-02-27 20:07:01 +00002262 ConstString class_name (class_str.c_str());
2263 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2264 }
2265
2266 if (!method_die_offsets.empty())
2267 {
2268 DWARFDebugInfo* debug_info = DebugInfo();
2269
2270 DWARFCompileUnit* method_cu = NULL;
2271 const size_t num_matches = method_die_offsets.size();
2272 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002273 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002274 const dw_offset_t die_offset = method_die_offsets[i];
2275 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2276
2277 if (method_die)
2278 ResolveType (method_cu, method_die);
2279 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002280 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002281 if (m_using_apple_tables)
2282 {
2283 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2284 die_offset, class_str.c_str());
2285 }
2286 }
2287 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002288 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002289
2290 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2291 pi != pe;
2292 ++pi)
2293 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002294 }
2295 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002296
2297 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2298 // need to tell the clang type it is actually a class.
2299 if (class_language != eLanguageTypeObjC)
2300 {
2301 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2302 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2303 }
2304
2305 // Since DW_TAG_structure_type gets used for both classes
2306 // and structures, we may need to set any DW_TAG_member
2307 // fields to have a "private" access if none was specified.
2308 // When we parsed the child members we tracked that actual
2309 // accessibility value for each DW_TAG_member in the
2310 // "member_accessibilities" array. If the value for the
2311 // member is zero, then it was set to the "default_accessibility"
2312 // which for structs was "public". Below we correct this
2313 // by setting any fields to "private" that weren't correctly
2314 // set.
2315 if (is_a_class && !member_accessibilities.empty())
2316 {
2317 // This is a class and all members that didn't have
2318 // their access specified are private.
2319 ast.SetDefaultAccessForRecordFields (clang_type,
2320 eAccessPrivate,
2321 &member_accessibilities.front(),
2322 member_accessibilities.size());
2323 }
2324
2325 if (!base_classes.empty())
2326 {
2327 ast.SetBaseClassesForClassType (clang_type,
2328 &base_classes.front(),
2329 base_classes.size());
2330
2331 // Clang will copy each CXXBaseSpecifier in "base_classes"
2332 // so we have to free them all.
2333 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2334 base_classes.size());
2335 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002336 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002337 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002338
2339 ast.BuildIndirectFields (clang_type);
2340
Sean Callanan77a1fd32012-02-27 20:07:01 +00002341 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002342
Greg Clayton2508b9b2012-11-01 23:20:02 +00002343 if (!layout_info.field_offsets.empty() ||
2344 !layout_info.base_offsets.empty() ||
2345 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002346 {
2347 if (type)
2348 layout_info.bit_size = type->GetByteSize() * 8;
2349 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002350 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002351
2352 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2353 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002354 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002355 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002356 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002357 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002358 "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 +00002359 clang_type,
2360 record_decl,
2361 layout_info.bit_size,
2362 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002363 (uint32_t)layout_info.field_offsets.size(),
2364 (uint32_t)layout_info.base_offsets.size(),
2365 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002366
Greg Clayton2508b9b2012-11-01 23:20:02 +00002367 uint32_t idx;
2368 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002369 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002370 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002371 {
2372 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002373 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002374 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002375 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002376 (uint32_t)pos->second,
2377 pos->first->getNameAsString().c_str());
2378 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002379 }
2380
2381 {
2382 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2383 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2384 {
2385 GetObjectFile()->GetModule()->LogMessage (log.get(),
2386 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2387 clang_type,
2388 idx,
2389 (uint32_t)base_pos->second.getQuantity(),
2390 base_pos->first->getNameAsString().c_str());
2391 }
2392 }
2393 {
2394 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2395 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2396 {
2397 GetObjectFile()->GetModule()->LogMessage (log.get(),
2398 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2399 clang_type,
2400 idx,
2401 (uint32_t)vbase_pos->second.getQuantity(),
2402 vbase_pos->first->getNameAsString().c_str());
2403 }
2404 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002405 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002406 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2407 }
2408 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002409 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002410
Greg Claytonc93237c2010-10-01 20:48:32 +00002411 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002412
2413 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002414 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002415 if (die->HasChildren())
2416 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002417 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002418 bool is_signed = false;
2419 ast.IsIntegerType(clang_type, is_signed);
2420 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002421 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002422 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002423 return clang_type;
2424
2425 default:
2426 assert(false && "not a forward clang type decl!");
2427 break;
2428 }
2429 return NULL;
2430}
2431
Greg Claytonc685f8e2010-09-15 04:15:46 +00002432Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002433SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002434{
2435 if (type_die != NULL)
2436 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002437 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002438
Greg Claytonc685f8e2010-09-15 04:15:46 +00002439 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002440 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002441
Greg Clayton24739922010-10-13 03:15:28 +00002442 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002443 {
2444 if (type != DIE_IS_BEING_PARSED)
2445 return type;
2446
2447 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002448 type_die->GetOffset(),
2449 DW_TAG_value_to_name(type_die->Tag()),
2450 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002451
2452 }
2453 else
2454 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002455 }
2456 return NULL;
2457}
2458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002459CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002460SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461{
2462 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002463 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002464 {
2465 // The symbol vendor doesn't know about this compile unit, we
2466 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002467 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002468 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002469 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470}
2471
2472bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002473SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002474{
Greg Clayton72310352013-02-23 04:12:47 +00002475 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002476 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002477 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002478
Greg Clayton81c22f62011-10-19 18:09:39 +00002479 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002480 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002481 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002482
2483 if (sc.function)
2484 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002485 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002486 return true;
2487 }
2488
2489 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490}
2491
2492uint32_t
2493SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2494{
2495 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002496 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002497 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002498 so_addr.GetOffset(),
2499 resolve_scope);
2500 uint32_t resolved = 0;
2501 if (resolve_scope & ( eSymbolContextCompUnit |
2502 eSymbolContextFunction |
2503 eSymbolContextBlock |
2504 eSymbolContextLineEntry))
2505 {
2506 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2507
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002508 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002509 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002510 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002511 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512 if (cu_offset != DW_INVALID_OFFSET)
2513 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002514 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002515 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2516 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002517 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002518 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002519 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002520 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002521 resolved |= eSymbolContextCompUnit;
2522
Greg Clayton6ab80132012-12-12 17:30:52 +00002523 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002524 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2525 {
2526 DWARFDebugInfoEntry *function_die = NULL;
2527 DWARFDebugInfoEntry *block_die = NULL;
2528 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002529 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002530 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2531 }
2532 else
2533 {
2534 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2535 }
2536
2537 if (function_die != NULL)
2538 {
2539 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2540 if (sc.function == NULL)
2541 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2542 }
2543 else
2544 {
2545 // We might have had a compile unit that had discontiguous
2546 // address ranges where the gaps are symbols that don't have
2547 // any debug info. Discontiguous compile unit address ranges
2548 // should only happen when there aren't other functions from
2549 // other compile units in these gaps. This helps keep the size
2550 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002551 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002552 }
2553
2554 if (sc.function != NULL)
2555 {
2556 resolved |= eSymbolContextFunction;
2557
2558 if (resolve_scope & eSymbolContextBlock)
2559 {
2560 Block& block = sc.function->GetBlock (true);
2561
2562 if (block_die != NULL)
2563 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2564 else
2565 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2566 if (sc.block)
2567 resolved |= eSymbolContextBlock;
2568 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002569 }
2570 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002571
2572 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2573 {
2574 LineTable *line_table = sc.comp_unit->GetLineTable();
2575 if (line_table != NULL)
2576 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002577 // And address that makes it into this function should be in terms
2578 // of this debug file if there is no debug map, or it will be an
2579 // address in the .o file which needs to be fixed up to be in terms
2580 // of the debug map executable. Either way, calling FixupAddress()
2581 // will work for us.
2582 Address exe_so_addr (so_addr);
2583 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002584 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002585 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002586 {
2587 resolved |= eSymbolContextLineEntry;
2588 }
2589 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002590 }
2591 }
2592
2593 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2594 {
2595 // We might have had a compile unit that had discontiguous
2596 // address ranges where the gaps are symbols that don't have
2597 // any debug info. Discontiguous compile unit address ranges
2598 // should only happen when there aren't other functions from
2599 // other compile units in these gaps. This helps keep the size
2600 // of the aranges down.
2601 sc.comp_unit = NULL;
2602 resolved &= ~eSymbolContextCompUnit;
2603 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002604 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002605 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002606 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002607 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2608 cu_offset,
2609 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002610 }
2611 }
2612 }
2613 }
2614 }
2615 return resolved;
2616}
2617
2618
2619
2620uint32_t
2621SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2622{
2623 const uint32_t prev_size = sc_list.GetSize();
2624 if (resolve_scope & eSymbolContextCompUnit)
2625 {
2626 DWARFDebugInfo* debug_info = DebugInfo();
2627 if (debug_info)
2628 {
2629 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002630 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002631
Greg Clayton53eb1c22012-04-02 22:59:12 +00002632 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002633 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002634 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002635 const bool full_match = file_spec.GetDirectory();
2636 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 +00002637 if (check_inlines || file_spec_matches_cu_file_spec)
2638 {
2639 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002640 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002641 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002642 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002643 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002644
Greg Clayton526a4ae2012-05-16 22:09:01 +00002645 // If we are looking for inline functions only and we don't
2646 // find it in the support files, we are done.
2647 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002648 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002649 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2650 if (file_idx == UINT32_MAX)
2651 continue;
2652 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002653
Greg Clayton526a4ae2012-05-16 22:09:01 +00002654 if (line != 0)
2655 {
2656 LineTable *line_table = sc.comp_unit->GetLineTable();
2657
2658 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002659 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002660 // We will have already looked up the file index if
2661 // we are searching for inline entries.
2662 if (!check_inlines)
2663 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664
Greg Clayton526a4ae2012-05-16 22:09:01 +00002665 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002666 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002667 uint32_t found_line;
2668 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2669 found_line = sc.line_entry.line;
2670
2671 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002672 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002673 sc.function = NULL;
2674 sc.block = NULL;
2675 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002676 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002677 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2678 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002679 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002680 DWARFDebugInfoEntry *function_die = NULL;
2681 DWARFDebugInfoEntry *block_die = NULL;
2682 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002683
Greg Clayton526a4ae2012-05-16 22:09:01 +00002684 if (function_die != NULL)
2685 {
2686 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2687 if (sc.function == NULL)
2688 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2689 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690
Greg Clayton526a4ae2012-05-16 22:09:01 +00002691 if (sc.function != NULL)
2692 {
2693 Block& block = sc.function->GetBlock (true);
2694
2695 if (block_die != NULL)
2696 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2697 else
2698 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2699 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002700 }
2701 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702
Greg Clayton526a4ae2012-05-16 22:09:01 +00002703 sc_list.Append(sc);
2704 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2705 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706 }
2707 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002708 else if (file_spec_matches_cu_file_spec && !check_inlines)
2709 {
2710 // only append the context if we aren't looking for inline call sites
2711 // by file and line and if the file spec matches that of the compile unit
2712 sc_list.Append(sc);
2713 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002714 }
2715 else if (file_spec_matches_cu_file_spec && !check_inlines)
2716 {
2717 // only append the context if we aren't looking for inline call sites
2718 // by file and line and if the file spec matches that of the compile unit
2719 sc_list.Append(sc);
2720 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002721
Greg Clayton526a4ae2012-05-16 22:09:01 +00002722 if (!check_inlines)
2723 break;
2724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725 }
2726 }
2727 }
2728 }
2729 return sc_list.GetSize() - prev_size;
2730}
2731
2732void
2733SymbolFileDWARF::Index ()
2734{
2735 if (m_indexed)
2736 return;
2737 m_indexed = true;
2738 Timer scoped_timer (__PRETTY_FUNCTION__,
2739 "SymbolFileDWARF::Index (%s)",
2740 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2741
2742 DWARFDebugInfo* debug_info = DebugInfo();
2743 if (debug_info)
2744 {
2745 uint32_t cu_idx = 0;
2746 const uint32_t num_compile_units = GetNumCompileUnits();
2747 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2748 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002749 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002750
Greg Clayton53eb1c22012-04-02 22:59:12 +00002751 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002752
Greg Clayton53eb1c22012-04-02 22:59:12 +00002753 dwarf_cu->Index (cu_idx,
2754 m_function_basename_index,
2755 m_function_fullname_index,
2756 m_function_method_index,
2757 m_function_selector_index,
2758 m_objc_class_selectors_index,
2759 m_global_index,
2760 m_type_index,
2761 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002762
2763 // Keep memory down by clearing DIEs if this generate function
2764 // caused them to be parsed
2765 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002766 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002767 }
2768
Greg Claytond4a2b372011-09-12 23:21:58 +00002769 m_function_basename_index.Finalize();
2770 m_function_fullname_index.Finalize();
2771 m_function_method_index.Finalize();
2772 m_function_selector_index.Finalize();
2773 m_objc_class_selectors_index.Finalize();
2774 m_global_index.Finalize();
2775 m_type_index.Finalize();
2776 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002777
Greg Clayton24739922010-10-13 03:15:28 +00002778#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002779 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002780 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002781 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2782 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002783 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2784 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2785 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2786 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2787 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2788 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002789 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002790 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002791#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002792 }
2793}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002794
2795bool
2796SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2797{
2798 if (namespace_decl == NULL)
2799 {
2800 // Invalid namespace decl which means we aren't matching only things
2801 // in this symbol file, so return true to indicate it matches this
2802 // symbol file.
2803 return true;
2804 }
2805
2806 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2807
2808 if (namespace_ast == NULL)
2809 return true; // No AST in the "namespace_decl", return true since it
2810 // could then match any symbol file, including this one
2811
2812 if (namespace_ast == GetClangASTContext().getASTContext())
2813 return true; // The ASTs match, return true
2814
2815 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002816 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2817
2818 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002819 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002820
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002821 return false;
2822}
2823
Greg Clayton2506a7a2011-10-12 23:34:26 +00002824bool
2825SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2826 DWARFCompileUnit* cu,
2827 const DWARFDebugInfoEntry* die)
2828{
2829 // No namespace specified, so the answesr i
2830 if (namespace_decl == NULL)
2831 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002832
2833 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002834
Greg Clayton437a1352012-04-09 22:43:43 +00002835 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2836 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002837 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002838 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002839 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002840
Greg Clayton2506a7a2011-10-12 23:34:26 +00002841 if (clang_namespace_decl)
2842 {
2843 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002844 {
2845 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002846 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002847 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002848 }
2849
Greg Clayton437a1352012-04-09 22:43:43 +00002850 if (clang_namespace_decl == die_clang_decl_ctx)
2851 return true;
2852 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002853 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002854 }
2855 else
2856 {
2857 // We have a namespace_decl that was not NULL but it contained
2858 // a NULL "clang::NamespaceDecl", so this means the global namespace
2859 // So as long the the contained decl context DIE isn't a namespace
2860 // we should be ok.
2861 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2862 return true;
2863 }
2864 }
Sean Callananebe60672011-10-13 21:50:33 +00002865
2866 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002867 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002868
Greg Clayton2506a7a2011-10-12 23:34:26 +00002869 return false;
2870}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002871uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002872SymbolFileDWARF::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 +00002873{
Greg Clayton21f2a492011-10-06 00:09:08 +00002874 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2875
2876 if (log)
2877 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002878 GetObjectFile()->GetModule()->LogMessage (log.get(),
2879 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2880 name.GetCString(),
2881 namespace_decl,
2882 append,
2883 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002884 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002885
2886 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2887 return 0;
2888
Greg Claytonc685f8e2010-09-15 04:15:46 +00002889 DWARFDebugInfo* info = DebugInfo();
2890 if (info == NULL)
2891 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002892
2893 // If we aren't appending the results to this list, then clear the list
2894 if (!append)
2895 variables.Clear();
2896
2897 // Remember how many variables are in the list before we search in case
2898 // we are appending the results to a variable list.
2899 const uint32_t original_size = variables.GetSize();
2900
Greg Claytond4a2b372011-09-12 23:21:58 +00002901 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002902
Greg Clayton97fbc342011-10-20 22:30:33 +00002903 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002904 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002905 if (m_apple_names_ap.get())
2906 {
2907 const char *name_cstr = name.GetCString();
2908 const char *base_name_start;
2909 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002910
Greg Clayton97fbc342011-10-20 22:30:33 +00002911 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2912 base_name_start = name_cstr;
2913
2914 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2915 }
Greg Clayton7f995132011-10-04 22:41:51 +00002916 }
2917 else
2918 {
2919 // Index the DWARF if we haven't already
2920 if (!m_indexed)
2921 Index ();
2922
2923 m_global_index.Find (name, die_offsets);
2924 }
2925
Greg Clayton437a1352012-04-09 22:43:43 +00002926 const size_t num_die_matches = die_offsets.size();
2927 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002928 {
Greg Clayton7f995132011-10-04 22:41:51 +00002929 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002930 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002931 assert (sc.module_sp);
2932
Greg Claytond4a2b372011-09-12 23:21:58 +00002933 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002934 DWARFCompileUnit* dwarf_cu = NULL;
2935 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002936 bool done = false;
2937 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002938 {
2939 const dw_offset_t die_offset = die_offsets[i];
2940 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002941
Greg Clayton95d87902011-11-11 03:16:25 +00002942 if (die)
2943 {
Greg Clayton437a1352012-04-09 22:43:43 +00002944 switch (die->Tag())
2945 {
2946 default:
2947 case DW_TAG_subprogram:
2948 case DW_TAG_inlined_subroutine:
2949 case DW_TAG_try_block:
2950 case DW_TAG_catch_block:
2951 break;
2952
2953 case DW_TAG_variable:
2954 {
2955 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002956
2957 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2958 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002959
Greg Clayton437a1352012-04-09 22:43:43 +00002960 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002961
Greg Clayton437a1352012-04-09 22:43:43 +00002962 if (variables.GetSize() - original_size >= max_matches)
2963 done = true;
2964 }
2965 break;
2966 }
Greg Clayton95d87902011-11-11 03:16:25 +00002967 }
2968 else
2969 {
2970 if (m_using_apple_tables)
2971 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002972 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2973 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002974 }
2975 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002977 }
2978
2979 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002980 const uint32_t num_matches = variables.GetSize() - original_size;
2981 if (log && num_matches > 0)
2982 {
2983 GetObjectFile()->GetModule()->LogMessage (log.get(),
2984 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2985 name.GetCString(),
2986 namespace_decl,
2987 append,
2988 max_matches,
2989 num_matches);
2990 }
2991 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002992}
2993
2994uint32_t
2995SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2996{
Greg Clayton21f2a492011-10-06 00:09:08 +00002997 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2998
2999 if (log)
3000 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003001 GetObjectFile()->GetModule()->LogMessage (log.get(),
3002 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3003 regex.GetText(),
3004 append,
3005 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003006 }
3007
Greg Claytonc685f8e2010-09-15 04:15:46 +00003008 DWARFDebugInfo* info = DebugInfo();
3009 if (info == NULL)
3010 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003011
3012 // If we aren't appending the results to this list, then clear the list
3013 if (!append)
3014 variables.Clear();
3015
3016 // Remember how many variables are in the list before we search in case
3017 // we are appending the results to a variable list.
3018 const uint32_t original_size = variables.GetSize();
3019
Greg Clayton7f995132011-10-04 22:41:51 +00003020 DIEArray die_offsets;
3021
Greg Clayton97fbc342011-10-20 22:30:33 +00003022 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003023 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003024 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003025 {
3026 DWARFMappedHash::DIEInfoArray hash_data_array;
3027 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3028 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3029 }
Greg Clayton7f995132011-10-04 22:41:51 +00003030 }
3031 else
3032 {
3033 // Index the DWARF if we haven't already
3034 if (!m_indexed)
3035 Index ();
3036
3037 m_global_index.Find (regex, die_offsets);
3038 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039
Greg Claytonc685f8e2010-09-15 04:15:46 +00003040 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003041 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003042 assert (sc.module_sp);
3043
Greg Claytond4a2b372011-09-12 23:21:58 +00003044 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003045 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003046 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003047 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003048 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003049 DWARFDebugInfo* debug_info = DebugInfo();
3050 for (size_t i=0; i<num_matches; ++i)
3051 {
3052 const dw_offset_t die_offset = die_offsets[i];
3053 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003054
3055 if (die)
3056 {
3057 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003058
Greg Clayton95d87902011-11-11 03:16:25 +00003059 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003060
Greg Clayton95d87902011-11-11 03:16:25 +00003061 if (variables.GetSize() - original_size >= max_matches)
3062 break;
3063 }
3064 else
3065 {
3066 if (m_using_apple_tables)
3067 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003068 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3069 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003070 }
3071 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003072 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003073 }
3074
3075 // Return the number of variable that were appended to the list
3076 return variables.GetSize() - original_size;
3077}
3078
Greg Claytonaa044962011-10-13 00:59:38 +00003079
Jim Ingham4cda6e02011-10-07 22:23:45 +00003080bool
3081SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3082 DWARFCompileUnit *&dwarf_cu,
3083 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003084{
Greg Claytonaa044962011-10-13 00:59:38 +00003085 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3086 return ResolveFunction (dwarf_cu, die, sc_list);
3087}
3088
3089
3090bool
3091SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3092 const DWARFDebugInfoEntry *die,
3093 SymbolContextList& sc_list)
3094{
Greg Clayton9e315582011-09-02 04:03:59 +00003095 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003096
3097 if (die == NULL)
3098 return false;
3099
Jim Ingham4cda6e02011-10-07 22:23:45 +00003100 // If we were passed a die that is not a function, just return false...
3101 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3102 return false;
3103
3104 const DWARFDebugInfoEntry* inlined_die = NULL;
3105 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003106 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003107 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003108
Jim Ingham4cda6e02011-10-07 22:23:45 +00003109 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003110 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003111 if (die->Tag() == DW_TAG_subprogram)
3112 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003113 }
3114 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003115 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003116 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003117 {
3118 Address addr;
3119 // Parse all blocks if needed
3120 if (inlined_die)
3121 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003122 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003123 assert (sc.block != NULL);
3124 if (sc.block->GetStartAddress (addr) == false)
3125 addr.Clear();
3126 }
3127 else
3128 {
3129 sc.block = NULL;
3130 addr = sc.function->GetAddressRange().GetBaseAddress();
3131 }
3132
3133 if (addr.IsValid())
3134 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003135 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003136 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003137 }
3138 }
3139
Greg Claytonaa044962011-10-13 00:59:38 +00003140 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003141}
3142
Greg Clayton7f995132011-10-04 22:41:51 +00003143void
3144SymbolFileDWARF::FindFunctions (const ConstString &name,
3145 const NameToDIE &name_to_die,
3146 SymbolContextList& sc_list)
3147{
Greg Claytond4a2b372011-09-12 23:21:58 +00003148 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003149 if (name_to_die.Find (name, die_offsets))
3150 {
3151 ParseFunctions (die_offsets, sc_list);
3152 }
3153}
3154
3155
3156void
3157SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3158 const NameToDIE &name_to_die,
3159 SymbolContextList& sc_list)
3160{
3161 DIEArray die_offsets;
3162 if (name_to_die.Find (regex, die_offsets))
3163 {
3164 ParseFunctions (die_offsets, sc_list);
3165 }
3166}
3167
3168
3169void
3170SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3171 const DWARFMappedHash::MemoryTable &memory_table,
3172 SymbolContextList& sc_list)
3173{
3174 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003175 DWARFMappedHash::DIEInfoArray hash_data_array;
3176 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003177 {
Greg Claytond1767f02011-12-08 02:13:16 +00003178 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003179 ParseFunctions (die_offsets, sc_list);
3180 }
3181}
3182
3183void
3184SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3185 SymbolContextList& sc_list)
3186{
3187 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003188 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003189 {
Greg Clayton7f995132011-10-04 22:41:51 +00003190 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003191
3192 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003193 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003194 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003195 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003196 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197 }
3198 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003199}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003200
Jim Ingham4cda6e02011-10-07 22:23:45 +00003201bool
3202SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3203 const DWARFCompileUnit *dwarf_cu,
3204 uint32_t name_type_mask,
3205 const char *partial_name,
3206 const char *base_name_start,
3207 const char *base_name_end)
3208{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003209 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3210 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003211 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003212 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3213 if (!containing_decl_ctx)
3214 return false;
3215
3216 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3217
Greg Claytonfbea0f62012-11-15 18:05:43 +00003218 if (name_type_mask == eFunctionNameTypeMethod)
3219 {
3220 if (is_cxx_method == false)
3221 return false;
3222 }
3223
3224 if (name_type_mask == eFunctionNameTypeBase)
3225 {
3226 if (is_cxx_method == true)
3227 return false;
3228 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003229 }
3230
3231 // Now we need to check whether the name we got back for this type matches the extra specifications
3232 // that were in the name we're looking up:
3233 if (base_name_start != partial_name || *base_name_end != '\0')
3234 {
3235 // First see if the stuff to the left matches the full name. To do that let's see if
3236 // we can pull out the mips linkage name attribute:
3237
3238 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003239 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003240 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003241 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3242 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003243 if (idx == UINT32_MAX)
3244 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003245 if (idx != UINT32_MAX)
3246 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003247 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3248 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003249 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3250 if (mangled_name)
3251 best_name.SetValue (ConstString(mangled_name), true);
3252 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003253 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003254
3255 if (!best_name)
3256 {
3257 idx = attributes.FindAttributeIndex(DW_AT_name);
3258 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3259 {
3260 const char *name = form_value.AsCString(&get_debug_str_data());
3261 best_name.SetValue (ConstString(name), false);
3262 }
3263 }
3264
3265 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003266 {
3267 const char *demangled = best_name.GetDemangledName().GetCString();
3268 if (demangled)
3269 {
3270 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003271 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3272 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003273 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003274 else
3275 {
3276 // Sort out the case where our name is something like "Process::Destroy" and the match is
3277 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3278 // namespace boundaries...
3279
3280 if (partial_name[0] == ':' && partial_name[1] == ':')
3281 {
3282 // The partial name was already on a namespace boundary so all matches are good.
3283 return true;
3284 }
3285 else if (partial_in_demangled == demangled)
3286 {
3287 // They both start the same, so this is an good match.
3288 return true;
3289 }
3290 else
3291 {
3292 if (partial_in_demangled - demangled == 1)
3293 {
3294 // Only one character difference, can't be a namespace boundary...
3295 return false;
3296 }
3297 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3298 {
3299 // We are on a namespace boundary, so this is also good.
3300 return true;
3301 }
3302 else
3303 return false;
3304 }
3305 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003306 }
3307 }
3308 }
3309
3310 return true;
3311}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003312
Greg Clayton0c5cd902010-06-28 21:30:43 +00003313uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003314SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003315 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003316 uint32_t name_type_mask,
3317 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003318 bool append,
3319 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003320{
3321 Timer scoped_timer (__PRETTY_FUNCTION__,
3322 "SymbolFileDWARF::FindFunctions (name = '%s')",
3323 name.AsCString());
3324
Greg Clayton21f2a492011-10-06 00:09:08 +00003325 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3326
3327 if (log)
3328 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003329 GetObjectFile()->GetModule()->LogMessage (log.get(),
3330 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3331 name.GetCString(),
3332 name_type_mask,
3333 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003334 }
3335
Greg Clayton0c5cd902010-06-28 21:30:43 +00003336 // If we aren't appending the results to this list, then clear the list
3337 if (!append)
3338 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003339
3340 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3341 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003342
3343 // If name is empty then we won't find anything.
3344 if (name.IsEmpty())
3345 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003346
3347 // Remember how many sc_list are in the list before we search in case
3348 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003349
Greg Clayton9e315582011-09-02 04:03:59 +00003350 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003351
Jim Ingham4cda6e02011-10-07 22:23:45 +00003352 const char *name_cstr = name.GetCString();
3353 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3354 const char *base_name_start = name_cstr;
3355 const char *base_name_end = name_cstr + strlen(name_cstr);
3356
3357 if (name_type_mask & eFunctionNameTypeAuto)
3358 {
3359 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3360 effective_name_type_mask = eFunctionNameTypeFull;
3361 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3362 effective_name_type_mask = eFunctionNameTypeFull;
3363 else
3364 {
3365 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3366 effective_name_type_mask |= eFunctionNameTypeSelector;
3367
3368 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3369 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3370 }
3371 }
3372 else
3373 {
3374 effective_name_type_mask = name_type_mask;
3375 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3376 {
3377 // If they've asked for a CPP method or function name and it can't be that, we don't
3378 // even need to search for CPP methods or names.
3379 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3380 {
3381 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3382 if (effective_name_type_mask == eFunctionNameTypeNone)
3383 return 0;
3384 }
3385 }
3386
3387 if (effective_name_type_mask & eFunctionNameTypeSelector)
3388 {
3389 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3390 {
3391 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3392 if (effective_name_type_mask == eFunctionNameTypeNone)
3393 return 0;
3394 }
3395 }
3396 }
3397
3398 DWARFDebugInfo* info = DebugInfo();
3399 if (info == NULL)
3400 return 0;
3401
Greg Claytonaa044962011-10-13 00:59:38 +00003402 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003403 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003404 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003405 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003406 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003407
3408 DIEArray die_offsets;
3409
3410 uint32_t num_matches = 0;
3411
3412 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003413 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003414 // If they asked for the full name, match what they typed. At some point we may
3415 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3416 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003417 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003418 for (uint32_t i = 0; i < num_matches; i++)
3419 {
Greg Clayton95d87902011-11-11 03:16:25 +00003420 const dw_offset_t die_offset = die_offsets[i];
3421 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003422 if (die)
3423 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003424 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3425 continue;
3426
Sean Callanan9df05fb2012-02-10 22:52:19 +00003427 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3428 continue;
3429
Greg Claytonaa044962011-10-13 00:59:38 +00003430 ResolveFunction (dwarf_cu, die, sc_list);
3431 }
Greg Clayton95d87902011-11-11 03:16:25 +00003432 else
3433 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003434 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3435 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003436 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003437 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003438 }
3439 else
3440 {
3441 if (effective_name_type_mask & eFunctionNameTypeSelector)
3442 {
3443 if (namespace_decl && *namespace_decl)
3444 return 0; // no selectors in namespaces
3445
3446 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3447 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3448 // and if it is an ObjC method name, we're good.
3449
3450 for (uint32_t i = 0; i < num_matches; i++)
3451 {
Greg Clayton95d87902011-11-11 03:16:25 +00003452 const dw_offset_t die_offset = die_offsets[i];
3453 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003454 if (die)
3455 {
3456 const char *die_name = die->GetName(this, dwarf_cu);
3457 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003458 {
3459 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3460 continue;
3461
Greg Clayton97fbc342011-10-20 22:30:33 +00003462 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003463 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003464 }
Greg Clayton95d87902011-11-11 03:16:25 +00003465 else
3466 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003467 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3468 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003469 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003470 }
3471 die_offsets.clear();
3472 }
3473
3474 if (effective_name_type_mask & eFunctionNameTypeMethod
3475 || effective_name_type_mask & eFunctionNameTypeBase)
3476 {
3477 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3478 (namespace_decl && *namespace_decl))
3479 return 0; // no methods in namespaces
3480
3481 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3482 // extract the base name, look that up, and if there is any other information in the name we were
3483 // passed in we have to post-filter based on that.
3484
3485 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3486 std::string base_name(base_name_start, base_name_end - base_name_start);
3487 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3488
3489 for (uint32_t i = 0; i < num_matches; i++)
3490 {
Greg Clayton95d87902011-11-11 03:16:25 +00003491 const dw_offset_t die_offset = die_offsets[i];
3492 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003493 if (die)
3494 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003495 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3496 continue;
3497
Greg Clayton97fbc342011-10-20 22:30:33 +00003498 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3499 continue;
3500
Greg Claytonfbea0f62012-11-15 18:05:43 +00003501 if (!FunctionDieMatchesPartialName(die,
Greg Clayton97fbc342011-10-20 22:30:33 +00003502 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003503 effective_name_type_mask,
Greg Clayton97fbc342011-10-20 22:30:33 +00003504 name_cstr,
3505 base_name_start,
3506 base_name_end))
3507 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003508
Greg Clayton97fbc342011-10-20 22:30:33 +00003509 // If we get to here, the die is good, and we should add it:
3510 ResolveFunction (dwarf_cu, die, sc_list);
3511 }
Greg Clayton95d87902011-11-11 03:16:25 +00003512 else
3513 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003514 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3515 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003516 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003517 }
3518 die_offsets.clear();
3519 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003520 }
3521 }
Greg Clayton7f995132011-10-04 22:41:51 +00003522 }
3523 else
3524 {
3525
3526 // Index the DWARF if we haven't already
3527 if (!m_indexed)
3528 Index ();
3529
Greg Clayton7f995132011-10-04 22:41:51 +00003530 if (name_type_mask & eFunctionNameTypeFull)
3531 FindFunctions (name, m_function_fullname_index, sc_list);
3532
Jim Ingham4cda6e02011-10-07 22:23:45 +00003533 std::string base_name(base_name_start, base_name_end - base_name_start);
3534 ConstString base_name_const(base_name.c_str());
3535 DIEArray die_offsets;
3536 DWARFCompileUnit *dwarf_cu = NULL;
3537
3538 if (effective_name_type_mask & eFunctionNameTypeBase)
3539 {
3540 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003541 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003542 {
Greg Claytonaa044962011-10-13 00:59:38 +00003543 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3544 if (die)
3545 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003546 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3547 continue;
3548
Sean Callanan213fdb82011-10-13 01:49:10 +00003549 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3550 continue;
3551
Greg Claytonaa044962011-10-13 00:59:38 +00003552 if (!FunctionDieMatchesPartialName(die,
3553 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003554 eFunctionNameTypeBase,
Greg Claytonaa044962011-10-13 00:59:38 +00003555 name_cstr,
3556 base_name_start,
3557 base_name_end))
3558 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003559
Greg Claytonaa044962011-10-13 00:59:38 +00003560 // If we get to here, the die is good, and we should add it:
3561 ResolveFunction (dwarf_cu, die, sc_list);
3562 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003563 }
3564 die_offsets.clear();
3565 }
3566
Jim Inghamea8005a2011-10-11 01:18:11 +00003567 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003568 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003569 if (namespace_decl && *namespace_decl)
3570 return 0; // no methods in namespaces
3571
Jim Ingham4cda6e02011-10-07 22:23:45 +00003572 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3573 {
Greg Claytonaa044962011-10-13 00:59:38 +00003574 for (uint32_t i = 0; i < num_base; i++)
3575 {
3576 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3577 if (die)
3578 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003579 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3580 continue;
3581
3582 if (!FunctionDieMatchesPartialName(die,
Greg Claytonaa044962011-10-13 00:59:38 +00003583 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003584 eFunctionNameTypeMethod,
Greg Claytonaa044962011-10-13 00:59:38 +00003585 name_cstr,
3586 base_name_start,
3587 base_name_end))
3588 continue;
3589
3590 // If we get to here, the die is good, and we should add it:
3591 ResolveFunction (dwarf_cu, die, sc_list);
3592 }
3593 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003594 }
3595 die_offsets.clear();
3596 }
Greg Clayton7f995132011-10-04 22:41:51 +00003597
Sean Callanan213fdb82011-10-13 01:49:10 +00003598 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003599 {
Greg Clayton7f995132011-10-04 22:41:51 +00003600 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003601 }
3602
Greg Clayton4d01ace2011-09-29 16:58:15 +00003603 }
3604
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003605 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003606 const uint32_t num_matches = sc_list.GetSize() - original_size;
3607
3608 if (log && num_matches > 0)
3609 {
3610 GetObjectFile()->GetModule()->LogMessage (log.get(),
3611 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3612 name.GetCString(),
3613 name_type_mask,
3614 append,
3615 num_matches);
3616 }
3617 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003618}
3619
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003620uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003621SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003622{
3623 Timer scoped_timer (__PRETTY_FUNCTION__,
3624 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3625 regex.GetText());
3626
Greg Clayton21f2a492011-10-06 00:09:08 +00003627 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3628
3629 if (log)
3630 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003631 GetObjectFile()->GetModule()->LogMessage (log.get(),
3632 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3633 regex.GetText(),
3634 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003635 }
3636
3637
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003638 // If we aren't appending the results to this list, then clear the list
3639 if (!append)
3640 sc_list.Clear();
3641
3642 // Remember how many sc_list are in the list before we search in case
3643 // we are appending the results to a variable list.
3644 uint32_t original_size = sc_list.GetSize();
3645
Greg Clayton97fbc342011-10-20 22:30:33 +00003646 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003647 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003648 if (m_apple_names_ap.get())
3649 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003650 }
3651 else
3652 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003653 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003654 if (!m_indexed)
3655 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003656
Greg Clayton7f995132011-10-04 22:41:51 +00003657 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003658
Greg Clayton7f995132011-10-04 22:41:51 +00003659 FindFunctions (regex, m_function_fullname_index, sc_list);
3660 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661
3662 // Return the number of variable that were appended to the list
3663 return sc_list.GetSize() - original_size;
3664}
Jim Ingham318c9f22011-08-26 19:44:13 +00003665
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003666uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003667SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3668 const ConstString &name,
3669 const lldb_private::ClangNamespaceDecl *namespace_decl,
3670 bool append,
3671 uint32_t max_matches,
3672 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003673{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003674 DWARFDebugInfo* info = DebugInfo();
3675 if (info == NULL)
3676 return 0;
3677
Greg Clayton21f2a492011-10-06 00:09:08 +00003678 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3679
3680 if (log)
3681 {
Greg Clayton437a1352012-04-09 22:43:43 +00003682 if (namespace_decl)
3683 {
3684 GetObjectFile()->GetModule()->LogMessage (log.get(),
3685 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3686 name.GetCString(),
3687 namespace_decl->GetNamespaceDecl(),
3688 namespace_decl->GetQualifiedName().c_str(),
3689 append,
3690 max_matches);
3691 }
3692 else
3693 {
3694 GetObjectFile()->GetModule()->LogMessage (log.get(),
3695 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3696 name.GetCString(),
3697 append,
3698 max_matches);
3699 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003700 }
3701
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003702 // If we aren't appending the results to this list, then clear the list
3703 if (!append)
3704 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003705
3706 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3707 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003708
Greg Claytond4a2b372011-09-12 23:21:58 +00003709 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003710
Greg Clayton97fbc342011-10-20 22:30:33 +00003711 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003712 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003713 if (m_apple_types_ap.get())
3714 {
3715 const char *name_cstr = name.GetCString();
3716 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3717 }
Greg Clayton7f995132011-10-04 22:41:51 +00003718 }
3719 else
3720 {
3721 if (!m_indexed)
3722 Index ();
3723
3724 m_type_index.Find (name, die_offsets);
3725 }
3726
Greg Clayton437a1352012-04-09 22:43:43 +00003727 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003728
Greg Clayton437a1352012-04-09 22:43:43 +00003729 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003730 {
Greg Clayton7f995132011-10-04 22:41:51 +00003731 const uint32_t initial_types_size = types.GetSize();
3732 DWARFCompileUnit* dwarf_cu = NULL;
3733 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003734 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003735 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003736 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003737 const dw_offset_t die_offset = die_offsets[i];
3738 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3739
Greg Clayton95d87902011-11-11 03:16:25 +00003740 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003741 {
Greg Clayton95d87902011-11-11 03:16:25 +00003742 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3743 continue;
3744
3745 Type *matching_type = ResolveType (dwarf_cu, die);
3746 if (matching_type)
3747 {
3748 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003749 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003750 if (types.GetSize() >= max_matches)
3751 break;
3752 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003753 }
Greg Clayton95d87902011-11-11 03:16:25 +00003754 else
3755 {
3756 if (m_using_apple_tables)
3757 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003758 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3759 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003760 }
3761 }
3762
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003763 }
Greg Clayton437a1352012-04-09 22:43:43 +00003764 const uint32_t num_matches = types.GetSize() - initial_types_size;
3765 if (log && num_matches)
3766 {
3767 if (namespace_decl)
3768 {
3769 GetObjectFile()->GetModule()->LogMessage (log.get(),
3770 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3771 name.GetCString(),
3772 namespace_decl->GetNamespaceDecl(),
3773 namespace_decl->GetQualifiedName().c_str(),
3774 append,
3775 max_matches,
3776 num_matches);
3777 }
3778 else
3779 {
3780 GetObjectFile()->GetModule()->LogMessage (log.get(),
3781 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3782 name.GetCString(),
3783 append,
3784 max_matches,
3785 num_matches);
3786 }
3787 }
3788 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003789 }
Greg Clayton7f995132011-10-04 22:41:51 +00003790 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003791}
3792
3793
Greg Clayton526e5af2010-11-13 03:52:47 +00003794ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003795SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003796 const ConstString &name,
3797 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003798{
Greg Clayton21f2a492011-10-06 00:09:08 +00003799 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3800
3801 if (log)
3802 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003803 GetObjectFile()->GetModule()->LogMessage (log.get(),
3804 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3805 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003806 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003807
3808 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3809 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003810
Greg Clayton526e5af2010-11-13 03:52:47 +00003811 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003812 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003813 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003814 {
Greg Clayton7f995132011-10-04 22:41:51 +00003815 DIEArray die_offsets;
3816
Greg Clayton526e5af2010-11-13 03:52:47 +00003817 // Index if we already haven't to make sure the compile units
3818 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003819 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003820 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003821 if (m_apple_namespaces_ap.get())
3822 {
3823 const char *name_cstr = name.GetCString();
3824 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3825 }
Greg Clayton7f995132011-10-04 22:41:51 +00003826 }
3827 else
3828 {
3829 if (!m_indexed)
3830 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003831
Greg Clayton7f995132011-10-04 22:41:51 +00003832 m_namespace_index.Find (name, die_offsets);
3833 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003834
3835 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003836 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003837 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003838 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003839 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003840 DWARFDebugInfo* debug_info = DebugInfo();
3841 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003842 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003843 const dw_offset_t die_offset = die_offsets[i];
3844 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003845
Greg Clayton95d87902011-11-11 03:16:25 +00003846 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003847 {
Greg Clayton95d87902011-11-11 03:16:25 +00003848 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3849 continue;
3850
3851 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3852 if (clang_namespace_decl)
3853 {
3854 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3855 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003856 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003857 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003858 }
Greg Clayton95d87902011-11-11 03:16:25 +00003859 else
3860 {
3861 if (m_using_apple_tables)
3862 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003863 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3864 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003865 }
3866 }
3867
Greg Clayton526e5af2010-11-13 03:52:47 +00003868 }
3869 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003870 }
Greg Clayton437a1352012-04-09 22:43:43 +00003871 if (log && namespace_decl.GetNamespaceDecl())
3872 {
3873 GetObjectFile()->GetModule()->LogMessage (log.get(),
3874 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3875 name.GetCString(),
3876 namespace_decl.GetNamespaceDecl(),
3877 namespace_decl.GetQualifiedName().c_str());
3878 }
3879
Greg Clayton526e5af2010-11-13 03:52:47 +00003880 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003881}
3882
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003884SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003885{
3886 // Remember how many sc_list are in the list before we search in case
3887 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003888 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003889
3890 const uint32_t num_die_offsets = die_offsets.size();
3891 // Parse all of the types we found from the pubtypes matches
3892 uint32_t i;
3893 uint32_t num_matches = 0;
3894 for (i = 0; i < num_die_offsets; ++i)
3895 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003896 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3897 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003898 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003899 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003900 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003901 ++num_matches;
3902 if (num_matches >= max_matches)
3903 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003904 }
3905 }
3906
3907 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003908 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003909}
3910
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003911
3912size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003913SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3914 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003915 DWARFCompileUnit* dwarf_cu,
3916 const DWARFDebugInfoEntry *parent_die,
3917 bool skip_artificial,
3918 bool &is_static,
3919 TypeList* type_list,
3920 std::vector<clang_type_t>& function_param_types,
3921 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003922 unsigned &type_quals,
3923 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003924{
3925 if (parent_die == NULL)
3926 return 0;
3927
Greg Claytond88d7592010-09-15 08:33:30 +00003928 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3929
Greg Clayton7fedea22010-11-16 02:10:54 +00003930 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003931 const DWARFDebugInfoEntry *die;
3932 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3933 {
3934 dw_tag_t tag = die->Tag();
3935 switch (tag)
3936 {
3937 case DW_TAG_formal_parameter:
3938 {
3939 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003940 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003941 if (num_attributes > 0)
3942 {
3943 const char *name = NULL;
3944 Declaration decl;
3945 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003946 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003947 // one of None, Auto, Register, Extern, Static, PrivateExtern
3948
Sean Callanane2ef6e32010-09-23 03:01:22 +00003949 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003950 uint32_t i;
3951 for (i=0; i<num_attributes; ++i)
3952 {
3953 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3954 DWARFFormValue form_value;
3955 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3956 {
3957 switch (attr)
3958 {
3959 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3960 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3961 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3962 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3963 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003964 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003965 case DW_AT_location:
3966 // if (form_value.BlockData())
3967 // {
3968 // const DataExtractor& debug_info_data = debug_info();
3969 // uint32_t block_length = form_value.Unsigned();
3970 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3971 // }
3972 // else
3973 // {
3974 // }
3975 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003976 case DW_AT_const_value:
3977 case DW_AT_default_value:
3978 case DW_AT_description:
3979 case DW_AT_endianity:
3980 case DW_AT_is_optional:
3981 case DW_AT_segment:
3982 case DW_AT_variable_parameter:
3983 default:
3984 case DW_AT_abstract_origin:
3985 case DW_AT_sibling:
3986 break;
3987 }
3988 }
3989 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003990
Greg Clayton0fffff52010-09-24 05:15:53 +00003991 bool skip = false;
3992 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003993 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003994 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003995 {
3996 // In order to determine if a C++ member function is
3997 // "const" we have to look at the const-ness of "this"...
3998 // Ugly, but that
3999 if (arg_idx == 0)
4000 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004001 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004002 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004003 // Often times compilers omit the "this" name for the
4004 // specification DIEs, so we can't rely upon the name
4005 // being in the formal parameter DIE...
4006 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004007 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004008 Type *this_type = ResolveTypeUID (param_type_die_offset);
4009 if (this_type)
4010 {
4011 uint32_t encoding_mask = this_type->GetEncodingMask();
4012 if (encoding_mask & Type::eEncodingIsPointerUID)
4013 {
4014 is_static = false;
4015
4016 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4017 type_quals |= clang::Qualifiers::Const;
4018 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4019 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004020 }
4021 }
4022 }
4023 }
4024 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004025 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004026 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004027 else
4028 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004029
Greg Clayton0fffff52010-09-24 05:15:53 +00004030 // HACK: Objective C formal parameters "self" and "_cmd"
4031 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004032 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4033 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004034 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004035 switch (comp_unit->GetLanguage())
4036 {
4037 case eLanguageTypeObjC:
4038 case eLanguageTypeObjC_plus_plus:
4039 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4040 skip = true;
4041 break;
4042 default:
4043 break;
4044 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004045 }
4046 }
4047 }
4048
4049 if (!skip)
4050 {
4051 Type *type = ResolveTypeUID(param_type_die_offset);
4052 if (type)
4053 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004054 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004055
Greg Clayton42ce2f32011-12-12 21:50:19 +00004056 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4057 type->GetClangForwardType(),
4058 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004059 assert(param_var_decl);
4060 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004061
Jim Ingham379397632012-10-27 02:54:13 +00004062 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004063 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004064 }
4065 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004066 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004067 }
4068 break;
4069
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004070 case DW_TAG_template_type_parameter:
4071 case DW_TAG_template_value_parameter:
4072 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4073 break;
4074
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004075 default:
4076 break;
4077 }
4078 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004079 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004080}
4081
4082size_t
4083SymbolFileDWARF::ParseChildEnumerators
4084(
4085 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004086 clang_type_t enumerator_clang_type,
4087 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004088 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004089 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004090 const DWARFDebugInfoEntry *parent_die
4091)
4092{
4093 if (parent_die == NULL)
4094 return 0;
4095
4096 size_t enumerators_added = 0;
4097 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004098 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4099
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004100 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4101 {
4102 const dw_tag_t tag = die->Tag();
4103 if (tag == DW_TAG_enumerator)
4104 {
4105 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004106 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004107 if (num_child_attributes > 0)
4108 {
4109 const char *name = NULL;
4110 bool got_value = false;
4111 int64_t enum_value = 0;
4112 Declaration decl;
4113
4114 uint32_t i;
4115 for (i=0; i<num_child_attributes; ++i)
4116 {
4117 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4118 DWARFFormValue form_value;
4119 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4120 {
4121 switch (attr)
4122 {
4123 case DW_AT_const_value:
4124 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004125 if (is_signed)
4126 enum_value = form_value.Signed();
4127 else
4128 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004129 break;
4130
4131 case DW_AT_name:
4132 name = form_value.AsCString(&get_debug_str_data());
4133 break;
4134
4135 case DW_AT_description:
4136 default:
4137 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4138 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4139 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4140 case DW_AT_sibling:
4141 break;
4142 }
4143 }
4144 }
4145
4146 if (name && name[0] && got_value)
4147 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004148 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4149 enumerator_clang_type,
4150 decl,
4151 name,
4152 enum_value,
4153 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004154 ++enumerators_added;
4155 }
4156 }
4157 }
4158 }
4159 return enumerators_added;
4160}
4161
4162void
4163SymbolFileDWARF::ParseChildArrayInfo
4164(
4165 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004166 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004167 const DWARFDebugInfoEntry *parent_die,
4168 int64_t& first_index,
4169 std::vector<uint64_t>& element_orders,
4170 uint32_t& byte_stride,
4171 uint32_t& bit_stride
4172)
4173{
4174 if (parent_die == NULL)
4175 return;
4176
4177 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004178 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004179 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4180 {
4181 const dw_tag_t tag = die->Tag();
4182 switch (tag)
4183 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004184 case DW_TAG_subrange_type:
4185 {
4186 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004187 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004188 if (num_child_attributes > 0)
4189 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004190 uint64_t num_elements = 0;
4191 uint64_t lower_bound = 0;
4192 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004193 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004194 uint32_t i;
4195 for (i=0; i<num_child_attributes; ++i)
4196 {
4197 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4198 DWARFFormValue form_value;
4199 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4200 {
4201 switch (attr)
4202 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004203 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204 break;
4205
4206 case DW_AT_count:
4207 num_elements = form_value.Unsigned();
4208 break;
4209
4210 case DW_AT_bit_stride:
4211 bit_stride = form_value.Unsigned();
4212 break;
4213
4214 case DW_AT_byte_stride:
4215 byte_stride = form_value.Unsigned();
4216 break;
4217
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 case DW_AT_lower_bound:
4219 lower_bound = form_value.Unsigned();
4220 break;
4221
4222 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004223 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004224 upper_bound = form_value.Unsigned();
4225 break;
4226
4227 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228 case DW_AT_abstract_origin:
4229 case DW_AT_accessibility:
4230 case DW_AT_allocated:
4231 case DW_AT_associated:
4232 case DW_AT_data_location:
4233 case DW_AT_declaration:
4234 case DW_AT_description:
4235 case DW_AT_sibling:
4236 case DW_AT_threads_scaled:
4237 case DW_AT_type:
4238 case DW_AT_visibility:
4239 break;
4240 }
4241 }
4242 }
4243
Greg Claytone6a07792012-12-05 21:59:39 +00004244 if (num_elements == 0)
4245 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004246 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004247 num_elements = upper_bound - lower_bound + 1;
4248 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004249
Sean Callananec979ba2012-10-22 23:56:48 +00004250 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004251 }
4252 }
4253 break;
4254 }
4255 }
4256}
4257
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004258TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004259SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004260{
4261 TypeSP type_sp;
4262 if (die != NULL)
4263 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004264 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004265 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004266 if (type_ptr == NULL)
4267 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004268 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004269 assert (lldb_cu);
4270 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004271 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004272 }
4273 else if (type_ptr != DIE_IS_BEING_PARSED)
4274 {
4275 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004276 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004277 }
4278
4279 }
4280 return type_sp;
4281}
4282
4283clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004284SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004285{
4286 if (die_offset != DW_INVALID_OFFSET)
4287 {
4288 DWARFCompileUnitSP cu_sp;
4289 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004290 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004291 }
4292 return NULL;
4293}
4294
Sean Callanan72e49402011-08-05 23:43:37 +00004295clang::DeclContext *
4296SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4297{
4298 if (die_offset != DW_INVALID_OFFSET)
4299 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004300 DWARFDebugInfo* debug_info = DebugInfo();
4301 if (debug_info)
4302 {
4303 DWARFCompileUnitSP cu_sp;
4304 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4305 if (die)
4306 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4307 }
Sean Callanan72e49402011-08-05 23:43:37 +00004308 }
4309 return NULL;
4310}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004311
Greg Clayton96d7d742010-11-10 23:42:09 +00004312clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004313SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004314{
Greg Clayton030a2042011-10-14 21:34:45 +00004315 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004316 {
Greg Clayton030a2042011-10-14 21:34:45 +00004317 // See if we already parsed this namespace DIE and associated it with a
4318 // uniqued namespace declaration
4319 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4320 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004321 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004322 else
4323 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004324 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4325 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004326 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4327 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4328 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004329 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004330 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004331 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004332 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004333 "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 +00004334 GetClangASTContext().getASTContext(),
4335 MakeUserID(die->GetOffset()),
4336 namespace_name,
4337 namespace_decl,
4338 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004339 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004340 else
4341 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004342 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004343 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004344 GetClangASTContext().getASTContext(),
4345 MakeUserID(die->GetOffset()),
4346 namespace_decl,
4347 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004348 }
Greg Clayton030a2042011-10-14 21:34:45 +00004349 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004350
4351 if (namespace_decl)
4352 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4353 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004354 }
4355 }
4356 return NULL;
4357}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004358
4359clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004360SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004361{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004362 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4363 if (clang_decl_ctx)
4364 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004365 // If this DIE has a specification, or an abstract origin, then trace to those.
4366
Greg Claytoncab36a32011-12-08 05:16:30 +00004367 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004368 if (die_offset != DW_INVALID_OFFSET)
4369 return GetClangDeclContextForDIEOffset (sc, die_offset);
4370
Greg Claytoncab36a32011-12-08 05:16:30 +00004371 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004372 if (die_offset != DW_INVALID_OFFSET)
4373 return GetClangDeclContextForDIEOffset (sc, die_offset);
4374
Greg Clayton3bffb082011-12-10 02:15:28 +00004375 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4376 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004377 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 +00004378 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004379 bool assert_not_being_parsed = true;
4380 ResolveTypeUID (cu, die, assert_not_being_parsed);
4381
Greg Clayton5cf58b92011-10-05 22:22:08 +00004382 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4383
4384 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004385}
4386
4387clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004388SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004389{
Greg Claytonca512b32011-01-14 04:54:56 +00004390 if (m_clang_tu_decl == NULL)
4391 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004392
Greg Clayton2bc22f82011-09-30 03:20:47 +00004393 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004394
4395 if (decl_ctx_die_copy)
4396 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004397
4398 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004399 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004400
Greg Clayton2bc22f82011-09-30 03:20:47 +00004401 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4402 if (pos != m_die_to_decl_ctx.end())
4403 return pos->second;
4404
4405 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004406 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004407 case DW_TAG_compile_unit:
4408 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004409
Greg Clayton2bc22f82011-09-30 03:20:47 +00004410 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004411 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004412 break;
4413
4414 case DW_TAG_structure_type:
4415 case DW_TAG_union_type:
4416 case DW_TAG_class_type:
4417 {
4418 Type* type = ResolveType (cu, decl_ctx_die);
4419 if (type)
4420 {
4421 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4422 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004423 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004424 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4425 if (decl_ctx)
4426 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004427 }
4428 }
Greg Claytonca512b32011-01-14 04:54:56 +00004429 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004430 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431
Greg Clayton2bc22f82011-09-30 03:20:47 +00004432 default:
4433 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004434 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435 }
Greg Clayton7a345282010-11-09 23:46:37 +00004436 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004437}
4438
Greg Clayton2bc22f82011-09-30 03:20:47 +00004439
4440const DWARFDebugInfoEntry *
4441SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4442{
4443 if (cu && die)
4444 {
4445 const DWARFDebugInfoEntry * const decl_die = die;
4446
4447 while (die != NULL)
4448 {
4449 // If this is the original DIE that we are searching for a declaration
4450 // for, then don't look in the cache as we don't want our own decl
4451 // context to be our decl context...
4452 if (decl_die != die)
4453 {
4454 switch (die->Tag())
4455 {
4456 case DW_TAG_compile_unit:
4457 case DW_TAG_namespace:
4458 case DW_TAG_structure_type:
4459 case DW_TAG_union_type:
4460 case DW_TAG_class_type:
4461 return die;
4462
4463 default:
4464 break;
4465 }
4466 }
4467
4468 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4469 if (die_offset != DW_INVALID_OFFSET)
4470 {
4471 DWARFCompileUnit *spec_cu = cu;
4472 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4473 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4474 if (spec_die_decl_ctx_die)
4475 return spec_die_decl_ctx_die;
4476 }
4477
4478 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4479 if (die_offset != DW_INVALID_OFFSET)
4480 {
4481 DWARFCompileUnit *abs_cu = cu;
4482 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4483 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4484 if (abs_die_decl_ctx_die)
4485 return abs_die_decl_ctx_die;
4486 }
4487
4488 die = die->GetParent();
4489 }
4490 }
4491 return NULL;
4492}
4493
4494
Greg Clayton901c5ca2011-12-03 04:40:03 +00004495Symbol *
4496SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4497{
4498 Symbol *objc_class_symbol = NULL;
4499 if (m_obj_file)
4500 {
4501 Symtab *symtab = m_obj_file->GetSymtab();
4502 if (symtab)
4503 {
4504 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4505 eSymbolTypeObjCClass,
4506 Symtab::eDebugNo,
4507 Symtab::eVisibilityAny);
4508 }
4509 }
4510 return objc_class_symbol;
4511}
4512
Greg Claytonc7f03b62012-01-12 04:33:28 +00004513// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4514// then we can end up looking through all class types for a complete type and never find
4515// the full definition. We need to know if this attribute is supported, so we determine
4516// this here and cache th result. We also need to worry about the debug map DWARF file
4517// if we are doing darwin DWARF in .o file debugging.
4518bool
4519SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4520{
4521 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4522 {
4523 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4524 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4525 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4526 else
4527 {
4528 DWARFDebugInfo* debug_info = DebugInfo();
4529 const uint32_t num_compile_units = GetNumCompileUnits();
4530 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4531 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004532 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4533 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004534 {
4535 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4536 break;
4537 }
4538 }
4539 }
Greg Clayton1f746072012-08-29 21:13:06 +00004540 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004541 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4542 }
4543 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4544}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004545
4546// This function can be used when a DIE is found that is a forward declaration
4547// DIE and we want to try and find a type that has the complete definition.
4548TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004549SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4550 const ConstString &type_name,
4551 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004552{
4553
4554 TypeSP type_sp;
4555
Greg Claytonc7f03b62012-01-12 04:33:28 +00004556 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004557 return type_sp;
4558
4559 DIEArray die_offsets;
4560
4561 if (m_using_apple_tables)
4562 {
4563 if (m_apple_types_ap.get())
4564 {
4565 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004566 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004567 }
4568 }
4569 else
4570 {
4571 if (!m_indexed)
4572 Index ();
4573
4574 m_type_index.Find (type_name, die_offsets);
4575 }
4576
Greg Clayton901c5ca2011-12-03 04:40:03 +00004577 const size_t num_matches = die_offsets.size();
4578
Greg Clayton901c5ca2011-12-03 04:40:03 +00004579 DWARFCompileUnit* type_cu = NULL;
4580 const DWARFDebugInfoEntry* type_die = NULL;
4581 if (num_matches)
4582 {
4583 DWARFDebugInfo* debug_info = DebugInfo();
4584 for (size_t i=0; i<num_matches; ++i)
4585 {
4586 const dw_offset_t die_offset = die_offsets[i];
4587 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4588
4589 if (type_die)
4590 {
4591 bool try_resolving_type = false;
4592
4593 // Don't try and resolve the DIE we are looking for with the DIE itself!
4594 if (type_die != die)
4595 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004596 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004597 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004598 case DW_TAG_class_type:
4599 case DW_TAG_structure_type:
4600 try_resolving_type = true;
4601 break;
4602 default:
4603 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004604 }
4605 }
4606
4607 if (try_resolving_type)
4608 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004609 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004610 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004611
4612 if (try_resolving_type)
4613 {
4614 Type *resolved_type = ResolveType (type_cu, type_die, false);
4615 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4616 {
Daniel Malead01b2952012-11-29 21:49:15 +00004617 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 +00004618 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004619 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004620 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4621 MakeUserID(type_die->GetOffset()),
4622 MakeUserID(type_cu->GetOffset()));
4623
Greg Claytonc7f03b62012-01-12 04:33:28 +00004624 if (die)
4625 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004626 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004627 break;
4628 }
4629 }
4630 }
4631 }
4632 else
4633 {
4634 if (m_using_apple_tables)
4635 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004636 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4637 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004638 }
4639 }
4640
4641 }
4642 }
4643 return type_sp;
4644}
4645
Greg Claytona8022fa2012-04-24 21:22:41 +00004646
Greg Clayton80c26302012-02-05 06:12:47 +00004647//----------------------------------------------------------------------
4648// This function helps to ensure that the declaration contexts match for
4649// two different DIEs. Often times debug information will refer to a
4650// forward declaration of a type (the equivalent of "struct my_struct;".
4651// There will often be a declaration of that type elsewhere that has the
4652// full definition. When we go looking for the full type "my_struct", we
4653// will find one or more matches in the accelerator tables and we will
4654// then need to make sure the type was in the same declaration context
4655// as the original DIE. This function can efficiently compare two DIEs
4656// and will return true when the declaration context matches, and false
4657// when they don't.
4658//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004659bool
4660SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4661 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4662{
Greg Claytona8022fa2012-04-24 21:22:41 +00004663 if (die1 == die2)
4664 return true;
4665
4666#if defined (LLDB_CONFIGURATION_DEBUG)
4667 // You can't and shouldn't call this function with a compile unit from
4668 // two different SymbolFileDWARF instances.
4669 assert (DebugInfo()->ContainsCompileUnit (cu1));
4670 assert (DebugInfo()->ContainsCompileUnit (cu2));
4671#endif
4672
Greg Clayton890ff562012-02-02 05:48:16 +00004673 DWARFDIECollection decl_ctx_1;
4674 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004675 //The declaration DIE stack is a stack of the declaration context
4676 // DIEs all the way back to the compile unit. If a type "T" is
4677 // declared inside a class "B", and class "B" is declared inside
4678 // a class "A" and class "A" is in a namespace "lldb", and the
4679 // namespace is in a compile unit, there will be a stack of DIEs:
4680 //
4681 // [0] DW_TAG_class_type for "B"
4682 // [1] DW_TAG_class_type for "A"
4683 // [2] DW_TAG_namespace for "lldb"
4684 // [3] DW_TAG_compile_unit for the source file.
4685 //
4686 // We grab both contexts and make sure that everything matches
4687 // all the way back to the compiler unit.
4688
4689 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004690 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004691 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004692 // Make sure the context arrays have the same size, otherwise
4693 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004694 const size_t count1 = decl_ctx_1.Size();
4695 const size_t count2 = decl_ctx_2.Size();
4696 if (count1 != count2)
4697 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004698
4699 // Make sure the DW_TAG values match all the way back up the the
4700 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004701 const DWARFDebugInfoEntry *decl_ctx_die1;
4702 const DWARFDebugInfoEntry *decl_ctx_die2;
4703 size_t i;
4704 for (i=0; i<count1; i++)
4705 {
4706 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4707 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4708 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4709 return false;
4710 }
Greg Clayton890ff562012-02-02 05:48:16 +00004711#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004712
4713 // Make sure the top item in the decl context die array is always
4714 // DW_TAG_compile_unit. If it isn't then something went wrong in
4715 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004716 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004717
Greg Clayton890ff562012-02-02 05:48:16 +00004718#endif
4719 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004720 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004721 for (i=0; i<count1 - 1; i++)
4722 {
4723 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4724 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4725 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004726 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004727 // If the string was from a DW_FORM_strp, then the pointer will often
4728 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004729 if (name1 == name2)
4730 continue;
4731
4732 // Name pointers are not equal, so only compare the strings
4733 // if both are not NULL.
4734 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004735 {
Greg Clayton5569e642012-02-06 01:44:54 +00004736 // If the strings don't compare, we are done...
4737 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004738 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004739 }
4740 else
4741 {
4742 // One name was NULL while the other wasn't
4743 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004744 }
4745 }
Greg Clayton80c26302012-02-05 06:12:47 +00004746 // We made it through all of the checks and the declaration contexts
4747 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004748 return true;
4749}
Greg Clayton220a0072011-12-09 08:48:30 +00004750
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004751// This function can be used when a DIE is found that is a forward declaration
4752// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004753// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004754TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004755SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004756 const DWARFDebugInfoEntry *die,
4757 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004758{
4759 TypeSP type_sp;
4760
Greg Claytona8022fa2012-04-24 21:22:41 +00004761#if defined (LLDB_CONFIGURATION_DEBUG)
4762 // You can't and shouldn't call this function with a compile unit from
4763 // another SymbolFileDWARF instance.
4764 assert (DebugInfo()->ContainsCompileUnit (cu));
4765#endif
4766
Greg Clayton1a65ae12011-01-25 23:55:37 +00004767 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004768 return type_sp;
4769
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004770 std::string qualified_name;
4771
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004772 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4773 if (log)
4774 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004775 die->GetQualifiedName(this, cu, qualified_name);
4776 GetObjectFile()->GetModule()->LogMessage (log.get(),
4777 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4778 die->GetOffset(),
4779 qualified_name.c_str(),
4780 type_name.GetCString());
4781 }
4782
Greg Clayton7f995132011-10-04 22:41:51 +00004783 DIEArray die_offsets;
4784
Greg Clayton97fbc342011-10-20 22:30:33 +00004785 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004786 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004787 if (m_apple_types_ap.get())
4788 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004789 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4790 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4791 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004792 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004793 if (qualified_name.empty())
4794 die->GetQualifiedName(this, cu, qualified_name);
4795
4796 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4797 if (log)
4798 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
4799 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4800 }
4801 else if (has_tag > 1)
4802 {
4803 if (log)
4804 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004805 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004806 }
4807 else
4808 {
4809 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4810 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004811 }
Greg Clayton7f995132011-10-04 22:41:51 +00004812 }
4813 else
4814 {
4815 if (!m_indexed)
4816 Index ();
4817
4818 m_type_index.Find (type_name, die_offsets);
4819 }
Greg Clayton7f995132011-10-04 22:41:51 +00004820
4821 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004822
Greg Clayton934cb052011-12-03 00:27:05 +00004823 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004824
4825 DWARFCompileUnit* type_cu = NULL;
4826 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004827 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004828 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004829 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004830 for (size_t i=0; i<num_matches; ++i)
4831 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004832 const dw_offset_t die_offset = die_offsets[i];
4833 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004834
Greg Clayton95d87902011-11-11 03:16:25 +00004835 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004836 {
Greg Clayton934cb052011-12-03 00:27:05 +00004837 bool try_resolving_type = false;
4838
4839 // Don't try and resolve the DIE we are looking for with the DIE itself!
4840 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004841 {
Greg Clayton934cb052011-12-03 00:27:05 +00004842 const dw_tag_t type_die_tag = type_die->Tag();
4843 // Make sure the tags match
4844 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004845 {
Greg Clayton934cb052011-12-03 00:27:05 +00004846 // The tags match, lets try resolving this type
4847 try_resolving_type = true;
4848 }
4849 else
4850 {
4851 // The tags don't match, but we need to watch our for a
4852 // forward declaration for a struct and ("struct foo")
4853 // ends up being a class ("class foo { ... };") or
4854 // vice versa.
4855 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004856 {
Greg Clayton934cb052011-12-03 00:27:05 +00004857 case DW_TAG_class_type:
4858 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4859 try_resolving_type = (die_tag == DW_TAG_structure_type);
4860 break;
4861 case DW_TAG_structure_type:
4862 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4863 try_resolving_type = (die_tag == DW_TAG_class_type);
4864 break;
4865 default:
4866 // Tags don't match, don't event try to resolve
4867 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004868 break;
4869 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004870 }
4871 }
Greg Clayton934cb052011-12-03 00:27:05 +00004872
4873 if (try_resolving_type)
4874 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004875 if (log)
4876 {
4877 std::string qualified_name;
4878 type_die->GetQualifiedName(this, cu, qualified_name);
4879 GetObjectFile()->GetModule()->LogMessage (log.get(),
4880 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4881 die->GetOffset(),
4882 type_name.GetCString(),
4883 type_die->GetOffset(),
4884 qualified_name.c_str());
4885 }
4886
Greg Clayton890ff562012-02-02 05:48:16 +00004887 // Make sure the decl contexts match all the way up
4888 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004889 {
Greg Clayton890ff562012-02-02 05:48:16 +00004890 Type *resolved_type = ResolveType (type_cu, type_die, false);
4891 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4892 {
Daniel Malead01b2952012-11-29 21:49:15 +00004893 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 +00004894 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004895 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004896 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4897 MakeUserID(type_die->GetOffset()),
4898 MakeUserID(type_cu->GetOffset()));
4899
4900 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004901 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004902 break;
4903 }
Greg Clayton934cb052011-12-03 00:27:05 +00004904 }
4905 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004906 else
4907 {
4908 if (log)
4909 {
4910 std::string qualified_name;
4911 type_die->GetQualifiedName(this, cu, qualified_name);
4912 GetObjectFile()->GetModule()->LogMessage (log.get(),
4913 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4914 die->GetOffset(),
4915 type_name.GetCString(),
4916 type_die->GetOffset(),
4917 qualified_name.c_str());
4918 }
4919 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004920 }
Greg Clayton95d87902011-11-11 03:16:25 +00004921 else
4922 {
4923 if (m_using_apple_tables)
4924 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004925 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4926 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004927 }
4928 }
4929
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004930 }
4931 }
4932 return type_sp;
4933}
4934
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004935TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004936SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4937{
4938 TypeSP type_sp;
4939
4940 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4941 if (dwarf_decl_ctx_count > 0)
4942 {
4943 const ConstString type_name(dwarf_decl_ctx[0].name);
4944 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4945
4946 if (type_name)
4947 {
4948 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4949 if (log)
4950 {
4951 GetObjectFile()->GetModule()->LogMessage (log.get(),
4952 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4953 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4954 dwarf_decl_ctx.GetQualifiedName());
4955 }
4956
4957 DIEArray die_offsets;
4958
4959 if (m_using_apple_tables)
4960 {
4961 if (m_apple_types_ap.get())
4962 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004963 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4964 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4965 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00004966 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004967 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
4968 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
4969 if (log)
4970 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
4971 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
4972 }
4973 else if (has_tag)
4974 {
4975 if (log)
4976 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00004977 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4978 }
4979 else
4980 {
4981 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4982 }
4983 }
4984 }
4985 else
4986 {
4987 if (!m_indexed)
4988 Index ();
4989
4990 m_type_index.Find (type_name, die_offsets);
4991 }
4992
4993 const size_t num_matches = die_offsets.size();
4994
4995
4996 DWARFCompileUnit* type_cu = NULL;
4997 const DWARFDebugInfoEntry* type_die = NULL;
4998 if (num_matches)
4999 {
5000 DWARFDebugInfo* debug_info = DebugInfo();
5001 for (size_t i=0; i<num_matches; ++i)
5002 {
5003 const dw_offset_t die_offset = die_offsets[i];
5004 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5005
5006 if (type_die)
5007 {
5008 bool try_resolving_type = false;
5009
5010 // Don't try and resolve the DIE we are looking for with the DIE itself!
5011 const dw_tag_t type_tag = type_die->Tag();
5012 // Make sure the tags match
5013 if (type_tag == tag)
5014 {
5015 // The tags match, lets try resolving this type
5016 try_resolving_type = true;
5017 }
5018 else
5019 {
5020 // The tags don't match, but we need to watch our for a
5021 // forward declaration for a struct and ("struct foo")
5022 // ends up being a class ("class foo { ... };") or
5023 // vice versa.
5024 switch (type_tag)
5025 {
5026 case DW_TAG_class_type:
5027 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5028 try_resolving_type = (tag == DW_TAG_structure_type);
5029 break;
5030 case DW_TAG_structure_type:
5031 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5032 try_resolving_type = (tag == DW_TAG_class_type);
5033 break;
5034 default:
5035 // Tags don't match, don't event try to resolve
5036 // using this type whose name matches....
5037 break;
5038 }
5039 }
5040
5041 if (try_resolving_type)
5042 {
5043 DWARFDeclContext type_dwarf_decl_ctx;
5044 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5045
5046 if (log)
5047 {
5048 GetObjectFile()->GetModule()->LogMessage (log.get(),
5049 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5050 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5051 dwarf_decl_ctx.GetQualifiedName(),
5052 type_die->GetOffset(),
5053 type_dwarf_decl_ctx.GetQualifiedName());
5054 }
5055
5056 // Make sure the decl contexts match all the way up
5057 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5058 {
5059 Type *resolved_type = ResolveType (type_cu, type_die, false);
5060 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5061 {
5062 type_sp = resolved_type->shared_from_this();
5063 break;
5064 }
5065 }
5066 }
5067 else
5068 {
5069 if (log)
5070 {
5071 std::string qualified_name;
5072 type_die->GetQualifiedName(this, type_cu, qualified_name);
5073 GetObjectFile()->GetModule()->LogMessage (log.get(),
5074 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5075 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5076 dwarf_decl_ctx.GetQualifiedName(),
5077 type_die->GetOffset(),
5078 qualified_name.c_str());
5079 }
5080 }
5081 }
5082 else
5083 {
5084 if (m_using_apple_tables)
5085 {
5086 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5087 die_offset, type_name.GetCString());
5088 }
5089 }
5090
5091 }
5092 }
5093 }
5094 }
5095 return type_sp;
5096}
5097
Greg Clayton4116e932012-05-15 02:33:01 +00005098bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005099SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005100 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005101 DWARFCompileUnit* src_cu,
5102 const DWARFDebugInfoEntry *src_class_die,
5103 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005104 const DWARFDebugInfoEntry *dst_class_die,
5105 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005106{
5107 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5108 return false;
5109 if (src_class_die->Tag() != dst_class_die->Tag())
5110 return false;
5111
5112 // We need to complete the class type so we can get all of the method types
5113 // parsed so we can then unique those types to their equivalent counterparts
5114 // in "dst_cu" and "dst_class_die"
5115 class_type->GetClangFullType();
5116
5117 const DWARFDebugInfoEntry *src_die;
5118 const DWARFDebugInfoEntry *dst_die;
5119 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5120 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005121 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5122 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005123 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5124 {
5125 if (src_die->Tag() == DW_TAG_subprogram)
5126 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005127 // Make sure this is a declaration and not a concrete instance by looking
5128 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5129 // are placed inside the class definitions and shouldn't be included in
5130 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005131 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005132 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005133 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005134 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005135 {
5136 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005137 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005138 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5139 else
5140 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5141 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005142 }
Greg Clayton4116e932012-05-15 02:33:01 +00005143 }
5144 }
5145 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5146 {
5147 if (dst_die->Tag() == DW_TAG_subprogram)
5148 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005149 // Make sure this is a declaration and not a concrete instance by looking
5150 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5151 // are placed inside the class definitions and shouldn't be included in
5152 // the list of things are are tracking here.
5153 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5154 {
5155 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5156 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005157 {
5158 ConstString dst_const_name(dst_name);
5159 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5160 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5161 else
5162 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5163 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005164 }
Greg Clayton4116e932012-05-15 02:33:01 +00005165 }
5166 }
5167 const uint32_t src_size = src_name_to_die.GetSize ();
5168 const uint32_t dst_size = dst_name_to_die.GetSize ();
5169 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005170
5171 // Is everything kosher so we can go through the members at top speed?
5172 bool fast_path = true;
5173
5174 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005175 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005176 if (src_size != 0 && dst_size != 0)
5177 {
5178 if (log)
5179 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)",
5180 src_class_die->GetOffset(),
5181 dst_class_die->GetOffset(),
5182 src_size,
5183 dst_size);
5184 }
5185
5186 fast_path = false;
5187 }
5188
5189 uint32_t idx;
5190
5191 if (fast_path)
5192 {
Greg Clayton4116e932012-05-15 02:33:01 +00005193 for (idx = 0; idx < src_size; ++idx)
5194 {
5195 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5196 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5197
5198 if (src_die->Tag() != dst_die->Tag())
5199 {
5200 if (log)
5201 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)",
5202 src_class_die->GetOffset(),
5203 dst_class_die->GetOffset(),
5204 src_die->GetOffset(),
5205 DW_TAG_value_to_name(src_die->Tag()),
5206 dst_die->GetOffset(),
5207 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005208 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005209 }
5210
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005211 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005212 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5213
5214 // Make sure the names match
5215 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5216 continue;
5217
5218 if (log)
5219 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)",
5220 src_class_die->GetOffset(),
5221 dst_class_die->GetOffset(),
5222 src_die->GetOffset(),
5223 src_name,
5224 dst_die->GetOffset(),
5225 dst_name);
5226
Sean Callanan2367f8a2013-02-26 01:12:25 +00005227 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005228 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005229 }
Greg Clayton4116e932012-05-15 02:33:01 +00005230
Sean Callanan2367f8a2013-02-26 01:12:25 +00005231 // Now do the work of linking the DeclContexts and Types.
5232 if (fast_path)
5233 {
5234 // We can do this quickly. Just run across the tables index-for-index since
5235 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005236 for (idx = 0; idx < src_size; ++idx)
5237 {
5238 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5239 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5240
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005241 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005242 if (src_decl_ctx)
5243 {
5244 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005245 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 +00005246 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5247 }
5248 else
5249 {
5250 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005251 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 +00005252 }
5253
5254 Type *src_child_type = m_die_to_type[src_die];
5255 if (src_child_type)
5256 {
5257 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005258 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 +00005259 m_die_to_type[dst_die] = src_child_type;
5260 }
5261 else
5262 {
5263 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005264 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());
5265 }
5266 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005267 }
5268 else
5269 {
5270 // We must do this slowly. For each member of the destination, look
5271 // up a member in the source with the same name, check its tag, and
5272 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005273
Sean Callanan2367f8a2013-02-26 01:12:25 +00005274 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5275 {
5276 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005277
Sean Callanan2367f8a2013-02-26 01:12:25 +00005278 for (idx = 0; idx < dst_size; ++idx)
5279 {
5280 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5281 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5282 src_die = src_name_to_die.Find(dst_name, NULL);
5283
5284 if (src_die && (src_die->Tag() == dst_die->Tag()))
5285 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005286 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005287 if (src_decl_ctx)
5288 {
5289 if (log)
5290 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5291 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5292 }
5293 else
5294 {
5295 if (log)
5296 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());
5297 }
5298
5299 Type *src_child_type = m_die_to_type[src_die];
5300 if (src_child_type)
5301 {
5302 if (log)
5303 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());
5304 m_die_to_type[dst_die] = src_child_type;
5305 }
5306 else
5307 {
5308 if (log)
5309 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());
5310 }
5311 }
5312 else
5313 {
5314 if (log)
5315 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005316
Sean Callanan2367f8a2013-02-26 01:12:25 +00005317 failures.push_back(dst_die);
5318 }
5319 }
5320 }
5321 }
5322
5323 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5324 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5325
5326 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5327
5328 if (src_size_artificial && dst_size_artificial)
5329 {
5330 dst_name_to_die_artificial.Sort();
5331
Greg Clayton65ec1032012-11-12 21:27:20 +00005332 for (idx = 0; idx < src_size_artificial; ++idx)
5333 {
5334 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5335 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5336 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5337
5338 if (dst_die)
5339 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005340 // Both classes have the artificial types, link them
5341 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5342 if (src_decl_ctx)
5343 {
5344 if (log)
5345 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5346 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5347 }
5348 else
5349 {
5350 if (log)
5351 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());
5352 }
5353
5354 Type *src_child_type = m_die_to_type[src_die];
5355 if (src_child_type)
5356 {
5357 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005358 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 +00005359 m_die_to_type[dst_die] = src_child_type;
5360 }
5361 else
5362 {
5363 if (log)
5364 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());
5365 }
5366 }
5367 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005368 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005369
Sean Callanan2367f8a2013-02-26 01:12:25 +00005370 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005371 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005372 for (idx = 0; idx < dst_size_artificial; ++idx)
5373 {
5374 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5375 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5376 if (log)
5377 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5378
5379 failures.push_back(dst_die);
5380 }
Greg Clayton4116e932012-05-15 02:33:01 +00005381 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005382
5383 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005384}
Greg Claytona8022fa2012-04-24 21:22:41 +00005385
5386TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005387SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005388{
5389 TypeSP type_sp;
5390
Greg Clayton1be10fc2010-09-29 01:12:09 +00005391 if (type_is_new_ptr)
5392 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005393
5394#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5395 static DIEStack g_die_stack;
5396 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5397#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005398
Sean Callananc7fbf732010-08-06 00:32:49 +00005399 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005400 if (die != NULL)
5401 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005402 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005403 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005404 {
5405 const DWARFDebugInfoEntry *context_die;
5406 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5407
Greg Clayton1fba87112012-02-09 20:03:49 +00005408 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 +00005409 die->GetOffset(),
5410 context,
5411 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005412 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005413 die->GetName(this, dwarf_cu));
5414
5415#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5416 scoped_die_logger.Push (dwarf_cu, die);
5417 g_die_stack.LogDIEs(log.get(), this);
5418#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005419 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005420//
5421// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5422// if (log && dwarf_cu)
5423// {
5424// StreamString s;
5425// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005426// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005427//
5428// }
Jim Ingham16746d12011-08-25 23:21:43 +00005429
Greg Clayton594e5ed2010-09-27 21:07:38 +00005430 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005431 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005432 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005433 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005434 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005435 if (type_is_new_ptr)
5436 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005437
Greg Clayton594e5ed2010-09-27 21:07:38 +00005438 const dw_tag_t tag = die->Tag();
5439
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005440 bool is_forward_declaration = false;
5441 DWARFDebugInfoEntry::Attributes attributes;
5442 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005443 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005444 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5445 size_t byte_size = 0;
5446 Declaration decl;
5447
Greg Clayton4957bf62010-09-30 21:49:03 +00005448 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005449 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005450
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005451 dw_attr_t attr;
5452
5453 switch (tag)
5454 {
5455 case DW_TAG_base_type:
5456 case DW_TAG_pointer_type:
5457 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005458 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005459 case DW_TAG_typedef:
5460 case DW_TAG_const_type:
5461 case DW_TAG_restrict_type:
5462 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005463 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005464 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005465 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005466 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005467
Greg Claytond88d7592010-09-15 08:33:30 +00005468 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005469 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005470 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5471
5472 if (num_attributes > 0)
5473 {
5474 uint32_t i;
5475 for (i=0; i<num_attributes; ++i)
5476 {
5477 attr = attributes.AttributeAtIndex(i);
5478 DWARFFormValue form_value;
5479 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5480 {
5481 switch (attr)
5482 {
5483 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5484 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5485 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5486 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005487
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005488 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005489 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5490 // include the "&"...
5491 if (tag == DW_TAG_reference_type)
5492 {
5493 if (strchr (type_name_cstr, '&') == NULL)
5494 type_name_cstr = NULL;
5495 }
5496 if (type_name_cstr)
5497 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005498 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005499 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005500 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5501 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5502 default:
5503 case DW_AT_sibling:
5504 break;
5505 }
5506 }
5507 }
5508 }
5509
Daniel Malead01b2952012-11-29 21:49:15 +00005510 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 +00005511
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005512 switch (tag)
5513 {
5514 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005515 break;
5516
Greg Claytond4436412011-10-28 21:00:00 +00005517 case DW_TAG_unspecified_type:
5518 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5519 {
5520 resolve_state = Type::eResolveStateFull;
5521 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5522 break;
5523 }
5524 // Fall through to base type below in case we can handle the type there...
5525
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005526 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005527 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005528 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5529 encoding,
5530 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005531 break;
5532
Sean Callanance8af862012-05-21 23:31:51 +00005533 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5534 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5535 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5536 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5537 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5538 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5539 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005540 }
5541
Sean Callanan82587052013-01-03 00:05:56 +00005542 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 +00005543 {
Sean Callanan82587052013-01-03 00:05:56 +00005544 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5545
5546 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005547 {
Sean Callanan82587052013-01-03 00:05:56 +00005548 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005549 {
Sean Callanan82587052013-01-03 00:05:56 +00005550 static ConstString g_objc_type_name_id("id");
5551 static ConstString g_objc_type_name_Class("Class");
5552 static ConstString g_objc_type_name_selector("SEL");
5553
5554 if (type_name_const_str == g_objc_type_name_id)
5555 {
5556 if (log)
5557 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5558 die->GetOffset(),
5559 DW_TAG_value_to_name(die->Tag()),
5560 die->GetName(this, dwarf_cu));
5561 clang_type = ast.GetBuiltInType_objc_id();
5562 encoding_data_type = Type::eEncodingIsUID;
5563 encoding_uid = LLDB_INVALID_UID;
5564 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005565
Sean Callanan82587052013-01-03 00:05:56 +00005566 }
5567 else if (type_name_const_str == g_objc_type_name_Class)
5568 {
5569 if (log)
5570 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5571 die->GetOffset(),
5572 DW_TAG_value_to_name(die->Tag()),
5573 die->GetName(this, dwarf_cu));
5574 clang_type = ast.GetBuiltInType_objc_Class();
5575 encoding_data_type = Type::eEncodingIsUID;
5576 encoding_uid = LLDB_INVALID_UID;
5577 resolve_state = Type::eResolveStateFull;
5578 }
5579 else if (type_name_const_str == g_objc_type_name_selector)
5580 {
5581 if (log)
5582 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5583 die->GetOffset(),
5584 DW_TAG_value_to_name(die->Tag()),
5585 die->GetName(this, dwarf_cu));
5586 clang_type = ast.GetBuiltInType_objc_selector();
5587 encoding_data_type = Type::eEncodingIsUID;
5588 encoding_uid = LLDB_INVALID_UID;
5589 resolve_state = Type::eResolveStateFull;
5590 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005591 }
Sean Callanan82587052013-01-03 00:05:56 +00005592 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005593 {
Sean Callanan82587052013-01-03 00:05:56 +00005594 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5595
5596 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5597
5598 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5599 {
5600 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5601 {
5602 if (!strcmp(struct_name, "objc_object"))
5603 {
5604 if (log)
5605 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
5606 die->GetOffset(),
5607 DW_TAG_value_to_name(die->Tag()),
5608 die->GetName(this, dwarf_cu));
5609 clang_type = ast.GetBuiltInType_objc_id();
5610 encoding_data_type = Type::eEncodingIsUID;
5611 encoding_uid = LLDB_INVALID_UID;
5612 resolve_state = Type::eResolveStateFull;
5613 }
5614 }
5615 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005616 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005617 }
5618 }
5619
Greg Clayton81c22f62011-10-19 18:09:39 +00005620 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005621 this,
5622 type_name_const_str,
5623 byte_size,
5624 NULL,
5625 encoding_uid,
5626 encoding_data_type,
5627 &decl,
5628 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005629 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005630
Greg Clayton594e5ed2010-09-27 21:07:38 +00005631 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005632
5633// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5634// if (encoding_type != NULL)
5635// {
5636// if (encoding_type != DIE_IS_BEING_PARSED)
5637// type_sp->SetEncodingType(encoding_type);
5638// else
5639// m_indirect_fixups.push_back(type_sp.get());
5640// }
5641 }
5642 break;
5643
5644 case DW_TAG_structure_type:
5645 case DW_TAG_union_type:
5646 case DW_TAG_class_type:
5647 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005648 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005649 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005650 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005651
Greg Clayton9e409562010-07-28 02:04:09 +00005652 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005653 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005654 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005655 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005656 if (num_attributes > 0)
5657 {
5658 uint32_t i;
5659 for (i=0; i<num_attributes; ++i)
5660 {
5661 attr = attributes.AttributeAtIndex(i);
5662 DWARFFormValue form_value;
5663 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5664 {
5665 switch (attr)
5666 {
Greg Clayton9e409562010-07-28 02:04:09 +00005667 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005668 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5669 {
5670 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5671 // point to the compile unit file, so we clear this invalid value
5672 // so that we can still unique types efficiently.
5673 decl.SetFile(FileSpec ("<invalid>", false));
5674 }
5675 else
5676 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005677 break;
5678
5679 case DW_AT_decl_line:
5680 decl.SetLine(form_value.Unsigned());
5681 break;
5682
5683 case DW_AT_decl_column:
5684 decl.SetColumn(form_value.Unsigned());
5685 break;
5686
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005687 case DW_AT_name:
5688 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005689 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005690 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005691
5692 case DW_AT_byte_size:
5693 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005694 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005695 break;
5696
5697 case DW_AT_accessibility:
5698 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5699 break;
5700
5701 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005702 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005703 break;
5704
5705 case DW_AT_APPLE_runtime_class:
5706 class_language = (LanguageType)form_value.Signed();
5707 break;
5708
Greg Clayton18774842011-11-29 23:40:34 +00005709 case DW_AT_APPLE_objc_complete_type:
5710 is_complete_objc_class = form_value.Signed();
5711 break;
5712
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005713 case DW_AT_allocated:
5714 case DW_AT_associated:
5715 case DW_AT_data_location:
5716 case DW_AT_description:
5717 case DW_AT_start_scope:
5718 case DW_AT_visibility:
5719 default:
5720 case DW_AT_sibling:
5721 break;
5722 }
5723 }
5724 }
5725 }
5726
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005727 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005728
Greg Clayton123edca2012-03-02 00:07:15 +00005729 // Only try and unique the type if it has a name.
5730 if (type_name_const_str &&
5731 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005732 this,
5733 dwarf_cu,
5734 die,
5735 decl,
5736 byte_size_valid ? byte_size : -1,
5737 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005738 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005739 // We have already parsed this type or from another
5740 // compile unit. GCC loves to use the "one definition
5741 // rule" which can result in multiple definitions
5742 // of the same class over and over in each compile
5743 // unit.
5744 type_sp = unique_ast_entry.m_type_sp;
5745 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005746 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005747 m_die_to_type[die] = type_sp.get();
5748 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005749 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005750 }
5751
Daniel Malead01b2952012-11-29 21:49:15 +00005752 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 +00005753
5754 int tag_decl_kind = -1;
5755 AccessType default_accessibility = eAccessNone;
5756 if (tag == DW_TAG_structure_type)
5757 {
5758 tag_decl_kind = clang::TTK_Struct;
5759 default_accessibility = eAccessPublic;
5760 }
5761 else if (tag == DW_TAG_union_type)
5762 {
5763 tag_decl_kind = clang::TTK_Union;
5764 default_accessibility = eAccessPublic;
5765 }
5766 else if (tag == DW_TAG_class_type)
5767 {
5768 tag_decl_kind = clang::TTK_Class;
5769 default_accessibility = eAccessPrivate;
5770 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005771
5772 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5773 die->HasChildren() == false &&
5774 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5775 {
5776 // Work around an issue with clang at the moment where
5777 // forward declarations for objective C classes are emitted
5778 // as:
5779 // DW_TAG_structure_type [2]
5780 // DW_AT_name( "ForwardObjcClass" )
5781 // DW_AT_byte_size( 0x00 )
5782 // DW_AT_decl_file( "..." )
5783 // DW_AT_decl_line( 1 )
5784 //
5785 // Note that there is no DW_AT_declaration and there are
5786 // no children, and the byte size is zero.
5787 is_forward_declaration = true;
5788 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005789
Sean Callanan7457f8d2012-04-25 01:03:57 +00005790 if (class_language == eLanguageTypeObjC ||
5791 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005792 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005793 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005794 {
5795 // We have a valid eSymbolTypeObjCClass class symbol whose
5796 // name matches the current objective C class that we
5797 // are trying to find and this DIE isn't the complete
5798 // definition (we checked is_complete_objc_class above and
5799 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005800 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005801
Greg Clayton1f746072012-08-29 21:13:06 +00005802 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005803 {
5804 // We weren't able to find a full declaration in
5805 // this DWARF, see if we have a declaration anywhere
5806 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005807 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005808 }
5809
5810 if (type_sp)
5811 {
5812 if (log)
5813 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005814 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005815 "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 +00005816 this,
5817 die->GetOffset(),
5818 DW_TAG_value_to_name(tag),
5819 type_name_cstr,
5820 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005821 }
5822
5823 // We found a real definition for this type elsewhere
5824 // so lets use it and cache the fact that we found
5825 // a complete type for this die
5826 m_die_to_type[die] = type_sp.get();
5827 return type_sp;
5828 }
5829 }
5830 }
5831
5832
5833 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005834 {
5835 // We have a forward declaration to a type and we need
5836 // to try and find a full declaration. We look in the
5837 // current type index just in case we have a forward
5838 // declaration followed by an actual declarations in the
5839 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005840 if (log)
5841 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005842 GetObjectFile()->GetModule()->LogMessage (log.get(),
5843 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5844 this,
5845 die->GetOffset(),
5846 DW_TAG_value_to_name(tag),
5847 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005848 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005849
Greg Claytona8022fa2012-04-24 21:22:41 +00005850 DWARFDeclContext die_decl_ctx;
5851 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5852
5853 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5854 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005855
Greg Clayton1f746072012-08-29 21:13:06 +00005856 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005857 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005858 // We weren't able to find a full declaration in
5859 // this DWARF, see if we have a declaration anywhere
5860 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005861 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005862 }
5863
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005864 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005865 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005866 if (log)
5867 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005868 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005869 "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 +00005870 this,
5871 die->GetOffset(),
5872 DW_TAG_value_to_name(tag),
5873 type_name_cstr,
5874 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005875 }
5876
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005877 // We found a real definition for this type elsewhere
5878 // so lets use it and cache the fact that we found
5879 // a complete type for this die
5880 m_die_to_type[die] = type_sp.get();
5881 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005882 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005883 }
5884 assert (tag_decl_kind != -1);
5885 bool clang_type_was_created = false;
5886 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5887 if (clang_type == NULL)
5888 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005889 const DWARFDebugInfoEntry *decl_ctx_die;
5890
5891 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005892 if (accessibility == eAccessNone && decl_ctx)
5893 {
5894 // Check the decl context that contains this class/struct/union.
5895 // If it is a class we must give it an accessability.
5896 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5897 if (DeclKindIsCXXClass (containing_decl_kind))
5898 accessibility = default_accessibility;
5899 }
5900
Greg Claytonc4ffd662013-03-08 01:37:30 +00005901 ClangASTMetadata metadata;
5902 metadata.SetUserID(MakeUserID(die->GetOffset()));
5903 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
5904
Greg Claytonf0705c82011-10-22 03:33:13 +00005905 if (type_name_cstr && strchr (type_name_cstr, '<'))
5906 {
5907 ClangASTContext::TemplateParameterInfos template_param_infos;
5908 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5909 {
5910 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005911 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005912 type_name_cstr,
5913 tag_decl_kind,
5914 template_param_infos);
5915
5916 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5917 class_template_decl,
5918 tag_decl_kind,
5919 template_param_infos);
5920 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5921 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005922
Greg Claytonc4ffd662013-03-08 01:37:30 +00005923 GetClangASTContext().SetMetadata ((uintptr_t)class_template_decl, metadata);
5924 GetClangASTContext().SetMetadata ((uintptr_t)class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005925 }
5926 }
5927
5928 if (!clang_type_was_created)
5929 {
5930 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005931 clang_type = ast.CreateRecordType (decl_ctx,
5932 accessibility,
5933 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005934 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005935 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005936 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005937 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005938 }
5939
5940 // Store a forward declaration to this class type in case any
5941 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005942 // types for function prototypes.
5943 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005944 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005945 this,
5946 type_name_const_str,
5947 byte_size,
5948 NULL,
5949 LLDB_INVALID_UID,
5950 Type::eEncodingIsUID,
5951 &decl,
5952 clang_type,
5953 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005954
5955 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005956
5957
5958 // Add our type to the unique type map so we don't
5959 // end up creating many copies of the same type over
5960 // and over in the ASTContext for our module
5961 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005962 unique_ast_entry.m_symfile = this;
5963 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005964 unique_ast_entry.m_die = die;
5965 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005966 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005967 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5968 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005969
Sean Callanan12014a02011-12-08 23:45:45 +00005970 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005971 {
5972 // Always start the definition for a class type so that
5973 // if the class has child classes or types that require
5974 // the class to be created for use as their decl contexts
5975 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005976 if (die->HasChildren() == false)
5977 {
5978 // No children for this struct/union/class, lets finish it
5979 ast.StartTagDeclarationDefinition (clang_type);
5980 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00005981
5982 if (tag == DW_TAG_structure_type) // this only applies in C
5983 {
5984 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
5985 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
5986
5987 if (record_type)
5988 {
5989 clang::RecordDecl *record_decl = record_type->getDecl();
5990
5991 if (record_decl)
5992 {
5993 LayoutInfo layout_info;
5994
5995 layout_info.alignment = 0;
5996 layout_info.bit_size = 0;
5997
5998 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
5999 }
6000 }
6001 }
Sean Callanan12014a02011-12-08 23:45:45 +00006002 }
6003 else if (clang_type_was_created)
6004 {
Greg Clayton219cf312012-03-30 00:51:13 +00006005 // Start the definition if the class is not objective C since
6006 // the underlying decls respond to isCompleteDefinition(). Objective
6007 // C decls dont' respond to isCompleteDefinition() so we can't
6008 // start the declaration definition right away. For C++ classs/union/structs
6009 // we want to start the definition in case the class is needed as the
6010 // declaration context for a contained class or type without the need
6011 // to complete that type..
6012
Sean Callanan7457f8d2012-04-25 01:03:57 +00006013 if (class_language != eLanguageTypeObjC &&
6014 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006015 ast.StartTagDeclarationDefinition (clang_type);
6016
Sean Callanan12014a02011-12-08 23:45:45 +00006017 // Leave this as a forward declaration until we need
6018 // to know the details of the type. lldb_private::Type
6019 // will automatically call the SymbolFile virtual function
6020 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6021 // When the definition needs to be defined.
6022 m_forward_decl_die_to_clang_type[die] = clang_type;
6023 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6024 ClangASTContext::SetHasExternalStorage (clang_type, true);
6025 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006026 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006027
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006028 }
6029 break;
6030
6031 case DW_TAG_enumeration_type:
6032 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006033 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006034 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006035
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006036 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006037
Greg Claytond88d7592010-09-15 08:33:30 +00006038 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006039 if (num_attributes > 0)
6040 {
6041 uint32_t i;
6042
6043 for (i=0; i<num_attributes; ++i)
6044 {
6045 attr = attributes.AttributeAtIndex(i);
6046 DWARFFormValue form_value;
6047 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6048 {
6049 switch (attr)
6050 {
Greg Clayton7a345282010-11-09 23:46:37 +00006051 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6052 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6053 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006054 case DW_AT_name:
6055 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006056 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006057 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006058 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006059 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6060 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6061 case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006062 case DW_AT_allocated:
6063 case DW_AT_associated:
6064 case DW_AT_bit_stride:
6065 case DW_AT_byte_stride:
6066 case DW_AT_data_location:
6067 case DW_AT_description:
6068 case DW_AT_start_scope:
6069 case DW_AT_visibility:
6070 case DW_AT_specification:
6071 case DW_AT_abstract_origin:
6072 case DW_AT_sibling:
6073 break;
6074 }
6075 }
6076 }
6077
Daniel Malead01b2952012-11-29 21:49:15 +00006078 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 +00006079
Greg Clayton1be10fc2010-09-29 01:12:09 +00006080 clang_type_t enumerator_clang_type = NULL;
6081 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6082 if (clang_type == NULL)
6083 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006084 if (encoding_uid != DW_INVALID_OFFSET)
6085 {
6086 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6087 if (enumerator_type)
6088 enumerator_clang_type = enumerator_type->GetClangFullType();
6089 }
6090
6091 if (enumerator_clang_type == NULL)
6092 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6093 DW_ATE_signed,
6094 byte_size * 8);
6095
Greg Claytonca512b32011-01-14 04:54:56 +00006096 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006097 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006098 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006099 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006100 }
6101 else
6102 {
6103 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006104 }
6105
Greg Claytona2721472011-06-25 00:44:06 +00006106 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6107
Greg Clayton81c22f62011-10-19 18:09:39 +00006108 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006109 this,
6110 type_name_const_str,
6111 byte_size,
6112 NULL,
6113 encoding_uid,
6114 Type::eEncodingIsUID,
6115 &decl,
6116 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006117 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006118
Greg Clayton6beaaa62011-01-17 03:46:26 +00006119 ast.StartTagDeclarationDefinition (clang_type);
6120 if (die->HasChildren())
6121 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006122 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006123 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006124 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006125 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006126 }
6127 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006128 }
6129 }
6130 break;
6131
Jim Inghamb0be4422010-08-12 01:20:14 +00006132 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006133 case DW_TAG_subprogram:
6134 case DW_TAG_subroutine_type:
6135 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006136 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006137 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006138
Greg Clayton23f59502012-07-17 03:23:13 +00006139 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006140 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006141 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006142 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006143 bool is_static = false;
6144 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006145 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006146 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006147 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6148 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006149 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006150
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006151 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006152 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006153
6154
Greg Claytond88d7592010-09-15 08:33:30 +00006155 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006156 if (num_attributes > 0)
6157 {
6158 uint32_t i;
6159 for (i=0; i<num_attributes; ++i)
6160 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006161 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006162 DWARFFormValue form_value;
6163 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6164 {
6165 switch (attr)
6166 {
6167 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6168 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6169 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6170 case DW_AT_name:
6171 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006172 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006173 break;
6174
Greg Clayton71415542012-12-08 00:24:40 +00006175 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006176 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006177 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006178 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006179 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00006180 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
6181 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00006182 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00006183 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6184
Greg Claytonf51de672010-10-01 02:31:07 +00006185
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006186 case DW_AT_external:
6187 if (form_value.Unsigned())
6188 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006189 if (storage == clang::SC_None)
6190 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006191 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006192 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006193 }
6194 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006195
Greg Clayton72da3972011-08-16 18:40:23 +00006196 case DW_AT_specification:
6197 specification_die_offset = form_value.Reference(dwarf_cu);
6198 break;
6199
6200 case DW_AT_abstract_origin:
6201 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6202 break;
6203
Jim Ingham379397632012-10-27 02:54:13 +00006204 case DW_AT_object_pointer:
6205 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6206 break;
6207
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006208 case DW_AT_allocated:
6209 case DW_AT_associated:
6210 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006211 case DW_AT_calling_convention:
6212 case DW_AT_data_location:
6213 case DW_AT_elemental:
6214 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006215 case DW_AT_frame_base:
6216 case DW_AT_high_pc:
6217 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006218 case DW_AT_prototyped:
6219 case DW_AT_pure:
6220 case DW_AT_ranges:
6221 case DW_AT_recursive:
6222 case DW_AT_return_addr:
6223 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006224 case DW_AT_start_scope:
6225 case DW_AT_static_link:
6226 case DW_AT_trampoline:
6227 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006228 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006229 case DW_AT_description:
6230 case DW_AT_sibling:
6231 break;
6232 }
6233 }
6234 }
Greg Clayton24739922010-10-13 03:15:28 +00006235 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006236
Jim Ingham379397632012-10-27 02:54:13 +00006237 std::string object_pointer_name;
6238 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6239 {
6240 // Get the name from the object pointer die
6241 StreamString s;
6242 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6243 {
6244 object_pointer_name.assign(s.GetData());
6245 }
6246 }
6247
Daniel Malead01b2952012-11-29 21:49:15 +00006248 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 +00006249
Greg Clayton24739922010-10-13 03:15:28 +00006250 clang_type_t return_clang_type = NULL;
6251 Type *func_type = NULL;
6252
6253 if (type_die_offset != DW_INVALID_OFFSET)
6254 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006255
Greg Clayton24739922010-10-13 03:15:28 +00006256 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006257 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006258 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006259 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006260
Greg Claytonf51de672010-10-01 02:31:07 +00006261
Greg Clayton24739922010-10-13 03:15:28 +00006262 std::vector<clang_type_t> function_param_types;
6263 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006264
Greg Clayton24739922010-10-13 03:15:28 +00006265 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006266
Greg Claytoncb5860a2011-10-13 23:49:28 +00006267 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6268 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006269 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6270
Greg Claytonf0705c82011-10-22 03:33:13 +00006271 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006272 // Start off static. This will be set to false in ParseChildParameters(...)
6273 // if we find a "this" paramters as the first parameter
6274 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006275 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006276 ClangASTContext::TemplateParameterInfos template_param_infos;
6277
Greg Clayton24739922010-10-13 03:15:28 +00006278 if (die->HasChildren())
6279 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006280 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006281 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006282 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006283 dwarf_cu,
6284 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006285 skip_artificial,
6286 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006287 type_list,
6288 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006289 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006290 type_quals,
6291 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006292 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006293
Greg Clayton24739922010-10-13 03:15:28 +00006294 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006295 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006296 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006297 function_param_types.size(),
6298 is_variadic,
6299 type_quals);
6300
Greg Clayton24739922010-10-13 03:15:28 +00006301 if (type_name_cstr)
6302 {
6303 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006304 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006305 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006306 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6307 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006308 {
Greg Clayton24739922010-10-13 03:15:28 +00006309 SymbolContext empty_sc;
6310 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006311 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006312 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006313 {
Greg Clayton24739922010-10-13 03:15:28 +00006314 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006315 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006316
6317 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006318 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006319 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6320 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6321 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006322 }
Greg Clayton24739922010-10-13 03:15:28 +00006323 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006324
Greg Clayton24739922010-10-13 03:15:28 +00006325 if (class_opaque_type)
6326 {
6327 // If accessibility isn't set to anything valid, assume public for
6328 // now...
6329 if (accessibility == eAccessNone)
6330 accessibility = eAccessPublic;
6331
Sean Callanan464a5b52012-10-04 22:06:29 +00006332 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6333 type_name_cstr,
6334 clang_type,
6335 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00006336 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006337 if (type_handled)
6338 {
6339 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Jim Ingham379397632012-10-27 02:54:13 +00006340 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006341 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006342 else
6343 {
Jason Molendac1a65832013-03-07 22:44:42 +00006344 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
Sean Callananc3a1d562013-02-06 23:21:59 +00006345 die->GetOffset(),
6346 tag,
6347 DW_TAG_value_to_name(tag));
6348 }
Greg Clayton24739922010-10-13 03:15:28 +00006349 }
6350 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006351 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006352 {
6353 // Look at the parent of this DIE and see if is is
6354 // a class or struct and see if this is actually a
6355 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006356 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006357 if (class_type)
6358 {
Greg Clayton4116e932012-05-15 02:33:01 +00006359 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6360 {
6361 // We uniqued the parent class of this function to another class
6362 // so we now need to associate all dies under "decl_ctx_die" to
6363 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006364 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006365 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006366 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006367
6368 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6369 if (debug_map_symfile)
6370 {
6371 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6372 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6373 }
6374 else
6375 {
6376 class_symfile = this;
6377 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6378 }
Greg Clayton4116e932012-05-15 02:33:01 +00006379 if (class_type_die)
6380 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006381 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6382
6383 CopyUniqueClassMethodTypes (class_symfile,
6384 class_type,
6385 class_type_cu_sp.get(),
6386 class_type_die,
6387 dwarf_cu,
6388 decl_ctx_die,
6389 failures);
6390
6391 // FIXME do something with these failures that's smarter than
6392 // just dropping them on the ground. Unfortunately classes don't
6393 // like having stuff added to them after their definitions are
6394 // complete...
6395
6396 type_ptr = m_die_to_type[die];
6397 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006398 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006399 type_sp = type_ptr->shared_from_this();
6400 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006401 }
6402 }
6403 }
6404
Greg Clayton72da3972011-08-16 18:40:23 +00006405 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006406 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006407 // We have a specification which we are going to base our function
6408 // prototype off of, so we need this type to be completed so that the
6409 // m_die_to_decl_ctx for the method in the specification has a valid
6410 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006411 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006412 // If we have a specification, then the function type should have been
6413 // made with the specification and not with this die.
6414 DWARFCompileUnitSP spec_cu_sp;
6415 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006416 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006417 if (spec_clang_decl_ctx)
6418 {
6419 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6420 }
6421 else
Jim Inghamc1663042011-09-29 22:12:35 +00006422 {
Daniel Malead01b2952012-11-29 21:49:15 +00006423 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006424 MakeUserID(die->GetOffset()),
6425 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006426 }
Greg Clayton72da3972011-08-16 18:40:23 +00006427 type_handled = true;
6428 }
6429 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6430 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006431 // We have a specification which we are going to base our function
6432 // prototype off of, so we need this type to be completed so that the
6433 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6434 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006435 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006436
Greg Clayton72da3972011-08-16 18:40:23 +00006437 DWARFCompileUnitSP abs_cu_sp;
6438 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006439 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006440 if (abs_clang_decl_ctx)
6441 {
6442 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6443 }
6444 else
Jim Inghamc1663042011-09-29 22:12:35 +00006445 {
Daniel Malead01b2952012-11-29 21:49:15 +00006446 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 +00006447 MakeUserID(die->GetOffset()),
6448 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006449 }
Greg Clayton72da3972011-08-16 18:40:23 +00006450 type_handled = true;
6451 }
6452 else
6453 {
6454 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6455 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006456 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006457 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006458 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006459 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6460 // in the DWARF for C++ methods... Default to public for now...
6461 if (accessibility == eAccessNone)
6462 accessibility = eAccessPublic;
6463
6464 if (!is_static && !die->HasChildren())
6465 {
6466 // We have a C++ member function with no children (this pointer!)
6467 // and clang will get mad if we try and make a function that isn't
6468 // well formed in the DWARF, so we will just skip it...
6469 type_handled = true;
6470 }
6471 else
6472 {
6473 clang::CXXMethodDecl *cxx_method_decl;
6474 // REMOVE THE CRASH DESCRIPTION BELOW
Daniel Malead01b2952012-11-29 21:49:15 +00006475 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 +00006476 type_name_cstr,
6477 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006478 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006479 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6480 m_obj_file->GetFileSpec().GetFilename().GetCString());
6481
Sean Callananc1b732d2011-11-01 18:07:13 +00006482 const bool is_attr_used = false;
6483
Greg Clayton20568dd2011-10-13 23:13:20 +00006484 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6485 type_name_cstr,
6486 clang_type,
6487 accessibility,
6488 is_virtual,
6489 is_static,
6490 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006491 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006492 is_attr_used,
6493 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006494
Greg Clayton20568dd2011-10-13 23:13:20 +00006495 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006496
6497 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006498 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006499 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6500
6501 Host::SetCrashDescription (NULL);
6502
6503
6504 ClangASTMetadata metadata;
6505 metadata.SetUserID(MakeUserID(die->GetOffset()));
6506
6507 if (!object_pointer_name.empty())
6508 {
6509 metadata.SetObjectPtrName(object_pointer_name.c_str());
6510 if (log)
6511 log->Printf ("Setting object pointer name: %s on method object 0x%ld.\n",
6512 object_pointer_name.c_str(),
6513 (uintptr_t) cxx_method_decl);
6514 }
6515 GetClangASTContext().SetMetadata ((uintptr_t)cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006516 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006517 }
Greg Clayton72da3972011-08-16 18:40:23 +00006518 }
6519 else
6520 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006521 // We were asked to parse the type for a method in a class, yet the
6522 // class hasn't been asked to complete itself through the
6523 // clang::ExternalASTSource protocol, so we need to just have the
6524 // class complete itself and do things the right way, then our
6525 // DIE should then have an entry in the m_die_to_type map. First
6526 // we need to modify the m_die_to_type so it doesn't think we are
6527 // trying to parse this DIE anymore...
6528 m_die_to_type[die] = NULL;
6529
6530 // Now we get the full type to force our class type to complete itself
6531 // using the clang::ExternalASTSource protocol which will parse all
6532 // base classes and all methods (including the method for this DIE).
6533 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006534
Greg Clayton20568dd2011-10-13 23:13:20 +00006535 // The type for this DIE should have been filled in the function call above
6536 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006537 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006538 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006539 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006540 break;
6541 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006542
6543 // FIXME This is fixing some even uglier behavior but we really need to
6544 // uniq the methods of each class as well as the class itself.
6545 // <rdar://problem/11240464>
6546 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006547 }
Greg Clayton931180e2011-01-27 06:44:37 +00006548 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006549 }
6550 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006551 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006552 }
Greg Clayton24739922010-10-13 03:15:28 +00006553
6554 if (!type_handled)
6555 {
6556 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006557 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6558 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006559 clang_type,
6560 storage,
6561 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006562
6563// if (template_param_infos.GetSize() > 0)
6564// {
6565// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6566// function_decl,
6567// type_name_cstr,
6568// template_param_infos);
6569//
6570// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6571// func_template_decl,
6572// template_param_infos);
6573// }
Greg Clayton24739922010-10-13 03:15:28 +00006574 // Add the decl to our DIE to decl context map
6575 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006576 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006577 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006578 ast.SetFunctionParameters (function_decl,
6579 &function_param_decls.front(),
6580 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006581
Jim Ingham379397632012-10-27 02:54:13 +00006582 ClangASTMetadata metadata;
6583 metadata.SetUserID(MakeUserID(die->GetOffset()));
6584
6585 if (!object_pointer_name.empty())
6586 {
6587 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006588 if (log)
6589 log->Printf ("Setting object pointer name: %s on function object 0x%ld.\n",
6590 object_pointer_name.c_str(),
6591 (uintptr_t) function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006592 }
6593 GetClangASTContext().SetMetadata ((uintptr_t)function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006594 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006595 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006596 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006597 this,
6598 type_name_const_str,
6599 0,
6600 NULL,
6601 LLDB_INVALID_UID,
6602 Type::eEncodingIsUID,
6603 &decl,
6604 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006605 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006606 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006607 }
6608 break;
6609
6610 case DW_TAG_array_type:
6611 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006612 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006613 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006614
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006615 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006616 int64_t first_index = 0;
6617 uint32_t byte_stride = 0;
6618 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006619 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006620
6621 if (num_attributes > 0)
6622 {
6623 uint32_t i;
6624 for (i=0; i<num_attributes; ++i)
6625 {
6626 attr = attributes.AttributeAtIndex(i);
6627 DWARFFormValue form_value;
6628 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6629 {
6630 switch (attr)
6631 {
6632 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6633 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6634 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6635 case DW_AT_name:
6636 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006637 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006638 break;
6639
6640 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006641 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006642 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6643 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006644 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6645 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006646 case DW_AT_allocated:
6647 case DW_AT_associated:
6648 case DW_AT_data_location:
6649 case DW_AT_description:
6650 case DW_AT_ordering:
6651 case DW_AT_start_scope:
6652 case DW_AT_visibility:
6653 case DW_AT_specification:
6654 case DW_AT_abstract_origin:
6655 case DW_AT_sibling:
6656 break;
6657 }
6658 }
6659 }
6660
Daniel Malead01b2952012-11-29 21:49:15 +00006661 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 +00006662
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006663 Type *element_type = ResolveTypeUID(type_die_offset);
6664
6665 if (element_type)
6666 {
6667 std::vector<uint64_t> element_orders;
6668 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6669 if (byte_stride == 0 && bit_stride == 0)
6670 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006671 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006672 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6673 uint64_t num_elements = 0;
6674 std::vector<uint64_t>::const_reverse_iterator pos;
6675 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6676 for (pos = element_orders.rbegin(); pos != end; ++pos)
6677 {
6678 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006679 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton4ef877f2012-12-06 02:33:54 +00006680 num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006681 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006682 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006683 }
6684 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006685 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006686 this,
6687 empty_name,
6688 array_element_bit_stride / 8,
6689 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006690 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006691 Type::eEncodingIsUID,
6692 &decl,
6693 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006694 Type::eResolveStateFull));
6695 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006696 }
6697 }
6698 }
6699 break;
6700
Greg Clayton9b81a312010-06-12 01:20:30 +00006701 case DW_TAG_ptr_to_member_type:
6702 {
6703 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6704 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6705
Greg Claytond88d7592010-09-15 08:33:30 +00006706 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006707
6708 if (num_attributes > 0) {
6709 uint32_t i;
6710 for (i=0; i<num_attributes; ++i)
6711 {
6712 attr = attributes.AttributeAtIndex(i);
6713 DWARFFormValue form_value;
6714 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6715 {
6716 switch (attr)
6717 {
6718 case DW_AT_type:
6719 type_die_offset = form_value.Reference(dwarf_cu); break;
6720 case DW_AT_containing_type:
6721 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6722 }
6723 }
6724 }
6725
6726 Type *pointee_type = ResolveTypeUID(type_die_offset);
6727 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6728
Greg Clayton526e5af2010-11-13 03:52:47 +00006729 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6730 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006731
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006732 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6733 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006734
Greg Clayton526e5af2010-11-13 03:52:47 +00006735 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6736 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006737
Greg Clayton81c22f62011-10-19 18:09:39 +00006738 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006739 this,
6740 type_name_const_str,
6741 byte_size,
6742 NULL,
6743 LLDB_INVALID_UID,
6744 Type::eEncodingIsUID,
6745 NULL,
6746 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006747 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006748 }
6749
6750 break;
6751 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006752 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006753 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",
6754 die->GetOffset(),
6755 tag,
6756 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006757 break;
6758 }
6759
6760 if (type_sp.get())
6761 {
6762 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6763 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6764
6765 SymbolContextScope * symbol_context_scope = NULL;
6766 if (sc_parent_tag == DW_TAG_compile_unit)
6767 {
6768 symbol_context_scope = sc.comp_unit;
6769 }
6770 else if (sc.function != NULL)
6771 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006772 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006773 if (symbol_context_scope == NULL)
6774 symbol_context_scope = sc.function;
6775 }
6776
6777 if (symbol_context_scope != NULL)
6778 {
6779 type_sp->SetSymbolContextScope(symbol_context_scope);
6780 }
6781
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006782 // We are ready to put this type into the uniqued list up at the module level
6783 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006784
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006785 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006786 }
6787 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006788 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006789 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006790 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006791 }
6792 }
6793 return type_sp;
6794}
6795
6796size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006797SymbolFileDWARF::ParseTypes
6798(
6799 const SymbolContext& sc,
6800 DWARFCompileUnit* dwarf_cu,
6801 const DWARFDebugInfoEntry *die,
6802 bool parse_siblings,
6803 bool parse_children
6804)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006805{
6806 size_t types_added = 0;
6807 while (die != NULL)
6808 {
6809 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006810 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006811 {
6812 if (type_is_new)
6813 ++types_added;
6814 }
6815
6816 if (parse_children && die->HasChildren())
6817 {
6818 if (die->Tag() == DW_TAG_subprogram)
6819 {
6820 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006821 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006822 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6823 }
6824 else
6825 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6826 }
6827
6828 if (parse_siblings)
6829 die = die->GetSibling();
6830 else
6831 die = NULL;
6832 }
6833 return types_added;
6834}
6835
6836
6837size_t
6838SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6839{
6840 assert(sc.comp_unit && sc.function);
6841 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006842 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006843 if (dwarf_cu)
6844 {
6845 dw_offset_t function_die_offset = sc.function->GetID();
6846 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6847 if (function_die)
6848 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006849 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006850 }
6851 }
6852
6853 return functions_added;
6854}
6855
6856
6857size_t
6858SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6859{
6860 // At least a compile unit must be valid
6861 assert(sc.comp_unit);
6862 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006863 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006864 if (dwarf_cu)
6865 {
6866 if (sc.function)
6867 {
6868 dw_offset_t function_die_offset = sc.function->GetID();
6869 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6870 if (func_die && func_die->HasChildren())
6871 {
6872 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6873 }
6874 }
6875 else
6876 {
6877 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6878 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6879 {
6880 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6881 }
6882 }
6883 }
6884
6885 return types_added;
6886}
6887
6888size_t
6889SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6890{
6891 if (sc.comp_unit != NULL)
6892 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006893 DWARFDebugInfo* info = DebugInfo();
6894 if (info == NULL)
6895 return 0;
6896
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006897 if (sc.function)
6898 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006899 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
6900
6901 if (dwarf_cu == NULL)
6902 return 0;
6903
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006904 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006905
Greg Claytonc7bece562013-01-25 18:06:21 +00006906 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6907 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006908 {
6909 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006910
Greg Claytone38a5ed2012-01-05 03:57:59 +00006911 // Let all blocks know they have parse all their variables
6912 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6913 return num_variables;
6914 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006915 }
6916 else if (sc.comp_unit)
6917 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006918 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
6919
6920 if (dwarf_cu == NULL)
6921 return 0;
6922
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006923 uint32_t vars_added = 0;
6924 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6925
6926 if (variables.get() == NULL)
6927 {
6928 variables.reset(new VariableList());
6929 sc.comp_unit->SetVariableList(variables);
6930
Greg Claytond4a2b372011-09-12 23:21:58 +00006931 DWARFCompileUnit* match_dwarf_cu = NULL;
6932 const DWARFDebugInfoEntry* die = NULL;
6933 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006934 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006935 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006936 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006937 {
6938 DWARFMappedHash::DIEInfoArray hash_data_array;
6939 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6940 dwarf_cu->GetNextCompileUnitOffset(),
6941 hash_data_array))
6942 {
6943 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6944 }
6945 }
Greg Clayton7f995132011-10-04 22:41:51 +00006946 }
6947 else
6948 {
6949 // Index if we already haven't to make sure the compile units
6950 // get indexed and make their global DIE index list
6951 if (!m_indexed)
6952 Index ();
6953
6954 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6955 dwarf_cu->GetNextCompileUnitOffset(),
6956 die_offsets);
6957 }
6958
6959 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006960 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006961 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006962 DWARFDebugInfo* debug_info = DebugInfo();
6963 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006964 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006965 const dw_offset_t die_offset = die_offsets[i];
6966 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006967 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006968 {
Greg Clayton95d87902011-11-11 03:16:25 +00006969 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6970 if (var_sp)
6971 {
6972 variables->AddVariableIfUnique (var_sp);
6973 ++vars_added;
6974 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006975 }
Greg Clayton95d87902011-11-11 03:16:25 +00006976 else
6977 {
6978 if (m_using_apple_tables)
6979 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006980 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 +00006981 }
6982 }
6983
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006984 }
6985 }
6986 }
6987 return vars_added;
6988 }
6989 }
6990 return 0;
6991}
6992
6993
6994VariableSP
6995SymbolFileDWARF::ParseVariableDIE
6996(
6997 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006998 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006999 const DWARFDebugInfoEntry *die,
7000 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007001)
7002{
7003
Greg Clayton83c5cd92010-11-14 22:13:40 +00007004 VariableSP var_sp (m_die_to_variable_sp[die]);
7005 if (var_sp)
7006 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007007
7008 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007009
7010 if ((tag == DW_TAG_variable) ||
7011 (tag == DW_TAG_constant) ||
7012 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007013 {
Greg Clayton7f995132011-10-04 22:41:51 +00007014 DWARFDebugInfoEntry::Attributes attributes;
7015 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7016 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007017 {
Greg Clayton7f995132011-10-04 22:41:51 +00007018 const char *name = NULL;
7019 const char *mangled = NULL;
7020 Declaration decl;
7021 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007022 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007023 DWARFExpression location;
7024 bool is_external = false;
7025 bool is_artificial = false;
7026 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007027 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007028 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007029
7030 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007031 {
Greg Clayton7f995132011-10-04 22:41:51 +00007032 dw_attr_t attr = attributes.AttributeAtIndex(i);
7033 DWARFFormValue form_value;
7034 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007035 {
Greg Clayton7f995132011-10-04 22:41:51 +00007036 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007037 {
Greg Clayton7f995132011-10-04 22:41:51 +00007038 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7039 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7040 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7041 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007042 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007043 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007044 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007045 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
7046 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007047 // If we have already found a DW_AT_location attribute, ignore this attribute.
7048 if (!has_explicit_location)
7049 {
7050 location_is_const_value_data = true;
7051 // The constant value will be either a block, a data value or a string.
7052 const DataExtractor& debug_info_data = get_debug_info_data();
7053 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7054 {
7055 // Retrieve the value as a block expression.
7056 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7057 uint32_t block_length = form_value.Unsigned();
7058 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7059 }
7060 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7061 {
7062 // Retrieve the value as a data expression.
7063 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7064 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7065 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7066 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7067 }
7068 else
7069 {
7070 // Retrieve the value as a string expression.
7071 if (form_value.Form() == DW_FORM_strp)
7072 {
7073 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7074 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7075 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7076 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7077 }
7078 else
7079 {
7080 const char *str = form_value.AsCString(&debug_info_data);
7081 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7082 uint32_t string_length = strlen(str) + 1;
7083 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7084 }
7085 }
7086 }
7087 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007088 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007089 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007090 location_is_const_value_data = false;
7091 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007092 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007093 {
Greg Clayton7f995132011-10-04 22:41:51 +00007094 const DataExtractor& debug_info_data = get_debug_info_data();
7095
7096 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7097 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007098 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007099 }
7100 else
7101 {
7102 const DataExtractor& debug_loc_data = get_debug_loc_data();
7103 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7104
7105 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7106 if (loc_list_length > 0)
7107 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007108 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007109 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7110 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7111 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007112 }
7113 }
Greg Clayton7f995132011-10-04 22:41:51 +00007114 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007115
Greg Clayton7f995132011-10-04 22:41:51 +00007116 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00007117 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007118 case DW_AT_declaration:
7119 case DW_AT_description:
7120 case DW_AT_endianity:
7121 case DW_AT_segment:
7122 case DW_AT_start_scope:
7123 case DW_AT_visibility:
7124 default:
7125 case DW_AT_abstract_origin:
7126 case DW_AT_sibling:
7127 case DW_AT_specification:
7128 break;
7129 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007130 }
7131 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007132
Greg Clayton7f995132011-10-04 22:41:51 +00007133 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007134 {
Greg Clayton7f995132011-10-04 22:41:51 +00007135 ValueType scope = eValueTypeInvalid;
7136
7137 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7138 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007139 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007140
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007141 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7142 // or static variable, so we have to do a little digging by
7143 // looking at the location of a varaible to see if it contains
7144 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7145 // somewhere because clang likes to combine small global variables
7146 // into the same symbol and have locations like:
7147 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7148 // So if we don't have a DW_TAG_formal_parameter, we can look at
7149 // the location to see if it contains a DW_OP_addr opcode, and
7150 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007151 if (tag == DW_TAG_formal_parameter)
7152 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007153 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007154 {
Greg Clayton96c09682012-01-04 22:56:43 +00007155 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007156 // Check if the location has a DW_OP_addr with any address value...
Greg Clayton9422dd62013-03-04 21:46:16 +00007157 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
Greg Claytond1767f02011-12-08 02:13:16 +00007158 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007159 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007160 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
Greg Clayton96c09682012-01-04 22:56:43 +00007161 if (op_error)
7162 {
7163 StreamString strm;
7164 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007165 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 +00007166 }
7167 }
Greg Claytond1767f02011-12-08 02:13:16 +00007168
Greg Clayton9422dd62013-03-04 21:46:16 +00007169 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007170 {
Greg Claytond1767f02011-12-08 02:13:16 +00007171 if (is_external)
Greg Claytond1767f02011-12-08 02:13:16 +00007172 scope = eValueTypeVariableGlobal;
Greg Clayton9422dd62013-03-04 21:46:16 +00007173 else
7174 scope = eValueTypeVariableStatic;
7175
7176
7177 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7178
7179 if (debug_map_symfile)
7180 {
7181 // When leaving the DWARF in the .o files on darwin,
7182 // when we have a global variable that wasn't initialized,
7183 // the .o file might not have allocated a virtual
7184 // address for the global variable. In this case it will
7185 // have created a symbol for the global variable
7186 // that is undefined/data and external and the value will
7187 // be the byte size of the variable. When we do the
7188 // address map in SymbolFileDWARFDebugMap we rely on
7189 // having an address, we need to do some magic here
7190 // so we can get the correct address for our global
7191 // variable. The address for all of these entries
7192 // will be zero, and there will be an undefined symbol
7193 // in this object file, and the executable will have
7194 // a matching symbol with a good address. So here we
7195 // dig up the correct address and replace it in the
7196 // location for the variable, and set the variable's
7197 // symbol context scope to be that of the main executable
7198 // so the file address will resolve correctly.
7199 bool linked_oso_file_addr = false;
7200 if (is_external && location_DW_OP_addr == 0)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007201 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007202
7203 // we have a possible uninitialized extern global
7204 ConstString const_name(mangled ? mangled : name);
7205 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7206 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007207 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007208 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7209 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007210 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007211 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7212 eSymbolTypeData,
7213 Symtab::eDebugYes,
7214 Symtab::eVisibilityExtern);
7215 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007216 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007217 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007218 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007219 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7220 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007221 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007222 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007223 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007224 linked_oso_file_addr = true;
7225 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007226 }
7227 }
7228 }
7229 }
7230 }
7231 }
7232 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007233
7234 if (!linked_oso_file_addr)
7235 {
7236 // The DW_OP_addr is not zero, but it contains a .o file address which
7237 // needs to be linked up correctly.
7238 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7239 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7240 {
7241 // Update the file address for this variable
7242 location.Update_DW_OP_addr (exe_file_addr);
7243 }
7244 else
7245 {
7246 // Variable didn't make it into the final executable
7247 return var_sp;
7248 }
7249 }
Greg Claytond1767f02011-12-08 02:13:16 +00007250 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007251 }
7252 else
Greg Claytond1767f02011-12-08 02:13:16 +00007253 {
7254 scope = eValueTypeVariableLocal;
7255 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007256 }
Greg Clayton7f995132011-10-04 22:41:51 +00007257
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007258 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007259 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007260 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007261 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007262 case DW_TAG_subprogram:
7263 case DW_TAG_inlined_subroutine:
7264 case DW_TAG_lexical_block:
7265 if (sc.function)
7266 {
7267 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7268 if (symbol_context_scope == NULL)
7269 symbol_context_scope = sc.function;
7270 }
7271 break;
7272
7273 default:
7274 symbol_context_scope = sc.comp_unit;
7275 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007276 }
Greg Clayton7f995132011-10-04 22:41:51 +00007277 }
7278
Greg Clayton5cf58b92011-10-05 22:22:08 +00007279 if (symbol_context_scope)
7280 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007281 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7282 name,
7283 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007284 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007285 scope,
7286 symbol_context_scope,
7287 &decl,
7288 location,
7289 is_external,
7290 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007291
7292 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7293 }
7294 else
7295 {
7296 // Not ready to parse this variable yet. It might be a global
7297 // or static variable that is in a function scope and the function
7298 // in the symbol context wasn't filled in yet
7299 return var_sp;
7300 }
Greg Clayton7f995132011-10-04 22:41:51 +00007301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007302 }
Greg Clayton7f995132011-10-04 22:41:51 +00007303 // Cache var_sp even if NULL (the variable was just a specification or
7304 // was missing vital information to be able to be displayed in the debugger
7305 // (missing location due to optimization, etc)) so we don't re-parse
7306 // this DIE over and over later...
7307 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007308 }
7309 return var_sp;
7310}
7311
Greg Claytonc662ec82011-06-17 22:10:16 +00007312
7313const DWARFDebugInfoEntry *
7314SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7315 dw_offset_t spec_block_die_offset,
7316 DWARFCompileUnit **result_die_cu_handle)
7317{
7318 // Give the concrete function die specified by "func_die_offset", find the
7319 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7320 // to "spec_block_die_offset"
7321 DWARFDebugInfo* info = DebugInfo();
7322
7323 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7324 if (die)
7325 {
7326 assert (*result_die_cu_handle);
7327 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7328 }
7329 return NULL;
7330}
7331
7332
7333const DWARFDebugInfoEntry *
7334SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7335 const DWARFDebugInfoEntry *die,
7336 dw_offset_t spec_block_die_offset,
7337 DWARFCompileUnit **result_die_cu_handle)
7338{
7339 if (die)
7340 {
7341 switch (die->Tag())
7342 {
7343 case DW_TAG_subprogram:
7344 case DW_TAG_inlined_subroutine:
7345 case DW_TAG_lexical_block:
7346 {
7347 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7348 {
7349 *result_die_cu_handle = dwarf_cu;
7350 return die;
7351 }
7352
7353 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7354 {
7355 *result_die_cu_handle = dwarf_cu;
7356 return die;
7357 }
7358 }
7359 break;
7360 }
7361
7362 // Give the concrete function die specified by "func_die_offset", find the
7363 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7364 // to "spec_block_die_offset"
7365 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7366 {
7367 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7368 child_die,
7369 spec_block_die_offset,
7370 result_die_cu_handle);
7371 if (result_die)
7372 return result_die;
7373 }
7374 }
7375
7376 *result_die_cu_handle = NULL;
7377 return NULL;
7378}
7379
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007380size_t
7381SymbolFileDWARF::ParseVariables
7382(
7383 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007384 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007385 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007386 const DWARFDebugInfoEntry *orig_die,
7387 bool parse_siblings,
7388 bool parse_children,
7389 VariableList* cc_variable_list
7390)
7391{
7392 if (orig_die == NULL)
7393 return 0;
7394
Greg Claytonc662ec82011-06-17 22:10:16 +00007395 VariableListSP variable_list_sp;
7396
7397 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007398 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007399 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007400 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007401 dw_tag_t tag = die->Tag();
7402
7403 // Check to see if we have already parsed this variable or constant?
7404 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007405 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007406 if (cc_variable_list)
7407 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007408 }
7409 else
7410 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007411 // We haven't already parsed it, lets do that now.
7412 if ((tag == DW_TAG_variable) ||
7413 (tag == DW_TAG_constant) ||
7414 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007415 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007416 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007417 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007418 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7419 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7420 switch (parent_tag)
7421 {
7422 case DW_TAG_compile_unit:
7423 if (sc.comp_unit != NULL)
7424 {
7425 variable_list_sp = sc.comp_unit->GetVariableList(false);
7426 if (variable_list_sp.get() == NULL)
7427 {
7428 variable_list_sp.reset(new VariableList());
7429 sc.comp_unit->SetVariableList(variable_list_sp);
7430 }
7431 }
7432 else
7433 {
Daniel Malead01b2952012-11-29 21:49:15 +00007434 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 +00007435 MakeUserID(sc_parent_die->GetOffset()),
7436 DW_TAG_value_to_name (parent_tag),
7437 MakeUserID(orig_die->GetOffset()),
7438 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007439 }
7440 break;
7441
7442 case DW_TAG_subprogram:
7443 case DW_TAG_inlined_subroutine:
7444 case DW_TAG_lexical_block:
7445 if (sc.function != NULL)
7446 {
7447 // Check to see if we already have parsed the variables for the given scope
7448
Greg Clayton81c22f62011-10-19 18:09:39 +00007449 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007450 if (block == NULL)
7451 {
7452 // This must be a specification or abstract origin with
7453 // a concrete block couterpart in the current function. We need
7454 // to find the concrete block so we can correctly add the
7455 // variable to it
7456 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7457 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7458 sc_parent_die->GetOffset(),
7459 &concrete_block_die_cu);
7460 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007461 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007462 }
7463
7464 if (block != NULL)
7465 {
7466 const bool can_create = false;
7467 variable_list_sp = block->GetBlockVariableList (can_create);
7468 if (variable_list_sp.get() == NULL)
7469 {
7470 variable_list_sp.reset(new VariableList());
7471 block->SetVariableList(variable_list_sp);
7472 }
7473 }
7474 }
7475 break;
7476
7477 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007478 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 +00007479 MakeUserID(orig_die->GetOffset()),
7480 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007481 break;
7482 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007483 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007484
7485 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007486 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007487 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7488 if (var_sp)
7489 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007490 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007491 if (cc_variable_list)
7492 cc_variable_list->AddVariableIfUnique (var_sp);
7493 ++vars_added;
7494 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007495 }
7496 }
7497 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007498
7499 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7500
7501 if (!skip_children && parse_children && die->HasChildren())
7502 {
7503 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7504 }
7505
7506 if (parse_siblings)
7507 die = die->GetSibling();
7508 else
7509 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007510 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007511 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007512}
7513
7514//------------------------------------------------------------------
7515// PluginInterface protocol
7516//------------------------------------------------------------------
7517const char *
7518SymbolFileDWARF::GetPluginName()
7519{
7520 return "SymbolFileDWARF";
7521}
7522
7523const char *
7524SymbolFileDWARF::GetShortPluginName()
7525{
7526 return GetPluginNameStatic();
7527}
7528
7529uint32_t
7530SymbolFileDWARF::GetPluginVersion()
7531{
7532 return 1;
7533}
7534
7535void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007536SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7537{
7538 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7539 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7540 if (clang_type)
7541 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7542}
7543
7544void
7545SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7546{
7547 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7548 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7549 if (clang_type)
7550 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7551}
7552
Greg Claytona2721472011-06-25 00:44:06 +00007553void
Sean Callanancc427fa2011-07-30 02:42:06 +00007554SymbolFileDWARF::DumpIndexes ()
7555{
7556 StreamFile s(stdout, false);
7557
7558 s.Printf ("DWARF index for (%s) '%s/%s':",
7559 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7560 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7561 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7562 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7563 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7564 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7565 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7566 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7567 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7568 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7569 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7570}
7571
7572void
7573SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7574 const char *name,
7575 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007576{
Sean Callanancc427fa2011-07-30 02:42:06 +00007577 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007578
7579 if (iter == m_decl_ctx_to_die.end())
7580 return;
7581
Greg Claytoncb5860a2011-10-13 23:49:28 +00007582 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007583 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007584 const DWARFDebugInfoEntry *context_die = *pos;
7585
7586 if (!results)
7587 return;
7588
7589 DWARFDebugInfo* info = DebugInfo();
7590
7591 DIEArray die_offsets;
7592
7593 DWARFCompileUnit* dwarf_cu = NULL;
7594 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007595
7596 if (m_using_apple_tables)
7597 {
7598 if (m_apple_types_ap.get())
7599 m_apple_types_ap->FindByName (name, die_offsets);
7600 }
7601 else
7602 {
7603 if (!m_indexed)
7604 Index ();
7605
7606 m_type_index.Find (ConstString(name), die_offsets);
7607 }
7608
Greg Clayton220a0072011-12-09 08:48:30 +00007609 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007610
7611 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007612 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007613 for (size_t i = 0; i < num_matches; ++i)
7614 {
7615 const dw_offset_t die_offset = die_offsets[i];
7616 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007617
Greg Claytoncb5860a2011-10-13 23:49:28 +00007618 if (die->GetParent() != context_die)
7619 continue;
7620
7621 Type *matching_type = ResolveType (dwarf_cu, die);
7622
Greg Clayton42ce2f32011-12-12 21:50:19 +00007623 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007624 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7625
7626 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7627 {
7628 clang::TagDecl *tag_decl = tag_type->getDecl();
7629 results->push_back(tag_decl);
7630 }
7631 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7632 {
7633 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7634 results->push_back(typedef_decl);
7635 }
Greg Claytona2721472011-06-25 00:44:06 +00007636 }
7637 }
7638 }
7639}
7640
7641void
7642SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007643 const clang::DeclContext *decl_context,
7644 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007645 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7646{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007647
7648 switch (decl_context->getDeclKind())
7649 {
7650 case clang::Decl::Namespace:
7651 case clang::Decl::TranslationUnit:
7652 {
7653 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7654 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7655 }
7656 break;
7657 default:
7658 break;
7659 }
Greg Claytona2721472011-06-25 00:44:06 +00007660}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007661
7662bool
7663SymbolFileDWARF::LayoutRecordType (void *baton,
7664 const clang::RecordDecl *record_decl,
7665 uint64_t &size,
7666 uint64_t &alignment,
7667 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7668 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7669 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7670{
7671 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7672 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7673}
7674
7675
7676bool
7677SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7678 uint64_t &bit_size,
7679 uint64_t &alignment,
7680 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7681 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7682 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7683{
7684 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7685 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7686 bool success = false;
7687 base_offsets.clear();
7688 vbase_offsets.clear();
7689 if (pos != m_record_decl_to_layout_map.end())
7690 {
7691 bit_size = pos->second.bit_size;
7692 alignment = pos->second.alignment;
7693 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007694 base_offsets.swap (pos->second.base_offsets);
7695 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007696 m_record_decl_to_layout_map.erase(pos);
7697 success = true;
7698 }
7699 else
7700 {
7701 bit_size = 0;
7702 alignment = 0;
7703 field_offsets.clear();
7704 }
7705
7706 if (log)
7707 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00007708 "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 +00007709 record_decl,
7710 bit_size,
7711 alignment,
7712 (uint32_t)field_offsets.size(),
7713 (uint32_t)base_offsets.size(),
7714 (uint32_t)vbase_offsets.size(),
7715 success);
7716 return success;
7717}
7718
7719
Greg Clayton1f746072012-08-29 21:13:06 +00007720SymbolFileDWARFDebugMap *
7721SymbolFileDWARF::GetDebugMapSymfile ()
7722{
7723 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7724 {
7725 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7726 if (module_sp)
7727 {
7728 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7729 if (sym_vendor)
7730 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7731 }
7732 }
7733 return m_debug_map_symfile;
7734}
7735
Greg Claytoncaab74e2012-01-28 00:48:57 +00007736