blob: 69954f41a345a663fcd547eace30c8edb0b506d2 [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();
Greg Clayton43e0af02012-09-18 18:04:04 +0000129 log_strm.Printf("DIEStack[%llu]:\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);
Greg Clayton43e0af02012-09-18 18:04:04 +0000136 log_strm.Printf ("[%llu] 0x%8.8x: %s name='%s'\n",
137 (uint64_t)i,
Greg Clayton1fba87112012-02-09 20:03:49 +0000138 die->GetOffset(),
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
141 }
142 log->PutCString(log_strm.GetData());
143 }
144 void Pop ()
145 {
146 m_dies.pop_back();
147 }
148
149 class ScopedPopper
150 {
151 public:
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
154 m_valid (false)
155 {
156 }
157
158 void
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
160 {
161 m_valid = true;
162 m_die_stack.Push (cu, die);
163 }
164
165 ~ScopedPopper ()
166 {
167 if (m_valid)
168 m_die_stack.Pop();
169 }
170
171
172
173 protected:
174 DIEStack &m_die_stack;
175 bool m_valid;
176 };
177
178protected:
179 struct DIEInfo {
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
181 cu(c),
182 die(d)
183 {
184 }
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
187 };
188 typedef std::vector<DIEInfo> Stack;
189 Stack m_dies;
190};
191#endif
192
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193void
194SymbolFileDWARF::Initialize()
195{
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
199 CreateInstance);
200}
201
202void
203SymbolFileDWARF::Terminate()
204{
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
207}
208
209
210const char *
211SymbolFileDWARF::GetPluginNameStatic()
212{
Greg Claytond4a2b372011-09-12 23:21:58 +0000213 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const char *
217SymbolFileDWARF::GetPluginDescriptionStatic()
218{
219 return "DWARF and DWARF3 debug symbol file reader.";
220}
221
222
223SymbolFile*
224SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
225{
226 return new SymbolFileDWARF(obj_file);
227}
228
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000229TypeList *
230SymbolFileDWARF::GetTypeList ()
231{
Greg Clayton1f746072012-08-29 21:13:06 +0000232 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000233 return m_debug_map_symfile->GetTypeList();
234 return m_obj_file->GetModule()->GetTypeList();
235
236}
237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238//----------------------------------------------------------------------
239// Gets the first parent that is a lexical block, function or inlined
240// subroutine, or compile unit.
241//----------------------------------------------------------------------
242static const DWARFDebugInfoEntry *
243GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
244{
245 const DWARFDebugInfoEntry *die;
246 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
247 {
248 dw_tag_t tag = die->Tag();
249
250 switch (tag)
251 {
252 case DW_TAG_compile_unit:
253 case DW_TAG_subprogram:
254 case DW_TAG_inlined_subroutine:
255 case DW_TAG_lexical_block:
256 return die;
257 }
258 }
259 return NULL;
260}
261
262
Greg Clayton450e3f32010-10-12 02:24:53 +0000263SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
264 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000265 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000266 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000267 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000268 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 m_data_debug_abbrev (),
271 m_data_debug_aranges (),
272 m_data_debug_frame (),
273 m_data_debug_info (),
274 m_data_debug_line (),
275 m_data_debug_loc (),
276 m_data_debug_ranges (),
277 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000278 m_data_apple_names (),
279 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000280 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_info(),
283 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000284 m_apple_names_ap (),
285 m_apple_types_ap (),
286 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000287 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000288 m_function_basename_index(),
289 m_function_fullname_index(),
290 m_function_method_index(),
291 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000292 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000293 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000294 m_type_index(),
295 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000296 m_indexed (false),
297 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000298 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000299 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000300 m_ranges(),
301 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302{
303}
304
305SymbolFileDWARF::~SymbolFileDWARF()
306{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000307 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000308 {
309 ModuleSP module_sp (m_obj_file->GetModule());
310 if (module_sp)
311 module_sp->GetClangASTContext().RemoveExternalSource ();
312 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000313}
314
315static const ConstString &
316GetDWARFMachOSegmentName ()
317{
318 static ConstString g_dwarf_section_name ("__DWARF");
319 return g_dwarf_section_name;
320}
321
Greg Claytone576ab22011-02-15 00:19:15 +0000322UniqueDWARFASTTypeMap &
323SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
324{
Greg Clayton1f746072012-08-29 21:13:06 +0000325 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000326 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
327 return m_unique_ast_type_map;
328}
329
Greg Clayton6beaaa62011-01-17 03:46:26 +0000330ClangASTContext &
331SymbolFileDWARF::GetClangASTContext ()
332{
Greg Clayton1f746072012-08-29 21:13:06 +0000333 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000334 return m_debug_map_symfile->GetClangASTContext ();
335
336 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
337 if (!m_is_external_ast_source)
338 {
339 m_is_external_ast_source = true;
340 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
341 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
342 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000343 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000344 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000346 ast.SetExternalSource (ast_source_ap);
347 }
348 return ast;
349}
350
351void
352SymbolFileDWARF::InitializeObject()
353{
354 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000355 ModuleSP module_sp (m_obj_file->GetModule());
356 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000357 {
358 const SectionList *section_list = m_obj_file->GetSectionList();
359
360 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
361
362 // Memory map the DWARF mach-o segment so we have everything mmap'ed
363 // to keep our heap memory usage down.
364 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000365 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000366 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000367 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000368 if (m_data_apple_names.GetByteSize() > 0)
369 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000370 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
371 if (m_apple_names_ap->IsValid())
372 m_using_apple_tables = true;
373 else
Greg Clayton7f995132011-10-04 22:41:51 +0000374 m_apple_names_ap.reset();
375 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000376 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000377 if (m_data_apple_types.GetByteSize() > 0)
378 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000379 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
380 if (m_apple_types_ap->IsValid())
381 m_using_apple_tables = true;
382 else
Greg Clayton7f995132011-10-04 22:41:51 +0000383 m_apple_types_ap.reset();
384 }
385
386 get_apple_namespaces_data();
387 if (m_data_apple_namespaces.GetByteSize() > 0)
388 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000389 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
390 if (m_apple_namespaces_ap->IsValid())
391 m_using_apple_tables = true;
392 else
Greg Clayton7f995132011-10-04 22:41:51 +0000393 m_apple_namespaces_ap.reset();
394 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000395
Greg Clayton5009f9d2011-10-27 17:55:14 +0000396 get_apple_objc_data();
397 if (m_data_apple_objc.GetByteSize() > 0)
398 {
399 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
400 if (m_apple_objc_ap->IsValid())
401 m_using_apple_tables = true;
402 else
403 m_apple_objc_ap.reset();
404 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407bool
408SymbolFileDWARF::SupportedVersion(uint16_t version)
409{
410 return version == 2 || version == 3;
411}
412
413uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000414SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415{
416 uint32_t abilities = 0;
417 if (m_obj_file != NULL)
418 {
419 const Section* section = NULL;
420 const SectionList *section_list = m_obj_file->GetSectionList();
421 if (section_list == NULL)
422 return 0;
423
424 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 uint64_t debug_info_file_size = 0;
426 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427
Greg Clayton6beaaa62011-01-17 03:46:26 +0000428 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
430 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432
Greg Clayton4ceb9982010-07-21 22:54:26 +0000433 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 if (section != NULL)
435 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000436 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000440 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 else
442 m_flags.Set (flagsGotDebugAbbrevData);
443
Greg Clayton4ceb9982010-07-21 22:54:26 +0000444 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000445 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_flags.Set (flagsGotDebugArangesData);
447
Greg Clayton4ceb9982010-07-21 22:54:26 +0000448 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000449 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 m_flags.Set (flagsGotDebugFrameData);
451
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000454 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 else
456 m_flags.Set (flagsGotDebugLineData);
457
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000459 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 m_flags.Set (flagsGotDebugLocData);
461
Greg Clayton4ceb9982010-07-21 22:54:26 +0000462 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000463 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_flags.Set (flagsGotDebugMacInfoData);
465
Greg Clayton4ceb9982010-07-21 22:54:26 +0000466 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000467 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 m_flags.Set (flagsGotDebugPubNamesData);
469
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000471 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 m_flags.Set (flagsGotDebugPubTypesData);
473
Greg Clayton4ceb9982010-07-21 22:54:26 +0000474 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000475 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_flags.Set (flagsGotDebugRangesData);
477
Greg Clayton4ceb9982010-07-21 22:54:26 +0000478 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000479 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 m_flags.Set (flagsGotDebugStrData);
481 }
Greg Clayton6c596612012-05-18 21:47:20 +0000482 else
483 {
484 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
485 if (symfile_dir_cstr)
486 {
487 if (strcasestr(symfile_dir_cstr, ".dsym"))
488 {
489 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
490 {
491 // We have a dSYM file that didn't have a any debug info.
492 // If the string table has a size of 1, then it was made from
493 // an executable with no debug info, or from an executable that
494 // was stripped.
495 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
496 if (section && section->GetFileSize() == 1)
497 {
498 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
499 }
500 }
501 }
502 }
503 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504
505 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507
508 if (debug_line_file_size > 0)
509 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 }
511 return abilities;
512}
513
514const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000515SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516{
517 if (m_flags.IsClear (got_flag))
518 {
519 m_flags.Set (got_flag);
520 const SectionList *section_list = m_obj_file->GetSectionList();
521 if (section_list)
522 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000523 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
524 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 {
526 // See if we memory mapped the DWARF segment?
527 if (m_dwarf_data.GetByteSize())
528 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000529 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 }
531 else
532 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000533 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 data.Clear();
535 }
536 }
537 }
538 }
539 return data;
540}
541
542const DataExtractor&
543SymbolFileDWARF::get_debug_abbrev_data()
544{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000545 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000549SymbolFileDWARF::get_debug_aranges_data()
550{
551 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
552}
553
554const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555SymbolFileDWARF::get_debug_frame_data()
556{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000557 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560const DataExtractor&
561SymbolFileDWARF::get_debug_info_data()
562{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000563 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566const DataExtractor&
567SymbolFileDWARF::get_debug_line_data()
568{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000569 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570}
571
572const DataExtractor&
573SymbolFileDWARF::get_debug_loc_data()
574{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000575 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576}
577
578const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579SymbolFileDWARF::get_debug_ranges_data()
580{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000581 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582}
583
584const DataExtractor&
585SymbolFileDWARF::get_debug_str_data()
586{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000587 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Greg Claytonf9eec202011-09-01 23:16:13 +0000590const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000591SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000592{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000593 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000594}
595
596const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000597SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000598{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000599 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000600}
601
Greg Clayton7f995132011-10-04 22:41:51 +0000602const DataExtractor&
603SymbolFileDWARF::get_apple_namespaces_data()
604{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000605 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
606}
607
608const DataExtractor&
609SymbolFileDWARF::get_apple_objc_data()
610{
611 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000612}
613
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615DWARFDebugAbbrev*
616SymbolFileDWARF::DebugAbbrev()
617{
618 if (m_abbr.get() == NULL)
619 {
620 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
621 if (debug_abbrev_data.GetByteSize() > 0)
622 {
623 m_abbr.reset(new DWARFDebugAbbrev());
624 if (m_abbr.get())
625 m_abbr->Parse(debug_abbrev_data);
626 }
627 }
628 return m_abbr.get();
629}
630
631const DWARFDebugAbbrev*
632SymbolFileDWARF::DebugAbbrev() const
633{
634 return m_abbr.get();
635}
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637
638DWARFDebugInfo*
639SymbolFileDWARF::DebugInfo()
640{
641 if (m_info.get() == NULL)
642 {
643 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
644 if (get_debug_info_data().GetByteSize() > 0)
645 {
646 m_info.reset(new DWARFDebugInfo());
647 if (m_info.get())
648 {
649 m_info->SetDwarfData(this);
650 }
651 }
652 }
653 return m_info.get();
654}
655
656const DWARFDebugInfo*
657SymbolFileDWARF::DebugInfo() const
658{
659 return m_info.get();
660}
661
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000663SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000666 if (info)
667 {
668 if (GetDebugMapSymfile ())
669 {
670 // The debug map symbol file made the compile units for this DWARF
671 // file which is .o file with DWARF in it, and we should have
672 // only 1 compile unit which is at offset zero in the DWARF.
673 // TODO: modify to support LTO .o files where each .o file might
674 // have multiple DW_TAG_compile_unit tags.
675 return info->GetCompileUnit(0).get();
676 }
677 else
678 {
679 // Just a normal DWARF file whose user ID for the compile unit is
680 // the DWARF offset itself
681 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
682 }
683 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 return NULL;
685}
686
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687
688DWARFDebugRanges*
689SymbolFileDWARF::DebugRanges()
690{
691 if (m_ranges.get() == NULL)
692 {
693 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
694 if (get_debug_ranges_data().GetByteSize() > 0)
695 {
696 m_ranges.reset(new DWARFDebugRanges());
697 if (m_ranges.get())
698 m_ranges->Extract(this);
699 }
700 }
701 return m_ranges.get();
702}
703
704const DWARFDebugRanges*
705SymbolFileDWARF::DebugRanges() const
706{
707 return m_ranges.get();
708}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710lldb::CompUnitSP
711SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000713 CompUnitSP cu_sp;
714 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000716 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
717 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000719 // We already parsed this compile unit, had out a shared pointer to it
720 cu_sp = comp_unit->shared_from_this();
721 }
722 else
723 {
Greg Clayton1f746072012-08-29 21:13:06 +0000724 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Greg Clayton1f746072012-08-29 21:13:06 +0000726 // Let the debug map create the compile unit
727 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
728 dwarf_cu->SetUserData(cu_sp.get());
729 }
730 else
731 {
732 ModuleSP module_sp (m_obj_file->GetModule());
733 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000734 {
Greg Clayton1f746072012-08-29 21:13:06 +0000735 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
736 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000737 {
Greg Clayton1f746072012-08-29 21:13:06 +0000738 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
739 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
740 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
741 if (cu_die_name)
742 {
743 std::string ramapped_file;
744 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000745
Greg Clayton1f746072012-08-29 21:13:06 +0000746 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Greg Clayton53eb1c22012-04-02 22:59:12 +0000747 {
Greg Clayton1f746072012-08-29 21:13:06 +0000748 // If we have a full path to the compile unit, we don't need to resolve
749 // the file. This can be expensive e.g. when the source files are NFS mounted.
750 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
751 cu_file_spec.SetFile (ramapped_file.c_str(), false);
752 else
753 cu_file_spec.SetFile (cu_die_name, false);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000754 }
755 else
756 {
Greg Clayton1f746072012-08-29 21:13:06 +0000757 std::string fullpath(cu_comp_dir);
758 if (*fullpath.rbegin() != '/')
759 fullpath += '/';
760 fullpath += cu_die_name;
761 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
762 cu_file_spec.SetFile (ramapped_file.c_str(), false);
763 else
764 cu_file_spec.SetFile (fullpath.c_str(), false);
765 }
766
767 cu_sp.reset(new CompileUnit (module_sp,
768 dwarf_cu,
769 cu_file_spec,
770 MakeUserID(dwarf_cu->GetOffset()),
771 cu_language));
772 if (cu_sp)
773 {
774 dwarf_cu->SetUserData(cu_sp.get());
775
Greg Clayton53eb1c22012-04-02 22:59:12 +0000776 // Figure out the compile unit index if we weren't given one
777 if (cu_idx == UINT32_MAX)
778 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779
780 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781 }
782 }
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000788 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789}
790
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791uint32_t
792SymbolFileDWARF::GetNumCompileUnits()
793{
794 DWARFDebugInfo* info = DebugInfo();
795 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return 0;
798}
799
800CompUnitSP
801SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000803 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 DWARFDebugInfo* info = DebugInfo();
805 if (info)
806 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000807 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808 if (dwarf_cu)
809 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000811 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000815AddRangesToBlock (Block& block,
816 DWARFDebugRanges::RangeList& ranges,
817 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000819 const size_t num_ranges = ranges.GetSize();
820 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000822 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823 const addr_t range_base = range.GetRangeBase();
824 assert (range_base >= block_base_addr);
825 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000827 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
829
830
831Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000832SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833{
834 DWARFDebugRanges::RangeList func_ranges;
835 const char *name = NULL;
836 const char *mangled = NULL;
837 int decl_file = 0;
838 int decl_line = 0;
839 int decl_column = 0;
840 int call_file = 0;
841 int call_line = 0;
842 int call_column = 0;
843 DWARFExpression frame_base;
844
Greg Claytonc93237c2010-10-01 20:48:32 +0000845 assert (die->Tag() == DW_TAG_subprogram);
846
847 if (die->Tag() != DW_TAG_subprogram)
848 return NULL;
849
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000850 if (die->GetDIENamesAndRanges (this,
851 dwarf_cu,
852 name,
853 mangled,
854 func_ranges,
855 decl_file,
856 decl_line,
857 decl_column,
858 call_file,
859 call_line,
860 call_column,
861 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
863 // Union of all ranges in the function DIE (if the function is discontiguous)
864 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000865 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868 {
869 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870 if (func_range.GetBaseAddress().IsValid())
871 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872 }
873
874 if (func_range.GetBaseAddress().IsValid())
875 {
876 Mangled func_name;
877 if (mangled)
Greg Clayton037520e2012-07-18 23:18:10 +0000878 func_name.SetValue(ConstString(mangled), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 else if (name)
Greg Clayton037520e2012-07-18 23:18:10 +0000880 func_name.SetValue(ConstString(name), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881
882 FunctionSP func_sp;
883 std::auto_ptr<Declaration> decl_ap;
884 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000885 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886 decl_line,
887 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000889 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000890 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891
892 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893
894 func_range.GetBaseAddress().ResolveLinkedAddress();
895
Greg Clayton81c22f62011-10-19 18:09:39 +0000896 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000898 func_user_id, // UserID is the DIE offset
899 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 func_name,
901 func_type,
902 func_range)); // first address range
903
904 if (func_sp.get() != NULL)
905 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000906 if (frame_base.IsValid())
907 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 sc.comp_unit->AddFunction(func_sp);
909 return func_sp.get();
910 }
911 }
912 }
913 return NULL;
914}
915
Greg Clayton1f746072012-08-29 21:13:06 +0000916lldb::LanguageType
917SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
918{
919 assert (sc.comp_unit);
920 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
921 if (dwarf_cu)
922 {
923 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +0000924 if (die)
925 {
926 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
927 if (language)
928 return (lldb::LanguageType)language;
929 }
Greg Clayton1f746072012-08-29 21:13:06 +0000930 }
931 return eLanguageTypeUnknown;
932}
933
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000934size_t
935SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
936{
937 assert (sc.comp_unit);
938 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +0000939 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000940 if (dwarf_cu)
941 {
942 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +0000943 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000944 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +0000945 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946 {
947 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000948 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949 {
950 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
951 ++functions_added;
952 }
953 }
954 //FixupTypes();
955 }
956 return functions_added;
957}
958
959bool
960SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
961{
962 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +0000963 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +0000964 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 {
Greg Claytonda2455b2012-11-01 17:28:37 +0000966 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967
Greg Claytonda2455b2012-11-01 17:28:37 +0000968 if (cu_die)
969 {
970 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
971 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000972
Greg Claytonda2455b2012-11-01 17:28:37 +0000973 // All file indexes in DWARF are one based and a file of index zero is
974 // supposed to be the compile unit itself.
975 support_files.Append (*sc.comp_unit);
976
977 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 }
980 return false;
981}
982
983struct ParseDWARFLineTableCallbackInfo
984{
985 LineTable* line_table;
986 const SectionList *section_list;
987 lldb::addr_t prev_sect_file_base_addr;
988 lldb::addr_t curr_sect_file_base_addr;
989 bool is_oso_for_debug_map;
990 bool prev_in_final_executable;
991 DWARFDebugLine::Row prev_row;
992 SectionSP prev_section_sp;
993 SectionSP curr_section_sp;
994};
995
996//----------------------------------------------------------------------
997// ParseStatementTableCallback
998//----------------------------------------------------------------------
999static void
1000ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1001{
1002 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
1003 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1004 {
1005 // Just started parsing the line table
1006 }
1007 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1008 {
1009 // Done parsing line table, nothing to do for the cleanup
1010 }
1011 else
1012 {
1013 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1014 // We have a new row, lets append it
1015
1016 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
1017 {
1018 info->prev_section_sp = info->curr_section_sp;
1019 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1020 // If this is an end sequence entry, then we subtract one from the
1021 // address to make sure we get an address that is not the end of
1022 // a section.
1023 if (state.end_sequence && state.address != 0)
1024 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1025 else
1026 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1027
1028 if (info->curr_section_sp.get())
1029 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1030 else
1031 info->curr_sect_file_base_addr = 0;
1032 }
1033 if (info->curr_section_sp.get())
1034 {
1035 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1036 // Check for the fancy section magic to determine if we
1037
1038 if (info->is_oso_for_debug_map)
1039 {
1040 // When this is a debug map object file that contains DWARF
1041 // (referenced from an N_OSO debug map nlist entry) we will have
1042 // a file address in the file range for our section from the
1043 // original .o file, and a load address in the executable that
1044 // contains the debug map.
1045 //
1046 // If the sections for the file range and load range are
1047 // different, we have a remapped section for the function and
1048 // this address is resolved. If they are the same, then the
1049 // function for this address didn't make it into the final
1050 // executable.
Jim Inghamf94e1792012-08-11 00:35:26 +00001051 bool curr_in_final_executable = (bool) info->curr_section_sp->GetLinkedSection ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052
1053 // If we are doing DWARF with debug map, then we need to carefully
1054 // add each line table entry as there may be gaps as functions
1055 // get moved around or removed.
1056 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1057 {
1058 if (info->prev_in_final_executable)
1059 {
1060 bool terminate_previous_entry = false;
1061 if (!curr_in_final_executable)
1062 {
1063 // Check for the case where the previous line entry
1064 // in a function made it into the final executable,
1065 // yet the current line entry falls in a function
1066 // that didn't. The line table used to be contiguous
1067 // through this address range but now it isn't. We
1068 // need to terminate the previous line entry so
1069 // that we can reconstruct the line range correctly
1070 // for it and to keep the line table correct.
1071 terminate_previous_entry = true;
1072 }
1073 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1074 {
1075 // Check for cases where the line entries used to be
1076 // contiguous address ranges, but now they aren't.
1077 // This can happen when order files specify the
1078 // ordering of the functions.
1079 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1080 Section *curr_sect = info->curr_section_sp.get();
1081 Section *prev_sect = info->prev_section_sp.get();
1082 assert (curr_sect->GetLinkedSection());
1083 assert (prev_sect->GetLinkedSection());
1084 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1085 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1086 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1087 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1088 if (object_file_addr_delta != linked_file_addr_delta)
1089 terminate_previous_entry = true;
1090 }
1091
1092 if (terminate_previous_entry)
1093 {
1094 line_table->InsertLineEntry (info->prev_section_sp,
1095 state.address - info->prev_sect_file_base_addr,
1096 info->prev_row.line,
1097 info->prev_row.column,
1098 info->prev_row.file,
1099 false, // is_stmt
1100 false, // basic_block
1101 false, // state.prologue_end
1102 false, // state.epilogue_begin
1103 true); // end_sequence);
1104 }
1105 }
1106 }
1107
1108 if (curr_in_final_executable)
1109 {
1110 line_table->InsertLineEntry (info->curr_section_sp,
1111 curr_line_section_offset,
1112 state.line,
1113 state.column,
1114 state.file,
1115 state.is_stmt,
1116 state.basic_block,
1117 state.prologue_end,
1118 state.epilogue_begin,
1119 state.end_sequence);
1120 info->prev_section_sp = info->curr_section_sp;
1121 }
1122 else
1123 {
1124 // If the current address didn't make it into the final
1125 // executable, the current section will be the __text
1126 // segment in the .o file, so we need to clear this so
1127 // we can catch the next function that did make it into
1128 // the final executable.
1129 info->prev_section_sp.reset();
1130 info->curr_section_sp.reset();
1131 }
1132
1133 info->prev_in_final_executable = curr_in_final_executable;
1134 }
1135 else
1136 {
1137 // We are not in an object file that contains DWARF for an
1138 // N_OSO, this is just a normal DWARF file. The DWARF spec
1139 // guarantees that the addresses will be in increasing order
1140 // so, since we store line tables in file address order, we
1141 // can always just append the line entry without needing to
1142 // search for the correct insertion point (we don't need to
1143 // use LineEntry::InsertLineEntry()).
1144 line_table->AppendLineEntry (info->curr_section_sp,
1145 curr_line_section_offset,
1146 state.line,
1147 state.column,
1148 state.file,
1149 state.is_stmt,
1150 state.basic_block,
1151 state.prologue_end,
1152 state.epilogue_begin,
1153 state.end_sequence);
1154 }
1155 }
1156
1157 info->prev_row = state;
1158 }
1159}
1160
1161bool
1162SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1163{
1164 assert (sc.comp_unit);
1165 if (sc.comp_unit->GetLineTable() != NULL)
1166 return true;
1167
Greg Clayton1f746072012-08-29 21:13:06 +00001168 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169 if (dwarf_cu)
1170 {
1171 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001172 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001174 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1175 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001177 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1178 if (line_table_ap.get())
1179 {
1180 ParseDWARFLineTableCallbackInfo info = {
1181 line_table_ap.get(),
1182 m_obj_file->GetSectionList(),
1183 0,
1184 0,
Greg Clayton1f746072012-08-29 21:13:06 +00001185 GetDebugMapSymfile () != NULL,
Greg Clayton129d12c2011-11-28 03:29:03 +00001186 false,
1187 DWARFDebugLine::Row(),
1188 SectionSP(),
1189 SectionSP()
1190 };
1191 uint32_t offset = cu_line_offset;
1192 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1193 sc.comp_unit->SetLineTable(line_table_ap.release());
1194 return true;
1195 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 }
1197 }
1198 }
1199 return false;
1200}
1201
1202size_t
1203SymbolFileDWARF::ParseFunctionBlocks
1204(
1205 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001206 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001207 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 const DWARFDebugInfoEntry *die,
1209 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001210 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211)
1212{
1213 size_t blocks_added = 0;
1214 while (die != NULL)
1215 {
1216 dw_tag_t tag = die->Tag();
1217
1218 switch (tag)
1219 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001221 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 case DW_TAG_lexical_block:
1223 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001224 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001225 if (tag == DW_TAG_subprogram)
1226 {
1227 // Skip any DW_TAG_subprogram DIEs that are inside
1228 // of a normal or inlined functions. These will be
1229 // parsed on their own as separate entities.
1230
1231 if (depth > 0)
1232 break;
1233
1234 block = parent_block;
1235 }
1236 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001237 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001238 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001239 parent_block->AddChild(block_sp);
1240 block = block_sp.get();
1241 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001242 DWARFDebugRanges::RangeList ranges;
1243 const char *name = NULL;
1244 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 int decl_file = 0;
1247 int decl_line = 0;
1248 int decl_column = 0;
1249 int call_file = 0;
1250 int call_line = 0;
1251 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001252 if (die->GetDIENamesAndRanges (this,
1253 dwarf_cu,
1254 name,
1255 mangled_name,
1256 ranges,
1257 decl_file, decl_line, decl_column,
1258 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001259 {
1260 if (tag == DW_TAG_subprogram)
1261 {
1262 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001263 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001265 else if (tag == DW_TAG_inlined_subroutine)
1266 {
1267 // We get called here for inlined subroutines in two ways.
1268 // The first time is when we are making the Function object
1269 // for this inlined concrete instance. Since we're creating a top level block at
1270 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1271 // adjust the containing address.
1272 // The second time is when we are parsing the blocks inside the function that contains
1273 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1274 // function the offset will be for that function.
1275 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1276 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001277 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001278 }
1279 }
1280
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001281 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282
1283 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1284 {
1285 std::auto_ptr<Declaration> decl_ap;
1286 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001287 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1288 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289
1290 std::auto_ptr<Declaration> call_ap;
1291 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001292 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1293 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001295 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 }
1297
1298 ++blocks_added;
1299
Greg Claytondd7feaf2011-08-12 17:54:33 +00001300 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001302 blocks_added += ParseFunctionBlocks (sc,
1303 block,
1304 dwarf_cu,
1305 die->GetFirstChild(),
1306 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001307 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 }
1309 }
1310 }
1311 break;
1312 default:
1313 break;
1314 }
1315
Greg Claytondd7feaf2011-08-12 17:54:33 +00001316 // Only parse siblings of the block if we are not at depth zero. A depth
1317 // of zero indicates we are currently parsing the top level
1318 // DW_TAG_subprogram DIE
1319
1320 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001322 else
1323 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324 }
1325 return blocks_added;
1326}
1327
Greg Claytonf0705c82011-10-22 03:33:13 +00001328bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001329SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1330 const DWARFDebugInfoEntry *die,
1331 ClangASTContext::TemplateParameterInfos &template_param_infos)
1332{
1333 const dw_tag_t tag = die->Tag();
1334
1335 switch (tag)
1336 {
1337 case DW_TAG_template_type_parameter:
1338 case DW_TAG_template_value_parameter:
1339 {
1340 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1341
1342 DWARFDebugInfoEntry::Attributes attributes;
1343 const size_t num_attributes = die->GetAttributes (this,
1344 dwarf_cu,
1345 fixed_form_sizes,
1346 attributes);
1347 const char *name = NULL;
1348 Type *lldb_type = NULL;
1349 clang_type_t clang_type = NULL;
1350 uint64_t uval64 = 0;
1351 bool uval64_valid = false;
1352 if (num_attributes > 0)
1353 {
1354 DWARFFormValue form_value;
1355 for (size_t i=0; i<num_attributes; ++i)
1356 {
1357 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1358
1359 switch (attr)
1360 {
1361 case DW_AT_name:
1362 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1363 name = form_value.AsCString(&get_debug_str_data());
1364 break;
1365
1366 case DW_AT_type:
1367 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1368 {
1369 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1370 lldb_type = ResolveTypeUID(type_die_offset);
1371 if (lldb_type)
1372 clang_type = lldb_type->GetClangForwardType();
1373 }
1374 break;
1375
1376 case DW_AT_const_value:
1377 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1378 {
1379 uval64_valid = true;
1380 uval64 = form_value.Unsigned();
1381 }
1382 break;
1383 default:
1384 break;
1385 }
1386 }
1387
1388 if (name && lldb_type && clang_type)
1389 {
1390 bool is_signed = false;
1391 template_param_infos.names.push_back(name);
1392 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1393 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1394 {
1395 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
Sean Callanan3d654b32012-09-24 22:25:51 +00001396 template_param_infos.args.push_back (clang::TemplateArgument (*GetClangASTContext().getASTContext(),
1397 llvm::APSInt(apint),
1398 clang_qual_type));
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001399 }
1400 else
1401 {
1402 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1403 }
1404 }
1405 else
1406 {
1407 return false;
1408 }
1409
1410 }
1411 }
1412 return true;
1413
1414 default:
1415 break;
1416 }
1417 return false;
1418}
1419
1420bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001421SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1422 const DWARFDebugInfoEntry *parent_die,
1423 ClangASTContext::TemplateParameterInfos &template_param_infos)
1424{
1425
1426 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001427 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001428
Greg Claytonf0705c82011-10-22 03:33:13 +00001429 Args template_parameter_names;
1430 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1431 die != NULL;
1432 die = die->GetSibling())
1433 {
1434 const dw_tag_t tag = die->Tag();
1435
1436 switch (tag)
1437 {
1438 case DW_TAG_template_type_parameter:
1439 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001440 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001441 break;
1442
1443 default:
1444 break;
1445 }
1446 }
1447 if (template_param_infos.args.empty())
1448 return false;
1449 return template_param_infos.args.size() == template_param_infos.names.size();
1450}
1451
1452clang::ClassTemplateDecl *
1453SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001454 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001455 const char *parent_name,
1456 int tag_decl_kind,
1457 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1458{
1459 if (template_param_infos.IsValid())
1460 {
1461 std::string template_basename(parent_name);
1462 template_basename.erase (template_basename.find('<'));
1463 ClangASTContext &ast = GetClangASTContext();
1464
1465 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001466 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001467 template_basename.c_str(),
1468 tag_decl_kind,
1469 template_param_infos);
1470 }
1471 return NULL;
1472}
1473
Sean Callanana0b80ab2012-06-04 22:28:05 +00001474class SymbolFileDWARF::DelayedAddObjCClassProperty
1475{
1476public:
1477 DelayedAddObjCClassProperty
1478 (
1479 clang::ASTContext *ast,
1480 lldb::clang_type_t class_opaque_type,
1481 const char *property_name,
1482 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1483 clang::ObjCIvarDecl *ivar_decl,
1484 const char *property_setter_name,
1485 const char *property_getter_name,
1486 uint32_t property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001487 const ClangASTMetadata *metadata
Sean Callanana0b80ab2012-06-04 22:28:05 +00001488 ) :
1489 m_ast (ast),
1490 m_class_opaque_type (class_opaque_type),
1491 m_property_name (property_name),
1492 m_property_opaque_type (property_opaque_type),
1493 m_ivar_decl (ivar_decl),
1494 m_property_setter_name (property_setter_name),
1495 m_property_getter_name (property_getter_name),
Jim Ingham379397632012-10-27 02:54:13 +00001496 m_property_attributes (property_attributes)
Sean Callanana0b80ab2012-06-04 22:28:05 +00001497 {
Jim Ingham379397632012-10-27 02:54:13 +00001498 if (metadata != NULL)
1499 {
1500 m_metadata_ap.reset(new ClangASTMetadata());
1501 *(m_metadata_ap.get()) = *metadata;
1502 }
1503 }
1504
1505 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1506 {
1507 m_ast = rhs.m_ast;
1508 m_class_opaque_type = rhs.m_class_opaque_type;
1509 m_property_name = rhs.m_property_name;
1510 m_property_opaque_type = rhs.m_property_opaque_type;
1511 m_ivar_decl = rhs.m_ivar_decl;
1512 m_property_setter_name = rhs.m_property_setter_name;
1513 m_property_getter_name = rhs.m_property_getter_name;
1514 m_property_attributes = rhs.m_property_attributes;
1515
1516 if (rhs.m_metadata_ap.get())
1517 {
1518 m_metadata_ap.reset (new ClangASTMetadata());
1519 *(m_metadata_ap.get()) = *(rhs.m_metadata_ap.get());
1520 }
1521
Sean Callanana0b80ab2012-06-04 22:28:05 +00001522 }
1523
1524 bool Finalize() const
1525 {
1526 return ClangASTContext::AddObjCClassProperty(m_ast,
1527 m_class_opaque_type,
1528 m_property_name,
1529 m_property_opaque_type,
1530 m_ivar_decl,
1531 m_property_setter_name,
1532 m_property_getter_name,
1533 m_property_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001534 m_metadata_ap.get());
Sean Callanana0b80ab2012-06-04 22:28:05 +00001535 }
1536private:
1537 clang::ASTContext *m_ast;
1538 lldb::clang_type_t m_class_opaque_type;
1539 const char *m_property_name;
1540 lldb::clang_type_t m_property_opaque_type;
1541 clang::ObjCIvarDecl *m_ivar_decl;
1542 const char *m_property_setter_name;
1543 const char *m_property_getter_name;
1544 uint32_t m_property_attributes;
Jim Ingham379397632012-10-27 02:54:13 +00001545 std::auto_ptr<ClangASTMetadata> m_metadata_ap;
Sean Callanana0b80ab2012-06-04 22:28:05 +00001546};
1547
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001548size_t
1549SymbolFileDWARF::ParseChildMembers
1550(
1551 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001552 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001553 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001554 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001555 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001556 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1557 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001558 DWARFDIECollection& member_function_dies,
Greg Clayton88bc7f32012-11-06 00:20:41 +00001559 BitfieldMap &bitfield_map,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001560 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001561 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001562 bool &is_a_class,
1563 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001564)
1565{
1566 if (parent_die == NULL)
1567 return 0;
1568
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569 size_t count = 0;
1570 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001571 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001572 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001573
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001574 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1575 {
1576 dw_tag_t tag = die->Tag();
1577
1578 switch (tag)
1579 {
1580 case DW_TAG_member:
Sean Callanan3d654b32012-09-24 22:25:51 +00001581 case DW_TAG_APPLE_property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582 {
1583 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001584 const size_t num_attributes = die->GetAttributes (this,
1585 dwarf_cu,
1586 fixed_form_sizes,
1587 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588 if (num_attributes > 0)
1589 {
1590 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001591 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001592 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001593 const char *prop_name = NULL;
1594 const char *prop_getter_name = NULL;
1595 const char *prop_setter_name = NULL;
1596 uint32_t prop_attributes = 0;
1597
1598
Greg Clayton24739922010-10-13 03:15:28 +00001599 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001600 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001601 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001602 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603 size_t byte_size = 0;
1604 size_t bit_offset = 0;
1605 size_t bit_size = 0;
1606 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001607 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001608 {
1609 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1610 DWARFFormValue form_value;
1611 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1612 {
1613 switch (attr)
1614 {
1615 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1616 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1617 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1618 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1619 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1620 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1621 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1622 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1623 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001624 if (form_value.BlockData())
1625 {
1626 Value initialValue(0);
1627 Value memberOffset(0);
1628 const DataExtractor& debug_info_data = get_debug_info_data();
1629 uint32_t block_length = form_value.Unsigned();
1630 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1631 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1632 NULL, // clang::ASTContext *
1633 NULL, // ClangExpressionVariableList *
1634 NULL, // ClangExpressionDeclMap *
1635 NULL, // RegisterContext *
1636 debug_info_data,
1637 block_offset,
1638 block_length,
1639 eRegisterKindDWARF,
1640 &initialValue,
1641 memberOffset,
1642 NULL))
1643 {
1644 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1645 }
1646 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001647 break;
1648
Greg Clayton8cf05932010-07-22 18:30:50 +00001649 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001650 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001651 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1652 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1653 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1654 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1655
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001656 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001657 case DW_AT_declaration:
1658 case DW_AT_description:
1659 case DW_AT_mutable:
1660 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001661 case DW_AT_sibling:
1662 break;
1663 }
1664 }
1665 }
Sean Callanana6582262012-04-05 00:12:52 +00001666
1667 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001668 {
Sean Callanana6582262012-04-05 00:12:52 +00001669 ConstString fixed_getter;
1670 ConstString fixed_setter;
1671
1672 // Check if the property getter/setter were provided as full
1673 // names. We want basenames, so we extract them.
1674
1675 if (prop_getter_name && prop_getter_name[0] == '-')
1676 {
1677 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1678 NULL,
1679 &fixed_getter,
1680 NULL,
1681 NULL);
1682 prop_getter_name = fixed_getter.GetCString();
1683 }
1684
1685 if (prop_setter_name && prop_setter_name[0] == '-')
1686 {
1687 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1688 NULL,
1689 &fixed_setter,
1690 NULL,
1691 NULL);
1692 prop_setter_name = fixed_setter.GetCString();
1693 }
1694
1695 // If the names haven't been provided, they need to be
1696 // filled in.
1697
1698 if (!prop_getter_name)
1699 {
1700 prop_getter_name = prop_name;
1701 }
1702 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1703 {
1704 StreamString ss;
1705
1706 ss.Printf("set%c%s:",
1707 toupper(prop_name[0]),
1708 &prop_name[1]);
1709
1710 fixed_setter.SetCString(ss.GetData());
1711 prop_setter_name = fixed_setter.GetCString();
1712 }
Sean Callanan751aac62012-03-29 19:07:06 +00001713 }
1714
1715 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001716 // represents fields that are references with bad byte size
1717 // and bit size/offset information such as:
1718 //
1719 // DW_AT_byte_size( 0x00 )
1720 // DW_AT_bit_size( 0x40 )
1721 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1722 //
1723 // So check the bit offset to make sure it is sane, and if
1724 // the values are not sane, remove them. If we don't do this
1725 // then we will end up with a crash if we try to use this
1726 // type in an expression when clang becomes unhappy with its
1727 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001728
Greg Clayton44953932011-10-25 01:25:35 +00001729 if (bit_offset > 128)
1730 {
1731 bit_size = 0;
1732 bit_offset = 0;
1733 }
1734
1735 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001736 if (class_language == eLanguageTypeObjC ||
1737 class_language == eLanguageTypeObjC_plus_plus)
1738 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001739
1740 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1741 {
1742 // Not all compilers will mark the vtable pointer
1743 // member as artificial (llvm-gcc). We can't have
1744 // the virtual members in our classes otherwise it
1745 // throws off all child offsets since we end up
1746 // having and extra pointer sized member in our
1747 // class layouts.
1748 is_artificial = true;
1749 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001750
Greg Clayton24739922010-10-13 03:15:28 +00001751 if (is_artificial == false)
1752 {
1753 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001754 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001755 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001756 {
Sean Callanan751aac62012-03-29 19:07:06 +00001757 if (member_type)
1758 {
1759 if (accessibility == eAccessNone)
1760 accessibility = default_accessibility;
1761 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762
Greg Clayton88bc7f32012-11-06 00:20:41 +00001763 // Code to detect unnamed bitifields
1764 if (bit_size > 0 && member_byte_offset != UINT32_MAX)
1765 {
1766 // Objective C has invalid DW_AT_bit_offset values so we can't use them to detect
1767 // unnamed bitfields. Once clang is fixed we will enable unnamed bitfields
1768 // in ObjC classes (<rdar://problem/12636970>)
1769
1770 if (!(class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus))
1771 {
1772 // We have a bitfield, we need to watch out for
1773 // unnamed bitfields that we need to insert if
1774 // there is a gap in the bytes as many compilers
1775 // doesn't emit DWARF DW_TAG_member tags for
1776 // unnammed bitfields.
1777 BitfieldMap::iterator bit_pos = bitfield_map.find(member_byte_offset);
1778 uint32_t unnamed_bit_size = 0;
1779 uint32_t unnamed_bit_offset = 0;
1780 if (bit_pos == bitfield_map.end())
1781 {
1782 // First bitfield in an integral type.
1783
1784 // We might need to insert a leading unnamed bitfield
1785 if (bit_offset < byte_size * 8)
1786 {
1787 unnamed_bit_size = byte_size * 8 - (bit_size + bit_offset);
1788 unnamed_bit_offset = byte_size * 8 - unnamed_bit_size;
1789 }
1790
1791 // Now put the current bitfield info into the map
1792 bitfield_map[member_byte_offset].bit_size = bit_size;
1793 bitfield_map[member_byte_offset].bit_offset = bit_offset;
1794 }
1795 else
1796 {
1797 // Subsequent bitfield in an integral type.
1798
1799 // We have a bitfield that isn't the first for this
1800 // integral type, check to make sure there aren't any
1801 // gaps.
1802 assert (bit_pos->second.bit_size > 0);
1803 if (bit_offset < bit_pos->second.bit_offset)
1804 {
1805 unnamed_bit_size = bit_pos->second.bit_offset - (bit_size + bit_offset);
1806 unnamed_bit_offset = bit_pos->second.bit_offset - unnamed_bit_size;
1807 }
1808
1809 // Now put the current bitfield info into the map
1810 bit_pos->second.bit_size = bit_size;
1811 bit_pos->second.bit_offset = bit_offset;
1812 }
1813
1814 if (unnamed_bit_size > 0)
1815 {
1816 //printf ("0x%8.8x: Unnamed bitfield added bit_size = 0x%x, bit_offset = 0x%x\n", die->GetOffset(), unnamed_bit_size, unnamed_bit_offset);
1817 clang::FieldDecl *unnamed_bitfield_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1818 NULL,
1819 member_type->GetClangLayoutType(),
1820 accessibility,
1821 unnamed_bit_size);
1822 uint64_t total_bit_offset = 0;
1823
1824 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1825
1826 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1827 {
1828 total_bit_offset += byte_size * 8;
1829 total_bit_offset -= (unnamed_bit_offset + unnamed_bit_size);
1830 }
1831 else
1832 {
1833 total_bit_offset += unnamed_bit_size;
1834 }
1835
1836 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, total_bit_offset));
1837 }
1838 }
1839 }
1840 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Sean Callanan751aac62012-03-29 19:07:06 +00001841 name,
1842 member_type->GetClangLayoutType(),
1843 accessibility,
1844 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001845
Jim Ingham379397632012-10-27 02:54:13 +00001846 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callanan5b26f272012-02-04 08:49:35 +00001847 }
1848 else
1849 {
Sean Callanan751aac62012-03-29 19:07:06 +00001850 if (name)
1851 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1852 MakeUserID(die->GetOffset()),
1853 name,
1854 encoding_uid);
1855 else
1856 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1857 MakeUserID(die->GetOffset()),
1858 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001859 }
Sean Callanan751aac62012-03-29 19:07:06 +00001860
1861 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1862 {
1863 /////////////////////////////////////////////////////////////
1864 // How to locate a field given the DWARF debug information
1865 //
1866 // AT_byte_size indicates the size of the word in which the
1867 // bit offset must be interpreted.
1868 //
1869 // AT_data_member_location indicates the byte offset of the
1870 // word from the base address of the structure.
1871 //
1872 // AT_bit_offset indicates how many bits into the word
1873 // (according to the host endianness) the low-order bit of
1874 // the field starts. AT_bit_offset can be negative.
1875 //
1876 // AT_bit_size indicates the size of the field in bits.
1877 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001878
Sean Callanan751aac62012-03-29 19:07:06 +00001879 uint64_t total_bit_offset = 0;
1880
1881 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1882
Greg Clayton88bc7f32012-11-06 00:20:41 +00001883 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
Sean Callanan751aac62012-03-29 19:07:06 +00001884 {
1885 total_bit_offset += byte_size * 8;
1886 total_bit_offset -= (bit_offset + bit_size);
1887 }
1888 else
1889 {
1890 total_bit_offset += bit_offset;
1891 }
1892
1893 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1894 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001895 }
Sean Callanan751aac62012-03-29 19:07:06 +00001896
Jim Inghame3ae82a2011-11-12 01:36:43 +00001897 if (prop_name != NULL)
1898 {
Sean Callanan751aac62012-03-29 19:07:06 +00001899 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001900
Sean Callanan751aac62012-03-29 19:07:06 +00001901 if (field_decl)
1902 {
1903 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1904 assert (ivar_decl != NULL);
1905 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001906
Jim Ingham379397632012-10-27 02:54:13 +00001907 ClangASTMetadata metadata;
1908 metadata.SetUserID (MakeUserID(die->GetOffset()));
Sean Callanana0b80ab2012-06-04 22:28:05 +00001909 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1910 class_clang_type,
1911 prop_name,
1912 member_type->GetClangLayoutType(),
1913 ivar_decl,
1914 prop_setter_name,
1915 prop_getter_name,
1916 prop_attributes,
Jim Ingham379397632012-10-27 02:54:13 +00001917 &metadata));
Sean Callanan60217122012-04-13 00:10:03 +00001918
Sean Callananad880762012-04-18 01:06:17 +00001919 if (ivar_decl)
Jim Ingham379397632012-10-27 02:54:13 +00001920 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001921 }
Greg Clayton24739922010-10-13 03:15:28 +00001922 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001924 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925 }
1926 break;
1927
1928 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001929 // Let the type parsing code handle this one for us.
1930 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931 break;
1932
1933 case DW_TAG_inheritance:
1934 {
1935 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001936 if (default_accessibility == eAccessNone)
1937 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001938 // TODO: implement DW_TAG_inheritance type parsing
1939 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001940 const size_t num_attributes = die->GetAttributes (this,
1941 dwarf_cu,
1942 fixed_form_sizes,
1943 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001944 if (num_attributes > 0)
1945 {
1946 Declaration decl;
1947 DWARFExpression location;
1948 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001949 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950 bool is_virtual = false;
1951 bool is_base_of_class = true;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001952 off_t member_byte_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 uint32_t i;
1954 for (i=0; i<num_attributes; ++i)
1955 {
1956 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1957 DWARFFormValue form_value;
1958 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1959 {
1960 switch (attr)
1961 {
1962 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1963 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1964 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1965 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton2508b9b2012-11-01 23:20:02 +00001966 case DW_AT_data_member_location:
1967 if (form_value.BlockData())
1968 {
1969 Value initialValue(0);
1970 Value memberOffset(0);
1971 const DataExtractor& debug_info_data = get_debug_info_data();
1972 uint32_t block_length = form_value.Unsigned();
1973 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1974 if (DWARFExpression::Evaluate (NULL,
1975 NULL,
1976 NULL,
1977 NULL,
1978 NULL,
1979 debug_info_data,
1980 block_offset,
1981 block_length,
1982 eRegisterKindDWARF,
1983 &initialValue,
1984 memberOffset,
1985 NULL))
1986 {
1987 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1988 }
1989 }
1990 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001991
1992 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001993 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001994 break;
1995
1996 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1997 default:
1998 case DW_AT_sibling:
1999 break;
2000 }
2001 }
2002 }
2003
Greg Clayton526e5af2010-11-13 03:52:47 +00002004 Type *base_class_type = ResolveTypeUID(encoding_uid);
2005 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002006
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002007 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
2008 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002009 if (class_language == eLanguageTypeObjC)
2010 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002011 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00002012 }
2013 else
2014 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00002015 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00002016 accessibility,
2017 is_virtual,
2018 is_base_of_class));
Greg Clayton2508b9b2012-11-01 23:20:02 +00002019
2020 if (is_virtual)
2021 {
2022 layout_info.vbase_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2023 clang::CharUnits::fromQuantity(member_byte_offset)));
2024 }
2025 else
2026 {
2027 layout_info.base_offsets.insert(std::make_pair(ClangASTType::GetAsCXXRecordDecl(class_clang_type),
2028 clang::CharUnits::fromQuantity(member_byte_offset)));
2029 }
Greg Clayton9e409562010-07-28 02:04:09 +00002030 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031 }
2032 }
2033 break;
2034
2035 default:
2036 break;
2037 }
2038 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002039
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040 return count;
2041}
2042
2043
2044clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00002045SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002046{
2047 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00002048 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049 {
2050 DWARFCompileUnitSP cu_sp;
2051 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2052 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00002053 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00002054 }
2055 return NULL;
2056}
2057
2058clang::DeclContext*
2059SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2060{
Greg Clayton81c22f62011-10-19 18:09:39 +00002061 if (UserIDMatches(type_uid))
2062 return GetClangDeclContextForDIEOffset (sc, type_uid);
2063 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002064}
2065
2066Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00002067SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068{
Greg Clayton81c22f62011-10-19 18:09:39 +00002069 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002071 DWARFDebugInfo* debug_info = DebugInfo();
2072 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00002073 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002074 DWARFCompileUnitSP cu_sp;
2075 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00002076 const bool assert_not_being_parsed = true;
2077 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00002078 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002079 }
2080 return NULL;
2081}
2082
Greg Claytoncab36a32011-12-08 05:16:30 +00002083Type*
2084SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00002085{
Greg Claytoncab36a32011-12-08 05:16:30 +00002086 if (die != NULL)
2087 {
Greg Clayton3bffb082011-12-10 02:15:28 +00002088 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
2089 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002090 GetObjectFile()->GetModule()->LogMessage (log.get(),
2091 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2092 die->GetOffset(),
2093 DW_TAG_value_to_name(die->Tag()),
2094 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00002095
Greg Claytoncab36a32011-12-08 05:16:30 +00002096 // We might be coming in in the middle of a type tree (a class
2097 // withing a class, an enum within a class), so parse any needed
2098 // parent DIEs before we get to this one...
2099 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2100 switch (decl_ctx_die->Tag())
2101 {
2102 case DW_TAG_structure_type:
2103 case DW_TAG_union_type:
2104 case DW_TAG_class_type:
2105 {
2106 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00002107 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002108 GetObjectFile()->GetModule()->LogMessage (log.get(),
2109 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2110 die->GetOffset(),
2111 DW_TAG_value_to_name(die->Tag()),
2112 die->GetName(this, cu),
2113 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00002114//
2115// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2116// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2117// {
2118// if (log)
2119// GetObjectFile()->GetModule()->LogMessage (log.get(),
2120// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2121// die->GetOffset(),
2122// DW_TAG_value_to_name(die->Tag()),
2123// die->GetName(this, cu),
2124// decl_ctx_die->GetOffset());
2125// // Ask the type to complete itself if it already hasn't since if we
2126// // want a function (method or static) from a class, the class must
2127// // create itself and add it's own methods and class functions.
2128// if (parent_type)
2129// parent_type->GetClangFullType();
2130// }
Greg Claytoncab36a32011-12-08 05:16:30 +00002131 }
2132 break;
2133
2134 default:
2135 break;
2136 }
2137 return ResolveType (cu, die);
2138 }
2139 return NULL;
2140}
2141
Greg Clayton6beaaa62011-01-17 03:46:26 +00002142// This function is used when SymbolFileDWARFDebugMap owns a bunch of
2143// SymbolFileDWARF objects to detect if this DWARF file is the one that
2144// can resolve a clang_type.
2145bool
2146SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
2147{
2148 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2149 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2150 return die != NULL;
2151}
2152
2153
Greg Clayton1be10fc2010-09-29 01:12:09 +00002154lldb::clang_type_t
2155SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2156{
2157 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002158 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2159 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002160 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002161 {
2162 // We have already resolved this type...
2163 return clang_type;
2164 }
2165 // Once we start resolving this type, remove it from the forward declaration
2166 // map in case anyone child members or other types require this type to get resolved.
2167 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2168 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002169 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002170
Greg Clayton1be10fc2010-09-29 01:12:09 +00002171
Greg Clayton85ae2e12011-10-18 23:36:41 +00002172 // Disable external storage for this type so we don't get anymore
2173 // clang::ExternalASTSource queries for this type.
2174 ClangASTContext::SetHasExternalStorage (clang_type, false);
2175
Greg Clayton450e3f32010-10-12 02:24:53 +00002176 DWARFDebugInfo* debug_info = DebugInfo();
2177
Greg Clayton53eb1c22012-04-02 22:59:12 +00002178 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002179 Type *type = m_die_to_type.lookup (die);
2180
2181 const dw_tag_t tag = die->Tag();
2182
Greg Claytonbaf95da2012-03-30 23:50:54 +00002183 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002184 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002185 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002186 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
2187 "0x%8.8llx: %s '%s' resolving forward declaration...",
2188 MakeUserID(die->GetOffset()),
2189 DW_TAG_value_to_name(tag),
2190 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002191
Greg Claytonbaf95da2012-03-30 23:50:54 +00002192 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002193 assert (clang_type);
2194 DWARFDebugInfoEntry::Attributes attributes;
2195
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002196 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002197
2198 switch (tag)
2199 {
2200 case DW_TAG_structure_type:
2201 case DW_TAG_union_type:
2202 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002203 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002204 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002205
Greg Clayton1be10fc2010-09-29 01:12:09 +00002206 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002207 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002208 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002209
Sean Callanan77a1fd32012-02-27 20:07:01 +00002210 LanguageType class_language = eLanguageTypeUnknown;
2211 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2212 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002213 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002214 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002215 // For objective C we don't start the definition when
2216 // the class is created.
2217 ast.StartTagDeclarationDefinition (clang_type);
2218 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002219
2220 int tag_decl_kind = -1;
2221 AccessType default_accessibility = eAccessNone;
2222 if (tag == DW_TAG_structure_type)
2223 {
2224 tag_decl_kind = clang::TTK_Struct;
2225 default_accessibility = eAccessPublic;
2226 }
2227 else if (tag == DW_TAG_union_type)
2228 {
2229 tag_decl_kind = clang::TTK_Union;
2230 default_accessibility = eAccessPublic;
2231 }
2232 else if (tag == DW_TAG_class_type)
2233 {
2234 tag_decl_kind = clang::TTK_Class;
2235 default_accessibility = eAccessPrivate;
2236 }
2237
Greg Clayton53eb1c22012-04-02 22:59:12 +00002238 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002239 std::vector<clang::CXXBaseSpecifier *> base_classes;
2240 std::vector<int> member_accessibilities;
2241 bool is_a_class = false;
2242 // Parse members and base classes first
2243 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002244
2245 DelayedPropertyList delayed_properties;
Greg Clayton88bc7f32012-11-06 00:20:41 +00002246 BitfieldMap bitfield_map;
2247 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002248 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002249 die,
2250 clang_type,
2251 class_language,
2252 base_classes,
2253 member_accessibilities,
2254 member_function_dies,
Greg Clayton88bc7f32012-11-06 00:20:41 +00002255 bitfield_map,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002256 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002257 default_accessibility,
2258 is_a_class,
2259 layout_info);
2260
2261 // Now parse any methods if there were any...
2262 size_t num_functions = member_function_dies.Size();
2263 if (num_functions > 0)
2264 {
2265 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002266 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002267 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002268 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002269 }
2270
2271 if (class_language == eLanguageTypeObjC)
2272 {
Greg Clayton84db9102012-03-26 23:03:23 +00002273 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002274 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002275 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002276
Sean Callanan77a1fd32012-02-27 20:07:01 +00002277 DIEArray method_die_offsets;
2278 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002279 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002280 if (m_apple_objc_ap.get())
2281 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2282 }
2283 else
2284 {
2285 if (!m_indexed)
2286 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002287
Sean Callanan77a1fd32012-02-27 20:07:01 +00002288 ConstString class_name (class_str.c_str());
2289 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2290 }
2291
2292 if (!method_die_offsets.empty())
2293 {
2294 DWARFDebugInfo* debug_info = DebugInfo();
2295
2296 DWARFCompileUnit* method_cu = NULL;
2297 const size_t num_matches = method_die_offsets.size();
2298 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002299 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002300 const dw_offset_t die_offset = method_die_offsets[i];
2301 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2302
2303 if (method_die)
2304 ResolveType (method_cu, method_die);
2305 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002306 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002307 if (m_using_apple_tables)
2308 {
2309 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2310 die_offset, class_str.c_str());
2311 }
2312 }
2313 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002314 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002315
2316 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2317 pi != pe;
2318 ++pi)
2319 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002320 }
2321 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002322
2323 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2324 // need to tell the clang type it is actually a class.
2325 if (class_language != eLanguageTypeObjC)
2326 {
2327 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2328 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2329 }
2330
2331 // Since DW_TAG_structure_type gets used for both classes
2332 // and structures, we may need to set any DW_TAG_member
2333 // fields to have a "private" access if none was specified.
2334 // When we parsed the child members we tracked that actual
2335 // accessibility value for each DW_TAG_member in the
2336 // "member_accessibilities" array. If the value for the
2337 // member is zero, then it was set to the "default_accessibility"
2338 // which for structs was "public". Below we correct this
2339 // by setting any fields to "private" that weren't correctly
2340 // set.
2341 if (is_a_class && !member_accessibilities.empty())
2342 {
2343 // This is a class and all members that didn't have
2344 // their access specified are private.
2345 ast.SetDefaultAccessForRecordFields (clang_type,
2346 eAccessPrivate,
2347 &member_accessibilities.front(),
2348 member_accessibilities.size());
2349 }
2350
2351 if (!base_classes.empty())
2352 {
2353 ast.SetBaseClassesForClassType (clang_type,
2354 &base_classes.front(),
2355 base_classes.size());
2356
2357 // Clang will copy each CXXBaseSpecifier in "base_classes"
2358 // so we have to free them all.
2359 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2360 base_classes.size());
2361 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002362 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002363 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002364
2365 ast.BuildIndirectFields (clang_type);
2366
Sean Callanan77a1fd32012-02-27 20:07:01 +00002367 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002368
Greg Clayton2508b9b2012-11-01 23:20:02 +00002369 if (!layout_info.field_offsets.empty() ||
2370 !layout_info.base_offsets.empty() ||
2371 !layout_info.vbase_offsets.empty() )
Greg Claytoncaab74e2012-01-28 00:48:57 +00002372 {
2373 if (type)
2374 layout_info.bit_size = type->GetByteSize() * 8;
2375 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002376 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Clayton2508b9b2012-11-01 23:20:02 +00002377
2378 clang::CXXRecordDecl *record_decl = ClangASTType::GetAsCXXRecordDecl(clang_type);
2379 if (record_decl)
Greg Claytoncaab74e2012-01-28 00:48:57 +00002380 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002381 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002382 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002383 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002384 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002385 clang_type,
2386 record_decl,
2387 layout_info.bit_size,
2388 layout_info.alignment,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002389 (uint32_t)layout_info.field_offsets.size(),
2390 (uint32_t)layout_info.base_offsets.size(),
2391 (uint32_t)layout_info.vbase_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002392
Greg Clayton2508b9b2012-11-01 23:20:02 +00002393 uint32_t idx;
2394 {
Greg Clayton821ac6d2012-01-28 02:22:27 +00002395 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
Greg Clayton2508b9b2012-11-01 23:20:02 +00002396 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002397 {
2398 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton2508b9b2012-11-01 23:20:02 +00002399 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
Greg Clayton821ac6d2012-01-28 02:22:27 +00002400 clang_type,
Greg Clayton2508b9b2012-11-01 23:20:02 +00002401 idx,
Greg Clayton821ac6d2012-01-28 02:22:27 +00002402 (uint32_t)pos->second,
2403 pos->first->getNameAsString().c_str());
2404 }
Greg Clayton2508b9b2012-11-01 23:20:02 +00002405 }
2406
2407 {
2408 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2409 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2410 {
2411 GetObjectFile()->GetModule()->LogMessage (log.get(),
2412 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2413 clang_type,
2414 idx,
2415 (uint32_t)base_pos->second.getQuantity(),
2416 base_pos->first->getNameAsString().c_str());
2417 }
2418 }
2419 {
2420 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2421 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2422 {
2423 GetObjectFile()->GetModule()->LogMessage (log.get(),
2424 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2425 clang_type,
2426 idx,
2427 (uint32_t)vbase_pos->second.getQuantity(),
2428 vbase_pos->first->getNameAsString().c_str());
2429 }
2430 }
Greg Clayton821ac6d2012-01-28 02:22:27 +00002431 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002432 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2433 }
2434 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002435 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002436
Greg Claytonc93237c2010-10-01 20:48:32 +00002437 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002438
2439 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002440 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002441 if (die->HasChildren())
2442 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002443 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2444 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002445 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002446 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002447 return clang_type;
2448
2449 default:
2450 assert(false && "not a forward clang type decl!");
2451 break;
2452 }
2453 return NULL;
2454}
2455
Greg Claytonc685f8e2010-09-15 04:15:46 +00002456Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002457SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002458{
2459 if (type_die != NULL)
2460 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002461 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002462
Greg Claytonc685f8e2010-09-15 04:15:46 +00002463 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002464 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002465
Greg Clayton24739922010-10-13 03:15:28 +00002466 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002467 {
2468 if (type != DIE_IS_BEING_PARSED)
2469 return type;
2470
2471 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002472 type_die->GetOffset(),
2473 DW_TAG_value_to_name(type_die->Tag()),
2474 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002475
2476 }
2477 else
2478 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002479 }
2480 return NULL;
2481}
2482
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002483CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002484SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002485{
2486 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002487 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002488 {
2489 // The symbol vendor doesn't know about this compile unit, we
2490 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002491 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002492 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002493 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002494}
2495
2496bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002497SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002498{
2499 sc.Clear();
2500 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002501 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502
Greg Clayton81c22f62011-10-19 18:09:39 +00002503 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002504 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002505 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002506
2507 if (sc.function)
2508 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002509 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002510 return true;
2511 }
2512
2513 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002514}
2515
2516uint32_t
2517SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2518{
2519 Timer scoped_timer(__PRETTY_FUNCTION__,
2520 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002521 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002522 so_addr.GetOffset(),
2523 resolve_scope);
2524 uint32_t resolved = 0;
2525 if (resolve_scope & ( eSymbolContextCompUnit |
2526 eSymbolContextFunction |
2527 eSymbolContextBlock |
2528 eSymbolContextLineEntry))
2529 {
2530 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2531
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002532 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002533 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002534 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002535 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002536 if (cu_offset != DW_INVALID_OFFSET)
2537 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002538 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002539 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2540 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002541 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002542 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002543 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002544 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002545 resolved |= eSymbolContextCompUnit;
2546
2547 if (resolve_scope & eSymbolContextLineEntry)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002548 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002549 LineTable *line_table = sc.comp_unit->GetLineTable();
2550 if (line_table != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002551 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002552 if (so_addr.IsLinkedAddress())
2553 {
2554 Address linked_addr (so_addr);
2555 linked_addr.ResolveLinkedAddress();
2556 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2557 {
2558 resolved |= eSymbolContextLineEntry;
2559 }
2560 }
2561 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002562 {
2563 resolved |= eSymbolContextLineEntry;
2564 }
2565 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002566 }
2567
2568 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2569 {
2570 DWARFDebugInfoEntry *function_die = NULL;
2571 DWARFDebugInfoEntry *block_die = NULL;
2572 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002573 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002574 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2575 }
2576 else
2577 {
2578 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2579 }
2580
2581 if (function_die != NULL)
2582 {
2583 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2584 if (sc.function == NULL)
2585 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2586 }
2587 else
2588 {
2589 // We might have had a compile unit that had discontiguous
2590 // address ranges where the gaps are symbols that don't have
2591 // any debug info. Discontiguous compile unit address ranges
2592 // should only happen when there aren't other functions from
2593 // other compile units in these gaps. This helps keep the size
2594 // of the aranges down.
2595 sc.comp_unit = NULL;
2596 resolved &= ~eSymbolContextCompUnit;
2597 }
2598
2599 if (sc.function != NULL)
2600 {
2601 resolved |= eSymbolContextFunction;
2602
2603 if (resolve_scope & eSymbolContextBlock)
2604 {
2605 Block& block = sc.function->GetBlock (true);
2606
2607 if (block_die != NULL)
2608 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2609 else
2610 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2611 if (sc.block)
2612 resolved |= eSymbolContextBlock;
2613 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002614 }
2615 }
2616 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002617 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002618 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002619 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2620 cu_offset,
2621 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002622 }
2623 }
2624 }
2625 }
2626 }
2627 return resolved;
2628}
2629
2630
2631
2632uint32_t
2633SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2634{
2635 const uint32_t prev_size = sc_list.GetSize();
2636 if (resolve_scope & eSymbolContextCompUnit)
2637 {
2638 DWARFDebugInfo* debug_info = DebugInfo();
2639 if (debug_info)
2640 {
2641 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002642 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002643
Greg Clayton53eb1c22012-04-02 22:59:12 +00002644 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002645 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002646 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00002647 const bool full_match = file_spec.GetDirectory();
2648 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 +00002649 if (check_inlines || file_spec_matches_cu_file_spec)
2650 {
2651 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002652 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002653 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002654 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002655 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002656
Greg Clayton526a4ae2012-05-16 22:09:01 +00002657 // If we are looking for inline functions only and we don't
2658 // find it in the support files, we are done.
2659 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002660 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002661 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2662 if (file_idx == UINT32_MAX)
2663 continue;
2664 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002665
Greg Clayton526a4ae2012-05-16 22:09:01 +00002666 if (line != 0)
2667 {
2668 LineTable *line_table = sc.comp_unit->GetLineTable();
2669
2670 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002671 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002672 // We will have already looked up the file index if
2673 // we are searching for inline entries.
2674 if (!check_inlines)
2675 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002676
Greg Clayton526a4ae2012-05-16 22:09:01 +00002677 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002678 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002679 uint32_t found_line;
2680 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2681 found_line = sc.line_entry.line;
2682
2683 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002684 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002685 sc.function = NULL;
2686 sc.block = NULL;
2687 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002688 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002689 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2690 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002691 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002692 DWARFDebugInfoEntry *function_die = NULL;
2693 DWARFDebugInfoEntry *block_die = NULL;
2694 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002695
Greg Clayton526a4ae2012-05-16 22:09:01 +00002696 if (function_die != NULL)
2697 {
2698 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2699 if (sc.function == NULL)
2700 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2701 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002702
Greg Clayton526a4ae2012-05-16 22:09:01 +00002703 if (sc.function != NULL)
2704 {
2705 Block& block = sc.function->GetBlock (true);
2706
2707 if (block_die != NULL)
2708 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2709 else
2710 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2711 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002712 }
2713 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002714
Greg Clayton526a4ae2012-05-16 22:09:01 +00002715 sc_list.Append(sc);
2716 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2717 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002718 }
2719 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002720 else if (file_spec_matches_cu_file_spec && !check_inlines)
2721 {
2722 // only append the context if we aren't looking for inline call sites
2723 // by file and line and if the file spec matches that of the compile unit
2724 sc_list.Append(sc);
2725 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002726 }
2727 else if (file_spec_matches_cu_file_spec && !check_inlines)
2728 {
2729 // only append the context if we aren't looking for inline call sites
2730 // by file and line and if the file spec matches that of the compile unit
2731 sc_list.Append(sc);
2732 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002733
Greg Clayton526a4ae2012-05-16 22:09:01 +00002734 if (!check_inlines)
2735 break;
2736 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002737 }
2738 }
2739 }
2740 }
2741 return sc_list.GetSize() - prev_size;
2742}
2743
2744void
2745SymbolFileDWARF::Index ()
2746{
2747 if (m_indexed)
2748 return;
2749 m_indexed = true;
2750 Timer scoped_timer (__PRETTY_FUNCTION__,
2751 "SymbolFileDWARF::Index (%s)",
2752 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2753
2754 DWARFDebugInfo* debug_info = DebugInfo();
2755 if (debug_info)
2756 {
2757 uint32_t cu_idx = 0;
2758 const uint32_t num_compile_units = GetNumCompileUnits();
2759 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2760 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002761 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002762
Greg Clayton53eb1c22012-04-02 22:59:12 +00002763 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002764
Greg Clayton53eb1c22012-04-02 22:59:12 +00002765 dwarf_cu->Index (cu_idx,
2766 m_function_basename_index,
2767 m_function_fullname_index,
2768 m_function_method_index,
2769 m_function_selector_index,
2770 m_objc_class_selectors_index,
2771 m_global_index,
2772 m_type_index,
2773 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002774
2775 // Keep memory down by clearing DIEs if this generate function
2776 // caused them to be parsed
2777 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002778 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002779 }
2780
Greg Claytond4a2b372011-09-12 23:21:58 +00002781 m_function_basename_index.Finalize();
2782 m_function_fullname_index.Finalize();
2783 m_function_method_index.Finalize();
2784 m_function_selector_index.Finalize();
2785 m_objc_class_selectors_index.Finalize();
2786 m_global_index.Finalize();
2787 m_type_index.Finalize();
2788 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002789
Greg Clayton24739922010-10-13 03:15:28 +00002790#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002791 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002792 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002793 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2794 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002795 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2796 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2797 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2798 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2799 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2800 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002801 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002802 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002803#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002804 }
2805}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002806
2807bool
2808SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2809{
2810 if (namespace_decl == NULL)
2811 {
2812 // Invalid namespace decl which means we aren't matching only things
2813 // in this symbol file, so return true to indicate it matches this
2814 // symbol file.
2815 return true;
2816 }
2817
2818 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2819
2820 if (namespace_ast == NULL)
2821 return true; // No AST in the "namespace_decl", return true since it
2822 // could then match any symbol file, including this one
2823
2824 if (namespace_ast == GetClangASTContext().getASTContext())
2825 return true; // The ASTs match, return true
2826
2827 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002828 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2829
2830 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002831 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002832
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002833 return false;
2834}
2835
Greg Clayton2506a7a2011-10-12 23:34:26 +00002836bool
2837SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2838 DWARFCompileUnit* cu,
2839 const DWARFDebugInfoEntry* die)
2840{
2841 // No namespace specified, so the answesr i
2842 if (namespace_decl == NULL)
2843 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002844
2845 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002846
Greg Clayton437a1352012-04-09 22:43:43 +00002847 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2848 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002849 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002850 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002851 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002852
Greg Clayton2506a7a2011-10-12 23:34:26 +00002853 if (clang_namespace_decl)
2854 {
2855 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002856 {
2857 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002858 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002859 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002860 }
2861
Greg Clayton437a1352012-04-09 22:43:43 +00002862 if (clang_namespace_decl == die_clang_decl_ctx)
2863 return true;
2864 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002865 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002866 }
2867 else
2868 {
2869 // We have a namespace_decl that was not NULL but it contained
2870 // a NULL "clang::NamespaceDecl", so this means the global namespace
2871 // So as long the the contained decl context DIE isn't a namespace
2872 // we should be ok.
2873 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2874 return true;
2875 }
2876 }
Sean Callananebe60672011-10-13 21:50:33 +00002877
2878 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002879 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002880
Greg Clayton2506a7a2011-10-12 23:34:26 +00002881 return false;
2882}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002883uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002884SymbolFileDWARF::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 +00002885{
Greg Clayton21f2a492011-10-06 00:09:08 +00002886 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2887
2888 if (log)
2889 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002890 GetObjectFile()->GetModule()->LogMessage (log.get(),
2891 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2892 name.GetCString(),
2893 namespace_decl,
2894 append,
2895 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002896 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002897
2898 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2899 return 0;
2900
Greg Claytonc685f8e2010-09-15 04:15:46 +00002901 DWARFDebugInfo* info = DebugInfo();
2902 if (info == NULL)
2903 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002904
2905 // If we aren't appending the results to this list, then clear the list
2906 if (!append)
2907 variables.Clear();
2908
2909 // Remember how many variables are in the list before we search in case
2910 // we are appending the results to a variable list.
2911 const uint32_t original_size = variables.GetSize();
2912
Greg Claytond4a2b372011-09-12 23:21:58 +00002913 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002914
Greg Clayton97fbc342011-10-20 22:30:33 +00002915 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002916 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002917 if (m_apple_names_ap.get())
2918 {
2919 const char *name_cstr = name.GetCString();
2920 const char *base_name_start;
2921 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002922
Greg Clayton97fbc342011-10-20 22:30:33 +00002923 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2924 base_name_start = name_cstr;
2925
2926 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2927 }
Greg Clayton7f995132011-10-04 22:41:51 +00002928 }
2929 else
2930 {
2931 // Index the DWARF if we haven't already
2932 if (!m_indexed)
2933 Index ();
2934
2935 m_global_index.Find (name, die_offsets);
2936 }
2937
Greg Clayton437a1352012-04-09 22:43:43 +00002938 const size_t num_die_matches = die_offsets.size();
2939 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002940 {
Greg Clayton7f995132011-10-04 22:41:51 +00002941 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002942 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002943 assert (sc.module_sp);
2944
Greg Claytond4a2b372011-09-12 23:21:58 +00002945 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002946 DWARFCompileUnit* dwarf_cu = NULL;
2947 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002948 bool done = false;
2949 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002950 {
2951 const dw_offset_t die_offset = die_offsets[i];
2952 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002953
Greg Clayton95d87902011-11-11 03:16:25 +00002954 if (die)
2955 {
Greg Clayton437a1352012-04-09 22:43:43 +00002956 switch (die->Tag())
2957 {
2958 default:
2959 case DW_TAG_subprogram:
2960 case DW_TAG_inlined_subroutine:
2961 case DW_TAG_try_block:
2962 case DW_TAG_catch_block:
2963 break;
2964
2965 case DW_TAG_variable:
2966 {
2967 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002968
2969 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2970 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002971
Greg Clayton437a1352012-04-09 22:43:43 +00002972 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002973
Greg Clayton437a1352012-04-09 22:43:43 +00002974 if (variables.GetSize() - original_size >= max_matches)
2975 done = true;
2976 }
2977 break;
2978 }
Greg Clayton95d87902011-11-11 03:16:25 +00002979 }
2980 else
2981 {
2982 if (m_using_apple_tables)
2983 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002984 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2985 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002986 }
2987 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002988 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002989 }
2990
2991 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002992 const uint32_t num_matches = variables.GetSize() - original_size;
2993 if (log && num_matches > 0)
2994 {
2995 GetObjectFile()->GetModule()->LogMessage (log.get(),
2996 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2997 name.GetCString(),
2998 namespace_decl,
2999 append,
3000 max_matches,
3001 num_matches);
3002 }
3003 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003004}
3005
3006uint32_t
3007SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3008{
Greg Clayton21f2a492011-10-06 00:09:08 +00003009 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3010
3011 if (log)
3012 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003013 GetObjectFile()->GetModule()->LogMessage (log.get(),
3014 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3015 regex.GetText(),
3016 append,
3017 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003018 }
3019
Greg Claytonc685f8e2010-09-15 04:15:46 +00003020 DWARFDebugInfo* info = DebugInfo();
3021 if (info == NULL)
3022 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023
3024 // If we aren't appending the results to this list, then clear the list
3025 if (!append)
3026 variables.Clear();
3027
3028 // Remember how many variables are in the list before we search in case
3029 // we are appending the results to a variable list.
3030 const uint32_t original_size = variables.GetSize();
3031
Greg Clayton7f995132011-10-04 22:41:51 +00003032 DIEArray die_offsets;
3033
Greg Clayton97fbc342011-10-20 22:30:33 +00003034 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003035 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003036 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003037 {
3038 DWARFMappedHash::DIEInfoArray hash_data_array;
3039 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3040 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3041 }
Greg Clayton7f995132011-10-04 22:41:51 +00003042 }
3043 else
3044 {
3045 // Index the DWARF if we haven't already
3046 if (!m_indexed)
3047 Index ();
3048
3049 m_global_index.Find (regex, die_offsets);
3050 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003051
Greg Claytonc685f8e2010-09-15 04:15:46 +00003052 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00003053 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00003054 assert (sc.module_sp);
3055
Greg Claytond4a2b372011-09-12 23:21:58 +00003056 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00003057 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003058 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003059 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003060 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003061 DWARFDebugInfo* debug_info = DebugInfo();
3062 for (size_t i=0; i<num_matches; ++i)
3063 {
3064 const dw_offset_t die_offset = die_offsets[i];
3065 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003066
3067 if (die)
3068 {
3069 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003070
Greg Clayton95d87902011-11-11 03:16:25 +00003071 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003072
Greg Clayton95d87902011-11-11 03:16:25 +00003073 if (variables.GetSize() - original_size >= max_matches)
3074 break;
3075 }
3076 else
3077 {
3078 if (m_using_apple_tables)
3079 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003080 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3081 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00003082 }
3083 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003085 }
3086
3087 // Return the number of variable that were appended to the list
3088 return variables.GetSize() - original_size;
3089}
3090
Greg Claytonaa044962011-10-13 00:59:38 +00003091
Jim Ingham4cda6e02011-10-07 22:23:45 +00003092bool
3093SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3094 DWARFCompileUnit *&dwarf_cu,
3095 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00003096{
Greg Claytonaa044962011-10-13 00:59:38 +00003097 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3098 return ResolveFunction (dwarf_cu, die, sc_list);
3099}
3100
3101
3102bool
3103SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3104 const DWARFDebugInfoEntry *die,
3105 SymbolContextList& sc_list)
3106{
Greg Clayton9e315582011-09-02 04:03:59 +00003107 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00003108
3109 if (die == NULL)
3110 return false;
3111
Jim Ingham4cda6e02011-10-07 22:23:45 +00003112 // If we were passed a die that is not a function, just return false...
3113 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3114 return false;
3115
3116 const DWARFDebugInfoEntry* inlined_die = NULL;
3117 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00003118 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003119 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00003120
Jim Ingham4cda6e02011-10-07 22:23:45 +00003121 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003122 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003123 if (die->Tag() == DW_TAG_subprogram)
3124 break;
Greg Clayton9e315582011-09-02 04:03:59 +00003125 }
3126 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003127 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00003128 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003129 {
3130 Address addr;
3131 // Parse all blocks if needed
3132 if (inlined_die)
3133 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003134 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00003135 assert (sc.block != NULL);
3136 if (sc.block->GetStartAddress (addr) == false)
3137 addr.Clear();
3138 }
3139 else
3140 {
3141 sc.block = NULL;
3142 addr = sc.function->GetAddressRange().GetBaseAddress();
3143 }
3144
3145 if (addr.IsValid())
3146 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003147 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00003148 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003149 }
3150 }
3151
Greg Claytonaa044962011-10-13 00:59:38 +00003152 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00003153}
3154
Greg Clayton7f995132011-10-04 22:41:51 +00003155void
3156SymbolFileDWARF::FindFunctions (const ConstString &name,
3157 const NameToDIE &name_to_die,
3158 SymbolContextList& sc_list)
3159{
Greg Claytond4a2b372011-09-12 23:21:58 +00003160 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003161 if (name_to_die.Find (name, die_offsets))
3162 {
3163 ParseFunctions (die_offsets, sc_list);
3164 }
3165}
3166
3167
3168void
3169SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3170 const NameToDIE &name_to_die,
3171 SymbolContextList& sc_list)
3172{
3173 DIEArray die_offsets;
3174 if (name_to_die.Find (regex, die_offsets))
3175 {
3176 ParseFunctions (die_offsets, sc_list);
3177 }
3178}
3179
3180
3181void
3182SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3183 const DWARFMappedHash::MemoryTable &memory_table,
3184 SymbolContextList& sc_list)
3185{
3186 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003187 DWARFMappedHash::DIEInfoArray hash_data_array;
3188 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003189 {
Greg Claytond1767f02011-12-08 02:13:16 +00003190 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003191 ParseFunctions (die_offsets, sc_list);
3192 }
3193}
3194
3195void
3196SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3197 SymbolContextList& sc_list)
3198{
3199 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003200 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003201 {
Greg Clayton7f995132011-10-04 22:41:51 +00003202 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003203
3204 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003205 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003206 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003207 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003208 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003209 }
3210 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003211}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003212
Jim Ingham4cda6e02011-10-07 22:23:45 +00003213bool
3214SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3215 const DWARFCompileUnit *dwarf_cu,
3216 uint32_t name_type_mask,
3217 const char *partial_name,
3218 const char *base_name_start,
3219 const char *base_name_end)
3220{
3221 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
3222 if (name_type_mask == eFunctionNameTypeMethod
3223 || name_type_mask == eFunctionNameTypeBase)
3224 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003225 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3226 if (!containing_decl_ctx)
3227 return false;
3228
3229 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3230
3231 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
3232 return false;
3233 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
3234 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003235 }
3236
3237 // Now we need to check whether the name we got back for this type matches the extra specifications
3238 // that were in the name we're looking up:
3239 if (base_name_start != partial_name || *base_name_end != '\0')
3240 {
3241 // First see if the stuff to the left matches the full name. To do that let's see if
3242 // we can pull out the mips linkage name attribute:
3243
3244 Mangled best_name;
3245
3246 DWARFDebugInfoEntry::Attributes attributes;
3247 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3248 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3249 if (idx != UINT32_MAX)
3250 {
3251 DWARFFormValue form_value;
3252 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3253 {
3254 const char *name = form_value.AsCString(&get_debug_str_data());
Greg Clayton037520e2012-07-18 23:18:10 +00003255 best_name.SetValue (ConstString(name), true);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003256 }
3257 }
3258 if (best_name)
3259 {
3260 const char *demangled = best_name.GetDemangledName().GetCString();
3261 if (demangled)
3262 {
3263 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003264 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3265 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003266 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003267 else
3268 {
3269 // Sort out the case where our name is something like "Process::Destroy" and the match is
3270 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3271 // namespace boundaries...
3272
3273 if (partial_name[0] == ':' && partial_name[1] == ':')
3274 {
3275 // The partial name was already on a namespace boundary so all matches are good.
3276 return true;
3277 }
3278 else if (partial_in_demangled == demangled)
3279 {
3280 // They both start the same, so this is an good match.
3281 return true;
3282 }
3283 else
3284 {
3285 if (partial_in_demangled - demangled == 1)
3286 {
3287 // Only one character difference, can't be a namespace boundary...
3288 return false;
3289 }
3290 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3291 {
3292 // We are on a namespace boundary, so this is also good.
3293 return true;
3294 }
3295 else
3296 return false;
3297 }
3298 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003299 }
3300 }
3301 }
3302
3303 return true;
3304}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003305
Greg Clayton0c5cd902010-06-28 21:30:43 +00003306uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003307SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003308 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003309 uint32_t name_type_mask,
3310 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003311 bool append,
3312 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003313{
3314 Timer scoped_timer (__PRETTY_FUNCTION__,
3315 "SymbolFileDWARF::FindFunctions (name = '%s')",
3316 name.AsCString());
3317
Greg Clayton21f2a492011-10-06 00:09:08 +00003318 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3319
3320 if (log)
3321 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003322 GetObjectFile()->GetModule()->LogMessage (log.get(),
3323 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3324 name.GetCString(),
3325 name_type_mask,
3326 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003327 }
3328
Greg Clayton0c5cd902010-06-28 21:30:43 +00003329 // If we aren't appending the results to this list, then clear the list
3330 if (!append)
3331 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003332
3333 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3334 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003335
3336 // If name is empty then we won't find anything.
3337 if (name.IsEmpty())
3338 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003339
3340 // Remember how many sc_list are in the list before we search in case
3341 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003342
Greg Clayton9e315582011-09-02 04:03:59 +00003343 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003344
Jim Ingham4cda6e02011-10-07 22:23:45 +00003345 const char *name_cstr = name.GetCString();
3346 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3347 const char *base_name_start = name_cstr;
3348 const char *base_name_end = name_cstr + strlen(name_cstr);
3349
3350 if (name_type_mask & eFunctionNameTypeAuto)
3351 {
3352 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3353 effective_name_type_mask = eFunctionNameTypeFull;
3354 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3355 effective_name_type_mask = eFunctionNameTypeFull;
3356 else
3357 {
3358 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3359 effective_name_type_mask |= eFunctionNameTypeSelector;
3360
3361 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3362 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3363 }
3364 }
3365 else
3366 {
3367 effective_name_type_mask = name_type_mask;
3368 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3369 {
3370 // If they've asked for a CPP method or function name and it can't be that, we don't
3371 // even need to search for CPP methods or names.
3372 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3373 {
3374 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3375 if (effective_name_type_mask == eFunctionNameTypeNone)
3376 return 0;
3377 }
3378 }
3379
3380 if (effective_name_type_mask & eFunctionNameTypeSelector)
3381 {
3382 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3383 {
3384 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3385 if (effective_name_type_mask == eFunctionNameTypeNone)
3386 return 0;
3387 }
3388 }
3389 }
3390
3391 DWARFDebugInfo* info = DebugInfo();
3392 if (info == NULL)
3393 return 0;
3394
Greg Claytonaa044962011-10-13 00:59:38 +00003395 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003396 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003397 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003398 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003399 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003400
3401 DIEArray die_offsets;
3402
3403 uint32_t num_matches = 0;
3404
3405 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003406 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003407 // If they asked for the full name, match what they typed. At some point we may
3408 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3409 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003410 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003411 for (uint32_t i = 0; i < num_matches; i++)
3412 {
Greg Clayton95d87902011-11-11 03:16:25 +00003413 const dw_offset_t die_offset = die_offsets[i];
3414 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003415 if (die)
3416 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003417 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3418 continue;
3419
Sean Callanan9df05fb2012-02-10 22:52:19 +00003420 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3421 continue;
3422
Greg Claytonaa044962011-10-13 00:59:38 +00003423 ResolveFunction (dwarf_cu, die, sc_list);
3424 }
Greg Clayton95d87902011-11-11 03:16:25 +00003425 else
3426 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003427 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3428 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003429 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003430 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003431 }
3432 else
3433 {
3434 if (effective_name_type_mask & eFunctionNameTypeSelector)
3435 {
3436 if (namespace_decl && *namespace_decl)
3437 return 0; // no selectors in namespaces
3438
3439 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3440 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3441 // and if it is an ObjC method name, we're good.
3442
3443 for (uint32_t i = 0; i < num_matches; i++)
3444 {
Greg Clayton95d87902011-11-11 03:16:25 +00003445 const dw_offset_t die_offset = die_offsets[i];
3446 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003447 if (die)
3448 {
3449 const char *die_name = die->GetName(this, dwarf_cu);
3450 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003451 {
3452 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3453 continue;
3454
Greg Clayton97fbc342011-10-20 22:30:33 +00003455 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003456 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003457 }
Greg Clayton95d87902011-11-11 03:16:25 +00003458 else
3459 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003460 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3461 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003462 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003463 }
3464 die_offsets.clear();
3465 }
3466
3467 if (effective_name_type_mask & eFunctionNameTypeMethod
3468 || effective_name_type_mask & eFunctionNameTypeBase)
3469 {
3470 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3471 (namespace_decl && *namespace_decl))
3472 return 0; // no methods in namespaces
3473
3474 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3475 // extract the base name, look that up, and if there is any other information in the name we were
3476 // passed in we have to post-filter based on that.
3477
3478 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3479 std::string base_name(base_name_start, base_name_end - base_name_start);
3480 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3481
3482 for (uint32_t i = 0; i < num_matches; i++)
3483 {
Greg Clayton95d87902011-11-11 03:16:25 +00003484 const dw_offset_t die_offset = die_offsets[i];
3485 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003486 if (die)
3487 {
3488 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3489 continue;
3490
3491 if (!FunctionDieMatchesPartialName(die,
3492 dwarf_cu,
3493 effective_name_type_mask,
3494 name_cstr,
3495 base_name_start,
3496 base_name_end))
3497 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003498
3499 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3500 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003501
3502 // If we get to here, the die is good, and we should add it:
3503 ResolveFunction (dwarf_cu, die, sc_list);
3504 }
Greg Clayton95d87902011-11-11 03:16:25 +00003505 else
3506 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003507 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3508 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003509 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003510 }
3511 die_offsets.clear();
3512 }
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 std::string base_name(base_name_start, base_name_end - base_name_start);
3527 ConstString base_name_const(base_name.c_str());
3528 DIEArray die_offsets;
3529 DWARFCompileUnit *dwarf_cu = NULL;
3530
3531 if (effective_name_type_mask & eFunctionNameTypeBase)
3532 {
3533 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003534 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003535 {
Greg Claytonaa044962011-10-13 00:59:38 +00003536 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3537 if (die)
3538 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003539 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3540 continue;
3541
Greg Claytonaa044962011-10-13 00:59:38 +00003542 if (!FunctionDieMatchesPartialName(die,
3543 dwarf_cu,
3544 effective_name_type_mask,
3545 name_cstr,
3546 base_name_start,
3547 base_name_end))
3548 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003549
Sean Callanan9df05fb2012-02-10 22:52:19 +00003550 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3551 continue;
3552
Greg Claytonaa044962011-10-13 00:59:38 +00003553 // If we get to here, the die is good, and we should add it:
3554 ResolveFunction (dwarf_cu, die, sc_list);
3555 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003556 }
3557 die_offsets.clear();
3558 }
3559
Jim Inghamea8005a2011-10-11 01:18:11 +00003560 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003561 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003562 if (namespace_decl && *namespace_decl)
3563 return 0; // no methods in namespaces
3564
Jim Ingham4cda6e02011-10-07 22:23:45 +00003565 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3566 {
Greg Claytonaa044962011-10-13 00:59:38 +00003567 for (uint32_t i = 0; i < num_base; i++)
3568 {
3569 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3570 if (die)
3571 {
3572 if (!FunctionDieMatchesPartialName(die,
3573 dwarf_cu,
3574 effective_name_type_mask,
3575 name_cstr,
3576 base_name_start,
3577 base_name_end))
3578 continue;
3579
Sean Callanan9df05fb2012-02-10 22:52:19 +00003580 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3581 continue;
3582
Greg Claytonaa044962011-10-13 00:59:38 +00003583 // If we get to here, the die is good, and we should add it:
3584 ResolveFunction (dwarf_cu, die, sc_list);
3585 }
3586 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003587 }
3588 die_offsets.clear();
3589 }
Greg Clayton7f995132011-10-04 22:41:51 +00003590
Sean Callanan213fdb82011-10-13 01:49:10 +00003591 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003592 {
Greg Clayton7f995132011-10-04 22:41:51 +00003593 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003594 }
3595
Greg Clayton4d01ace2011-09-29 16:58:15 +00003596 }
3597
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003598 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003599 const uint32_t num_matches = sc_list.GetSize() - original_size;
3600
3601 if (log && num_matches > 0)
3602 {
3603 GetObjectFile()->GetModule()->LogMessage (log.get(),
3604 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3605 name.GetCString(),
3606 name_type_mask,
3607 append,
3608 num_matches);
3609 }
3610 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003611}
3612
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003613uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003614SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003615{
3616 Timer scoped_timer (__PRETTY_FUNCTION__,
3617 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3618 regex.GetText());
3619
Greg Clayton21f2a492011-10-06 00:09:08 +00003620 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3621
3622 if (log)
3623 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003624 GetObjectFile()->GetModule()->LogMessage (log.get(),
3625 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3626 regex.GetText(),
3627 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003628 }
3629
3630
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003631 // If we aren't appending the results to this list, then clear the list
3632 if (!append)
3633 sc_list.Clear();
3634
3635 // Remember how many sc_list are in the list before we search in case
3636 // we are appending the results to a variable list.
3637 uint32_t original_size = sc_list.GetSize();
3638
Greg Clayton97fbc342011-10-20 22:30:33 +00003639 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003640 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003641 if (m_apple_names_ap.get())
3642 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003643 }
3644 else
3645 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003646 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003647 if (!m_indexed)
3648 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003649
Greg Clayton7f995132011-10-04 22:41:51 +00003650 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003651
Greg Clayton7f995132011-10-04 22:41:51 +00003652 FindFunctions (regex, m_function_fullname_index, sc_list);
3653 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003654
3655 // Return the number of variable that were appended to the list
3656 return sc_list.GetSize() - original_size;
3657}
Jim Ingham318c9f22011-08-26 19:44:13 +00003658
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003659uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003660SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3661 const ConstString &name,
3662 const lldb_private::ClangNamespaceDecl *namespace_decl,
3663 bool append,
3664 uint32_t max_matches,
3665 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003666{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003667 DWARFDebugInfo* info = DebugInfo();
3668 if (info == NULL)
3669 return 0;
3670
Greg Clayton21f2a492011-10-06 00:09:08 +00003671 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3672
3673 if (log)
3674 {
Greg Clayton437a1352012-04-09 22:43:43 +00003675 if (namespace_decl)
3676 {
3677 GetObjectFile()->GetModule()->LogMessage (log.get(),
3678 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3679 name.GetCString(),
3680 namespace_decl->GetNamespaceDecl(),
3681 namespace_decl->GetQualifiedName().c_str(),
3682 append,
3683 max_matches);
3684 }
3685 else
3686 {
3687 GetObjectFile()->GetModule()->LogMessage (log.get(),
3688 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3689 name.GetCString(),
3690 append,
3691 max_matches);
3692 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003693 }
3694
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003695 // If we aren't appending the results to this list, then clear the list
3696 if (!append)
3697 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003698
3699 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3700 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003701
Greg Claytond4a2b372011-09-12 23:21:58 +00003702 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003703
Greg Clayton97fbc342011-10-20 22:30:33 +00003704 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003705 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003706 if (m_apple_types_ap.get())
3707 {
3708 const char *name_cstr = name.GetCString();
3709 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3710 }
Greg Clayton7f995132011-10-04 22:41:51 +00003711 }
3712 else
3713 {
3714 if (!m_indexed)
3715 Index ();
3716
3717 m_type_index.Find (name, die_offsets);
3718 }
3719
Greg Clayton437a1352012-04-09 22:43:43 +00003720 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003721
Greg Clayton437a1352012-04-09 22:43:43 +00003722 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003723 {
Greg Clayton7f995132011-10-04 22:41:51 +00003724 const uint32_t initial_types_size = types.GetSize();
3725 DWARFCompileUnit* dwarf_cu = NULL;
3726 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003727 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003728 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003729 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003730 const dw_offset_t die_offset = die_offsets[i];
3731 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3732
Greg Clayton95d87902011-11-11 03:16:25 +00003733 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003734 {
Greg Clayton95d87902011-11-11 03:16:25 +00003735 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3736 continue;
3737
3738 Type *matching_type = ResolveType (dwarf_cu, die);
3739 if (matching_type)
3740 {
3741 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003742 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003743 if (types.GetSize() >= max_matches)
3744 break;
3745 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003746 }
Greg Clayton95d87902011-11-11 03:16:25 +00003747 else
3748 {
3749 if (m_using_apple_tables)
3750 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003751 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3752 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003753 }
3754 }
3755
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003756 }
Greg Clayton437a1352012-04-09 22:43:43 +00003757 const uint32_t num_matches = types.GetSize() - initial_types_size;
3758 if (log && num_matches)
3759 {
3760 if (namespace_decl)
3761 {
3762 GetObjectFile()->GetModule()->LogMessage (log.get(),
3763 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3764 name.GetCString(),
3765 namespace_decl->GetNamespaceDecl(),
3766 namespace_decl->GetQualifiedName().c_str(),
3767 append,
3768 max_matches,
3769 num_matches);
3770 }
3771 else
3772 {
3773 GetObjectFile()->GetModule()->LogMessage (log.get(),
3774 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3775 name.GetCString(),
3776 append,
3777 max_matches,
3778 num_matches);
3779 }
3780 }
3781 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003782 }
Greg Clayton7f995132011-10-04 22:41:51 +00003783 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003784}
3785
3786
Greg Clayton526e5af2010-11-13 03:52:47 +00003787ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003788SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003789 const ConstString &name,
3790 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003791{
Greg Clayton21f2a492011-10-06 00:09:08 +00003792 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3793
3794 if (log)
3795 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003796 GetObjectFile()->GetModule()->LogMessage (log.get(),
3797 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3798 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003799 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003800
3801 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3802 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003803
Greg Clayton526e5af2010-11-13 03:52:47 +00003804 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003805 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003806 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003807 {
Greg Clayton7f995132011-10-04 22:41:51 +00003808 DIEArray die_offsets;
3809
Greg Clayton526e5af2010-11-13 03:52:47 +00003810 // Index if we already haven't to make sure the compile units
3811 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003812 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003813 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003814 if (m_apple_namespaces_ap.get())
3815 {
3816 const char *name_cstr = name.GetCString();
3817 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3818 }
Greg Clayton7f995132011-10-04 22:41:51 +00003819 }
3820 else
3821 {
3822 if (!m_indexed)
3823 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003824
Greg Clayton7f995132011-10-04 22:41:51 +00003825 m_namespace_index.Find (name, die_offsets);
3826 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003827
3828 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003829 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003830 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003831 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003832 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003833 DWARFDebugInfo* debug_info = DebugInfo();
3834 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003835 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003836 const dw_offset_t die_offset = die_offsets[i];
3837 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003838
Greg Clayton95d87902011-11-11 03:16:25 +00003839 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003840 {
Greg Clayton95d87902011-11-11 03:16:25 +00003841 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3842 continue;
3843
3844 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3845 if (clang_namespace_decl)
3846 {
3847 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3848 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003849 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003850 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003851 }
Greg Clayton95d87902011-11-11 03:16:25 +00003852 else
3853 {
3854 if (m_using_apple_tables)
3855 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003856 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3857 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003858 }
3859 }
3860
Greg Clayton526e5af2010-11-13 03:52:47 +00003861 }
3862 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003863 }
Greg Clayton437a1352012-04-09 22:43:43 +00003864 if (log && namespace_decl.GetNamespaceDecl())
3865 {
3866 GetObjectFile()->GetModule()->LogMessage (log.get(),
3867 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3868 name.GetCString(),
3869 namespace_decl.GetNamespaceDecl(),
3870 namespace_decl.GetQualifiedName().c_str());
3871 }
3872
Greg Clayton526e5af2010-11-13 03:52:47 +00003873 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003874}
3875
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003876uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003877SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003878{
3879 // Remember how many sc_list are in the list before we search in case
3880 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003881 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003882
3883 const uint32_t num_die_offsets = die_offsets.size();
3884 // Parse all of the types we found from the pubtypes matches
3885 uint32_t i;
3886 uint32_t num_matches = 0;
3887 for (i = 0; i < num_die_offsets; ++i)
3888 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003889 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3890 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003891 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003892 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003893 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003894 ++num_matches;
3895 if (num_matches >= max_matches)
3896 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003897 }
3898 }
3899
3900 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003901 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003902}
3903
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003904
3905size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003906SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3907 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003908 DWARFCompileUnit* dwarf_cu,
3909 const DWARFDebugInfoEntry *parent_die,
3910 bool skip_artificial,
3911 bool &is_static,
3912 TypeList* type_list,
3913 std::vector<clang_type_t>& function_param_types,
3914 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003915 unsigned &type_quals,
3916 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003917{
3918 if (parent_die == NULL)
3919 return 0;
3920
Greg Claytond88d7592010-09-15 08:33:30 +00003921 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3922
Greg Clayton7fedea22010-11-16 02:10:54 +00003923 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003924 const DWARFDebugInfoEntry *die;
3925 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3926 {
3927 dw_tag_t tag = die->Tag();
3928 switch (tag)
3929 {
3930 case DW_TAG_formal_parameter:
3931 {
3932 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003933 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003934 if (num_attributes > 0)
3935 {
3936 const char *name = NULL;
3937 Declaration decl;
3938 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003939 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003940 // one of None, Auto, Register, Extern, Static, PrivateExtern
3941
Sean Callanane2ef6e32010-09-23 03:01:22 +00003942 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003943 uint32_t i;
3944 for (i=0; i<num_attributes; ++i)
3945 {
3946 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3947 DWARFFormValue form_value;
3948 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3949 {
3950 switch (attr)
3951 {
3952 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3953 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3954 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3955 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3956 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003957 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003958 case DW_AT_location:
3959 // if (form_value.BlockData())
3960 // {
3961 // const DataExtractor& debug_info_data = debug_info();
3962 // uint32_t block_length = form_value.Unsigned();
3963 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3964 // }
3965 // else
3966 // {
3967 // }
3968 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003969 case DW_AT_const_value:
3970 case DW_AT_default_value:
3971 case DW_AT_description:
3972 case DW_AT_endianity:
3973 case DW_AT_is_optional:
3974 case DW_AT_segment:
3975 case DW_AT_variable_parameter:
3976 default:
3977 case DW_AT_abstract_origin:
3978 case DW_AT_sibling:
3979 break;
3980 }
3981 }
3982 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003983
Greg Clayton0fffff52010-09-24 05:15:53 +00003984 bool skip = false;
3985 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003986 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003987 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003988 {
3989 // In order to determine if a C++ member function is
3990 // "const" we have to look at the const-ness of "this"...
3991 // Ugly, but that
3992 if (arg_idx == 0)
3993 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003994 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003995 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003996 // Often times compilers omit the "this" name for the
3997 // specification DIEs, so we can't rely upon the name
3998 // being in the formal parameter DIE...
3999 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00004000 {
Greg Clayton5113dc82011-08-12 06:47:54 +00004001 Type *this_type = ResolveTypeUID (param_type_die_offset);
4002 if (this_type)
4003 {
4004 uint32_t encoding_mask = this_type->GetEncodingMask();
4005 if (encoding_mask & Type::eEncodingIsPointerUID)
4006 {
4007 is_static = false;
4008
4009 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4010 type_quals |= clang::Qualifiers::Const;
4011 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4012 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00004013 }
4014 }
4015 }
4016 }
4017 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004018 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00004019 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004020 else
4021 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004022
Greg Clayton0fffff52010-09-24 05:15:53 +00004023 // HACK: Objective C formal parameters "self" and "_cmd"
4024 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00004025 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4026 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00004027 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004028 switch (comp_unit->GetLanguage())
4029 {
4030 case eLanguageTypeObjC:
4031 case eLanguageTypeObjC_plus_plus:
4032 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4033 skip = true;
4034 break;
4035 default:
4036 break;
4037 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004038 }
4039 }
4040 }
4041
4042 if (!skip)
4043 {
4044 Type *type = ResolveTypeUID(param_type_die_offset);
4045 if (type)
4046 {
Greg Claytonc93237c2010-10-01 20:48:32 +00004047 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00004048
Greg Clayton42ce2f32011-12-12 21:50:19 +00004049 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4050 type->GetClangForwardType(),
4051 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00004052 assert(param_var_decl);
4053 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00004054
Jim Ingham379397632012-10-27 02:54:13 +00004055 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00004056 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004057 }
4058 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004059 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004060 }
4061 break;
4062
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00004063 case DW_TAG_template_type_parameter:
4064 case DW_TAG_template_value_parameter:
4065 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4066 break;
4067
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004068 default:
4069 break;
4070 }
4071 }
Greg Clayton7fedea22010-11-16 02:10:54 +00004072 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004073}
4074
4075size_t
4076SymbolFileDWARF::ParseChildEnumerators
4077(
4078 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00004079 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004080 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00004081 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004082 const DWARFDebugInfoEntry *parent_die
4083)
4084{
4085 if (parent_die == NULL)
4086 return 0;
4087
4088 size_t enumerators_added = 0;
4089 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004090 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4091
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004092 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4093 {
4094 const dw_tag_t tag = die->Tag();
4095 if (tag == DW_TAG_enumerator)
4096 {
4097 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004098 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004099 if (num_child_attributes > 0)
4100 {
4101 const char *name = NULL;
4102 bool got_value = false;
4103 int64_t enum_value = 0;
4104 Declaration decl;
4105
4106 uint32_t i;
4107 for (i=0; i<num_child_attributes; ++i)
4108 {
4109 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4110 DWARFFormValue form_value;
4111 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4112 {
4113 switch (attr)
4114 {
4115 case DW_AT_const_value:
4116 got_value = true;
4117 enum_value = form_value.Unsigned();
4118 break;
4119
4120 case DW_AT_name:
4121 name = form_value.AsCString(&get_debug_str_data());
4122 break;
4123
4124 case DW_AT_description:
4125 default:
4126 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4127 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4128 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4129 case DW_AT_sibling:
4130 break;
4131 }
4132 }
4133 }
4134
4135 if (name && name[0] && got_value)
4136 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004137 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
4138 enumerator_clang_type,
4139 decl,
4140 name,
4141 enum_value,
4142 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004143 ++enumerators_added;
4144 }
4145 }
4146 }
4147 }
4148 return enumerators_added;
4149}
4150
4151void
4152SymbolFileDWARF::ParseChildArrayInfo
4153(
4154 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004155 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 const DWARFDebugInfoEntry *parent_die,
4157 int64_t& first_index,
4158 std::vector<uint64_t>& element_orders,
4159 uint32_t& byte_stride,
4160 uint32_t& bit_stride
4161)
4162{
4163 if (parent_die == NULL)
4164 return;
4165
4166 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00004167 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004168 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4169 {
4170 const dw_tag_t tag = die->Tag();
4171 switch (tag)
4172 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004173 case DW_TAG_subrange_type:
4174 {
4175 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004176 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004177 if (num_child_attributes > 0)
4178 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004179 uint64_t num_elements = 0;
4180 uint64_t lower_bound = 0;
4181 uint64_t upper_bound = 0;
4182 uint32_t i;
4183 for (i=0; i<num_child_attributes; ++i)
4184 {
4185 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4186 DWARFFormValue form_value;
4187 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4188 {
4189 switch (attr)
4190 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004191 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192 break;
4193
4194 case DW_AT_count:
4195 num_elements = form_value.Unsigned();
4196 break;
4197
4198 case DW_AT_bit_stride:
4199 bit_stride = form_value.Unsigned();
4200 break;
4201
4202 case DW_AT_byte_stride:
4203 byte_stride = form_value.Unsigned();
4204 break;
4205
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004206 case DW_AT_lower_bound:
4207 lower_bound = form_value.Unsigned();
4208 break;
4209
4210 case DW_AT_upper_bound:
4211 upper_bound = form_value.Unsigned();
4212 break;
4213
4214 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004215 case DW_AT_abstract_origin:
4216 case DW_AT_accessibility:
4217 case DW_AT_allocated:
4218 case DW_AT_associated:
4219 case DW_AT_data_location:
4220 case DW_AT_declaration:
4221 case DW_AT_description:
4222 case DW_AT_sibling:
4223 case DW_AT_threads_scaled:
4224 case DW_AT_type:
4225 case DW_AT_visibility:
4226 break;
4227 }
4228 }
4229 }
4230
4231 if (upper_bound > lower_bound)
4232 num_elements = upper_bound - lower_bound + 1;
4233
Sean Callananec979ba2012-10-22 23:56:48 +00004234 element_orders.push_back (num_elements);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235 }
4236 }
4237 break;
4238 }
4239 }
4240}
4241
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004243SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004244{
4245 TypeSP type_sp;
4246 if (die != NULL)
4247 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004248 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004249 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004250 if (type_ptr == NULL)
4251 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004252 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004253 assert (lldb_cu);
4254 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004255 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004256 }
4257 else if (type_ptr != DIE_IS_BEING_PARSED)
4258 {
4259 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004260 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004261 }
4262
4263 }
4264 return type_sp;
4265}
4266
4267clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004268SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004269{
4270 if (die_offset != DW_INVALID_OFFSET)
4271 {
4272 DWARFCompileUnitSP cu_sp;
4273 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004274 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275 }
4276 return NULL;
4277}
4278
Sean Callanan72e49402011-08-05 23:43:37 +00004279clang::DeclContext *
4280SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4281{
4282 if (die_offset != DW_INVALID_OFFSET)
4283 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004284 DWARFDebugInfo* debug_info = DebugInfo();
4285 if (debug_info)
4286 {
4287 DWARFCompileUnitSP cu_sp;
4288 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4289 if (die)
4290 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4291 }
Sean Callanan72e49402011-08-05 23:43:37 +00004292 }
4293 return NULL;
4294}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295
Greg Clayton96d7d742010-11-10 23:42:09 +00004296clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004297SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004298{
Greg Clayton030a2042011-10-14 21:34:45 +00004299 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004300 {
Greg Clayton030a2042011-10-14 21:34:45 +00004301 // See if we already parsed this namespace DIE and associated it with a
4302 // uniqued namespace declaration
4303 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4304 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004305 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004306 else
4307 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004308 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4309 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004310 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4311 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4312 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004313 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004314 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004315 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004316 GetObjectFile()->GetModule()->LogMessage (log.get(),
4317 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4318 GetClangASTContext().getASTContext(),
4319 MakeUserID(die->GetOffset()),
4320 namespace_name,
4321 namespace_decl,
4322 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004323 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004324 else
4325 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004326 GetObjectFile()->GetModule()->LogMessage (log.get(),
4327 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4328 GetClangASTContext().getASTContext(),
4329 MakeUserID(die->GetOffset()),
4330 namespace_decl,
4331 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004332 }
Greg Clayton030a2042011-10-14 21:34:45 +00004333 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004334
4335 if (namespace_decl)
4336 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4337 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004338 }
4339 }
4340 return NULL;
4341}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004342
4343clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004344SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004345{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004346 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4347 if (clang_decl_ctx)
4348 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004349 // If this DIE has a specification, or an abstract origin, then trace to those.
4350
Greg Claytoncab36a32011-12-08 05:16:30 +00004351 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004352 if (die_offset != DW_INVALID_OFFSET)
4353 return GetClangDeclContextForDIEOffset (sc, die_offset);
4354
Greg Claytoncab36a32011-12-08 05:16:30 +00004355 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004356 if (die_offset != DW_INVALID_OFFSET)
4357 return GetClangDeclContextForDIEOffset (sc, die_offset);
4358
Greg Clayton3bffb082011-12-10 02:15:28 +00004359 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4360 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004361 GetObjectFile()->GetModule()->LogMessage(log.get(), "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu));
Sean Callanan72e49402011-08-05 23:43:37 +00004362 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004363 bool assert_not_being_parsed = true;
4364 ResolveTypeUID (cu, die, assert_not_being_parsed);
4365
Greg Clayton5cf58b92011-10-05 22:22:08 +00004366 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4367
4368 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004369}
4370
4371clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004372SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004373{
Greg Claytonca512b32011-01-14 04:54:56 +00004374 if (m_clang_tu_decl == NULL)
4375 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004376
Greg Clayton2bc22f82011-09-30 03:20:47 +00004377 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004378
4379 if (decl_ctx_die_copy)
4380 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004381
4382 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004383 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004384
Greg Clayton2bc22f82011-09-30 03:20:47 +00004385 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4386 if (pos != m_die_to_decl_ctx.end())
4387 return pos->second;
4388
4389 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004390 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004391 case DW_TAG_compile_unit:
4392 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004393
Greg Clayton2bc22f82011-09-30 03:20:47 +00004394 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004395 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004396 break;
4397
4398 case DW_TAG_structure_type:
4399 case DW_TAG_union_type:
4400 case DW_TAG_class_type:
4401 {
4402 Type* type = ResolveType (cu, decl_ctx_die);
4403 if (type)
4404 {
4405 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4406 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004407 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004408 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4409 if (decl_ctx)
4410 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004411 }
4412 }
Greg Claytonca512b32011-01-14 04:54:56 +00004413 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004414 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004415
Greg Clayton2bc22f82011-09-30 03:20:47 +00004416 default:
4417 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004418 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004419 }
Greg Clayton7a345282010-11-09 23:46:37 +00004420 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004421}
4422
Greg Clayton2bc22f82011-09-30 03:20:47 +00004423
4424const DWARFDebugInfoEntry *
4425SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4426{
4427 if (cu && die)
4428 {
4429 const DWARFDebugInfoEntry * const decl_die = die;
4430
4431 while (die != NULL)
4432 {
4433 // If this is the original DIE that we are searching for a declaration
4434 // for, then don't look in the cache as we don't want our own decl
4435 // context to be our decl context...
4436 if (decl_die != die)
4437 {
4438 switch (die->Tag())
4439 {
4440 case DW_TAG_compile_unit:
4441 case DW_TAG_namespace:
4442 case DW_TAG_structure_type:
4443 case DW_TAG_union_type:
4444 case DW_TAG_class_type:
4445 return die;
4446
4447 default:
4448 break;
4449 }
4450 }
4451
4452 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4453 if (die_offset != DW_INVALID_OFFSET)
4454 {
4455 DWARFCompileUnit *spec_cu = cu;
4456 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4457 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4458 if (spec_die_decl_ctx_die)
4459 return spec_die_decl_ctx_die;
4460 }
4461
4462 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4463 if (die_offset != DW_INVALID_OFFSET)
4464 {
4465 DWARFCompileUnit *abs_cu = cu;
4466 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4467 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4468 if (abs_die_decl_ctx_die)
4469 return abs_die_decl_ctx_die;
4470 }
4471
4472 die = die->GetParent();
4473 }
4474 }
4475 return NULL;
4476}
4477
4478
Greg Clayton901c5ca2011-12-03 04:40:03 +00004479Symbol *
4480SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4481{
4482 Symbol *objc_class_symbol = NULL;
4483 if (m_obj_file)
4484 {
4485 Symtab *symtab = m_obj_file->GetSymtab();
4486 if (symtab)
4487 {
4488 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4489 eSymbolTypeObjCClass,
4490 Symtab::eDebugNo,
4491 Symtab::eVisibilityAny);
4492 }
4493 }
4494 return objc_class_symbol;
4495}
4496
Greg Claytonc7f03b62012-01-12 04:33:28 +00004497// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4498// then we can end up looking through all class types for a complete type and never find
4499// the full definition. We need to know if this attribute is supported, so we determine
4500// this here and cache th result. We also need to worry about the debug map DWARF file
4501// if we are doing darwin DWARF in .o file debugging.
4502bool
4503SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4504{
4505 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4506 {
4507 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4508 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4509 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4510 else
4511 {
4512 DWARFDebugInfo* debug_info = DebugInfo();
4513 const uint32_t num_compile_units = GetNumCompileUnits();
4514 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4515 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004516 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4517 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004518 {
4519 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4520 break;
4521 }
4522 }
4523 }
Greg Clayton1f746072012-08-29 21:13:06 +00004524 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004525 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4526 }
4527 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4528}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004529
4530// This function can be used when a DIE is found that is a forward declaration
4531// DIE and we want to try and find a type that has the complete definition.
4532TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004533SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4534 const ConstString &type_name,
4535 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004536{
4537
4538 TypeSP type_sp;
4539
Greg Claytonc7f03b62012-01-12 04:33:28 +00004540 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004541 return type_sp;
4542
4543 DIEArray die_offsets;
4544
4545 if (m_using_apple_tables)
4546 {
4547 if (m_apple_types_ap.get())
4548 {
4549 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004550 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004551 }
4552 }
4553 else
4554 {
4555 if (!m_indexed)
4556 Index ();
4557
4558 m_type_index.Find (type_name, die_offsets);
4559 }
4560
Greg Clayton901c5ca2011-12-03 04:40:03 +00004561 const size_t num_matches = die_offsets.size();
4562
Greg Clayton901c5ca2011-12-03 04:40:03 +00004563 DWARFCompileUnit* type_cu = NULL;
4564 const DWARFDebugInfoEntry* type_die = NULL;
4565 if (num_matches)
4566 {
4567 DWARFDebugInfo* debug_info = DebugInfo();
4568 for (size_t i=0; i<num_matches; ++i)
4569 {
4570 const dw_offset_t die_offset = die_offsets[i];
4571 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4572
4573 if (type_die)
4574 {
4575 bool try_resolving_type = false;
4576
4577 // Don't try and resolve the DIE we are looking for with the DIE itself!
4578 if (type_die != die)
4579 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004580 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004581 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004582 case DW_TAG_class_type:
4583 case DW_TAG_structure_type:
4584 try_resolving_type = true;
4585 break;
4586 default:
4587 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004588 }
4589 }
4590
4591 if (try_resolving_type)
4592 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004593 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004594 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004595
4596 if (try_resolving_type)
4597 {
4598 Type *resolved_type = ResolveType (type_cu, type_die, false);
4599 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4600 {
4601 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4602 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004603 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004604 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4605 MakeUserID(type_die->GetOffset()),
4606 MakeUserID(type_cu->GetOffset()));
4607
Greg Claytonc7f03b62012-01-12 04:33:28 +00004608 if (die)
4609 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004610 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004611 break;
4612 }
4613 }
4614 }
4615 }
4616 else
4617 {
4618 if (m_using_apple_tables)
4619 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004620 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4621 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004622 }
4623 }
4624
4625 }
4626 }
4627 return type_sp;
4628}
4629
Greg Claytona8022fa2012-04-24 21:22:41 +00004630
Greg Clayton80c26302012-02-05 06:12:47 +00004631//----------------------------------------------------------------------
4632// This function helps to ensure that the declaration contexts match for
4633// two different DIEs. Often times debug information will refer to a
4634// forward declaration of a type (the equivalent of "struct my_struct;".
4635// There will often be a declaration of that type elsewhere that has the
4636// full definition. When we go looking for the full type "my_struct", we
4637// will find one or more matches in the accelerator tables and we will
4638// then need to make sure the type was in the same declaration context
4639// as the original DIE. This function can efficiently compare two DIEs
4640// and will return true when the declaration context matches, and false
4641// when they don't.
4642//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004643bool
4644SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4645 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4646{
Greg Claytona8022fa2012-04-24 21:22:41 +00004647 if (die1 == die2)
4648 return true;
4649
4650#if defined (LLDB_CONFIGURATION_DEBUG)
4651 // You can't and shouldn't call this function with a compile unit from
4652 // two different SymbolFileDWARF instances.
4653 assert (DebugInfo()->ContainsCompileUnit (cu1));
4654 assert (DebugInfo()->ContainsCompileUnit (cu2));
4655#endif
4656
Greg Clayton890ff562012-02-02 05:48:16 +00004657 DWARFDIECollection decl_ctx_1;
4658 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004659 //The declaration DIE stack is a stack of the declaration context
4660 // DIEs all the way back to the compile unit. If a type "T" is
4661 // declared inside a class "B", and class "B" is declared inside
4662 // a class "A" and class "A" is in a namespace "lldb", and the
4663 // namespace is in a compile unit, there will be a stack of DIEs:
4664 //
4665 // [0] DW_TAG_class_type for "B"
4666 // [1] DW_TAG_class_type for "A"
4667 // [2] DW_TAG_namespace for "lldb"
4668 // [3] DW_TAG_compile_unit for the source file.
4669 //
4670 // We grab both contexts and make sure that everything matches
4671 // all the way back to the compiler unit.
4672
4673 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004674 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004675 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004676 // Make sure the context arrays have the same size, otherwise
4677 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004678 const size_t count1 = decl_ctx_1.Size();
4679 const size_t count2 = decl_ctx_2.Size();
4680 if (count1 != count2)
4681 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004682
4683 // Make sure the DW_TAG values match all the way back up the the
4684 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004685 const DWARFDebugInfoEntry *decl_ctx_die1;
4686 const DWARFDebugInfoEntry *decl_ctx_die2;
4687 size_t i;
4688 for (i=0; i<count1; i++)
4689 {
4690 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4691 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4692 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4693 return false;
4694 }
Greg Clayton890ff562012-02-02 05:48:16 +00004695#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004696
4697 // Make sure the top item in the decl context die array is always
4698 // DW_TAG_compile_unit. If it isn't then something went wrong in
4699 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004700 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004701
Greg Clayton890ff562012-02-02 05:48:16 +00004702#endif
4703 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004704 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004705 for (i=0; i<count1 - 1; i++)
4706 {
4707 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4708 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4709 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004710 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004711 // If the string was from a DW_FORM_strp, then the pointer will often
4712 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004713 if (name1 == name2)
4714 continue;
4715
4716 // Name pointers are not equal, so only compare the strings
4717 // if both are not NULL.
4718 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004719 {
Greg Clayton5569e642012-02-06 01:44:54 +00004720 // If the strings don't compare, we are done...
4721 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004722 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004723 }
4724 else
4725 {
4726 // One name was NULL while the other wasn't
4727 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004728 }
4729 }
Greg Clayton80c26302012-02-05 06:12:47 +00004730 // We made it through all of the checks and the declaration contexts
4731 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004732 return true;
4733}
Greg Clayton220a0072011-12-09 08:48:30 +00004734
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004735// This function can be used when a DIE is found that is a forward declaration
4736// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004737// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004738TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004739SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004740 const DWARFDebugInfoEntry *die,
4741 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004742{
4743 TypeSP type_sp;
4744
Greg Claytona8022fa2012-04-24 21:22:41 +00004745#if defined (LLDB_CONFIGURATION_DEBUG)
4746 // You can't and shouldn't call this function with a compile unit from
4747 // another SymbolFileDWARF instance.
4748 assert (DebugInfo()->ContainsCompileUnit (cu));
4749#endif
4750
Greg Clayton1a65ae12011-01-25 23:55:37 +00004751 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004752 return type_sp;
4753
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004754 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4755 if (log)
4756 {
4757 std::string qualified_name;
4758 die->GetQualifiedName(this, cu, qualified_name);
4759 GetObjectFile()->GetModule()->LogMessage (log.get(),
4760 "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 Claytond1767f02011-12-08 02:13:16 +00004772 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4773 {
Greg Claytonae920b62012-01-06 00:17:16 +00004774 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004775 }
4776 else
4777 {
4778 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4779 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004780 }
Greg Clayton7f995132011-10-04 22:41:51 +00004781 }
4782 else
4783 {
4784 if (!m_indexed)
4785 Index ();
4786
4787 m_type_index.Find (type_name, die_offsets);
4788 }
Greg Clayton7f995132011-10-04 22:41:51 +00004789
4790 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004791
Greg Clayton934cb052011-12-03 00:27:05 +00004792 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004793
4794 DWARFCompileUnit* type_cu = NULL;
4795 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004796 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004797 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004798 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004799 for (size_t i=0; i<num_matches; ++i)
4800 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004801 const dw_offset_t die_offset = die_offsets[i];
4802 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004803
Greg Clayton95d87902011-11-11 03:16:25 +00004804 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004805 {
Greg Clayton934cb052011-12-03 00:27:05 +00004806 bool try_resolving_type = false;
4807
4808 // Don't try and resolve the DIE we are looking for with the DIE itself!
4809 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004810 {
Greg Clayton934cb052011-12-03 00:27:05 +00004811 const dw_tag_t type_die_tag = type_die->Tag();
4812 // Make sure the tags match
4813 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004814 {
Greg Clayton934cb052011-12-03 00:27:05 +00004815 // The tags match, lets try resolving this type
4816 try_resolving_type = true;
4817 }
4818 else
4819 {
4820 // The tags don't match, but we need to watch our for a
4821 // forward declaration for a struct and ("struct foo")
4822 // ends up being a class ("class foo { ... };") or
4823 // vice versa.
4824 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004825 {
Greg Clayton934cb052011-12-03 00:27:05 +00004826 case DW_TAG_class_type:
4827 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4828 try_resolving_type = (die_tag == DW_TAG_structure_type);
4829 break;
4830 case DW_TAG_structure_type:
4831 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4832 try_resolving_type = (die_tag == DW_TAG_class_type);
4833 break;
4834 default:
4835 // Tags don't match, don't event try to resolve
4836 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004837 break;
4838 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004839 }
4840 }
Greg Clayton934cb052011-12-03 00:27:05 +00004841
4842 if (try_resolving_type)
4843 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004844 if (log)
4845 {
4846 std::string qualified_name;
4847 type_die->GetQualifiedName(this, cu, qualified_name);
4848 GetObjectFile()->GetModule()->LogMessage (log.get(),
4849 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4850 die->GetOffset(),
4851 type_name.GetCString(),
4852 type_die->GetOffset(),
4853 qualified_name.c_str());
4854 }
4855
Greg Clayton890ff562012-02-02 05:48:16 +00004856 // Make sure the decl contexts match all the way up
4857 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004858 {
Greg Clayton890ff562012-02-02 05:48:16 +00004859 Type *resolved_type = ResolveType (type_cu, type_die, false);
4860 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4861 {
4862 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4863 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004864 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004865 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4866 MakeUserID(type_die->GetOffset()),
4867 MakeUserID(type_cu->GetOffset()));
4868
4869 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004870 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004871 break;
4872 }
Greg Clayton934cb052011-12-03 00:27:05 +00004873 }
4874 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004875 else
4876 {
4877 if (log)
4878 {
4879 std::string qualified_name;
4880 type_die->GetQualifiedName(this, cu, qualified_name);
4881 GetObjectFile()->GetModule()->LogMessage (log.get(),
4882 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4883 die->GetOffset(),
4884 type_name.GetCString(),
4885 type_die->GetOffset(),
4886 qualified_name.c_str());
4887 }
4888 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004889 }
Greg Clayton95d87902011-11-11 03:16:25 +00004890 else
4891 {
4892 if (m_using_apple_tables)
4893 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004894 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4895 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004896 }
4897 }
4898
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004899 }
4900 }
4901 return type_sp;
4902}
4903
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004904TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004905SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4906{
4907 TypeSP type_sp;
4908
4909 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4910 if (dwarf_decl_ctx_count > 0)
4911 {
4912 const ConstString type_name(dwarf_decl_ctx[0].name);
4913 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4914
4915 if (type_name)
4916 {
4917 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4918 if (log)
4919 {
4920 GetObjectFile()->GetModule()->LogMessage (log.get(),
4921 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4922 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4923 dwarf_decl_ctx.GetQualifiedName());
4924 }
4925
4926 DIEArray die_offsets;
4927
4928 if (m_using_apple_tables)
4929 {
4930 if (m_apple_types_ap.get())
4931 {
4932 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4933 {
4934 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4935 }
4936 else
4937 {
4938 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4939 }
4940 }
4941 }
4942 else
4943 {
4944 if (!m_indexed)
4945 Index ();
4946
4947 m_type_index.Find (type_name, die_offsets);
4948 }
4949
4950 const size_t num_matches = die_offsets.size();
4951
4952
4953 DWARFCompileUnit* type_cu = NULL;
4954 const DWARFDebugInfoEntry* type_die = NULL;
4955 if (num_matches)
4956 {
4957 DWARFDebugInfo* debug_info = DebugInfo();
4958 for (size_t i=0; i<num_matches; ++i)
4959 {
4960 const dw_offset_t die_offset = die_offsets[i];
4961 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4962
4963 if (type_die)
4964 {
4965 bool try_resolving_type = false;
4966
4967 // Don't try and resolve the DIE we are looking for with the DIE itself!
4968 const dw_tag_t type_tag = type_die->Tag();
4969 // Make sure the tags match
4970 if (type_tag == tag)
4971 {
4972 // The tags match, lets try resolving this type
4973 try_resolving_type = true;
4974 }
4975 else
4976 {
4977 // The tags don't match, but we need to watch our for a
4978 // forward declaration for a struct and ("struct foo")
4979 // ends up being a class ("class foo { ... };") or
4980 // vice versa.
4981 switch (type_tag)
4982 {
4983 case DW_TAG_class_type:
4984 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4985 try_resolving_type = (tag == DW_TAG_structure_type);
4986 break;
4987 case DW_TAG_structure_type:
4988 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4989 try_resolving_type = (tag == DW_TAG_class_type);
4990 break;
4991 default:
4992 // Tags don't match, don't event try to resolve
4993 // using this type whose name matches....
4994 break;
4995 }
4996 }
4997
4998 if (try_resolving_type)
4999 {
5000 DWARFDeclContext type_dwarf_decl_ctx;
5001 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5002
5003 if (log)
5004 {
5005 GetObjectFile()->GetModule()->LogMessage (log.get(),
5006 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5007 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5008 dwarf_decl_ctx.GetQualifiedName(),
5009 type_die->GetOffset(),
5010 type_dwarf_decl_ctx.GetQualifiedName());
5011 }
5012
5013 // Make sure the decl contexts match all the way up
5014 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5015 {
5016 Type *resolved_type = ResolveType (type_cu, type_die, false);
5017 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5018 {
5019 type_sp = resolved_type->shared_from_this();
5020 break;
5021 }
5022 }
5023 }
5024 else
5025 {
5026 if (log)
5027 {
5028 std::string qualified_name;
5029 type_die->GetQualifiedName(this, type_cu, qualified_name);
5030 GetObjectFile()->GetModule()->LogMessage (log.get(),
5031 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5032 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5033 dwarf_decl_ctx.GetQualifiedName(),
5034 type_die->GetOffset(),
5035 qualified_name.c_str());
5036 }
5037 }
5038 }
5039 else
5040 {
5041 if (m_using_apple_tables)
5042 {
5043 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5044 die_offset, type_name.GetCString());
5045 }
5046 }
5047
5048 }
5049 }
5050 }
5051 }
5052 return type_sp;
5053}
5054
Greg Clayton4116e932012-05-15 02:33:01 +00005055bool
5056SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type,
5057 DWARFCompileUnit* src_cu,
5058 const DWARFDebugInfoEntry *src_class_die,
5059 DWARFCompileUnit* dst_cu,
5060 const DWARFDebugInfoEntry *dst_class_die)
5061{
5062 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5063 return false;
5064 if (src_class_die->Tag() != dst_class_die->Tag())
5065 return false;
5066
5067 // We need to complete the class type so we can get all of the method types
5068 // parsed so we can then unique those types to their equivalent counterparts
5069 // in "dst_cu" and "dst_class_die"
5070 class_type->GetClangFullType();
5071
5072 const DWARFDebugInfoEntry *src_die;
5073 const DWARFDebugInfoEntry *dst_die;
5074 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5075 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
5076 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5077 {
5078 if (src_die->Tag() == DW_TAG_subprogram)
5079 {
5080 const char *src_name = src_die->GetMangledName (this, src_cu);
5081 if (src_name)
5082 src_name_to_die.Append(ConstString(src_name).GetCString(), src_die);
5083 }
5084 }
5085 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5086 {
5087 if (dst_die->Tag() == DW_TAG_subprogram)
5088 {
5089 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5090 if (dst_name)
5091 dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die);
5092 }
5093 }
5094 const uint32_t src_size = src_name_to_die.GetSize ();
5095 const uint32_t dst_size = dst_name_to_die.GetSize ();
5096 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
5097
5098 if (src_size && dst_size)
5099 {
Sean Callanan210b8152012-07-07 00:29:33 +00005100 if (src_size != dst_size)
5101 {
5102 if (log)
5103 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)",
5104 src_class_die->GetOffset(),
5105 dst_class_die->GetOffset(),
5106 src_size,
5107 dst_size);
5108
5109 return false;
5110 }
5111
Greg Clayton4116e932012-05-15 02:33:01 +00005112 uint32_t idx;
5113 for (idx = 0; idx < src_size; ++idx)
5114 {
5115 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5116 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5117
5118 if (src_die->Tag() != dst_die->Tag())
5119 {
5120 if (log)
5121 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)",
5122 src_class_die->GetOffset(),
5123 dst_class_die->GetOffset(),
5124 src_die->GetOffset(),
5125 DW_TAG_value_to_name(src_die->Tag()),
5126 dst_die->GetOffset(),
5127 DW_TAG_value_to_name(src_die->Tag()));
5128 return false;
5129 }
5130
5131 const char *src_name = src_die->GetMangledName (this, src_cu);
5132 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5133
5134 // Make sure the names match
5135 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5136 continue;
5137
5138 if (log)
5139 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)",
5140 src_class_die->GetOffset(),
5141 dst_class_die->GetOffset(),
5142 src_die->GetOffset(),
5143 src_name,
5144 dst_die->GetOffset(),
5145 dst_name);
5146
5147 return false;
5148 }
5149
5150 for (idx = 0; idx < src_size; ++idx)
5151 {
5152 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5153 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5154
5155 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5156 if (src_decl_ctx)
5157 {
5158 if (log)
5159 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5160 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5161 }
5162 else
5163 {
5164 if (log)
5165 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset());
5166 }
5167
5168 Type *src_child_type = m_die_to_type[src_die];
5169 if (src_child_type)
5170 {
5171 if (log)
5172 log->Printf ("uniquing type %p (uid=0x%llx) from 0x%8.8x for 0x%8.8x\n", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5173 m_die_to_type[dst_die] = src_child_type;
5174 }
5175 else
5176 {
5177 if (log)
5178 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found\n", src_die->GetOffset(), dst_die->GetOffset());
5179 }
5180 }
5181 return true;
5182 }
5183 else
5184 {
5185 if (log)
5186 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x has %u methods and 0x%8.8x has %u",
5187 src_class_die->GetOffset(),
5188 dst_class_die->GetOffset(),
5189 src_die->GetOffset(),
5190 src_size,
5191 dst_die->GetOffset(),
5192 dst_size);
5193 }
5194 return false;
5195}
Greg Claytona8022fa2012-04-24 21:22:41 +00005196
5197TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005198SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005199{
5200 TypeSP type_sp;
5201
Greg Clayton1be10fc2010-09-29 01:12:09 +00005202 if (type_is_new_ptr)
5203 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005204
5205#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5206 static DIEStack g_die_stack;
5207 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5208#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005209
Sean Callananc7fbf732010-08-06 00:32:49 +00005210 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005211 if (die != NULL)
5212 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005213 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005214 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005215 {
5216 const DWARFDebugInfoEntry *context_die;
5217 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5218
Greg Clayton1fba87112012-02-09 20:03:49 +00005219 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
Sean Callanan5b26f272012-02-04 08:49:35 +00005220 die->GetOffset(),
5221 context,
5222 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005223 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005224 die->GetName(this, dwarf_cu));
5225
5226#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5227 scoped_die_logger.Push (dwarf_cu, die);
5228 g_die_stack.LogDIEs(log.get(), this);
5229#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005230 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005231//
5232// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5233// if (log && dwarf_cu)
5234// {
5235// StreamString s;
5236// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005237// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005238//
5239// }
Jim Ingham16746d12011-08-25 23:21:43 +00005240
Greg Clayton594e5ed2010-09-27 21:07:38 +00005241 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005242 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005243 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005244 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005245 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005246 if (type_is_new_ptr)
5247 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005248
Greg Clayton594e5ed2010-09-27 21:07:38 +00005249 const dw_tag_t tag = die->Tag();
5250
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005251 bool is_forward_declaration = false;
5252 DWARFDebugInfoEntry::Attributes attributes;
5253 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005254 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005255 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5256 size_t byte_size = 0;
5257 Declaration decl;
5258
Greg Clayton4957bf62010-09-30 21:49:03 +00005259 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005260 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005262 dw_attr_t attr;
5263
5264 switch (tag)
5265 {
5266 case DW_TAG_base_type:
5267 case DW_TAG_pointer_type:
5268 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005269 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005270 case DW_TAG_typedef:
5271 case DW_TAG_const_type:
5272 case DW_TAG_restrict_type:
5273 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005274 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005275 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005276 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005277 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005278
Greg Claytond88d7592010-09-15 08:33:30 +00005279 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005280 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005281 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5282
5283 if (num_attributes > 0)
5284 {
5285 uint32_t i;
5286 for (i=0; i<num_attributes; ++i)
5287 {
5288 attr = attributes.AttributeAtIndex(i);
5289 DWARFFormValue form_value;
5290 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5291 {
5292 switch (attr)
5293 {
5294 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5295 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5296 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5297 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005298
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005299 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005300 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5301 // include the "&"...
5302 if (tag == DW_TAG_reference_type)
5303 {
5304 if (strchr (type_name_cstr, '&') == NULL)
5305 type_name_cstr = NULL;
5306 }
5307 if (type_name_cstr)
5308 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005309 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005310 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005311 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5312 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5313 default:
5314 case DW_AT_sibling:
5315 break;
5316 }
5317 }
5318 }
5319 }
5320
Greg Clayton81c22f62011-10-19 18:09:39 +00005321 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00005322
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005323 switch (tag)
5324 {
5325 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005326 break;
5327
Greg Claytond4436412011-10-28 21:00:00 +00005328 case DW_TAG_unspecified_type:
5329 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5330 {
5331 resolve_state = Type::eResolveStateFull;
5332 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5333 break;
5334 }
5335 // Fall through to base type below in case we can handle the type there...
5336
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005337 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005338 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005339 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5340 encoding,
5341 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005342 break;
5343
Sean Callanance8af862012-05-21 23:31:51 +00005344 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5345 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5346 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5347 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5348 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5349 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5350 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005351 }
5352
Greg Claytonc7f03b62012-01-12 04:33:28 +00005353 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005354 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005355 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
5356 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005357 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005358 static ConstString g_objc_type_name_id("id");
5359 static ConstString g_objc_type_name_Class("Class");
5360 static ConstString g_objc_type_name_selector("SEL");
5361
5362 if (type_name_const_str == g_objc_type_name_id)
5363 {
5364 if (log)
5365 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5366 die->GetOffset(),
5367 DW_TAG_value_to_name(die->Tag()),
5368 die->GetName(this, dwarf_cu));
5369 clang_type = ast.GetBuiltInType_objc_id();
5370 encoding_data_type = Type::eEncodingIsUID;
5371 encoding_uid = LLDB_INVALID_UID;
5372 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005373
Greg Claytonc7f03b62012-01-12 04:33:28 +00005374 }
5375 else if (type_name_const_str == g_objc_type_name_Class)
5376 {
5377 if (log)
5378 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5379 die->GetOffset(),
5380 DW_TAG_value_to_name(die->Tag()),
5381 die->GetName(this, dwarf_cu));
5382 clang_type = ast.GetBuiltInType_objc_Class();
5383 encoding_data_type = Type::eEncodingIsUID;
5384 encoding_uid = LLDB_INVALID_UID;
5385 resolve_state = Type::eResolveStateFull;
5386 }
5387 else if (type_name_const_str == g_objc_type_name_selector)
5388 {
5389 if (log)
5390 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5391 die->GetOffset(),
5392 DW_TAG_value_to_name(die->Tag()),
5393 die->GetName(this, dwarf_cu));
5394 clang_type = ast.GetBuiltInType_objc_selector();
5395 encoding_data_type = Type::eEncodingIsUID;
5396 encoding_uid = LLDB_INVALID_UID;
5397 resolve_state = Type::eResolveStateFull;
5398 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005399 }
5400 }
5401
Greg Clayton81c22f62011-10-19 18:09:39 +00005402 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005403 this,
5404 type_name_const_str,
5405 byte_size,
5406 NULL,
5407 encoding_uid,
5408 encoding_data_type,
5409 &decl,
5410 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005411 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005412
Greg Clayton594e5ed2010-09-27 21:07:38 +00005413 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005414
5415// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5416// if (encoding_type != NULL)
5417// {
5418// if (encoding_type != DIE_IS_BEING_PARSED)
5419// type_sp->SetEncodingType(encoding_type);
5420// else
5421// m_indirect_fixups.push_back(type_sp.get());
5422// }
5423 }
5424 break;
5425
5426 case DW_TAG_structure_type:
5427 case DW_TAG_union_type:
5428 case DW_TAG_class_type:
5429 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005430 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005431 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005432 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005433
Greg Clayton9e409562010-07-28 02:04:09 +00005434 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005435 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005436 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005437 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005438 if (num_attributes > 0)
5439 {
5440 uint32_t i;
5441 for (i=0; i<num_attributes; ++i)
5442 {
5443 attr = attributes.AttributeAtIndex(i);
5444 DWARFFormValue form_value;
5445 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5446 {
5447 switch (attr)
5448 {
Greg Clayton9e409562010-07-28 02:04:09 +00005449 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005450 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5451 {
5452 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5453 // point to the compile unit file, so we clear this invalid value
5454 // so that we can still unique types efficiently.
5455 decl.SetFile(FileSpec ("<invalid>", false));
5456 }
5457 else
5458 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005459 break;
5460
5461 case DW_AT_decl_line:
5462 decl.SetLine(form_value.Unsigned());
5463 break;
5464
5465 case DW_AT_decl_column:
5466 decl.SetColumn(form_value.Unsigned());
5467 break;
5468
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005469 case DW_AT_name:
5470 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005471 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005472 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005473
5474 case DW_AT_byte_size:
5475 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005476 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005477 break;
5478
5479 case DW_AT_accessibility:
5480 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5481 break;
5482
5483 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005484 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005485 break;
5486
5487 case DW_AT_APPLE_runtime_class:
5488 class_language = (LanguageType)form_value.Signed();
5489 break;
5490
Greg Clayton18774842011-11-29 23:40:34 +00005491 case DW_AT_APPLE_objc_complete_type:
5492 is_complete_objc_class = form_value.Signed();
5493 break;
5494
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005495 case DW_AT_allocated:
5496 case DW_AT_associated:
5497 case DW_AT_data_location:
5498 case DW_AT_description:
5499 case DW_AT_start_scope:
5500 case DW_AT_visibility:
5501 default:
5502 case DW_AT_sibling:
5503 break;
5504 }
5505 }
5506 }
5507 }
5508
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005509 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005510
Greg Clayton123edca2012-03-02 00:07:15 +00005511 // Only try and unique the type if it has a name.
5512 if (type_name_const_str &&
5513 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005514 this,
5515 dwarf_cu,
5516 die,
5517 decl,
5518 byte_size_valid ? byte_size : -1,
5519 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005520 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005521 // We have already parsed this type or from another
5522 // compile unit. GCC loves to use the "one definition
5523 // rule" which can result in multiple definitions
5524 // of the same class over and over in each compile
5525 // unit.
5526 type_sp = unique_ast_entry.m_type_sp;
5527 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005528 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005529 m_die_to_type[die] = type_sp.get();
5530 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005531 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005532 }
5533
Greg Clayton81c22f62011-10-19 18:09:39 +00005534 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005535
5536 int tag_decl_kind = -1;
5537 AccessType default_accessibility = eAccessNone;
5538 if (tag == DW_TAG_structure_type)
5539 {
5540 tag_decl_kind = clang::TTK_Struct;
5541 default_accessibility = eAccessPublic;
5542 }
5543 else if (tag == DW_TAG_union_type)
5544 {
5545 tag_decl_kind = clang::TTK_Union;
5546 default_accessibility = eAccessPublic;
5547 }
5548 else if (tag == DW_TAG_class_type)
5549 {
5550 tag_decl_kind = clang::TTK_Class;
5551 default_accessibility = eAccessPrivate;
5552 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005553
5554 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5555 die->HasChildren() == false &&
5556 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5557 {
5558 // Work around an issue with clang at the moment where
5559 // forward declarations for objective C classes are emitted
5560 // as:
5561 // DW_TAG_structure_type [2]
5562 // DW_AT_name( "ForwardObjcClass" )
5563 // DW_AT_byte_size( 0x00 )
5564 // DW_AT_decl_file( "..." )
5565 // DW_AT_decl_line( 1 )
5566 //
5567 // Note that there is no DW_AT_declaration and there are
5568 // no children, and the byte size is zero.
5569 is_forward_declaration = true;
5570 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005571
Sean Callanan7457f8d2012-04-25 01:03:57 +00005572 if (class_language == eLanguageTypeObjC ||
5573 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005574 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005575 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005576 {
5577 // We have a valid eSymbolTypeObjCClass class symbol whose
5578 // name matches the current objective C class that we
5579 // are trying to find and this DIE isn't the complete
5580 // definition (we checked is_complete_objc_class above and
5581 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005582 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005583
Greg Clayton1f746072012-08-29 21:13:06 +00005584 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton901c5ca2011-12-03 04:40:03 +00005585 {
5586 // We weren't able to find a full declaration in
5587 // this DWARF, see if we have a declaration anywhere
5588 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005589 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005590 }
5591
5592 if (type_sp)
5593 {
5594 if (log)
5595 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005596 GetObjectFile()->GetModule()->LogMessage (log.get(),
5597 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
5598 this,
5599 die->GetOffset(),
5600 DW_TAG_value_to_name(tag),
5601 type_name_cstr,
5602 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005603 }
5604
5605 // We found a real definition for this type elsewhere
5606 // so lets use it and cache the fact that we found
5607 // a complete type for this die
5608 m_die_to_type[die] = type_sp.get();
5609 return type_sp;
5610 }
5611 }
5612 }
5613
5614
5615 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005616 {
5617 // We have a forward declaration to a type and we need
5618 // to try and find a full declaration. We look in the
5619 // current type index just in case we have a forward
5620 // declaration followed by an actual declarations in the
5621 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005622 if (log)
5623 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005624 GetObjectFile()->GetModule()->LogMessage (log.get(),
5625 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5626 this,
5627 die->GetOffset(),
5628 DW_TAG_value_to_name(tag),
5629 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005630 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005631
Greg Claytona8022fa2012-04-24 21:22:41 +00005632 DWARFDeclContext die_decl_ctx;
5633 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5634
5635 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5636 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005637
Greg Clayton1f746072012-08-29 21:13:06 +00005638 if (!type_sp && GetDebugMapSymfile ())
Greg Clayton4272cc72011-02-02 02:24:04 +00005639 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005640 // We weren't able to find a full declaration in
5641 // this DWARF, see if we have a declaration anywhere
5642 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005643 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005644 }
5645
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005646 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005647 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005648 if (log)
5649 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005650 GetObjectFile()->GetModule()->LogMessage (log.get(),
5651 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5652 this,
5653 die->GetOffset(),
5654 DW_TAG_value_to_name(tag),
5655 type_name_cstr,
5656 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005657 }
5658
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005659 // We found a real definition for this type elsewhere
5660 // so lets use it and cache the fact that we found
5661 // a complete type for this die
5662 m_die_to_type[die] = type_sp.get();
5663 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005664 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005665 }
5666 assert (tag_decl_kind != -1);
5667 bool clang_type_was_created = false;
5668 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5669 if (clang_type == NULL)
5670 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005671 const DWARFDebugInfoEntry *decl_ctx_die;
5672
5673 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005674 if (accessibility == eAccessNone && decl_ctx)
5675 {
5676 // Check the decl context that contains this class/struct/union.
5677 // If it is a class we must give it an accessability.
5678 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5679 if (DeclKindIsCXXClass (containing_decl_kind))
5680 accessibility = default_accessibility;
5681 }
5682
Greg Claytonf0705c82011-10-22 03:33:13 +00005683 if (type_name_cstr && strchr (type_name_cstr, '<'))
5684 {
5685 ClangASTContext::TemplateParameterInfos template_param_infos;
5686 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5687 {
5688 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005689 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005690 type_name_cstr,
5691 tag_decl_kind,
5692 template_param_infos);
5693
5694 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5695 class_template_decl,
5696 tag_decl_kind,
5697 template_param_infos);
5698 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5699 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005700
Jim Ingham379397632012-10-27 02:54:13 +00005701 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
5702 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005703 }
5704 }
5705
5706 if (!clang_type_was_created)
5707 {
5708 clang_type_was_created = true;
Jim Ingham379397632012-10-27 02:54:13 +00005709 ClangASTMetadata metadata;
5710 metadata.SetUserID(MakeUserID(die->GetOffset()));
Greg Clayton55561e92011-10-26 03:31:36 +00005711 clang_type = ast.CreateRecordType (decl_ctx,
5712 accessibility,
5713 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005714 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005715 class_language,
Jim Ingham379397632012-10-27 02:54:13 +00005716 &metadata);
Greg Claytonf0705c82011-10-22 03:33:13 +00005717 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005718 }
5719
5720 // Store a forward declaration to this class type in case any
5721 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005722 // types for function prototypes.
5723 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005724 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005725 this,
5726 type_name_const_str,
5727 byte_size,
5728 NULL,
5729 LLDB_INVALID_UID,
5730 Type::eEncodingIsUID,
5731 &decl,
5732 clang_type,
5733 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005734
5735 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005736
5737
5738 // Add our type to the unique type map so we don't
5739 // end up creating many copies of the same type over
5740 // and over in the ASTContext for our module
5741 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005742 unique_ast_entry.m_symfile = this;
5743 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005744 unique_ast_entry.m_die = die;
5745 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005746 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005747 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5748 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005749
Sean Callanan12014a02011-12-08 23:45:45 +00005750 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005751 {
5752 // Always start the definition for a class type so that
5753 // if the class has child classes or types that require
5754 // the class to be created for use as their decl contexts
5755 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005756 if (die->HasChildren() == false)
5757 {
5758 // No children for this struct/union/class, lets finish it
5759 ast.StartTagDeclarationDefinition (clang_type);
5760 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan433cd222012-10-19 01:37:25 +00005761
5762 if (tag == DW_TAG_structure_type) // this only applies in C
5763 {
5764 clang::QualType qual_type = clang::QualType::getFromOpaquePtr (clang_type);
5765 const clang::RecordType *record_type = qual_type->getAs<clang::RecordType> ();
5766
5767 if (record_type)
5768 {
5769 clang::RecordDecl *record_decl = record_type->getDecl();
5770
5771 if (record_decl)
5772 {
5773 LayoutInfo layout_info;
5774
5775 layout_info.alignment = 0;
5776 layout_info.bit_size = 0;
5777
5778 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
5779 }
5780 }
5781 }
Sean Callanan12014a02011-12-08 23:45:45 +00005782 }
5783 else if (clang_type_was_created)
5784 {
Greg Clayton219cf312012-03-30 00:51:13 +00005785 // Start the definition if the class is not objective C since
5786 // the underlying decls respond to isCompleteDefinition(). Objective
5787 // C decls dont' respond to isCompleteDefinition() so we can't
5788 // start the declaration definition right away. For C++ classs/union/structs
5789 // we want to start the definition in case the class is needed as the
5790 // declaration context for a contained class or type without the need
5791 // to complete that type..
5792
Sean Callanan7457f8d2012-04-25 01:03:57 +00005793 if (class_language != eLanguageTypeObjC &&
5794 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00005795 ast.StartTagDeclarationDefinition (clang_type);
5796
Sean Callanan12014a02011-12-08 23:45:45 +00005797 // Leave this as a forward declaration until we need
5798 // to know the details of the type. lldb_private::Type
5799 // will automatically call the SymbolFile virtual function
5800 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5801 // When the definition needs to be defined.
5802 m_forward_decl_die_to_clang_type[die] = clang_type;
5803 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5804 ClangASTContext::SetHasExternalStorage (clang_type, true);
5805 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005806 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005807
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005808 }
5809 break;
5810
5811 case DW_TAG_enumeration_type:
5812 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005813 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005814 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005815
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005816 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005817
Greg Claytond88d7592010-09-15 08:33:30 +00005818 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005819 if (num_attributes > 0)
5820 {
5821 uint32_t i;
5822
5823 for (i=0; i<num_attributes; ++i)
5824 {
5825 attr = attributes.AttributeAtIndex(i);
5826 DWARFFormValue form_value;
5827 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5828 {
5829 switch (attr)
5830 {
Greg Clayton7a345282010-11-09 23:46:37 +00005831 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5832 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5833 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005834 case DW_AT_name:
5835 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005836 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005837 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005838 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00005839 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
5840 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5841 case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005842 case DW_AT_allocated:
5843 case DW_AT_associated:
5844 case DW_AT_bit_stride:
5845 case DW_AT_byte_stride:
5846 case DW_AT_data_location:
5847 case DW_AT_description:
5848 case DW_AT_start_scope:
5849 case DW_AT_visibility:
5850 case DW_AT_specification:
5851 case DW_AT_abstract_origin:
5852 case DW_AT_sibling:
5853 break;
5854 }
5855 }
5856 }
5857
Greg Clayton81c22f62011-10-19 18:09:39 +00005858 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00005859
Greg Clayton1be10fc2010-09-29 01:12:09 +00005860 clang_type_t enumerator_clang_type = NULL;
5861 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5862 if (clang_type == NULL)
5863 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005864 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5865 DW_ATE_signed,
5866 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005867 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005868 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005869 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005870 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005871 }
5872 else
5873 {
5874 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5875 assert (enumerator_clang_type != NULL);
5876 }
5877
Greg Claytona2721472011-06-25 00:44:06 +00005878 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5879
Greg Clayton81c22f62011-10-19 18:09:39 +00005880 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005881 this,
5882 type_name_const_str,
5883 byte_size,
5884 NULL,
5885 encoding_uid,
5886 Type::eEncodingIsUID,
5887 &decl,
5888 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005889 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005890
Greg Clayton6beaaa62011-01-17 03:46:26 +00005891 ast.StartTagDeclarationDefinition (clang_type);
5892 if (die->HasChildren())
5893 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005894 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5895 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005896 }
5897 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005898 }
5899 }
5900 break;
5901
Jim Inghamb0be4422010-08-12 01:20:14 +00005902 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005903 case DW_TAG_subprogram:
5904 case DW_TAG_subroutine_type:
5905 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005906 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005907 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005908
Greg Clayton23f59502012-07-17 03:23:13 +00005909 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005910 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005911 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005912 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005913 bool is_static = false;
5914 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005915 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005916 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005917 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5918 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Jim Ingham379397632012-10-27 02:54:13 +00005919 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005920
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005921 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005922 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005923
5924
Greg Claytond88d7592010-09-15 08:33:30 +00005925 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005926 if (num_attributes > 0)
5927 {
5928 uint32_t i;
5929 for (i=0; i<num_attributes; ++i)
5930 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005931 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005932 DWARFFormValue form_value;
5933 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5934 {
5935 switch (attr)
5936 {
5937 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5938 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5939 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5940 case DW_AT_name:
5941 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005942 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005943 break;
5944
Greg Clayton23f59502012-07-17 03:23:13 +00005945 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005946 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005947 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00005948 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005949 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5950 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005951 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005952 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5953
Greg Claytonf51de672010-10-01 02:31:07 +00005954
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005955 case DW_AT_external:
5956 if (form_value.Unsigned())
5957 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005958 if (storage == clang::SC_None)
5959 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005960 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005961 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005962 }
5963 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005964
Greg Clayton72da3972011-08-16 18:40:23 +00005965 case DW_AT_specification:
5966 specification_die_offset = form_value.Reference(dwarf_cu);
5967 break;
5968
5969 case DW_AT_abstract_origin:
5970 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5971 break;
5972
Jim Ingham379397632012-10-27 02:54:13 +00005973 case DW_AT_object_pointer:
5974 object_pointer_die_offset = form_value.Reference(dwarf_cu);
5975 break;
5976
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005977 case DW_AT_allocated:
5978 case DW_AT_associated:
5979 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005980 case DW_AT_calling_convention:
5981 case DW_AT_data_location:
5982 case DW_AT_elemental:
5983 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005984 case DW_AT_frame_base:
5985 case DW_AT_high_pc:
5986 case DW_AT_low_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005987 case DW_AT_prototyped:
5988 case DW_AT_pure:
5989 case DW_AT_ranges:
5990 case DW_AT_recursive:
5991 case DW_AT_return_addr:
5992 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005993 case DW_AT_start_scope:
5994 case DW_AT_static_link:
5995 case DW_AT_trampoline:
5996 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005997 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005998 case DW_AT_description:
5999 case DW_AT_sibling:
6000 break;
6001 }
6002 }
6003 }
Greg Clayton24739922010-10-13 03:15:28 +00006004 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006005
Jim Ingham379397632012-10-27 02:54:13 +00006006 std::string object_pointer_name;
6007 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6008 {
6009 // Get the name from the object pointer die
6010 StreamString s;
6011 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6012 {
6013 object_pointer_name.assign(s.GetData());
6014 }
6015 }
6016
Greg Clayton81c22f62011-10-19 18:09:39 +00006017 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006018
Greg Clayton24739922010-10-13 03:15:28 +00006019 clang_type_t return_clang_type = NULL;
6020 Type *func_type = NULL;
6021
6022 if (type_die_offset != DW_INVALID_OFFSET)
6023 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00006024
Greg Clayton24739922010-10-13 03:15:28 +00006025 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00006026 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00006027 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006028 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006029
Greg Claytonf51de672010-10-01 02:31:07 +00006030
Greg Clayton24739922010-10-13 03:15:28 +00006031 std::vector<clang_type_t> function_param_types;
6032 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006033
Greg Clayton24739922010-10-13 03:15:28 +00006034 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00006035
Greg Claytoncb5860a2011-10-13 23:49:28 +00006036 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6037 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00006038 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6039
Greg Claytonf0705c82011-10-22 03:33:13 +00006040 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00006041 // Start off static. This will be set to false in ParseChildParameters(...)
6042 // if we find a "this" paramters as the first parameter
6043 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00006044 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006045 ClangASTContext::TemplateParameterInfos template_param_infos;
6046
Greg Clayton24739922010-10-13 03:15:28 +00006047 if (die->HasChildren())
6048 {
Greg Clayton0fffff52010-09-24 05:15:53 +00006049 bool skip_artificial = true;
Jim Ingham379397632012-10-27 02:54:13 +00006050 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00006051 containing_decl_ctx,
Jim Ingham379397632012-10-27 02:54:13 +00006052 dwarf_cu,
6053 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00006054 skip_artificial,
6055 is_static,
Jim Ingham379397632012-10-27 02:54:13 +00006056 type_list,
6057 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00006058 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006059 type_quals,
6060 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00006061 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006062
Greg Clayton24739922010-10-13 03:15:28 +00006063 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006064 clang_type = ast.CreateFunctionType (return_clang_type,
Greg Clayton9cb25c42012-10-30 17:02:18 +00006065 function_param_types.data(),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006066 function_param_types.size(),
6067 is_variadic,
6068 type_quals);
6069
Greg Clayton24739922010-10-13 03:15:28 +00006070 if (type_name_cstr)
6071 {
6072 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00006073 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006074 {
Greg Clayton7c810422012-01-18 23:40:49 +00006075 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00006076 ConstString class_name_no_category;
6077 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00006078 {
Greg Claytone42ae842012-01-19 03:24:53 +00006079 // Use the class name with no category if there is one
6080 if (class_name_no_category)
6081 class_name = class_name_no_category;
6082
Greg Clayton24739922010-10-13 03:15:28 +00006083 SymbolContext empty_sc;
6084 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00006085 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00006086 {
Greg Clayton24739922010-10-13 03:15:28 +00006087 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00006088 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00006089
6090 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00006091 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00006092 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6093 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
6094 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00006095 }
Greg Clayton24739922010-10-13 03:15:28 +00006096 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006097
Greg Clayton24739922010-10-13 03:15:28 +00006098 if (class_opaque_type)
6099 {
6100 // If accessibility isn't set to anything valid, assume public for
6101 // now...
6102 if (accessibility == eAccessNone)
6103 accessibility = eAccessPublic;
6104
Sean Callanan464a5b52012-10-04 22:06:29 +00006105 clang::ObjCMethodDecl *objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
6106 type_name_cstr,
6107 clang_type,
6108 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00006109 type_handled = objc_method_decl != NULL;
Sean Callanan464a5b52012-10-04 22:06:29 +00006110 if (type_handled)
6111 {
6112 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Jim Ingham379397632012-10-27 02:54:13 +00006113 GetClangASTContext().SetMetadataAsUserID ((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Sean Callanan464a5b52012-10-04 22:06:29 +00006114 }
Greg Clayton24739922010-10-13 03:15:28 +00006115 }
6116 }
Greg Clayton5113dc82011-08-12 06:47:54 +00006117 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00006118 {
6119 // Look at the parent of this DIE and see if is is
6120 // a class or struct and see if this is actually a
6121 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00006122 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00006123 if (class_type)
6124 {
Greg Clayton4116e932012-05-15 02:33:01 +00006125 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6126 {
6127 // We uniqued the parent class of this function to another class
6128 // so we now need to associate all dies under "decl_ctx_die" to
6129 // DIEs in the DIE for "class_type"...
6130 DWARFCompileUnitSP class_type_cu_sp;
6131 const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6132 if (class_type_die)
6133 {
6134 if (CopyUniqueClassMethodTypes (class_type,
6135 class_type_cu_sp.get(),
6136 class_type_die,
6137 dwarf_cu,
6138 decl_ctx_die))
6139 {
6140 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006141 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00006142 {
6143 type_sp = type_ptr->shared_from_this();
6144 break;
6145 }
6146 }
6147 }
6148 }
6149
Greg Clayton72da3972011-08-16 18:40:23 +00006150 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00006151 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006152 // We have a specification which we are going to base our function
6153 // prototype off of, so we need this type to be completed so that the
6154 // m_die_to_decl_ctx for the method in the specification has a valid
6155 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006156 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00006157 // If we have a specification, then the function type should have been
6158 // made with the specification and not with this die.
6159 DWARFCompileUnitSP spec_cu_sp;
6160 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006161 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006162 if (spec_clang_decl_ctx)
6163 {
6164 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6165 }
6166 else
Jim Inghamc1663042011-09-29 22:12:35 +00006167 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006168 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
6169 MakeUserID(die->GetOffset()),
6170 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006171 }
Greg Clayton72da3972011-08-16 18:40:23 +00006172 type_handled = true;
6173 }
6174 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6175 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00006176 // We have a specification which we are going to base our function
6177 // prototype off of, so we need this type to be completed so that the
6178 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6179 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00006180 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00006181
Greg Clayton72da3972011-08-16 18:40:23 +00006182 DWARFCompileUnitSP abs_cu_sp;
6183 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00006184 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00006185 if (abs_clang_decl_ctx)
6186 {
6187 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6188 }
6189 else
Jim Inghamc1663042011-09-29 22:12:35 +00006190 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006191 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
6192 MakeUserID(die->GetOffset()),
6193 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00006194 }
Greg Clayton72da3972011-08-16 18:40:23 +00006195 type_handled = true;
6196 }
6197 else
6198 {
6199 clang_type_t class_opaque_type = class_type->GetClangForwardType();
6200 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00006201 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006202 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00006203 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006204 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6205 // in the DWARF for C++ methods... Default to public for now...
6206 if (accessibility == eAccessNone)
6207 accessibility = eAccessPublic;
6208
6209 if (!is_static && !die->HasChildren())
6210 {
6211 // We have a C++ member function with no children (this pointer!)
6212 // and clang will get mad if we try and make a function that isn't
6213 // well formed in the DWARF, so we will just skip it...
6214 type_handled = true;
6215 }
6216 else
6217 {
6218 clang::CXXMethodDecl *cxx_method_decl;
6219 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00006220 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s",
Greg Clayton20568dd2011-10-13 23:13:20 +00006221 type_name_cstr,
6222 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006223 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006224 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6225 m_obj_file->GetFileSpec().GetFilename().GetCString());
6226
Sean Callananc1b732d2011-11-01 18:07:13 +00006227 const bool is_attr_used = false;
6228
Greg Clayton20568dd2011-10-13 23:13:20 +00006229 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6230 type_name_cstr,
6231 clang_type,
6232 accessibility,
6233 is_virtual,
6234 is_static,
6235 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006236 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006237 is_attr_used,
6238 is_artificial);
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006239
Greg Clayton20568dd2011-10-13 23:13:20 +00006240 type_handled = cxx_method_decl != NULL;
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006241
6242 if (type_handled)
Jim Ingham379397632012-10-27 02:54:13 +00006243 {
Sean Callanan4ac7ec72012-10-31 02:01:58 +00006244 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6245
6246 Host::SetCrashDescription (NULL);
6247
6248
6249 ClangASTMetadata metadata;
6250 metadata.SetUserID(MakeUserID(die->GetOffset()));
6251
6252 if (!object_pointer_name.empty())
6253 {
6254 metadata.SetObjectPtrName(object_pointer_name.c_str());
6255 if (log)
6256 log->Printf ("Setting object pointer name: %s on method object 0x%ld.\n",
6257 object_pointer_name.c_str(),
6258 (uintptr_t) cxx_method_decl);
6259 }
6260 GetClangASTContext().SetMetadata ((uintptr_t)cxx_method_decl, metadata);
Jim Ingham379397632012-10-27 02:54:13 +00006261 }
Greg Clayton20568dd2011-10-13 23:13:20 +00006262 }
Greg Clayton72da3972011-08-16 18:40:23 +00006263 }
6264 else
6265 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006266 // We were asked to parse the type for a method in a class, yet the
6267 // class hasn't been asked to complete itself through the
6268 // clang::ExternalASTSource protocol, so we need to just have the
6269 // class complete itself and do things the right way, then our
6270 // DIE should then have an entry in the m_die_to_type map. First
6271 // we need to modify the m_die_to_type so it doesn't think we are
6272 // trying to parse this DIE anymore...
6273 m_die_to_type[die] = NULL;
6274
6275 // Now we get the full type to force our class type to complete itself
6276 // using the clang::ExternalASTSource protocol which will parse all
6277 // base classes and all methods (including the method for this DIE).
6278 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006279
Greg Clayton20568dd2011-10-13 23:13:20 +00006280 // The type for this DIE should have been filled in the function call above
6281 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006282 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006283 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006284 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006285 break;
6286 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006287
6288 // FIXME This is fixing some even uglier behavior but we really need to
6289 // uniq the methods of each class as well as the class itself.
6290 // <rdar://problem/11240464>
6291 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006292 }
Greg Clayton931180e2011-01-27 06:44:37 +00006293 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006294 }
6295 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006296 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006297 }
Greg Clayton24739922010-10-13 03:15:28 +00006298
6299 if (!type_handled)
6300 {
6301 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006302 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6303 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006304 clang_type,
6305 storage,
6306 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006307
6308// if (template_param_infos.GetSize() > 0)
6309// {
6310// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6311// function_decl,
6312// type_name_cstr,
6313// template_param_infos);
6314//
6315// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6316// func_template_decl,
6317// template_param_infos);
6318// }
Greg Clayton24739922010-10-13 03:15:28 +00006319 // Add the decl to our DIE to decl context map
6320 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006321 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006322 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006323 ast.SetFunctionParameters (function_decl,
6324 &function_param_decls.front(),
6325 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006326
Jim Ingham379397632012-10-27 02:54:13 +00006327 ClangASTMetadata metadata;
6328 metadata.SetUserID(MakeUserID(die->GetOffset()));
6329
6330 if (!object_pointer_name.empty())
6331 {
6332 metadata.SetObjectPtrName(object_pointer_name.c_str());
Jim Ingham2cffda3f2012-10-30 23:34:07 +00006333 if (log)
6334 log->Printf ("Setting object pointer name: %s on function object 0x%ld.\n",
6335 object_pointer_name.c_str(),
6336 (uintptr_t) function_decl);
Jim Ingham379397632012-10-27 02:54:13 +00006337 }
6338 GetClangASTContext().SetMetadata ((uintptr_t)function_decl, metadata);
Greg Clayton24739922010-10-13 03:15:28 +00006339 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006340 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006341 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006342 this,
6343 type_name_const_str,
6344 0,
6345 NULL,
6346 LLDB_INVALID_UID,
6347 Type::eEncodingIsUID,
6348 &decl,
6349 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006350 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006351 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006352 }
6353 break;
6354
6355 case DW_TAG_array_type:
6356 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006357 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006358 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006359
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006360 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006361 int64_t first_index = 0;
6362 uint32_t byte_stride = 0;
6363 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006364 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006365
6366 if (num_attributes > 0)
6367 {
6368 uint32_t i;
6369 for (i=0; i<num_attributes; ++i)
6370 {
6371 attr = attributes.AttributeAtIndex(i);
6372 DWARFFormValue form_value;
6373 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6374 {
6375 switch (attr)
6376 {
6377 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6378 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6379 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6380 case DW_AT_name:
6381 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006382 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006383 break;
6384
6385 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006386 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006387 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6388 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006389 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6390 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006391 case DW_AT_allocated:
6392 case DW_AT_associated:
6393 case DW_AT_data_location:
6394 case DW_AT_description:
6395 case DW_AT_ordering:
6396 case DW_AT_start_scope:
6397 case DW_AT_visibility:
6398 case DW_AT_specification:
6399 case DW_AT_abstract_origin:
6400 case DW_AT_sibling:
6401 break;
6402 }
6403 }
6404 }
6405
Greg Clayton81c22f62011-10-19 18:09:39 +00006406 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00006407
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006408 Type *element_type = ResolveTypeUID(type_die_offset);
6409
6410 if (element_type)
6411 {
6412 std::vector<uint64_t> element_orders;
6413 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6414 if (byte_stride == 0 && bit_stride == 0)
6415 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006416 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006417 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6418 uint64_t num_elements = 0;
6419 std::vector<uint64_t>::const_reverse_iterator pos;
6420 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6421 for (pos = element_orders.rbegin(); pos != end; ++pos)
6422 {
6423 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006424 clang_type = ast.CreateArrayType (array_element_type,
6425 num_elements,
6426 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006427 array_element_type = clang_type;
6428 array_element_bit_stride = array_element_bit_stride * num_elements;
6429 }
6430 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006431 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006432 this,
6433 empty_name,
6434 array_element_bit_stride / 8,
6435 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006436 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006437 Type::eEncodingIsUID,
6438 &decl,
6439 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006440 Type::eResolveStateFull));
6441 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006442 }
6443 }
6444 }
6445 break;
6446
Greg Clayton9b81a312010-06-12 01:20:30 +00006447 case DW_TAG_ptr_to_member_type:
6448 {
6449 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6450 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6451
Greg Claytond88d7592010-09-15 08:33:30 +00006452 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006453
6454 if (num_attributes > 0) {
6455 uint32_t i;
6456 for (i=0; i<num_attributes; ++i)
6457 {
6458 attr = attributes.AttributeAtIndex(i);
6459 DWARFFormValue form_value;
6460 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6461 {
6462 switch (attr)
6463 {
6464 case DW_AT_type:
6465 type_die_offset = form_value.Reference(dwarf_cu); break;
6466 case DW_AT_containing_type:
6467 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6468 }
6469 }
6470 }
6471
6472 Type *pointee_type = ResolveTypeUID(type_die_offset);
6473 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6474
Greg Clayton526e5af2010-11-13 03:52:47 +00006475 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6476 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006477
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006478 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6479 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006480
Greg Clayton526e5af2010-11-13 03:52:47 +00006481 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6482 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006483
Greg Clayton81c22f62011-10-19 18:09:39 +00006484 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006485 this,
6486 type_name_const_str,
6487 byte_size,
6488 NULL,
6489 LLDB_INVALID_UID,
6490 Type::eEncodingIsUID,
6491 NULL,
6492 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006493 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006494 }
6495
6496 break;
6497 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006498 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00006499 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006500 break;
6501 }
6502
6503 if (type_sp.get())
6504 {
6505 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6506 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6507
6508 SymbolContextScope * symbol_context_scope = NULL;
6509 if (sc_parent_tag == DW_TAG_compile_unit)
6510 {
6511 symbol_context_scope = sc.comp_unit;
6512 }
6513 else if (sc.function != NULL)
6514 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006515 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006516 if (symbol_context_scope == NULL)
6517 symbol_context_scope = sc.function;
6518 }
6519
6520 if (symbol_context_scope != NULL)
6521 {
6522 type_sp->SetSymbolContextScope(symbol_context_scope);
6523 }
6524
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006525 // We are ready to put this type into the uniqued list up at the module level
6526 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006527
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006528 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006529 }
6530 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006531 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006532 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006533 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006534 }
6535 }
6536 return type_sp;
6537}
6538
6539size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006540SymbolFileDWARF::ParseTypes
6541(
6542 const SymbolContext& sc,
6543 DWARFCompileUnit* dwarf_cu,
6544 const DWARFDebugInfoEntry *die,
6545 bool parse_siblings,
6546 bool parse_children
6547)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006548{
6549 size_t types_added = 0;
6550 while (die != NULL)
6551 {
6552 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006553 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006554 {
6555 if (type_is_new)
6556 ++types_added;
6557 }
6558
6559 if (parse_children && die->HasChildren())
6560 {
6561 if (die->Tag() == DW_TAG_subprogram)
6562 {
6563 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006564 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006565 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6566 }
6567 else
6568 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6569 }
6570
6571 if (parse_siblings)
6572 die = die->GetSibling();
6573 else
6574 die = NULL;
6575 }
6576 return types_added;
6577}
6578
6579
6580size_t
6581SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6582{
6583 assert(sc.comp_unit && sc.function);
6584 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006585 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006586 if (dwarf_cu)
6587 {
6588 dw_offset_t function_die_offset = sc.function->GetID();
6589 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6590 if (function_die)
6591 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006592 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006593 }
6594 }
6595
6596 return functions_added;
6597}
6598
6599
6600size_t
6601SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6602{
6603 // At least a compile unit must be valid
6604 assert(sc.comp_unit);
6605 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00006606 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006607 if (dwarf_cu)
6608 {
6609 if (sc.function)
6610 {
6611 dw_offset_t function_die_offset = sc.function->GetID();
6612 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6613 if (func_die && func_die->HasChildren())
6614 {
6615 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6616 }
6617 }
6618 else
6619 {
6620 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6621 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6622 {
6623 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6624 }
6625 }
6626 }
6627
6628 return types_added;
6629}
6630
6631size_t
6632SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6633{
6634 if (sc.comp_unit != NULL)
6635 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006636 DWARFDebugInfo* info = DebugInfo();
6637 if (info == NULL)
6638 return 0;
6639
6640 uint32_t cu_idx = UINT32_MAX;
6641 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006642
6643 if (dwarf_cu == NULL)
6644 return 0;
6645
6646 if (sc.function)
6647 {
6648 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006649
6650 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006651 if (func_lo_pc != DW_INVALID_ADDRESS)
6652 {
6653 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006654
Greg Claytone38a5ed2012-01-05 03:57:59 +00006655 // Let all blocks know they have parse all their variables
6656 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6657 return num_variables;
6658 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006659 }
6660 else if (sc.comp_unit)
6661 {
6662 uint32_t vars_added = 0;
6663 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6664
6665 if (variables.get() == NULL)
6666 {
6667 variables.reset(new VariableList());
6668 sc.comp_unit->SetVariableList(variables);
6669
Greg Claytond4a2b372011-09-12 23:21:58 +00006670 DWARFCompileUnit* match_dwarf_cu = NULL;
6671 const DWARFDebugInfoEntry* die = NULL;
6672 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006673 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006674 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006675 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006676 {
6677 DWARFMappedHash::DIEInfoArray hash_data_array;
6678 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6679 dwarf_cu->GetNextCompileUnitOffset(),
6680 hash_data_array))
6681 {
6682 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6683 }
6684 }
Greg Clayton7f995132011-10-04 22:41:51 +00006685 }
6686 else
6687 {
6688 // Index if we already haven't to make sure the compile units
6689 // get indexed and make their global DIE index list
6690 if (!m_indexed)
6691 Index ();
6692
6693 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6694 dwarf_cu->GetNextCompileUnitOffset(),
6695 die_offsets);
6696 }
6697
6698 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006699 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006700 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006701 DWARFDebugInfo* debug_info = DebugInfo();
6702 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006703 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006704 const dw_offset_t die_offset = die_offsets[i];
6705 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006706 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006707 {
Greg Clayton95d87902011-11-11 03:16:25 +00006708 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6709 if (var_sp)
6710 {
6711 variables->AddVariableIfUnique (var_sp);
6712 ++vars_added;
6713 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006714 }
Greg Clayton95d87902011-11-11 03:16:25 +00006715 else
6716 {
6717 if (m_using_apple_tables)
6718 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006719 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 +00006720 }
6721 }
6722
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006723 }
6724 }
6725 }
6726 return vars_added;
6727 }
6728 }
6729 return 0;
6730}
6731
6732
6733VariableSP
6734SymbolFileDWARF::ParseVariableDIE
6735(
6736 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006737 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006738 const DWARFDebugInfoEntry *die,
6739 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006740)
6741{
6742
Greg Clayton83c5cd92010-11-14 22:13:40 +00006743 VariableSP var_sp (m_die_to_variable_sp[die]);
6744 if (var_sp)
6745 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006746
6747 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006748
6749 if ((tag == DW_TAG_variable) ||
6750 (tag == DW_TAG_constant) ||
6751 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006752 {
Greg Clayton7f995132011-10-04 22:41:51 +00006753 DWARFDebugInfoEntry::Attributes attributes;
6754 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6755 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006756 {
Greg Clayton7f995132011-10-04 22:41:51 +00006757 const char *name = NULL;
6758 const char *mangled = NULL;
6759 Declaration decl;
6760 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006761 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006762 DWARFExpression location;
6763 bool is_external = false;
6764 bool is_artificial = false;
6765 bool location_is_const_value_data = false;
Greg Clayton23f59502012-07-17 03:23:13 +00006766 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00006767
6768 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006769 {
Greg Clayton7f995132011-10-04 22:41:51 +00006770 dw_attr_t attr = attributes.AttributeAtIndex(i);
6771 DWARFFormValue form_value;
6772 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006773 {
Greg Clayton7f995132011-10-04 22:41:51 +00006774 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006775 {
Greg Clayton7f995132011-10-04 22:41:51 +00006776 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6777 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6778 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6779 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6780 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006781 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006782 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6783 case DW_AT_const_value:
6784 location_is_const_value_data = true;
6785 // Fall through...
6786 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006787 {
Greg Clayton7f995132011-10-04 22:41:51 +00006788 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006789 {
Greg Clayton7f995132011-10-04 22:41:51 +00006790 const DataExtractor& debug_info_data = get_debug_info_data();
6791
6792 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6793 uint32_t block_length = form_value.Unsigned();
Greg Clayton7f4c7432012-08-11 00:49:14 +00006794 location.CopyOpcodeData(get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00006795 }
6796 else
6797 {
6798 const DataExtractor& debug_loc_data = get_debug_loc_data();
6799 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6800
6801 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6802 if (loc_list_length > 0)
6803 {
Greg Clayton7f4c7432012-08-11 00:49:14 +00006804 location.CopyOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00006805 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6806 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6807 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006808 }
6809 }
Greg Clayton7f995132011-10-04 22:41:51 +00006810 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006811
Greg Clayton7f995132011-10-04 22:41:51 +00006812 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00006813 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006814 case DW_AT_declaration:
6815 case DW_AT_description:
6816 case DW_AT_endianity:
6817 case DW_AT_segment:
6818 case DW_AT_start_scope:
6819 case DW_AT_visibility:
6820 default:
6821 case DW_AT_abstract_origin:
6822 case DW_AT_sibling:
6823 case DW_AT_specification:
6824 break;
6825 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006826 }
6827 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006828
Greg Clayton7f995132011-10-04 22:41:51 +00006829 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006830 {
Greg Clayton7f995132011-10-04 22:41:51 +00006831 ValueType scope = eValueTypeInvalid;
6832
6833 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6834 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006835 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006836
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006837 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6838 // or static variable, so we have to do a little digging by
6839 // looking at the location of a varaible to see if it contains
6840 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6841 // somewhere because clang likes to combine small global variables
6842 // into the same symbol and have locations like:
6843 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6844 // So if we don't have a DW_TAG_formal_parameter, we can look at
6845 // the location to see if it contains a DW_OP_addr opcode, and
6846 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006847 if (tag == DW_TAG_formal_parameter)
6848 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006849 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006850 {
Greg Clayton96c09682012-01-04 22:56:43 +00006851 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006852 // Check if the location has a DW_OP_addr with any address value...
6853 addr_t location_has_op_addr = false;
6854 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006855 {
6856 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6857 if (op_error)
6858 {
6859 StreamString strm;
6860 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006861 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 +00006862 }
6863 }
Greg Claytond1767f02011-12-08 02:13:16 +00006864
6865 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006866 {
Greg Claytond1767f02011-12-08 02:13:16 +00006867 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006868 {
Greg Claytond1767f02011-12-08 02:13:16 +00006869 scope = eValueTypeVariableGlobal;
6870
Greg Clayton1f746072012-08-29 21:13:06 +00006871 if (GetDebugMapSymfile ())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006872 {
Greg Claytond1767f02011-12-08 02:13:16 +00006873 // When leaving the DWARF in the .o files on darwin,
6874 // when we have a global variable that wasn't initialized,
6875 // the .o file might not have allocated a virtual
6876 // address for the global variable. In this case it will
6877 // have created a symbol for the global variable
6878 // that is undefined and external and the value will
6879 // be the byte size of the variable. When we do the
6880 // address map in SymbolFileDWARFDebugMap we rely on
6881 // having an address, we need to do some magic here
6882 // so we can get the correct address for our global
6883 // variable. The address for all of these entries
6884 // will be zero, and there will be an undefined symbol
6885 // in this object file, and the executable will have
6886 // a matching symbol with a good address. So here we
6887 // dig up the correct address and replace it in the
6888 // location for the variable, and set the variable's
6889 // symbol context scope to be that of the main executable
6890 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006891 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006892 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006893
Greg Claytond1767f02011-12-08 02:13:16 +00006894 // we have a possible uninitialized extern global
6895 Symtab *symtab = m_obj_file->GetSymtab();
6896 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006897 {
Greg Claytond1767f02011-12-08 02:13:16 +00006898 ConstString const_name(name);
6899 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6900 eSymbolTypeUndefined,
6901 Symtab::eDebugNo,
6902 Symtab::eVisibilityExtern);
6903
6904 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006905 {
Greg Claytond1767f02011-12-08 02:13:16 +00006906 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6907 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006908 {
Greg Claytond1767f02011-12-08 02:13:16 +00006909 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6910 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6911 eSymbolTypeData,
6912 Symtab::eDebugYes,
6913 Symtab::eVisibilityExtern);
6914 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006915 {
Greg Claytone7612132012-03-07 21:03:09 +00006916 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006917 {
Greg Claytone7612132012-03-07 21:03:09 +00006918 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006919 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006920 {
Greg Claytond1767f02011-12-08 02:13:16 +00006921 if (location.Update_DW_OP_addr (defined_addr))
6922 {
6923 symbol_context_scope = defined_symbol;
6924 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006925 }
6926 }
6927 }
6928 }
6929 }
6930 }
6931 }
6932 }
6933 }
Greg Claytond1767f02011-12-08 02:13:16 +00006934 else
6935 {
6936 scope = eValueTypeVariableStatic;
6937 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006938 }
6939 else
Greg Claytond1767f02011-12-08 02:13:16 +00006940 {
6941 scope = eValueTypeVariableLocal;
6942 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006943 }
Greg Clayton7f995132011-10-04 22:41:51 +00006944
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006945 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006946 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006947 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006948 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006949 case DW_TAG_subprogram:
6950 case DW_TAG_inlined_subroutine:
6951 case DW_TAG_lexical_block:
6952 if (sc.function)
6953 {
6954 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6955 if (symbol_context_scope == NULL)
6956 symbol_context_scope = sc.function;
6957 }
6958 break;
6959
6960 default:
6961 symbol_context_scope = sc.comp_unit;
6962 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006963 }
Greg Clayton7f995132011-10-04 22:41:51 +00006964 }
6965
Greg Clayton5cf58b92011-10-05 22:22:08 +00006966 if (symbol_context_scope)
6967 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006968 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6969 name,
6970 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006971 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006972 scope,
6973 symbol_context_scope,
6974 &decl,
6975 location,
6976 is_external,
6977 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006978
6979 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6980 }
6981 else
6982 {
6983 // Not ready to parse this variable yet. It might be a global
6984 // or static variable that is in a function scope and the function
6985 // in the symbol context wasn't filled in yet
6986 return var_sp;
6987 }
Greg Clayton7f995132011-10-04 22:41:51 +00006988 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006989 }
Greg Clayton7f995132011-10-04 22:41:51 +00006990 // Cache var_sp even if NULL (the variable was just a specification or
6991 // was missing vital information to be able to be displayed in the debugger
6992 // (missing location due to optimization, etc)) so we don't re-parse
6993 // this DIE over and over later...
6994 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006995 }
6996 return var_sp;
6997}
6998
Greg Claytonc662ec82011-06-17 22:10:16 +00006999
7000const DWARFDebugInfoEntry *
7001SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7002 dw_offset_t spec_block_die_offset,
7003 DWARFCompileUnit **result_die_cu_handle)
7004{
7005 // Give the concrete function die specified by "func_die_offset", find the
7006 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7007 // to "spec_block_die_offset"
7008 DWARFDebugInfo* info = DebugInfo();
7009
7010 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7011 if (die)
7012 {
7013 assert (*result_die_cu_handle);
7014 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7015 }
7016 return NULL;
7017}
7018
7019
7020const DWARFDebugInfoEntry *
7021SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7022 const DWARFDebugInfoEntry *die,
7023 dw_offset_t spec_block_die_offset,
7024 DWARFCompileUnit **result_die_cu_handle)
7025{
7026 if (die)
7027 {
7028 switch (die->Tag())
7029 {
7030 case DW_TAG_subprogram:
7031 case DW_TAG_inlined_subroutine:
7032 case DW_TAG_lexical_block:
7033 {
7034 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7035 {
7036 *result_die_cu_handle = dwarf_cu;
7037 return die;
7038 }
7039
7040 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7041 {
7042 *result_die_cu_handle = dwarf_cu;
7043 return die;
7044 }
7045 }
7046 break;
7047 }
7048
7049 // Give the concrete function die specified by "func_die_offset", find the
7050 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7051 // to "spec_block_die_offset"
7052 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7053 {
7054 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7055 child_die,
7056 spec_block_die_offset,
7057 result_die_cu_handle);
7058 if (result_die)
7059 return result_die;
7060 }
7061 }
7062
7063 *result_die_cu_handle = NULL;
7064 return NULL;
7065}
7066
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007067size_t
7068SymbolFileDWARF::ParseVariables
7069(
7070 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00007071 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00007072 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007073 const DWARFDebugInfoEntry *orig_die,
7074 bool parse_siblings,
7075 bool parse_children,
7076 VariableList* cc_variable_list
7077)
7078{
7079 if (orig_die == NULL)
7080 return 0;
7081
Greg Claytonc662ec82011-06-17 22:10:16 +00007082 VariableListSP variable_list_sp;
7083
7084 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007085 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00007086 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007087 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007088 dw_tag_t tag = die->Tag();
7089
7090 // Check to see if we have already parsed this variable or constant?
7091 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007092 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007093 if (cc_variable_list)
7094 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007095 }
7096 else
7097 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007098 // We haven't already parsed it, lets do that now.
7099 if ((tag == DW_TAG_variable) ||
7100 (tag == DW_TAG_constant) ||
7101 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007102 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007103 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00007104 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007105 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7106 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7107 switch (parent_tag)
7108 {
7109 case DW_TAG_compile_unit:
7110 if (sc.comp_unit != NULL)
7111 {
7112 variable_list_sp = sc.comp_unit->GetVariableList(false);
7113 if (variable_list_sp.get() == NULL)
7114 {
7115 variable_list_sp.reset(new VariableList());
7116 sc.comp_unit->SetVariableList(variable_list_sp);
7117 }
7118 }
7119 else
7120 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00007121 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
7122 MakeUserID(sc_parent_die->GetOffset()),
7123 DW_TAG_value_to_name (parent_tag),
7124 MakeUserID(orig_die->GetOffset()),
7125 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007126 }
7127 break;
7128
7129 case DW_TAG_subprogram:
7130 case DW_TAG_inlined_subroutine:
7131 case DW_TAG_lexical_block:
7132 if (sc.function != NULL)
7133 {
7134 // Check to see if we already have parsed the variables for the given scope
7135
Greg Clayton81c22f62011-10-19 18:09:39 +00007136 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007137 if (block == NULL)
7138 {
7139 // This must be a specification or abstract origin with
7140 // a concrete block couterpart in the current function. We need
7141 // to find the concrete block so we can correctly add the
7142 // variable to it
7143 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7144 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7145 sc_parent_die->GetOffset(),
7146 &concrete_block_die_cu);
7147 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00007148 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007149 }
7150
7151 if (block != NULL)
7152 {
7153 const bool can_create = false;
7154 variable_list_sp = block->GetBlockVariableList (can_create);
7155 if (variable_list_sp.get() == NULL)
7156 {
7157 variable_list_sp.reset(new VariableList());
7158 block->SetVariableList(variable_list_sp);
7159 }
7160 }
7161 }
7162 break;
7163
7164 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00007165 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
7166 MakeUserID(orig_die->GetOffset()),
7167 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00007168 break;
7169 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00007170 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007171
7172 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007173 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00007174 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7175 if (var_sp)
7176 {
Greg Claytonc662ec82011-06-17 22:10:16 +00007177 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00007178 if (cc_variable_list)
7179 cc_variable_list->AddVariableIfUnique (var_sp);
7180 ++vars_added;
7181 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007182 }
7183 }
7184 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007185
7186 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7187
7188 if (!skip_children && parse_children && die->HasChildren())
7189 {
7190 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7191 }
7192
7193 if (parse_siblings)
7194 die = die->GetSibling();
7195 else
7196 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007197 }
Greg Claytonc662ec82011-06-17 22:10:16 +00007198 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00007199}
7200
7201//------------------------------------------------------------------
7202// PluginInterface protocol
7203//------------------------------------------------------------------
7204const char *
7205SymbolFileDWARF::GetPluginName()
7206{
7207 return "SymbolFileDWARF";
7208}
7209
7210const char *
7211SymbolFileDWARF::GetShortPluginName()
7212{
7213 return GetPluginNameStatic();
7214}
7215
7216uint32_t
7217SymbolFileDWARF::GetPluginVersion()
7218{
7219 return 1;
7220}
7221
7222void
Greg Clayton6beaaa62011-01-17 03:46:26 +00007223SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7224{
7225 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7226 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7227 if (clang_type)
7228 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7229}
7230
7231void
7232SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7233{
7234 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7235 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7236 if (clang_type)
7237 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7238}
7239
Greg Claytona2721472011-06-25 00:44:06 +00007240void
Sean Callanancc427fa2011-07-30 02:42:06 +00007241SymbolFileDWARF::DumpIndexes ()
7242{
7243 StreamFile s(stdout, false);
7244
7245 s.Printf ("DWARF index for (%s) '%s/%s':",
7246 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7247 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7248 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7249 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7250 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7251 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7252 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7253 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7254 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7255 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7256 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7257}
7258
7259void
7260SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7261 const char *name,
7262 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007263{
Sean Callanancc427fa2011-07-30 02:42:06 +00007264 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007265
7266 if (iter == m_decl_ctx_to_die.end())
7267 return;
7268
Greg Claytoncb5860a2011-10-13 23:49:28 +00007269 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007270 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007271 const DWARFDebugInfoEntry *context_die = *pos;
7272
7273 if (!results)
7274 return;
7275
7276 DWARFDebugInfo* info = DebugInfo();
7277
7278 DIEArray die_offsets;
7279
7280 DWARFCompileUnit* dwarf_cu = NULL;
7281 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007282
7283 if (m_using_apple_tables)
7284 {
7285 if (m_apple_types_ap.get())
7286 m_apple_types_ap->FindByName (name, die_offsets);
7287 }
7288 else
7289 {
7290 if (!m_indexed)
7291 Index ();
7292
7293 m_type_index.Find (ConstString(name), die_offsets);
7294 }
7295
Greg Clayton220a0072011-12-09 08:48:30 +00007296 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007297
7298 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007299 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007300 for (size_t i = 0; i < num_matches; ++i)
7301 {
7302 const dw_offset_t die_offset = die_offsets[i];
7303 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007304
Greg Claytoncb5860a2011-10-13 23:49:28 +00007305 if (die->GetParent() != context_die)
7306 continue;
7307
7308 Type *matching_type = ResolveType (dwarf_cu, die);
7309
Greg Clayton42ce2f32011-12-12 21:50:19 +00007310 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007311 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7312
7313 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7314 {
7315 clang::TagDecl *tag_decl = tag_type->getDecl();
7316 results->push_back(tag_decl);
7317 }
7318 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7319 {
7320 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7321 results->push_back(typedef_decl);
7322 }
Greg Claytona2721472011-06-25 00:44:06 +00007323 }
7324 }
7325 }
7326}
7327
7328void
7329SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007330 const clang::DeclContext *decl_context,
7331 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007332 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7333{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007334
7335 switch (decl_context->getDeclKind())
7336 {
7337 case clang::Decl::Namespace:
7338 case clang::Decl::TranslationUnit:
7339 {
7340 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7341 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7342 }
7343 break;
7344 default:
7345 break;
7346 }
Greg Claytona2721472011-06-25 00:44:06 +00007347}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007348
7349bool
7350SymbolFileDWARF::LayoutRecordType (void *baton,
7351 const clang::RecordDecl *record_decl,
7352 uint64_t &size,
7353 uint64_t &alignment,
7354 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7355 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7356 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7357{
7358 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7359 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7360}
7361
7362
7363bool
7364SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7365 uint64_t &bit_size,
7366 uint64_t &alignment,
7367 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7368 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7369 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7370{
7371 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7372 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7373 bool success = false;
7374 base_offsets.clear();
7375 vbase_offsets.clear();
7376 if (pos != m_record_decl_to_layout_map.end())
7377 {
7378 bit_size = pos->second.bit_size;
7379 alignment = pos->second.alignment;
7380 field_offsets.swap(pos->second.field_offsets);
Greg Clayton2508b9b2012-11-01 23:20:02 +00007381 base_offsets.swap (pos->second.base_offsets);
7382 vbase_offsets.swap (pos->second.vbase_offsets);
Greg Claytoncaab74e2012-01-28 00:48:57 +00007383 m_record_decl_to_layout_map.erase(pos);
7384 success = true;
7385 }
7386 else
7387 {
7388 bit_size = 0;
7389 alignment = 0;
7390 field_offsets.clear();
7391 }
7392
7393 if (log)
7394 GetObjectFile()->GetModule()->LogMessage (log.get(),
7395 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
7396 record_decl,
7397 bit_size,
7398 alignment,
7399 (uint32_t)field_offsets.size(),
7400 (uint32_t)base_offsets.size(),
7401 (uint32_t)vbase_offsets.size(),
7402 success);
7403 return success;
7404}
7405
7406
Greg Clayton1f746072012-08-29 21:13:06 +00007407SymbolFileDWARFDebugMap *
7408SymbolFileDWARF::GetDebugMapSymfile ()
7409{
7410 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
7411 {
7412 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
7413 if (module_sp)
7414 {
7415 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
7416 if (sym_vendor)
7417 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
7418 }
7419 }
7420 return m_debug_map_symfile;
7421}
7422
Greg Claytoncaab74e2012-01-28 00:48:57 +00007423