blob: 35cd1296a4a4e8abe63fa56310b4ec95e2454757 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/Module.h"
30#include "lldb/Core/PluginManager.h"
31#include "lldb/Core/RegularExpression.h"
32#include "lldb/Core/Scalar.h"
33#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000034#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000035#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Core/Timer.h"
37#include "lldb/Core/Value.h"
38
Greg Clayton20568dd2011-10-13 23:13:20 +000039#include "lldb/Host/Host.h"
40
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000042#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/CompileUnit.h"
44#include "lldb/Symbol/LineTable.h"
45#include "lldb/Symbol/ObjectFile.h"
46#include "lldb/Symbol/SymbolVendor.h"
47#include "lldb/Symbol/VariableList.h"
48
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000050#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000051
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "DWARFCompileUnit.h"
53#include "DWARFDebugAbbrev.h"
54#include "DWARFDebugAranges.h"
55#include "DWARFDebugInfo.h"
56#include "DWARFDebugInfoEntry.h"
57#include "DWARFDebugLine.h"
58#include "DWARFDebugPubnames.h"
59#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000060#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "DWARFDIECollection.h"
62#include "DWARFFormValue.h"
63#include "DWARFLocationList.h"
64#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000065#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67#include <map>
68
Greg Clayton62742b12010-11-11 01:09:45 +000069//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000070
71#ifdef ENABLE_DEBUG_PRINTF
72#include <stdio.h>
73#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
74#else
75#define DEBUG_PRINTF(fmt, ...)
76#endif
77
Greg Clayton594e5ed2010-09-27 21:07:38 +000078#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079
80using namespace lldb;
81using namespace lldb_private;
82
Greg Clayton219cf312012-03-30 00:51:13 +000083//static inline bool
84//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
85//{
86// switch (tag)
87// {
88// default:
89// break;
90// case DW_TAG_subprogram:
91// case DW_TAG_inlined_subroutine:
92// case DW_TAG_class_type:
93// case DW_TAG_structure_type:
94// case DW_TAG_union_type:
95// return true;
96// }
97// return false;
98//}
99//
Sean Callananc7fbf732010-08-06 00:32:49 +0000100static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000101DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102{
103 switch (dwarf_accessibility)
104 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000108 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000110 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
Greg Clayton1fba87112012-02-09 20:03:49 +0000113#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
114
115class DIEStack
116{
117public:
118
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
120 {
121 m_dies.push_back (DIEInfo(cu, die));
122 }
123
124
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
126 {
127 StreamString log_strm;
128 const size_t n = m_dies.size();
Daniel Malead01b2952012-11-29 21:49:15 +0000129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
Greg Clayton1fba87112012-02-09 20:03:49 +0000130 for (size_t i=0; i<n; i++)
131 {
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
Daniel Malead01b2952012-11-29 21:49:15 +0000136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
Greg Clayton43e0af02012-09-18 18:04:04 +0000137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
Greg Clayton1f746072012-08-29 21:13:06 +0000232 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000266 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000267 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000268 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 m_data_debug_abbrev (),
271 m_data_debug_aranges (),
272 m_data_debug_frame (),
273 m_data_debug_info (),
274 m_data_debug_line (),
275 m_data_debug_loc (),
276 m_data_debug_ranges (),
277 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000278 m_data_apple_names (),
279 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000280 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_info(),
283 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000284 m_apple_names_ap (),
285 m_apple_types_ap (),
286 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000287 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000288 m_function_basename_index(),
289 m_function_fullname_index(),
290 m_function_method_index(),
291 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000292 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000293 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000294 m_type_index(),
295 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000296 m_indexed (false),
297 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000298 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000299 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000300 m_ranges(),
301 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
303}
304
305SymbolFileDWARF::~SymbolFileDWARF()
306{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000307 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000308 {
309 ModuleSP module_sp (m_obj_file->GetModule());
310 if (module_sp)
311 module_sp->GetClangASTContext().RemoveExternalSource ();
312 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000313}
314
315static const ConstString &
316GetDWARFMachOSegmentName ()
317{
318 static ConstString g_dwarf_section_name ("__DWARF");
319 return g_dwarf_section_name;
320}
321
Greg Claytone576ab22011-02-15 00:19:15 +0000322UniqueDWARFASTTypeMap &
323SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
324{
Greg Clayton1f746072012-08-29 21:13:06 +0000325 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000326 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
327 return m_unique_ast_type_map;
328}
329
Greg Clayton6beaaa62011-01-17 03:46:26 +0000330ClangASTContext &
331SymbolFileDWARF::GetClangASTContext ()
332{
Greg Clayton1f746072012-08-29 21:13:06 +0000333 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000334 return m_debug_map_symfile->GetClangASTContext ();
335
336 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
337 if (!m_is_external_ast_source)
338 {
339 m_is_external_ast_source = true;
340 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
341 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
342 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000343 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000344 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 ast.SetExternalSource (ast_source_ap);
347 }
348 return ast;
349}
350
351void
352SymbolFileDWARF::InitializeObject()
353{
354 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000355 ModuleSP module_sp (m_obj_file->GetModule());
356 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000357 {
358 const SectionList *section_list = m_obj_file->GetSectionList();
359
360 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
361
362 // Memory map the DWARF mach-o segment so we have everything mmap'ed
363 // to keep our heap memory usage down.
364 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000365 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000366 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000367 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000368 if (m_data_apple_names.GetByteSize() > 0)
369 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000370 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
371 if (m_apple_names_ap->IsValid())
372 m_using_apple_tables = true;
373 else
Greg Clayton7f995132011-10-04 22:41:51 +0000374 m_apple_names_ap.reset();
375 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000376 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000377 if (m_data_apple_types.GetByteSize() > 0)
378 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000379 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
380 if (m_apple_types_ap->IsValid())
381 m_using_apple_tables = true;
382 else
Greg Clayton7f995132011-10-04 22:41:51 +0000383 m_apple_types_ap.reset();
384 }
385
386 get_apple_namespaces_data();
387 if (m_data_apple_namespaces.GetByteSize() > 0)
388 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000389 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
390 if (m_apple_namespaces_ap->IsValid())
391 m_using_apple_tables = true;
392 else
Greg Clayton7f995132011-10-04 22:41:51 +0000393 m_apple_namespaces_ap.reset();
394 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000395
Greg Clayton5009f9d2011-10-27 17:55:14 +0000396 get_apple_objc_data();
397 if (m_data_apple_objc.GetByteSize() > 0)
398 {
399 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
400 if (m_apple_objc_ap->IsValid())
401 m_using_apple_tables = true;
402 else
403 m_apple_objc_ap.reset();
404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407bool
408SymbolFileDWARF::SupportedVersion(uint16_t version)
409{
410 return version == 2 || version == 3;
411}
412
413uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000414SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
416 uint32_t abilities = 0;
417 if (m_obj_file != NULL)
418 {
419 const Section* section = NULL;
420 const SectionList *section_list = m_obj_file->GetSectionList();
421 if (section_list == NULL)
422 return 0;
423
424 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
430 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
Greg Clayton4ceb9982010-07-21 22:54:26 +0000433 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 if (section != NULL)
435 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000436 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000440 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 else
442 m_flags.Set (flagsGotDebugAbbrevData);
443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000445 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_flags.Set (flagsGotDebugArangesData);
447
Greg Clayton4ceb9982010-07-21 22:54:26 +0000448 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000449 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_flags.Set (flagsGotDebugFrameData);
451
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000454 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 else
456 m_flags.Set (flagsGotDebugLineData);
457
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000459 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 m_flags.Set (flagsGotDebugLocData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000463 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_flags.Set (flagsGotDebugMacInfoData);
465
Greg Clayton4ceb9982010-07-21 22:54:26 +0000466 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000467 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 m_flags.Set (flagsGotDebugPubNamesData);
469
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000471 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 m_flags.Set (flagsGotDebugPubTypesData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000475 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_flags.Set (flagsGotDebugRangesData);
477
Greg Clayton4ceb9982010-07-21 22:54:26 +0000478 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000479 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 m_flags.Set (flagsGotDebugStrData);
481 }
Greg Clayton6c596612012-05-18 21:47:20 +0000482 else
483 {
484 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
485 if (symfile_dir_cstr)
486 {
487 if (strcasestr(symfile_dir_cstr, ".dsym"))
488 {
489 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
490 {
491 // We have a dSYM file that didn't have a any debug info.
492 // If the string table has a size of 1, then it was made from
493 // an executable with no debug info, or from an executable that
494 // was stripped.
495 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
496 if (section && section->GetFileSize() == 1)
497 {
498 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
499 }
500 }
501 }
502 }
503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 return abilities;
512}
513
514const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000515SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
517 if (m_flags.IsClear (got_flag))
518 {
519 m_flags.Set (got_flag);
520 const SectionList *section_list = m_obj_file->GetSectionList();
521 if (section_list)
522 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000523 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
524 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 {
526 // See if we memory mapped the DWARF segment?
527 if (m_dwarf_data.GetByteSize())
528 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000529 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531 else
532 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 data.Clear();
535 }
536 }
537 }
538 }
539 return data;
540}
541
542const DataExtractor&
543SymbolFileDWARF::get_debug_abbrev_data()
544{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000545 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000549SymbolFileDWARF::get_debug_aranges_data()
550{
551 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
552}
553
554const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555SymbolFileDWARF::get_debug_frame_data()
556{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000557 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560const DataExtractor&
561SymbolFileDWARF::get_debug_info_data()
562{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000563 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566const DataExtractor&
567SymbolFileDWARF::get_debug_line_data()
568{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000569 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570}
571
572const DataExtractor&
573SymbolFileDWARF::get_debug_loc_data()
574{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000575 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576}
577
578const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SymbolFileDWARF::get_debug_ranges_data()
580{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000581 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582}
583
584const DataExtractor&
585SymbolFileDWARF::get_debug_str_data()
586{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000587 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Greg Claytonf9eec202011-09-01 23:16:13 +0000590const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000591SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000592{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000593 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000594}
595
596const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000597SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000598{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000599 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000600}
601
Greg Clayton7f995132011-10-04 22:41:51 +0000602const DataExtractor&
603SymbolFileDWARF::get_apple_namespaces_data()
604{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000605 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
606}
607
608const DataExtractor&
609SymbolFileDWARF::get_apple_objc_data()
610{
611 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000612}
613
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615DWARFDebugAbbrev*
616SymbolFileDWARF::DebugAbbrev()
617{
618 if (m_abbr.get() == NULL)
619 {
620 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
621 if (debug_abbrev_data.GetByteSize() > 0)
622 {
623 m_abbr.reset(new DWARFDebugAbbrev());
624 if (m_abbr.get())
625 m_abbr->Parse(debug_abbrev_data);
626 }
627 }
628 return m_abbr.get();
629}
630
631const DWARFDebugAbbrev*
632SymbolFileDWARF::DebugAbbrev() const
633{
634 return m_abbr.get();
635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugInfo*
639SymbolFileDWARF::DebugInfo()
640{
641 if (m_info.get() == NULL)
642 {
643 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
644 if (get_debug_info_data().GetByteSize() > 0)
645 {
646 m_info.reset(new DWARFDebugInfo());
647 if (m_info.get())
648 {
649 m_info->SetDwarfData(this);
650 }
651 }
652 }
653 return m_info.get();
654}
655
656const DWARFDebugInfo*
657SymbolFileDWARF::DebugInfo() const
658{
659 return m_info.get();
660}
661
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000663SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000666 if (info)
667 {
668 if (GetDebugMapSymfile ())
669 {
670 // The debug map symbol file made the compile units for this DWARF
671 // file which is .o file with DWARF in it, and we should have
672 // only 1 compile unit which is at offset zero in the DWARF.
673 // TODO: modify to support LTO .o files where each .o file might
674 // have multiple DW_TAG_compile_unit tags.
675 return info->GetCompileUnit(0).get();
676 }
677 else
678 {
679 // Just a normal DWARF file whose user ID for the compile unit is
680 // the DWARF offset itself
681 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
682 }
683 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 return NULL;
685}
686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
688DWARFDebugRanges*
689SymbolFileDWARF::DebugRanges()
690{
691 if (m_ranges.get() == NULL)
692 {
693 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
694 if (get_debug_ranges_data().GetByteSize() > 0)
695 {
696 m_ranges.reset(new DWARFDebugRanges());
697 if (m_ranges.get())
698 m_ranges->Extract(this);
699 }
700 }
701 return m_ranges.get();
702}
703
704const DWARFDebugRanges*
705SymbolFileDWARF::DebugRanges() const
706{
707 return m_ranges.get();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710lldb::CompUnitSP
711SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000713 CompUnitSP cu_sp;
714 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000716 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
717 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000719 // We already parsed this compile unit, had out a shared pointer to it
720 cu_sp = comp_unit->shared_from_this();
721 }
722 else
723 {
Greg Clayton1f746072012-08-29 21:13:06 +0000724 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton1f746072012-08-29 21:13:06 +0000726 // Let the debug map create the compile unit
727 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
728 dwarf_cu->SetUserData(cu_sp.get());
729 }
730 else
731 {
732 ModuleSP module_sp (m_obj_file->GetModule());
733 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 {
Greg Clayton1f746072012-08-29 21:13:06 +0000735 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
736 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 {
Greg Clayton1f746072012-08-29 21:13:06 +0000738 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
739 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
740 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
741 if (cu_die_name)
742 {
743 std::string ramapped_file;
744 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000745
Greg Clayton1f746072012-08-29 21:13:06 +0000746 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000747 {
Greg Clayton1f746072012-08-29 21:13:06 +0000748 // If we have a full path to the compile unit, we don't need to resolve
749 // the file. This can be expensive e.g. when the source files are NFS mounted.
750 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
751 cu_file_spec.SetFile (ramapped_file.c_str(), false);
752 else
753 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000754 }
755 else
756 {
Greg Clayton1f746072012-08-29 21:13:06 +0000757 std::string fullpath(cu_comp_dir);
758 if (*fullpath.rbegin() != '/')
759 fullpath += '/';
760 fullpath += cu_die_name;
761 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
762 cu_file_spec.SetFile (ramapped_file.c_str(), false);
763 else
764 cu_file_spec.SetFile (fullpath.c_str(), false);
765 }
766
767 cu_sp.reset(new CompileUnit (module_sp,
768 dwarf_cu,
769 cu_file_spec,
770 MakeUserID(dwarf_cu->GetOffset()),
771 cu_language));
772 if (cu_sp)
773 {
774 dwarf_cu->SetUserData(cu_sp.get());
775
Greg Clayton53eb1c22012-04-02 22:59:12 +0000776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000878 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000880 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
Greg Clayton9422dd62013-03-04 21:46:16 +0000894 if (FixupAddress (func_range.GetBaseAddress()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
897 func_sp.reset(new Function (sc.comp_unit,
898 MakeUserID(func_user_id), // UserID is the DIE offset
899 MakeUserID(func_user_id),
900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
913 }
914 return NULL;
915}
916
Greg Clayton9422dd62013-03-04 21:46:16 +0000917bool
918SymbolFileDWARF::FixupAddress (Address &addr)
919{
920 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
921 if (debug_map_symfile)
922 {
923 return debug_map_symfile->LinkOSOAddress(addr);
924 }
925 // This is a normal DWARF file, no address fixups need to happen
926 return true;
927}
Greg Clayton1f746072012-08-29 21:13:06 +0000928lldb::LanguageType
929SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
930{
931 assert (sc.comp_unit);
932 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
933 if (dwarf_cu)
934 {
935 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000936 if (die)
937 {
938 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
939 if (language)
940 return (lldb::LanguageType)language;
941 }
Greg Clayton1f746072012-08-29 21:13:06 +0000942 }
943 return eLanguageTypeUnknown;
944}
945
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946size_t
947SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
948{
949 assert (sc.comp_unit);
950 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000951 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000952 if (dwarf_cu)
953 {
954 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000955 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000957 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958 {
959 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000960 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 {
962 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
963 ++functions_added;
964 }
965 }
966 //FixupTypes();
967 }
968 return functions_added;
969}
970
971bool
972SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
973{
974 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000975 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000976 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000978 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979
Greg Claytonda2455b2012-11-01 17:28:37 +0000980 if (cu_die)
981 {
982 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
983 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000984
Greg Claytonda2455b2012-11-01 17:28:37 +0000985 // All file indexes in DWARF are one based and a file of index zero is
986 // supposed to be the compile unit itself.
987 support_files.Append (*sc.comp_unit);
988
989 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
990 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991 }
992 return false;
993}
994
995struct ParseDWARFLineTableCallbackInfo
996{
997 LineTable* line_table;
Greg Clayton9422dd62013-03-04 21:46:16 +0000998 std::auto_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999};
1000
1001//----------------------------------------------------------------------
1002// ParseStatementTableCallback
1003//----------------------------------------------------------------------
1004static void
1005ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1006{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1008 {
1009 // Just started parsing the line table
1010 }
1011 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1012 {
1013 // Done parsing line table, nothing to do for the cleanup
1014 }
1015 else
1016 {
1017 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001018 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019
Greg Clayton9422dd62013-03-04 21:46:16 +00001020 // If this is our first time here, we need to create a
1021 // sequence container.
1022 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001024 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1025 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001027 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1028 state.address,
1029 state.line,
1030 state.column,
1031 state.file,
1032 state.is_stmt,
1033 state.basic_block,
1034 state.prologue_end,
1035 state.epilogue_begin,
1036 state.end_sequence);
1037 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001039 // First, put the current sequence into the line table.
1040 line_table->InsertSequence(info->sequence_ap.get());
1041 // Then, empty it to prepare for the next sequence.
1042 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 }
1045}
1046
1047bool
1048SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1049{
1050 assert (sc.comp_unit);
1051 if (sc.comp_unit->GetLineTable() != NULL)
1052 return true;
1053
Greg Clayton1f746072012-08-29 21:13:06 +00001054 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055 if (dwarf_cu)
1056 {
1057 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001058 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001060 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1061 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001063 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1064 if (line_table_ap.get())
1065 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001066 ParseDWARFLineTableCallbackInfo info;
1067 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001068 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001069 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001070 if (m_debug_map_symfile)
1071 {
1072 // We have an object file that has a line table with addresses
1073 // that are not linked. We need to link the line table and convert
1074 // the addresses that are relative to the .o file into addresses
1075 // for the main executable.
1076 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1077 }
1078 else
1079 {
1080 sc.comp_unit->SetLineTable(line_table_ap.release());
1081 return true;
1082 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001083 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 }
1085 }
1086 }
1087 return false;
1088}
1089
1090size_t
1091SymbolFileDWARF::ParseFunctionBlocks
1092(
1093 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001094 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001095 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001096 const DWARFDebugInfoEntry *die,
1097 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001098 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099)
1100{
1101 size_t blocks_added = 0;
1102 while (die != NULL)
1103 {
1104 dw_tag_t tag = die->Tag();
1105
1106 switch (tag)
1107 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001109 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 case DW_TAG_lexical_block:
1111 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001112 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001113 if (tag == DW_TAG_subprogram)
1114 {
1115 // Skip any DW_TAG_subprogram DIEs that are inside
1116 // of a normal or inlined functions. These will be
1117 // parsed on their own as separate entities.
1118
1119 if (depth > 0)
1120 break;
1121
1122 block = parent_block;
1123 }
1124 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001125 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001126 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001127 parent_block->AddChild(block_sp);
1128 block = block_sp.get();
1129 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001130 DWARFDebugRanges::RangeList ranges;
1131 const char *name = NULL;
1132 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 int decl_file = 0;
1135 int decl_line = 0;
1136 int decl_column = 0;
1137 int call_file = 0;
1138 int call_line = 0;
1139 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001140 if (die->GetDIENamesAndRanges (this,
1141 dwarf_cu,
1142 name,
1143 mangled_name,
1144 ranges,
1145 decl_file, decl_line, decl_column,
1146 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 {
1148 if (tag == DW_TAG_subprogram)
1149 {
1150 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001151 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001153 else if (tag == DW_TAG_inlined_subroutine)
1154 {
1155 // We get called here for inlined subroutines in two ways.
1156 // The first time is when we are making the Function object
1157 // for this inlined concrete instance. Since we're creating a top level block at
1158 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1159 // adjust the containing address.
1160 // The second time is when we are parsing the blocks inside the function that contains
1161 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1162 // function the offset will be for that function.
1163 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1164 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001165 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001166 }
1167 }
1168
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001169 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170
1171 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1172 {
1173 std::auto_ptr<Declaration> decl_ap;
1174 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001175 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1176 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177
1178 std::auto_ptr<Declaration> call_ap;
1179 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001180 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1181 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001183 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 }
1185
1186 ++blocks_added;
1187
Greg Claytondd7feaf2011-08-12 17:54:33 +00001188 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001190 blocks_added += ParseFunctionBlocks (sc,
1191 block,
1192 dwarf_cu,
1193 die->GetFirstChild(),
1194 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001195 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 }
1197 }
1198 }
1199 break;
1200 default:
1201 break;
1202 }
1203
Greg Claytondd7feaf2011-08-12 17:54:33 +00001204 // Only parse siblings of the block if we are not at depth zero. A depth
1205 // of zero indicates we are currently parsing the top level
1206 // DW_TAG_subprogram DIE
1207
1208 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001210 else
1211 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 return blocks_added;
1214}
1215
Greg Claytonf0705c82011-10-22 03:33:13 +00001216bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001217SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1218 const DWARFDebugInfoEntry *die,
1219 ClangASTContext::TemplateParameterInfos &template_param_infos)
1220{
1221 const dw_tag_t tag = die->Tag();
1222
1223 switch (tag)
1224 {
1225 case DW_TAG_template_type_parameter:
1226 case DW_TAG_template_value_parameter:
1227 {
1228 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1229
1230 DWARFDebugInfoEntry::Attributes attributes;
1231 const size_t num_attributes = die->GetAttributes (this,
1232 dwarf_cu,
1233 fixed_form_sizes,
1234 attributes);
1235 const char *name = NULL;
1236 Type *lldb_type = NULL;
1237 clang_type_t clang_type = NULL;
1238 uint64_t uval64 = 0;
1239 bool uval64_valid = false;
1240 if (num_attributes > 0)
1241 {
1242 DWARFFormValue form_value;
1243 for (size_t i=0; i<num_attributes; ++i)
1244 {
1245 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1246
1247 switch (attr)
1248 {
1249 case DW_AT_name:
1250 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1251 name = form_value.AsCString(&get_debug_str_data());
1252 break;
1253
1254 case DW_AT_type:
1255 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1256 {
1257 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1258 lldb_type = ResolveTypeUID(type_die_offset);
1259 if (lldb_type)
1260 clang_type = lldb_type->GetClangForwardType();
1261 }
1262 break;
1263
1264 case DW_AT_const_value:
1265 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1266 {
1267 uval64_valid = true;
1268 uval64 = form_value.Unsigned();
1269 }
1270 break;
1271 default:
1272 break;
1273 }
1274 }
1275
1276 if (name && lldb_type && clang_type)
1277 {
1278 bool is_signed = false;
1279 template_param_infos.names.push_back(name);
1280 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1281 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1282 {
1283 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001284 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1285 llvm::APSInt(apint),
1286 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001287 }
1288 else
1289 {
1290 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1291 }
1292 }
1293 else
1294 {
1295 return false;
1296 }
1297
1298 }
1299 }
1300 return true;
1301
1302 default:
1303 break;
1304 }
1305 return false;
1306}
1307
1308bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001309SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1310 const DWARFDebugInfoEntry *parent_die,
1311 ClangASTContext::TemplateParameterInfos &template_param_infos)
1312{
1313
1314 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001315 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001316
Greg Claytonf0705c82011-10-22 03:33:13 +00001317 Args template_parameter_names;
1318 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1319 die != NULL;
1320 die = die->GetSibling())
1321 {
1322 const dw_tag_t tag = die->Tag();
1323
1324 switch (tag)
1325 {
1326 case DW_TAG_template_type_parameter:
1327 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001328 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001329 break;
1330
1331 default:
1332 break;
1333 }
1334 }
1335 if (template_param_infos.args.empty())
1336 return false;
1337 return template_param_infos.args.size() == template_param_infos.names.size();
1338}
1339
1340clang::ClassTemplateDecl *
1341SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001342 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001343 const char *parent_name,
1344 int tag_decl_kind,
1345 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1346{
1347 if (template_param_infos.IsValid())
1348 {
1349 std::string template_basename(parent_name);
1350 template_basename.erase (template_basename.find('<'));
1351 ClangASTContext &ast = GetClangASTContext();
1352
1353 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001354 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001355 template_basename.c_str(),
1356 tag_decl_kind,
1357 template_param_infos);
1358 }
1359 return NULL;
1360}
1361
Sean Callanana0b80ab2012-06-04 22:28:05 +00001362class SymbolFileDWARF::DelayedAddObjCClassProperty
1363{
1364public:
1365 DelayedAddObjCClassProperty
1366 (
1367 clang::ASTContext *ast,
1368 lldb::clang_type_t class_opaque_type,
1369 const char *property_name,
1370 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1371 clang::ObjCIvarDecl *ivar_decl,
1372 const char *property_setter_name,
1373 const char *property_getter_name,
1374 uint32_t property_attributes,
Greg Claytonc4ffd662013-03-08 01:37:30 +00001375 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001376 ) :
1377 m_ast (ast),
1378 m_class_opaque_type (class_opaque_type),
1379 m_property_name (property_name),
1380 m_property_opaque_type (property_opaque_type),
1381 m_ivar_decl (ivar_decl),
1382 m_property_setter_name (property_setter_name),
1383 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001384 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001385 {
Jim Ingham379397632012-10-27 02:54:13 +00001386 if (metadata != NULL)
1387 {
1388 m_metadata_ap.reset(new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001389 *m_metadata_ap = *metadata;
Jim Ingham379397632012-10-27 02:54:13 +00001390 }
1391 }
1392
1393 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1394 {
Daniel Malead4c5be62012-11-12 21:02:14 +00001395 *this = rhs;
1396 }
1397
1398 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1399 {
Jim Ingham379397632012-10-27 02:54:13 +00001400 m_ast = rhs.m_ast;
1401 m_class_opaque_type = rhs.m_class_opaque_type;
1402 m_property_name = rhs.m_property_name;
1403 m_property_opaque_type = rhs.m_property_opaque_type;
1404 m_ivar_decl = rhs.m_ivar_decl;
1405 m_property_setter_name = rhs.m_property_setter_name;
1406 m_property_getter_name = rhs.m_property_getter_name;
1407 m_property_attributes = rhs.m_property_attributes;
1408
1409 if (rhs.m_metadata_ap.get())
1410 {
1411 m_metadata_ap.reset (new ClangASTMetadata());
Greg Claytonc4ffd662013-03-08 01:37:30 +00001412 *m_metadata_ap = *rhs.m_metadata_ap;
Jim Ingham379397632012-10-27 02:54:13 +00001413 }
Daniel Malead4c5be62012-11-12 21:02:14 +00001414 return *this;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001415 }
1416
1417 bool Finalize() const
1418 {
Greg Claytonc4ffd662013-03-08 01:37:30 +00001419 return ClangASTContext::AddObjCClassProperty (m_ast,
1420 m_class_opaque_type,
1421 m_property_name,
1422 m_property_opaque_type,
1423 m_ivar_decl,
1424 m_property_setter_name,
1425 m_property_getter_name,
1426 m_property_attributes,
1427 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001428 }
1429private:
1430 clang::ASTContext *m_ast;
1431 lldb::clang_type_t m_class_opaque_type;
1432 const char *m_property_name;
1433 lldb::clang_type_t m_property_opaque_type;
1434 clang::ObjCIvarDecl *m_ivar_decl;
1435 const char *m_property_setter_name;
1436 const char *m_property_getter_name;
1437 uint32_t m_property_attributes;
Greg Claytonc4ffd662013-03-08 01:37:30 +00001438 std::auto_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001439};
1440
Sean Callananfaa0bb32012-12-05 23:37:14 +00001441struct BitfieldInfo
1442{
1443 uint64_t bit_size;
1444 uint64_t bit_offset;
1445
1446 BitfieldInfo () :
1447 bit_size (LLDB_INVALID_ADDRESS),
1448 bit_offset (LLDB_INVALID_ADDRESS)
1449 {
1450 }
1451
1452 bool IsValid ()
1453 {
1454 return (bit_size != LLDB_INVALID_ADDRESS) &&
1455 (bit_offset != LLDB_INVALID_ADDRESS);
1456 }
1457};
1458
Greg Claytonc4ffd662013-03-08 01:37:30 +00001459
1460bool
1461SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1462 const DWARFDebugInfoEntry *parent_die)
1463{
1464 if (parent_die)
1465 {
1466 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1467 {
1468 dw_tag_t tag = die->Tag();
1469 bool check_virtuality = false;
1470 switch (tag)
1471 {
1472 case DW_TAG_inheritance:
1473 case DW_TAG_subprogram:
1474 check_virtuality = true;
1475 break;
1476 default:
1477 break;
1478 }
1479 if (check_virtuality)
1480 {
1481 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1482 return true;
1483 }
1484 }
1485 }
1486 return false;
1487}
1488
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489size_t
1490SymbolFileDWARF::ParseChildMembers
1491(
1492 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001493 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001495 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001496 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1498 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001499 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001500 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001501 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001502 bool &is_a_class,
1503 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504)
1505{
1506 if (parent_die == NULL)
1507 return 0;
1508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 size_t count = 0;
1510 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001511 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001512 uint32_t member_idx = 0;
Sean Callananfaa0bb32012-12-05 23:37:14 +00001513 BitfieldInfo last_field_info;
Greg Claytond88d7592010-09-15 08:33:30 +00001514
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1516 {
1517 dw_tag_t tag = die->Tag();
1518
1519 switch (tag)
1520 {
1521 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001522 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 {
1524 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001525 const size_t num_attributes = die->GetAttributes (this,
1526 dwarf_cu,
1527 fixed_form_sizes,
1528 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001529 if (num_attributes > 0)
1530 {
1531 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001532 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001533 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001534 const char *prop_name = NULL;
1535 const char *prop_getter_name = NULL;
1536 const char *prop_setter_name = NULL;
Greg Claytone528efd72013-02-26 23:45:18 +00001537 uint32_t prop_attributes = 0;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001538
1539
Greg Clayton24739922010-10-13 03:15:28 +00001540 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001542 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001543 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544 size_t byte_size = 0;
1545 size_t bit_offset = 0;
1546 size_t bit_size = 0;
Greg Claytone528efd72013-02-26 23:45:18 +00001547 bool is_external = false; // On DW_TAG_members, this means the member is static
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001548 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001549 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001550 {
1551 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1552 DWARFFormValue form_value;
1553 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1554 {
1555 switch (attr)
1556 {
1557 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1558 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1559 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1560 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1561 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1562 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1563 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1564 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1565 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001566 if (form_value.BlockData())
1567 {
1568 Value initialValue(0);
1569 Value memberOffset(0);
1570 const DataExtractor& debug_info_data = get_debug_info_data();
1571 uint32_t block_length = form_value.Unsigned();
1572 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1573 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1574 NULL, // clang::ASTContext *
1575 NULL, // ClangExpressionVariableList *
1576 NULL, // ClangExpressionDeclMap *
1577 NULL, // RegisterContext *
1578 debug_info_data,
1579 block_offset,
1580 block_length,
1581 eRegisterKindDWARF,
1582 &initialValue,
1583 memberOffset,
1584 NULL))
1585 {
1586 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1587 }
1588 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589 break;
1590
Greg Clayton8cf05932010-07-22 18:30:50 +00001591 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001592 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001593 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1594 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1595 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1596 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
Greg Claytone528efd72013-02-26 23:45:18 +00001597 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001598
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001600 case DW_AT_declaration:
1601 case DW_AT_description:
1602 case DW_AT_mutable:
1603 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604 case DW_AT_sibling:
1605 break;
1606 }
1607 }
1608 }
Sean Callanana6582262012-04-05 00:12:52 +00001609
1610 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001611 {
Sean Callanana6582262012-04-05 00:12:52 +00001612 ConstString fixed_getter;
1613 ConstString fixed_setter;
1614
1615 // Check if the property getter/setter were provided as full
1616 // names. We want basenames, so we extract them.
1617
1618 if (prop_getter_name && prop_getter_name[0] == '-')
1619 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001620 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1621 prop_getter_name = prop_getter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001622 }
1623
1624 if (prop_setter_name && prop_setter_name[0] == '-')
1625 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00001626 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1627 prop_setter_name = prop_setter_method.GetSelector().GetCString();
Sean Callanana6582262012-04-05 00:12:52 +00001628 }
1629
1630 // If the names haven't been provided, they need to be
1631 // filled in.
1632
1633 if (!prop_getter_name)
1634 {
1635 prop_getter_name = prop_name;
1636 }
1637 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1638 {
1639 StreamString ss;
1640
1641 ss.Printf("set%c%s:",
1642 toupper(prop_name[0]),
1643 &prop_name[1]);
1644
1645 fixed_setter.SetCString(ss.GetData());
1646 prop_setter_name = fixed_setter.GetCString();
1647 }
Sean Callanan751aac62012-03-29 19:07:06 +00001648 }
1649
1650 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001651 // represents fields that are references with bad byte size
1652 // and bit size/offset information such as:
1653 //
1654 // DW_AT_byte_size( 0x00 )
1655 // DW_AT_bit_size( 0x40 )
1656 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1657 //
1658 // So check the bit offset to make sure it is sane, and if
1659 // the values are not sane, remove them. If we don't do this
1660 // then we will end up with a crash if we try to use this
1661 // type in an expression when clang becomes unhappy with its
1662 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001663
Greg Clayton44953932011-10-25 01:25:35 +00001664 if (bit_offset > 128)
1665 {
1666 bit_size = 0;
1667 bit_offset = 0;
1668 }
1669
1670 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001671 if (class_language == eLanguageTypeObjC ||
1672 class_language == eLanguageTypeObjC_plus_plus)
1673 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001674
1675 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1676 {
1677 // Not all compilers will mark the vtable pointer
1678 // member as artificial (llvm-gcc). We can't have
1679 // the virtual members in our classes otherwise it
1680 // throws off all child offsets since we end up
1681 // having and extra pointer sized member in our
1682 // class layouts.
1683 is_artificial = true;
1684 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685
Greg Claytone528efd72013-02-26 23:45:18 +00001686 // Skip static members
1687 if (is_external && member_byte_offset == UINT32_MAX)
1688 break;
1689
Greg Clayton24739922010-10-13 03:15:28 +00001690 if (is_artificial == false)
1691 {
1692 Type *member_type = ResolveTypeUID(encoding_uid);
Sean Callananfa3ab452012-12-14 00:54:13 +00001693
Jim Inghame3ae82a2011-11-12 01:36:43 +00001694 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001695 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001696 {
Sean Callanan751aac62012-03-29 19:07:06 +00001697 if (member_type)
1698 {
1699 if (accessibility == eAccessNone)
1700 accessibility = default_accessibility;
1701 member_accessibilities.push_back(accessibility);
Sean Callananfaa0bb32012-12-05 23:37:14 +00001702
1703 BitfieldInfo this_field_info;
1704
1705 this_field_info.bit_size = bit_size;
1706
1707 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001708 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001709 /////////////////////////////////////////////////////////////
1710 // How to locate a field given the DWARF debug information
1711 //
1712 // AT_byte_size indicates the size of the word in which the
1713 // bit offset must be interpreted.
1714 //
1715 // AT_data_member_location indicates the byte offset of the
1716 // word from the base address of the structure.
1717 //
1718 // AT_bit_offset indicates how many bits into the word
1719 // (according to the host endianness) the low-order bit of
1720 // the field starts. AT_bit_offset can be negative.
1721 //
1722 // AT_bit_size indicates the size of the field in bits.
1723 /////////////////////////////////////////////////////////////
1724
1725 this_field_info.bit_offset = 0;
1726
1727 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1728
1729 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1730 {
1731 this_field_info.bit_offset += byte_size * 8;
1732 this_field_info.bit_offset -= (bit_offset + bit_size);
1733 }
1734 else
1735 {
1736 this_field_info.bit_offset += bit_offset;
1737 }
1738 }
1739
1740 // If the member to be emitted did not start on a character boundary and there is
1741 // empty space between the last field and this one, then we need to emit an
1742 // anonymous member filling up the space up to its start. There are three cases
1743 // here:
1744 //
1745 // 1 If the previous member ended on a character boundary, then we can emit an
1746 // anonymous member starting at the most recent character boundary.
1747 //
1748 // 2 If the previous member did not end on a character boundary and the distance
1749 // from the end of the previous member to the current member is less than a
1750 // word width, then we can emit an anonymous member starting right after the
1751 // previous member and right before this member.
1752 //
1753 // 3 If the previous member did not end on a character boundary and the distance
1754 // from the end of the previous member to the current member is greater than
1755 // or equal a word width, then we act as in Case 1.
1756
1757 const uint64_t character_width = 8;
1758 const uint64_t word_width = 32;
1759
1760 if (this_field_info.IsValid())
1761 {
1762 // Objective-C has invalid DW_AT_bit_offset values in older versions
1763 // of clang, so we have to be careful and only insert unnammed bitfields
Greg Clayton37c36e42012-11-27 00:59:26 +00001764 // if we have a new enough clang.
1765 bool detect_unnamed_bitfields = true;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001766
Greg Clayton37c36e42012-11-27 00:59:26 +00001767 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1768 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1769
1770 if (detect_unnamed_bitfields)
Greg Clayton88bc7f32012-11-06 00:20:41 +00001771 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001772 BitfieldInfo anon_field_info;
1773
1774 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
Greg Clayton88bc7f32012-11-06 00:20:41 +00001775 {
Sean Callananfaa0bb32012-12-05 23:37:14 +00001776 uint64_t last_field_end = 0;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001777
Sean Callananfaa0bb32012-12-05 23:37:14 +00001778 if (last_field_info.IsValid())
1779 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
Greg Clayton88bc7f32012-11-06 00:20:41 +00001780
Sean Callananfaa0bb32012-12-05 23:37:14 +00001781 if (this_field_info.bit_offset != last_field_end)
1782 {
1783 if (((last_field_end % character_width) == 0) || // case 1
1784 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
1785 {
1786 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
1787 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
1788 }
1789 else // case 2
1790 {
1791 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
1792 anon_field_info.bit_offset = last_field_end;
1793 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001794 }
Greg Clayton88bc7f32012-11-06 00:20:41 +00001795 }
1796
Sean Callananfaa0bb32012-12-05 23:37:14 +00001797 if (anon_field_info.IsValid())
Greg Clayton88bc7f32012-11-06 00:20:41 +00001798 {
Greg Clayton88bc7f32012-11-06 00:20:41 +00001799 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1800 NULL,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001801 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
Greg Clayton88bc7f32012-11-06 00:20:41 +00001802 accessibility,
Sean Callananfaa0bb32012-12-05 23:37:14 +00001803 anon_field_info.bit_size);
Greg Clayton88bc7f32012-11-06 00:20:41 +00001804
Sean Callananfaa0bb32012-12-05 23:37:14 +00001805 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
Greg Clayton88bc7f32012-11-06 00:20:41 +00001806 }
1807 }
1808 }
Sean Callananfaa0bb32012-12-05 23:37:14 +00001809
Sean Callananfa3ab452012-12-14 00:54:13 +00001810 clang_type_t member_clang_type = member_type->GetClangLayoutType();
1811
1812 {
1813 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
1814 // If the current field is at the end of the structure, then there is definitely no room for extra
1815 // elements and we override the type to array[0].
1816
1817 clang_type_t member_array_element_type;
1818 uint64_t member_array_size;
1819 bool member_array_is_incomplete;
1820
1821 if (GetClangASTContext().IsArrayType(member_clang_type,
1822 &member_array_element_type,
1823 &member_array_size,
1824 &member_array_is_incomplete) &&
1825 !member_array_is_incomplete)
1826 {
1827 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
1828
1829 if (member_byte_offset >= parent_byte_size)
1830 {
1831 if (member_array_size != 1)
1832 {
1833 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64,
1834 MakeUserID(die->GetOffset()),
1835 name,
1836 encoding_uid,
1837 MakeUserID(parent_die->GetOffset()));
1838 }
1839
1840 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0);
1841 }
1842 }
1843 }
1844
Greg Clayton88bc7f32012-11-06 00:20:41 +00001845 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001846 name,
Sean Callananfa3ab452012-12-14 00:54:13 +00001847 member_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001848 accessibility,
1849 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001850
Greg Claytond0029442013-03-27 01:48:02 +00001851 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
Sean Callananfaa0bb32012-12-05 23:37:14 +00001852
1853 if (this_field_info.IsValid())
1854 {
1855 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset));
1856 last_field_info = this_field_info;
1857 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001858 }
1859 else
1860 {
Sean Callanan751aac62012-03-29 19:07:06 +00001861 if (name)
Daniel Malead01b2952012-11-29 21:49:15 +00001862 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00001863 MakeUserID(die->GetOffset()),
1864 name,
1865 encoding_uid);
1866 else
Daniel Malead01b2952012-11-29 21:49:15 +00001867 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
Sean Callanan751aac62012-03-29 19:07:06 +00001868 MakeUserID(die->GetOffset()),
1869 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001870 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001871 }
Sean Callanan751aac62012-03-29 19:07:06 +00001872
Jim Inghame3ae82a2011-11-12 01:36:43 +00001873 if (prop_name != NULL)
1874 {
Sean Callanan751aac62012-03-29 19:07:06 +00001875 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001876
Sean Callanan751aac62012-03-29 19:07:06 +00001877 if (field_decl)
1878 {
1879 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1880 assert (ivar_decl != NULL);
1881 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001882
Jim Ingham379397632012-10-27 02:54:13 +00001883 ClangASTMetadata metadata;
1884 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001885 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1886 class_clang_type,
1887 prop_name,
1888 member_type->GetClangLayoutType(),
1889 ivar_decl,
1890 prop_setter_name,
1891 prop_getter_name,
1892 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001893 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001894
Sean Callananad880762012-04-18 01:06:17 +00001895 if (ivar_decl)
Greg Claytond0029442013-03-27 01:48:02 +00001896 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001897 }
Greg Clayton24739922010-10-13 03:15:28 +00001898 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001900 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901 }
1902 break;
1903
1904 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001905 // Let the type parsing code handle this one for us.
1906 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 break;
1908
1909 case DW_TAG_inheritance:
1910 {
1911 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001912 if (default_accessibility == eAccessNone)
1913 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001914 // TODO: implement DW_TAG_inheritance type parsing
1915 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001916 const size_t num_attributes = die->GetAttributes (this,
1917 dwarf_cu,
1918 fixed_form_sizes,
1919 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 if (num_attributes > 0)
1921 {
1922 Declaration decl;
1923 DWARFExpression location;
1924 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001925 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926 bool is_virtual = false;
1927 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001928 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 uint32_t i;
1930 for (i=0; i<num_attributes; ++i)
1931 {
1932 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1933 DWARFFormValue form_value;
1934 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1935 {
1936 switch (attr)
1937 {
1938 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1939 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1940 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1941 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001942 case DW_AT_data_member_location:
1943 if (form_value.BlockData())
1944 {
1945 Value initialValue(0);
1946 Value memberOffset(0);
1947 const DataExtractor& debug_info_data = get_debug_info_data();
1948 uint32_t block_length = form_value.Unsigned();
1949 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1950 if (DWARFExpression::Evaluate (NULL,
1951 NULL,
1952 NULL,
1953 NULL,
1954 NULL,
1955 debug_info_data,
1956 block_offset,
1957 block_length,
1958 eRegisterKindDWARF,
1959 &initialValue,
1960 memberOffset,
1961 NULL))
1962 {
1963 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1964 }
1965 }
1966 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001967
1968 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001969 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970 break;
1971
1972 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1973 default:
1974 case DW_AT_sibling:
1975 break;
1976 }
1977 }
1978 }
1979
Greg Clayton526e5af2010-11-13 03:52:47 +00001980 Type *base_class_type = ResolveTypeUID(encoding_uid);
1981 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001982
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001983 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1984 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001985 if (class_language == eLanguageTypeObjC)
1986 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001987 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001988 }
1989 else
1990 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001991 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001992 accessibility,
1993 is_virtual,
1994 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00001995
1996 if (is_virtual)
1997 {
1998 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
1999 clang::CharUnits::fromQuantity(member_byte_offset)));
2000 }
2001 else
2002 {
2003 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2004 clang::CharUnits::fromQuantity(member_byte_offset)));
2005 }
Greg Clayton9e409562010-07-28 02:04:09 +00002006 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007 }
2008 }
2009 break;
2010
2011 default:
2012 break;
2013 }
2014 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002015
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 return count;
2017}
2018
2019
2020clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002021SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022{
2023 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002024 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025 {
2026 DWARFCompileUnitSP cu_sp;
2027 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2028 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002029 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002030 }
2031 return NULL;
2032}
2033
2034clang::DeclContext*
2035SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2036{
Greg Clayton81c22f62011-10-19 18:09:39 +00002037 if (UserIDMatches(type_uid))
2038 return GetClangDeclContextForDIEOffset (sc, type_uid);
2039 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040}
2041
2042Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002043SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002044{
Greg Clayton81c22f62011-10-19 18:09:39 +00002045 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002046 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002047 DWARFDebugInfo* debug_info = DebugInfo();
2048 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002049 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002050 DWARFCompileUnitSP cu_sp;
2051 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002052 const bool assert_not_being_parsed = true;
2053 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002054 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055 }
2056 return NULL;
2057}
2058
Greg Claytoncab36a32011-12-08 05:16:30 +00002059Type*
2060SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002061{
Greg Claytoncab36a32011-12-08 05:16:30 +00002062 if (die != NULL)
2063 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002064 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00002065 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002066 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002067 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2068 die->GetOffset(),
2069 DW_TAG_value_to_name(die->Tag()),
2070 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002071
Greg Claytoncab36a32011-12-08 05:16:30 +00002072 // We might be coming in in the middle of a type tree (a class
2073 // withing a class, an enum within a class), so parse any needed
2074 // parent DIEs before we get to this one...
2075 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2076 switch (decl_ctx_die->Tag())
2077 {
2078 case DW_TAG_structure_type:
2079 case DW_TAG_union_type:
2080 case DW_TAG_class_type:
2081 {
2082 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002083 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002084 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002085 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2086 die->GetOffset(),
2087 DW_TAG_value_to_name(die->Tag()),
2088 die->GetName(this, cu),
2089 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002090//
2091// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2092// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2093// {
2094// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002095// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00002096// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2097// die->GetOffset(),
2098// DW_TAG_value_to_name(die->Tag()),
2099// die->GetName(this, cu),
2100// decl_ctx_die->GetOffset());
2101// // Ask the type to complete itself if it already hasn't since if we
2102// // want a function (method or static) from a class, the class must
2103// // create itself and add it's own methods and class functions.
2104// if (parent_type)
2105// parent_type->GetClangFullType();
2106// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002107 }
2108 break;
2109
2110 default:
2111 break;
2112 }
2113 return ResolveType (cu, die);
2114 }
2115 return NULL;
2116}
2117
Greg Clayton6beaaa62011-01-17 03:46:26 +00002118// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2119// SymbolFileDWARF objects to detect if this DWARF file is the one that
2120// can resolve a clang_type.
2121bool
2122SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2123{
2124 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2125 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2126 return die != NULL;
2127}
2128
2129
Greg Clayton1be10fc2010-09-29 01:12:09 +00002130lldb::clang_type_t
2131SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2132{
2133 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002134 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2135 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002136 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002137 {
2138 // We have already resolved this type...
2139 return clang_type;
2140 }
2141 // Once we start resolving this type, remove it from the forward declaration
2142 // map in case anyone child members or other types require this type to get resolved.
2143 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2144 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002145 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002146
Greg Clayton1be10fc2010-09-29 01:12:09 +00002147
Greg Clayton85ae2e12011-10-18 23:36:41 +00002148 // Disable external storage for this type so we don't get anymore
2149 // clang::ExternalASTSource queries for this type.
2150 ClangASTContext::SetHasExternalStorage (clang_type, false);
2151
Greg Clayton450e3f32010-10-12 02:24:53 +00002152 DWARFDebugInfo* debug_info = DebugInfo();
2153
Greg Clayton53eb1c22012-04-02 22:59:12 +00002154 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002155 Type *type = m_die_to_type.lookup (die);
2156
2157 const dw_tag_t tag = die->Tag();
2158
Greg Clayton5160ce52013-03-27 23:08:40 +00002159 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002160 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002161 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002162 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002163 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00002164 MakeUserID(die->GetOffset()),
2165 DW_TAG_value_to_name(tag),
2166 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002167
Greg Claytonbaf95da2012-03-30 23:50:54 +00002168 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002169 assert (clang_type);
2170 DWARFDebugInfoEntry::Attributes attributes;
2171
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002172 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002173
2174 switch (tag)
2175 {
2176 case DW_TAG_structure_type:
2177 case DW_TAG_union_type:
2178 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002179 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002180 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002181
Greg Clayton1be10fc2010-09-29 01:12:09 +00002182 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002183 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002184 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002185
Sean Callanan77a1fd32012-02-27 20:07:01 +00002186 LanguageType class_language = eLanguageTypeUnknown;
2187 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2188 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002189 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002190 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002191 // For objective C we don't start the definition when
2192 // the class is created.
2193 ast.StartTagDeclarationDefinition (clang_type);
2194 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002195
2196 int tag_decl_kind = -1;
2197 AccessType default_accessibility = eAccessNone;
2198 if (tag == DW_TAG_structure_type)
2199 {
2200 tag_decl_kind = clang::TTK_Struct;
2201 default_accessibility = eAccessPublic;
2202 }
2203 else if (tag == DW_TAG_union_type)
2204 {
2205 tag_decl_kind = clang::TTK_Union;
2206 default_accessibility = eAccessPublic;
2207 }
2208 else if (tag == DW_TAG_class_type)
2209 {
2210 tag_decl_kind = clang::TTK_Class;
2211 default_accessibility = eAccessPrivate;
2212 }
2213
Greg Clayton53eb1c22012-04-02 22:59:12 +00002214 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002215 std::vector<clang::CXXBaseSpecifier *> base_classes;
2216 std::vector<int> member_accessibilities;
2217 bool is_a_class = false;
2218 // Parse members and base classes first
2219 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002220
2221 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002222 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002223 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002224 die,
2225 clang_type,
2226 class_language,
2227 base_classes,
2228 member_accessibilities,
2229 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002230 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002231 default_accessibility,
2232 is_a_class,
2233 layout_info);
2234
2235 // Now parse any methods if there were any...
2236 size_t num_functions = member_function_dies.Size();
2237 if (num_functions > 0)
2238 {
2239 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002240 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002241 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002242 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002243 }
2244
2245 if (class_language == eLanguageTypeObjC)
2246 {
Greg Clayton84db9102012-03-26 23:03:23 +00002247 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002248 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002249 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002250
Sean Callanan77a1fd32012-02-27 20:07:01 +00002251 DIEArray method_die_offsets;
2252 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002253 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002254 if (m_apple_objc_ap.get())
2255 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2256 }
2257 else
2258 {
2259 if (!m_indexed)
2260 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002261
Sean Callanan77a1fd32012-02-27 20:07:01 +00002262 ConstString class_name (class_str.c_str());
2263 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2264 }
2265
2266 if (!method_die_offsets.empty())
2267 {
2268 DWARFDebugInfo* debug_info = DebugInfo();
2269
2270 DWARFCompileUnit* method_cu = NULL;
2271 const size_t num_matches = method_die_offsets.size();
2272 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002273 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002274 const dw_offset_t die_offset = method_die_offsets[i];
2275 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2276
2277 if (method_die)
2278 ResolveType (method_cu, method_die);
2279 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002280 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002281 if (m_using_apple_tables)
2282 {
2283 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2284 die_offset, class_str.c_str());
2285 }
2286 }
2287 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002288 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002289
2290 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2291 pi != pe;
2292 ++pi)
2293 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002294 }
2295 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002296
2297 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2298 // need to tell the clang type it is actually a class.
2299 if (class_language != eLanguageTypeObjC)
2300 {
2301 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2302 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2303 }
2304
2305 // Since DW_TAG_structure_type gets used for both classes
2306 // and structures, we may need to set any DW_TAG_member
2307 // fields to have a "private" access if none was specified.
2308 // When we parsed the child members we tracked that actual
2309 // accessibility value for each DW_TAG_member in the
2310 // "member_accessibilities" array. If the value for the
2311 // member is zero, then it was set to the "default_accessibility"
2312 // which for structs was "public". Below we correct this
2313 // by setting any fields to "private" that weren't correctly
2314 // set.
2315 if (is_a_class && !member_accessibilities.empty())
2316 {
2317 // This is a class and all members that didn't have
2318 // their access specified are private.
2319 ast.SetDefaultAccessForRecordFields (clang_type,
2320 eAccessPrivate,
2321 &member_accessibilities.front(),
2322 member_accessibilities.size());
2323 }
2324
2325 if (!base_classes.empty())
2326 {
2327 ast.SetBaseClassesForClassType (clang_type,
2328 &base_classes.front(),
2329 base_classes.size());
2330
2331 // Clang will copy each CXXBaseSpecifier in "base_classes"
2332 // so we have to free them all.
2333 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2334 base_classes.size());
2335 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002336 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002337 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002338
2339 ast.BuildIndirectFields (clang_type);
2340
Sean Callanan77a1fd32012-02-27 20:07:01 +00002341 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002342
Greg Clayton2508b9b2012-11-01 23:20:02 +00002343 if (!layout_info.field_offsets.empty() ||
2344 !layout_info.base_offsets.empty() ||
2345 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002346 {
2347 if (type)
2348 layout_info.bit_size = type->GetByteSize() * 8;
2349 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002350 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002351
2352 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2353 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002354 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002355 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002356 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002357 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00002358 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002359 clang_type,
2360 record_decl,
2361 layout_info.bit_size,
2362 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002363 (uint32_t)layout_info.field_offsets.size(),
2364 (uint32_t)layout_info.base_offsets.size(),
2365 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002366
Greg Clayton2508b9b2012-11-01 23:20:02 +00002367 uint32_t idx;
2368 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002369 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002370 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002371 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002372 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002373 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002374 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002375 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002376 (uint32_t)pos->second,
2377 pos->first->getNameAsString().c_str());
2378 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002379 }
2380
2381 {
2382 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2383 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2384 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002385 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002386 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2387 clang_type,
2388 idx,
2389 (uint32_t)base_pos->second.getQuantity(),
2390 base_pos->first->getNameAsString().c_str());
2391 }
2392 }
2393 {
2394 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2395 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2396 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002397 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002398 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2399 clang_type,
2400 idx,
2401 (uint32_t)vbase_pos->second.getQuantity(),
2402 vbase_pos->first->getNameAsString().c_str());
2403 }
2404 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002405 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002406 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2407 }
2408 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002409 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002410
Greg Claytonc93237c2010-10-01 20:48:32 +00002411 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002412
2413 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002414 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002415 if (die->HasChildren())
2416 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002417 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00002418 bool is_signed = false;
2419 ast.IsIntegerType(clang_type, is_signed);
2420 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002421 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002422 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002423 return clang_type;
2424
2425 default:
2426 assert(false && "not a forward clang type decl!");
2427 break;
2428 }
2429 return NULL;
2430}
2431
Greg Claytonc685f8e2010-09-15 04:15:46 +00002432Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002433SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002434{
2435 if (type_die != NULL)
2436 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002437 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002438
Greg Claytonc685f8e2010-09-15 04:15:46 +00002439 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002440 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002441
Greg Clayton24739922010-10-13 03:15:28 +00002442 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002443 {
2444 if (type != DIE_IS_BEING_PARSED)
2445 return type;
2446
2447 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002448 type_die->GetOffset(),
2449 DW_TAG_value_to_name(type_die->Tag()),
2450 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002451
2452 }
2453 else
2454 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002455 }
2456 return NULL;
2457}
2458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002459CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002460SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461{
2462 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002463 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002464 {
2465 // The symbol vendor doesn't know about this compile unit, we
2466 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002467 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002468 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002469 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470}
2471
2472bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002473SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002474{
Greg Clayton72310352013-02-23 04:12:47 +00002475 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002476 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002477 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002478
Greg Clayton81c22f62011-10-19 18:09:39 +00002479 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002480 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002481 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002482
2483 if (sc.function)
2484 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002485 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002486 return true;
2487 }
2488
2489 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490}
2491
2492uint32_t
2493SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2494{
2495 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00002496 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002497 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002498 so_addr.GetOffset(),
2499 resolve_scope);
2500 uint32_t resolved = 0;
2501 if (resolve_scope & ( eSymbolContextCompUnit |
2502 eSymbolContextFunction |
2503 eSymbolContextBlock |
2504 eSymbolContextLineEntry))
2505 {
2506 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2507
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002508 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002509 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002510 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002511 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512 if (cu_offset != DW_INVALID_OFFSET)
2513 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002514 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002515 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2516 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002517 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002518 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002519 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002520 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002521 resolved |= eSymbolContextCompUnit;
2522
Greg Clayton6ab80132012-12-12 17:30:52 +00002523 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002524 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2525 {
2526 DWARFDebugInfoEntry *function_die = NULL;
2527 DWARFDebugInfoEntry *block_die = NULL;
2528 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002529 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002530 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2531 }
2532 else
2533 {
2534 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2535 }
2536
2537 if (function_die != NULL)
2538 {
2539 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2540 if (sc.function == NULL)
2541 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2542 }
2543 else
2544 {
2545 // We might have had a compile unit that had discontiguous
2546 // address ranges where the gaps are symbols that don't have
2547 // any debug info. Discontiguous compile unit address ranges
2548 // should only happen when there aren't other functions from
2549 // other compile units in these gaps. This helps keep the size
2550 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00002551 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00002552 }
2553
2554 if (sc.function != NULL)
2555 {
2556 resolved |= eSymbolContextFunction;
2557
2558 if (resolve_scope & eSymbolContextBlock)
2559 {
2560 Block& block = sc.function->GetBlock (true);
2561
2562 if (block_die != NULL)
2563 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2564 else
2565 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2566 if (sc.block)
2567 resolved |= eSymbolContextBlock;
2568 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002569 }
2570 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002571
2572 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2573 {
2574 LineTable *line_table = sc.comp_unit->GetLineTable();
2575 if (line_table != NULL)
2576 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002577 // And address that makes it into this function should be in terms
2578 // of this debug file if there is no debug map, or it will be an
2579 // address in the .o file which needs to be fixed up to be in terms
2580 // of the debug map executable. Either way, calling FixupAddress()
2581 // will work for us.
2582 Address exe_so_addr (so_addr);
2583 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00002584 {
Greg Clayton9422dd62013-03-04 21:46:16 +00002585 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00002586 {
2587 resolved |= eSymbolContextLineEntry;
2588 }
2589 }
Greg Clayton6ab80132012-12-12 17:30:52 +00002590 }
2591 }
2592
2593 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2594 {
2595 // We might have had a compile unit that had discontiguous
2596 // address ranges where the gaps are symbols that don't have
2597 // any debug info. Discontiguous compile unit address ranges
2598 // should only happen when there aren't other functions from
2599 // other compile units in these gaps. This helps keep the size
2600 // of the aranges down.
2601 sc.comp_unit = NULL;
2602 resolved &= ~eSymbolContextCompUnit;
2603 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002604 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002605 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002606 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002607 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2608 cu_offset,
2609 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002610 }
2611 }
2612 }
2613 }
2614 }
2615 return resolved;
2616}
2617
2618
2619
2620uint32_t
2621SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2622{
2623 const uint32_t prev_size = sc_list.GetSize();
2624 if (resolve_scope & eSymbolContextCompUnit)
2625 {
2626 DWARFDebugInfo* debug_info = DebugInfo();
2627 if (debug_info)
2628 {
2629 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002630 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002631
Greg Clayton53eb1c22012-04-02 22:59:12 +00002632 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002633 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002634 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002635 const bool full_match = file_spec.GetDirectory();
2636 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002637 if (check_inlines || file_spec_matches_cu_file_spec)
2638 {
2639 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002640 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002641 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002642 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002643 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002644
Greg Clayton526a4ae2012-05-16 22:09:01 +00002645 // If we are looking for inline functions only and we don't
2646 // find it in the support files, we are done.
2647 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002648 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002649 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2650 if (file_idx == UINT32_MAX)
2651 continue;
2652 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002653
Greg Clayton526a4ae2012-05-16 22:09:01 +00002654 if (line != 0)
2655 {
2656 LineTable *line_table = sc.comp_unit->GetLineTable();
2657
2658 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002659 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002660 // We will have already looked up the file index if
2661 // we are searching for inline entries.
2662 if (!check_inlines)
2663 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664
Greg Clayton526a4ae2012-05-16 22:09:01 +00002665 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002666 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002667 uint32_t found_line;
2668 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2669 found_line = sc.line_entry.line;
2670
2671 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002672 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002673 sc.function = NULL;
2674 sc.block = NULL;
2675 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002676 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002677 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2678 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002679 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002680 DWARFDebugInfoEntry *function_die = NULL;
2681 DWARFDebugInfoEntry *block_die = NULL;
2682 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002683
Greg Clayton526a4ae2012-05-16 22:09:01 +00002684 if (function_die != NULL)
2685 {
2686 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2687 if (sc.function == NULL)
2688 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2689 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690
Greg Clayton526a4ae2012-05-16 22:09:01 +00002691 if (sc.function != NULL)
2692 {
2693 Block& block = sc.function->GetBlock (true);
2694
2695 if (block_die != NULL)
2696 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2697 else
2698 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2699 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002700 }
2701 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702
Greg Clayton526a4ae2012-05-16 22:09:01 +00002703 sc_list.Append(sc);
2704 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2705 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706 }
2707 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002708 else if (file_spec_matches_cu_file_spec && !check_inlines)
2709 {
2710 // only append the context if we aren't looking for inline call sites
2711 // by file and line and if the file spec matches that of the compile unit
2712 sc_list.Append(sc);
2713 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002714 }
2715 else if (file_spec_matches_cu_file_spec && !check_inlines)
2716 {
2717 // only append the context if we aren't looking for inline call sites
2718 // by file and line and if the file spec matches that of the compile unit
2719 sc_list.Append(sc);
2720 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002721
Greg Clayton526a4ae2012-05-16 22:09:01 +00002722 if (!check_inlines)
2723 break;
2724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002725 }
2726 }
2727 }
2728 }
2729 return sc_list.GetSize() - prev_size;
2730}
2731
2732void
2733SymbolFileDWARF::Index ()
2734{
2735 if (m_indexed)
2736 return;
2737 m_indexed = true;
2738 Timer scoped_timer (__PRETTY_FUNCTION__,
2739 "SymbolFileDWARF::Index (%s)",
2740 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2741
2742 DWARFDebugInfo* debug_info = DebugInfo();
2743 if (debug_info)
2744 {
2745 uint32_t cu_idx = 0;
2746 const uint32_t num_compile_units = GetNumCompileUnits();
2747 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2748 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002749 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002750
Greg Clayton53eb1c22012-04-02 22:59:12 +00002751 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002752
Greg Clayton53eb1c22012-04-02 22:59:12 +00002753 dwarf_cu->Index (cu_idx,
2754 m_function_basename_index,
2755 m_function_fullname_index,
2756 m_function_method_index,
2757 m_function_selector_index,
2758 m_objc_class_selectors_index,
2759 m_global_index,
2760 m_type_index,
2761 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002762
2763 // Keep memory down by clearing DIEs if this generate function
2764 // caused them to be parsed
2765 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002766 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002767 }
2768
Greg Claytond4a2b372011-09-12 23:21:58 +00002769 m_function_basename_index.Finalize();
2770 m_function_fullname_index.Finalize();
2771 m_function_method_index.Finalize();
2772 m_function_selector_index.Finalize();
2773 m_objc_class_selectors_index.Finalize();
2774 m_global_index.Finalize();
2775 m_type_index.Finalize();
2776 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002777
Greg Clayton24739922010-10-13 03:15:28 +00002778#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002779 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002780 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002781 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2782 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002783 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2784 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2785 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2786 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2787 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2788 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002789 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002790 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002791#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002792 }
2793}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002794
2795bool
2796SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2797{
2798 if (namespace_decl == NULL)
2799 {
2800 // Invalid namespace decl which means we aren't matching only things
2801 // in this symbol file, so return true to indicate it matches this
2802 // symbol file.
2803 return true;
2804 }
2805
2806 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2807
2808 if (namespace_ast == NULL)
2809 return true; // No AST in the "namespace_decl", return true since it
2810 // could then match any symbol file, including this one
2811
2812 if (namespace_ast == GetClangASTContext().getASTContext())
2813 return true; // The ASTs match, return true
2814
2815 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002816 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002817
2818 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002819 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002820
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002821 return false;
2822}
2823
Greg Clayton2506a7a2011-10-12 23:34:26 +00002824bool
2825SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2826 DWARFCompileUnit* cu,
2827 const DWARFDebugInfoEntry* die)
2828{
2829 // No namespace specified, so the answesr i
2830 if (namespace_decl == NULL)
2831 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002832
Greg Clayton5160ce52013-03-27 23:08:40 +00002833 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002834
Greg Clayton437a1352012-04-09 22:43:43 +00002835 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2836 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002837 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002838 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002839 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002840
Greg Clayton2506a7a2011-10-12 23:34:26 +00002841 if (clang_namespace_decl)
2842 {
2843 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002844 {
2845 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002846 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002847 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002848 }
2849
Greg Clayton437a1352012-04-09 22:43:43 +00002850 if (clang_namespace_decl == die_clang_decl_ctx)
2851 return true;
2852 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002853 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002854 }
2855 else
2856 {
2857 // We have a namespace_decl that was not NULL but it contained
2858 // a NULL "clang::NamespaceDecl", so this means the global namespace
2859 // So as long the the contained decl context DIE isn't a namespace
2860 // we should be ok.
2861 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2862 return true;
2863 }
2864 }
Sean Callananebe60672011-10-13 21:50:33 +00002865
2866 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002867 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002868
Greg Clayton2506a7a2011-10-12 23:34:26 +00002869 return false;
2870}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002871uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002872SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002873{
Greg Clayton5160ce52013-03-27 23:08:40 +00002874 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002875
2876 if (log)
2877 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002878 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002879 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2880 name.GetCString(),
2881 namespace_decl,
2882 append,
2883 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002884 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002885
2886 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2887 return 0;
2888
Greg Claytonc685f8e2010-09-15 04:15:46 +00002889 DWARFDebugInfo* info = DebugInfo();
2890 if (info == NULL)
2891 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002892
2893 // If we aren't appending the results to this list, then clear the list
2894 if (!append)
2895 variables.Clear();
2896
2897 // Remember how many variables are in the list before we search in case
2898 // we are appending the results to a variable list.
2899 const uint32_t original_size = variables.GetSize();
2900
Greg Claytond4a2b372011-09-12 23:21:58 +00002901 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002902
Greg Clayton97fbc342011-10-20 22:30:33 +00002903 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002904 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002905 if (m_apple_names_ap.get())
2906 {
2907 const char *name_cstr = name.GetCString();
2908 const char *base_name_start;
2909 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002910
Greg Clayton97fbc342011-10-20 22:30:33 +00002911 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2912 base_name_start = name_cstr;
2913
2914 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2915 }
Greg Clayton7f995132011-10-04 22:41:51 +00002916 }
2917 else
2918 {
2919 // Index the DWARF if we haven't already
2920 if (!m_indexed)
2921 Index ();
2922
2923 m_global_index.Find (name, die_offsets);
2924 }
2925
Greg Clayton437a1352012-04-09 22:43:43 +00002926 const size_t num_die_matches = die_offsets.size();
2927 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002928 {
Greg Clayton7f995132011-10-04 22:41:51 +00002929 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002930 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002931 assert (sc.module_sp);
2932
Greg Claytond4a2b372011-09-12 23:21:58 +00002933 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002934 DWARFCompileUnit* dwarf_cu = NULL;
2935 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002936 bool done = false;
2937 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002938 {
2939 const dw_offset_t die_offset = die_offsets[i];
2940 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002941
Greg Clayton95d87902011-11-11 03:16:25 +00002942 if (die)
2943 {
Greg Clayton437a1352012-04-09 22:43:43 +00002944 switch (die->Tag())
2945 {
2946 default:
2947 case DW_TAG_subprogram:
2948 case DW_TAG_inlined_subroutine:
2949 case DW_TAG_try_block:
2950 case DW_TAG_catch_block:
2951 break;
2952
2953 case DW_TAG_variable:
2954 {
2955 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002956
2957 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2958 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002959
Greg Clayton437a1352012-04-09 22:43:43 +00002960 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002961
Greg Clayton437a1352012-04-09 22:43:43 +00002962 if (variables.GetSize() - original_size >= max_matches)
2963 done = true;
2964 }
2965 break;
2966 }
Greg Clayton95d87902011-11-11 03:16:25 +00002967 }
2968 else
2969 {
2970 if (m_using_apple_tables)
2971 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002972 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2973 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002974 }
2975 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002977 }
2978
2979 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002980 const uint32_t num_matches = variables.GetSize() - original_size;
2981 if (log && num_matches > 0)
2982 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002983 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00002984 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2985 name.GetCString(),
2986 namespace_decl,
2987 append,
2988 max_matches,
2989 num_matches);
2990 }
2991 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002992}
2993
2994uint32_t
2995SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2996{
Greg Clayton5160ce52013-03-27 23:08:40 +00002997 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002998
2999 if (log)
3000 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003001 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003002 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3003 regex.GetText(),
3004 append,
3005 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003006 }
3007
Greg Claytonc685f8e2010-09-15 04:15:46 +00003008 DWARFDebugInfo* info = DebugInfo();
3009 if (info == NULL)
3010 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003011
3012 // If we aren't appending the results to this list, then clear the list
3013 if (!append)
3014 variables.Clear();
3015
3016 // Remember how many variables are in the list before we search in case
3017 // we are appending the results to a variable list.
3018 const uint32_t original_size = variables.GetSize();
3019
Greg Clayton7f995132011-10-04 22:41:51 +00003020 DIEArray die_offsets;
3021
Greg Clayton97fbc342011-10-20 22:30:33 +00003022 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003023 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003024 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003025 {
3026 DWARFMappedHash::DIEInfoArray hash_data_array;
3027 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3028 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3029 }
Greg Clayton7f995132011-10-04 22:41:51 +00003030 }
3031 else
3032 {
3033 // Index the DWARF if we haven't already
3034 if (!m_indexed)
3035 Index ();
3036
3037 m_global_index.Find (regex, die_offsets);
3038 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039
Greg Claytonc685f8e2010-09-15 04:15:46 +00003040 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003041 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003042 assert (sc.module_sp);
3043
Greg Claytond4a2b372011-09-12 23:21:58 +00003044 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003045 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003046 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003047 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003048 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003049 DWARFDebugInfo* debug_info = DebugInfo();
3050 for (size_t i=0; i<num_matches; ++i)
3051 {
3052 const dw_offset_t die_offset = die_offsets[i];
3053 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003054
3055 if (die)
3056 {
3057 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003058
Greg Clayton95d87902011-11-11 03:16:25 +00003059 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003060
Greg Clayton95d87902011-11-11 03:16:25 +00003061 if (variables.GetSize() - original_size >= max_matches)
3062 break;
3063 }
3064 else
3065 {
3066 if (m_using_apple_tables)
3067 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003068 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3069 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003070 }
3071 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003072 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003073 }
3074
3075 // Return the number of variable that were appended to the list
3076 return variables.GetSize() - original_size;
3077}
3078
Greg Claytonaa044962011-10-13 00:59:38 +00003079
Jim Ingham4cda6e02011-10-07 22:23:45 +00003080bool
3081SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3082 DWARFCompileUnit *&dwarf_cu,
3083 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003084{
Greg Claytonaa044962011-10-13 00:59:38 +00003085 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3086 return ResolveFunction (dwarf_cu, die, sc_list);
3087}
3088
3089
3090bool
3091SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3092 const DWARFDebugInfoEntry *die,
3093 SymbolContextList& sc_list)
3094{
Greg Clayton9e315582011-09-02 04:03:59 +00003095 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003096
3097 if (die == NULL)
3098 return false;
3099
Jim Ingham4cda6e02011-10-07 22:23:45 +00003100 // If we were passed a die that is not a function, just return false...
3101 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3102 return false;
3103
3104 const DWARFDebugInfoEntry* inlined_die = NULL;
3105 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003106 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003107 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003108
Jim Ingham4cda6e02011-10-07 22:23:45 +00003109 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003110 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003111 if (die->Tag() == DW_TAG_subprogram)
3112 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003113 }
3114 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003115 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003116 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003117 {
3118 Address addr;
3119 // Parse all blocks if needed
3120 if (inlined_die)
3121 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003122 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003123 assert (sc.block != NULL);
3124 if (sc.block->GetStartAddress (addr) == false)
3125 addr.Clear();
3126 }
3127 else
3128 {
3129 sc.block = NULL;
3130 addr = sc.function->GetAddressRange().GetBaseAddress();
3131 }
3132
3133 if (addr.IsValid())
3134 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003135 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003136 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003137 }
3138 }
3139
Greg Claytonaa044962011-10-13 00:59:38 +00003140 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003141}
3142
Greg Clayton7f995132011-10-04 22:41:51 +00003143void
3144SymbolFileDWARF::FindFunctions (const ConstString &name,
3145 const NameToDIE &name_to_die,
3146 SymbolContextList& sc_list)
3147{
Greg Claytond4a2b372011-09-12 23:21:58 +00003148 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003149 if (name_to_die.Find (name, die_offsets))
3150 {
3151 ParseFunctions (die_offsets, sc_list);
3152 }
3153}
3154
3155
3156void
3157SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3158 const NameToDIE &name_to_die,
3159 SymbolContextList& sc_list)
3160{
3161 DIEArray die_offsets;
3162 if (name_to_die.Find (regex, die_offsets))
3163 {
3164 ParseFunctions (die_offsets, sc_list);
3165 }
3166}
3167
3168
3169void
3170SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3171 const DWARFMappedHash::MemoryTable &memory_table,
3172 SymbolContextList& sc_list)
3173{
3174 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003175 DWARFMappedHash::DIEInfoArray hash_data_array;
3176 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003177 {
Greg Claytond1767f02011-12-08 02:13:16 +00003178 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003179 ParseFunctions (die_offsets, sc_list);
3180 }
3181}
3182
3183void
3184SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3185 SymbolContextList& sc_list)
3186{
3187 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003188 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003189 {
Greg Clayton7f995132011-10-04 22:41:51 +00003190 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003191
3192 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003193 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003194 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003195 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003196 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197 }
3198 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003199}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003200
Jim Ingham4cda6e02011-10-07 22:23:45 +00003201bool
3202SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3203 const DWARFCompileUnit *dwarf_cu,
3204 uint32_t name_type_mask,
3205 const char *partial_name,
3206 const char *base_name_start,
3207 const char *base_name_end)
3208{
Greg Claytonfbea0f62012-11-15 18:05:43 +00003209 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3210 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003211 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003212 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3213 if (!containing_decl_ctx)
3214 return false;
3215
3216 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3217
Greg Claytonfbea0f62012-11-15 18:05:43 +00003218 if (name_type_mask == eFunctionNameTypeMethod)
3219 {
3220 if (is_cxx_method == false)
3221 return false;
3222 }
3223
3224 if (name_type_mask == eFunctionNameTypeBase)
3225 {
3226 if (is_cxx_method == true)
3227 return false;
3228 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003229 }
3230
3231 // Now we need to check whether the name we got back for this type matches the extra specifications
3232 // that were in the name we're looking up:
3233 if (base_name_start != partial_name || *base_name_end != '\0')
3234 {
3235 // First see if the stuff to the left matches the full name. To do that let's see if
3236 // we can pull out the mips linkage name attribute:
3237
3238 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003239 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00003240 DWARFFormValue form_value;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003241 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3242 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00003243 if (idx == UINT32_MAX)
3244 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003245 if (idx != UINT32_MAX)
3246 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003247 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3248 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003249 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3250 if (mangled_name)
3251 best_name.SetValue (ConstString(mangled_name), true);
3252 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003253 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00003254
3255 if (!best_name)
3256 {
3257 idx = attributes.FindAttributeIndex(DW_AT_name);
3258 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3259 {
3260 const char *name = form_value.AsCString(&get_debug_str_data());
3261 best_name.SetValue (ConstString(name), false);
3262 }
3263 }
3264
3265 if (best_name.GetDemangledName())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003266 {
3267 const char *demangled = best_name.GetDemangledName().GetCString();
3268 if (demangled)
3269 {
3270 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003271 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3272 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003273 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003274 else
3275 {
3276 // Sort out the case where our name is something like "Process::Destroy" and the match is
3277 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3278 // namespace boundaries...
3279
3280 if (partial_name[0] == ':' && partial_name[1] == ':')
3281 {
3282 // The partial name was already on a namespace boundary so all matches are good.
3283 return true;
3284 }
3285 else if (partial_in_demangled == demangled)
3286 {
3287 // They both start the same, so this is an good match.
3288 return true;
3289 }
3290 else
3291 {
3292 if (partial_in_demangled - demangled == 1)
3293 {
3294 // Only one character difference, can't be a namespace boundary...
3295 return false;
3296 }
3297 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3298 {
3299 // We are on a namespace boundary, so this is also good.
3300 return true;
3301 }
3302 else
3303 return false;
3304 }
3305 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003306 }
3307 }
3308 }
3309
3310 return true;
3311}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003312
Greg Clayton0c5cd902010-06-28 21:30:43 +00003313uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003314SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003315 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003316 uint32_t name_type_mask,
3317 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003318 bool append,
3319 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003320{
3321 Timer scoped_timer (__PRETTY_FUNCTION__,
3322 "SymbolFileDWARF::FindFunctions (name = '%s')",
3323 name.AsCString());
3324
Greg Clayton43fe2172013-04-03 02:00:15 +00003325 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3326 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3327
Greg Clayton5160ce52013-03-27 23:08:40 +00003328 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003329
3330 if (log)
3331 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003332 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003333 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3334 name.GetCString(),
3335 name_type_mask,
3336 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003337 }
3338
Greg Clayton0c5cd902010-06-28 21:30:43 +00003339 // If we aren't appending the results to this list, then clear the list
3340 if (!append)
3341 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003342
3343 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3344 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003345
3346 // If name is empty then we won't find anything.
3347 if (name.IsEmpty())
3348 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003349
3350 // Remember how many sc_list are in the list before we search in case
3351 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003352
Jim Ingham4cda6e02011-10-07 22:23:45 +00003353 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00003354
3355 const uint32_t original_size = sc_list.GetSize();
3356
Jim Ingham4cda6e02011-10-07 22:23:45 +00003357 DWARFDebugInfo* info = DebugInfo();
3358 if (info == NULL)
3359 return 0;
3360
Greg Claytonaa044962011-10-13 00:59:38 +00003361 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00003362 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00003363 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003364 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003365 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003366 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003367
3368 DIEArray die_offsets;
3369
3370 uint32_t num_matches = 0;
3371
Greg Clayton43fe2172013-04-03 02:00:15 +00003372 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003373 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003374 // If they asked for the full name, match what they typed. At some point we may
3375 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3376 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003377 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003378 for (uint32_t i = 0; i < num_matches; i++)
3379 {
Greg Clayton95d87902011-11-11 03:16:25 +00003380 const dw_offset_t die_offset = die_offsets[i];
3381 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003382 if (die)
3383 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003384 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3385 continue;
3386
Sean Callanan9df05fb2012-02-10 22:52:19 +00003387 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3388 continue;
3389
Greg Clayton43fe2172013-04-03 02:00:15 +00003390 if (resolved_dies.find(die) == resolved_dies.end())
3391 {
3392 if (ResolveFunction (dwarf_cu, die, sc_list))
3393 resolved_dies.insert(die);
3394 }
Greg Claytonaa044962011-10-13 00:59:38 +00003395 }
Greg Clayton95d87902011-11-11 03:16:25 +00003396 else
3397 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003398 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3399 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003400 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003401 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003402 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003403
3404 if (name_type_mask & eFunctionNameTypeSelector)
3405 {
3406 if (namespace_decl && *namespace_decl)
3407 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00003408
Greg Clayton43fe2172013-04-03 02:00:15 +00003409 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3410 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3411 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00003412
Greg Clayton43fe2172013-04-03 02:00:15 +00003413 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00003414 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003415 const dw_offset_t die_offset = die_offsets[i];
3416 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3417 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00003418 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003419 const char *die_name = die->GetName(this, dwarf_cu);
3420 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00003421 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003422 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3423 continue;
3424
Greg Clayton43fe2172013-04-03 02:00:15 +00003425 if (resolved_dies.find(die) == resolved_dies.end())
3426 {
3427 if (ResolveFunction (dwarf_cu, die, sc_list))
3428 resolved_dies.insert(die);
3429 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003430 }
3431 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003432 else
3433 {
3434 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3435 die_offset, name_cstr);
3436 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003437 }
Greg Clayton43fe2172013-04-03 02:00:15 +00003438 die_offsets.clear();
3439 }
3440
3441 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3442 {
3443 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3444 // extract the base name, look that up, and if there is any other information in the name we were
3445 // passed in we have to post-filter based on that.
3446
3447 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3448 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3449
3450 for (uint32_t i = 0; i < num_matches; i++)
3451 {
3452 const dw_offset_t die_offset = die_offsets[i];
3453 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3454 if (die)
3455 {
3456 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3457 continue;
3458
3459 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3460 continue;
3461
3462 // If we get to here, the die is good, and we should add it:
3463 if (resolved_dies.find(die) == resolved_dies.end())
3464 if (ResolveFunction (dwarf_cu, die, sc_list))
3465 {
3466 bool keep_die = true;
3467 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3468 {
3469 // We are looking for either basenames or methods, so we need to
3470 // trim out the ones we won't want by looking at the type
3471 SymbolContext sc;
3472 if (sc_list.GetLastContext(sc))
3473 {
3474 if (sc.block)
3475 {
3476 // We have an inlined function
3477 }
3478 else if (sc.function)
3479 {
3480 Type *type = sc.function->GetType();
3481
3482 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3483 if (decl_ctx->isRecord())
3484 {
3485 if (name_type_mask & eFunctionNameTypeBase)
3486 {
3487 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3488 keep_die = false;
3489 }
3490 }
3491 else
3492 {
3493 if (name_type_mask & eFunctionNameTypeMethod)
3494 {
3495 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3496 keep_die = false;
3497 }
3498 }
3499 }
3500 }
3501 }
3502 if (keep_die)
3503 resolved_dies.insert(die);
3504 }
3505 }
3506 else
3507 {
3508 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3509 die_offset, name_cstr);
3510 }
3511 }
3512 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00003513 }
3514 }
Greg Clayton7f995132011-10-04 22:41:51 +00003515 }
3516 else
3517 {
3518
3519 // Index the DWARF if we haven't already
3520 if (!m_indexed)
3521 Index ();
3522
Greg Clayton7f995132011-10-04 22:41:51 +00003523 if (name_type_mask & eFunctionNameTypeFull)
3524 FindFunctions (name, m_function_fullname_index, sc_list);
3525
Jim Ingham4cda6e02011-10-07 22:23:45 +00003526 DIEArray die_offsets;
3527 DWARFCompileUnit *dwarf_cu = NULL;
3528
Greg Clayton43fe2172013-04-03 02:00:15 +00003529 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003530 {
Greg Clayton43fe2172013-04-03 02:00:15 +00003531 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003532 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003533 {
Greg Claytonaa044962011-10-13 00:59:38 +00003534 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3535 if (die)
3536 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003537 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3538 continue;
3539
Sean Callanan213fdb82011-10-13 01:49:10 +00003540 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3541 continue;
3542
Greg Claytonaa044962011-10-13 00:59:38 +00003543 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003544 if (resolved_dies.find(die) == resolved_dies.end())
3545 {
3546 if (ResolveFunction (dwarf_cu, die, sc_list))
3547 resolved_dies.insert(die);
3548 }
Greg Claytonaa044962011-10-13 00:59:38 +00003549 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003550 }
3551 die_offsets.clear();
3552 }
3553
Greg Clayton43fe2172013-04-03 02:00:15 +00003554 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003555 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003556 if (namespace_decl && *namespace_decl)
3557 return 0; // no methods in namespaces
3558
Greg Clayton43fe2172013-04-03 02:00:15 +00003559 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003560 {
Greg Claytonaa044962011-10-13 00:59:38 +00003561 for (uint32_t i = 0; i < num_base; i++)
3562 {
3563 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3564 if (die)
3565 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00003566 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3567 continue;
3568
Greg Claytonaa044962011-10-13 00:59:38 +00003569 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00003570 if (resolved_dies.find(die) == resolved_dies.end())
3571 {
3572 if (ResolveFunction (dwarf_cu, die, sc_list))
3573 resolved_dies.insert(die);
3574 }
Greg Claytonaa044962011-10-13 00:59:38 +00003575 }
3576 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003577 }
3578 die_offsets.clear();
3579 }
Greg Clayton7f995132011-10-04 22:41:51 +00003580
Greg Clayton43fe2172013-04-03 02:00:15 +00003581 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003582 {
Greg Clayton7f995132011-10-04 22:41:51 +00003583 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003584 }
3585
Greg Clayton4d01ace2011-09-29 16:58:15 +00003586 }
3587
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003588 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003589 const uint32_t num_matches = sc_list.GetSize() - original_size;
3590
3591 if (log && num_matches > 0)
3592 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003593 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003594 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3595 name.GetCString(),
3596 name_type_mask,
3597 append,
3598 num_matches);
3599 }
3600 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601}
3602
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003603uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003604SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003605{
3606 Timer scoped_timer (__PRETTY_FUNCTION__,
3607 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3608 regex.GetText());
3609
Greg Clayton5160ce52013-03-27 23:08:40 +00003610 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003611
3612 if (log)
3613 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003614 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003615 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3616 regex.GetText(),
3617 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003618 }
3619
3620
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003621 // If we aren't appending the results to this list, then clear the list
3622 if (!append)
3623 sc_list.Clear();
3624
3625 // Remember how many sc_list are in the list before we search in case
3626 // we are appending the results to a variable list.
3627 uint32_t original_size = sc_list.GetSize();
3628
Greg Clayton97fbc342011-10-20 22:30:33 +00003629 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003630 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003631 if (m_apple_names_ap.get())
3632 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003633 }
3634 else
3635 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003636 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003637 if (!m_indexed)
3638 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003639
Greg Clayton7f995132011-10-04 22:41:51 +00003640 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003641
Greg Clayton7f995132011-10-04 22:41:51 +00003642 FindFunctions (regex, m_function_fullname_index, sc_list);
3643 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003644
3645 // Return the number of variable that were appended to the list
3646 return sc_list.GetSize() - original_size;
3647}
Jim Ingham318c9f22011-08-26 19:44:13 +00003648
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003649uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003650SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3651 const ConstString &name,
3652 const lldb_private::ClangNamespaceDecl *namespace_decl,
3653 bool append,
3654 uint32_t max_matches,
3655 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003656{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003657 DWARFDebugInfo* info = DebugInfo();
3658 if (info == NULL)
3659 return 0;
3660
Greg Clayton5160ce52013-03-27 23:08:40 +00003661 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003662
3663 if (log)
3664 {
Greg Clayton437a1352012-04-09 22:43:43 +00003665 if (namespace_decl)
3666 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003667 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003668 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3669 name.GetCString(),
3670 namespace_decl->GetNamespaceDecl(),
3671 namespace_decl->GetQualifiedName().c_str(),
3672 append,
3673 max_matches);
3674 }
3675 else
3676 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003677 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003678 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3679 name.GetCString(),
3680 append,
3681 max_matches);
3682 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003683 }
3684
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003685 // If we aren't appending the results to this list, then clear the list
3686 if (!append)
3687 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003688
3689 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3690 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003691
Greg Claytond4a2b372011-09-12 23:21:58 +00003692 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003693
Greg Clayton97fbc342011-10-20 22:30:33 +00003694 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003695 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003696 if (m_apple_types_ap.get())
3697 {
3698 const char *name_cstr = name.GetCString();
3699 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3700 }
Greg Clayton7f995132011-10-04 22:41:51 +00003701 }
3702 else
3703 {
3704 if (!m_indexed)
3705 Index ();
3706
3707 m_type_index.Find (name, die_offsets);
3708 }
3709
Greg Clayton437a1352012-04-09 22:43:43 +00003710 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003711
Greg Clayton437a1352012-04-09 22:43:43 +00003712 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003713 {
Greg Clayton7f995132011-10-04 22:41:51 +00003714 const uint32_t initial_types_size = types.GetSize();
3715 DWARFCompileUnit* dwarf_cu = NULL;
3716 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003717 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003718 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003719 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003720 const dw_offset_t die_offset = die_offsets[i];
3721 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3722
Greg Clayton95d87902011-11-11 03:16:25 +00003723 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003724 {
Greg Clayton95d87902011-11-11 03:16:25 +00003725 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3726 continue;
3727
3728 Type *matching_type = ResolveType (dwarf_cu, die);
3729 if (matching_type)
3730 {
3731 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003732 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003733 if (types.GetSize() >= max_matches)
3734 break;
3735 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003736 }
Greg Clayton95d87902011-11-11 03:16:25 +00003737 else
3738 {
3739 if (m_using_apple_tables)
3740 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003741 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3742 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003743 }
3744 }
3745
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003746 }
Greg Clayton437a1352012-04-09 22:43:43 +00003747 const uint32_t num_matches = types.GetSize() - initial_types_size;
3748 if (log && num_matches)
3749 {
3750 if (namespace_decl)
3751 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003752 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003753 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3754 name.GetCString(),
3755 namespace_decl->GetNamespaceDecl(),
3756 namespace_decl->GetQualifiedName().c_str(),
3757 append,
3758 max_matches,
3759 num_matches);
3760 }
3761 else
3762 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003763 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003764 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3765 name.GetCString(),
3766 append,
3767 max_matches,
3768 num_matches);
3769 }
3770 }
3771 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003772 }
Greg Clayton7f995132011-10-04 22:41:51 +00003773 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003774}
3775
3776
Greg Clayton526e5af2010-11-13 03:52:47 +00003777ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003778SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003779 const ConstString &name,
3780 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003781{
Greg Clayton5160ce52013-03-27 23:08:40 +00003782 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003783
3784 if (log)
3785 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003786 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003787 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3788 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003789 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003790
3791 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3792 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003793
Greg Clayton526e5af2010-11-13 03:52:47 +00003794 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003795 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003796 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003797 {
Greg Clayton7f995132011-10-04 22:41:51 +00003798 DIEArray die_offsets;
3799
Greg Clayton526e5af2010-11-13 03:52:47 +00003800 // Index if we already haven't to make sure the compile units
3801 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003802 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003803 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003804 if (m_apple_namespaces_ap.get())
3805 {
3806 const char *name_cstr = name.GetCString();
3807 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3808 }
Greg Clayton7f995132011-10-04 22:41:51 +00003809 }
3810 else
3811 {
3812 if (!m_indexed)
3813 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003814
Greg Clayton7f995132011-10-04 22:41:51 +00003815 m_namespace_index.Find (name, die_offsets);
3816 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003817
3818 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003819 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003820 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003821 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003822 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003823 DWARFDebugInfo* debug_info = DebugInfo();
3824 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003825 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003826 const dw_offset_t die_offset = die_offsets[i];
3827 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003828
Greg Clayton95d87902011-11-11 03:16:25 +00003829 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003830 {
Greg Clayton95d87902011-11-11 03:16:25 +00003831 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3832 continue;
3833
3834 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3835 if (clang_namespace_decl)
3836 {
3837 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3838 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003839 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003840 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003841 }
Greg Clayton95d87902011-11-11 03:16:25 +00003842 else
3843 {
3844 if (m_using_apple_tables)
3845 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003846 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3847 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003848 }
3849 }
3850
Greg Clayton526e5af2010-11-13 03:52:47 +00003851 }
3852 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003853 }
Greg Clayton437a1352012-04-09 22:43:43 +00003854 if (log && namespace_decl.GetNamespaceDecl())
3855 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003856 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton437a1352012-04-09 22:43:43 +00003857 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3858 name.GetCString(),
3859 namespace_decl.GetNamespaceDecl(),
3860 namespace_decl.GetQualifiedName().c_str());
3861 }
3862
Greg Clayton526e5af2010-11-13 03:52:47 +00003863 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003864}
3865
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003866uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003867SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003868{
3869 // Remember how many sc_list are in the list before we search in case
3870 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003871 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003872
3873 const uint32_t num_die_offsets = die_offsets.size();
3874 // Parse all of the types we found from the pubtypes matches
3875 uint32_t i;
3876 uint32_t num_matches = 0;
3877 for (i = 0; i < num_die_offsets; ++i)
3878 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003879 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3880 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003881 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003882 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003883 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003884 ++num_matches;
3885 if (num_matches >= max_matches)
3886 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003887 }
3888 }
3889
3890 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003891 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003892}
3893
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003894
3895size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003896SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3897 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003898 DWARFCompileUnit* dwarf_cu,
3899 const DWARFDebugInfoEntry *parent_die,
3900 bool skip_artificial,
3901 bool &is_static,
3902 TypeList* type_list,
3903 std::vector<clang_type_t>& function_param_types,
3904 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003905 unsigned &type_quals,
3906 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003907{
3908 if (parent_die == NULL)
3909 return 0;
3910
Greg Claytond88d7592010-09-15 08:33:30 +00003911 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3912
Greg Clayton7fedea22010-11-16 02:10:54 +00003913 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003914 const DWARFDebugInfoEntry *die;
3915 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3916 {
3917 dw_tag_t tag = die->Tag();
3918 switch (tag)
3919 {
3920 case DW_TAG_formal_parameter:
3921 {
3922 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003923 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003924 if (num_attributes > 0)
3925 {
3926 const char *name = NULL;
3927 Declaration decl;
3928 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003929 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003930 // one of None, Auto, Register, Extern, Static, PrivateExtern
3931
Sean Callanane2ef6e32010-09-23 03:01:22 +00003932 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003933 uint32_t i;
3934 for (i=0; i<num_attributes; ++i)
3935 {
3936 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3937 DWARFFormValue form_value;
3938 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3939 {
3940 switch (attr)
3941 {
3942 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3943 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3944 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3945 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3946 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003947 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003948 case DW_AT_location:
3949 // if (form_value.BlockData())
3950 // {
3951 // const DataExtractor& debug_info_data = debug_info();
3952 // uint32_t block_length = form_value.Unsigned();
3953 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3954 // }
3955 // else
3956 // {
3957 // }
3958 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003959 case DW_AT_const_value:
3960 case DW_AT_default_value:
3961 case DW_AT_description:
3962 case DW_AT_endianity:
3963 case DW_AT_is_optional:
3964 case DW_AT_segment:
3965 case DW_AT_variable_parameter:
3966 default:
3967 case DW_AT_abstract_origin:
3968 case DW_AT_sibling:
3969 break;
3970 }
3971 }
3972 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003973
Greg Clayton0fffff52010-09-24 05:15:53 +00003974 bool skip = false;
3975 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003976 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003977 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003978 {
3979 // In order to determine if a C++ member function is
3980 // "const" we have to look at the const-ness of "this"...
3981 // Ugly, but that
3982 if (arg_idx == 0)
3983 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003984 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003985 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003986 // Often times compilers omit the "this" name for the
3987 // specification DIEs, so we can't rely upon the name
3988 // being in the formal parameter DIE...
3989 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003990 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003991 Type *this_type = ResolveTypeUID (param_type_die_offset);
3992 if (this_type)
3993 {
3994 uint32_t encoding_mask = this_type->GetEncodingMask();
3995 if (encoding_mask & Type::eEncodingIsPointerUID)
3996 {
3997 is_static = false;
3998
3999 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4000 type_quals |= clang::Qualifiers::Const;
4001 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4002 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004003 }
4004 }
4005 }
4006 }
4007 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004008 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004009 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004010 else
4011 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004012
Greg Clayton0fffff52010-09-24 05:15:53 +00004013 // HACK: Objective C formal parameters "self" and "_cmd"
4014 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004015 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4016 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004017 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004018 switch (comp_unit->GetLanguage())
4019 {
4020 case eLanguageTypeObjC:
4021 case eLanguageTypeObjC_plus_plus:
4022 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4023 skip = true;
4024 break;
4025 default:
4026 break;
4027 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004028 }
4029 }
4030 }
4031
4032 if (!skip)
4033 {
4034 Type *type = ResolveTypeUID(param_type_die_offset);
4035 if (type)
4036 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004037 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004038
Greg Clayton42ce2f32011-12-12 21:50:19 +00004039 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4040 type->GetClangForwardType(),
4041 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004042 assert(param_var_decl);
4043 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004044
Greg Claytond0029442013-03-27 01:48:02 +00004045 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004046 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004047 }
4048 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004049 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004050 }
4051 break;
4052
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004053 case DW_TAG_template_type_parameter:
4054 case DW_TAG_template_value_parameter:
4055 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4056 break;
4057
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004058 default:
4059 break;
4060 }
4061 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004062 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004063}
4064
4065size_t
4066SymbolFileDWARF::ParseChildEnumerators
4067(
4068 const SymbolContext& sc,
Greg Clayton3e067532013-03-05 23:54:39 +00004069 clang_type_t enumerator_clang_type,
4070 bool is_signed,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004071 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004072 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004073 const DWARFDebugInfoEntry *parent_die
4074)
4075{
4076 if (parent_die == NULL)
4077 return 0;
4078
4079 size_t enumerators_added = 0;
4080 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004081 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4082
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004083 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4084 {
4085 const dw_tag_t tag = die->Tag();
4086 if (tag == DW_TAG_enumerator)
4087 {
4088 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004089 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004090 if (num_child_attributes > 0)
4091 {
4092 const char *name = NULL;
4093 bool got_value = false;
4094 int64_t enum_value = 0;
4095 Declaration decl;
4096
4097 uint32_t i;
4098 for (i=0; i<num_child_attributes; ++i)
4099 {
4100 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4101 DWARFFormValue form_value;
4102 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4103 {
4104 switch (attr)
4105 {
4106 case DW_AT_const_value:
4107 got_value = true;
Greg Clayton3e067532013-03-05 23:54:39 +00004108 if (is_signed)
4109 enum_value = form_value.Signed();
4110 else
4111 enum_value = form_value.Unsigned();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004112 break;
4113
4114 case DW_AT_name:
4115 name = form_value.AsCString(&get_debug_str_data());
4116 break;
4117
4118 case DW_AT_description:
4119 default:
4120 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4121 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4122 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4123 case DW_AT_sibling:
4124 break;
4125 }
4126 }
4127 }
4128
4129 if (name && name[0] && got_value)
4130 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004131 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4132 enumerator_clang_type,
4133 decl,
4134 name,
4135 enum_value,
4136 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137 ++enumerators_added;
4138 }
4139 }
4140 }
4141 }
4142 return enumerators_added;
4143}
4144
4145void
4146SymbolFileDWARF::ParseChildArrayInfo
4147(
4148 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004149 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004150 const DWARFDebugInfoEntry *parent_die,
4151 int64_t& first_index,
4152 std::vector<uint64_t>& element_orders,
4153 uint32_t& byte_stride,
4154 uint32_t& bit_stride
4155)
4156{
4157 if (parent_die == NULL)
4158 return;
4159
4160 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004161 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004162 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4163 {
4164 const dw_tag_t tag = die->Tag();
4165 switch (tag)
4166 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004167 case DW_TAG_subrange_type:
4168 {
4169 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004170 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004171 if (num_child_attributes > 0)
4172 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173 uint64_t num_elements = 0;
4174 uint64_t lower_bound = 0;
4175 uint64_t upper_bound = 0;
Greg Clayton4ef877f2012-12-06 02:33:54 +00004176 bool upper_bound_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004177 uint32_t i;
4178 for (i=0; i<num_child_attributes; ++i)
4179 {
4180 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4181 DWARFFormValue form_value;
4182 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4183 {
4184 switch (attr)
4185 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004186 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004187 break;
4188
4189 case DW_AT_count:
4190 num_elements = form_value.Unsigned();
4191 break;
4192
4193 case DW_AT_bit_stride:
4194 bit_stride = form_value.Unsigned();
4195 break;
4196
4197 case DW_AT_byte_stride:
4198 byte_stride = form_value.Unsigned();
4199 break;
4200
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004201 case DW_AT_lower_bound:
4202 lower_bound = form_value.Unsigned();
4203 break;
4204
4205 case DW_AT_upper_bound:
Greg Clayton4ef877f2012-12-06 02:33:54 +00004206 upper_bound_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004207 upper_bound = form_value.Unsigned();
4208 break;
4209
4210 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004211 case DW_AT_abstract_origin:
4212 case DW_AT_accessibility:
4213 case DW_AT_allocated:
4214 case DW_AT_associated:
4215 case DW_AT_data_location:
4216 case DW_AT_declaration:
4217 case DW_AT_description:
4218 case DW_AT_sibling:
4219 case DW_AT_threads_scaled:
4220 case DW_AT_type:
4221 case DW_AT_visibility:
4222 break;
4223 }
4224 }
4225 }
4226
Greg Claytone6a07792012-12-05 21:59:39 +00004227 if (num_elements == 0)
4228 {
Greg Clayton4ef877f2012-12-06 02:33:54 +00004229 if (upper_bound_valid && upper_bound >= lower_bound)
Greg Claytone6a07792012-12-05 21:59:39 +00004230 num_elements = upper_bound - lower_bound + 1;
4231 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004232
Sean Callananec979ba2012-10-22 23:56:48 +00004233 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004234 }
4235 }
4236 break;
4237 }
4238 }
4239}
4240
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004241TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004242SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004243{
4244 TypeSP type_sp;
4245 if (die != NULL)
4246 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004247 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004248 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004249 if (type_ptr == NULL)
4250 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004251 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004252 assert (lldb_cu);
4253 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004254 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004255 }
4256 else if (type_ptr != DIE_IS_BEING_PARSED)
4257 {
4258 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004259 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004260 }
4261
4262 }
4263 return type_sp;
4264}
4265
4266clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004267SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004268{
4269 if (die_offset != DW_INVALID_OFFSET)
4270 {
4271 DWARFCompileUnitSP cu_sp;
4272 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004273 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004274 }
4275 return NULL;
4276}
4277
Sean Callanan72e49402011-08-05 23:43:37 +00004278clang::DeclContext *
4279SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4280{
4281 if (die_offset != DW_INVALID_OFFSET)
4282 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004283 DWARFDebugInfo* debug_info = DebugInfo();
4284 if (debug_info)
4285 {
4286 DWARFCompileUnitSP cu_sp;
4287 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4288 if (die)
4289 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4290 }
Sean Callanan72e49402011-08-05 23:43:37 +00004291 }
4292 return NULL;
4293}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004294
Greg Clayton96d7d742010-11-10 23:42:09 +00004295clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004296SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004297{
Greg Clayton030a2042011-10-14 21:34:45 +00004298 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004299 {
Greg Clayton030a2042011-10-14 21:34:45 +00004300 // See if we already parsed this namespace DIE and associated it with a
4301 // uniqued namespace declaration
4302 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4303 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004304 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004305 else
4306 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004307 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4308 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004309 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
Greg Clayton5160ce52013-03-27 23:08:40 +00004310 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton9d3d6882011-10-31 23:51:19 +00004311 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004312 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004313 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004314 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004315 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004316 "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 +00004317 GetClangASTContext().getASTContext(),
4318 MakeUserID(die->GetOffset()),
4319 namespace_name,
4320 namespace_decl,
4321 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004322 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004323 else
4324 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004325 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00004326 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004327 GetClangASTContext().getASTContext(),
4328 MakeUserID(die->GetOffset()),
4329 namespace_decl,
4330 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004331 }
Greg Clayton030a2042011-10-14 21:34:45 +00004332 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004333
4334 if (namespace_decl)
4335 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4336 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004337 }
4338 }
4339 return NULL;
4340}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004341
4342clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004343SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004344{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004345 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4346 if (clang_decl_ctx)
4347 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004348 // If this DIE has a specification, or an abstract origin, then trace to those.
4349
Greg Claytoncab36a32011-12-08 05:16:30 +00004350 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004351 if (die_offset != DW_INVALID_OFFSET)
4352 return GetClangDeclContextForDIEOffset (sc, die_offset);
4353
Greg Claytoncab36a32011-12-08 05:16:30 +00004354 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004355 if (die_offset != DW_INVALID_OFFSET)
4356 return GetClangDeclContextForDIEOffset (sc, die_offset);
4357
Greg Clayton5160ce52013-03-27 23:08:40 +00004358 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004359 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004360 GetObjectFile()->GetModule()->LogMessage(log, "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 +00004361 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004362 bool assert_not_being_parsed = true;
4363 ResolveTypeUID (cu, die, assert_not_being_parsed);
4364
Greg Clayton5cf58b92011-10-05 22:22:08 +00004365 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4366
4367 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004368}
4369
4370clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004371SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004372{
Greg Claytonca512b32011-01-14 04:54:56 +00004373 if (m_clang_tu_decl == NULL)
4374 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004375
Greg Clayton2bc22f82011-09-30 03:20:47 +00004376 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004377
4378 if (decl_ctx_die_copy)
4379 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004380
4381 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004382 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004383
Greg Clayton2bc22f82011-09-30 03:20:47 +00004384 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4385 if (pos != m_die_to_decl_ctx.end())
4386 return pos->second;
4387
4388 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004389 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004390 case DW_TAG_compile_unit:
4391 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004392
Greg Clayton2bc22f82011-09-30 03:20:47 +00004393 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004394 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004395 break;
4396
4397 case DW_TAG_structure_type:
4398 case DW_TAG_union_type:
4399 case DW_TAG_class_type:
4400 {
4401 Type* type = ResolveType (cu, decl_ctx_die);
4402 if (type)
4403 {
4404 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4405 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004406 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004407 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4408 if (decl_ctx)
4409 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004410 }
4411 }
Greg Claytonca512b32011-01-14 04:54:56 +00004412 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004413 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004414
Greg Clayton2bc22f82011-09-30 03:20:47 +00004415 default:
4416 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004417 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004418 }
Greg Clayton7a345282010-11-09 23:46:37 +00004419 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004420}
4421
Greg Clayton2bc22f82011-09-30 03:20:47 +00004422
4423const DWARFDebugInfoEntry *
4424SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4425{
4426 if (cu && die)
4427 {
4428 const DWARFDebugInfoEntry * const decl_die = die;
4429
4430 while (die != NULL)
4431 {
4432 // If this is the original DIE that we are searching for a declaration
4433 // for, then don't look in the cache as we don't want our own decl
4434 // context to be our decl context...
4435 if (decl_die != die)
4436 {
4437 switch (die->Tag())
4438 {
4439 case DW_TAG_compile_unit:
4440 case DW_TAG_namespace:
4441 case DW_TAG_structure_type:
4442 case DW_TAG_union_type:
4443 case DW_TAG_class_type:
4444 return die;
4445
4446 default:
4447 break;
4448 }
4449 }
4450
4451 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4452 if (die_offset != DW_INVALID_OFFSET)
4453 {
4454 DWARFCompileUnit *spec_cu = cu;
4455 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4456 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4457 if (spec_die_decl_ctx_die)
4458 return spec_die_decl_ctx_die;
4459 }
4460
4461 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4462 if (die_offset != DW_INVALID_OFFSET)
4463 {
4464 DWARFCompileUnit *abs_cu = cu;
4465 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4466 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4467 if (abs_die_decl_ctx_die)
4468 return abs_die_decl_ctx_die;
4469 }
4470
4471 die = die->GetParent();
4472 }
4473 }
4474 return NULL;
4475}
4476
4477
Greg Clayton901c5ca2011-12-03 04:40:03 +00004478Symbol *
4479SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4480{
4481 Symbol *objc_class_symbol = NULL;
4482 if (m_obj_file)
4483 {
4484 Symtab *symtab = m_obj_file->GetSymtab();
4485 if (symtab)
4486 {
4487 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4488 eSymbolTypeObjCClass,
4489 Symtab::eDebugNo,
4490 Symtab::eVisibilityAny);
4491 }
4492 }
4493 return objc_class_symbol;
4494}
4495
Greg Claytonc7f03b62012-01-12 04:33:28 +00004496// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4497// then we can end up looking through all class types for a complete type and never find
4498// the full definition. We need to know if this attribute is supported, so we determine
4499// this here and cache th result. We also need to worry about the debug map DWARF file
4500// if we are doing darwin DWARF in .o file debugging.
4501bool
4502SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4503{
4504 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4505 {
4506 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4507 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4508 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4509 else
4510 {
4511 DWARFDebugInfo* debug_info = DebugInfo();
4512 const uint32_t num_compile_units = GetNumCompileUnits();
4513 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4514 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004515 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4516 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004517 {
4518 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4519 break;
4520 }
4521 }
4522 }
Greg Clayton1f746072012-08-29 21:13:06 +00004523 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004524 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4525 }
4526 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4527}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004528
4529// This function can be used when a DIE is found that is a forward declaration
4530// DIE and we want to try and find a type that has the complete definition.
4531TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004532SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4533 const ConstString &type_name,
4534 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004535{
4536
4537 TypeSP type_sp;
4538
Greg Claytonc7f03b62012-01-12 04:33:28 +00004539 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004540 return type_sp;
4541
4542 DIEArray die_offsets;
4543
4544 if (m_using_apple_tables)
4545 {
4546 if (m_apple_types_ap.get())
4547 {
4548 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004549 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004550 }
4551 }
4552 else
4553 {
4554 if (!m_indexed)
4555 Index ();
4556
4557 m_type_index.Find (type_name, die_offsets);
4558 }
4559
Greg Clayton901c5ca2011-12-03 04:40:03 +00004560 const size_t num_matches = die_offsets.size();
4561
Greg Clayton901c5ca2011-12-03 04:40:03 +00004562 DWARFCompileUnit* type_cu = NULL;
4563 const DWARFDebugInfoEntry* type_die = NULL;
4564 if (num_matches)
4565 {
4566 DWARFDebugInfo* debug_info = DebugInfo();
4567 for (size_t i=0; i<num_matches; ++i)
4568 {
4569 const dw_offset_t die_offset = die_offsets[i];
4570 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4571
4572 if (type_die)
4573 {
4574 bool try_resolving_type = false;
4575
4576 // Don't try and resolve the DIE we are looking for with the DIE itself!
4577 if (type_die != die)
4578 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004579 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004580 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004581 case DW_TAG_class_type:
4582 case DW_TAG_structure_type:
4583 try_resolving_type = true;
4584 break;
4585 default:
4586 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004587 }
4588 }
4589
4590 if (try_resolving_type)
4591 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004592 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004593 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004594
4595 if (try_resolving_type)
4596 {
4597 Type *resolved_type = ResolveType (type_cu, type_die, false);
4598 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4599 {
Daniel Malead01b2952012-11-29 21:49:15 +00004600 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 +00004601 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004602 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004603 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4604 MakeUserID(type_die->GetOffset()),
4605 MakeUserID(type_cu->GetOffset()));
4606
Greg Claytonc7f03b62012-01-12 04:33:28 +00004607 if (die)
4608 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004609 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004610 break;
4611 }
4612 }
4613 }
4614 }
4615 else
4616 {
4617 if (m_using_apple_tables)
4618 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004619 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4620 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004621 }
4622 }
4623
4624 }
4625 }
4626 return type_sp;
4627}
4628
Greg Claytona8022fa2012-04-24 21:22:41 +00004629
Greg Clayton80c26302012-02-05 06:12:47 +00004630//----------------------------------------------------------------------
4631// This function helps to ensure that the declaration contexts match for
4632// two different DIEs. Often times debug information will refer to a
4633// forward declaration of a type (the equivalent of "struct my_struct;".
4634// There will often be a declaration of that type elsewhere that has the
4635// full definition. When we go looking for the full type "my_struct", we
4636// will find one or more matches in the accelerator tables and we will
4637// then need to make sure the type was in the same declaration context
4638// as the original DIE. This function can efficiently compare two DIEs
4639// and will return true when the declaration context matches, and false
4640// when they don't.
4641//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004642bool
4643SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4644 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4645{
Greg Claytona8022fa2012-04-24 21:22:41 +00004646 if (die1 == die2)
4647 return true;
4648
4649#if defined (LLDB_CONFIGURATION_DEBUG)
4650 // You can't and shouldn't call this function with a compile unit from
4651 // two different SymbolFileDWARF instances.
4652 assert (DebugInfo()->ContainsCompileUnit (cu1));
4653 assert (DebugInfo()->ContainsCompileUnit (cu2));
4654#endif
4655
Greg Clayton890ff562012-02-02 05:48:16 +00004656 DWARFDIECollection decl_ctx_1;
4657 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004658 //The declaration DIE stack is a stack of the declaration context
4659 // DIEs all the way back to the compile unit. If a type "T" is
4660 // declared inside a class "B", and class "B" is declared inside
4661 // a class "A" and class "A" is in a namespace "lldb", and the
4662 // namespace is in a compile unit, there will be a stack of DIEs:
4663 //
4664 // [0] DW_TAG_class_type for "B"
4665 // [1] DW_TAG_class_type for "A"
4666 // [2] DW_TAG_namespace for "lldb"
4667 // [3] DW_TAG_compile_unit for the source file.
4668 //
4669 // We grab both contexts and make sure that everything matches
4670 // all the way back to the compiler unit.
4671
4672 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004673 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004674 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004675 // Make sure the context arrays have the same size, otherwise
4676 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004677 const size_t count1 = decl_ctx_1.Size();
4678 const size_t count2 = decl_ctx_2.Size();
4679 if (count1 != count2)
4680 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004681
4682 // Make sure the DW_TAG values match all the way back up the the
4683 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004684 const DWARFDebugInfoEntry *decl_ctx_die1;
4685 const DWARFDebugInfoEntry *decl_ctx_die2;
4686 size_t i;
4687 for (i=0; i<count1; i++)
4688 {
4689 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4690 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4691 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4692 return false;
4693 }
Greg Clayton890ff562012-02-02 05:48:16 +00004694#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004695
4696 // Make sure the top item in the decl context die array is always
4697 // DW_TAG_compile_unit. If it isn't then something went wrong in
4698 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004699 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004700
Greg Clayton890ff562012-02-02 05:48:16 +00004701#endif
4702 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004703 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004704 for (i=0; i<count1 - 1; i++)
4705 {
4706 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4707 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4708 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004709 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004710 // If the string was from a DW_FORM_strp, then the pointer will often
4711 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004712 if (name1 == name2)
4713 continue;
4714
4715 // Name pointers are not equal, so only compare the strings
4716 // if both are not NULL.
4717 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004718 {
Greg Clayton5569e642012-02-06 01:44:54 +00004719 // If the strings don't compare, we are done...
4720 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004721 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004722 }
4723 else
4724 {
4725 // One name was NULL while the other wasn't
4726 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004727 }
4728 }
Greg Clayton80c26302012-02-05 06:12:47 +00004729 // We made it through all of the checks and the declaration contexts
4730 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004731 return true;
4732}
Greg Clayton220a0072011-12-09 08:48:30 +00004733
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004734// This function can be used when a DIE is found that is a forward declaration
4735// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004736// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004737TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004738SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004739 const DWARFDebugInfoEntry *die,
4740 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004741{
4742 TypeSP type_sp;
4743
Greg Claytona8022fa2012-04-24 21:22:41 +00004744#if defined (LLDB_CONFIGURATION_DEBUG)
4745 // You can't and shouldn't call this function with a compile unit from
4746 // another SymbolFileDWARF instance.
4747 assert (DebugInfo()->ContainsCompileUnit (cu));
4748#endif
4749
Greg Clayton1a65ae12011-01-25 23:55:37 +00004750 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004751 return type_sp;
4752
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004753 std::string qualified_name;
4754
Greg Clayton5160ce52013-03-27 23:08:40 +00004755 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004756 if (log)
4757 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004758 die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004759 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004760 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4761 die->GetOffset(),
4762 qualified_name.c_str(),
4763 type_name.GetCString());
4764 }
4765
Greg Clayton7f995132011-10-04 22:41:51 +00004766 DIEArray die_offsets;
4767
Greg Clayton97fbc342011-10-20 22:30:33 +00004768 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004769 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004770 if (m_apple_types_ap.get())
4771 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004772 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4773 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4774 if (has_tag && has_qualified_name_hash)
Greg Claytond1767f02011-12-08 02:13:16 +00004775 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004776 if (qualified_name.empty())
4777 die->GetQualifiedName(this, cu, qualified_name);
4778
4779 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
4780 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004781 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004782 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
4783 }
4784 else if (has_tag > 1)
4785 {
4786 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004787 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytonae920b62012-01-06 00:17:16 +00004788 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004789 }
4790 else
4791 {
4792 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4793 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004794 }
Greg Clayton7f995132011-10-04 22:41:51 +00004795 }
4796 else
4797 {
4798 if (!m_indexed)
4799 Index ();
4800
4801 m_type_index.Find (type_name, die_offsets);
4802 }
Greg Clayton7f995132011-10-04 22:41:51 +00004803
4804 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004805
Greg Clayton934cb052011-12-03 00:27:05 +00004806 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004807
4808 DWARFCompileUnit* type_cu = NULL;
4809 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004810 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004811 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004812 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004813 for (size_t i=0; i<num_matches; ++i)
4814 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004815 const dw_offset_t die_offset = die_offsets[i];
4816 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004817
Greg Clayton95d87902011-11-11 03:16:25 +00004818 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004819 {
Greg Clayton934cb052011-12-03 00:27:05 +00004820 bool try_resolving_type = false;
4821
4822 // Don't try and resolve the DIE we are looking for with the DIE itself!
4823 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004824 {
Greg Clayton934cb052011-12-03 00:27:05 +00004825 const dw_tag_t type_die_tag = type_die->Tag();
4826 // Make sure the tags match
4827 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004828 {
Greg Clayton934cb052011-12-03 00:27:05 +00004829 // The tags match, lets try resolving this type
4830 try_resolving_type = true;
4831 }
4832 else
4833 {
4834 // The tags don't match, but we need to watch our for a
4835 // forward declaration for a struct and ("struct foo")
4836 // ends up being a class ("class foo { ... };") or
4837 // vice versa.
4838 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004839 {
Greg Clayton934cb052011-12-03 00:27:05 +00004840 case DW_TAG_class_type:
4841 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4842 try_resolving_type = (die_tag == DW_TAG_structure_type);
4843 break;
4844 case DW_TAG_structure_type:
4845 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4846 try_resolving_type = (die_tag == DW_TAG_class_type);
4847 break;
4848 default:
4849 // Tags don't match, don't event try to resolve
4850 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004851 break;
4852 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004853 }
4854 }
Greg Clayton934cb052011-12-03 00:27:05 +00004855
4856 if (try_resolving_type)
4857 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004858 if (log)
4859 {
4860 std::string qualified_name;
4861 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004862 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004863 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4864 die->GetOffset(),
4865 type_name.GetCString(),
4866 type_die->GetOffset(),
4867 qualified_name.c_str());
4868 }
4869
Greg Clayton890ff562012-02-02 05:48:16 +00004870 // Make sure the decl contexts match all the way up
4871 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004872 {
Greg Clayton890ff562012-02-02 05:48:16 +00004873 Type *resolved_type = ResolveType (type_cu, type_die, false);
4874 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4875 {
Daniel Malead01b2952012-11-29 21:49:15 +00004876 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 +00004877 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004878 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004879 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4880 MakeUserID(type_die->GetOffset()),
4881 MakeUserID(type_cu->GetOffset()));
4882
4883 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004884 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004885 break;
4886 }
Greg Clayton934cb052011-12-03 00:27:05 +00004887 }
4888 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004889 else
4890 {
4891 if (log)
4892 {
4893 std::string qualified_name;
4894 type_die->GetQualifiedName(this, cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00004895 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004896 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4897 die->GetOffset(),
4898 type_name.GetCString(),
4899 type_die->GetOffset(),
4900 qualified_name.c_str());
4901 }
4902 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004903 }
Greg Clayton95d87902011-11-11 03:16:25 +00004904 else
4905 {
4906 if (m_using_apple_tables)
4907 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004908 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4909 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004910 }
4911 }
4912
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004913 }
4914 }
4915 return type_sp;
4916}
4917
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004918TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004919SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4920{
4921 TypeSP type_sp;
4922
4923 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4924 if (dwarf_decl_ctx_count > 0)
4925 {
4926 const ConstString type_name(dwarf_decl_ctx[0].name);
4927 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4928
4929 if (type_name)
4930 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004931 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00004932 if (log)
4933 {
Greg Clayton5160ce52013-03-27 23:08:40 +00004934 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00004935 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4936 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4937 dwarf_decl_ctx.GetQualifiedName());
4938 }
4939
4940 DIEArray die_offsets;
4941
4942 if (m_using_apple_tables)
4943 {
4944 if (m_apple_types_ap.get())
4945 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004946 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
4947 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
4948 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00004949 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004950 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
4951 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
4952 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004953 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00004954 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
4955 }
4956 else if (has_tag)
4957 {
4958 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00004959 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00004960 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4961 }
4962 else
4963 {
4964 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4965 }
4966 }
4967 }
4968 else
4969 {
4970 if (!m_indexed)
4971 Index ();
4972
4973 m_type_index.Find (type_name, die_offsets);
4974 }
4975
4976 const size_t num_matches = die_offsets.size();
4977
4978
4979 DWARFCompileUnit* type_cu = NULL;
4980 const DWARFDebugInfoEntry* type_die = NULL;
4981 if (num_matches)
4982 {
4983 DWARFDebugInfo* debug_info = DebugInfo();
4984 for (size_t i=0; i<num_matches; ++i)
4985 {
4986 const dw_offset_t die_offset = die_offsets[i];
4987 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4988
4989 if (type_die)
4990 {
4991 bool try_resolving_type = false;
4992
4993 // Don't try and resolve the DIE we are looking for with the DIE itself!
4994 const dw_tag_t type_tag = type_die->Tag();
4995 // Make sure the tags match
4996 if (type_tag == tag)
4997 {
4998 // The tags match, lets try resolving this type
4999 try_resolving_type = true;
5000 }
5001 else
5002 {
5003 // The tags don't match, but we need to watch our for a
5004 // forward declaration for a struct and ("struct foo")
5005 // ends up being a class ("class foo { ... };") or
5006 // vice versa.
5007 switch (type_tag)
5008 {
5009 case DW_TAG_class_type:
5010 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5011 try_resolving_type = (tag == DW_TAG_structure_type);
5012 break;
5013 case DW_TAG_structure_type:
5014 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5015 try_resolving_type = (tag == DW_TAG_class_type);
5016 break;
5017 default:
5018 // Tags don't match, don't event try to resolve
5019 // using this type whose name matches....
5020 break;
5021 }
5022 }
5023
5024 if (try_resolving_type)
5025 {
5026 DWARFDeclContext type_dwarf_decl_ctx;
5027 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5028
5029 if (log)
5030 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005031 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005032 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5033 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5034 dwarf_decl_ctx.GetQualifiedName(),
5035 type_die->GetOffset(),
5036 type_dwarf_decl_ctx.GetQualifiedName());
5037 }
5038
5039 // Make sure the decl contexts match all the way up
5040 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5041 {
5042 Type *resolved_type = ResolveType (type_cu, type_die, false);
5043 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5044 {
5045 type_sp = resolved_type->shared_from_this();
5046 break;
5047 }
5048 }
5049 }
5050 else
5051 {
5052 if (log)
5053 {
5054 std::string qualified_name;
5055 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00005056 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00005057 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5058 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5059 dwarf_decl_ctx.GetQualifiedName(),
5060 type_die->GetOffset(),
5061 qualified_name.c_str());
5062 }
5063 }
5064 }
5065 else
5066 {
5067 if (m_using_apple_tables)
5068 {
5069 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5070 die_offset, type_name.GetCString());
5071 }
5072 }
5073
5074 }
5075 }
5076 }
5077 }
5078 return type_sp;
5079}
5080
Greg Clayton4116e932012-05-15 02:33:01 +00005081bool
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005082SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005083 Type *class_type,
Greg Clayton4116e932012-05-15 02:33:01 +00005084 DWARFCompileUnit* src_cu,
5085 const DWARFDebugInfoEntry *src_class_die,
5086 DWARFCompileUnit* dst_cu,
Sean Callanan2367f8a2013-02-26 01:12:25 +00005087 const DWARFDebugInfoEntry *dst_class_die,
5088 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
Greg Clayton4116e932012-05-15 02:33:01 +00005089{
5090 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5091 return false;
5092 if (src_class_die->Tag() != dst_class_die->Tag())
5093 return false;
5094
5095 // We need to complete the class type so we can get all of the method types
5096 // parsed so we can then unique those types to their equivalent counterparts
5097 // in "dst_cu" and "dst_class_die"
5098 class_type->GetClangFullType();
5099
5100 const DWARFDebugInfoEntry *src_die;
5101 const DWARFDebugInfoEntry *dst_die;
5102 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5103 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
Greg Clayton65ec1032012-11-12 21:27:20 +00005104 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5105 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
Greg Clayton4116e932012-05-15 02:33:01 +00005106 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5107 {
5108 if (src_die->Tag() == DW_TAG_subprogram)
5109 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005110 // Make sure this is a declaration and not a concrete instance by looking
5111 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5112 // are placed inside the class definitions and shouldn't be included in
5113 // the list of things are are tracking here.
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005114 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
Greg Clayton84afacd2012-11-07 23:09:32 +00005115 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005116 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton84afacd2012-11-07 23:09:32 +00005117 if (src_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005118 {
5119 ConstString src_const_name(src_name);
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005120 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
Greg Clayton65ec1032012-11-12 21:27:20 +00005121 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5122 else
5123 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5124 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005125 }
Greg Clayton4116e932012-05-15 02:33:01 +00005126 }
5127 }
5128 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5129 {
5130 if (dst_die->Tag() == DW_TAG_subprogram)
5131 {
Greg Clayton84afacd2012-11-07 23:09:32 +00005132 // Make sure this is a declaration and not a concrete instance by looking
5133 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5134 // are placed inside the class definitions and shouldn't be included in
5135 // the list of things are are tracking here.
5136 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5137 {
5138 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5139 if (dst_name)
Greg Clayton65ec1032012-11-12 21:27:20 +00005140 {
5141 ConstString dst_const_name(dst_name);
5142 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5143 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5144 else
5145 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5146 }
Greg Clayton84afacd2012-11-07 23:09:32 +00005147 }
Greg Clayton4116e932012-05-15 02:33:01 +00005148 }
5149 }
5150 const uint32_t src_size = src_name_to_die.GetSize ();
5151 const uint32_t dst_size = dst_name_to_die.GetSize ();
Greg Clayton5160ce52013-03-27 23:08:40 +00005152 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005153
5154 // Is everything kosher so we can go through the members at top speed?
5155 bool fast_path = true;
5156
5157 if (src_size != dst_size)
Greg Clayton4116e932012-05-15 02:33:01 +00005158 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005159 if (src_size != 0 && dst_size != 0)
5160 {
5161 if (log)
5162 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)",
5163 src_class_die->GetOffset(),
5164 dst_class_die->GetOffset(),
5165 src_size,
5166 dst_size);
5167 }
5168
5169 fast_path = false;
5170 }
5171
5172 uint32_t idx;
5173
5174 if (fast_path)
5175 {
Greg Clayton4116e932012-05-15 02:33:01 +00005176 for (idx = 0; idx < src_size; ++idx)
5177 {
5178 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5179 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5180
5181 if (src_die->Tag() != dst_die->Tag())
5182 {
5183 if (log)
5184 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)",
5185 src_class_die->GetOffset(),
5186 dst_class_die->GetOffset(),
5187 src_die->GetOffset(),
5188 DW_TAG_value_to_name(src_die->Tag()),
5189 dst_die->GetOffset(),
5190 DW_TAG_value_to_name(src_die->Tag()));
Sean Callanan2367f8a2013-02-26 01:12:25 +00005191 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005192 }
5193
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005194 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
Greg Clayton4116e932012-05-15 02:33:01 +00005195 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5196
5197 // Make sure the names match
5198 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5199 continue;
5200
5201 if (log)
5202 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)",
5203 src_class_die->GetOffset(),
5204 dst_class_die->GetOffset(),
5205 src_die->GetOffset(),
5206 src_name,
5207 dst_die->GetOffset(),
5208 dst_name);
5209
Sean Callanan2367f8a2013-02-26 01:12:25 +00005210 fast_path = false;
Greg Clayton4116e932012-05-15 02:33:01 +00005211 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005212 }
Greg Clayton4116e932012-05-15 02:33:01 +00005213
Sean Callanan2367f8a2013-02-26 01:12:25 +00005214 // Now do the work of linking the DeclContexts and Types.
5215 if (fast_path)
5216 {
5217 // We can do this quickly. Just run across the tables index-for-index since
5218 // we know each node has matching names and tags.
Greg Clayton4116e932012-05-15 02:33:01 +00005219 for (idx = 0; idx < src_size; ++idx)
5220 {
5221 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5222 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5223
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005224 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Greg Clayton4116e932012-05-15 02:33:01 +00005225 if (src_decl_ctx)
5226 {
5227 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005228 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 +00005229 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5230 }
5231 else
5232 {
5233 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005234 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 +00005235 }
5236
5237 Type *src_child_type = m_die_to_type[src_die];
5238 if (src_child_type)
5239 {
5240 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005241 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 +00005242 m_die_to_type[dst_die] = src_child_type;
5243 }
5244 else
5245 {
5246 if (log)
Greg Clayton65ec1032012-11-12 21:27:20 +00005247 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());
5248 }
5249 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005250 }
5251 else
5252 {
5253 // We must do this slowly. For each member of the destination, look
5254 // up a member in the source with the same name, check its tag, and
5255 // unique them if everything matches up. Report failures.
Greg Clayton65ec1032012-11-12 21:27:20 +00005256
Sean Callanan2367f8a2013-02-26 01:12:25 +00005257 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5258 {
5259 src_name_to_die.Sort();
Greg Clayton65ec1032012-11-12 21:27:20 +00005260
Sean Callanan2367f8a2013-02-26 01:12:25 +00005261 for (idx = 0; idx < dst_size; ++idx)
5262 {
5263 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5264 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5265 src_die = src_name_to_die.Find(dst_name, NULL);
5266
5267 if (src_die && (src_die->Tag() == dst_die->Tag()))
5268 {
Greg Clayton5d650c6a2013-02-26 01:31:37 +00005269 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
Sean Callanan2367f8a2013-02-26 01:12:25 +00005270 if (src_decl_ctx)
5271 {
5272 if (log)
5273 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5274 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5275 }
5276 else
5277 {
5278 if (log)
5279 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());
5280 }
5281
5282 Type *src_child_type = m_die_to_type[src_die];
5283 if (src_child_type)
5284 {
5285 if (log)
5286 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());
5287 m_die_to_type[dst_die] = src_child_type;
5288 }
5289 else
5290 {
5291 if (log)
5292 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());
5293 }
5294 }
5295 else
5296 {
5297 if (log)
5298 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
Greg Clayton65ec1032012-11-12 21:27:20 +00005299
Sean Callanan2367f8a2013-02-26 01:12:25 +00005300 failures.push_back(dst_die);
5301 }
5302 }
5303 }
5304 }
5305
5306 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5307 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5308
5309 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5310
5311 if (src_size_artificial && dst_size_artificial)
5312 {
5313 dst_name_to_die_artificial.Sort();
5314
Greg Clayton65ec1032012-11-12 21:27:20 +00005315 for (idx = 0; idx < src_size_artificial; ++idx)
5316 {
5317 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5318 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5319 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5320
5321 if (dst_die)
5322 {
Greg Clayton65ec1032012-11-12 21:27:20 +00005323 // Both classes have the artificial types, link them
5324 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5325 if (src_decl_ctx)
5326 {
5327 if (log)
5328 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5329 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5330 }
5331 else
5332 {
5333 if (log)
5334 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());
5335 }
5336
5337 Type *src_child_type = m_die_to_type[src_die];
5338 if (src_child_type)
5339 {
5340 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00005341 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 +00005342 m_die_to_type[dst_die] = src_child_type;
5343 }
5344 else
5345 {
5346 if (log)
5347 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());
5348 }
5349 }
5350 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005351 }
Greg Clayton65ec1032012-11-12 21:27:20 +00005352
Sean Callanan2367f8a2013-02-26 01:12:25 +00005353 if (dst_size_artificial)
Greg Clayton4116e932012-05-15 02:33:01 +00005354 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00005355 for (idx = 0; idx < dst_size_artificial; ++idx)
5356 {
5357 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5358 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5359 if (log)
5360 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5361
5362 failures.push_back(dst_die);
5363 }
Greg Clayton4116e932012-05-15 02:33:01 +00005364 }
Sean Callanan2367f8a2013-02-26 01:12:25 +00005365
5366 return (failures.size() != 0);
Greg Clayton4116e932012-05-15 02:33:01 +00005367}
Greg Claytona8022fa2012-04-24 21:22:41 +00005368
5369TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005370SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005371{
5372 TypeSP type_sp;
5373
Greg Clayton1be10fc2010-09-29 01:12:09 +00005374 if (type_is_new_ptr)
5375 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005376
5377#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5378 static DIEStack g_die_stack;
5379 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5380#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005381
Sean Callananc7fbf732010-08-06 00:32:49 +00005382 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005383 if (die != NULL)
5384 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005385 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005386 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005387 {
5388 const DWARFDebugInfoEntry *context_die;
5389 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5390
Greg Clayton5160ce52013-03-27 23:08:40 +00005391 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Sean Callanan5b26f272012-02-04 08:49:35 +00005392 die->GetOffset(),
5393 context,
5394 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005395 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005396 die->GetName(this, dwarf_cu));
5397
5398#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5399 scoped_die_logger.Push (dwarf_cu, die);
Greg Clayton5160ce52013-03-27 23:08:40 +00005400 g_die_stack.LogDIEs(log, this);
Greg Clayton1fba87112012-02-09 20:03:49 +00005401#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005402 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005403//
Greg Clayton5160ce52013-03-27 23:08:40 +00005404// Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005405// if (log && dwarf_cu)
5406// {
5407// StreamString s;
5408// die->DumpLocation (this, dwarf_cu, s);
Greg Clayton5160ce52013-03-27 23:08:40 +00005409// GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005410//
5411// }
Jim Ingham16746d12011-08-25 23:21:43 +00005412
Greg Clayton594e5ed2010-09-27 21:07:38 +00005413 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005414 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005415 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005416 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005417 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005418 if (type_is_new_ptr)
5419 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005420
Greg Clayton594e5ed2010-09-27 21:07:38 +00005421 const dw_tag_t tag = die->Tag();
5422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005423 bool is_forward_declaration = false;
5424 DWARFDebugInfoEntry::Attributes attributes;
5425 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005426 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005427 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
Greg Claytonfaac1112013-03-14 18:31:44 +00005428 uint64_t byte_size = 0;
Greg Clayton526e5af2010-11-13 03:52:47 +00005429 Declaration decl;
5430
Greg Clayton4957bf62010-09-30 21:49:03 +00005431 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005432 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005433
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005434 dw_attr_t attr;
5435
5436 switch (tag)
5437 {
5438 case DW_TAG_base_type:
5439 case DW_TAG_pointer_type:
5440 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005441 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005442 case DW_TAG_typedef:
5443 case DW_TAG_const_type:
5444 case DW_TAG_restrict_type:
5445 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005446 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005447 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005448 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005449 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005450
Greg Claytond88d7592010-09-15 08:33:30 +00005451 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005452 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005453 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5454
5455 if (num_attributes > 0)
5456 {
5457 uint32_t i;
5458 for (i=0; i<num_attributes; ++i)
5459 {
5460 attr = attributes.AttributeAtIndex(i);
5461 DWARFFormValue form_value;
5462 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5463 {
5464 switch (attr)
5465 {
5466 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5467 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5468 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5469 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005470
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005471 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005472 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5473 // include the "&"...
5474 if (tag == DW_TAG_reference_type)
5475 {
5476 if (strchr (type_name_cstr, '&') == NULL)
5477 type_name_cstr = NULL;
5478 }
5479 if (type_name_cstr)
5480 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005481 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005482 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005483 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5484 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5485 default:
5486 case DW_AT_sibling:
5487 break;
5488 }
5489 }
5490 }
5491 }
5492
Daniel Malead01b2952012-11-29 21:49:15 +00005493 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 +00005494
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005495 switch (tag)
5496 {
5497 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005498 break;
5499
Greg Claytond4436412011-10-28 21:00:00 +00005500 case DW_TAG_unspecified_type:
5501 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5502 {
5503 resolve_state = Type::eResolveStateFull;
5504 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5505 break;
5506 }
5507 // Fall through to base type below in case we can handle the type there...
5508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005509 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005510 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005511 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5512 encoding,
5513 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005514 break;
5515
Sean Callanance8af862012-05-21 23:31:51 +00005516 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5517 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5518 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5519 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5520 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5521 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5522 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005523 }
5524
Sean Callanan82587052013-01-03 00:05:56 +00005525 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 +00005526 {
Sean Callanan82587052013-01-03 00:05:56 +00005527 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5528
5529 if (translation_unit_is_objc)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005530 {
Sean Callanan82587052013-01-03 00:05:56 +00005531 if (type_name_cstr != NULL)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005532 {
Sean Callanan82587052013-01-03 00:05:56 +00005533 static ConstString g_objc_type_name_id("id");
5534 static ConstString g_objc_type_name_Class("Class");
5535 static ConstString g_objc_type_name_selector("SEL");
5536
5537 if (type_name_const_str == g_objc_type_name_id)
5538 {
5539 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005540 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005541 die->GetOffset(),
5542 DW_TAG_value_to_name(die->Tag()),
5543 die->GetName(this, dwarf_cu));
5544 clang_type = ast.GetBuiltInType_objc_id();
5545 encoding_data_type = Type::eEncodingIsUID;
5546 encoding_uid = LLDB_INVALID_UID;
5547 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005548
Sean Callanan82587052013-01-03 00:05:56 +00005549 }
5550 else if (type_name_const_str == g_objc_type_name_Class)
5551 {
5552 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005553 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005554 die->GetOffset(),
5555 DW_TAG_value_to_name(die->Tag()),
5556 die->GetName(this, dwarf_cu));
5557 clang_type = ast.GetBuiltInType_objc_Class();
5558 encoding_data_type = Type::eEncodingIsUID;
5559 encoding_uid = LLDB_INVALID_UID;
5560 resolve_state = Type::eResolveStateFull;
5561 }
5562 else if (type_name_const_str == g_objc_type_name_selector)
5563 {
5564 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005565 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
Sean Callanan82587052013-01-03 00:05:56 +00005566 die->GetOffset(),
5567 DW_TAG_value_to_name(die->Tag()),
5568 die->GetName(this, dwarf_cu));
5569 clang_type = ast.GetBuiltInType_objc_selector();
5570 encoding_data_type = Type::eEncodingIsUID;
5571 encoding_uid = LLDB_INVALID_UID;
5572 resolve_state = Type::eResolveStateFull;
5573 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005574 }
Sean Callanan82587052013-01-03 00:05:56 +00005575 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
Greg Claytonc7f03b62012-01-12 04:33:28 +00005576 {
Sean Callanan82587052013-01-03 00:05:56 +00005577 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5578
5579 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5580
5581 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5582 {
5583 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5584 {
5585 if (!strcmp(struct_name, "objc_object"))
5586 {
5587 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00005588 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
Sean Callanan82587052013-01-03 00:05:56 +00005589 die->GetOffset(),
5590 DW_TAG_value_to_name(die->Tag()),
5591 die->GetName(this, dwarf_cu));
5592 clang_type = ast.GetBuiltInType_objc_id();
5593 encoding_data_type = Type::eEncodingIsUID;
5594 encoding_uid = LLDB_INVALID_UID;
5595 resolve_state = Type::eResolveStateFull;
5596 }
5597 }
5598 }
Greg Claytonc7f03b62012-01-12 04:33:28 +00005599 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005600 }
5601 }
5602
Greg Clayton81c22f62011-10-19 18:09:39 +00005603 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005604 this,
5605 type_name_const_str,
5606 byte_size,
5607 NULL,
5608 encoding_uid,
5609 encoding_data_type,
5610 &decl,
5611 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005612 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005613
Greg Clayton594e5ed2010-09-27 21:07:38 +00005614 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005615
5616// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5617// if (encoding_type != NULL)
5618// {
5619// if (encoding_type != DIE_IS_BEING_PARSED)
5620// type_sp->SetEncodingType(encoding_type);
5621// else
5622// m_indirect_fixups.push_back(type_sp.get());
5623// }
5624 }
5625 break;
5626
5627 case DW_TAG_structure_type:
5628 case DW_TAG_union_type:
5629 case DW_TAG_class_type:
5630 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005631 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005632 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005633 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005634
Greg Clayton9e409562010-07-28 02:04:09 +00005635 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005636 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005637 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005638 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005639 if (num_attributes > 0)
5640 {
5641 uint32_t i;
5642 for (i=0; i<num_attributes; ++i)
5643 {
5644 attr = attributes.AttributeAtIndex(i);
5645 DWARFFormValue form_value;
5646 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5647 {
5648 switch (attr)
5649 {
Greg Clayton9e409562010-07-28 02:04:09 +00005650 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005651 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5652 {
5653 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5654 // point to the compile unit file, so we clear this invalid value
5655 // so that we can still unique types efficiently.
5656 decl.SetFile(FileSpec ("<invalid>", false));
5657 }
5658 else
5659 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005660 break;
5661
5662 case DW_AT_decl_line:
5663 decl.SetLine(form_value.Unsigned());
5664 break;
5665
5666 case DW_AT_decl_column:
5667 decl.SetColumn(form_value.Unsigned());
5668 break;
5669
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005670 case DW_AT_name:
5671 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005672 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005673 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005674
5675 case DW_AT_byte_size:
5676 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005677 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005678 break;
5679
5680 case DW_AT_accessibility:
5681 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5682 break;
5683
5684 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005685 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005686 break;
5687
5688 case DW_AT_APPLE_runtime_class:
5689 class_language = (LanguageType)form_value.Signed();
5690 break;
5691
Greg Clayton18774842011-11-29 23:40:34 +00005692 case DW_AT_APPLE_objc_complete_type:
5693 is_complete_objc_class = form_value.Signed();
5694 break;
5695
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005696 case DW_AT_allocated:
5697 case DW_AT_associated:
5698 case DW_AT_data_location:
5699 case DW_AT_description:
5700 case DW_AT_start_scope:
5701 case DW_AT_visibility:
5702 default:
5703 case DW_AT_sibling:
5704 break;
5705 }
5706 }
5707 }
5708 }
5709
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005710 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005711
Greg Clayton123edca2012-03-02 00:07:15 +00005712 // Only try and unique the type if it has a name.
5713 if (type_name_const_str &&
5714 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005715 this,
5716 dwarf_cu,
5717 die,
5718 decl,
5719 byte_size_valid ? byte_size : -1,
5720 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005721 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005722 // We have already parsed this type or from another
5723 // compile unit. GCC loves to use the "one definition
5724 // rule" which can result in multiple definitions
5725 // of the same class over and over in each compile
5726 // unit.
5727 type_sp = unique_ast_entry.m_type_sp;
5728 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005729 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005730 m_die_to_type[die] = type_sp.get();
5731 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005732 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005733 }
5734
Daniel Malead01b2952012-11-29 21:49:15 +00005735 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 +00005736
5737 int tag_decl_kind = -1;
5738 AccessType default_accessibility = eAccessNone;
5739 if (tag == DW_TAG_structure_type)
5740 {
5741 tag_decl_kind = clang::TTK_Struct;
5742 default_accessibility = eAccessPublic;
5743 }
5744 else if (tag == DW_TAG_union_type)
5745 {
5746 tag_decl_kind = clang::TTK_Union;
5747 default_accessibility = eAccessPublic;
5748 }
5749 else if (tag == DW_TAG_class_type)
5750 {
5751 tag_decl_kind = clang::TTK_Class;
5752 default_accessibility = eAccessPrivate;
5753 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005754
5755 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5756 die->HasChildren() == false &&
5757 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5758 {
5759 // Work around an issue with clang at the moment where
5760 // forward declarations for objective C classes are emitted
5761 // as:
5762 // DW_TAG_structure_type [2]
5763 // DW_AT_name( "ForwardObjcClass" )
5764 // DW_AT_byte_size( 0x00 )
5765 // DW_AT_decl_file( "..." )
5766 // DW_AT_decl_line( 1 )
5767 //
5768 // Note that there is no DW_AT_declaration and there are
5769 // no children, and the byte size is zero.
5770 is_forward_declaration = true;
5771 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005772
Sean Callanan7457f8d2012-04-25 01:03:57 +00005773 if (class_language == eLanguageTypeObjC ||
5774 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005775 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005776 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005777 {
5778 // We have a valid eSymbolTypeObjCClass class symbol whose
5779 // name matches the current objective C class that we
5780 // are trying to find and this DIE isn't the complete
5781 // definition (we checked is_complete_objc_class above and
5782 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005783 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005784
Greg Clayton1f746072012-08-29 21:13:06 +00005785 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005786 {
5787 // We weren't able to find a full declaration in
5788 // this DWARF, see if we have a declaration anywhere
5789 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005790 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005791 }
5792
5793 if (type_sp)
5794 {
5795 if (log)
5796 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005797 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005798 "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 +00005799 this,
5800 die->GetOffset(),
5801 DW_TAG_value_to_name(tag),
5802 type_name_cstr,
5803 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005804 }
5805
5806 // We found a real definition for this type elsewhere
5807 // so lets use it and cache the fact that we found
5808 // a complete type for this die
5809 m_die_to_type[die] = type_sp.get();
5810 return type_sp;
5811 }
5812 }
5813 }
5814
5815
5816 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005817 {
5818 // We have a forward declaration to a type and we need
5819 // to try and find a full declaration. We look in the
5820 // current type index just in case we have a forward
5821 // declaration followed by an actual declarations in the
5822 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005823 if (log)
5824 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005825 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00005826 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5827 this,
5828 die->GetOffset(),
5829 DW_TAG_value_to_name(tag),
5830 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005831 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005832
Greg Claytona8022fa2012-04-24 21:22:41 +00005833 DWARFDeclContext die_decl_ctx;
5834 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5835
5836 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5837 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005838
Greg Clayton1f746072012-08-29 21:13:06 +00005839 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005840 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005841 // We weren't able to find a full declaration in
5842 // this DWARF, see if we have a declaration anywhere
5843 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005844 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005845 }
5846
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005847 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005848 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005849 if (log)
5850 {
Greg Clayton5160ce52013-03-27 23:08:40 +00005851 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00005852 "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 +00005853 this,
5854 die->GetOffset(),
5855 DW_TAG_value_to_name(tag),
5856 type_name_cstr,
5857 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005858 }
5859
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005860 // We found a real definition for this type elsewhere
5861 // so lets use it and cache the fact that we found
5862 // a complete type for this die
5863 m_die_to_type[die] = type_sp.get();
5864 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005865 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005866 }
5867 assert (tag_decl_kind != -1);
5868 bool clang_type_was_created = false;
5869 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5870 if (clang_type == NULL)
5871 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005872 const DWARFDebugInfoEntry *decl_ctx_die;
5873
5874 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005875 if (accessibility == eAccessNone && decl_ctx)
5876 {
5877 // Check the decl context that contains this class/struct/union.
5878 // If it is a class we must give it an accessability.
5879 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5880 if (DeclKindIsCXXClass (containing_decl_kind))
5881 accessibility = default_accessibility;
5882 }
5883
Greg Claytonc4ffd662013-03-08 01:37:30 +00005884 ClangASTMetadata metadata;
5885 metadata.SetUserID(MakeUserID(die->GetOffset()));
5886 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
5887
Greg Claytonf0705c82011-10-22 03:33:13 +00005888 if (type_name_cstr && strchr (type_name_cstr, '<'))
5889 {
5890 ClangASTContext::TemplateParameterInfos template_param_infos;
5891 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5892 {
5893 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005894 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005895 type_name_cstr,
5896 tag_decl_kind,
5897 template_param_infos);
5898
5899 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5900 class_template_decl,
5901 tag_decl_kind,
5902 template_param_infos);
5903 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5904 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005905
Greg Claytond0029442013-03-27 01:48:02 +00005906 GetClangASTContext().SetMetadata (class_template_decl, metadata);
5907 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005908 }
5909 }
5910
5911 if (!clang_type_was_created)
5912 {
5913 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005914 clang_type = ast.CreateRecordType (decl_ctx,
5915 accessibility,
5916 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005917 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005918 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005919 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005920 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005921 }
5922
5923 // Store a forward declaration to this class type in case any
5924 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005925 // types for function prototypes.
5926 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005927 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005928 this,
5929 type_name_const_str,
5930 byte_size,
5931 NULL,
5932 LLDB_INVALID_UID,
5933 Type::eEncodingIsUID,
5934 &decl,
5935 clang_type,
5936 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005937
5938 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005939
5940
5941 // Add our type to the unique type map so we don't
5942 // end up creating many copies of the same type over
5943 // and over in the ASTContext for our module
5944 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005945 unique_ast_entry.m_symfile = this;
5946 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005947 unique_ast_entry.m_die = die;
5948 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005949 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005950 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5951 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005952
Sean Callanan12014a02011-12-08 23:45:45 +00005953 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005954 {
5955 // Always start the definition for a class type so that
5956 // if the class has child classes or types that require
5957 // the class to be created for use as their decl contexts
5958 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005959 if (die->HasChildren() == false)
5960 {
5961 // No children for this struct/union/class, lets finish it
5962 ast.StartTagDeclarationDefinition (clang_type);
5963 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00005964
5965 if (tag == DW_TAG_structure_type) // this only applies in C
5966 {
5967 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
5968 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
5969
5970 if (record_type)
5971 {
5972 clang::RecordDecl *record_decl = record_type->getDecl();
5973
5974 if (record_decl)
5975 {
5976 LayoutInfo layout_info;
5977
5978 layout_info.alignment = 0;
5979 layout_info.bit_size = 0;
5980
5981 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
5982 }
5983 }
5984 }
Sean Callanan12014a02011-12-08 23:45:45 +00005985 }
5986 else if (clang_type_was_created)
5987 {
Greg Clayton219cf312012-03-30 00:51:13 +00005988 // Start the definition if the class is not objective C since
5989 // the underlying decls respond to isCompleteDefinition(). Objective
5990 // C decls dont' respond to isCompleteDefinition() so we can't
5991 // start the declaration definition right away. For C++ classs/union/structs
5992 // we want to start the definition in case the class is needed as the
5993 // declaration context for a contained class or type without the need
5994 // to complete that type..
5995
Sean Callanan7457f8d2012-04-25 01:03:57 +00005996 if (class_language != eLanguageTypeObjC &&
5997 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00005998 ast.StartTagDeclarationDefinition (clang_type);
5999
Sean Callanan12014a02011-12-08 23:45:45 +00006000 // Leave this as a forward declaration until we need
6001 // to know the details of the type. lldb_private::Type
6002 // will automatically call the SymbolFile virtual function
6003 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6004 // When the definition needs to be defined.
6005 m_forward_decl_die_to_clang_type[die] = clang_type;
6006 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
6007 ClangASTContext::SetHasExternalStorage (clang_type, true);
6008 }
Greg Claytonc615ce42010-11-09 04:42:43 +00006009 }
Greg Claytoncab36a32011-12-08 05:16:30 +00006010
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006011 }
6012 break;
6013
6014 case DW_TAG_enumeration_type:
6015 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006016 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006017 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006018
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006019 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006020
Greg Claytond88d7592010-09-15 08:33:30 +00006021 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006022 if (num_attributes > 0)
6023 {
6024 uint32_t i;
6025
6026 for (i=0; i<num_attributes; ++i)
6027 {
6028 attr = attributes.AttributeAtIndex(i);
6029 DWARFFormValue form_value;
6030 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6031 {
6032 switch (attr)
6033 {
Greg Clayton7a345282010-11-09 23:46:37 +00006034 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6035 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6036 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006037 case DW_AT_name:
6038 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006039 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006040 break;
Greg Clayton7a345282010-11-09 23:46:37 +00006041 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006042 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6043 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6044 case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006045 case DW_AT_allocated:
6046 case DW_AT_associated:
6047 case DW_AT_bit_stride:
6048 case DW_AT_byte_stride:
6049 case DW_AT_data_location:
6050 case DW_AT_description:
6051 case DW_AT_start_scope:
6052 case DW_AT_visibility:
6053 case DW_AT_specification:
6054 case DW_AT_abstract_origin:
6055 case DW_AT_sibling:
6056 break;
6057 }
6058 }
6059 }
6060
Daniel Malead01b2952012-11-29 21:49:15 +00006061 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 +00006062
Greg Clayton1be10fc2010-09-29 01:12:09 +00006063 clang_type_t enumerator_clang_type = NULL;
6064 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
6065 if (clang_type == NULL)
6066 {
Greg Clayton5d14fc02013-03-06 06:23:54 +00006067 if (encoding_uid != DW_INVALID_OFFSET)
6068 {
6069 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6070 if (enumerator_type)
6071 enumerator_clang_type = enumerator_type->GetClangFullType();
6072 }
6073
6074 if (enumerator_clang_type == NULL)
6075 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6076 DW_ATE_signed,
6077 byte_size * 8);
6078
Greg Claytonca512b32011-01-14 04:54:56 +00006079 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00006080 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00006081 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006082 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006083 }
6084 else
6085 {
6086 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00006087 }
6088
Greg Claytona2721472011-06-25 00:44:06 +00006089 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
6090
Greg Clayton81c22f62011-10-19 18:09:39 +00006091 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006092 this,
6093 type_name_const_str,
6094 byte_size,
6095 NULL,
6096 encoding_uid,
6097 Type::eEncodingIsUID,
6098 &decl,
6099 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006100 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006101
Greg Clayton6beaaa62011-01-17 03:46:26 +00006102 ast.StartTagDeclarationDefinition (clang_type);
6103 if (die->HasChildren())
6104 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006105 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Greg Clayton3e067532013-03-05 23:54:39 +00006106 bool is_signed = false;
Greg Clayton5d14fc02013-03-06 06:23:54 +00006107 ast.IsIntegerType(enumerator_clang_type, is_signed);
Greg Clayton3e067532013-03-05 23:54:39 +00006108 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00006109 }
6110 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006111 }
6112 }
6113 break;
6114
Jim Inghamb0be4422010-08-12 01:20:14 +00006115 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006116 case DW_TAG_subprogram:
6117 case DW_TAG_subroutine_type:
6118 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006119 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006120 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006121
Greg Clayton23f59502012-07-17 03:23:13 +00006122 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006123 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00006124 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006125 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00006126 bool is_static = false;
6127 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00006128 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00006129 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00006130 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6131 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00006132 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00006133
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006134 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00006135 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006136
6137
Greg Claytond88d7592010-09-15 08:33:30 +00006138 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006139 if (num_attributes > 0)
6140 {
6141 uint32_t i;
6142 for (i=0; i<num_attributes; ++i)
6143 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00006144 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006145 DWARFFormValue form_value;
6146 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6147 {
6148 switch (attr)
6149 {
6150 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6151 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6152 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6153 case DW_AT_name:
6154 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006155 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006156 break;
6157
Greg Clayton71415542012-12-08 00:24:40 +00006158 case DW_AT_linkage_name:
Greg Clayton23f59502012-07-17 03:23:13 +00006159 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006160 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006161 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006162 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00006163 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
6164 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00006165 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00006166 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6167
Greg Claytonf51de672010-10-01 02:31:07 +00006168
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006169 case DW_AT_external:
6170 if (form_value.Unsigned())
6171 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00006172 if (storage == clang::SC_None)
6173 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006174 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00006175 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006176 }
6177 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006178
Greg Clayton72da3972011-08-16 18:40:23 +00006179 case DW_AT_specification:
6180 specification_die_offset = form_value.Reference(dwarf_cu);
6181 break;
6182
6183 case DW_AT_abstract_origin:
6184 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6185 break;
6186
Jim Ingham379397632012-10-27 02:54:13 +00006187 case DW_AT_object_pointer:
6188 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6189 break;
6190
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006191 case DW_AT_allocated:
6192 case DW_AT_associated:
6193 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006194 case DW_AT_calling_convention:
6195 case DW_AT_data_location:
6196 case DW_AT_elemental:
6197 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006198 case DW_AT_frame_base:
6199 case DW_AT_high_pc:
6200 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006201 case DW_AT_prototyped:
6202 case DW_AT_pure:
6203 case DW_AT_ranges:
6204 case DW_AT_recursive:
6205 case DW_AT_return_addr:
6206 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006207 case DW_AT_start_scope:
6208 case DW_AT_static_link:
6209 case DW_AT_trampoline:
6210 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006211 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 case DW_AT_description:
6213 case DW_AT_sibling:
6214 break;
6215 }
6216 }
6217 }
Greg Clayton24739922010-10-13 03:15:28 +00006218 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006219
Jim Ingham379397632012-10-27 02:54:13 +00006220 std::string object_pointer_name;
6221 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6222 {
6223 // Get the name from the object pointer die
6224 StreamString s;
6225 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6226 {
6227 object_pointer_name.assign(s.GetData());
6228 }
6229 }
6230
Daniel Malead01b2952012-11-29 21:49:15 +00006231 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 +00006232
Greg Clayton24739922010-10-13 03:15:28 +00006233 clang_type_t return_clang_type = NULL;
6234 Type *func_type = NULL;
6235
6236 if (type_die_offset != DW_INVALID_OFFSET)
6237 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006238
Greg Clayton24739922010-10-13 03:15:28 +00006239 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006240 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006241 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006242 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006243
Greg Claytonf51de672010-10-01 02:31:07 +00006244
Greg Clayton24739922010-10-13 03:15:28 +00006245 std::vector<clang_type_t> function_param_types;
6246 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006247
Greg Clayton24739922010-10-13 03:15:28 +00006248 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006249
Greg Claytoncb5860a2011-10-13 23:49:28 +00006250 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6251 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006252 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6253
Greg Claytonf0705c82011-10-22 03:33:13 +00006254 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006255 // Start off static. This will be set to false in ParseChildParameters(...)
6256 // if we find a "this" paramters as the first parameter
6257 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006258 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006259 ClangASTContext::TemplateParameterInfos template_param_infos;
6260
Greg Clayton24739922010-10-13 03:15:28 +00006261 if (die->HasChildren())
6262 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006263 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006264 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006265 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006266 dwarf_cu,
6267 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006268 skip_artificial,
6269 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006270 type_list,
6271 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006272 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006273 type_quals,
6274 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006275 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006276
Greg Clayton24739922010-10-13 03:15:28 +00006277 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006278 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006279 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006280 function_param_types.size(),
6281 is_variadic,
6282 type_quals);
6283
Greg Clayton24739922010-10-13 03:15:28 +00006284 if (type_name_cstr)
6285 {
6286 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006287 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006288 {
Greg Clayton1b3815c2013-01-30 00:18:29 +00006289 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6290 if (objc_method.IsValid(true))
Greg Clayton0fffff52010-09-24 05:15:53 +00006291 {
Greg Clayton24739922010-10-13 03:15:28 +00006292 SymbolContext empty_sc;
6293 clang_type_t class_opaque_type = NULL;
Greg Clayton1b3815c2013-01-30 00:18:29 +00006294 ConstString class_name(objc_method.GetClassName());
Greg Clayton7c810422012-01-18 23:40:49 +00006295 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006296 {
Greg Clayton24739922010-10-13 03:15:28 +00006297 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006298 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006299
6300 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006301 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006302 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6303 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6304 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006305 }
Greg Clayton24739922010-10-13 03:15:28 +00006306 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006307
Greg Clayton24739922010-10-13 03:15:28 +00006308 if (class_opaque_type)
6309 {
6310 // If accessibility isn't set to anything valid, assume public for
6311 // now...
6312 if (accessibility == eAccessNone)
6313 accessibility = eAccessPublic;
6314
Sean Callanan464a5b52012-10-04 22:06:29 +00006315 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6316 type_name_cstr,
6317 clang_type,
Greg Clayton1bbcc032013-03-08 02:42:06 +00006318 accessibility,
6319 is_artificial);
Greg Clayton24739922010-10-13 03:15:28 +00006320 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006321 if (type_handled)
6322 {
6323 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Claytond0029442013-03-27 01:48:02 +00006324 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006325 }
Sean Callananc3a1d562013-02-06 23:21:59 +00006326 else
6327 {
Jason Molendac1a65832013-03-07 22:44:42 +00006328 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
Sean Callananc3a1d562013-02-06 23:21:59 +00006329 die->GetOffset(),
6330 tag,
6331 DW_TAG_value_to_name(tag));
6332 }
Greg Clayton24739922010-10-13 03:15:28 +00006333 }
6334 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006335 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006336 {
6337 // Look at the parent of this DIE and see if is is
6338 // a class or struct and see if this is actually a
6339 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006340 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006341 if (class_type)
6342 {
Greg Clayton4116e932012-05-15 02:33:01 +00006343 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6344 {
6345 // We uniqued the parent class of this function to another class
6346 // so we now need to associate all dies under "decl_ctx_die" to
6347 // DIEs in the DIE for "class_type"...
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006348 SymbolFileDWARF *class_symfile = NULL;
Greg Clayton4116e932012-05-15 02:33:01 +00006349 DWARFCompileUnitSP class_type_cu_sp;
Greg Clayton5d650c6a2013-02-26 01:31:37 +00006350 const DWARFDebugInfoEntry *class_type_die = NULL;
Sean Callanan2367f8a2013-02-26 01:12:25 +00006351
6352 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6353 if (debug_map_symfile)
6354 {
6355 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6356 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6357 }
6358 else
6359 {
6360 class_symfile = this;
6361 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6362 }
Greg Clayton4116e932012-05-15 02:33:01 +00006363 if (class_type_die)
6364 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006365 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6366
6367 CopyUniqueClassMethodTypes (class_symfile,
6368 class_type,
6369 class_type_cu_sp.get(),
6370 class_type_die,
6371 dwarf_cu,
6372 decl_ctx_die,
6373 failures);
6374
6375 // FIXME do something with these failures that's smarter than
6376 // just dropping them on the ground. Unfortunately classes don't
6377 // like having stuff added to them after their definitions are
6378 // complete...
6379
6380 type_ptr = m_die_to_type[die];
6381 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006382 {
Sean Callanan2367f8a2013-02-26 01:12:25 +00006383 type_sp = type_ptr->shared_from_this();
6384 break;
Greg Clayton4116e932012-05-15 02:33:01 +00006385 }
6386 }
6387 }
6388
Greg Clayton72da3972011-08-16 18:40:23 +00006389 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006390 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006391 // We have a specification which we are going to base our function
6392 // prototype off of, so we need this type to be completed so that the
6393 // m_die_to_decl_ctx for the method in the specification has a valid
6394 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006395 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006396 // If we have a specification, then the function type should have been
6397 // made with the specification and not with this die.
6398 DWARFCompileUnitSP spec_cu_sp;
6399 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006400 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006401 if (spec_clang_decl_ctx)
6402 {
6403 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6404 }
6405 else
Jim Inghamc1663042011-09-29 22:12:35 +00006406 {
Daniel Malead01b2952012-11-29 21:49:15 +00006407 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00006408 MakeUserID(die->GetOffset()),
6409 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006410 }
Greg Clayton72da3972011-08-16 18:40:23 +00006411 type_handled = true;
6412 }
6413 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6414 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006415 // We have a specification which we are going to base our function
6416 // prototype off of, so we need this type to be completed so that the
6417 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6418 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006419 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006420
Greg Clayton72da3972011-08-16 18:40:23 +00006421 DWARFCompileUnitSP abs_cu_sp;
6422 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006423 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006424 if (abs_clang_decl_ctx)
6425 {
6426 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6427 }
6428 else
Jim Inghamc1663042011-09-29 22:12:35 +00006429 {
Daniel Malead01b2952012-11-29 21:49:15 +00006430 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 +00006431 MakeUserID(die->GetOffset()),
6432 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006433 }
Greg Clayton72da3972011-08-16 18:40:23 +00006434 type_handled = true;
6435 }
6436 else
6437 {
6438 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6439 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006440 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006441 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006442 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006443 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6444 // in the DWARF for C++ methods... Default to public for now...
6445 if (accessibility == eAccessNone)
6446 accessibility = eAccessPublic;
6447
6448 if (!is_static && !die->HasChildren())
6449 {
6450 // We have a C++ member function with no children (this pointer!)
6451 // and clang will get mad if we try and make a function that isn't
6452 // well formed in the DWARF, so we will just skip it...
6453 type_handled = true;
6454 }
6455 else
6456 {
6457 clang::CXXMethodDecl *cxx_method_decl;
6458 // REMOVE THE CRASH DESCRIPTION BELOW
Daniel Malead01b2952012-11-29 21:49:15 +00006459 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 +00006460 type_name_cstr,
6461 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006462 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006463 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6464 m_obj_file->GetFileSpec().GetFilename().GetCString());
6465
Sean Callananc1b732d2011-11-01 18:07:13 +00006466 const bool is_attr_used = false;
6467
Greg Clayton20568dd2011-10-13 23:13:20 +00006468 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6469 type_name_cstr,
6470 clang_type,
6471 accessibility,
6472 is_virtual,
6473 is_static,
6474 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006475 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006476 is_attr_used,
6477 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006478
Greg Clayton20568dd2011-10-13 23:13:20 +00006479 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006480
6481 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006482 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006483 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6484
6485 Host::SetCrashDescription (NULL);
6486
6487
6488 ClangASTMetadata metadata;
6489 metadata.SetUserID(MakeUserID(die->GetOffset()));
6490
6491 if (!object_pointer_name.empty())
6492 {
6493 metadata.SetObjectPtrName(object_pointer_name.c_str());
6494 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006495 log->Printf ("Setting object pointer name: %s on method object %p.\n",
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006496 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006497 cxx_method_decl);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006498 }
Greg Claytond0029442013-03-27 01:48:02 +00006499 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006500 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006501 }
Greg Clayton72da3972011-08-16 18:40:23 +00006502 }
6503 else
6504 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006505 // We were asked to parse the type for a method in a class, yet the
6506 // class hasn't been asked to complete itself through the
6507 // clang::ExternalASTSource protocol, so we need to just have the
6508 // class complete itself and do things the right way, then our
6509 // DIE should then have an entry in the m_die_to_type map. First
6510 // we need to modify the m_die_to_type so it doesn't think we are
6511 // trying to parse this DIE anymore...
6512 m_die_to_type[die] = NULL;
6513
6514 // Now we get the full type to force our class type to complete itself
6515 // using the clang::ExternalASTSource protocol which will parse all
6516 // base classes and all methods (including the method for this DIE).
6517 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006518
Greg Clayton20568dd2011-10-13 23:13:20 +00006519 // The type for this DIE should have been filled in the function call above
6520 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006521 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006522 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006523 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006524 break;
6525 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006526
6527 // FIXME This is fixing some even uglier behavior but we really need to
6528 // uniq the methods of each class as well as the class itself.
6529 // <rdar://problem/11240464>
6530 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006531 }
Greg Clayton931180e2011-01-27 06:44:37 +00006532 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006533 }
6534 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006535 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006536 }
Greg Clayton24739922010-10-13 03:15:28 +00006537
6538 if (!type_handled)
6539 {
6540 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006541 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6542 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006543 clang_type,
6544 storage,
6545 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006546
6547// if (template_param_infos.GetSize() > 0)
6548// {
6549// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6550// function_decl,
6551// type_name_cstr,
6552// template_param_infos);
6553//
6554// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6555// func_template_decl,
6556// template_param_infos);
6557// }
Greg Clayton24739922010-10-13 03:15:28 +00006558 // Add the decl to our DIE to decl context map
6559 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006560 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006561 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006562 ast.SetFunctionParameters (function_decl,
6563 &function_param_decls.front(),
6564 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006565
Jim Ingham379397632012-10-27 02:54:13 +00006566 ClangASTMetadata metadata;
6567 metadata.SetUserID(MakeUserID(die->GetOffset()));
6568
6569 if (!object_pointer_name.empty())
6570 {
6571 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006572 if (log)
Greg Claytond0029442013-03-27 01:48:02 +00006573 log->Printf ("Setting object pointer name: %s on function object %p.",
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006574 object_pointer_name.c_str(),
Greg Claytond0029442013-03-27 01:48:02 +00006575 function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006576 }
Greg Claytond0029442013-03-27 01:48:02 +00006577 GetClangASTContext().SetMetadata (function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006578 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006579 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006580 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006581 this,
6582 type_name_const_str,
6583 0,
6584 NULL,
6585 LLDB_INVALID_UID,
6586 Type::eEncodingIsUID,
6587 &decl,
6588 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006589 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006590 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006591 }
6592 break;
6593
6594 case DW_TAG_array_type:
6595 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006596 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006597 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006598
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006599 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006600 int64_t first_index = 0;
6601 uint32_t byte_stride = 0;
6602 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006603 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006604
6605 if (num_attributes > 0)
6606 {
6607 uint32_t i;
6608 for (i=0; i<num_attributes; ++i)
6609 {
6610 attr = attributes.AttributeAtIndex(i);
6611 DWARFFormValue form_value;
6612 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6613 {
6614 switch (attr)
6615 {
6616 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6617 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6618 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6619 case DW_AT_name:
6620 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006621 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006622 break;
6623
6624 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006625 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006626 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6627 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006628 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6629 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006630 case DW_AT_allocated:
6631 case DW_AT_associated:
6632 case DW_AT_data_location:
6633 case DW_AT_description:
6634 case DW_AT_ordering:
6635 case DW_AT_start_scope:
6636 case DW_AT_visibility:
6637 case DW_AT_specification:
6638 case DW_AT_abstract_origin:
6639 case DW_AT_sibling:
6640 break;
6641 }
6642 }
6643 }
6644
Daniel Malead01b2952012-11-29 21:49:15 +00006645 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 +00006646
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006647 Type *element_type = ResolveTypeUID(type_die_offset);
6648
6649 if (element_type)
6650 {
6651 std::vector<uint64_t> element_orders;
6652 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6653 if (byte_stride == 0 && bit_stride == 0)
6654 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006655 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006656 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6657 uint64_t num_elements = 0;
6658 std::vector<uint64_t>::const_reverse_iterator pos;
6659 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6660 for (pos = element_orders.rbegin(); pos != end; ++pos)
6661 {
6662 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006663 clang_type = ast.CreateArrayType (array_element_type,
Greg Clayton4ef877f2012-12-06 02:33:54 +00006664 num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006665 array_element_type = clang_type;
Greg Clayton4ef877f2012-12-06 02:33:54 +00006666 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006667 }
6668 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006669 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006670 this,
6671 empty_name,
6672 array_element_bit_stride / 8,
6673 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006674 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006675 Type::eEncodingIsUID,
6676 &decl,
6677 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006678 Type::eResolveStateFull));
6679 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006680 }
6681 }
6682 }
6683 break;
6684
Greg Clayton9b81a312010-06-12 01:20:30 +00006685 case DW_TAG_ptr_to_member_type:
6686 {
6687 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6688 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6689
Greg Claytond88d7592010-09-15 08:33:30 +00006690 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006691
6692 if (num_attributes > 0) {
6693 uint32_t i;
6694 for (i=0; i<num_attributes; ++i)
6695 {
6696 attr = attributes.AttributeAtIndex(i);
6697 DWARFFormValue form_value;
6698 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6699 {
6700 switch (attr)
6701 {
6702 case DW_AT_type:
6703 type_die_offset = form_value.Reference(dwarf_cu); break;
6704 case DW_AT_containing_type:
6705 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6706 }
6707 }
6708 }
6709
6710 Type *pointee_type = ResolveTypeUID(type_die_offset);
6711 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6712
Greg Clayton526e5af2010-11-13 03:52:47 +00006713 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6714 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006715
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006716 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6717 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006718
Greg Clayton526e5af2010-11-13 03:52:47 +00006719 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6720 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006721
Greg Clayton81c22f62011-10-19 18:09:39 +00006722 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006723 this,
6724 type_name_const_str,
6725 byte_size,
6726 NULL,
6727 LLDB_INVALID_UID,
6728 Type::eEncodingIsUID,
6729 NULL,
6730 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006731 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006732 }
6733
6734 break;
6735 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006736 default:
Greg Clayton84afacd2012-11-07 23:09:32 +00006737 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",
6738 die->GetOffset(),
6739 tag,
6740 DW_TAG_value_to_name(tag));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006741 break;
6742 }
6743
6744 if (type_sp.get())
6745 {
6746 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6747 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6748
6749 SymbolContextScope * symbol_context_scope = NULL;
6750 if (sc_parent_tag == DW_TAG_compile_unit)
6751 {
6752 symbol_context_scope = sc.comp_unit;
6753 }
6754 else if (sc.function != NULL)
6755 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006756 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006757 if (symbol_context_scope == NULL)
6758 symbol_context_scope = sc.function;
6759 }
6760
6761 if (symbol_context_scope != NULL)
6762 {
6763 type_sp->SetSymbolContextScope(symbol_context_scope);
6764 }
6765
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006766 // We are ready to put this type into the uniqued list up at the module level
6767 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006768
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006769 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006770 }
6771 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006772 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006773 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006774 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006775 }
6776 }
6777 return type_sp;
6778}
6779
6780size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006781SymbolFileDWARF::ParseTypes
6782(
6783 const SymbolContext& sc,
6784 DWARFCompileUnit* dwarf_cu,
6785 const DWARFDebugInfoEntry *die,
6786 bool parse_siblings,
6787 bool parse_children
6788)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006789{
6790 size_t types_added = 0;
6791 while (die != NULL)
6792 {
6793 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006794 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006795 {
6796 if (type_is_new)
6797 ++types_added;
6798 }
6799
6800 if (parse_children && die->HasChildren())
6801 {
6802 if (die->Tag() == DW_TAG_subprogram)
6803 {
6804 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006805 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006806 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6807 }
6808 else
6809 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6810 }
6811
6812 if (parse_siblings)
6813 die = die->GetSibling();
6814 else
6815 die = NULL;
6816 }
6817 return types_added;
6818}
6819
6820
6821size_t
6822SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6823{
6824 assert(sc.comp_unit && sc.function);
6825 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006826 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006827 if (dwarf_cu)
6828 {
6829 dw_offset_t function_die_offset = sc.function->GetID();
6830 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6831 if (function_die)
6832 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006833 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006834 }
6835 }
6836
6837 return functions_added;
6838}
6839
6840
6841size_t
6842SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6843{
6844 // At least a compile unit must be valid
6845 assert(sc.comp_unit);
6846 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006847 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006848 if (dwarf_cu)
6849 {
6850 if (sc.function)
6851 {
6852 dw_offset_t function_die_offset = sc.function->GetID();
6853 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6854 if (func_die && func_die->HasChildren())
6855 {
6856 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6857 }
6858 }
6859 else
6860 {
6861 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6862 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6863 {
6864 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6865 }
6866 }
6867 }
6868
6869 return types_added;
6870}
6871
6872size_t
6873SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6874{
6875 if (sc.comp_unit != NULL)
6876 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006877 DWARFDebugInfo* info = DebugInfo();
6878 if (info == NULL)
6879 return 0;
6880
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006881 if (sc.function)
6882 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006883 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
6884
6885 if (dwarf_cu == NULL)
6886 return 0;
6887
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006888 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006889
Greg Claytonc7bece562013-01-25 18:06:21 +00006890 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
6891 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00006892 {
6893 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006894
Greg Claytone38a5ed2012-01-05 03:57:59 +00006895 // Let all blocks know they have parse all their variables
6896 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6897 return num_variables;
6898 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006899 }
6900 else if (sc.comp_unit)
6901 {
Greg Clayton9422dd62013-03-04 21:46:16 +00006902 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
6903
6904 if (dwarf_cu == NULL)
6905 return 0;
6906
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006907 uint32_t vars_added = 0;
6908 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6909
6910 if (variables.get() == NULL)
6911 {
6912 variables.reset(new VariableList());
6913 sc.comp_unit->SetVariableList(variables);
6914
Greg Claytond4a2b372011-09-12 23:21:58 +00006915 DWARFCompileUnit* match_dwarf_cu = NULL;
6916 const DWARFDebugInfoEntry* die = NULL;
6917 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006918 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006919 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006920 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006921 {
6922 DWARFMappedHash::DIEInfoArray hash_data_array;
6923 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6924 dwarf_cu->GetNextCompileUnitOffset(),
6925 hash_data_array))
6926 {
6927 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6928 }
6929 }
Greg Clayton7f995132011-10-04 22:41:51 +00006930 }
6931 else
6932 {
6933 // Index if we already haven't to make sure the compile units
6934 // get indexed and make their global DIE index list
6935 if (!m_indexed)
6936 Index ();
6937
6938 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6939 dwarf_cu->GetNextCompileUnitOffset(),
6940 die_offsets);
6941 }
6942
6943 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006944 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006945 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006946 DWARFDebugInfo* debug_info = DebugInfo();
6947 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006948 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006949 const dw_offset_t die_offset = die_offsets[i];
6950 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006951 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006952 {
Greg Clayton95d87902011-11-11 03:16:25 +00006953 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6954 if (var_sp)
6955 {
6956 variables->AddVariableIfUnique (var_sp);
6957 ++vars_added;
6958 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006959 }
Greg Clayton95d87902011-11-11 03:16:25 +00006960 else
6961 {
6962 if (m_using_apple_tables)
6963 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006964 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 +00006965 }
6966 }
6967
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006968 }
6969 }
6970 }
6971 return vars_added;
6972 }
6973 }
6974 return 0;
6975}
6976
6977
6978VariableSP
6979SymbolFileDWARF::ParseVariableDIE
6980(
6981 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006982 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006983 const DWARFDebugInfoEntry *die,
6984 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006985)
6986{
6987
Greg Clayton83c5cd92010-11-14 22:13:40 +00006988 VariableSP var_sp (m_die_to_variable_sp[die]);
6989 if (var_sp)
6990 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006991
6992 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006993
6994 if ((tag == DW_TAG_variable) ||
6995 (tag == DW_TAG_constant) ||
6996 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006997 {
Greg Clayton7f995132011-10-04 22:41:51 +00006998 DWARFDebugInfoEntry::Attributes attributes;
6999 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7000 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007001 {
Greg Clayton7f995132011-10-04 22:41:51 +00007002 const char *name = NULL;
7003 const char *mangled = NULL;
7004 Declaration decl;
7005 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00007006 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00007007 DWARFExpression location;
7008 bool is_external = false;
7009 bool is_artificial = false;
7010 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007011 bool has_explicit_location = false;
Greg Clayton23f59502012-07-17 03:23:13 +00007012 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00007013
7014 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007015 {
Greg Clayton7f995132011-10-04 22:41:51 +00007016 dw_attr_t attr = attributes.AttributeAtIndex(i);
7017 DWARFFormValue form_value;
7018 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007019 {
Greg Clayton7f995132011-10-04 22:41:51 +00007020 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007021 {
Greg Clayton7f995132011-10-04 22:41:51 +00007022 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7023 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7024 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7025 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00007026 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00007027 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00007028 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007029 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
7030 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007031 // If we have already found a DW_AT_location attribute, ignore this attribute.
7032 if (!has_explicit_location)
7033 {
7034 location_is_const_value_data = true;
7035 // The constant value will be either a block, a data value or a string.
7036 const DataExtractor& debug_info_data = get_debug_info_data();
7037 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7038 {
7039 // Retrieve the value as a block expression.
7040 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7041 uint32_t block_length = form_value.Unsigned();
7042 location.CopyOpcodeData(debug_info_data, block_offset, block_length);
7043 }
7044 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7045 {
7046 // Retrieve the value as a data expression.
7047 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7048 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7049 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7050 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7051 }
7052 else
7053 {
7054 // Retrieve the value as a string expression.
7055 if (form_value.Form() == DW_FORM_strp)
7056 {
7057 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7058 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7059 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7060 location.CopyOpcodeData(debug_info_data, data_offset, data_length);
7061 }
7062 else
7063 {
7064 const char *str = form_value.AsCString(&debug_info_data);
7065 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7066 uint32_t string_length = strlen(str) + 1;
7067 location.CopyOpcodeData(debug_info_data, string_offset, string_length);
7068 }
7069 }
7070 }
7071 break;
Greg Clayton7f995132011-10-04 22:41:51 +00007072 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007073 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00007074 location_is_const_value_data = false;
7075 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00007076 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007077 {
Greg Clayton7f995132011-10-04 22:41:51 +00007078 const DataExtractor& debug_info_data = get_debug_info_data();
7079
7080 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7081 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00007082 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007083 }
7084 else
7085 {
7086 const DataExtractor& debug_loc_data = get_debug_loc_data();
7087 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7088
7089 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7090 if (loc_list_length > 0)
7091 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00007092 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00007093 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7094 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7095 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007096 }
7097 }
Greg Clayton7f995132011-10-04 22:41:51 +00007098 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007099
Greg Clayton7f995132011-10-04 22:41:51 +00007100 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00007101 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00007102 case DW_AT_declaration:
7103 case DW_AT_description:
7104 case DW_AT_endianity:
7105 case DW_AT_segment:
7106 case DW_AT_start_scope:
7107 case DW_AT_visibility:
7108 default:
7109 case DW_AT_abstract_origin:
7110 case DW_AT_sibling:
7111 case DW_AT_specification:
7112 break;
7113 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007114 }
7115 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007116
Greg Clayton7f995132011-10-04 22:41:51 +00007117 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007118 {
Greg Clayton7f995132011-10-04 22:41:51 +00007119 ValueType scope = eValueTypeInvalid;
7120
7121 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7122 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007123 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00007124
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007125 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7126 // or static variable, so we have to do a little digging by
7127 // looking at the location of a varaible to see if it contains
7128 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7129 // somewhere because clang likes to combine small global variables
7130 // into the same symbol and have locations like:
7131 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7132 // So if we don't have a DW_TAG_formal_parameter, we can look at
7133 // the location to see if it contains a DW_OP_addr opcode, and
7134 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00007135 if (tag == DW_TAG_formal_parameter)
7136 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00007137 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007138 {
Greg Clayton96c09682012-01-04 22:56:43 +00007139 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00007140 // Check if the location has a DW_OP_addr with any address value...
Greg Clayton9422dd62013-03-04 21:46:16 +00007141 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
Greg Claytond1767f02011-12-08 02:13:16 +00007142 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00007143 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007144 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
Greg Clayton96c09682012-01-04 22:56:43 +00007145 if (op_error)
7146 {
7147 StreamString strm;
7148 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00007149 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 +00007150 }
7151 }
Greg Claytond1767f02011-12-08 02:13:16 +00007152
Greg Clayton9422dd62013-03-04 21:46:16 +00007153 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007154 {
Greg Claytond1767f02011-12-08 02:13:16 +00007155 if (is_external)
Greg Claytond1767f02011-12-08 02:13:16 +00007156 scope = eValueTypeVariableGlobal;
Greg Clayton9422dd62013-03-04 21:46:16 +00007157 else
7158 scope = eValueTypeVariableStatic;
7159
7160
7161 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7162
7163 if (debug_map_symfile)
7164 {
7165 // When leaving the DWARF in the .o files on darwin,
7166 // when we have a global variable that wasn't initialized,
7167 // the .o file might not have allocated a virtual
7168 // address for the global variable. In this case it will
7169 // have created a symbol for the global variable
7170 // that is undefined/data and external and the value will
7171 // be the byte size of the variable. When we do the
7172 // address map in SymbolFileDWARFDebugMap we rely on
7173 // having an address, we need to do some magic here
7174 // so we can get the correct address for our global
7175 // variable. The address for all of these entries
7176 // will be zero, and there will be an undefined symbol
7177 // in this object file, and the executable will have
7178 // a matching symbol with a good address. So here we
7179 // dig up the correct address and replace it in the
7180 // location for the variable, and set the variable's
7181 // symbol context scope to be that of the main executable
7182 // so the file address will resolve correctly.
7183 bool linked_oso_file_addr = false;
7184 if (is_external && location_DW_OP_addr == 0)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007185 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007186
7187 // we have a possible uninitialized extern global
7188 ConstString const_name(mangled ? mangled : name);
7189 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7190 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007191 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007192 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7193 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007194 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007195 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7196 eSymbolTypeData,
7197 Symtab::eDebugYes,
7198 Symtab::eVisibilityExtern);
7199 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007200 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007201 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007202 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007203 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7204 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007205 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007206 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007207 {
Greg Clayton9422dd62013-03-04 21:46:16 +00007208 linked_oso_file_addr = true;
7209 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007210 }
7211 }
7212 }
7213 }
7214 }
7215 }
7216 }
Greg Clayton9422dd62013-03-04 21:46:16 +00007217
7218 if (!linked_oso_file_addr)
7219 {
7220 // The DW_OP_addr is not zero, but it contains a .o file address which
7221 // needs to be linked up correctly.
7222 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7223 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7224 {
7225 // Update the file address for this variable
7226 location.Update_DW_OP_addr (exe_file_addr);
7227 }
7228 else
7229 {
7230 // Variable didn't make it into the final executable
7231 return var_sp;
7232 }
7233 }
Greg Claytond1767f02011-12-08 02:13:16 +00007234 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007235 }
7236 else
Greg Claytond1767f02011-12-08 02:13:16 +00007237 {
7238 scope = eValueTypeVariableLocal;
7239 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007240 }
Greg Clayton7f995132011-10-04 22:41:51 +00007241
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007242 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00007243 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007244 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00007245 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00007246 case DW_TAG_subprogram:
7247 case DW_TAG_inlined_subroutine:
7248 case DW_TAG_lexical_block:
7249 if (sc.function)
7250 {
7251 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7252 if (symbol_context_scope == NULL)
7253 symbol_context_scope = sc.function;
7254 }
7255 break;
7256
7257 default:
7258 symbol_context_scope = sc.comp_unit;
7259 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00007260 }
Greg Clayton7f995132011-10-04 22:41:51 +00007261 }
7262
Greg Clayton5cf58b92011-10-05 22:22:08 +00007263 if (symbol_context_scope)
7264 {
Greg Clayton81c22f62011-10-19 18:09:39 +00007265 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7266 name,
7267 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00007268 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00007269 scope,
7270 symbol_context_scope,
7271 &decl,
7272 location,
7273 is_external,
7274 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00007275
7276 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7277 }
7278 else
7279 {
7280 // Not ready to parse this variable yet. It might be a global
7281 // or static variable that is in a function scope and the function
7282 // in the symbol context wasn't filled in yet
7283 return var_sp;
7284 }
Greg Clayton7f995132011-10-04 22:41:51 +00007285 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007286 }
Greg Clayton7f995132011-10-04 22:41:51 +00007287 // Cache var_sp even if NULL (the variable was just a specification or
7288 // was missing vital information to be able to be displayed in the debugger
7289 // (missing location due to optimization, etc)) so we don't re-parse
7290 // this DIE over and over later...
7291 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007292 }
7293 return var_sp;
7294}
7295
Greg Claytonc662ec82011-06-17 22:10:16 +00007296
7297const DWARFDebugInfoEntry *
7298SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7299 dw_offset_t spec_block_die_offset,
7300 DWARFCompileUnit **result_die_cu_handle)
7301{
7302 // Give the concrete function die specified by "func_die_offset", find the
7303 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7304 // to "spec_block_die_offset"
7305 DWARFDebugInfo* info = DebugInfo();
7306
7307 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7308 if (die)
7309 {
7310 assert (*result_die_cu_handle);
7311 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7312 }
7313 return NULL;
7314}
7315
7316
7317const DWARFDebugInfoEntry *
7318SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7319 const DWARFDebugInfoEntry *die,
7320 dw_offset_t spec_block_die_offset,
7321 DWARFCompileUnit **result_die_cu_handle)
7322{
7323 if (die)
7324 {
7325 switch (die->Tag())
7326 {
7327 case DW_TAG_subprogram:
7328 case DW_TAG_inlined_subroutine:
7329 case DW_TAG_lexical_block:
7330 {
7331 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7332 {
7333 *result_die_cu_handle = dwarf_cu;
7334 return die;
7335 }
7336
7337 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7338 {
7339 *result_die_cu_handle = dwarf_cu;
7340 return die;
7341 }
7342 }
7343 break;
7344 }
7345
7346 // Give the concrete function die specified by "func_die_offset", find the
7347 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7348 // to "spec_block_die_offset"
7349 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7350 {
7351 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7352 child_die,
7353 spec_block_die_offset,
7354 result_die_cu_handle);
7355 if (result_die)
7356 return result_die;
7357 }
7358 }
7359
7360 *result_die_cu_handle = NULL;
7361 return NULL;
7362}
7363
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007364size_t
7365SymbolFileDWARF::ParseVariables
7366(
7367 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007368 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007369 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007370 const DWARFDebugInfoEntry *orig_die,
7371 bool parse_siblings,
7372 bool parse_children,
7373 VariableList* cc_variable_list
7374)
7375{
7376 if (orig_die == NULL)
7377 return 0;
7378
Greg Claytonc662ec82011-06-17 22:10:16 +00007379 VariableListSP variable_list_sp;
7380
7381 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007382 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007383 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007384 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007385 dw_tag_t tag = die->Tag();
7386
7387 // Check to see if we have already parsed this variable or constant?
7388 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007389 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007390 if (cc_variable_list)
7391 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007392 }
7393 else
7394 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007395 // We haven't already parsed it, lets do that now.
7396 if ((tag == DW_TAG_variable) ||
7397 (tag == DW_TAG_constant) ||
7398 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007399 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007400 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007401 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007402 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7403 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7404 switch (parent_tag)
7405 {
7406 case DW_TAG_compile_unit:
7407 if (sc.comp_unit != NULL)
7408 {
7409 variable_list_sp = sc.comp_unit->GetVariableList(false);
7410 if (variable_list_sp.get() == NULL)
7411 {
7412 variable_list_sp.reset(new VariableList());
7413 sc.comp_unit->SetVariableList(variable_list_sp);
7414 }
7415 }
7416 else
7417 {
Daniel Malead01b2952012-11-29 21:49:15 +00007418 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 +00007419 MakeUserID(sc_parent_die->GetOffset()),
7420 DW_TAG_value_to_name (parent_tag),
7421 MakeUserID(orig_die->GetOffset()),
7422 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007423 }
7424 break;
7425
7426 case DW_TAG_subprogram:
7427 case DW_TAG_inlined_subroutine:
7428 case DW_TAG_lexical_block:
7429 if (sc.function != NULL)
7430 {
7431 // Check to see if we already have parsed the variables for the given scope
7432
Greg Clayton81c22f62011-10-19 18:09:39 +00007433 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007434 if (block == NULL)
7435 {
7436 // This must be a specification or abstract origin with
7437 // a concrete block couterpart in the current function. We need
7438 // to find the concrete block so we can correctly add the
7439 // variable to it
7440 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7441 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7442 sc_parent_die->GetOffset(),
7443 &concrete_block_die_cu);
7444 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007445 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007446 }
7447
7448 if (block != NULL)
7449 {
7450 const bool can_create = false;
7451 variable_list_sp = block->GetBlockVariableList (can_create);
7452 if (variable_list_sp.get() == NULL)
7453 {
7454 variable_list_sp.reset(new VariableList());
7455 block->SetVariableList(variable_list_sp);
7456 }
7457 }
7458 }
7459 break;
7460
7461 default:
Daniel Malead01b2952012-11-29 21:49:15 +00007462 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 +00007463 MakeUserID(orig_die->GetOffset()),
7464 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007465 break;
7466 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007467 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007468
7469 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007470 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007471 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7472 if (var_sp)
7473 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007474 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007475 if (cc_variable_list)
7476 cc_variable_list->AddVariableIfUnique (var_sp);
7477 ++vars_added;
7478 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007479 }
7480 }
7481 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007482
7483 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7484
7485 if (!skip_children && parse_children && die->HasChildren())
7486 {
7487 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7488 }
7489
7490 if (parse_siblings)
7491 die = die->GetSibling();
7492 else
7493 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007494 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007495 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007496}
7497
7498//------------------------------------------------------------------
7499// PluginInterface protocol
7500//------------------------------------------------------------------
7501const char *
7502SymbolFileDWARF::GetPluginName()
7503{
7504 return "SymbolFileDWARF";
7505}
7506
7507const char *
7508SymbolFileDWARF::GetShortPluginName()
7509{
7510 return GetPluginNameStatic();
7511}
7512
7513uint32_t
7514SymbolFileDWARF::GetPluginVersion()
7515{
7516 return 1;
7517}
7518
7519void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007520SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7521{
7522 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7523 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7524 if (clang_type)
7525 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7526}
7527
7528void
7529SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7530{
7531 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7532 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7533 if (clang_type)
7534 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7535}
7536
Greg Claytona2721472011-06-25 00:44:06 +00007537void
Sean Callanancc427fa2011-07-30 02:42:06 +00007538SymbolFileDWARF::DumpIndexes ()
7539{
7540 StreamFile s(stdout, false);
7541
7542 s.Printf ("DWARF index for (%s) '%s/%s':",
7543 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7544 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7545 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7546 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7547 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7548 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7549 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7550 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7551 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7552 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7553 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7554}
7555
7556void
7557SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7558 const char *name,
7559 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007560{
Sean Callanancc427fa2011-07-30 02:42:06 +00007561 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007562
7563 if (iter == m_decl_ctx_to_die.end())
7564 return;
7565
Greg Claytoncb5860a2011-10-13 23:49:28 +00007566 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007567 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007568 const DWARFDebugInfoEntry *context_die = *pos;
7569
7570 if (!results)
7571 return;
7572
7573 DWARFDebugInfo* info = DebugInfo();
7574
7575 DIEArray die_offsets;
7576
7577 DWARFCompileUnit* dwarf_cu = NULL;
7578 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007579
7580 if (m_using_apple_tables)
7581 {
7582 if (m_apple_types_ap.get())
7583 m_apple_types_ap->FindByName (name, die_offsets);
7584 }
7585 else
7586 {
7587 if (!m_indexed)
7588 Index ();
7589
7590 m_type_index.Find (ConstString(name), die_offsets);
7591 }
7592
Greg Clayton220a0072011-12-09 08:48:30 +00007593 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007594
7595 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007596 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007597 for (size_t i = 0; i < num_matches; ++i)
7598 {
7599 const dw_offset_t die_offset = die_offsets[i];
7600 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007601
Greg Claytoncb5860a2011-10-13 23:49:28 +00007602 if (die->GetParent() != context_die)
7603 continue;
7604
7605 Type *matching_type = ResolveType (dwarf_cu, die);
7606
Greg Clayton42ce2f32011-12-12 21:50:19 +00007607 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007608 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7609
7610 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7611 {
7612 clang::TagDecl *tag_decl = tag_type->getDecl();
7613 results->push_back(tag_decl);
7614 }
7615 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7616 {
7617 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7618 results->push_back(typedef_decl);
7619 }
Greg Claytona2721472011-06-25 00:44:06 +00007620 }
7621 }
7622 }
7623}
7624
7625void
7626SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007627 const clang::DeclContext *decl_context,
7628 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007629 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7630{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007631
7632 switch (decl_context->getDeclKind())
7633 {
7634 case clang::Decl::Namespace:
7635 case clang::Decl::TranslationUnit:
7636 {
7637 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7638 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7639 }
7640 break;
7641 default:
7642 break;
7643 }
Greg Claytona2721472011-06-25 00:44:06 +00007644}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007645
7646bool
7647SymbolFileDWARF::LayoutRecordType (void *baton,
7648 const clang::RecordDecl *record_decl,
7649 uint64_t &size,
7650 uint64_t &alignment,
7651 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7652 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7653 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7654{
7655 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7656 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7657}
7658
7659
7660bool
7661SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7662 uint64_t &bit_size,
7663 uint64_t &alignment,
7664 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7665 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7666 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7667{
Greg Clayton5160ce52013-03-27 23:08:40 +00007668 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Claytoncaab74e2012-01-28 00:48:57 +00007669 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7670 bool success = false;
7671 base_offsets.clear();
7672 vbase_offsets.clear();
7673 if (pos != m_record_decl_to_layout_map.end())
7674 {
7675 bit_size = pos->second.bit_size;
7676 alignment = pos->second.alignment;
7677 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007678 base_offsets.swap (pos->second.base_offsets);
7679 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007680 m_record_decl_to_layout_map.erase(pos);
7681 success = true;
7682 }
7683 else
7684 {
7685 bit_size = 0;
7686 alignment = 0;
7687 field_offsets.clear();
7688 }
7689
7690 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00007691 GetObjectFile()->GetModule()->LogMessage (log,
Daniel Malead01b2952012-11-29 21:49:15 +00007692 "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 +00007693 record_decl,
7694 bit_size,
7695 alignment,
7696 (uint32_t)field_offsets.size(),
7697 (uint32_t)base_offsets.size(),
7698 (uint32_t)vbase_offsets.size(),
7699 success);
7700 return success;
7701}
7702
7703
Greg Clayton1f746072012-08-29 21:13:06 +00007704SymbolFileDWARFDebugMap *
7705SymbolFileDWARF::GetDebugMapSymfile ()
7706{
7707 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7708 {
7709 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7710 if (module_sp)
7711 {
7712 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7713 if (sym_vendor)
7714 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7715 }
7716 }
7717 return m_debug_map_symfile;
7718}
7719
Greg Claytoncaab74e2012-01-28 00:48:57 +00007720