blob: ffda80bca19d7bd7669e1c6b7dd16006516c181b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
Greg Clayton1f746072012-08-29 21:13:06 +0000232 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000266 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000267 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000268 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 m_data_debug_abbrev (),
271 m_data_debug_aranges (),
272 m_data_debug_frame (),
273 m_data_debug_info (),
274 m_data_debug_line (),
275 m_data_debug_loc (),
276 m_data_debug_ranges (),
277 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000278 m_data_apple_names (),
279 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000280 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_info(),
283 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000284 m_apple_names_ap (),
285 m_apple_types_ap (),
286 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000287 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000288 m_function_basename_index(),
289 m_function_fullname_index(),
290 m_function_method_index(),
291 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000292 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000293 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000294 m_type_index(),
295 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000296 m_indexed (false),
297 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000298 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000299 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000300 m_ranges(),
301 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
303}
304
305SymbolFileDWARF::~SymbolFileDWARF()
306{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000307 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000308 {
309 ModuleSP module_sp (m_obj_file->GetModule());
310 if (module_sp)
311 module_sp->GetClangASTContext().RemoveExternalSource ();
312 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000313}
314
315static const ConstString &
316GetDWARFMachOSegmentName ()
317{
318 static ConstString g_dwarf_section_name ("__DWARF");
319 return g_dwarf_section_name;
320}
321
Greg Claytone576ab22011-02-15 00:19:15 +0000322UniqueDWARFASTTypeMap &
323SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
324{
Greg Clayton1f746072012-08-29 21:13:06 +0000325 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000326 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
327 return m_unique_ast_type_map;
328}
329
Greg Clayton6beaaa62011-01-17 03:46:26 +0000330ClangASTContext &
331SymbolFileDWARF::GetClangASTContext ()
332{
Greg Clayton1f746072012-08-29 21:13:06 +0000333 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000334 return m_debug_map_symfile->GetClangASTContext ();
335
336 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
337 if (!m_is_external_ast_source)
338 {
339 m_is_external_ast_source = true;
340 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
341 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
342 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000343 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000344 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 ast.SetExternalSource (ast_source_ap);
347 }
348 return ast;
349}
350
351void
352SymbolFileDWARF::InitializeObject()
353{
354 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000355 ModuleSP module_sp (m_obj_file->GetModule());
356 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000357 {
358 const SectionList *section_list = m_obj_file->GetSectionList();
359
360 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
361
362 // Memory map the DWARF mach-o segment so we have everything mmap'ed
363 // to keep our heap memory usage down.
364 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000365 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000366 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000367 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000368 if (m_data_apple_names.GetByteSize() > 0)
369 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000370 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
371 if (m_apple_names_ap->IsValid())
372 m_using_apple_tables = true;
373 else
Greg Clayton7f995132011-10-04 22:41:51 +0000374 m_apple_names_ap.reset();
375 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000376 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000377 if (m_data_apple_types.GetByteSize() > 0)
378 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000379 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
380 if (m_apple_types_ap->IsValid())
381 m_using_apple_tables = true;
382 else
Greg Clayton7f995132011-10-04 22:41:51 +0000383 m_apple_types_ap.reset();
384 }
385
386 get_apple_namespaces_data();
387 if (m_data_apple_namespaces.GetByteSize() > 0)
388 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000389 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
390 if (m_apple_namespaces_ap->IsValid())
391 m_using_apple_tables = true;
392 else
Greg Clayton7f995132011-10-04 22:41:51 +0000393 m_apple_namespaces_ap.reset();
394 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000395
Greg Clayton5009f9d2011-10-27 17:55:14 +0000396 get_apple_objc_data();
397 if (m_data_apple_objc.GetByteSize() > 0)
398 {
399 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
400 if (m_apple_objc_ap->IsValid())
401 m_using_apple_tables = true;
402 else
403 m_apple_objc_ap.reset();
404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407bool
408SymbolFileDWARF::SupportedVersion(uint16_t version)
409{
410 return version == 2 || version == 3;
411}
412
413uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000414SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
416 uint32_t abilities = 0;
417 if (m_obj_file != NULL)
418 {
419 const Section* section = NULL;
420 const SectionList *section_list = m_obj_file->GetSectionList();
421 if (section_list == NULL)
422 return 0;
423
424 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
430 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
Greg Clayton4ceb9982010-07-21 22:54:26 +0000433 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 if (section != NULL)
435 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000436 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000440 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 else
442 m_flags.Set (flagsGotDebugAbbrevData);
443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000445 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_flags.Set (flagsGotDebugArangesData);
447
Greg Clayton4ceb9982010-07-21 22:54:26 +0000448 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000449 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_flags.Set (flagsGotDebugFrameData);
451
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000454 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 else
456 m_flags.Set (flagsGotDebugLineData);
457
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000459 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 m_flags.Set (flagsGotDebugLocData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000463 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_flags.Set (flagsGotDebugMacInfoData);
465
Greg Clayton4ceb9982010-07-21 22:54:26 +0000466 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000467 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 m_flags.Set (flagsGotDebugPubNamesData);
469
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000471 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 m_flags.Set (flagsGotDebugPubTypesData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000475 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_flags.Set (flagsGotDebugRangesData);
477
Greg Clayton4ceb9982010-07-21 22:54:26 +0000478 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000479 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 m_flags.Set (flagsGotDebugStrData);
481 }
Greg Clayton6c596612012-05-18 21:47:20 +0000482 else
483 {
484 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
485 if (symfile_dir_cstr)
486 {
487 if (strcasestr(symfile_dir_cstr, ".dsym"))
488 {
489 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
490 {
491 // We have a dSYM file that didn't have a any debug info.
492 // If the string table has a size of 1, then it was made from
493 // an executable with no debug info, or from an executable that
494 // was stripped.
495 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
496 if (section && section->GetFileSize() == 1)
497 {
498 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
499 }
500 }
501 }
502 }
503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 return abilities;
512}
513
514const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000515SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
517 if (m_flags.IsClear (got_flag))
518 {
519 m_flags.Set (got_flag);
520 const SectionList *section_list = m_obj_file->GetSectionList();
521 if (section_list)
522 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000523 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
524 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 {
526 // See if we memory mapped the DWARF segment?
527 if (m_dwarf_data.GetByteSize())
528 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000529 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531 else
532 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 data.Clear();
535 }
536 }
537 }
538 }
539 return data;
540}
541
542const DataExtractor&
543SymbolFileDWARF::get_debug_abbrev_data()
544{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000545 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000549SymbolFileDWARF::get_debug_aranges_data()
550{
551 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
552}
553
554const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555SymbolFileDWARF::get_debug_frame_data()
556{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000557 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560const DataExtractor&
561SymbolFileDWARF::get_debug_info_data()
562{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000563 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566const DataExtractor&
567SymbolFileDWARF::get_debug_line_data()
568{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000569 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570}
571
572const DataExtractor&
573SymbolFileDWARF::get_debug_loc_data()
574{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000575 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576}
577
578const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SymbolFileDWARF::get_debug_ranges_data()
580{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000581 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582}
583
584const DataExtractor&
585SymbolFileDWARF::get_debug_str_data()
586{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000587 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Greg Claytonf9eec202011-09-01 23:16:13 +0000590const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000591SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000592{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000593 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000594}
595
596const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000597SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000598{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000599 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000600}
601
Greg Clayton7f995132011-10-04 22:41:51 +0000602const DataExtractor&
603SymbolFileDWARF::get_apple_namespaces_data()
604{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000605 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
606}
607
608const DataExtractor&
609SymbolFileDWARF::get_apple_objc_data()
610{
611 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000612}
613
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615DWARFDebugAbbrev*
616SymbolFileDWARF::DebugAbbrev()
617{
618 if (m_abbr.get() == NULL)
619 {
620 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
621 if (debug_abbrev_data.GetByteSize() > 0)
622 {
623 m_abbr.reset(new DWARFDebugAbbrev());
624 if (m_abbr.get())
625 m_abbr->Parse(debug_abbrev_data);
626 }
627 }
628 return m_abbr.get();
629}
630
631const DWARFDebugAbbrev*
632SymbolFileDWARF::DebugAbbrev() const
633{
634 return m_abbr.get();
635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugInfo*
639SymbolFileDWARF::DebugInfo()
640{
641 if (m_info.get() == NULL)
642 {
643 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
644 if (get_debug_info_data().GetByteSize() > 0)
645 {
646 m_info.reset(new DWARFDebugInfo());
647 if (m_info.get())
648 {
649 m_info->SetDwarfData(this);
650 }
651 }
652 }
653 return m_info.get();
654}
655
656const DWARFDebugInfo*
657SymbolFileDWARF::DebugInfo() const
658{
659 return m_info.get();
660}
661
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000663SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000666 if (info)
667 {
668 if (GetDebugMapSymfile ())
669 {
670 // The debug map symbol file made the compile units for this DWARF
671 // file which is .o file with DWARF in it, and we should have
672 // only 1 compile unit which is at offset zero in the DWARF.
673 // TODO: modify to support LTO .o files where each .o file might
674 // have multiple DW_TAG_compile_unit tags.
675 return info->GetCompileUnit(0).get();
676 }
677 else
678 {
679 // Just a normal DWARF file whose user ID for the compile unit is
680 // the DWARF offset itself
681 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
682 }
683 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 return NULL;
685}
686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
688DWARFDebugRanges*
689SymbolFileDWARF::DebugRanges()
690{
691 if (m_ranges.get() == NULL)
692 {
693 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
694 if (get_debug_ranges_data().GetByteSize() > 0)
695 {
696 m_ranges.reset(new DWARFDebugRanges());
697 if (m_ranges.get())
698 m_ranges->Extract(this);
699 }
700 }
701 return m_ranges.get();
702}
703
704const DWARFDebugRanges*
705SymbolFileDWARF::DebugRanges() const
706{
707 return m_ranges.get();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710lldb::CompUnitSP
711SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000713 CompUnitSP cu_sp;
714 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000716 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
717 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000719 // We already parsed this compile unit, had out a shared pointer to it
720 cu_sp = comp_unit->shared_from_this();
721 }
722 else
723 {
Greg Clayton1f746072012-08-29 21:13:06 +0000724 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton1f746072012-08-29 21:13:06 +0000726 // Let the debug map create the compile unit
727 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
728 dwarf_cu->SetUserData(cu_sp.get());
729 }
730 else
731 {
732 ModuleSP module_sp (m_obj_file->GetModule());
733 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 {
Greg Clayton1f746072012-08-29 21:13:06 +0000735 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
736 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 {
Greg Clayton1f746072012-08-29 21:13:06 +0000738 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
739 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
740 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
741 if (cu_die_name)
742 {
743 std::string ramapped_file;
744 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000745
Greg Clayton1f746072012-08-29 21:13:06 +0000746 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000747 {
Greg Clayton1f746072012-08-29 21:13:06 +0000748 // If we have a full path to the compile unit, we don't need to resolve
749 // the file. This can be expensive e.g. when the source files are NFS mounted.
750 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
751 cu_file_spec.SetFile (ramapped_file.c_str(), false);
752 else
753 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000754 }
755 else
756 {
Greg Clayton1f746072012-08-29 21:13:06 +0000757 std::string fullpath(cu_comp_dir);
758 if (*fullpath.rbegin() != '/')
759 fullpath += '/';
760 fullpath += cu_die_name;
761 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
762 cu_file_spec.SetFile (ramapped_file.c_str(), false);
763 else
764 cu_file_spec.SetFile (fullpath.c_str(), false);
765 }
766
767 cu_sp.reset(new CompileUnit (module_sp,
768 dwarf_cu,
769 cu_file_spec,
770 MakeUserID(dwarf_cu->GetOffset()),
771 cu_language));
772 if (cu_sp)
773 {
774 dwarf_cu->SetUserData(cu_sp.get());
775
Greg Clayton53eb1c22012-04-02 22:59:12 +0000776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000878 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000880 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
894 func_range.GetBaseAddress().ResolveLinkedAddress();
895
Greg Clayton81c22f62011-10-19 18:09:39 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000898 func_user_id, // UserID is the DIE offset
899 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
911 }
912 }
913 return NULL;
914}
915
Greg Clayton1f746072012-08-29 21:13:06 +0000916lldb::LanguageType
917SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
918{
919 assert (sc.comp_unit);
920 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
921 if (dwarf_cu)
922 {
923 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000924 if (die)
925 {
926 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
927 if (language)
928 return (lldb::LanguageType)language;
929 }
Greg Clayton1f746072012-08-29 21:13:06 +0000930 }
931 return eLanguageTypeUnknown;
932}
933
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000934size_t
935SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
936{
937 assert (sc.comp_unit);
938 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000939 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000940 if (dwarf_cu)
941 {
942 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000943 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000944 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000945 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946 {
947 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000948 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949 {
950 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
951 ++functions_added;
952 }
953 }
954 //FixupTypes();
955 }
956 return functions_added;
957}
958
959bool
960SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
961{
962 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000963 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000964 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000966 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967
Greg Claytonda2455b2012-11-01 17:28:37 +0000968 if (cu_die)
969 {
970 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
971 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000972
Greg Claytonda2455b2012-11-01 17:28:37 +0000973 // All file indexes in DWARF are one based and a file of index zero is
974 // supposed to be the compile unit itself.
975 support_files.Append (*sc.comp_unit);
976
977 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 }
980 return false;
981}
982
983struct ParseDWARFLineTableCallbackInfo
984{
985 LineTable* line_table;
986 const SectionList *section_list;
987 lldb::addr_t prev_sect_file_base_addr;
988 lldb::addr_t curr_sect_file_base_addr;
989 bool is_oso_for_debug_map;
990 bool prev_in_final_executable;
991 DWARFDebugLine::Row prev_row;
992 SectionSP prev_section_sp;
993 SectionSP curr_section_sp;
Andrew Kaylorc7401502013-01-04 22:57:56 +0000994 llvm::OwningPtr<LineSequence> curr_sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995};
996
997//----------------------------------------------------------------------
998// ParseStatementTableCallback
999//----------------------------------------------------------------------
1000static void
1001ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1002{
1003 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
1004 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1005 {
1006 // Just started parsing the line table
1007 }
1008 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1009 {
1010 // Done parsing line table, nothing to do for the cleanup
1011 }
1012 else
1013 {
1014 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1015 // We have a new row, lets append it
1016
1017 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
1018 {
1019 info->prev_section_sp = info->curr_section_sp;
1020 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1021 // If this is an end sequence entry, then we subtract one from the
1022 // address to make sure we get an address that is not the end of
1023 // a section.
1024 if (state.end_sequence && state.address != 0)
1025 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1026 else
1027 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1028
1029 if (info->curr_section_sp.get())
1030 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1031 else
1032 info->curr_sect_file_base_addr = 0;
1033 }
1034 if (info->curr_section_sp.get())
1035 {
1036 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1037 // Check for the fancy section magic to determine if we
1038
1039 if (info->is_oso_for_debug_map)
1040 {
1041 // When this is a debug map object file that contains DWARF
1042 // (referenced from an N_OSO debug map nlist entry) we will have
1043 // a file address in the file range for our section from the
1044 // original .o file, and a load address in the executable that
1045 // contains the debug map.
1046 //
1047 // If the sections for the file range and load range are
1048 // different, we have a remapped section for the function and
1049 // this address is resolved. If they are the same, then the
1050 // function for this address didn't make it into the final
1051 // executable.
Jim Inghamf94e1792012-08-11 00:35:26 +00001052 bool curr_in_final_executable = (bool) info->curr_section_sp->GetLinkedSection ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053
1054 // If we are doing DWARF with debug map, then we need to carefully
1055 // add each line table entry as there may be gaps as functions
1056 // get moved around or removed.
1057 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1058 {
1059 if (info->prev_in_final_executable)
1060 {
1061 bool terminate_previous_entry = false;
1062 if (!curr_in_final_executable)
1063 {
1064 // Check for the case where the previous line entry
1065 // in a function made it into the final executable,
1066 // yet the current line entry falls in a function
1067 // that didn't. The line table used to be contiguous
1068 // through this address range but now it isn't. We
1069 // need to terminate the previous line entry so
1070 // that we can reconstruct the line range correctly
1071 // for it and to keep the line table correct.
1072 terminate_previous_entry = true;
1073 }
1074 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1075 {
1076 // Check for cases where the line entries used to be
1077 // contiguous address ranges, but now they aren't.
1078 // This can happen when order files specify the
1079 // ordering of the functions.
1080 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1081 Section *curr_sect = info->curr_section_sp.get();
1082 Section *prev_sect = info->prev_section_sp.get();
1083 assert (curr_sect->GetLinkedSection());
1084 assert (prev_sect->GetLinkedSection());
1085 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1086 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1087 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1088 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1089 if (object_file_addr_delta != linked_file_addr_delta)
1090 terminate_previous_entry = true;
1091 }
1092
1093 if (terminate_previous_entry)
1094 {
1095 line_table->InsertLineEntry (info->prev_section_sp,
1096 state.address - info->prev_sect_file_base_addr,
1097 info->prev_row.line,
1098 info->prev_row.column,
1099 info->prev_row.file,
1100 false, // is_stmt
1101 false, // basic_block
1102 false, // state.prologue_end
1103 false, // state.epilogue_begin
1104 true); // end_sequence);
1105 }
1106 }
1107 }
1108
1109 if (curr_in_final_executable)
1110 {
1111 line_table->InsertLineEntry (info->curr_section_sp,
1112 curr_line_section_offset,
1113 state.line,
1114 state.column,
1115 state.file,
1116 state.is_stmt,
1117 state.basic_block,
1118 state.prologue_end,
1119 state.epilogue_begin,
1120 state.end_sequence);
1121 info->prev_section_sp = info->curr_section_sp;
1122 }
1123 else
1124 {
1125 // If the current address didn't make it into the final
1126 // executable, the current section will be the __text
1127 // segment in the .o file, so we need to clear this so
1128 // we can catch the next function that did make it into
1129 // the final executable.
1130 info->prev_section_sp.reset();
1131 info->curr_section_sp.reset();
1132 }
1133
1134 info->prev_in_final_executable = curr_in_final_executable;
1135 }
1136 else
1137 {
1138 // We are not in an object file that contains DWARF for an
1139 // N_OSO, this is just a normal DWARF file. The DWARF spec
1140 // guarantees that the addresses will be in increasing order
Andrew Kaylorc7401502013-01-04 22:57:56 +00001141 // for a sequence, but the line table for a single compile unit
1142 // may contain multiple sequences so we append entries to the
1143 // current sequence until we find its end, then we merge the
1144 // sequence into the main line table collection.
1145
1146 // If this is our first time here, we need to create a
1147 // sequence container.
1148 if (!info->curr_sequence_ap)
1149 {
1150 info->curr_sequence_ap.reset(line_table->CreateLineSequenceContainer());
1151 assert(info->curr_sequence_ap);
1152 }
1153 line_table->AppendLineEntryToSequence(info->curr_sequence_ap.get(),
1154 info->curr_section_sp,
1155 curr_line_section_offset,
1156 state.line,
1157 state.column,
1158 state.file,
1159 state.is_stmt,
1160 state.basic_block,
1161 state.prologue_end,
1162 state.epilogue_begin,
1163 state.end_sequence);
1164 if (state.end_sequence)
1165 {
1166 // First, put the current sequence into the line table.
1167 line_table->InsertSequence(info->curr_sequence_ap.get());
1168 // Then, empty it to prepare for the next sequence.
1169 info->curr_sequence_ap->Clear();
1170 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 }
1172 }
1173
1174 info->prev_row = state;
1175 }
1176}
1177
1178bool
1179SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1180{
1181 assert (sc.comp_unit);
1182 if (sc.comp_unit->GetLineTable() != NULL)
1183 return true;
1184
Greg Clayton1f746072012-08-29 21:13:06 +00001185 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 if (dwarf_cu)
1187 {
1188 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001189 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001191 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1192 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001194 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1195 if (line_table_ap.get())
1196 {
1197 ParseDWARFLineTableCallbackInfo info = {
1198 line_table_ap.get(),
1199 m_obj_file->GetSectionList(),
1200 0,
1201 0,
Greg Clayton1f746072012-08-29 21:13:06 +00001202 GetDebugMapSymfile () != NULL,
Greg Clayton129d12c2011-11-28 03:29:03 +00001203 false,
1204 DWARFDebugLine::Row(),
1205 SectionSP(),
Andrew Kaylorc7401502013-01-04 22:57:56 +00001206 SectionSP(),
1207 llvm::OwningPtr<LineSequence>()
Greg Clayton129d12c2011-11-28 03:29:03 +00001208 };
Greg Claytonc7bece562013-01-25 18:06:21 +00001209 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001210 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1211 sc.comp_unit->SetLineTable(line_table_ap.release());
1212 return true;
1213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 }
1215 }
1216 }
1217 return false;
1218}
1219
1220size_t
1221SymbolFileDWARF::ParseFunctionBlocks
1222(
1223 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001224 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001225 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 const DWARFDebugInfoEntry *die,
1227 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001228 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229)
1230{
1231 size_t blocks_added = 0;
1232 while (die != NULL)
1233 {
1234 dw_tag_t tag = die->Tag();
1235
1236 switch (tag)
1237 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001239 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 case DW_TAG_lexical_block:
1241 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001242 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001243 if (tag == DW_TAG_subprogram)
1244 {
1245 // Skip any DW_TAG_subprogram DIEs that are inside
1246 // of a normal or inlined functions. These will be
1247 // parsed on their own as separate entities.
1248
1249 if (depth > 0)
1250 break;
1251
1252 block = parent_block;
1253 }
1254 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001255 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001256 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001257 parent_block->AddChild(block_sp);
1258 block = block_sp.get();
1259 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001260 DWARFDebugRanges::RangeList ranges;
1261 const char *name = NULL;
1262 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 int decl_file = 0;
1265 int decl_line = 0;
1266 int decl_column = 0;
1267 int call_file = 0;
1268 int call_line = 0;
1269 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001270 if (die->GetDIENamesAndRanges (this,
1271 dwarf_cu,
1272 name,
1273 mangled_name,
1274 ranges,
1275 decl_file, decl_line, decl_column,
1276 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 {
1278 if (tag == DW_TAG_subprogram)
1279 {
1280 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001281 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001283 else if (tag == DW_TAG_inlined_subroutine)
1284 {
1285 // We get called here for inlined subroutines in two ways.
1286 // The first time is when we are making the Function object
1287 // for this inlined concrete instance. Since we're creating a top level block at
1288 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1289 // adjust the containing address.
1290 // The second time is when we are parsing the blocks inside the function that contains
1291 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1292 // function the offset will be for that function.
1293 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1294 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001295 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001296 }
1297 }
1298
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001299 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300
1301 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1302 {
1303 std::auto_ptr<Declaration> decl_ap;
1304 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001305 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1306 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307
1308 std::auto_ptr<Declaration> call_ap;
1309 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001310 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1311 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001313 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 }
1315
1316 ++blocks_added;
1317
Greg Claytondd7feaf2011-08-12 17:54:33 +00001318 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001320 blocks_added += ParseFunctionBlocks (sc,
1321 block,
1322 dwarf_cu,
1323 die->GetFirstChild(),
1324 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001325 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 }
1327 }
1328 }
1329 break;
1330 default:
1331 break;
1332 }
1333
Greg Claytondd7feaf2011-08-12 17:54:33 +00001334 // Only parse siblings of the block if we are not at depth zero. A depth
1335 // of zero indicates we are currently parsing the top level
1336 // DW_TAG_subprogram DIE
1337
1338 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001340 else
1341 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 }
1343 return blocks_added;
1344}
1345
Greg Claytonf0705c82011-10-22 03:33:13 +00001346bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001347SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1348 const DWARFDebugInfoEntry *die,
1349 ClangASTContext::TemplateParameterInfos &template_param_infos)
1350{
1351 const dw_tag_t tag = die->Tag();
1352
1353 switch (tag)
1354 {
1355 case DW_TAG_template_type_parameter:
1356 case DW_TAG_template_value_parameter:
1357 {
1358 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1359
1360 DWARFDebugInfoEntry::Attributes attributes;
1361 const size_t num_attributes = die->GetAttributes (this,
1362 dwarf_cu,
1363 fixed_form_sizes,
1364 attributes);
1365 const char *name = NULL;
1366 Type *lldb_type = NULL;
1367 clang_type_t clang_type = NULL;
1368 uint64_t uval64 = 0;
1369 bool uval64_valid = false;
1370 if (num_attributes > 0)
1371 {
1372 DWARFFormValue form_value;
1373 for (size_t i=0; i<num_attributes; ++i)
1374 {
1375 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1376
1377 switch (attr)
1378 {
1379 case DW_AT_name:
1380 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1381 name = form_value.AsCString(&get_debug_str_data());
1382 break;
1383
1384 case DW_AT_type:
1385 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1386 {
1387 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1388 lldb_type = ResolveTypeUID(type_die_offset);
1389 if (lldb_type)
1390 clang_type = lldb_type->GetClangForwardType();
1391 }
1392 break;
1393
1394 case DW_AT_const_value:
1395 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1396 {
1397 uval64_valid = true;
1398 uval64 = form_value.Unsigned();
1399 }
1400 break;
1401 default:
1402 break;
1403 }
1404 }
1405
1406 if (name && lldb_type && clang_type)
1407 {
1408 bool is_signed = false;
1409 template_param_infos.names.push_back(name);
1410 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1411 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1412 {
1413 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001414 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1415 llvm::APSInt(apint),
1416 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001417 }
1418 else
1419 {
1420 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1421 }
1422 }
1423 else
1424 {
1425 return false;
1426 }
1427
1428 }
1429 }
1430 return true;
1431
1432 default:
1433 break;
1434 }
1435 return false;
1436}
1437
1438bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001439SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1440 const DWARFDebugInfoEntry *parent_die,
1441 ClangASTContext::TemplateParameterInfos &template_param_infos)
1442{
1443
1444 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001445 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001446
Greg Claytonf0705c82011-10-22 03:33:13 +00001447 Args template_parameter_names;
1448 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1449 die != NULL;
1450 die = die->GetSibling())
1451 {
1452 const dw_tag_t tag = die->Tag();
1453
1454 switch (tag)
1455 {
1456 case DW_TAG_template_type_parameter:
1457 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001458 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001459 break;
1460
1461 default:
1462 break;
1463 }
1464 }
1465 if (template_param_infos.args.empty())
1466 return false;
1467 return template_param_infos.args.size() == template_param_infos.names.size();
1468}
1469
1470clang::ClassTemplateDecl *
1471SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001472 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001473 const char *parent_name,
1474 int tag_decl_kind,
1475 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1476{
1477 if (template_param_infos.IsValid())
1478 {
1479 std::string template_basename(parent_name);
1480 template_basename.erase (template_basename.find('<'));
1481 ClangASTContext &ast = GetClangASTContext();
1482
1483 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001484 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001485 template_basename.c_str(),
1486 tag_decl_kind,
1487 template_param_infos);
1488 }
1489 return NULL;
1490}
1491
Sean Callanana0b80ab2012-06-04 22:28:05 +00001492class SymbolFileDWARF::DelayedAddObjCClassProperty
1493{
1494public:
1495 DelayedAddObjCClassProperty
1496 (
1497 clang::ASTContext *ast,
1498 lldb::clang_type_t class_opaque_type,
1499 const char *property_name,
1500 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1501 clang::ObjCIvarDecl *ivar_decl,
1502 const char *property_setter_name,
1503 const char *property_getter_name,
1504 uint32_t property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001505 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001506 ) :
1507 m_ast (ast),
1508 m_class_opaque_type (class_opaque_type),
1509 m_property_name (property_name),
1510 m_property_opaque_type (property_opaque_type),
1511 m_ivar_decl (ivar_decl),
1512 m_property_setter_name (property_setter_name),
1513 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001514 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001515 {
Jim Ingham379397632012-10-27 02:54:13 +00001516 if (metadata != NULL)
1517 {
1518 m_metadata_ap.reset(new ClangASTMetadata());
1519 *(m_metadata_ap.get()) = *metadata;
1520 }
1521 }
1522
1523 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1524 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001525 *this = rhs;
1526 }
1527
1528 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1529 {
Jim Ingham379397632012-10-27 02:54:13 +00001530 m_ast = rhs.m_ast;
1531 m_class_opaque_type = rhs.m_class_opaque_type;
1532 m_property_name = rhs.m_property_name;
1533 m_property_opaque_type = rhs.m_property_opaque_type;
1534 m_ivar_decl = rhs.m_ivar_decl;
1535 m_property_setter_name = rhs.m_property_setter_name;
1536 m_property_getter_name = rhs.m_property_getter_name;
1537 m_property_attributes = rhs.m_property_attributes;
1538
1539 if (rhs.m_metadata_ap.get())
1540 {
1541 m_metadata_ap.reset (new ClangASTMetadata());
1542 *(m_metadata_ap.get()) = *(rhs.m_metadata_ap.get());
1543 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001544 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001545 }
1546
1547 bool Finalize() const
1548 {
1549 return ClangASTContext::AddObjCClassProperty(m_ast,
1550 m_class_opaque_type,
1551 m_property_name,
1552 m_property_opaque_type,
1553 m_ivar_decl,
1554 m_property_setter_name,
1555 m_property_getter_name,
1556 m_property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001557 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001558 }
1559private:
1560 clang::ASTContext *m_ast;
1561 lldb::clang_type_t m_class_opaque_type;
1562 const char *m_property_name;
1563 lldb::clang_type_t m_property_opaque_type;
1564 clang::ObjCIvarDecl *m_ivar_decl;
1565 const char *m_property_setter_name;
1566 const char *m_property_getter_name;
1567 uint32_t m_property_attributes;
Jim Ingham379397632012-10-27 02:54:13 +00001568 std::auto_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001569};
1570
Sean Callananfaa0bb32012-12-05 23:37:14 +00001571struct BitfieldInfo
1572{
1573 uint64_t bit_size;
1574 uint64_t bit_offset;
1575
1576 BitfieldInfo () :
1577 bit_size (LLDB_INVALID_ADDRESS),
1578 bit_offset (LLDB_INVALID_ADDRESS)
1579 {
1580 }
1581
1582 bool IsValid ()
1583 {
1584 return (bit_size != LLDB_INVALID_ADDRESS) &&
1585 (bit_offset != LLDB_INVALID_ADDRESS);
1586 }
1587};
1588
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589size_t
1590SymbolFileDWARF::ParseChildMembers
1591(
1592 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001593 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001594 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001595 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001596 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1598 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001599 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001600 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001601 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001602 bool &is_a_class,
1603 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604)
1605{
1606 if (parent_die == NULL)
1607 return 0;
1608
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609 size_t count = 0;
1610 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001611 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001612 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001613 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001614
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1616 {
1617 dw_tag_t tag = die->Tag();
1618
1619 switch (tag)
1620 {
1621 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001622 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623 {
1624 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001625 const size_t num_attributes = die->GetAttributes (this,
1626 dwarf_cu,
1627 fixed_form_sizes,
1628 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001629 if (num_attributes > 0)
1630 {
1631 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001632 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001633 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001634 const char *prop_name = NULL;
1635 const char *prop_getter_name = NULL;
1636 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001637 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001638
1639
Greg Clayton24739922010-10-13 03:15:28 +00001640 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001641 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001642 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001643 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 size_t byte_size = 0;
1645 size_t bit_offset = 0;
1646 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001647 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001648 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001649 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650 {
1651 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1652 DWARFFormValue form_value;
1653 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1654 {
1655 switch (attr)
1656 {
1657 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1658 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1659 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1660 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1661 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1662 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1663 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1664 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1665 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001666 if (form_value.BlockData())
1667 {
1668 Value initialValue(0);
1669 Value memberOffset(0);
1670 const DataExtractor& debug_info_data = get_debug_info_data();
1671 uint32_t block_length = form_value.Unsigned();
1672 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1673 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1674 NULL, // clang::ASTContext *
1675 NULL, // ClangExpressionVariableList *
1676 NULL, // ClangExpressionDeclMap *
1677 NULL, // RegisterContext *
1678 debug_info_data,
1679 block_offset,
1680 block_length,
1681 eRegisterKindDWARF,
1682 &initialValue,
1683 memberOffset,
1684 NULL))
1685 {
1686 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1687 }
1688 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001689 break;
1690
Greg Clayton8cf05932010-07-22 18:30:50 +00001691 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001692 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001693 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1694 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1695 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1696 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001697 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001698
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001700 case DW_AT_declaration:
1701 case DW_AT_description:
1702 case DW_AT_mutable:
1703 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704 case DW_AT_sibling:
1705 break;
1706 }
1707 }
1708 }
Sean Callanana6582262012-04-05 00:12:52 +00001709
1710 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001711 {
Sean Callanana6582262012-04-05 00:12:52 +00001712 ConstString fixed_getter;
1713 ConstString fixed_setter;
1714
1715 // Check if the property getter/setter were provided as full
1716 // names. We want basenames, so we extract them.
1717
1718 if (prop_getter_name && prop_getter_name[0] == '-')
1719 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001720 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1721 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001722 }
1723
1724 if (prop_setter_name && prop_setter_name[0] == '-')
1725 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001726 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1727 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001728 }
1729
1730 // If the names haven't been provided, they need to be
1731 // filled in.
1732
1733 if (!prop_getter_name)
1734 {
1735 prop_getter_name = prop_name;
1736 }
1737 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1738 {
1739 StreamString ss;
1740
1741 ss.Printf("set%c%s:",
1742 toupper(prop_name[0]),
1743 &prop_name[1]);
1744
1745 fixed_setter.SetCString(ss.GetData());
1746 prop_setter_name = fixed_setter.GetCString();
1747 }
Sean Callanan751aac62012-03-29 19:07:06 +00001748 }
1749
1750 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001751 // represents fields that are references with bad byte size
1752 // and bit size/offset information such as:
1753 //
1754 // DW_AT_byte_size( 0x00 )
1755 // DW_AT_bit_size( 0x40 )
1756 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1757 //
1758 // So check the bit offset to make sure it is sane, and if
1759 // the values are not sane, remove them. If we don't do this
1760 // then we will end up with a crash if we try to use this
1761 // type in an expression when clang becomes unhappy with its
1762 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001763
Greg Clayton44953932011-10-25 01:25:35 +00001764 if (bit_offset > 128)
1765 {
1766 bit_size = 0;
1767 bit_offset = 0;
1768 }
1769
1770 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001771 if (class_language == eLanguageTypeObjC ||
1772 class_language == eLanguageTypeObjC_plus_plus)
1773 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001774
1775 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1776 {
1777 // Not all compilers will mark the vtable pointer
1778 // member as artificial (llvm-gcc). We can't have
1779 // the virtual members in our classes otherwise it
1780 // throws off all child offsets since we end up
1781 // having and extra pointer sized member in our
1782 // class layouts.
1783 is_artificial = true;
1784 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001785
Greg Claytone528efd72013-02-26 23:45:18 +00001786 // Skip static members
1787 if (is_external && member_byte_offset == UINT32_MAX)
1788 break;
1789
Greg Clayton24739922010-10-13 03:15:28 +00001790 if (is_artificial == false)
1791 {
1792 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001793
Jim Inghame3ae82a2011-11-12 01:36:43 +00001794 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001795 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001796 {
Sean Callanan751aac62012-03-29 19:07:06 +00001797 if (member_type)
1798 {
1799 if (accessibility == eAccessNone)
1800 accessibility = default_accessibility;
1801 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001802
1803 BitfieldInfo this_field_info;
1804
1805 this_field_info.bit_size = bit_size;
1806
1807 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001808 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001809 /////////////////////////////////////////////////////////////
1810 // How to locate a field given the DWARF debug information
1811 //
1812 // AT_byte_size indicates the size of the word in which the
1813 // bit offset must be interpreted.
1814 //
1815 // AT_data_member_location indicates the byte offset of the
1816 // word from the base address of the structure.
1817 //
1818 // AT_bit_offset indicates how many bits into the word
1819 // (according to the host endianness) the low-order bit of
1820 // the field starts. AT_bit_offset can be negative.
1821 //
1822 // AT_bit_size indicates the size of the field in bits.
1823 /////////////////////////////////////////////////////////////
1824
1825 this_field_info.bit_offset = 0;
1826
1827 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1828
1829 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1830 {
1831 this_field_info.bit_offset += byte_size * 8;
1832 this_field_info.bit_offset -= (bit_offset + bit_size);
1833 }
1834 else
1835 {
1836 this_field_info.bit_offset += bit_offset;
1837 }
1838 }
1839
1840 // If the member to be emitted did not start on a character boundary and there is
1841 // empty space between the last field and this one, then we need to emit an
1842 // anonymous member filling up the space up to its start. There are three cases
1843 // here:
1844 //
1845 // 1 If the previous member ended on a character boundary, then we can emit an
1846 // anonymous member starting at the most recent character boundary.
1847 //
1848 // 2 If the previous member did not end on a character boundary and the distance
1849 // from the end of the previous member to the current member is less than a
1850 // word width, then we can emit an anonymous member starting right after the
1851 // previous member and right before this member.
1852 //
1853 // 3 If the previous member did not end on a character boundary and the distance
1854 // from the end of the previous member to the current member is greater than
1855 // or equal a word width, then we act as in Case 1.
1856
1857 const uint64_t character_width = 8;
1858 const uint64_t word_width = 32;
1859
1860 if (this_field_info.IsValid())
1861 {
1862 // Objective-C has invalid DW_AT_bit_offset values in older versions
1863 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001864 // if we have a new enough clang.
1865 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001866
Greg Clayton37c36e42012-11-27 00:59:26 +00001867 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1868 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1869
1870 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001871 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001872 BitfieldInfo anon_field_info;
1873
1874 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001875 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001876 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001877
Sean Callananfaa0bb32012-12-05 23:37:14 +00001878 if (last_field_info.IsValid())
1879 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001880
Sean Callananfaa0bb32012-12-05 23:37:14 +00001881 if (this_field_info.bit_offset != last_field_end)
1882 {
1883 if (((last_field_end % character_width) == 0) || // case 1
1884 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1885 {
1886 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1887 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1888 }
1889 else // case 2
1890 {
1891 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1892 anon_field_info.bit_offset = last_field_end;
1893 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001894 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001895 }
1896
Sean Callananfaa0bb32012-12-05 23:37:14 +00001897 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001898 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001899 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1900 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001901 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001902 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001903 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001904
Sean Callananfaa0bb32012-12-05 23:37:14 +00001905 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001906 }
1907 }
1908 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001909
Sean Callananfa3ab452012-12-14 00:54:13 +00001910 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1911
1912 {
1913 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1914 // If the current field is at the end of the structure, then there is definitely no room for extra
1915 // elements and we override the type to array[0].
1916
1917 clang_type_t member_array_element_type;
1918 uint64_t member_array_size;
1919 bool member_array_is_incomplete;
1920
1921 if (GetClangASTContext().IsArrayType(member_clang_type,
1922 &member_array_element_type,
1923 &member_array_size,
1924 &member_array_is_incomplete) &&
1925 !member_array_is_incomplete)
1926 {
1927 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1928
1929 if (member_byte_offset >= parent_byte_size)
1930 {
1931 if (member_array_size != 1)
1932 {
1933 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,
1934 MakeUserID(die->GetOffset()),
1935 name,
1936 encoding_uid,
1937 MakeUserID(parent_die->GetOffset()));
1938 }
1939
1940 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0);
1941 }
1942 }
1943 }
1944
Greg Clayton88bc7f32012-11-06 00:20:41 +00001945 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001946 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001947 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001948 accessibility,
1949 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001950
Jim Ingham379397632012-10-27 02:54:13 +00001951 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001952
1953 if (this_field_info.IsValid())
1954 {
1955 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1956 last_field_info = this_field_info;
1957 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001958 }
1959 else
1960 {
Sean Callanan751aac62012-03-29 19:07:06 +00001961 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001962 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 +00001963 MakeUserID(die->GetOffset()),
1964 name,
1965 encoding_uid);
1966 else
Daniel Malead01b2952012-11-29 21:49:15 +00001967 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 +00001968 MakeUserID(die->GetOffset()),
1969 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001970 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001971 }
Sean Callanan751aac62012-03-29 19:07:06 +00001972
Jim Inghame3ae82a2011-11-12 01:36:43 +00001973 if (prop_name != NULL)
1974 {
Sean Callanan751aac62012-03-29 19:07:06 +00001975 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001976
Sean Callanan751aac62012-03-29 19:07:06 +00001977 if (field_decl)
1978 {
1979 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1980 assert (ivar_decl != NULL);
1981 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001982
Jim Ingham379397632012-10-27 02:54:13 +00001983 ClangASTMetadata metadata;
1984 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001985 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1986 class_clang_type,
1987 prop_name,
1988 member_type->GetClangLayoutType(),
1989 ivar_decl,
1990 prop_setter_name,
1991 prop_getter_name,
1992 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001993 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001994
Sean Callananad880762012-04-18 01:06:17 +00001995 if (ivar_decl)
Jim Ingham379397632012-10-27 02:54:13 +00001996 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001997 }
Greg Clayton24739922010-10-13 03:15:28 +00001998 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00002000 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001 }
2002 break;
2003
2004 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00002005 // Let the type parsing code handle this one for us.
2006 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007 break;
2008
2009 case DW_TAG_inheritance:
2010 {
2011 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00002012 if (default_accessibility == eAccessNone)
2013 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 // TODO: implement DW_TAG_inheritance type parsing
2015 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00002016 const size_t num_attributes = die->GetAttributes (this,
2017 dwarf_cu,
2018 fixed_form_sizes,
2019 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020 if (num_attributes > 0)
2021 {
2022 Declaration decl;
2023 DWARFExpression location;
2024 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00002025 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002026 bool is_virtual = false;
2027 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002028 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 uint32_t i;
2030 for (i=0; i<num_attributes; ++i)
2031 {
2032 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2033 DWARFFormValue form_value;
2034 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2035 {
2036 switch (attr)
2037 {
2038 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2039 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2040 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2041 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002042 case DW_AT_data_member_location:
2043 if (form_value.BlockData())
2044 {
2045 Value initialValue(0);
2046 Value memberOffset(0);
2047 const DataExtractor& debug_info_data = get_debug_info_data();
2048 uint32_t block_length = form_value.Unsigned();
2049 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2050 if (DWARFExpression::Evaluate (NULL,
2051 NULL,
2052 NULL,
2053 NULL,
2054 NULL,
2055 debug_info_data,
2056 block_offset,
2057 block_length,
2058 eRegisterKindDWARF,
2059 &initialValue,
2060 memberOffset,
2061 NULL))
2062 {
2063 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
2064 }
2065 }
2066 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067
2068 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00002069 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070 break;
2071
2072 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
2073 default:
2074 case DW_AT_sibling:
2075 break;
2076 }
2077 }
2078 }
2079
Greg Clayton526e5af2010-11-13 03:52:47 +00002080 Type *base_class_type = ResolveTypeUID(encoding_uid);
2081 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002082
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002083 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2084 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002085 if (class_language == eLanguageTypeObjC)
2086 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002087 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002088 }
2089 else
2090 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002091 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002092 accessibility,
2093 is_virtual,
2094 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002095
2096 if (is_virtual)
2097 {
2098 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2099 clang::CharUnits::fromQuantity(member_byte_offset)));
2100 }
2101 else
2102 {
2103 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2104 clang::CharUnits::fromQuantity(member_byte_offset)));
2105 }
Greg Clayton9e409562010-07-28 02:04:09 +00002106 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002107 }
2108 }
2109 break;
2110
2111 default:
2112 break;
2113 }
2114 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002115
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116 return count;
2117}
2118
2119
2120clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002121SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002122{
2123 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002124 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002125 {
2126 DWARFCompileUnitSP cu_sp;
2127 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2128 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002129 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002130 }
2131 return NULL;
2132}
2133
2134clang::DeclContext*
2135SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2136{
Greg Clayton81c22f62011-10-19 18:09:39 +00002137 if (UserIDMatches(type_uid))
2138 return GetClangDeclContextForDIEOffset (sc, type_uid);
2139 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002140}
2141
2142Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002143SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002144{
Greg Clayton81c22f62011-10-19 18:09:39 +00002145 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002146 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002147 DWARFDebugInfo* debug_info = DebugInfo();
2148 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002149 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002150 DWARFCompileUnitSP cu_sp;
2151 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002152 const bool assert_not_being_parsed = true;
2153 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002154 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002155 }
2156 return NULL;
2157}
2158
Greg Claytoncab36a32011-12-08 05:16:30 +00002159Type*
2160SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002161{
Greg Claytoncab36a32011-12-08 05:16:30 +00002162 if (die != NULL)
2163 {
Greg Clayton3bffb082011-12-10 02:15:28 +00002164 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
2165 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002166 GetObjectFile()->GetModule()->LogMessage (log.get(),
2167 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2168 die->GetOffset(),
2169 DW_TAG_value_to_name(die->Tag()),
2170 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002171
Greg Claytoncab36a32011-12-08 05:16:30 +00002172 // We might be coming in in the middle of a type tree (a class
2173 // withing a class, an enum within a class), so parse any needed
2174 // parent DIEs before we get to this one...
2175 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2176 switch (decl_ctx_die->Tag())
2177 {
2178 case DW_TAG_structure_type:
2179 case DW_TAG_union_type:
2180 case DW_TAG_class_type:
2181 {
2182 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002183 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002184 GetObjectFile()->GetModule()->LogMessage (log.get(),
2185 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2186 die->GetOffset(),
2187 DW_TAG_value_to_name(die->Tag()),
2188 die->GetName(this, cu),
2189 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002190//
2191// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2192// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2193// {
2194// if (log)
2195// GetObjectFile()->GetModule()->LogMessage (log.get(),
2196// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2197// die->GetOffset(),
2198// DW_TAG_value_to_name(die->Tag()),
2199// die->GetName(this, cu),
2200// decl_ctx_die->GetOffset());
2201// // Ask the type to complete itself if it already hasn't since if we
2202// // want a function (method or static) from a class, the class must
2203// // create itself and add it's own methods and class functions.
2204// if (parent_type)
2205// parent_type->GetClangFullType();
2206// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002207 }
2208 break;
2209
2210 default:
2211 break;
2212 }
2213 return ResolveType (cu, die);
2214 }
2215 return NULL;
2216}
2217
Greg Clayton6beaaa62011-01-17 03:46:26 +00002218// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2219// SymbolFileDWARF objects to detect if this DWARF file is the one that
2220// can resolve a clang_type.
2221bool
2222SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2223{
2224 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2225 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2226 return die != NULL;
2227}
2228
2229
Greg Clayton1be10fc2010-09-29 01:12:09 +00002230lldb::clang_type_t
2231SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2232{
2233 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002234 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2235 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002236 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002237 {
2238 // We have already resolved this type...
2239 return clang_type;
2240 }
2241 // Once we start resolving this type, remove it from the forward declaration
2242 // map in case anyone child members or other types require this type to get resolved.
2243 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2244 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002245 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002246
Greg Clayton1be10fc2010-09-29 01:12:09 +00002247
Greg Clayton85ae2e12011-10-18 23:36:41 +00002248 // Disable external storage for this type so we don't get anymore
2249 // clang::ExternalASTSource queries for this type.
2250 ClangASTContext::SetHasExternalStorage (clang_type, false);
2251
Greg Clayton450e3f32010-10-12 02:24:53 +00002252 DWARFDebugInfo* debug_info = DebugInfo();
2253
Greg Clayton53eb1c22012-04-02 22:59:12 +00002254 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002255 Type *type = m_die_to_type.lookup (die);
2256
2257 const dw_tag_t tag = die->Tag();
2258
Greg Claytonbaf95da2012-03-30 23:50:54 +00002259 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002260 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002261 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002262 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002263 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002264 MakeUserID(die->GetOffset()),
2265 DW_TAG_value_to_name(tag),
2266 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002267
Greg Claytonbaf95da2012-03-30 23:50:54 +00002268 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002269 assert (clang_type);
2270 DWARFDebugInfoEntry::Attributes attributes;
2271
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002272 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002273
2274 switch (tag)
2275 {
2276 case DW_TAG_structure_type:
2277 case DW_TAG_union_type:
2278 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002279 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002280 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002281
Greg Clayton1be10fc2010-09-29 01:12:09 +00002282 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002283 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002284 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002285
Sean Callanan77a1fd32012-02-27 20:07:01 +00002286 LanguageType class_language = eLanguageTypeUnknown;
2287 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2288 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002289 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002290 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002291 // For objective C we don't start the definition when
2292 // the class is created.
2293 ast.StartTagDeclarationDefinition (clang_type);
2294 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002295
2296 int tag_decl_kind = -1;
2297 AccessType default_accessibility = eAccessNone;
2298 if (tag == DW_TAG_structure_type)
2299 {
2300 tag_decl_kind = clang::TTK_Struct;
2301 default_accessibility = eAccessPublic;
2302 }
2303 else if (tag == DW_TAG_union_type)
2304 {
2305 tag_decl_kind = clang::TTK_Union;
2306 default_accessibility = eAccessPublic;
2307 }
2308 else if (tag == DW_TAG_class_type)
2309 {
2310 tag_decl_kind = clang::TTK_Class;
2311 default_accessibility = eAccessPrivate;
2312 }
2313
Greg Clayton53eb1c22012-04-02 22:59:12 +00002314 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002315 std::vector<clang::CXXBaseSpecifier *> base_classes;
2316 std::vector<int> member_accessibilities;
2317 bool is_a_class = false;
2318 // Parse members and base classes first
2319 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002320
2321 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002322 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002323 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002324 die,
2325 clang_type,
2326 class_language,
2327 base_classes,
2328 member_accessibilities,
2329 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002330 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002331 default_accessibility,
2332 is_a_class,
2333 layout_info);
2334
2335 // Now parse any methods if there were any...
2336 size_t num_functions = member_function_dies.Size();
2337 if (num_functions > 0)
2338 {
2339 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002340 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002341 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002342 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002343 }
2344
2345 if (class_language == eLanguageTypeObjC)
2346 {
Greg Clayton84db9102012-03-26 23:03:23 +00002347 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002348 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002349 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002350
Sean Callanan77a1fd32012-02-27 20:07:01 +00002351 DIEArray method_die_offsets;
2352 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002353 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002354 if (m_apple_objc_ap.get())
2355 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2356 }
2357 else
2358 {
2359 if (!m_indexed)
2360 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002361
Sean Callanan77a1fd32012-02-27 20:07:01 +00002362 ConstString class_name (class_str.c_str());
2363 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2364 }
2365
2366 if (!method_die_offsets.empty())
2367 {
2368 DWARFDebugInfo* debug_info = DebugInfo();
2369
2370 DWARFCompileUnit* method_cu = NULL;
2371 const size_t num_matches = method_die_offsets.size();
2372 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002373 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002374 const dw_offset_t die_offset = method_die_offsets[i];
2375 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2376
2377 if (method_die)
2378 ResolveType (method_cu, method_die);
2379 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002380 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002381 if (m_using_apple_tables)
2382 {
2383 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2384 die_offset, class_str.c_str());
2385 }
2386 }
2387 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002388 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002389
2390 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2391 pi != pe;
2392 ++pi)
2393 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002394 }
2395 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002396
2397 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2398 // need to tell the clang type it is actually a class.
2399 if (class_language != eLanguageTypeObjC)
2400 {
2401 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2402 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2403 }
2404
2405 // Since DW_TAG_structure_type gets used for both classes
2406 // and structures, we may need to set any DW_TAG_member
2407 // fields to have a "private" access if none was specified.
2408 // When we parsed the child members we tracked that actual
2409 // accessibility value for each DW_TAG_member in the
2410 // "member_accessibilities" array. If the value for the
2411 // member is zero, then it was set to the "default_accessibility"
2412 // which for structs was "public". Below we correct this
2413 // by setting any fields to "private" that weren't correctly
2414 // set.
2415 if (is_a_class && !member_accessibilities.empty())
2416 {
2417 // This is a class and all members that didn't have
2418 // their access specified are private.
2419 ast.SetDefaultAccessForRecordFields (clang_type,
2420 eAccessPrivate,
2421 &member_accessibilities.front(),
2422 member_accessibilities.size());
2423 }
2424
2425 if (!base_classes.empty())
2426 {
2427 ast.SetBaseClassesForClassType (clang_type,
2428 &base_classes.front(),
2429 base_classes.size());
2430
2431 // Clang will copy each CXXBaseSpecifier in "base_classes"
2432 // so we have to free them all.
2433 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2434 base_classes.size());
2435 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002436 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002437 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002438
2439 ast.BuildIndirectFields (clang_type);
2440
Sean Callanan77a1fd32012-02-27 20:07:01 +00002441 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002442
Greg Clayton2508b9b2012-11-01 23:20:02 +00002443 if (!layout_info.field_offsets.empty() ||
2444 !layout_info.base_offsets.empty() ||
2445 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002446 {
2447 if (type)
2448 layout_info.bit_size = type->GetByteSize() * 8;
2449 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002450 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002451
2452 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2453 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002454 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002455 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002456 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002457 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00002458 "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 +00002459 clang_type,
2460 record_decl,
2461 layout_info.bit_size,
2462 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002463 (uint32_t)layout_info.field_offsets.size(),
2464 (uint32_t)layout_info.base_offsets.size(),
2465 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002466
Greg Clayton2508b9b2012-11-01 23:20:02 +00002467 uint32_t idx;
2468 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002469 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002470 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002471 {
2472 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002473 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002474 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002475 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002476 (uint32_t)pos->second,
2477 pos->first->getNameAsString().c_str());
2478 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002479 }
2480
2481 {
2482 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2483 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2484 {
2485 GetObjectFile()->GetModule()->LogMessage (log.get(),
2486 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2487 clang_type,
2488 idx,
2489 (uint32_t)base_pos->second.getQuantity(),
2490 base_pos->first->getNameAsString().c_str());
2491 }
2492 }
2493 {
2494 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2495 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2496 {
2497 GetObjectFile()->GetModule()->LogMessage (log.get(),
2498 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2499 clang_type,
2500 idx,
2501 (uint32_t)vbase_pos->second.getQuantity(),
2502 vbase_pos->first->getNameAsString().c_str());
2503 }
2504 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002505 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002506 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2507 }
2508 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002509 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002510
Greg Claytonc93237c2010-10-01 20:48:32 +00002511 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002512
2513 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002514 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002515 if (die->HasChildren())
2516 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002517 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2518 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002519 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002520 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002521 return clang_type;
2522
2523 default:
2524 assert(false && "not a forward clang type decl!");
2525 break;
2526 }
2527 return NULL;
2528}
2529
Greg Claytonc685f8e2010-09-15 04:15:46 +00002530Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002531SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002532{
2533 if (type_die != NULL)
2534 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002535 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002536
Greg Claytonc685f8e2010-09-15 04:15:46 +00002537 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002538 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002539
Greg Clayton24739922010-10-13 03:15:28 +00002540 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002541 {
2542 if (type != DIE_IS_BEING_PARSED)
2543 return type;
2544
2545 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002546 type_die->GetOffset(),
2547 DW_TAG_value_to_name(type_die->Tag()),
2548 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002549
2550 }
2551 else
2552 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002553 }
2554 return NULL;
2555}
2556
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002557CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002558SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002559{
2560 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002561 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002562 {
2563 // The symbol vendor doesn't know about this compile unit, we
2564 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002565 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002566 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002567 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002568}
2569
2570bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002571SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002572{
Greg Clayton72310352013-02-23 04:12:47 +00002573 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002574 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002575 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002576
Greg Clayton81c22f62011-10-19 18:09:39 +00002577 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002578 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002579 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002580
2581 if (sc.function)
2582 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002583 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002584 return true;
2585 }
2586
2587 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002588}
2589
2590uint32_t
2591SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2592{
2593 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002594 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002595 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002596 so_addr.GetOffset(),
2597 resolve_scope);
2598 uint32_t resolved = 0;
2599 if (resolve_scope & ( eSymbolContextCompUnit |
2600 eSymbolContextFunction |
2601 eSymbolContextBlock |
2602 eSymbolContextLineEntry))
2603 {
2604 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2605
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002606 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002607 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002608 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002609 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002610 if (cu_offset != DW_INVALID_OFFSET)
2611 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002612 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002613 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2614 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002615 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002616 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002617 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002618 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002619 resolved |= eSymbolContextCompUnit;
2620
Greg Clayton6ab80132012-12-12 17:30:52 +00002621 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002622 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2623 {
2624 DWARFDebugInfoEntry *function_die = NULL;
2625 DWARFDebugInfoEntry *block_die = NULL;
2626 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002627 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002628 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2629 }
2630 else
2631 {
2632 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2633 }
2634
2635 if (function_die != NULL)
2636 {
2637 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2638 if (sc.function == NULL)
2639 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2640 }
2641 else
2642 {
2643 // We might have had a compile unit that had discontiguous
2644 // address ranges where the gaps are symbols that don't have
2645 // any debug info. Discontiguous compile unit address ranges
2646 // should only happen when there aren't other functions from
2647 // other compile units in these gaps. This helps keep the size
2648 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002649 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002650 }
2651
2652 if (sc.function != NULL)
2653 {
2654 resolved |= eSymbolContextFunction;
2655
2656 if (resolve_scope & eSymbolContextBlock)
2657 {
2658 Block& block = sc.function->GetBlock (true);
2659
2660 if (block_die != NULL)
2661 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2662 else
2663 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2664 if (sc.block)
2665 resolved |= eSymbolContextBlock;
2666 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002667 }
2668 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002669
2670 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2671 {
2672 LineTable *line_table = sc.comp_unit->GetLineTable();
2673 if (line_table != NULL)
2674 {
2675 if (so_addr.IsLinkedAddress())
2676 {
2677 Address linked_addr (so_addr);
2678 linked_addr.ResolveLinkedAddress();
2679 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2680 {
2681 resolved |= eSymbolContextLineEntry;
2682 }
2683 }
2684 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2685 {
2686 resolved |= eSymbolContextLineEntry;
2687 }
2688 }
2689 }
2690
2691 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2692 {
2693 // We might have had a compile unit that had discontiguous
2694 // address ranges where the gaps are symbols that don't have
2695 // any debug info. Discontiguous compile unit address ranges
2696 // should only happen when there aren't other functions from
2697 // other compile units in these gaps. This helps keep the size
2698 // of the aranges down.
2699 sc.comp_unit = NULL;
2700 resolved &= ~eSymbolContextCompUnit;
2701 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002703 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002704 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002705 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2706 cu_offset,
2707 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002708 }
2709 }
2710 }
2711 }
2712 }
2713 return resolved;
2714}
2715
2716
2717
2718uint32_t
2719SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2720{
2721 const uint32_t prev_size = sc_list.GetSize();
2722 if (resolve_scope & eSymbolContextCompUnit)
2723 {
2724 DWARFDebugInfo* debug_info = DebugInfo();
2725 if (debug_info)
2726 {
2727 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002728 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002729
Greg Clayton53eb1c22012-04-02 22:59:12 +00002730 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002731 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002732 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002733 const bool full_match = file_spec.GetDirectory();
2734 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 +00002735 if (check_inlines || file_spec_matches_cu_file_spec)
2736 {
2737 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002738 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002739 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002740 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002741 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002742
Greg Clayton526a4ae2012-05-16 22:09:01 +00002743 // If we are looking for inline functions only and we don't
2744 // find it in the support files, we are done.
2745 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002746 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002747 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2748 if (file_idx == UINT32_MAX)
2749 continue;
2750 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002751
Greg Clayton526a4ae2012-05-16 22:09:01 +00002752 if (line != 0)
2753 {
2754 LineTable *line_table = sc.comp_unit->GetLineTable();
2755
2756 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002757 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002758 // We will have already looked up the file index if
2759 // we are searching for inline entries.
2760 if (!check_inlines)
2761 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002762
Greg Clayton526a4ae2012-05-16 22:09:01 +00002763 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002764 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002765 uint32_t found_line;
2766 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2767 found_line = sc.line_entry.line;
2768
2769 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002770 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002771 sc.function = NULL;
2772 sc.block = NULL;
2773 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002774 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002775 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2776 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002777 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002778 DWARFDebugInfoEntry *function_die = NULL;
2779 DWARFDebugInfoEntry *block_die = NULL;
2780 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002781
Greg Clayton526a4ae2012-05-16 22:09:01 +00002782 if (function_die != NULL)
2783 {
2784 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2785 if (sc.function == NULL)
2786 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2787 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002788
Greg Clayton526a4ae2012-05-16 22:09:01 +00002789 if (sc.function != NULL)
2790 {
2791 Block& block = sc.function->GetBlock (true);
2792
2793 if (block_die != NULL)
2794 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2795 else
2796 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2797 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002798 }
2799 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002800
Greg Clayton526a4ae2012-05-16 22:09:01 +00002801 sc_list.Append(sc);
2802 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2803 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002804 }
2805 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002806 else if (file_spec_matches_cu_file_spec && !check_inlines)
2807 {
2808 // only append the context if we aren't looking for inline call sites
2809 // by file and line and if the file spec matches that of the compile unit
2810 sc_list.Append(sc);
2811 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002812 }
2813 else if (file_spec_matches_cu_file_spec && !check_inlines)
2814 {
2815 // only append the context if we aren't looking for inline call sites
2816 // by file and line and if the file spec matches that of the compile unit
2817 sc_list.Append(sc);
2818 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002819
Greg Clayton526a4ae2012-05-16 22:09:01 +00002820 if (!check_inlines)
2821 break;
2822 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002823 }
2824 }
2825 }
2826 }
2827 return sc_list.GetSize() - prev_size;
2828}
2829
2830void
2831SymbolFileDWARF::Index ()
2832{
2833 if (m_indexed)
2834 return;
2835 m_indexed = true;
2836 Timer scoped_timer (__PRETTY_FUNCTION__,
2837 "SymbolFileDWARF::Index (%s)",
2838 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2839
2840 DWARFDebugInfo* debug_info = DebugInfo();
2841 if (debug_info)
2842 {
2843 uint32_t cu_idx = 0;
2844 const uint32_t num_compile_units = GetNumCompileUnits();
2845 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2846 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002847 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002848
Greg Clayton53eb1c22012-04-02 22:59:12 +00002849 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002850
Greg Clayton53eb1c22012-04-02 22:59:12 +00002851 dwarf_cu->Index (cu_idx,
2852 m_function_basename_index,
2853 m_function_fullname_index,
2854 m_function_method_index,
2855 m_function_selector_index,
2856 m_objc_class_selectors_index,
2857 m_global_index,
2858 m_type_index,
2859 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860
2861 // Keep memory down by clearing DIEs if this generate function
2862 // caused them to be parsed
2863 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002864 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002865 }
2866
Greg Claytond4a2b372011-09-12 23:21:58 +00002867 m_function_basename_index.Finalize();
2868 m_function_fullname_index.Finalize();
2869 m_function_method_index.Finalize();
2870 m_function_selector_index.Finalize();
2871 m_objc_class_selectors_index.Finalize();
2872 m_global_index.Finalize();
2873 m_type_index.Finalize();
2874 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002875
Greg Clayton24739922010-10-13 03:15:28 +00002876#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002877 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002878 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002879 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2880 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002881 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2882 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2883 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2884 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2885 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2886 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002887 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002888 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002889#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002890 }
2891}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002892
2893bool
2894SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2895{
2896 if (namespace_decl == NULL)
2897 {
2898 // Invalid namespace decl which means we aren't matching only things
2899 // in this symbol file, so return true to indicate it matches this
2900 // symbol file.
2901 return true;
2902 }
2903
2904 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2905
2906 if (namespace_ast == NULL)
2907 return true; // No AST in the "namespace_decl", return true since it
2908 // could then match any symbol file, including this one
2909
2910 if (namespace_ast == GetClangASTContext().getASTContext())
2911 return true; // The ASTs match, return true
2912
2913 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002914 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2915
2916 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002917 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002918
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002919 return false;
2920}
2921
Greg Clayton2506a7a2011-10-12 23:34:26 +00002922bool
2923SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2924 DWARFCompileUnit* cu,
2925 const DWARFDebugInfoEntry* die)
2926{
2927 // No namespace specified, so the answesr i
2928 if (namespace_decl == NULL)
2929 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002930
2931 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002932
Greg Clayton437a1352012-04-09 22:43:43 +00002933 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2934 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002935 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002936 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002937 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002938
Greg Clayton2506a7a2011-10-12 23:34:26 +00002939 if (clang_namespace_decl)
2940 {
2941 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002942 {
2943 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002944 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002945 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002946 }
2947
Greg Clayton437a1352012-04-09 22:43:43 +00002948 if (clang_namespace_decl == die_clang_decl_ctx)
2949 return true;
2950 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002951 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002952 }
2953 else
2954 {
2955 // We have a namespace_decl that was not NULL but it contained
2956 // a NULL "clang::NamespaceDecl", so this means the global namespace
2957 // So as long the the contained decl context DIE isn't a namespace
2958 // we should be ok.
2959 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2960 return true;
2961 }
2962 }
Sean Callananebe60672011-10-13 21:50:33 +00002963
2964 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002965 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002966
Greg Clayton2506a7a2011-10-12 23:34:26 +00002967 return false;
2968}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002969uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002970SymbolFileDWARF::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 +00002971{
Greg Clayton21f2a492011-10-06 00:09:08 +00002972 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2973
2974 if (log)
2975 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002976 GetObjectFile()->GetModule()->LogMessage (log.get(),
2977 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2978 name.GetCString(),
2979 namespace_decl,
2980 append,
2981 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002982 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002983
2984 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2985 return 0;
2986
Greg Claytonc685f8e2010-09-15 04:15:46 +00002987 DWARFDebugInfo* info = DebugInfo();
2988 if (info == NULL)
2989 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002990
2991 // If we aren't appending the results to this list, then clear the list
2992 if (!append)
2993 variables.Clear();
2994
2995 // Remember how many variables are in the list before we search in case
2996 // we are appending the results to a variable list.
2997 const uint32_t original_size = variables.GetSize();
2998
Greg Claytond4a2b372011-09-12 23:21:58 +00002999 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003000
Greg Clayton97fbc342011-10-20 22:30:33 +00003001 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003002 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003003 if (m_apple_names_ap.get())
3004 {
3005 const char *name_cstr = name.GetCString();
3006 const char *base_name_start;
3007 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003008
Greg Clayton97fbc342011-10-20 22:30:33 +00003009 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3010 base_name_start = name_cstr;
3011
3012 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3013 }
Greg Clayton7f995132011-10-04 22:41:51 +00003014 }
3015 else
3016 {
3017 // Index the DWARF if we haven't already
3018 if (!m_indexed)
3019 Index ();
3020
3021 m_global_index.Find (name, die_offsets);
3022 }
3023
Greg Clayton437a1352012-04-09 22:43:43 +00003024 const size_t num_die_matches = die_offsets.size();
3025 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003026 {
Greg Clayton7f995132011-10-04 22:41:51 +00003027 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003028 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003029 assert (sc.module_sp);
3030
Greg Claytond4a2b372011-09-12 23:21:58 +00003031 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00003032 DWARFCompileUnit* dwarf_cu = NULL;
3033 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00003034 bool done = false;
3035 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00003036 {
3037 const dw_offset_t die_offset = die_offsets[i];
3038 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039
Greg Clayton95d87902011-11-11 03:16:25 +00003040 if (die)
3041 {
Greg Clayton437a1352012-04-09 22:43:43 +00003042 switch (die->Tag())
3043 {
3044 default:
3045 case DW_TAG_subprogram:
3046 case DW_TAG_inlined_subroutine:
3047 case DW_TAG_try_block:
3048 case DW_TAG_catch_block:
3049 break;
3050
3051 case DW_TAG_variable:
3052 {
3053 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00003054
3055 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3056 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003057
Greg Clayton437a1352012-04-09 22:43:43 +00003058 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003059
Greg Clayton437a1352012-04-09 22:43:43 +00003060 if (variables.GetSize() - original_size >= max_matches)
3061 done = true;
3062 }
3063 break;
3064 }
Greg Clayton95d87902011-11-11 03:16:25 +00003065 }
3066 else
3067 {
3068 if (m_using_apple_tables)
3069 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003070 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3071 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003072 }
3073 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003074 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003075 }
3076
3077 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003078 const uint32_t num_matches = variables.GetSize() - original_size;
3079 if (log && num_matches > 0)
3080 {
3081 GetObjectFile()->GetModule()->LogMessage (log.get(),
3082 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3083 name.GetCString(),
3084 namespace_decl,
3085 append,
3086 max_matches,
3087 num_matches);
3088 }
3089 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003090}
3091
3092uint32_t
3093SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3094{
Greg Clayton21f2a492011-10-06 00:09:08 +00003095 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3096
3097 if (log)
3098 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003099 GetObjectFile()->GetModule()->LogMessage (log.get(),
3100 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3101 regex.GetText(),
3102 append,
3103 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003104 }
3105
Greg Claytonc685f8e2010-09-15 04:15:46 +00003106 DWARFDebugInfo* info = DebugInfo();
3107 if (info == NULL)
3108 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109
3110 // If we aren't appending the results to this list, then clear the list
3111 if (!append)
3112 variables.Clear();
3113
3114 // Remember how many variables are in the list before we search in case
3115 // we are appending the results to a variable list.
3116 const uint32_t original_size = variables.GetSize();
3117
Greg Clayton7f995132011-10-04 22:41:51 +00003118 DIEArray die_offsets;
3119
Greg Clayton97fbc342011-10-20 22:30:33 +00003120 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003121 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003122 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003123 {
3124 DWARFMappedHash::DIEInfoArray hash_data_array;
3125 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3126 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3127 }
Greg Clayton7f995132011-10-04 22:41:51 +00003128 }
3129 else
3130 {
3131 // Index the DWARF if we haven't already
3132 if (!m_indexed)
3133 Index ();
3134
3135 m_global_index.Find (regex, die_offsets);
3136 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003137
Greg Claytonc685f8e2010-09-15 04:15:46 +00003138 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003139 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003140 assert (sc.module_sp);
3141
Greg Claytond4a2b372011-09-12 23:21:58 +00003142 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003143 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003144 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003145 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003146 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003147 DWARFDebugInfo* debug_info = DebugInfo();
3148 for (size_t i=0; i<num_matches; ++i)
3149 {
3150 const dw_offset_t die_offset = die_offsets[i];
3151 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003152
3153 if (die)
3154 {
3155 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003156
Greg Clayton95d87902011-11-11 03:16:25 +00003157 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003158
Greg Clayton95d87902011-11-11 03:16:25 +00003159 if (variables.GetSize() - original_size >= max_matches)
3160 break;
3161 }
3162 else
3163 {
3164 if (m_using_apple_tables)
3165 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003166 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3167 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003168 }
3169 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003170 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003171 }
3172
3173 // Return the number of variable that were appended to the list
3174 return variables.GetSize() - original_size;
3175}
3176
Greg Claytonaa044962011-10-13 00:59:38 +00003177
Jim Ingham4cda6e02011-10-07 22:23:45 +00003178bool
3179SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3180 DWARFCompileUnit *&dwarf_cu,
3181 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003182{
Greg Claytonaa044962011-10-13 00:59:38 +00003183 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3184 return ResolveFunction (dwarf_cu, die, sc_list);
3185}
3186
3187
3188bool
3189SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3190 const DWARFDebugInfoEntry *die,
3191 SymbolContextList& sc_list)
3192{
Greg Clayton9e315582011-09-02 04:03:59 +00003193 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003194
3195 if (die == NULL)
3196 return false;
3197
Jim Ingham4cda6e02011-10-07 22:23:45 +00003198 // If we were passed a die that is not a function, just return false...
3199 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3200 return false;
3201
3202 const DWARFDebugInfoEntry* inlined_die = NULL;
3203 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003204 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003205 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003206
Jim Ingham4cda6e02011-10-07 22:23:45 +00003207 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003208 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003209 if (die->Tag() == DW_TAG_subprogram)
3210 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003211 }
3212 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003213 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003214 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003215 {
3216 Address addr;
3217 // Parse all blocks if needed
3218 if (inlined_die)
3219 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003220 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003221 assert (sc.block != NULL);
3222 if (sc.block->GetStartAddress (addr) == false)
3223 addr.Clear();
3224 }
3225 else
3226 {
3227 sc.block = NULL;
3228 addr = sc.function->GetAddressRange().GetBaseAddress();
3229 }
3230
3231 if (addr.IsValid())
3232 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003233 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003234 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003235 }
3236 }
3237
Greg Claytonaa044962011-10-13 00:59:38 +00003238 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003239}
3240
Greg Clayton7f995132011-10-04 22:41:51 +00003241void
3242SymbolFileDWARF::FindFunctions (const ConstString &name,
3243 const NameToDIE &name_to_die,
3244 SymbolContextList& sc_list)
3245{
Greg Claytond4a2b372011-09-12 23:21:58 +00003246 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003247 if (name_to_die.Find (name, die_offsets))
3248 {
3249 ParseFunctions (die_offsets, sc_list);
3250 }
3251}
3252
3253
3254void
3255SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3256 const NameToDIE &name_to_die,
3257 SymbolContextList& sc_list)
3258{
3259 DIEArray die_offsets;
3260 if (name_to_die.Find (regex, die_offsets))
3261 {
3262 ParseFunctions (die_offsets, sc_list);
3263 }
3264}
3265
3266
3267void
3268SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3269 const DWARFMappedHash::MemoryTable &memory_table,
3270 SymbolContextList& sc_list)
3271{
3272 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003273 DWARFMappedHash::DIEInfoArray hash_data_array;
3274 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003275 {
Greg Claytond1767f02011-12-08 02:13:16 +00003276 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003277 ParseFunctions (die_offsets, sc_list);
3278 }
3279}
3280
3281void
3282SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3283 SymbolContextList& sc_list)
3284{
3285 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003286 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003287 {
Greg Clayton7f995132011-10-04 22:41:51 +00003288 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003289
3290 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003291 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003292 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003293 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003294 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003295 }
3296 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003297}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003298
Jim Ingham4cda6e02011-10-07 22:23:45 +00003299bool
3300SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3301 const DWARFCompileUnit *dwarf_cu,
3302 uint32_t name_type_mask,
3303 const char *partial_name,
3304 const char *base_name_start,
3305 const char *base_name_end)
3306{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003307 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3308 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003309 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003310 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3311 if (!containing_decl_ctx)
3312 return false;
3313
3314 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3315
Greg Claytonfbea0f62012-11-15 18:05:43 +00003316 if (name_type_mask == eFunctionNameTypeMethod)
3317 {
3318 if (is_cxx_method == false)
3319 return false;
3320 }
3321
3322 if (name_type_mask == eFunctionNameTypeBase)
3323 {
3324 if (is_cxx_method == true)
3325 return false;
3326 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003327 }
3328
3329 // Now we need to check whether the name we got back for this type matches the extra specifications
3330 // that were in the name we're looking up:
3331 if (base_name_start != partial_name || *base_name_end != '\0')
3332 {
3333 // First see if the stuff to the left matches the full name. To do that let's see if
3334 // we can pull out the mips linkage name attribute:
3335
3336 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003337 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003338 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003339 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3340 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003341 if (idx == UINT32_MAX)
3342 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003343 if (idx != UINT32_MAX)
3344 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003345 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3346 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003347 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3348 if (mangled_name)
3349 best_name.SetValue (ConstString(mangled_name), true);
3350 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003351 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003352
3353 if (!best_name)
3354 {
3355 idx = attributes.FindAttributeIndex(DW_AT_name);
3356 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3357 {
3358 const char *name = form_value.AsCString(&get_debug_str_data());
3359 best_name.SetValue (ConstString(name), false);
3360 }
3361 }
3362
3363 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003364 {
3365 const char *demangled = best_name.GetDemangledName().GetCString();
3366 if (demangled)
3367 {
3368 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003369 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3370 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003371 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003372 else
3373 {
3374 // Sort out the case where our name is something like "Process::Destroy" and the match is
3375 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3376 // namespace boundaries...
3377
3378 if (partial_name[0] == ':' && partial_name[1] == ':')
3379 {
3380 // The partial name was already on a namespace boundary so all matches are good.
3381 return true;
3382 }
3383 else if (partial_in_demangled == demangled)
3384 {
3385 // They both start the same, so this is an good match.
3386 return true;
3387 }
3388 else
3389 {
3390 if (partial_in_demangled - demangled == 1)
3391 {
3392 // Only one character difference, can't be a namespace boundary...
3393 return false;
3394 }
3395 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3396 {
3397 // We are on a namespace boundary, so this is also good.
3398 return true;
3399 }
3400 else
3401 return false;
3402 }
3403 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003404 }
3405 }
3406 }
3407
3408 return true;
3409}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003410
Greg Clayton0c5cd902010-06-28 21:30:43 +00003411uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003412SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003413 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003414 uint32_t name_type_mask,
3415 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003416 bool append,
3417 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003418{
3419 Timer scoped_timer (__PRETTY_FUNCTION__,
3420 "SymbolFileDWARF::FindFunctions (name = '%s')",
3421 name.AsCString());
3422
Greg Clayton21f2a492011-10-06 00:09:08 +00003423 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3424
3425 if (log)
3426 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003427 GetObjectFile()->GetModule()->LogMessage (log.get(),
3428 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3429 name.GetCString(),
3430 name_type_mask,
3431 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003432 }
3433
Greg Clayton0c5cd902010-06-28 21:30:43 +00003434 // If we aren't appending the results to this list, then clear the list
3435 if (!append)
3436 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003437
3438 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3439 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003440
3441 // If name is empty then we won't find anything.
3442 if (name.IsEmpty())
3443 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003444
3445 // Remember how many sc_list are in the list before we search in case
3446 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003447
Greg Clayton9e315582011-09-02 04:03:59 +00003448 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003449
Jim Ingham4cda6e02011-10-07 22:23:45 +00003450 const char *name_cstr = name.GetCString();
3451 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3452 const char *base_name_start = name_cstr;
3453 const char *base_name_end = name_cstr + strlen(name_cstr);
3454
3455 if (name_type_mask & eFunctionNameTypeAuto)
3456 {
3457 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3458 effective_name_type_mask = eFunctionNameTypeFull;
3459 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3460 effective_name_type_mask = eFunctionNameTypeFull;
3461 else
3462 {
3463 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3464 effective_name_type_mask |= eFunctionNameTypeSelector;
3465
3466 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3467 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3468 }
3469 }
3470 else
3471 {
3472 effective_name_type_mask = name_type_mask;
3473 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3474 {
3475 // If they've asked for a CPP method or function name and it can't be that, we don't
3476 // even need to search for CPP methods or names.
3477 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3478 {
3479 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3480 if (effective_name_type_mask == eFunctionNameTypeNone)
3481 return 0;
3482 }
3483 }
3484
3485 if (effective_name_type_mask & eFunctionNameTypeSelector)
3486 {
3487 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3488 {
3489 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3490 if (effective_name_type_mask == eFunctionNameTypeNone)
3491 return 0;
3492 }
3493 }
3494 }
3495
3496 DWARFDebugInfo* info = DebugInfo();
3497 if (info == NULL)
3498 return 0;
3499
Greg Claytonaa044962011-10-13 00:59:38 +00003500 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003501 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003502 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003503 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003504 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003505
3506 DIEArray die_offsets;
3507
3508 uint32_t num_matches = 0;
3509
3510 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003511 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003512 // If they asked for the full name, match what they typed. At some point we may
3513 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3514 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003515 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003516 for (uint32_t i = 0; i < num_matches; i++)
3517 {
Greg Clayton95d87902011-11-11 03:16:25 +00003518 const dw_offset_t die_offset = die_offsets[i];
3519 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003520 if (die)
3521 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003522 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3523 continue;
3524
Sean Callanan9df05fb2012-02-10 22:52:19 +00003525 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3526 continue;
3527
Greg Claytonaa044962011-10-13 00:59:38 +00003528 ResolveFunction (dwarf_cu, die, sc_list);
3529 }
Greg Clayton95d87902011-11-11 03:16:25 +00003530 else
3531 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003532 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3533 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003534 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003535 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003536 }
3537 else
3538 {
3539 if (effective_name_type_mask & eFunctionNameTypeSelector)
3540 {
3541 if (namespace_decl && *namespace_decl)
3542 return 0; // no selectors in namespaces
3543
3544 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3545 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3546 // and if it is an ObjC method name, we're good.
3547
3548 for (uint32_t i = 0; i < num_matches; i++)
3549 {
Greg Clayton95d87902011-11-11 03:16:25 +00003550 const dw_offset_t die_offset = die_offsets[i];
3551 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003552 if (die)
3553 {
3554 const char *die_name = die->GetName(this, dwarf_cu);
3555 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003556 {
3557 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3558 continue;
3559
Greg Clayton97fbc342011-10-20 22:30:33 +00003560 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003561 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003562 }
Greg Clayton95d87902011-11-11 03:16:25 +00003563 else
3564 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003565 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3566 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003567 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003568 }
3569 die_offsets.clear();
3570 }
3571
3572 if (effective_name_type_mask & eFunctionNameTypeMethod
3573 || effective_name_type_mask & eFunctionNameTypeBase)
3574 {
3575 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3576 (namespace_decl && *namespace_decl))
3577 return 0; // no methods in namespaces
3578
3579 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3580 // extract the base name, look that up, and if there is any other information in the name we were
3581 // passed in we have to post-filter based on that.
3582
3583 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3584 std::string base_name(base_name_start, base_name_end - base_name_start);
3585 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3586
3587 for (uint32_t i = 0; i < num_matches; i++)
3588 {
Greg Clayton95d87902011-11-11 03:16:25 +00003589 const dw_offset_t die_offset = die_offsets[i];
3590 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003591 if (die)
3592 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003593 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3594 continue;
3595
Greg Clayton97fbc342011-10-20 22:30:33 +00003596 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3597 continue;
3598
Greg Claytonfbea0f62012-11-15 18:05:43 +00003599 if (!FunctionDieMatchesPartialName(die,
Greg Clayton97fbc342011-10-20 22:30:33 +00003600 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003601 effective_name_type_mask,
Greg Clayton97fbc342011-10-20 22:30:33 +00003602 name_cstr,
3603 base_name_start,
3604 base_name_end))
3605 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003606
Greg Clayton97fbc342011-10-20 22:30:33 +00003607 // If we get to here, the die is good, and we should add it:
3608 ResolveFunction (dwarf_cu, die, sc_list);
3609 }
Greg Clayton95d87902011-11-11 03:16:25 +00003610 else
3611 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003612 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3613 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003614 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003615 }
3616 die_offsets.clear();
3617 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003618 }
3619 }
Greg Clayton7f995132011-10-04 22:41:51 +00003620 }
3621 else
3622 {
3623
3624 // Index the DWARF if we haven't already
3625 if (!m_indexed)
3626 Index ();
3627
Greg Clayton7f995132011-10-04 22:41:51 +00003628 if (name_type_mask & eFunctionNameTypeFull)
3629 FindFunctions (name, m_function_fullname_index, sc_list);
3630
Jim Ingham4cda6e02011-10-07 22:23:45 +00003631 std::string base_name(base_name_start, base_name_end - base_name_start);
3632 ConstString base_name_const(base_name.c_str());
3633 DIEArray die_offsets;
3634 DWARFCompileUnit *dwarf_cu = NULL;
3635
3636 if (effective_name_type_mask & eFunctionNameTypeBase)
3637 {
3638 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003639 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003640 {
Greg Claytonaa044962011-10-13 00:59:38 +00003641 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3642 if (die)
3643 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003644 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3645 continue;
3646
Sean Callanan213fdb82011-10-13 01:49:10 +00003647 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3648 continue;
3649
Greg Claytonaa044962011-10-13 00:59:38 +00003650 if (!FunctionDieMatchesPartialName(die,
3651 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003652 eFunctionNameTypeBase,
Greg Claytonaa044962011-10-13 00:59:38 +00003653 name_cstr,
3654 base_name_start,
3655 base_name_end))
3656 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003657
Greg Claytonaa044962011-10-13 00:59:38 +00003658 // If we get to here, the die is good, and we should add it:
3659 ResolveFunction (dwarf_cu, die, sc_list);
3660 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003661 }
3662 die_offsets.clear();
3663 }
3664
Jim Inghamea8005a2011-10-11 01:18:11 +00003665 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003666 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003667 if (namespace_decl && *namespace_decl)
3668 return 0; // no methods in namespaces
3669
Jim Ingham4cda6e02011-10-07 22:23:45 +00003670 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3671 {
Greg Claytonaa044962011-10-13 00:59:38 +00003672 for (uint32_t i = 0; i < num_base; i++)
3673 {
3674 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3675 if (die)
3676 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003677 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3678 continue;
3679
3680 if (!FunctionDieMatchesPartialName(die,
Greg Claytonaa044962011-10-13 00:59:38 +00003681 dwarf_cu,
Greg Claytonfbea0f62012-11-15 18:05:43 +00003682 eFunctionNameTypeMethod,
Greg Claytonaa044962011-10-13 00:59:38 +00003683 name_cstr,
3684 base_name_start,
3685 base_name_end))
3686 continue;
3687
3688 // If we get to here, the die is good, and we should add it:
3689 ResolveFunction (dwarf_cu, die, sc_list);
3690 }
3691 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003692 }
3693 die_offsets.clear();
3694 }
Greg Clayton7f995132011-10-04 22:41:51 +00003695
Sean Callanan213fdb82011-10-13 01:49:10 +00003696 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003697 {
Greg Clayton7f995132011-10-04 22:41:51 +00003698 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003699 }
3700
Greg Clayton4d01ace2011-09-29 16:58:15 +00003701 }
3702
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003703 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003704 const uint32_t num_matches = sc_list.GetSize() - original_size;
3705
3706 if (log && num_matches > 0)
3707 {
3708 GetObjectFile()->GetModule()->LogMessage (log.get(),
3709 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3710 name.GetCString(),
3711 name_type_mask,
3712 append,
3713 num_matches);
3714 }
3715 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003716}
3717
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003718uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003719SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003720{
3721 Timer scoped_timer (__PRETTY_FUNCTION__,
3722 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3723 regex.GetText());
3724
Greg Clayton21f2a492011-10-06 00:09:08 +00003725 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3726
3727 if (log)
3728 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003729 GetObjectFile()->GetModule()->LogMessage (log.get(),
3730 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3731 regex.GetText(),
3732 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003733 }
3734
3735
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003736 // If we aren't appending the results to this list, then clear the list
3737 if (!append)
3738 sc_list.Clear();
3739
3740 // Remember how many sc_list are in the list before we search in case
3741 // we are appending the results to a variable list.
3742 uint32_t original_size = sc_list.GetSize();
3743
Greg Clayton97fbc342011-10-20 22:30:33 +00003744 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003745 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003746 if (m_apple_names_ap.get())
3747 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003748 }
3749 else
3750 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003751 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003752 if (!m_indexed)
3753 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003754
Greg Clayton7f995132011-10-04 22:41:51 +00003755 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003756
Greg Clayton7f995132011-10-04 22:41:51 +00003757 FindFunctions (regex, m_function_fullname_index, sc_list);
3758 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759
3760 // Return the number of variable that were appended to the list
3761 return sc_list.GetSize() - original_size;
3762}
Jim Ingham318c9f22011-08-26 19:44:13 +00003763
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003764uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003765SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3766 const ConstString &name,
3767 const lldb_private::ClangNamespaceDecl *namespace_decl,
3768 bool append,
3769 uint32_t max_matches,
3770 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003771{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003772 DWARFDebugInfo* info = DebugInfo();
3773 if (info == NULL)
3774 return 0;
3775
Greg Clayton21f2a492011-10-06 00:09:08 +00003776 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3777
3778 if (log)
3779 {
Greg Clayton437a1352012-04-09 22:43:43 +00003780 if (namespace_decl)
3781 {
3782 GetObjectFile()->GetModule()->LogMessage (log.get(),
3783 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3784 name.GetCString(),
3785 namespace_decl->GetNamespaceDecl(),
3786 namespace_decl->GetQualifiedName().c_str(),
3787 append,
3788 max_matches);
3789 }
3790 else
3791 {
3792 GetObjectFile()->GetModule()->LogMessage (log.get(),
3793 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3794 name.GetCString(),
3795 append,
3796 max_matches);
3797 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003798 }
3799
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003800 // If we aren't appending the results to this list, then clear the list
3801 if (!append)
3802 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003803
3804 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3805 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003806
Greg Claytond4a2b372011-09-12 23:21:58 +00003807 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003808
Greg Clayton97fbc342011-10-20 22:30:33 +00003809 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003810 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003811 if (m_apple_types_ap.get())
3812 {
3813 const char *name_cstr = name.GetCString();
3814 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3815 }
Greg Clayton7f995132011-10-04 22:41:51 +00003816 }
3817 else
3818 {
3819 if (!m_indexed)
3820 Index ();
3821
3822 m_type_index.Find (name, die_offsets);
3823 }
3824
Greg Clayton437a1352012-04-09 22:43:43 +00003825 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003826
Greg Clayton437a1352012-04-09 22:43:43 +00003827 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003828 {
Greg Clayton7f995132011-10-04 22:41:51 +00003829 const uint32_t initial_types_size = types.GetSize();
3830 DWARFCompileUnit* dwarf_cu = NULL;
3831 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003832 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003833 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003834 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003835 const dw_offset_t die_offset = die_offsets[i];
3836 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3837
Greg Clayton95d87902011-11-11 03:16:25 +00003838 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003839 {
Greg Clayton95d87902011-11-11 03:16:25 +00003840 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3841 continue;
3842
3843 Type *matching_type = ResolveType (dwarf_cu, die);
3844 if (matching_type)
3845 {
3846 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003847 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003848 if (types.GetSize() >= max_matches)
3849 break;
3850 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003851 }
Greg Clayton95d87902011-11-11 03:16:25 +00003852 else
3853 {
3854 if (m_using_apple_tables)
3855 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003856 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3857 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003858 }
3859 }
3860
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003861 }
Greg Clayton437a1352012-04-09 22:43:43 +00003862 const uint32_t num_matches = types.GetSize() - initial_types_size;
3863 if (log && num_matches)
3864 {
3865 if (namespace_decl)
3866 {
3867 GetObjectFile()->GetModule()->LogMessage (log.get(),
3868 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3869 name.GetCString(),
3870 namespace_decl->GetNamespaceDecl(),
3871 namespace_decl->GetQualifiedName().c_str(),
3872 append,
3873 max_matches,
3874 num_matches);
3875 }
3876 else
3877 {
3878 GetObjectFile()->GetModule()->LogMessage (log.get(),
3879 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3880 name.GetCString(),
3881 append,
3882 max_matches,
3883 num_matches);
3884 }
3885 }
3886 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003887 }
Greg Clayton7f995132011-10-04 22:41:51 +00003888 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003889}
3890
3891
Greg Clayton526e5af2010-11-13 03:52:47 +00003892ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003893SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003894 const ConstString &name,
3895 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003896{
Greg Clayton21f2a492011-10-06 00:09:08 +00003897 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3898
3899 if (log)
3900 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003901 GetObjectFile()->GetModule()->LogMessage (log.get(),
3902 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3903 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003904 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003905
3906 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3907 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003908
Greg Clayton526e5af2010-11-13 03:52:47 +00003909 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003910 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003911 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003912 {
Greg Clayton7f995132011-10-04 22:41:51 +00003913 DIEArray die_offsets;
3914
Greg Clayton526e5af2010-11-13 03:52:47 +00003915 // Index if we already haven't to make sure the compile units
3916 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003917 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003918 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003919 if (m_apple_namespaces_ap.get())
3920 {
3921 const char *name_cstr = name.GetCString();
3922 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3923 }
Greg Clayton7f995132011-10-04 22:41:51 +00003924 }
3925 else
3926 {
3927 if (!m_indexed)
3928 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003929
Greg Clayton7f995132011-10-04 22:41:51 +00003930 m_namespace_index.Find (name, die_offsets);
3931 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003932
3933 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003934 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003935 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003936 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003937 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003938 DWARFDebugInfo* debug_info = DebugInfo();
3939 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003940 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003941 const dw_offset_t die_offset = die_offsets[i];
3942 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003943
Greg Clayton95d87902011-11-11 03:16:25 +00003944 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003945 {
Greg Clayton95d87902011-11-11 03:16:25 +00003946 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3947 continue;
3948
3949 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3950 if (clang_namespace_decl)
3951 {
3952 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3953 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003954 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003955 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003956 }
Greg Clayton95d87902011-11-11 03:16:25 +00003957 else
3958 {
3959 if (m_using_apple_tables)
3960 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003961 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3962 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003963 }
3964 }
3965
Greg Clayton526e5af2010-11-13 03:52:47 +00003966 }
3967 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003968 }
Greg Clayton437a1352012-04-09 22:43:43 +00003969 if (log && namespace_decl.GetNamespaceDecl())
3970 {
3971 GetObjectFile()->GetModule()->LogMessage (log.get(),
3972 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3973 name.GetCString(),
3974 namespace_decl.GetNamespaceDecl(),
3975 namespace_decl.GetQualifiedName().c_str());
3976 }
3977
Greg Clayton526e5af2010-11-13 03:52:47 +00003978 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003979}
3980
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003981uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003982SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003983{
3984 // Remember how many sc_list are in the list before we search in case
3985 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003986 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003987
3988 const uint32_t num_die_offsets = die_offsets.size();
3989 // Parse all of the types we found from the pubtypes matches
3990 uint32_t i;
3991 uint32_t num_matches = 0;
3992 for (i = 0; i < num_die_offsets; ++i)
3993 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003994 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3995 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003996 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003997 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003998 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003999 ++num_matches;
4000 if (num_matches >= max_matches)
4001 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004002 }
4003 }
4004
4005 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004006 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004007}
4008
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004009
4010size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00004011SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4012 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00004013 DWARFCompileUnit* dwarf_cu,
4014 const DWARFDebugInfoEntry *parent_die,
4015 bool skip_artificial,
4016 bool &is_static,
4017 TypeList* type_list,
4018 std::vector<clang_type_t>& function_param_types,
4019 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004020 unsigned &type_quals,
4021 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004022{
4023 if (parent_die == NULL)
4024 return 0;
4025
Greg Claytond88d7592010-09-15 08:33:30 +00004026 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4027
Greg Clayton7fedea22010-11-16 02:10:54 +00004028 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004029 const DWARFDebugInfoEntry *die;
4030 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4031 {
4032 dw_tag_t tag = die->Tag();
4033 switch (tag)
4034 {
4035 case DW_TAG_formal_parameter:
4036 {
4037 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004038 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004039 if (num_attributes > 0)
4040 {
4041 const char *name = NULL;
4042 Declaration decl;
4043 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004044 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004045 // one of None, Auto, Register, Extern, Static, PrivateExtern
4046
Sean Callanane2ef6e32010-09-23 03:01:22 +00004047 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004048 uint32_t i;
4049 for (i=0; i<num_attributes; ++i)
4050 {
4051 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4052 DWARFFormValue form_value;
4053 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4054 {
4055 switch (attr)
4056 {
4057 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4058 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4059 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4060 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4061 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004062 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004063 case DW_AT_location:
4064 // if (form_value.BlockData())
4065 // {
4066 // const DataExtractor& debug_info_data = debug_info();
4067 // uint32_t block_length = form_value.Unsigned();
4068 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
4069 // }
4070 // else
4071 // {
4072 // }
4073 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004074 case DW_AT_const_value:
4075 case DW_AT_default_value:
4076 case DW_AT_description:
4077 case DW_AT_endianity:
4078 case DW_AT_is_optional:
4079 case DW_AT_segment:
4080 case DW_AT_variable_parameter:
4081 default:
4082 case DW_AT_abstract_origin:
4083 case DW_AT_sibling:
4084 break;
4085 }
4086 }
4087 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00004088
Greg Clayton0fffff52010-09-24 05:15:53 +00004089 bool skip = false;
4090 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004091 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004092 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00004093 {
4094 // In order to determine if a C++ member function is
4095 // "const" we have to look at the const-ness of "this"...
4096 // Ugly, but that
4097 if (arg_idx == 0)
4098 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004099 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00004100 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004101 // Often times compilers omit the "this" name for the
4102 // specification DIEs, so we can't rely upon the name
4103 // being in the formal parameter DIE...
4104 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004105 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004106 Type *this_type = ResolveTypeUID (param_type_die_offset);
4107 if (this_type)
4108 {
4109 uint32_t encoding_mask = this_type->GetEncodingMask();
4110 if (encoding_mask & Type::eEncodingIsPointerUID)
4111 {
4112 is_static = false;
4113
4114 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4115 type_quals |= clang::Qualifiers::Const;
4116 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4117 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004118 }
4119 }
4120 }
4121 }
4122 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004123 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004124 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004125 else
4126 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004127
Greg Clayton0fffff52010-09-24 05:15:53 +00004128 // HACK: Objective C formal parameters "self" and "_cmd"
4129 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004130 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4131 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004132 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004133 switch (comp_unit->GetLanguage())
4134 {
4135 case eLanguageTypeObjC:
4136 case eLanguageTypeObjC_plus_plus:
4137 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4138 skip = true;
4139 break;
4140 default:
4141 break;
4142 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004143 }
4144 }
4145 }
4146
4147 if (!skip)
4148 {
4149 Type *type = ResolveTypeUID(param_type_die_offset);
4150 if (type)
4151 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004152 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004153
Greg Clayton42ce2f32011-12-12 21:50:19 +00004154 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4155 type->GetClangForwardType(),
4156 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004157 assert(param_var_decl);
4158 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004159
Jim Ingham379397632012-10-27 02:54:13 +00004160 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004161 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004162 }
4163 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004164 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004165 }
4166 break;
4167
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004168 case DW_TAG_template_type_parameter:
4169 case DW_TAG_template_value_parameter:
4170 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4171 break;
4172
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173 default:
4174 break;
4175 }
4176 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004177 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004178}
4179
4180size_t
4181SymbolFileDWARF::ParseChildEnumerators
4182(
4183 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00004184 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004185 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004186 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004187 const DWARFDebugInfoEntry *parent_die
4188)
4189{
4190 if (parent_die == NULL)
4191 return 0;
4192
4193 size_t enumerators_added = 0;
4194 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004195 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4196
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004197 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4198 {
4199 const dw_tag_t tag = die->Tag();
4200 if (tag == DW_TAG_enumerator)
4201 {
4202 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004203 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204 if (num_child_attributes > 0)
4205 {
4206 const char *name = NULL;
4207 bool got_value = false;
4208 int64_t enum_value = 0;
4209 Declaration decl;
4210
4211 uint32_t i;
4212 for (i=0; i<num_child_attributes; ++i)
4213 {
4214 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4215 DWARFFormValue form_value;
4216 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4217 {
4218 switch (attr)
4219 {
4220 case DW_AT_const_value:
4221 got_value = true;
4222 enum_value = form_value.Unsigned();
4223 break;
4224
4225 case DW_AT_name:
4226 name = form_value.AsCString(&get_debug_str_data());
4227 break;
4228
4229 case DW_AT_description:
4230 default:
4231 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4232 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4233 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4234 case DW_AT_sibling:
4235 break;
4236 }
4237 }
4238 }
4239
4240 if (name && name[0] && got_value)
4241 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004242 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4243 enumerator_clang_type,
4244 decl,
4245 name,
4246 enum_value,
4247 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004248 ++enumerators_added;
4249 }
4250 }
4251 }
4252 }
4253 return enumerators_added;
4254}
4255
4256void
4257SymbolFileDWARF::ParseChildArrayInfo
4258(
4259 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004260 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004261 const DWARFDebugInfoEntry *parent_die,
4262 int64_t& first_index,
4263 std::vector<uint64_t>& element_orders,
4264 uint32_t& byte_stride,
4265 uint32_t& bit_stride
4266)
4267{
4268 if (parent_die == NULL)
4269 return;
4270
4271 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004272 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004273 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4274 {
4275 const dw_tag_t tag = die->Tag();
4276 switch (tag)
4277 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004278 case DW_TAG_subrange_type:
4279 {
4280 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004281 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004282 if (num_child_attributes > 0)
4283 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004284 uint64_t num_elements = 0;
4285 uint64_t lower_bound = 0;
4286 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004287 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004288 uint32_t i;
4289 for (i=0; i<num_child_attributes; ++i)
4290 {
4291 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4292 DWARFFormValue form_value;
4293 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4294 {
4295 switch (attr)
4296 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004297 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004298 break;
4299
4300 case DW_AT_count:
4301 num_elements = form_value.Unsigned();
4302 break;
4303
4304 case DW_AT_bit_stride:
4305 bit_stride = form_value.Unsigned();
4306 break;
4307
4308 case DW_AT_byte_stride:
4309 byte_stride = form_value.Unsigned();
4310 break;
4311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004312 case DW_AT_lower_bound:
4313 lower_bound = form_value.Unsigned();
4314 break;
4315
4316 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004317 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004318 upper_bound = form_value.Unsigned();
4319 break;
4320
4321 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004322 case DW_AT_abstract_origin:
4323 case DW_AT_accessibility:
4324 case DW_AT_allocated:
4325 case DW_AT_associated:
4326 case DW_AT_data_location:
4327 case DW_AT_declaration:
4328 case DW_AT_description:
4329 case DW_AT_sibling:
4330 case DW_AT_threads_scaled:
4331 case DW_AT_type:
4332 case DW_AT_visibility:
4333 break;
4334 }
4335 }
4336 }
4337
Greg Claytone6a07792012-12-05 21:59:39 +00004338 if (num_elements == 0)
4339 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004340 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004341 num_elements = upper_bound - lower_bound + 1;
4342 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004343
Sean Callananec979ba2012-10-22 23:56:48 +00004344 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004345 }
4346 }
4347 break;
4348 }
4349 }
4350}
4351
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004352TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004353SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004354{
4355 TypeSP type_sp;
4356 if (die != NULL)
4357 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004358 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004359 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004360 if (type_ptr == NULL)
4361 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004362 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004363 assert (lldb_cu);
4364 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004365 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004366 }
4367 else if (type_ptr != DIE_IS_BEING_PARSED)
4368 {
4369 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004370 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004371 }
4372
4373 }
4374 return type_sp;
4375}
4376
4377clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004378SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004379{
4380 if (die_offset != DW_INVALID_OFFSET)
4381 {
4382 DWARFCompileUnitSP cu_sp;
4383 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004384 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004385 }
4386 return NULL;
4387}
4388
Sean Callanan72e49402011-08-05 23:43:37 +00004389clang::DeclContext *
4390SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4391{
4392 if (die_offset != DW_INVALID_OFFSET)
4393 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004394 DWARFDebugInfo* debug_info = DebugInfo();
4395 if (debug_info)
4396 {
4397 DWARFCompileUnitSP cu_sp;
4398 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4399 if (die)
4400 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4401 }
Sean Callanan72e49402011-08-05 23:43:37 +00004402 }
4403 return NULL;
4404}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405
Greg Clayton96d7d742010-11-10 23:42:09 +00004406clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004407SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004408{
Greg Clayton030a2042011-10-14 21:34:45 +00004409 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004410 {
Greg Clayton030a2042011-10-14 21:34:45 +00004411 // See if we already parsed this namespace DIE and associated it with a
4412 // uniqued namespace declaration
4413 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4414 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004415 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004416 else
4417 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004418 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4419 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004420 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4421 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4422 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004423 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004424 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004425 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004426 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004427 "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 +00004428 GetClangASTContext().getASTContext(),
4429 MakeUserID(die->GetOffset()),
4430 namespace_name,
4431 namespace_decl,
4432 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004433 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004434 else
4435 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004436 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00004437 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004438 GetClangASTContext().getASTContext(),
4439 MakeUserID(die->GetOffset()),
4440 namespace_decl,
4441 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004442 }
Greg Clayton030a2042011-10-14 21:34:45 +00004443 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004444
4445 if (namespace_decl)
4446 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4447 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004448 }
4449 }
4450 return NULL;
4451}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004452
4453clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004454SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004455{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004456 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4457 if (clang_decl_ctx)
4458 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004459 // If this DIE has a specification, or an abstract origin, then trace to those.
4460
Greg Claytoncab36a32011-12-08 05:16:30 +00004461 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004462 if (die_offset != DW_INVALID_OFFSET)
4463 return GetClangDeclContextForDIEOffset (sc, die_offset);
4464
Greg Claytoncab36a32011-12-08 05:16:30 +00004465 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004466 if (die_offset != DW_INVALID_OFFSET)
4467 return GetClangDeclContextForDIEOffset (sc, die_offset);
4468
Greg Clayton3bffb082011-12-10 02:15:28 +00004469 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4470 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004471 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 +00004472 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004473 bool assert_not_being_parsed = true;
4474 ResolveTypeUID (cu, die, assert_not_being_parsed);
4475
Greg Clayton5cf58b92011-10-05 22:22:08 +00004476 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4477
4478 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004479}
4480
4481clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004482SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004483{
Greg Claytonca512b32011-01-14 04:54:56 +00004484 if (m_clang_tu_decl == NULL)
4485 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004486
Greg Clayton2bc22f82011-09-30 03:20:47 +00004487 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004488
4489 if (decl_ctx_die_copy)
4490 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004491
4492 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004493 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004494
Greg Clayton2bc22f82011-09-30 03:20:47 +00004495 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4496 if (pos != m_die_to_decl_ctx.end())
4497 return pos->second;
4498
4499 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004500 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004501 case DW_TAG_compile_unit:
4502 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004503
Greg Clayton2bc22f82011-09-30 03:20:47 +00004504 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004505 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004506 break;
4507
4508 case DW_TAG_structure_type:
4509 case DW_TAG_union_type:
4510 case DW_TAG_class_type:
4511 {
4512 Type* type = ResolveType (cu, decl_ctx_die);
4513 if (type)
4514 {
4515 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4516 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004517 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004518 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4519 if (decl_ctx)
4520 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004521 }
4522 }
Greg Claytonca512b32011-01-14 04:54:56 +00004523 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004524 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004525
Greg Clayton2bc22f82011-09-30 03:20:47 +00004526 default:
4527 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004528 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004529 }
Greg Clayton7a345282010-11-09 23:46:37 +00004530 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004531}
4532
Greg Clayton2bc22f82011-09-30 03:20:47 +00004533
4534const DWARFDebugInfoEntry *
4535SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4536{
4537 if (cu && die)
4538 {
4539 const DWARFDebugInfoEntry * const decl_die = die;
4540
4541 while (die != NULL)
4542 {
4543 // If this is the original DIE that we are searching for a declaration
4544 // for, then don't look in the cache as we don't want our own decl
4545 // context to be our decl context...
4546 if (decl_die != die)
4547 {
4548 switch (die->Tag())
4549 {
4550 case DW_TAG_compile_unit:
4551 case DW_TAG_namespace:
4552 case DW_TAG_structure_type:
4553 case DW_TAG_union_type:
4554 case DW_TAG_class_type:
4555 return die;
4556
4557 default:
4558 break;
4559 }
4560 }
4561
4562 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4563 if (die_offset != DW_INVALID_OFFSET)
4564 {
4565 DWARFCompileUnit *spec_cu = cu;
4566 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4567 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4568 if (spec_die_decl_ctx_die)
4569 return spec_die_decl_ctx_die;
4570 }
4571
4572 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4573 if (die_offset != DW_INVALID_OFFSET)
4574 {
4575 DWARFCompileUnit *abs_cu = cu;
4576 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4577 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4578 if (abs_die_decl_ctx_die)
4579 return abs_die_decl_ctx_die;
4580 }
4581
4582 die = die->GetParent();
4583 }
4584 }
4585 return NULL;
4586}
4587
4588
Greg Clayton901c5ca2011-12-03 04:40:03 +00004589Symbol *
4590SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4591{
4592 Symbol *objc_class_symbol = NULL;
4593 if (m_obj_file)
4594 {
4595 Symtab *symtab = m_obj_file->GetSymtab();
4596 if (symtab)
4597 {
4598 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4599 eSymbolTypeObjCClass,
4600 Symtab::eDebugNo,
4601 Symtab::eVisibilityAny);
4602 }
4603 }
4604 return objc_class_symbol;
4605}
4606
Greg Claytonc7f03b62012-01-12 04:33:28 +00004607// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4608// then we can end up looking through all class types for a complete type and never find
4609// the full definition. We need to know if this attribute is supported, so we determine
4610// this here and cache th result. We also need to worry about the debug map DWARF file
4611// if we are doing darwin DWARF in .o file debugging.
4612bool
4613SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4614{
4615 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4616 {
4617 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4618 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4619 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4620 else
4621 {
4622 DWARFDebugInfo* debug_info = DebugInfo();
4623 const uint32_t num_compile_units = GetNumCompileUnits();
4624 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4625 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004626 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4627 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004628 {
4629 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4630 break;
4631 }
4632 }
4633 }
Greg Clayton1f746072012-08-29 21:13:06 +00004634 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004635 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4636 }
4637 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4638}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004639
4640// This function can be used when a DIE is found that is a forward declaration
4641// DIE and we want to try and find a type that has the complete definition.
4642TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004643SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4644 const ConstString &type_name,
4645 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004646{
4647
4648 TypeSP type_sp;
4649
Greg Claytonc7f03b62012-01-12 04:33:28 +00004650 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004651 return type_sp;
4652
4653 DIEArray die_offsets;
4654
4655 if (m_using_apple_tables)
4656 {
4657 if (m_apple_types_ap.get())
4658 {
4659 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004660 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004661 }
4662 }
4663 else
4664 {
4665 if (!m_indexed)
4666 Index ();
4667
4668 m_type_index.Find (type_name, die_offsets);
4669 }
4670
Greg Clayton901c5ca2011-12-03 04:40:03 +00004671 const size_t num_matches = die_offsets.size();
4672
Greg Clayton901c5ca2011-12-03 04:40:03 +00004673 DWARFCompileUnit* type_cu = NULL;
4674 const DWARFDebugInfoEntry* type_die = NULL;
4675 if (num_matches)
4676 {
4677 DWARFDebugInfo* debug_info = DebugInfo();
4678 for (size_t i=0; i<num_matches; ++i)
4679 {
4680 const dw_offset_t die_offset = die_offsets[i];
4681 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4682
4683 if (type_die)
4684 {
4685 bool try_resolving_type = false;
4686
4687 // Don't try and resolve the DIE we are looking for with the DIE itself!
4688 if (type_die != die)
4689 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004690 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004691 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004692 case DW_TAG_class_type:
4693 case DW_TAG_structure_type:
4694 try_resolving_type = true;
4695 break;
4696 default:
4697 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004698 }
4699 }
4700
4701 if (try_resolving_type)
4702 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004703 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004704 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004705
4706 if (try_resolving_type)
4707 {
4708 Type *resolved_type = ResolveType (type_cu, type_die, false);
4709 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4710 {
Daniel Malead01b2952012-11-29 21:49:15 +00004711 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 +00004712 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004713 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004714 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4715 MakeUserID(type_die->GetOffset()),
4716 MakeUserID(type_cu->GetOffset()));
4717
Greg Claytonc7f03b62012-01-12 04:33:28 +00004718 if (die)
4719 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004720 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004721 break;
4722 }
4723 }
4724 }
4725 }
4726 else
4727 {
4728 if (m_using_apple_tables)
4729 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004730 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4731 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004732 }
4733 }
4734
4735 }
4736 }
4737 return type_sp;
4738}
4739
Greg Claytona8022fa2012-04-24 21:22:41 +00004740
Greg Clayton80c26302012-02-05 06:12:47 +00004741//----------------------------------------------------------------------
4742// This function helps to ensure that the declaration contexts match for
4743// two different DIEs. Often times debug information will refer to a
4744// forward declaration of a type (the equivalent of "struct my_struct;".
4745// There will often be a declaration of that type elsewhere that has the
4746// full definition. When we go looking for the full type "my_struct", we
4747// will find one or more matches in the accelerator tables and we will
4748// then need to make sure the type was in the same declaration context
4749// as the original DIE. This function can efficiently compare two DIEs
4750// and will return true when the declaration context matches, and false
4751// when they don't.
4752//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004753bool
4754SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4755 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4756{
Greg Claytona8022fa2012-04-24 21:22:41 +00004757 if (die1 == die2)
4758 return true;
4759
4760#if defined (LLDB_CONFIGURATION_DEBUG)
4761 // You can't and shouldn't call this function with a compile unit from
4762 // two different SymbolFileDWARF instances.
4763 assert (DebugInfo()->ContainsCompileUnit (cu1));
4764 assert (DebugInfo()->ContainsCompileUnit (cu2));
4765#endif
4766
Greg Clayton890ff562012-02-02 05:48:16 +00004767 DWARFDIECollection decl_ctx_1;
4768 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004769 //The declaration DIE stack is a stack of the declaration context
4770 // DIEs all the way back to the compile unit. If a type "T" is
4771 // declared inside a class "B", and class "B" is declared inside
4772 // a class "A" and class "A" is in a namespace "lldb", and the
4773 // namespace is in a compile unit, there will be a stack of DIEs:
4774 //
4775 // [0] DW_TAG_class_type for "B"
4776 // [1] DW_TAG_class_type for "A"
4777 // [2] DW_TAG_namespace for "lldb"
4778 // [3] DW_TAG_compile_unit for the source file.
4779 //
4780 // We grab both contexts and make sure that everything matches
4781 // all the way back to the compiler unit.
4782
4783 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004784 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004785 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004786 // Make sure the context arrays have the same size, otherwise
4787 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004788 const size_t count1 = decl_ctx_1.Size();
4789 const size_t count2 = decl_ctx_2.Size();
4790 if (count1 != count2)
4791 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004792
4793 // Make sure the DW_TAG values match all the way back up the the
4794 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004795 const DWARFDebugInfoEntry *decl_ctx_die1;
4796 const DWARFDebugInfoEntry *decl_ctx_die2;
4797 size_t i;
4798 for (i=0; i<count1; i++)
4799 {
4800 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4801 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4802 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4803 return false;
4804 }
Greg Clayton890ff562012-02-02 05:48:16 +00004805#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004806
4807 // Make sure the top item in the decl context die array is always
4808 // DW_TAG_compile_unit. If it isn't then something went wrong in
4809 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004810 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004811
Greg Clayton890ff562012-02-02 05:48:16 +00004812#endif
4813 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004814 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004815 for (i=0; i<count1 - 1; i++)
4816 {
4817 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4818 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4819 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004820 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004821 // If the string was from a DW_FORM_strp, then the pointer will often
4822 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004823 if (name1 == name2)
4824 continue;
4825
4826 // Name pointers are not equal, so only compare the strings
4827 // if both are not NULL.
4828 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004829 {
Greg Clayton5569e642012-02-06 01:44:54 +00004830 // If the strings don't compare, we are done...
4831 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004832 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004833 }
4834 else
4835 {
4836 // One name was NULL while the other wasn't
4837 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004838 }
4839 }
Greg Clayton80c26302012-02-05 06:12:47 +00004840 // We made it through all of the checks and the declaration contexts
4841 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004842 return true;
4843}
Greg Clayton220a0072011-12-09 08:48:30 +00004844
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004845// This function can be used when a DIE is found that is a forward declaration
4846// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004847// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004848TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004849SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004850 const DWARFDebugInfoEntry *die,
4851 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004852{
4853 TypeSP type_sp;
4854
Greg Claytona8022fa2012-04-24 21:22:41 +00004855#if defined (LLDB_CONFIGURATION_DEBUG)
4856 // You can't and shouldn't call this function with a compile unit from
4857 // another SymbolFileDWARF instance.
4858 assert (DebugInfo()->ContainsCompileUnit (cu));
4859#endif
4860
Greg Clayton1a65ae12011-01-25 23:55:37 +00004861 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004862 return type_sp;
4863
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004864 std::string qualified_name;
4865
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004866 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4867 if (log)
4868 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004869 die->GetQualifiedName(this, cu, qualified_name);
4870 GetObjectFile()->GetModule()->LogMessage (log.get(),
4871 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4872 die->GetOffset(),
4873 qualified_name.c_str(),
4874 type_name.GetCString());
4875 }
4876
Greg Clayton7f995132011-10-04 22:41:51 +00004877 DIEArray die_offsets;
4878
Greg Clayton97fbc342011-10-20 22:30:33 +00004879 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004880 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004881 if (m_apple_types_ap.get())
4882 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004883 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4884 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4885 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004886 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004887 if (qualified_name.empty())
4888 die->GetQualifiedName(this, cu, qualified_name);
4889
4890 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4891 if (log)
4892 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
4893 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4894 }
4895 else if (has_tag > 1)
4896 {
4897 if (log)
4898 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004899 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004900 }
4901 else
4902 {
4903 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4904 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004905 }
Greg Clayton7f995132011-10-04 22:41:51 +00004906 }
4907 else
4908 {
4909 if (!m_indexed)
4910 Index ();
4911
4912 m_type_index.Find (type_name, die_offsets);
4913 }
Greg Clayton7f995132011-10-04 22:41:51 +00004914
4915 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004916
Greg Clayton934cb052011-12-03 00:27:05 +00004917 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004918
4919 DWARFCompileUnit* type_cu = NULL;
4920 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004921 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004922 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004923 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004924 for (size_t i=0; i<num_matches; ++i)
4925 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004926 const dw_offset_t die_offset = die_offsets[i];
4927 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004928
Greg Clayton95d87902011-11-11 03:16:25 +00004929 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004930 {
Greg Clayton934cb052011-12-03 00:27:05 +00004931 bool try_resolving_type = false;
4932
4933 // Don't try and resolve the DIE we are looking for with the DIE itself!
4934 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004935 {
Greg Clayton934cb052011-12-03 00:27:05 +00004936 const dw_tag_t type_die_tag = type_die->Tag();
4937 // Make sure the tags match
4938 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004939 {
Greg Clayton934cb052011-12-03 00:27:05 +00004940 // The tags match, lets try resolving this type
4941 try_resolving_type = true;
4942 }
4943 else
4944 {
4945 // The tags don't match, but we need to watch our for a
4946 // forward declaration for a struct and ("struct foo")
4947 // ends up being a class ("class foo { ... };") or
4948 // vice versa.
4949 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004950 {
Greg Clayton934cb052011-12-03 00:27:05 +00004951 case DW_TAG_class_type:
4952 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4953 try_resolving_type = (die_tag == DW_TAG_structure_type);
4954 break;
4955 case DW_TAG_structure_type:
4956 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4957 try_resolving_type = (die_tag == DW_TAG_class_type);
4958 break;
4959 default:
4960 // Tags don't match, don't event try to resolve
4961 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004962 break;
4963 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004964 }
4965 }
Greg Clayton934cb052011-12-03 00:27:05 +00004966
4967 if (try_resolving_type)
4968 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004969 if (log)
4970 {
4971 std::string qualified_name;
4972 type_die->GetQualifiedName(this, cu, qualified_name);
4973 GetObjectFile()->GetModule()->LogMessage (log.get(),
4974 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4975 die->GetOffset(),
4976 type_name.GetCString(),
4977 type_die->GetOffset(),
4978 qualified_name.c_str());
4979 }
4980
Greg Clayton890ff562012-02-02 05:48:16 +00004981 // Make sure the decl contexts match all the way up
4982 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004983 {
Greg Clayton890ff562012-02-02 05:48:16 +00004984 Type *resolved_type = ResolveType (type_cu, type_die, false);
4985 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4986 {
Daniel Malead01b2952012-11-29 21:49:15 +00004987 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 +00004988 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004989 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004990 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4991 MakeUserID(type_die->GetOffset()),
4992 MakeUserID(type_cu->GetOffset()));
4993
4994 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004995 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004996 break;
4997 }
Greg Clayton934cb052011-12-03 00:27:05 +00004998 }
4999 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00005000 else
5001 {
5002 if (log)
5003 {
5004 std::string qualified_name;
5005 type_die->GetQualifiedName(this, cu, qualified_name);
5006 GetObjectFile()->GetModule()->LogMessage (log.get(),
5007 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5008 die->GetOffset(),
5009 type_name.GetCString(),
5010 type_die->GetOffset(),
5011 qualified_name.c_str());
5012 }
5013 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005014 }
Greg Clayton95d87902011-11-11 03:16:25 +00005015 else
5016 {
5017 if (m_using_apple_tables)
5018 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005019 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5020 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00005021 }
5022 }
5023
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00005024 }
5025 }
5026 return type_sp;
5027}
5028
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005029TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00005030SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5031{
5032 TypeSP type_sp;
5033
5034 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5035 if (dwarf_decl_ctx_count > 0)
5036 {
5037 const ConstString type_name(dwarf_decl_ctx[0].name);
5038 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5039
5040 if (type_name)
5041 {
5042 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
5043 if (log)
5044 {
5045 GetObjectFile()->GetModule()->LogMessage (log.get(),
5046 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5047 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5048 dwarf_decl_ctx.GetQualifiedName());
5049 }
5050
5051 DIEArray die_offsets;
5052
5053 if (m_using_apple_tables)
5054 {
5055 if (m_apple_types_ap.get())
5056 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005057 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5058 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5059 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00005060 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00005061 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5062 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5063 if (log)
5064 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTagAndQualifiedNameHash()");
5065 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5066 }
5067 else if (has_tag)
5068 {
5069 if (log)
5070 GetObjectFile()->GetModule()->LogMessage (log.get(),"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00005071 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5072 }
5073 else
5074 {
5075 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5076 }
5077 }
5078 }
5079 else
5080 {
5081 if (!m_indexed)
5082 Index ();
5083
5084 m_type_index.Find (type_name, die_offsets);
5085 }
5086
5087 const size_t num_matches = die_offsets.size();
5088
5089
5090 DWARFCompileUnit* type_cu = NULL;
5091 const DWARFDebugInfoEntry* type_die = NULL;
5092 if (num_matches)
5093 {
5094 DWARFDebugInfo* debug_info = DebugInfo();
5095 for (size_t i=0; i<num_matches; ++i)
5096 {
5097 const dw_offset_t die_offset = die_offsets[i];
5098 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5099
5100 if (type_die)
5101 {
5102 bool try_resolving_type = false;
5103
5104 // Don't try and resolve the DIE we are looking for with the DIE itself!
5105 const dw_tag_t type_tag = type_die->Tag();
5106 // Make sure the tags match
5107 if (type_tag == tag)
5108 {
5109 // The tags match, lets try resolving this type
5110 try_resolving_type = true;
5111 }
5112 else
5113 {
5114 // The tags don't match, but we need to watch our for a
5115 // forward declaration for a struct and ("struct foo")
5116 // ends up being a class ("class foo { ... };") or
5117 // vice versa.
5118 switch (type_tag)
5119 {
5120 case DW_TAG_class_type:
5121 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5122 try_resolving_type = (tag == DW_TAG_structure_type);
5123 break;
5124 case DW_TAG_structure_type:
5125 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5126 try_resolving_type = (tag == DW_TAG_class_type);
5127 break;
5128 default:
5129 // Tags don't match, don't event try to resolve
5130 // using this type whose name matches....
5131 break;
5132 }
5133 }
5134
5135 if (try_resolving_type)
5136 {
5137 DWARFDeclContext type_dwarf_decl_ctx;
5138 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5139
5140 if (log)
5141 {
5142 GetObjectFile()->GetModule()->LogMessage (log.get(),
5143 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5144 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5145 dwarf_decl_ctx.GetQualifiedName(),
5146 type_die->GetOffset(),
5147 type_dwarf_decl_ctx.GetQualifiedName());
5148 }
5149
5150 // Make sure the decl contexts match all the way up
5151 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5152 {
5153 Type *resolved_type = ResolveType (type_cu, type_die, false);
5154 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5155 {
5156 type_sp = resolved_type->shared_from_this();
5157 break;
5158 }
5159 }
5160 }
5161 else
5162 {
5163 if (log)
5164 {
5165 std::string qualified_name;
5166 type_die->GetQualifiedName(this, type_cu, qualified_name);
5167 GetObjectFile()->GetModule()->LogMessage (log.get(),
5168 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5169 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5170 dwarf_decl_ctx.GetQualifiedName(),
5171 type_die->GetOffset(),
5172 qualified_name.c_str());
5173 }
5174 }
5175 }
5176 else
5177 {
5178 if (m_using_apple_tables)
5179 {
5180 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5181 die_offset, type_name.GetCString());
5182 }
5183 }
5184
5185 }
5186 }
5187 }
5188 }
5189 return type_sp;
5190}
5191
Greg Clayton4116e932012-05-15 02:33:01 +00005192bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005193SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005194 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005195 DWARFCompileUnit* src_cu,
5196 const DWARFDebugInfoEntry *src_class_die,
5197 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005198 const DWARFDebugInfoEntry *dst_class_die,
5199 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005200{
5201 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5202 return false;
5203 if (src_class_die->Tag() != dst_class_die->Tag())
5204 return false;
5205
5206 // We need to complete the class type so we can get all of the method types
5207 // parsed so we can then unique those types to their equivalent counterparts
5208 // in "dst_cu" and "dst_class_die"
5209 class_type->GetClangFullType();
5210
5211 const DWARFDebugInfoEntry *src_die;
5212 const DWARFDebugInfoEntry *dst_die;
5213 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5214 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005215 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5216 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005217 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5218 {
5219 if (src_die->Tag() == DW_TAG_subprogram)
5220 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005221 // Make sure this is a declaration and not a concrete instance by looking
5222 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5223 // are placed inside the class definitions and shouldn't be included in
5224 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005225 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005226 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005227 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005228 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005229 {
5230 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005231 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005232 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5233 else
5234 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5235 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005236 }
Greg Clayton4116e932012-05-15 02:33:01 +00005237 }
5238 }
5239 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5240 {
5241 if (dst_die->Tag() == DW_TAG_subprogram)
5242 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005243 // Make sure this is a declaration and not a concrete instance by looking
5244 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5245 // are placed inside the class definitions and shouldn't be included in
5246 // the list of things are are tracking here.
5247 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5248 {
5249 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5250 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005251 {
5252 ConstString dst_const_name(dst_name);
5253 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5254 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5255 else
5256 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5257 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005258 }
Greg Clayton4116e932012-05-15 02:33:01 +00005259 }
5260 }
5261 const uint32_t src_size = src_name_to_die.GetSize ();
5262 const uint32_t dst_size = dst_name_to_die.GetSize ();
5263 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005264
5265 // Is everything kosher so we can go through the members at top speed?
5266 bool fast_path = true;
5267
5268 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005269 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005270 if (src_size != 0 && dst_size != 0)
5271 {
5272 if (log)
5273 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)",
5274 src_class_die->GetOffset(),
5275 dst_class_die->GetOffset(),
5276 src_size,
5277 dst_size);
5278 }
5279
5280 fast_path = false;
5281 }
5282
5283 uint32_t idx;
5284
5285 if (fast_path)
5286 {
Greg Clayton4116e932012-05-15 02:33:01 +00005287 for (idx = 0; idx < src_size; ++idx)
5288 {
5289 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5290 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5291
5292 if (src_die->Tag() != dst_die->Tag())
5293 {
5294 if (log)
5295 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)",
5296 src_class_die->GetOffset(),
5297 dst_class_die->GetOffset(),
5298 src_die->GetOffset(),
5299 DW_TAG_value_to_name(src_die->Tag()),
5300 dst_die->GetOffset(),
5301 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005302 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005303 }
5304
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005305 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005306 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5307
5308 // Make sure the names match
5309 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5310 continue;
5311
5312 if (log)
5313 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)",
5314 src_class_die->GetOffset(),
5315 dst_class_die->GetOffset(),
5316 src_die->GetOffset(),
5317 src_name,
5318 dst_die->GetOffset(),
5319 dst_name);
5320
Sean Callanan2367f8a2013-02-26 01:12:25 +00005321 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005322 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005323 }
Greg Clayton4116e932012-05-15 02:33:01 +00005324
Sean Callanan2367f8a2013-02-26 01:12:25 +00005325 // Now do the work of linking the DeclContexts and Types.
5326 if (fast_path)
5327 {
5328 // We can do this quickly. Just run across the tables index-for-index since
5329 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005330 for (idx = 0; idx < src_size; ++idx)
5331 {
5332 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5333 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5334
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005335 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005336 if (src_decl_ctx)
5337 {
5338 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005339 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 +00005340 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5341 }
5342 else
5343 {
5344 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005345 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 +00005346 }
5347
5348 Type *src_child_type = m_die_to_type[src_die];
5349 if (src_child_type)
5350 {
5351 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005352 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 +00005353 m_die_to_type[dst_die] = src_child_type;
5354 }
5355 else
5356 {
5357 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005358 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());
5359 }
5360 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005361 }
5362 else
5363 {
5364 // We must do this slowly. For each member of the destination, look
5365 // up a member in the source with the same name, check its tag, and
5366 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005367
Sean Callanan2367f8a2013-02-26 01:12:25 +00005368 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5369 {
5370 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005371
Sean Callanan2367f8a2013-02-26 01:12:25 +00005372 for (idx = 0; idx < dst_size; ++idx)
5373 {
5374 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5375 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5376 src_die = src_name_to_die.Find(dst_name, NULL);
5377
5378 if (src_die && (src_die->Tag() == dst_die->Tag()))
5379 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005380 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005381 if (src_decl_ctx)
5382 {
5383 if (log)
5384 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5385 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5386 }
5387 else
5388 {
5389 if (log)
5390 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());
5391 }
5392
5393 Type *src_child_type = m_die_to_type[src_die];
5394 if (src_child_type)
5395 {
5396 if (log)
5397 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());
5398 m_die_to_type[dst_die] = src_child_type;
5399 }
5400 else
5401 {
5402 if (log)
5403 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());
5404 }
5405 }
5406 else
5407 {
5408 if (log)
5409 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005410
Sean Callanan2367f8a2013-02-26 01:12:25 +00005411 failures.push_back(dst_die);
5412 }
5413 }
5414 }
5415 }
5416
5417 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5418 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5419
5420 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5421
5422 if (src_size_artificial && dst_size_artificial)
5423 {
5424 dst_name_to_die_artificial.Sort();
5425
Greg Clayton65ec1032012-11-12 21:27:20 +00005426 for (idx = 0; idx < src_size_artificial; ++idx)
5427 {
5428 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5429 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5430 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5431
5432 if (dst_die)
5433 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005434 // Both classes have the artificial types, link them
5435 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5436 if (src_decl_ctx)
5437 {
5438 if (log)
5439 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5440 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5441 }
5442 else
5443 {
5444 if (log)
5445 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());
5446 }
5447
5448 Type *src_child_type = m_die_to_type[src_die];
5449 if (src_child_type)
5450 {
5451 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005452 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 +00005453 m_die_to_type[dst_die] = src_child_type;
5454 }
5455 else
5456 {
5457 if (log)
5458 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());
5459 }
5460 }
5461 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005462 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005463
Sean Callanan2367f8a2013-02-26 01:12:25 +00005464 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005465 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005466 for (idx = 0; idx < dst_size_artificial; ++idx)
5467 {
5468 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5469 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5470 if (log)
5471 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5472
5473 failures.push_back(dst_die);
5474 }
Greg Clayton4116e932012-05-15 02:33:01 +00005475 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005476
5477 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005478}
Greg Claytona8022fa2012-04-24 21:22:41 +00005479
5480TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005481SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005482{
5483 TypeSP type_sp;
5484
Greg Clayton1be10fc2010-09-29 01:12:09 +00005485 if (type_is_new_ptr)
5486 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005487
5488#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5489 static DIEStack g_die_stack;
5490 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5491#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005492
Sean Callananc7fbf732010-08-06 00:32:49 +00005493 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005494 if (die != NULL)
5495 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005496 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005497 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005498 {
5499 const DWARFDebugInfoEntry *context_die;
5500 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5501
Greg Clayton1fba87112012-02-09 20:03:49 +00005502 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 +00005503 die->GetOffset(),
5504 context,
5505 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005506 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005507 die->GetName(this, dwarf_cu));
5508
5509#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5510 scoped_die_logger.Push (dwarf_cu, die);
5511 g_die_stack.LogDIEs(log.get(), this);
5512#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005513 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005514//
5515// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5516// if (log && dwarf_cu)
5517// {
5518// StreamString s;
5519// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005520// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005521//
5522// }
Jim Ingham16746d12011-08-25 23:21:43 +00005523
Greg Clayton594e5ed2010-09-27 21:07:38 +00005524 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005525 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005526 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005527 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005528 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005529 if (type_is_new_ptr)
5530 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005531
Greg Clayton594e5ed2010-09-27 21:07:38 +00005532 const dw_tag_t tag = die->Tag();
5533
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005534 bool is_forward_declaration = false;
5535 DWARFDebugInfoEntry::Attributes attributes;
5536 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005537 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005538 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5539 size_t byte_size = 0;
5540 Declaration decl;
5541
Greg Clayton4957bf62010-09-30 21:49:03 +00005542 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005543 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005544
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005545 dw_attr_t attr;
5546
5547 switch (tag)
5548 {
5549 case DW_TAG_base_type:
5550 case DW_TAG_pointer_type:
5551 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005552 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005553 case DW_TAG_typedef:
5554 case DW_TAG_const_type:
5555 case DW_TAG_restrict_type:
5556 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005557 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005558 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005559 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005560 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005561
Greg Claytond88d7592010-09-15 08:33:30 +00005562 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005563 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005564 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5565
5566 if (num_attributes > 0)
5567 {
5568 uint32_t i;
5569 for (i=0; i<num_attributes; ++i)
5570 {
5571 attr = attributes.AttributeAtIndex(i);
5572 DWARFFormValue form_value;
5573 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5574 {
5575 switch (attr)
5576 {
5577 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5578 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5579 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5580 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005581
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005582 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005583 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5584 // include the "&"...
5585 if (tag == DW_TAG_reference_type)
5586 {
5587 if (strchr (type_name_cstr, '&') == NULL)
5588 type_name_cstr = NULL;
5589 }
5590 if (type_name_cstr)
5591 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005592 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005593 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005594 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5595 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5596 default:
5597 case DW_AT_sibling:
5598 break;
5599 }
5600 }
5601 }
5602 }
5603
Daniel Malead01b2952012-11-29 21:49:15 +00005604 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 +00005605
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005606 switch (tag)
5607 {
5608 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005609 break;
5610
Greg Claytond4436412011-10-28 21:00:00 +00005611 case DW_TAG_unspecified_type:
5612 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5613 {
5614 resolve_state = Type::eResolveStateFull;
5615 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5616 break;
5617 }
5618 // Fall through to base type below in case we can handle the type there...
5619
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005620 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005621 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005622 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5623 encoding,
5624 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005625 break;
5626
Sean Callanance8af862012-05-21 23:31:51 +00005627 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5628 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5629 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5630 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5631 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5632 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5633 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005634 }
5635
Sean Callanan82587052013-01-03 00:05:56 +00005636 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 +00005637 {
Sean Callanan82587052013-01-03 00:05:56 +00005638 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5639
5640 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005641 {
Sean Callanan82587052013-01-03 00:05:56 +00005642 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005643 {
Sean Callanan82587052013-01-03 00:05:56 +00005644 static ConstString g_objc_type_name_id("id");
5645 static ConstString g_objc_type_name_Class("Class");
5646 static ConstString g_objc_type_name_selector("SEL");
5647
5648 if (type_name_const_str == g_objc_type_name_id)
5649 {
5650 if (log)
5651 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5652 die->GetOffset(),
5653 DW_TAG_value_to_name(die->Tag()),
5654 die->GetName(this, dwarf_cu));
5655 clang_type = ast.GetBuiltInType_objc_id();
5656 encoding_data_type = Type::eEncodingIsUID;
5657 encoding_uid = LLDB_INVALID_UID;
5658 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005659
Sean Callanan82587052013-01-03 00:05:56 +00005660 }
5661 else if (type_name_const_str == g_objc_type_name_Class)
5662 {
5663 if (log)
5664 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5665 die->GetOffset(),
5666 DW_TAG_value_to_name(die->Tag()),
5667 die->GetName(this, dwarf_cu));
5668 clang_type = ast.GetBuiltInType_objc_Class();
5669 encoding_data_type = Type::eEncodingIsUID;
5670 encoding_uid = LLDB_INVALID_UID;
5671 resolve_state = Type::eResolveStateFull;
5672 }
5673 else if (type_name_const_str == g_objc_type_name_selector)
5674 {
5675 if (log)
5676 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5677 die->GetOffset(),
5678 DW_TAG_value_to_name(die->Tag()),
5679 die->GetName(this, dwarf_cu));
5680 clang_type = ast.GetBuiltInType_objc_selector();
5681 encoding_data_type = Type::eEncodingIsUID;
5682 encoding_uid = LLDB_INVALID_UID;
5683 resolve_state = Type::eResolveStateFull;
5684 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005685 }
Sean Callanan82587052013-01-03 00:05:56 +00005686 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005687 {
Sean Callanan82587052013-01-03 00:05:56 +00005688 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5689
5690 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5691
5692 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5693 {
5694 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5695 {
5696 if (!strcmp(struct_name, "objc_object"))
5697 {
5698 if (log)
5699 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
5700 die->GetOffset(),
5701 DW_TAG_value_to_name(die->Tag()),
5702 die->GetName(this, dwarf_cu));
5703 clang_type = ast.GetBuiltInType_objc_id();
5704 encoding_data_type = Type::eEncodingIsUID;
5705 encoding_uid = LLDB_INVALID_UID;
5706 resolve_state = Type::eResolveStateFull;
5707 }
5708 }
5709 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005710 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005711 }
5712 }
5713
Greg Clayton81c22f62011-10-19 18:09:39 +00005714 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005715 this,
5716 type_name_const_str,
5717 byte_size,
5718 NULL,
5719 encoding_uid,
5720 encoding_data_type,
5721 &decl,
5722 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005723 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005724
Greg Clayton594e5ed2010-09-27 21:07:38 +00005725 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005726
5727// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5728// if (encoding_type != NULL)
5729// {
5730// if (encoding_type != DIE_IS_BEING_PARSED)
5731// type_sp->SetEncodingType(encoding_type);
5732// else
5733// m_indirect_fixups.push_back(type_sp.get());
5734// }
5735 }
5736 break;
5737
5738 case DW_TAG_structure_type:
5739 case DW_TAG_union_type:
5740 case DW_TAG_class_type:
5741 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005742 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005743 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005744 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005745
Greg Clayton9e409562010-07-28 02:04:09 +00005746 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005747 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005748 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005749 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005750 if (num_attributes > 0)
5751 {
5752 uint32_t i;
5753 for (i=0; i<num_attributes; ++i)
5754 {
5755 attr = attributes.AttributeAtIndex(i);
5756 DWARFFormValue form_value;
5757 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5758 {
5759 switch (attr)
5760 {
Greg Clayton9e409562010-07-28 02:04:09 +00005761 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005762 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5763 {
5764 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5765 // point to the compile unit file, so we clear this invalid value
5766 // so that we can still unique types efficiently.
5767 decl.SetFile(FileSpec ("<invalid>", false));
5768 }
5769 else
5770 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005771 break;
5772
5773 case DW_AT_decl_line:
5774 decl.SetLine(form_value.Unsigned());
5775 break;
5776
5777 case DW_AT_decl_column:
5778 decl.SetColumn(form_value.Unsigned());
5779 break;
5780
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005781 case DW_AT_name:
5782 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005783 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005784 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005785
5786 case DW_AT_byte_size:
5787 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005788 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005789 break;
5790
5791 case DW_AT_accessibility:
5792 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5793 break;
5794
5795 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005796 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005797 break;
5798
5799 case DW_AT_APPLE_runtime_class:
5800 class_language = (LanguageType)form_value.Signed();
5801 break;
5802
Greg Clayton18774842011-11-29 23:40:34 +00005803 case DW_AT_APPLE_objc_complete_type:
5804 is_complete_objc_class = form_value.Signed();
5805 break;
5806
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005807 case DW_AT_allocated:
5808 case DW_AT_associated:
5809 case DW_AT_data_location:
5810 case DW_AT_description:
5811 case DW_AT_start_scope:
5812 case DW_AT_visibility:
5813 default:
5814 case DW_AT_sibling:
5815 break;
5816 }
5817 }
5818 }
5819 }
5820
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005821 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005822
Greg Clayton123edca2012-03-02 00:07:15 +00005823 // Only try and unique the type if it has a name.
5824 if (type_name_const_str &&
5825 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005826 this,
5827 dwarf_cu,
5828 die,
5829 decl,
5830 byte_size_valid ? byte_size : -1,
5831 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005832 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005833 // We have already parsed this type or from another
5834 // compile unit. GCC loves to use the "one definition
5835 // rule" which can result in multiple definitions
5836 // of the same class over and over in each compile
5837 // unit.
5838 type_sp = unique_ast_entry.m_type_sp;
5839 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005840 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005841 m_die_to_type[die] = type_sp.get();
5842 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005843 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005844 }
5845
Daniel Malead01b2952012-11-29 21:49:15 +00005846 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 +00005847
5848 int tag_decl_kind = -1;
5849 AccessType default_accessibility = eAccessNone;
5850 if (tag == DW_TAG_structure_type)
5851 {
5852 tag_decl_kind = clang::TTK_Struct;
5853 default_accessibility = eAccessPublic;
5854 }
5855 else if (tag == DW_TAG_union_type)
5856 {
5857 tag_decl_kind = clang::TTK_Union;
5858 default_accessibility = eAccessPublic;
5859 }
5860 else if (tag == DW_TAG_class_type)
5861 {
5862 tag_decl_kind = clang::TTK_Class;
5863 default_accessibility = eAccessPrivate;
5864 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005865
5866 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5867 die->HasChildren() == false &&
5868 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5869 {
5870 // Work around an issue with clang at the moment where
5871 // forward declarations for objective C classes are emitted
5872 // as:
5873 // DW_TAG_structure_type [2]
5874 // DW_AT_name( "ForwardObjcClass" )
5875 // DW_AT_byte_size( 0x00 )
5876 // DW_AT_decl_file( "..." )
5877 // DW_AT_decl_line( 1 )
5878 //
5879 // Note that there is no DW_AT_declaration and there are
5880 // no children, and the byte size is zero.
5881 is_forward_declaration = true;
5882 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005883
Sean Callanan7457f8d2012-04-25 01:03:57 +00005884 if (class_language == eLanguageTypeObjC ||
5885 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005886 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005887 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005888 {
5889 // We have a valid eSymbolTypeObjCClass class symbol whose
5890 // name matches the current objective C class that we
5891 // are trying to find and this DIE isn't the complete
5892 // definition (we checked is_complete_objc_class above and
5893 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005894 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005895
Greg Clayton1f746072012-08-29 21:13:06 +00005896 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005897 {
5898 // We weren't able to find a full declaration in
5899 // this DWARF, see if we have a declaration anywhere
5900 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005901 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005902 }
5903
5904 if (type_sp)
5905 {
5906 if (log)
5907 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005908 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005909 "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 +00005910 this,
5911 die->GetOffset(),
5912 DW_TAG_value_to_name(tag),
5913 type_name_cstr,
5914 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005915 }
5916
5917 // We found a real definition for this type elsewhere
5918 // so lets use it and cache the fact that we found
5919 // a complete type for this die
5920 m_die_to_type[die] = type_sp.get();
5921 return type_sp;
5922 }
5923 }
5924 }
5925
5926
5927 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005928 {
5929 // We have a forward declaration to a type and we need
5930 // to try and find a full declaration. We look in the
5931 // current type index just in case we have a forward
5932 // declaration followed by an actual declarations in the
5933 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005934 if (log)
5935 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005936 GetObjectFile()->GetModule()->LogMessage (log.get(),
5937 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5938 this,
5939 die->GetOffset(),
5940 DW_TAG_value_to_name(tag),
5941 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005942 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005943
Greg Claytona8022fa2012-04-24 21:22:41 +00005944 DWARFDeclContext die_decl_ctx;
5945 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5946
5947 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5948 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005949
Greg Clayton1f746072012-08-29 21:13:06 +00005950 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005951 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005952 // We weren't able to find a full declaration in
5953 // this DWARF, see if we have a declaration anywhere
5954 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005955 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005956 }
5957
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005958 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005959 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005960 if (log)
5961 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005962 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00005963 "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 +00005964 this,
5965 die->GetOffset(),
5966 DW_TAG_value_to_name(tag),
5967 type_name_cstr,
5968 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005969 }
5970
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005971 // We found a real definition for this type elsewhere
5972 // so lets use it and cache the fact that we found
5973 // a complete type for this die
5974 m_die_to_type[die] = type_sp.get();
5975 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005976 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005977 }
5978 assert (tag_decl_kind != -1);
5979 bool clang_type_was_created = false;
5980 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5981 if (clang_type == NULL)
5982 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005983 const DWARFDebugInfoEntry *decl_ctx_die;
5984
5985 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005986 if (accessibility == eAccessNone && decl_ctx)
5987 {
5988 // Check the decl context that contains this class/struct/union.
5989 // If it is a class we must give it an accessability.
5990 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5991 if (DeclKindIsCXXClass (containing_decl_kind))
5992 accessibility = default_accessibility;
5993 }
5994
Greg Claytonf0705c82011-10-22 03:33:13 +00005995 if (type_name_cstr && strchr (type_name_cstr, '<'))
5996 {
5997 ClangASTContext::TemplateParameterInfos template_param_infos;
5998 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5999 {
6000 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00006001 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00006002 type_name_cstr,
6003 tag_decl_kind,
6004 template_param_infos);
6005
6006 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6007 class_template_decl,
6008 tag_decl_kind,
6009 template_param_infos);
6010 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6011 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00006012
Jim Ingham379397632012-10-27 02:54:13 +00006013 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
6014 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00006015 }
6016 }
6017
6018 if (!clang_type_was_created)
6019 {
6020 clang_type_was_created = true;
Jim Ingham379397632012-10-27 02:54:13 +00006021 ClangASTMetadata metadata;
6022 metadata.SetUserID(MakeUserID(die->GetOffset()));
Greg Clayton55561e92011-10-26 03:31:36 +00006023 clang_type = ast.CreateRecordType (decl_ctx,
6024 accessibility,
6025 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00006026 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00006027 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00006028 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00006029 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006030 }
6031
6032 // Store a forward declaration to this class type in case any
6033 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00006034 // types for function prototypes.
6035 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00006036 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006037 this,
6038 type_name_const_str,
6039 byte_size,
6040 NULL,
6041 LLDB_INVALID_UID,
6042 Type::eEncodingIsUID,
6043 &decl,
6044 clang_type,
6045 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00006046
6047 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006048
6049
6050 // Add our type to the unique type map so we don't
6051 // end up creating many copies of the same type over
6052 // and over in the ASTContext for our module
6053 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00006054 unique_ast_entry.m_symfile = this;
6055 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006056 unique_ast_entry.m_die = die;
6057 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00006058 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00006059 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6060 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006061
Sean Callanan12014a02011-12-08 23:45:45 +00006062 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00006063 {
6064 // Always start the definition for a class type so that
6065 // if the class has child classes or types that require
6066 // the class to be created for use as their decl contexts
6067 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00006068 if (die->HasChildren() == false)
6069 {
6070 // No children for this struct/union/class, lets finish it
6071 ast.StartTagDeclarationDefinition (clang_type);
6072 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00006073
6074 if (tag == DW_TAG_structure_type) // this only applies in C
6075 {
6076 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
6077 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
6078
6079 if (record_type)
6080 {
6081 clang::RecordDecl *record_decl = record_type->getDecl();
6082
6083 if (record_decl)
6084 {
6085 LayoutInfo layout_info;
6086
6087 layout_info.alignment = 0;
6088 layout_info.bit_size = 0;
6089
6090 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6091 }
6092 }
6093 }
Sean Callanan12014a02011-12-08 23:45:45 +00006094 }
6095 else if (clang_type_was_created)
6096 {
Greg Clayton219cf312012-03-30 00:51:13 +00006097 // Start the definition if the class is not objective C since
6098 // the underlying decls respond to isCompleteDefinition(). Objective
6099 // C decls dont' respond to isCompleteDefinition() so we can't
6100 // start the declaration definition right away. For C++ classs/union/structs
6101 // we want to start the definition in case the class is needed as the
6102 // declaration context for a contained class or type without the need
6103 // to complete that type..
6104
Sean Callanan7457f8d2012-04-25 01:03:57 +00006105 if (class_language != eLanguageTypeObjC &&
6106 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00006107 ast.StartTagDeclarationDefinition (clang_type);
6108
Sean Callanan12014a02011-12-08 23:45:45 +00006109 // Leave this as a forward declaration until we need
6110 // to know the details of the type. lldb_private::Type
6111 // will automatically call the SymbolFile virtual function
6112 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6113 // When the definition needs to be defined.
6114 m_forward_decl_die_to_clang_type[die] = clang_type;
6115 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6116 ClangASTContext::SetHasExternalStorage (clang_type, true);
6117 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006118 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006119
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006120 }
6121 break;
6122
6123 case DW_TAG_enumeration_type:
6124 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006125 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006126 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006127
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006128 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006129
Greg Claytond88d7592010-09-15 08:33:30 +00006130 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006131 if (num_attributes > 0)
6132 {
6133 uint32_t i;
6134
6135 for (i=0; i<num_attributes; ++i)
6136 {
6137 attr = attributes.AttributeAtIndex(i);
6138 DWARFFormValue form_value;
6139 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6140 {
6141 switch (attr)
6142 {
Greg Clayton7a345282010-11-09 23:46:37 +00006143 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6144 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6145 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006146 case DW_AT_name:
6147 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006148 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006149 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006150 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006151 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6152 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6153 case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006154 case DW_AT_allocated:
6155 case DW_AT_associated:
6156 case DW_AT_bit_stride:
6157 case DW_AT_byte_stride:
6158 case DW_AT_data_location:
6159 case DW_AT_description:
6160 case DW_AT_start_scope:
6161 case DW_AT_visibility:
6162 case DW_AT_specification:
6163 case DW_AT_abstract_origin:
6164 case DW_AT_sibling:
6165 break;
6166 }
6167 }
6168 }
6169
Daniel Malead01b2952012-11-29 21:49:15 +00006170 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 +00006171
Greg Clayton1be10fc2010-09-29 01:12:09 +00006172 clang_type_t enumerator_clang_type = NULL;
6173 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6174 if (clang_type == NULL)
6175 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006176 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6177 DW_ATE_signed,
6178 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00006179 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006180 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006181 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006182 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006183 }
6184 else
6185 {
6186 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
6187 assert (enumerator_clang_type != NULL);
6188 }
6189
Greg Claytona2721472011-06-25 00:44:06 +00006190 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6191
Greg Clayton81c22f62011-10-19 18:09:39 +00006192 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006193 this,
6194 type_name_const_str,
6195 byte_size,
6196 NULL,
6197 encoding_uid,
6198 Type::eEncodingIsUID,
6199 &decl,
6200 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006201 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006202
Greg Clayton6beaaa62011-01-17 03:46:26 +00006203 ast.StartTagDeclarationDefinition (clang_type);
6204 if (die->HasChildren())
6205 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006206 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
6207 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006208 }
6209 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006210 }
6211 }
6212 break;
6213
Jim Inghamb0be4422010-08-12 01:20:14 +00006214 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006215 case DW_TAG_subprogram:
6216 case DW_TAG_subroutine_type:
6217 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006218 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006219 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006220
Greg Clayton23f59502012-07-17 03:23:13 +00006221 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006222 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006223 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006224 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006225 bool is_static = false;
6226 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006227 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006228 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006229 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6230 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006231 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006232
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006233 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006234 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006235
6236
Greg Claytond88d7592010-09-15 08:33:30 +00006237 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006238 if (num_attributes > 0)
6239 {
6240 uint32_t i;
6241 for (i=0; i<num_attributes; ++i)
6242 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006243 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006244 DWARFFormValue form_value;
6245 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6246 {
6247 switch (attr)
6248 {
6249 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6250 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6251 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6252 case DW_AT_name:
6253 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006254 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006255 break;
6256
Greg Clayton71415542012-12-08 00:24:40 +00006257 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006258 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006259 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006260 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006261 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00006262 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
6263 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00006264 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00006265 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6266
Greg Claytonf51de672010-10-01 02:31:07 +00006267
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006268 case DW_AT_external:
6269 if (form_value.Unsigned())
6270 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006271 if (storage == clang::SC_None)
6272 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006273 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006274 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006275 }
6276 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006277
Greg Clayton72da3972011-08-16 18:40:23 +00006278 case DW_AT_specification:
6279 specification_die_offset = form_value.Reference(dwarf_cu);
6280 break;
6281
6282 case DW_AT_abstract_origin:
6283 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6284 break;
6285
Jim Ingham379397632012-10-27 02:54:13 +00006286 case DW_AT_object_pointer:
6287 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6288 break;
6289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006290 case DW_AT_allocated:
6291 case DW_AT_associated:
6292 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006293 case DW_AT_calling_convention:
6294 case DW_AT_data_location:
6295 case DW_AT_elemental:
6296 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006297 case DW_AT_frame_base:
6298 case DW_AT_high_pc:
6299 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006300 case DW_AT_prototyped:
6301 case DW_AT_pure:
6302 case DW_AT_ranges:
6303 case DW_AT_recursive:
6304 case DW_AT_return_addr:
6305 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006306 case DW_AT_start_scope:
6307 case DW_AT_static_link:
6308 case DW_AT_trampoline:
6309 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006310 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006311 case DW_AT_description:
6312 case DW_AT_sibling:
6313 break;
6314 }
6315 }
6316 }
Greg Clayton24739922010-10-13 03:15:28 +00006317 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006318
Jim Ingham379397632012-10-27 02:54:13 +00006319 std::string object_pointer_name;
6320 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6321 {
6322 // Get the name from the object pointer die
6323 StreamString s;
6324 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6325 {
6326 object_pointer_name.assign(s.GetData());
6327 }
6328 }
6329
Daniel Malead01b2952012-11-29 21:49:15 +00006330 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 +00006331
Greg Clayton24739922010-10-13 03:15:28 +00006332 clang_type_t return_clang_type = NULL;
6333 Type *func_type = NULL;
6334
6335 if (type_die_offset != DW_INVALID_OFFSET)
6336 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006337
Greg Clayton24739922010-10-13 03:15:28 +00006338 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006339 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006340 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006341 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006342
Greg Claytonf51de672010-10-01 02:31:07 +00006343
Greg Clayton24739922010-10-13 03:15:28 +00006344 std::vector<clang_type_t> function_param_types;
6345 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006346
Greg Clayton24739922010-10-13 03:15:28 +00006347 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006348
Greg Claytoncb5860a2011-10-13 23:49:28 +00006349 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6350 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006351 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6352
Greg Claytonf0705c82011-10-22 03:33:13 +00006353 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006354 // Start off static. This will be set to false in ParseChildParameters(...)
6355 // if we find a "this" paramters as the first parameter
6356 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006357 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006358 ClangASTContext::TemplateParameterInfos template_param_infos;
6359
Greg Clayton24739922010-10-13 03:15:28 +00006360 if (die->HasChildren())
6361 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006362 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006363 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006364 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006365 dwarf_cu,
6366 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006367 skip_artificial,
6368 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006369 type_list,
6370 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006371 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006372 type_quals,
6373 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006374 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006375
Greg Clayton24739922010-10-13 03:15:28 +00006376 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006377 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006378 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006379 function_param_types.size(),
6380 is_variadic,
6381 type_quals);
6382
Greg Clayton24739922010-10-13 03:15:28 +00006383 if (type_name_cstr)
6384 {
6385 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006386 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006387 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006388 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6389 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006390 {
Greg Clayton24739922010-10-13 03:15:28 +00006391 SymbolContext empty_sc;
6392 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006393 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006394 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006395 {
Greg Clayton24739922010-10-13 03:15:28 +00006396 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006397 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006398
6399 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006400 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006401 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6402 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6403 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006404 }
Greg Clayton24739922010-10-13 03:15:28 +00006405 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006406
Greg Clayton24739922010-10-13 03:15:28 +00006407 if (class_opaque_type)
6408 {
6409 // If accessibility isn't set to anything valid, assume public for
6410 // now...
6411 if (accessibility == eAccessNone)
6412 accessibility = eAccessPublic;
6413
Sean Callanan464a5b52012-10-04 22:06:29 +00006414 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6415 type_name_cstr,
6416 clang_type,
6417 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00006418 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006419 if (type_handled)
6420 {
6421 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Jim Ingham379397632012-10-27 02:54:13 +00006422 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006423 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006424 else
6425 {
6426 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invaliad Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
6427 die->GetOffset(),
6428 tag,
6429 DW_TAG_value_to_name(tag));
6430 }
Greg Clayton24739922010-10-13 03:15:28 +00006431 }
6432 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006433 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006434 {
6435 // Look at the parent of this DIE and see if is is
6436 // a class or struct and see if this is actually a
6437 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006438 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006439 if (class_type)
6440 {
Greg Clayton4116e932012-05-15 02:33:01 +00006441 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6442 {
6443 // We uniqued the parent class of this function to another class
6444 // so we now need to associate all dies under "decl_ctx_die" to
6445 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006446 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006447 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006448 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006449
6450 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6451 if (debug_map_symfile)
6452 {
6453 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6454 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6455 }
6456 else
6457 {
6458 class_symfile = this;
6459 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6460 }
Greg Clayton4116e932012-05-15 02:33:01 +00006461 if (class_type_die)
6462 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006463 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6464
6465 CopyUniqueClassMethodTypes (class_symfile,
6466 class_type,
6467 class_type_cu_sp.get(),
6468 class_type_die,
6469 dwarf_cu,
6470 decl_ctx_die,
6471 failures);
6472
6473 // FIXME do something with these failures that's smarter than
6474 // just dropping them on the ground. Unfortunately classes don't
6475 // like having stuff added to them after their definitions are
6476 // complete...
6477
6478 type_ptr = m_die_to_type[die];
6479 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006480 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006481 type_sp = type_ptr->shared_from_this();
6482 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006483 }
6484 }
6485 }
6486
Greg Clayton72da3972011-08-16 18:40:23 +00006487 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006488 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006489 // We have a specification which we are going to base our function
6490 // prototype off of, so we need this type to be completed so that the
6491 // m_die_to_decl_ctx for the method in the specification has a valid
6492 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006493 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006494 // If we have a specification, then the function type should have been
6495 // made with the specification and not with this die.
6496 DWARFCompileUnitSP spec_cu_sp;
6497 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006498 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006499 if (spec_clang_decl_ctx)
6500 {
6501 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6502 }
6503 else
Jim Inghamc1663042011-09-29 22:12:35 +00006504 {
Daniel Malead01b2952012-11-29 21:49:15 +00006505 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006506 MakeUserID(die->GetOffset()),
6507 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006508 }
Greg Clayton72da3972011-08-16 18:40:23 +00006509 type_handled = true;
6510 }
6511 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6512 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006513 // We have a specification which we are going to base our function
6514 // prototype off of, so we need this type to be completed so that the
6515 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6516 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006517 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006518
Greg Clayton72da3972011-08-16 18:40:23 +00006519 DWARFCompileUnitSP abs_cu_sp;
6520 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006521 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006522 if (abs_clang_decl_ctx)
6523 {
6524 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6525 }
6526 else
Jim Inghamc1663042011-09-29 22:12:35 +00006527 {
Daniel Malead01b2952012-11-29 21:49:15 +00006528 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 +00006529 MakeUserID(die->GetOffset()),
6530 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006531 }
Greg Clayton72da3972011-08-16 18:40:23 +00006532 type_handled = true;
6533 }
6534 else
6535 {
6536 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6537 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006538 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006539 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006540 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006541 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6542 // in the DWARF for C++ methods... Default to public for now...
6543 if (accessibility == eAccessNone)
6544 accessibility = eAccessPublic;
6545
6546 if (!is_static && !die->HasChildren())
6547 {
6548 // We have a C++ member function with no children (this pointer!)
6549 // and clang will get mad if we try and make a function that isn't
6550 // well formed in the DWARF, so we will just skip it...
6551 type_handled = true;
6552 }
6553 else
6554 {
6555 clang::CXXMethodDecl *cxx_method_decl;
6556 // REMOVE THE CRASH DESCRIPTION BELOW
Daniel Malead01b2952012-11-29 21:49:15 +00006557 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 +00006558 type_name_cstr,
6559 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006560 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006561 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6562 m_obj_file->GetFileSpec().GetFilename().GetCString());
6563
Sean Callananc1b732d2011-11-01 18:07:13 +00006564 const bool is_attr_used = false;
6565
Greg Clayton20568dd2011-10-13 23:13:20 +00006566 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6567 type_name_cstr,
6568 clang_type,
6569 accessibility,
6570 is_virtual,
6571 is_static,
6572 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006573 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006574 is_attr_used,
6575 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006576
Greg Clayton20568dd2011-10-13 23:13:20 +00006577 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006578
6579 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006580 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006581 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6582
6583 Host::SetCrashDescription (NULL);
6584
6585
6586 ClangASTMetadata metadata;
6587 metadata.SetUserID(MakeUserID(die->GetOffset()));
6588
6589 if (!object_pointer_name.empty())
6590 {
6591 metadata.SetObjectPtrName(object_pointer_name.c_str());
6592 if (log)
6593 log->Printf ("Setting object pointer name: %s on method object 0x%ld.\n",
6594 object_pointer_name.c_str(),
6595 (uintptr_t) cxx_method_decl);
6596 }
6597 GetClangASTContext().SetMetadata ((uintptr_t)cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006598 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006599 }
Greg Clayton72da3972011-08-16 18:40:23 +00006600 }
6601 else
6602 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006603 // We were asked to parse the type for a method in a class, yet the
6604 // class hasn't been asked to complete itself through the
6605 // clang::ExternalASTSource protocol, so we need to just have the
6606 // class complete itself and do things the right way, then our
6607 // DIE should then have an entry in the m_die_to_type map. First
6608 // we need to modify the m_die_to_type so it doesn't think we are
6609 // trying to parse this DIE anymore...
6610 m_die_to_type[die] = NULL;
6611
6612 // Now we get the full type to force our class type to complete itself
6613 // using the clang::ExternalASTSource protocol which will parse all
6614 // base classes and all methods (including the method for this DIE).
6615 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006616
Greg Clayton20568dd2011-10-13 23:13:20 +00006617 // The type for this DIE should have been filled in the function call above
6618 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006619 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006620 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006621 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006622 break;
6623 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006624
6625 // FIXME This is fixing some even uglier behavior but we really need to
6626 // uniq the methods of each class as well as the class itself.
6627 // <rdar://problem/11240464>
6628 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006629 }
Greg Clayton931180e2011-01-27 06:44:37 +00006630 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006631 }
6632 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006633 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006634 }
Greg Clayton24739922010-10-13 03:15:28 +00006635
6636 if (!type_handled)
6637 {
6638 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006639 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6640 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006641 clang_type,
6642 storage,
6643 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006644
6645// if (template_param_infos.GetSize() > 0)
6646// {
6647// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6648// function_decl,
6649// type_name_cstr,
6650// template_param_infos);
6651//
6652// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6653// func_template_decl,
6654// template_param_infos);
6655// }
Greg Clayton24739922010-10-13 03:15:28 +00006656 // Add the decl to our DIE to decl context map
6657 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006658 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006659 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006660 ast.SetFunctionParameters (function_decl,
6661 &function_param_decls.front(),
6662 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006663
Jim Ingham379397632012-10-27 02:54:13 +00006664 ClangASTMetadata metadata;
6665 metadata.SetUserID(MakeUserID(die->GetOffset()));
6666
6667 if (!object_pointer_name.empty())
6668 {
6669 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006670 if (log)
6671 log->Printf ("Setting object pointer name: %s on function object 0x%ld.\n",
6672 object_pointer_name.c_str(),
6673 (uintptr_t) function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006674 }
6675 GetClangASTContext().SetMetadata ((uintptr_t)function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006676 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006677 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006678 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006679 this,
6680 type_name_const_str,
6681 0,
6682 NULL,
6683 LLDB_INVALID_UID,
6684 Type::eEncodingIsUID,
6685 &decl,
6686 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006687 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006688 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006689 }
6690 break;
6691
6692 case DW_TAG_array_type:
6693 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006694 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006695 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006696
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006697 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006698 int64_t first_index = 0;
6699 uint32_t byte_stride = 0;
6700 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006701 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006702
6703 if (num_attributes > 0)
6704 {
6705 uint32_t i;
6706 for (i=0; i<num_attributes; ++i)
6707 {
6708 attr = attributes.AttributeAtIndex(i);
6709 DWARFFormValue form_value;
6710 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6711 {
6712 switch (attr)
6713 {
6714 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6715 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6716 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6717 case DW_AT_name:
6718 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006719 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006720 break;
6721
6722 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006723 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006724 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6725 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006726 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6727 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006728 case DW_AT_allocated:
6729 case DW_AT_associated:
6730 case DW_AT_data_location:
6731 case DW_AT_description:
6732 case DW_AT_ordering:
6733 case DW_AT_start_scope:
6734 case DW_AT_visibility:
6735 case DW_AT_specification:
6736 case DW_AT_abstract_origin:
6737 case DW_AT_sibling:
6738 break;
6739 }
6740 }
6741 }
6742
Daniel Malead01b2952012-11-29 21:49:15 +00006743 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 +00006744
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006745 Type *element_type = ResolveTypeUID(type_die_offset);
6746
6747 if (element_type)
6748 {
6749 std::vector<uint64_t> element_orders;
6750 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6751 if (byte_stride == 0 && bit_stride == 0)
6752 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006753 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006754 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6755 uint64_t num_elements = 0;
6756 std::vector<uint64_t>::const_reverse_iterator pos;
6757 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6758 for (pos = element_orders.rbegin(); pos != end; ++pos)
6759 {
6760 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006761 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton4ef877f2012-12-06 02:33:54 +00006762 num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006763 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006764 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006765 }
6766 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006767 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006768 this,
6769 empty_name,
6770 array_element_bit_stride / 8,
6771 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006772 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006773 Type::eEncodingIsUID,
6774 &decl,
6775 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006776 Type::eResolveStateFull));
6777 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006778 }
6779 }
6780 }
6781 break;
6782
Greg Clayton9b81a312010-06-12 01:20:30 +00006783 case DW_TAG_ptr_to_member_type:
6784 {
6785 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6786 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6787
Greg Claytond88d7592010-09-15 08:33:30 +00006788 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006789
6790 if (num_attributes > 0) {
6791 uint32_t i;
6792 for (i=0; i<num_attributes; ++i)
6793 {
6794 attr = attributes.AttributeAtIndex(i);
6795 DWARFFormValue form_value;
6796 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6797 {
6798 switch (attr)
6799 {
6800 case DW_AT_type:
6801 type_die_offset = form_value.Reference(dwarf_cu); break;
6802 case DW_AT_containing_type:
6803 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6804 }
6805 }
6806 }
6807
6808 Type *pointee_type = ResolveTypeUID(type_die_offset);
6809 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6810
Greg Clayton526e5af2010-11-13 03:52:47 +00006811 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6812 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006813
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006814 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6815 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006816
Greg Clayton526e5af2010-11-13 03:52:47 +00006817 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6818 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006819
Greg Clayton81c22f62011-10-19 18:09:39 +00006820 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006821 this,
6822 type_name_const_str,
6823 byte_size,
6824 NULL,
6825 LLDB_INVALID_UID,
6826 Type::eEncodingIsUID,
6827 NULL,
6828 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006829 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006830 }
6831
6832 break;
6833 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006834 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006835 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",
6836 die->GetOffset(),
6837 tag,
6838 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006839 break;
6840 }
6841
6842 if (type_sp.get())
6843 {
6844 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6845 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6846
6847 SymbolContextScope * symbol_context_scope = NULL;
6848 if (sc_parent_tag == DW_TAG_compile_unit)
6849 {
6850 symbol_context_scope = sc.comp_unit;
6851 }
6852 else if (sc.function != NULL)
6853 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006854 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006855 if (symbol_context_scope == NULL)
6856 symbol_context_scope = sc.function;
6857 }
6858
6859 if (symbol_context_scope != NULL)
6860 {
6861 type_sp->SetSymbolContextScope(symbol_context_scope);
6862 }
6863
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006864 // We are ready to put this type into the uniqued list up at the module level
6865 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006866
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006867 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006868 }
6869 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006870 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006871 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006872 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006873 }
6874 }
6875 return type_sp;
6876}
6877
6878size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006879SymbolFileDWARF::ParseTypes
6880(
6881 const SymbolContext& sc,
6882 DWARFCompileUnit* dwarf_cu,
6883 const DWARFDebugInfoEntry *die,
6884 bool parse_siblings,
6885 bool parse_children
6886)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006887{
6888 size_t types_added = 0;
6889 while (die != NULL)
6890 {
6891 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006892 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006893 {
6894 if (type_is_new)
6895 ++types_added;
6896 }
6897
6898 if (parse_children && die->HasChildren())
6899 {
6900 if (die->Tag() == DW_TAG_subprogram)
6901 {
6902 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006903 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006904 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6905 }
6906 else
6907 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6908 }
6909
6910 if (parse_siblings)
6911 die = die->GetSibling();
6912 else
6913 die = NULL;
6914 }
6915 return types_added;
6916}
6917
6918
6919size_t
6920SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6921{
6922 assert(sc.comp_unit && sc.function);
6923 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006924 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006925 if (dwarf_cu)
6926 {
6927 dw_offset_t function_die_offset = sc.function->GetID();
6928 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6929 if (function_die)
6930 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006931 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006932 }
6933 }
6934
6935 return functions_added;
6936}
6937
6938
6939size_t
6940SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6941{
6942 // At least a compile unit must be valid
6943 assert(sc.comp_unit);
6944 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006945 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006946 if (dwarf_cu)
6947 {
6948 if (sc.function)
6949 {
6950 dw_offset_t function_die_offset = sc.function->GetID();
6951 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6952 if (func_die && func_die->HasChildren())
6953 {
6954 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6955 }
6956 }
6957 else
6958 {
6959 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6960 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6961 {
6962 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6963 }
6964 }
6965 }
6966
6967 return types_added;
6968}
6969
6970size_t
6971SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6972{
6973 if (sc.comp_unit != NULL)
6974 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006975 DWARFDebugInfo* info = DebugInfo();
6976 if (info == NULL)
6977 return 0;
6978
6979 uint32_t cu_idx = UINT32_MAX;
6980 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006981
6982 if (dwarf_cu == NULL)
6983 return 0;
6984
6985 if (sc.function)
6986 {
6987 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006988
Greg Claytonc7bece562013-01-25 18:06:21 +00006989 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6990 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006991 {
6992 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006993
Greg Claytone38a5ed2012-01-05 03:57:59 +00006994 // Let all blocks know they have parse all their variables
6995 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6996 return num_variables;
6997 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006998 }
6999 else if (sc.comp_unit)
7000 {
7001 uint32_t vars_added = 0;
7002 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7003
7004 if (variables.get() == NULL)
7005 {
7006 variables.reset(new VariableList());
7007 sc.comp_unit->SetVariableList(variables);
7008
Greg Claytond4a2b372011-09-12 23:21:58 +00007009 DWARFCompileUnit* match_dwarf_cu = NULL;
7010 const DWARFDebugInfoEntry* die = NULL;
7011 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00007012 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00007013 {
Greg Clayton97fbc342011-10-20 22:30:33 +00007014 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00007015 {
7016 DWARFMappedHash::DIEInfoArray hash_data_array;
7017 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7018 dwarf_cu->GetNextCompileUnitOffset(),
7019 hash_data_array))
7020 {
7021 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7022 }
7023 }
Greg Clayton7f995132011-10-04 22:41:51 +00007024 }
7025 else
7026 {
7027 // Index if we already haven't to make sure the compile units
7028 // get indexed and make their global DIE index list
7029 if (!m_indexed)
7030 Index ();
7031
7032 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7033 dwarf_cu->GetNextCompileUnitOffset(),
7034 die_offsets);
7035 }
7036
7037 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00007038 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007039 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007040 DWARFDebugInfo* debug_info = DebugInfo();
7041 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007042 {
Greg Claytond4a2b372011-09-12 23:21:58 +00007043 const dw_offset_t die_offset = die_offsets[i];
7044 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00007045 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00007046 {
Greg Clayton95d87902011-11-11 03:16:25 +00007047 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7048 if (var_sp)
7049 {
7050 variables->AddVariableIfUnique (var_sp);
7051 ++vars_added;
7052 }
Greg Claytond4a2b372011-09-12 23:21:58 +00007053 }
Greg Clayton95d87902011-11-11 03:16:25 +00007054 else
7055 {
7056 if (m_using_apple_tables)
7057 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007058 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 +00007059 }
7060 }
7061
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007062 }
7063 }
7064 }
7065 return vars_added;
7066 }
7067 }
7068 return 0;
7069}
7070
7071
7072VariableSP
7073SymbolFileDWARF::ParseVariableDIE
7074(
7075 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007076 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007077 const DWARFDebugInfoEntry *die,
7078 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007079)
7080{
7081
Greg Clayton83c5cd92010-11-14 22:13:40 +00007082 VariableSP var_sp (m_die_to_variable_sp[die]);
7083 if (var_sp)
7084 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085
7086 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00007087
7088 if ((tag == DW_TAG_variable) ||
7089 (tag == DW_TAG_constant) ||
7090 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007091 {
Greg Clayton7f995132011-10-04 22:41:51 +00007092 DWARFDebugInfoEntry::Attributes attributes;
7093 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7094 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007095 {
Greg Clayton7f995132011-10-04 22:41:51 +00007096 const char *name = NULL;
7097 const char *mangled = NULL;
7098 Declaration decl;
7099 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007100 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007101 DWARFExpression location;
7102 bool is_external = false;
7103 bool is_artificial = false;
7104 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007105 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007106 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007107
7108 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007109 {
Greg Clayton7f995132011-10-04 22:41:51 +00007110 dw_attr_t attr = attributes.AttributeAtIndex(i);
7111 DWARFFormValue form_value;
7112 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007113 {
Greg Clayton7f995132011-10-04 22:41:51 +00007114 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007115 {
Greg Clayton7f995132011-10-04 22:41:51 +00007116 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7117 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7118 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7119 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007120 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007121 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007122 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007123 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
7124 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007125 // If we have already found a DW_AT_location attribute, ignore this attribute.
7126 if (!has_explicit_location)
7127 {
7128 location_is_const_value_data = true;
7129 // The constant value will be either a block, a data value or a string.
7130 const DataExtractor& debug_info_data = get_debug_info_data();
7131 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7132 {
7133 // Retrieve the value as a block expression.
7134 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7135 uint32_t block_length = form_value.Unsigned();
7136 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7137 }
7138 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7139 {
7140 // Retrieve the value as a data expression.
7141 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7142 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7143 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7144 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7145 }
7146 else
7147 {
7148 // Retrieve the value as a string expression.
7149 if (form_value.Form() == DW_FORM_strp)
7150 {
7151 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7152 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7153 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7154 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7155 }
7156 else
7157 {
7158 const char *str = form_value.AsCString(&debug_info_data);
7159 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7160 uint32_t string_length = strlen(str) + 1;
7161 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7162 }
7163 }
7164 }
7165 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007166 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007167 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007168 location_is_const_value_data = false;
7169 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007170 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007171 {
Greg Clayton7f995132011-10-04 22:41:51 +00007172 const DataExtractor& debug_info_data = get_debug_info_data();
7173
7174 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7175 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007176 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007177 }
7178 else
7179 {
7180 const DataExtractor& debug_loc_data = get_debug_loc_data();
7181 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7182
7183 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7184 if (loc_list_length > 0)
7185 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007186 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007187 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7188 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7189 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007190 }
7191 }
Greg Clayton7f995132011-10-04 22:41:51 +00007192 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007193
Greg Clayton7f995132011-10-04 22:41:51 +00007194 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00007195 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007196 case DW_AT_declaration:
7197 case DW_AT_description:
7198 case DW_AT_endianity:
7199 case DW_AT_segment:
7200 case DW_AT_start_scope:
7201 case DW_AT_visibility:
7202 default:
7203 case DW_AT_abstract_origin:
7204 case DW_AT_sibling:
7205 case DW_AT_specification:
7206 break;
7207 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007208 }
7209 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007210
Greg Clayton7f995132011-10-04 22:41:51 +00007211 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007212 {
Greg Clayton7f995132011-10-04 22:41:51 +00007213 ValueType scope = eValueTypeInvalid;
7214
7215 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7216 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007217 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007218
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007219 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7220 // or static variable, so we have to do a little digging by
7221 // looking at the location of a varaible to see if it contains
7222 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7223 // somewhere because clang likes to combine small global variables
7224 // into the same symbol and have locations like:
7225 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7226 // So if we don't have a DW_TAG_formal_parameter, we can look at
7227 // the location to see if it contains a DW_OP_addr opcode, and
7228 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007229 if (tag == DW_TAG_formal_parameter)
7230 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007231 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007232 {
Greg Clayton96c09682012-01-04 22:56:43 +00007233 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007234 // Check if the location has a DW_OP_addr with any address value...
7235 addr_t location_has_op_addr = false;
7236 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007237 {
7238 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
7239 if (op_error)
7240 {
7241 StreamString strm;
7242 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007243 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 +00007244 }
7245 }
Greg Claytond1767f02011-12-08 02:13:16 +00007246
7247 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007248 {
Greg Claytond1767f02011-12-08 02:13:16 +00007249 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007250 {
Greg Claytond1767f02011-12-08 02:13:16 +00007251 scope = eValueTypeVariableGlobal;
7252
Greg Clayton1f746072012-08-29 21:13:06 +00007253 if (GetDebugMapSymfile ())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007254 {
Greg Claytond1767f02011-12-08 02:13:16 +00007255 // When leaving the DWARF in the .o files on darwin,
7256 // when we have a global variable that wasn't initialized,
7257 // the .o file might not have allocated a virtual
7258 // address for the global variable. In this case it will
7259 // have created a symbol for the global variable
Greg Claytonf5fc0842013-02-01 22:08:49 +00007260 // that is undefined/data and external and the value will
Greg Claytond1767f02011-12-08 02:13:16 +00007261 // be the byte size of the variable. When we do the
7262 // address map in SymbolFileDWARFDebugMap we rely on
7263 // having an address, we need to do some magic here
7264 // so we can get the correct address for our global
7265 // variable. The address for all of these entries
7266 // will be zero, and there will be an undefined symbol
7267 // in this object file, and the executable will have
7268 // a matching symbol with a good address. So here we
7269 // dig up the correct address and replace it in the
7270 // location for the variable, and set the variable's
7271 // symbol context scope to be that of the main executable
7272 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00007273 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007274 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007275
Greg Claytond1767f02011-12-08 02:13:16 +00007276 // we have a possible uninitialized extern global
7277 Symtab *symtab = m_obj_file->GetSymtab();
7278 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007279 {
Greg Claytonf5fc0842013-02-01 22:08:49 +00007280 ConstString const_name(mangled ? mangled : name);
7281 Symbol *o_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
7282 eSymbolTypeAny,
7283 Symtab::eDebugNo,
7284 Symtab::eVisibilityExtern);
Greg Claytond1767f02011-12-08 02:13:16 +00007285
Greg Claytonf5fc0842013-02-01 22:08:49 +00007286 if (o_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007287 {
Greg Claytond1767f02011-12-08 02:13:16 +00007288 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
7289 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007290 {
Greg Claytond1767f02011-12-08 02:13:16 +00007291 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7292 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7293 eSymbolTypeData,
7294 Symtab::eDebugYes,
7295 Symtab::eVisibilityExtern);
7296 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007297 {
Greg Claytone7612132012-03-07 21:03:09 +00007298 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007299 {
Greg Claytone7612132012-03-07 21:03:09 +00007300 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00007301 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007302 {
Greg Claytond1767f02011-12-08 02:13:16 +00007303 if (location.Update_DW_OP_addr (defined_addr))
7304 {
7305 symbol_context_scope = defined_symbol;
7306 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007307 }
7308 }
7309 }
7310 }
7311 }
7312 }
7313 }
7314 }
7315 }
Greg Claytond1767f02011-12-08 02:13:16 +00007316 else
7317 {
7318 scope = eValueTypeVariableStatic;
7319 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007320 }
7321 else
Greg Claytond1767f02011-12-08 02:13:16 +00007322 {
7323 scope = eValueTypeVariableLocal;
7324 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007325 }
Greg Clayton7f995132011-10-04 22:41:51 +00007326
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007327 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007328 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007329 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007330 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007331 case DW_TAG_subprogram:
7332 case DW_TAG_inlined_subroutine:
7333 case DW_TAG_lexical_block:
7334 if (sc.function)
7335 {
7336 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7337 if (symbol_context_scope == NULL)
7338 symbol_context_scope = sc.function;
7339 }
7340 break;
7341
7342 default:
7343 symbol_context_scope = sc.comp_unit;
7344 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007345 }
Greg Clayton7f995132011-10-04 22:41:51 +00007346 }
7347
Greg Clayton5cf58b92011-10-05 22:22:08 +00007348 if (symbol_context_scope)
7349 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007350 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7351 name,
7352 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007353 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007354 scope,
7355 symbol_context_scope,
7356 &decl,
7357 location,
7358 is_external,
7359 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007360
7361 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7362 }
7363 else
7364 {
7365 // Not ready to parse this variable yet. It might be a global
7366 // or static variable that is in a function scope and the function
7367 // in the symbol context wasn't filled in yet
7368 return var_sp;
7369 }
Greg Clayton7f995132011-10-04 22:41:51 +00007370 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007371 }
Greg Clayton7f995132011-10-04 22:41:51 +00007372 // Cache var_sp even if NULL (the variable was just a specification or
7373 // was missing vital information to be able to be displayed in the debugger
7374 // (missing location due to optimization, etc)) so we don't re-parse
7375 // this DIE over and over later...
7376 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007377 }
7378 return var_sp;
7379}
7380
Greg Claytonc662ec82011-06-17 22:10:16 +00007381
7382const DWARFDebugInfoEntry *
7383SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7384 dw_offset_t spec_block_die_offset,
7385 DWARFCompileUnit **result_die_cu_handle)
7386{
7387 // Give the concrete function die specified by "func_die_offset", find the
7388 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7389 // to "spec_block_die_offset"
7390 DWARFDebugInfo* info = DebugInfo();
7391
7392 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7393 if (die)
7394 {
7395 assert (*result_die_cu_handle);
7396 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7397 }
7398 return NULL;
7399}
7400
7401
7402const DWARFDebugInfoEntry *
7403SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7404 const DWARFDebugInfoEntry *die,
7405 dw_offset_t spec_block_die_offset,
7406 DWARFCompileUnit **result_die_cu_handle)
7407{
7408 if (die)
7409 {
7410 switch (die->Tag())
7411 {
7412 case DW_TAG_subprogram:
7413 case DW_TAG_inlined_subroutine:
7414 case DW_TAG_lexical_block:
7415 {
7416 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7417 {
7418 *result_die_cu_handle = dwarf_cu;
7419 return die;
7420 }
7421
7422 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7423 {
7424 *result_die_cu_handle = dwarf_cu;
7425 return die;
7426 }
7427 }
7428 break;
7429 }
7430
7431 // Give the concrete function die specified by "func_die_offset", find the
7432 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7433 // to "spec_block_die_offset"
7434 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7435 {
7436 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7437 child_die,
7438 spec_block_die_offset,
7439 result_die_cu_handle);
7440 if (result_die)
7441 return result_die;
7442 }
7443 }
7444
7445 *result_die_cu_handle = NULL;
7446 return NULL;
7447}
7448
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007449size_t
7450SymbolFileDWARF::ParseVariables
7451(
7452 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007453 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007454 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007455 const DWARFDebugInfoEntry *orig_die,
7456 bool parse_siblings,
7457 bool parse_children,
7458 VariableList* cc_variable_list
7459)
7460{
7461 if (orig_die == NULL)
7462 return 0;
7463
Greg Claytonc662ec82011-06-17 22:10:16 +00007464 VariableListSP variable_list_sp;
7465
7466 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007467 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007468 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007469 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007470 dw_tag_t tag = die->Tag();
7471
7472 // Check to see if we have already parsed this variable or constant?
7473 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007474 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007475 if (cc_variable_list)
7476 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007477 }
7478 else
7479 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007480 // We haven't already parsed it, lets do that now.
7481 if ((tag == DW_TAG_variable) ||
7482 (tag == DW_TAG_constant) ||
7483 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007484 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007485 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007486 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007487 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7488 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7489 switch (parent_tag)
7490 {
7491 case DW_TAG_compile_unit:
7492 if (sc.comp_unit != NULL)
7493 {
7494 variable_list_sp = sc.comp_unit->GetVariableList(false);
7495 if (variable_list_sp.get() == NULL)
7496 {
7497 variable_list_sp.reset(new VariableList());
7498 sc.comp_unit->SetVariableList(variable_list_sp);
7499 }
7500 }
7501 else
7502 {
Daniel Malead01b2952012-11-29 21:49:15 +00007503 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 +00007504 MakeUserID(sc_parent_die->GetOffset()),
7505 DW_TAG_value_to_name (parent_tag),
7506 MakeUserID(orig_die->GetOffset()),
7507 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007508 }
7509 break;
7510
7511 case DW_TAG_subprogram:
7512 case DW_TAG_inlined_subroutine:
7513 case DW_TAG_lexical_block:
7514 if (sc.function != NULL)
7515 {
7516 // Check to see if we already have parsed the variables for the given scope
7517
Greg Clayton81c22f62011-10-19 18:09:39 +00007518 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007519 if (block == NULL)
7520 {
7521 // This must be a specification or abstract origin with
7522 // a concrete block couterpart in the current function. We need
7523 // to find the concrete block so we can correctly add the
7524 // variable to it
7525 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7526 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7527 sc_parent_die->GetOffset(),
7528 &concrete_block_die_cu);
7529 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007530 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007531 }
7532
7533 if (block != NULL)
7534 {
7535 const bool can_create = false;
7536 variable_list_sp = block->GetBlockVariableList (can_create);
7537 if (variable_list_sp.get() == NULL)
7538 {
7539 variable_list_sp.reset(new VariableList());
7540 block->SetVariableList(variable_list_sp);
7541 }
7542 }
7543 }
7544 break;
7545
7546 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007547 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 +00007548 MakeUserID(orig_die->GetOffset()),
7549 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007550 break;
7551 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007552 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007553
7554 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007555 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007556 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7557 if (var_sp)
7558 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007559 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007560 if (cc_variable_list)
7561 cc_variable_list->AddVariableIfUnique (var_sp);
7562 ++vars_added;
7563 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007564 }
7565 }
7566 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007567
7568 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7569
7570 if (!skip_children && parse_children && die->HasChildren())
7571 {
7572 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7573 }
7574
7575 if (parse_siblings)
7576 die = die->GetSibling();
7577 else
7578 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007579 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007580 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007581}
7582
7583//------------------------------------------------------------------
7584// PluginInterface protocol
7585//------------------------------------------------------------------
7586const char *
7587SymbolFileDWARF::GetPluginName()
7588{
7589 return "SymbolFileDWARF";
7590}
7591
7592const char *
7593SymbolFileDWARF::GetShortPluginName()
7594{
7595 return GetPluginNameStatic();
7596}
7597
7598uint32_t
7599SymbolFileDWARF::GetPluginVersion()
7600{
7601 return 1;
7602}
7603
7604void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007605SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7606{
7607 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7608 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7609 if (clang_type)
7610 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7611}
7612
7613void
7614SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7615{
7616 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7617 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7618 if (clang_type)
7619 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7620}
7621
Greg Claytona2721472011-06-25 00:44:06 +00007622void
Sean Callanancc427fa2011-07-30 02:42:06 +00007623SymbolFileDWARF::DumpIndexes ()
7624{
7625 StreamFile s(stdout, false);
7626
7627 s.Printf ("DWARF index for (%s) '%s/%s':",
7628 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7629 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7630 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7631 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7632 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7633 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7634 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7635 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7636 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7637 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7638 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7639}
7640
7641void
7642SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7643 const char *name,
7644 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007645{
Sean Callanancc427fa2011-07-30 02:42:06 +00007646 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007647
7648 if (iter == m_decl_ctx_to_die.end())
7649 return;
7650
Greg Claytoncb5860a2011-10-13 23:49:28 +00007651 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007652 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007653 const DWARFDebugInfoEntry *context_die = *pos;
7654
7655 if (!results)
7656 return;
7657
7658 DWARFDebugInfo* info = DebugInfo();
7659
7660 DIEArray die_offsets;
7661
7662 DWARFCompileUnit* dwarf_cu = NULL;
7663 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007664
7665 if (m_using_apple_tables)
7666 {
7667 if (m_apple_types_ap.get())
7668 m_apple_types_ap->FindByName (name, die_offsets);
7669 }
7670 else
7671 {
7672 if (!m_indexed)
7673 Index ();
7674
7675 m_type_index.Find (ConstString(name), die_offsets);
7676 }
7677
Greg Clayton220a0072011-12-09 08:48:30 +00007678 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007679
7680 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007681 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007682 for (size_t i = 0; i < num_matches; ++i)
7683 {
7684 const dw_offset_t die_offset = die_offsets[i];
7685 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007686
Greg Claytoncb5860a2011-10-13 23:49:28 +00007687 if (die->GetParent() != context_die)
7688 continue;
7689
7690 Type *matching_type = ResolveType (dwarf_cu, die);
7691
Greg Clayton42ce2f32011-12-12 21:50:19 +00007692 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007693 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7694
7695 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7696 {
7697 clang::TagDecl *tag_decl = tag_type->getDecl();
7698 results->push_back(tag_decl);
7699 }
7700 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7701 {
7702 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7703 results->push_back(typedef_decl);
7704 }
Greg Claytona2721472011-06-25 00:44:06 +00007705 }
7706 }
7707 }
7708}
7709
7710void
7711SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007712 const clang::DeclContext *decl_context,
7713 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007714 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7715{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007716
7717 switch (decl_context->getDeclKind())
7718 {
7719 case clang::Decl::Namespace:
7720 case clang::Decl::TranslationUnit:
7721 {
7722 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7723 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7724 }
7725 break;
7726 default:
7727 break;
7728 }
Greg Claytona2721472011-06-25 00:44:06 +00007729}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007730
7731bool
7732SymbolFileDWARF::LayoutRecordType (void *baton,
7733 const clang::RecordDecl *record_decl,
7734 uint64_t &size,
7735 uint64_t &alignment,
7736 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7737 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7738 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7739{
7740 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7741 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7742}
7743
7744
7745bool
7746SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7747 uint64_t &bit_size,
7748 uint64_t &alignment,
7749 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7750 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7751 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7752{
7753 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7754 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7755 bool success = false;
7756 base_offsets.clear();
7757 vbase_offsets.clear();
7758 if (pos != m_record_decl_to_layout_map.end())
7759 {
7760 bit_size = pos->second.bit_size;
7761 alignment = pos->second.alignment;
7762 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007763 base_offsets.swap (pos->second.base_offsets);
7764 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007765 m_record_decl_to_layout_map.erase(pos);
7766 success = true;
7767 }
7768 else
7769 {
7770 bit_size = 0;
7771 alignment = 0;
7772 field_offsets.clear();
7773 }
7774
7775 if (log)
7776 GetObjectFile()->GetModule()->LogMessage (log.get(),
Daniel Malead01b2952012-11-29 21:49:15 +00007777 "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 +00007778 record_decl,
7779 bit_size,
7780 alignment,
7781 (uint32_t)field_offsets.size(),
7782 (uint32_t)base_offsets.size(),
7783 (uint32_t)vbase_offsets.size(),
7784 success);
7785 return success;
7786}
7787
7788
Greg Clayton1f746072012-08-29 21:13:06 +00007789SymbolFileDWARFDebugMap *
7790SymbolFileDWARF::GetDebugMapSymfile ()
7791{
7792 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7793 {
7794 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7795 if (module_sp)
7796 {
7797 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7798 if (sym_vendor)
7799 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7800 }
7801 }
7802 return m_debug_map_symfile;
7803}
7804
Greg Claytoncaab74e2012-01-28 00:48:57 +00007805