blob: 371343c7f4bc8f51fdababd07d4b21e868f33c7e [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();
129 log_strm.Printf("DIEStack[%zu]:\n", n);
130 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);
136 log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n",
137 i,
138 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{
232 if (m_debug_map_symfile)
233 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 Clayton450e3f32010-10-12 02:24:53 +0000266 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000267 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000269 m_data_debug_abbrev (),
270 m_data_debug_aranges (),
271 m_data_debug_frame (),
272 m_data_debug_info (),
273 m_data_debug_line (),
274 m_data_debug_loc (),
275 m_data_debug_ranges (),
276 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000277 m_data_apple_names (),
278 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000279 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 m_info(),
282 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000283 m_apple_names_ap (),
284 m_apple_types_ap (),
285 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000286 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000287 m_function_basename_index(),
288 m_function_fullname_index(),
289 m_function_method_index(),
290 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000291 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000292 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000293 m_type_index(),
294 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000295 m_indexed (false),
296 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000297 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000298 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000299 m_ranges(),
300 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301{
302}
303
304SymbolFileDWARF::~SymbolFileDWARF()
305{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000306 if (m_is_external_ast_source)
Greg Claytone72dfb32012-02-24 01:59:29 +0000307 {
308 ModuleSP module_sp (m_obj_file->GetModule());
309 if (module_sp)
310 module_sp->GetClangASTContext().RemoveExternalSource ();
311 }
Greg Clayton6beaaa62011-01-17 03:46:26 +0000312}
313
314static const ConstString &
315GetDWARFMachOSegmentName ()
316{
317 static ConstString g_dwarf_section_name ("__DWARF");
318 return g_dwarf_section_name;
319}
320
Greg Claytone576ab22011-02-15 00:19:15 +0000321UniqueDWARFASTTypeMap &
322SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
323{
324 if (m_debug_map_symfile)
325 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
326 return m_unique_ast_type_map;
327}
328
Greg Clayton6beaaa62011-01-17 03:46:26 +0000329ClangASTContext &
330SymbolFileDWARF::GetClangASTContext ()
331{
332 if (m_debug_map_symfile)
333 return m_debug_map_symfile->GetClangASTContext ();
334
335 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
336 if (!m_is_external_ast_source)
337 {
338 m_is_external_ast_source = true;
339 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
340 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
341 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000342 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000343 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000344 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000345 ast.SetExternalSource (ast_source_ap);
346 }
347 return ast;
348}
349
350void
351SymbolFileDWARF::InitializeObject()
352{
353 // Install our external AST source callbacks so we can complete Clang types.
Greg Claytone72dfb32012-02-24 01:59:29 +0000354 ModuleSP module_sp (m_obj_file->GetModule());
355 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000356 {
357 const SectionList *section_list = m_obj_file->GetSectionList();
358
359 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
360
361 // Memory map the DWARF mach-o segment so we have everything mmap'ed
362 // to keep our heap memory usage down.
363 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000364 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000365 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000366 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000367 if (m_data_apple_names.GetByteSize() > 0)
368 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000369 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
370 if (m_apple_names_ap->IsValid())
371 m_using_apple_tables = true;
372 else
Greg Clayton7f995132011-10-04 22:41:51 +0000373 m_apple_names_ap.reset();
374 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000375 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000376 if (m_data_apple_types.GetByteSize() > 0)
377 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000378 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
379 if (m_apple_types_ap->IsValid())
380 m_using_apple_tables = true;
381 else
Greg Clayton7f995132011-10-04 22:41:51 +0000382 m_apple_types_ap.reset();
383 }
384
385 get_apple_namespaces_data();
386 if (m_data_apple_namespaces.GetByteSize() > 0)
387 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000388 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
389 if (m_apple_namespaces_ap->IsValid())
390 m_using_apple_tables = true;
391 else
Greg Clayton7f995132011-10-04 22:41:51 +0000392 m_apple_namespaces_ap.reset();
393 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000394
Greg Clayton5009f9d2011-10-27 17:55:14 +0000395 get_apple_objc_data();
396 if (m_data_apple_objc.GetByteSize() > 0)
397 {
398 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
399 if (m_apple_objc_ap->IsValid())
400 m_using_apple_tables = true;
401 else
402 m_apple_objc_ap.reset();
403 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404}
405
406bool
407SymbolFileDWARF::SupportedVersion(uint16_t version)
408{
409 return version == 2 || version == 3;
410}
411
412uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000413SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414{
415 uint32_t abilities = 0;
416 if (m_obj_file != NULL)
417 {
418 const Section* section = NULL;
419 const SectionList *section_list = m_obj_file->GetSectionList();
420 if (section_list == NULL)
421 return 0;
422
423 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 uint64_t debug_info_file_size = 0;
425 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426
Greg Clayton6beaaa62011-01-17 03:46:26 +0000427 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428
429 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000430 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431
Greg Clayton4ceb9982010-07-21 22:54:26 +0000432 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 if (section != NULL)
434 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000435 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436
Greg Clayton4ceb9982010-07-21 22:54:26 +0000437 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000439 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 else
441 m_flags.Set (flagsGotDebugAbbrevData);
442
Greg Clayton4ceb9982010-07-21 22:54:26 +0000443 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000444 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 m_flags.Set (flagsGotDebugArangesData);
446
Greg Clayton4ceb9982010-07-21 22:54:26 +0000447 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000448 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 m_flags.Set (flagsGotDebugFrameData);
450
Greg Clayton4ceb9982010-07-21 22:54:26 +0000451 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000453 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 else
455 m_flags.Set (flagsGotDebugLineData);
456
Greg Clayton4ceb9982010-07-21 22:54:26 +0000457 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000458 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 m_flags.Set (flagsGotDebugLocData);
460
Greg Clayton4ceb9982010-07-21 22:54:26 +0000461 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000462 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 m_flags.Set (flagsGotDebugMacInfoData);
464
Greg Clayton4ceb9982010-07-21 22:54:26 +0000465 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000466 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 m_flags.Set (flagsGotDebugPubNamesData);
468
Greg Clayton4ceb9982010-07-21 22:54:26 +0000469 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000470 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 m_flags.Set (flagsGotDebugPubTypesData);
472
Greg Clayton4ceb9982010-07-21 22:54:26 +0000473 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000474 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 m_flags.Set (flagsGotDebugRangesData);
476
Greg Clayton4ceb9982010-07-21 22:54:26 +0000477 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000478 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 m_flags.Set (flagsGotDebugStrData);
480 }
Greg Clayton6c596612012-05-18 21:47:20 +0000481 else
482 {
483 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
484 if (symfile_dir_cstr)
485 {
486 if (strcasestr(symfile_dir_cstr, ".dsym"))
487 {
488 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
489 {
490 // We have a dSYM file that didn't have a any debug info.
491 // If the string table has a size of 1, then it was made from
492 // an executable with no debug info, or from an executable that
493 // was stripped.
494 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
495 if (section && section->GetFileSize() == 1)
496 {
497 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
498 }
499 }
500 }
501 }
502 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503
504 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
505 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
506
507 if (debug_line_file_size > 0)
508 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 }
510 return abilities;
511}
512
513const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000514SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515{
516 if (m_flags.IsClear (got_flag))
517 {
518 m_flags.Set (got_flag);
519 const SectionList *section_list = m_obj_file->GetSectionList();
520 if (section_list)
521 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000522 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
523 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 {
525 // See if we memory mapped the DWARF segment?
526 if (m_dwarf_data.GetByteSize())
527 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000528 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 }
530 else
531 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000532 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 data.Clear();
534 }
535 }
536 }
537 }
538 return data;
539}
540
541const DataExtractor&
542SymbolFileDWARF::get_debug_abbrev_data()
543{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000544 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545}
546
547const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000548SymbolFileDWARF::get_debug_aranges_data()
549{
550 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
551}
552
553const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554SymbolFileDWARF::get_debug_frame_data()
555{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000556 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557}
558
559const DataExtractor&
560SymbolFileDWARF::get_debug_info_data()
561{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000562 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563}
564
565const DataExtractor&
566SymbolFileDWARF::get_debug_line_data()
567{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000568 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569}
570
571const DataExtractor&
572SymbolFileDWARF::get_debug_loc_data()
573{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000574 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575}
576
577const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578SymbolFileDWARF::get_debug_ranges_data()
579{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000580 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581}
582
583const DataExtractor&
584SymbolFileDWARF::get_debug_str_data()
585{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000586 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588
Greg Claytonf9eec202011-09-01 23:16:13 +0000589const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000590SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000591{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000592 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000593}
594
595const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000596SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000597{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000598 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000599}
600
Greg Clayton7f995132011-10-04 22:41:51 +0000601const DataExtractor&
602SymbolFileDWARF::get_apple_namespaces_data()
603{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000604 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
605}
606
607const DataExtractor&
608SymbolFileDWARF::get_apple_objc_data()
609{
610 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000611}
612
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613
614DWARFDebugAbbrev*
615SymbolFileDWARF::DebugAbbrev()
616{
617 if (m_abbr.get() == NULL)
618 {
619 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
620 if (debug_abbrev_data.GetByteSize() > 0)
621 {
622 m_abbr.reset(new DWARFDebugAbbrev());
623 if (m_abbr.get())
624 m_abbr->Parse(debug_abbrev_data);
625 }
626 }
627 return m_abbr.get();
628}
629
630const DWARFDebugAbbrev*
631SymbolFileDWARF::DebugAbbrev() const
632{
633 return m_abbr.get();
634}
635
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636
637DWARFDebugInfo*
638SymbolFileDWARF::DebugInfo()
639{
640 if (m_info.get() == NULL)
641 {
642 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
643 if (get_debug_info_data().GetByteSize() > 0)
644 {
645 m_info.reset(new DWARFDebugInfo());
646 if (m_info.get())
647 {
648 m_info->SetDwarfData(this);
649 }
650 }
651 }
652 return m_info.get();
653}
654
655const DWARFDebugInfo*
656SymbolFileDWARF::DebugInfo() const
657{
658 return m_info.get();
659}
660
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661DWARFCompileUnit*
662SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
663{
664 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000665 if (info && UserIDMatches(cu_uid))
666 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 return NULL;
668}
669
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670
671DWARFDebugRanges*
672SymbolFileDWARF::DebugRanges()
673{
674 if (m_ranges.get() == NULL)
675 {
676 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
677 if (get_debug_ranges_data().GetByteSize() > 0)
678 {
679 m_ranges.reset(new DWARFDebugRanges());
680 if (m_ranges.get())
681 m_ranges->Extract(this);
682 }
683 }
684 return m_ranges.get();
685}
686
687const DWARFDebugRanges*
688SymbolFileDWARF::DebugRanges() const
689{
690 return m_ranges.get();
691}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692
Greg Clayton53eb1c22012-04-02 22:59:12 +0000693lldb::CompUnitSP
694SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000696 CompUnitSP cu_sp;
697 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000699 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
700 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000702 // We already parsed this compile unit, had out a shared pointer to it
703 cu_sp = comp_unit->shared_from_this();
704 }
705 else
706 {
707 ModuleSP module_sp (m_obj_file->GetModule());
708 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000710 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
711 if (cu_die)
712 {
713 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
714 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
715 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
716 if (cu_die_name)
717 {
718 std::string ramapped_file;
719 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000720
Greg Clayton53eb1c22012-04-02 22:59:12 +0000721 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
722 {
723 // If we have a full path to the compile unit, we don't need to resolve
724 // the file. This can be expensive e.g. when the source files are NFS mounted.
725 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
726 cu_file_spec.SetFile (ramapped_file.c_str(), false);
727 else
728 cu_file_spec.SetFile (cu_die_name, false);
729 }
730 else
731 {
732 std::string fullpath(cu_comp_dir);
733 if (*fullpath.rbegin() != '/')
734 fullpath += '/';
735 fullpath += cu_die_name;
736 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
737 cu_file_spec.SetFile (ramapped_file.c_str(), false);
738 else
739 cu_file_spec.SetFile (fullpath.c_str(), false);
740 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741
Greg Clayton53eb1c22012-04-02 22:59:12 +0000742 cu_sp.reset(new CompileUnit (module_sp,
743 dwarf_cu,
744 cu_file_spec,
745 MakeUserID(dwarf_cu->GetOffset()),
746 cu_language));
747 if (cu_sp)
748 {
749 dwarf_cu->SetUserData(cu_sp.get());
750
751 if (m_debug_map_symfile)
752 {
753 // Let the symbol file register the compile unit with
754 // the symbol vendor using its compile unit index
755 // when we are doing DWARF in .o files + debug map
756 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
757 }
758 else
759 {
760 // Figure out the compile unit index if we weren't given one
761 if (cu_idx == UINT32_MAX)
762 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
763
764 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
765 }
766 }
767 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768 }
769 }
770 }
771 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000772 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773}
774
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775uint32_t
776SymbolFileDWARF::GetNumCompileUnits()
777{
778 DWARFDebugInfo* info = DebugInfo();
779 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 return 0;
782}
783
784CompUnitSP
785SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
786{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000787 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788 DWARFDebugInfo* info = DebugInfo();
789 if (info)
790 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000791 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
792 if (dwarf_cu)
793 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000795 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796}
797
798static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000799AddRangesToBlock (Block& block,
800 DWARFDebugRanges::RangeList& ranges,
801 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000803 const size_t num_ranges = ranges.GetSize();
804 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000806 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
807 const addr_t range_base = range.GetRangeBase();
808 assert (range_base >= block_base_addr);
809 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000811 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814
815Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000816SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817{
818 DWARFDebugRanges::RangeList func_ranges;
819 const char *name = NULL;
820 const char *mangled = NULL;
821 int decl_file = 0;
822 int decl_line = 0;
823 int decl_column = 0;
824 int call_file = 0;
825 int call_line = 0;
826 int call_column = 0;
827 DWARFExpression frame_base;
828
Greg Claytonc93237c2010-10-01 20:48:32 +0000829 assert (die->Tag() == DW_TAG_subprogram);
830
831 if (die->Tag() != DW_TAG_subprogram)
832 return NULL;
833
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000834 if (die->GetDIENamesAndRanges (this,
835 dwarf_cu,
836 name,
837 mangled,
838 func_ranges,
839 decl_file,
840 decl_line,
841 decl_column,
842 call_file,
843 call_line,
844 call_column,
845 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 {
847 // Union of all ranges in the function DIE (if the function is discontiguous)
848 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000849 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
850 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
852 {
853 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
854 if (func_range.GetBaseAddress().IsValid())
855 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
856 }
857
858 if (func_range.GetBaseAddress().IsValid())
859 {
860 Mangled func_name;
861 if (mangled)
862 func_name.SetValue(mangled, true);
863 else if (name)
864 func_name.SetValue(name, false);
865
866 FunctionSP func_sp;
867 std::auto_ptr<Declaration> decl_ap;
868 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000869 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
870 decl_line,
871 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000873 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000874 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000875
876 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
877
878 func_range.GetBaseAddress().ResolveLinkedAddress();
879
Greg Clayton81c22f62011-10-19 18:09:39 +0000880 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000881 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000882 func_user_id, // UserID is the DIE offset
883 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884 func_name,
885 func_type,
886 func_range)); // first address range
887
888 if (func_sp.get() != NULL)
889 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000890 if (frame_base.IsValid())
891 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000892 sc.comp_unit->AddFunction(func_sp);
893 return func_sp.get();
894 }
895 }
896 }
897 return NULL;
898}
899
900size_t
901SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
902{
903 assert (sc.comp_unit);
904 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000905 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000906 if (dwarf_cu)
907 {
908 DWARFDIECollection function_dies;
909 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
910 size_t func_idx;
911 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
912 {
913 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000914 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000915 {
916 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
917 ++functions_added;
918 }
919 }
920 //FixupTypes();
921 }
922 return functions_added;
923}
924
925bool
926SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
927{
928 assert (sc.comp_unit);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000929 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
930 assert (dwarf_cu);
931 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932
933 if (cu_die)
934 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000935 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
936 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 +0000937
938 // All file indexes in DWARF are one based and a file of index zero is
939 // supposed to be the compile unit itself.
940 support_files.Append (*sc.comp_unit);
941
Greg Claytond804d282012-03-15 21:01:31 +0000942 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943 }
944 return false;
945}
946
947struct ParseDWARFLineTableCallbackInfo
948{
949 LineTable* line_table;
950 const SectionList *section_list;
951 lldb::addr_t prev_sect_file_base_addr;
952 lldb::addr_t curr_sect_file_base_addr;
953 bool is_oso_for_debug_map;
954 bool prev_in_final_executable;
955 DWARFDebugLine::Row prev_row;
956 SectionSP prev_section_sp;
957 SectionSP curr_section_sp;
958};
959
960//----------------------------------------------------------------------
961// ParseStatementTableCallback
962//----------------------------------------------------------------------
963static void
964ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
965{
966 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
967 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
968 {
969 // Just started parsing the line table
970 }
971 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
972 {
973 // Done parsing line table, nothing to do for the cleanup
974 }
975 else
976 {
977 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
978 // We have a new row, lets append it
979
980 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
981 {
982 info->prev_section_sp = info->curr_section_sp;
983 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
984 // If this is an end sequence entry, then we subtract one from the
985 // address to make sure we get an address that is not the end of
986 // a section.
987 if (state.end_sequence && state.address != 0)
988 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
989 else
990 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
991
992 if (info->curr_section_sp.get())
993 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
994 else
995 info->curr_sect_file_base_addr = 0;
996 }
997 if (info->curr_section_sp.get())
998 {
999 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1000 // Check for the fancy section magic to determine if we
1001
1002 if (info->is_oso_for_debug_map)
1003 {
1004 // When this is a debug map object file that contains DWARF
1005 // (referenced from an N_OSO debug map nlist entry) we will have
1006 // a file address in the file range for our section from the
1007 // original .o file, and a load address in the executable that
1008 // contains the debug map.
1009 //
1010 // If the sections for the file range and load range are
1011 // different, we have a remapped section for the function and
1012 // this address is resolved. If they are the same, then the
1013 // function for this address didn't make it into the final
1014 // executable.
1015 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1016
1017 // If we are doing DWARF with debug map, then we need to carefully
1018 // add each line table entry as there may be gaps as functions
1019 // get moved around or removed.
1020 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1021 {
1022 if (info->prev_in_final_executable)
1023 {
1024 bool terminate_previous_entry = false;
1025 if (!curr_in_final_executable)
1026 {
1027 // Check for the case where the previous line entry
1028 // in a function made it into the final executable,
1029 // yet the current line entry falls in a function
1030 // that didn't. The line table used to be contiguous
1031 // through this address range but now it isn't. We
1032 // need to terminate the previous line entry so
1033 // that we can reconstruct the line range correctly
1034 // for it and to keep the line table correct.
1035 terminate_previous_entry = true;
1036 }
1037 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1038 {
1039 // Check for cases where the line entries used to be
1040 // contiguous address ranges, but now they aren't.
1041 // This can happen when order files specify the
1042 // ordering of the functions.
1043 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1044 Section *curr_sect = info->curr_section_sp.get();
1045 Section *prev_sect = info->prev_section_sp.get();
1046 assert (curr_sect->GetLinkedSection());
1047 assert (prev_sect->GetLinkedSection());
1048 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1049 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1050 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1051 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1052 if (object_file_addr_delta != linked_file_addr_delta)
1053 terminate_previous_entry = true;
1054 }
1055
1056 if (terminate_previous_entry)
1057 {
1058 line_table->InsertLineEntry (info->prev_section_sp,
1059 state.address - info->prev_sect_file_base_addr,
1060 info->prev_row.line,
1061 info->prev_row.column,
1062 info->prev_row.file,
1063 false, // is_stmt
1064 false, // basic_block
1065 false, // state.prologue_end
1066 false, // state.epilogue_begin
1067 true); // end_sequence);
1068 }
1069 }
1070 }
1071
1072 if (curr_in_final_executable)
1073 {
1074 line_table->InsertLineEntry (info->curr_section_sp,
1075 curr_line_section_offset,
1076 state.line,
1077 state.column,
1078 state.file,
1079 state.is_stmt,
1080 state.basic_block,
1081 state.prologue_end,
1082 state.epilogue_begin,
1083 state.end_sequence);
1084 info->prev_section_sp = info->curr_section_sp;
1085 }
1086 else
1087 {
1088 // If the current address didn't make it into the final
1089 // executable, the current section will be the __text
1090 // segment in the .o file, so we need to clear this so
1091 // we can catch the next function that did make it into
1092 // the final executable.
1093 info->prev_section_sp.reset();
1094 info->curr_section_sp.reset();
1095 }
1096
1097 info->prev_in_final_executable = curr_in_final_executable;
1098 }
1099 else
1100 {
1101 // We are not in an object file that contains DWARF for an
1102 // N_OSO, this is just a normal DWARF file. The DWARF spec
1103 // guarantees that the addresses will be in increasing order
1104 // so, since we store line tables in file address order, we
1105 // can always just append the line entry without needing to
1106 // search for the correct insertion point (we don't need to
1107 // use LineEntry::InsertLineEntry()).
1108 line_table->AppendLineEntry (info->curr_section_sp,
1109 curr_line_section_offset,
1110 state.line,
1111 state.column,
1112 state.file,
1113 state.is_stmt,
1114 state.basic_block,
1115 state.prologue_end,
1116 state.epilogue_begin,
1117 state.end_sequence);
1118 }
1119 }
1120
1121 info->prev_row = state;
1122 }
1123}
1124
1125bool
1126SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1127{
1128 assert (sc.comp_unit);
1129 if (sc.comp_unit->GetLineTable() != NULL)
1130 return true;
1131
1132 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1133 if (dwarf_cu)
1134 {
1135 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001136 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001137 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001138 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1139 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001141 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1142 if (line_table_ap.get())
1143 {
1144 ParseDWARFLineTableCallbackInfo info = {
1145 line_table_ap.get(),
1146 m_obj_file->GetSectionList(),
1147 0,
1148 0,
1149 m_debug_map_symfile != NULL,
1150 false,
1151 DWARFDebugLine::Row(),
1152 SectionSP(),
1153 SectionSP()
1154 };
1155 uint32_t offset = cu_line_offset;
1156 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1157 sc.comp_unit->SetLineTable(line_table_ap.release());
1158 return true;
1159 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160 }
1161 }
1162 }
1163 return false;
1164}
1165
1166size_t
1167SymbolFileDWARF::ParseFunctionBlocks
1168(
1169 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001170 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001171 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001172 const DWARFDebugInfoEntry *die,
1173 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001174 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175)
1176{
1177 size_t blocks_added = 0;
1178 while (die != NULL)
1179 {
1180 dw_tag_t tag = die->Tag();
1181
1182 switch (tag)
1183 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001185 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 case DW_TAG_lexical_block:
1187 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001188 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001189 if (tag == DW_TAG_subprogram)
1190 {
1191 // Skip any DW_TAG_subprogram DIEs that are inside
1192 // of a normal or inlined functions. These will be
1193 // parsed on their own as separate entities.
1194
1195 if (depth > 0)
1196 break;
1197
1198 block = parent_block;
1199 }
1200 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001201 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001202 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001203 parent_block->AddChild(block_sp);
1204 block = block_sp.get();
1205 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001206 DWARFDebugRanges::RangeList ranges;
1207 const char *name = NULL;
1208 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 int decl_file = 0;
1211 int decl_line = 0;
1212 int decl_column = 0;
1213 int call_file = 0;
1214 int call_line = 0;
1215 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001216 if (die->GetDIENamesAndRanges (this,
1217 dwarf_cu,
1218 name,
1219 mangled_name,
1220 ranges,
1221 decl_file, decl_line, decl_column,
1222 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223 {
1224 if (tag == DW_TAG_subprogram)
1225 {
1226 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001227 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001229 else if (tag == DW_TAG_inlined_subroutine)
1230 {
1231 // We get called here for inlined subroutines in two ways.
1232 // The first time is when we are making the Function object
1233 // for this inlined concrete instance. Since we're creating a top level block at
1234 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1235 // adjust the containing address.
1236 // The second time is when we are parsing the blocks inside the function that contains
1237 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1238 // function the offset will be for that function.
1239 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1240 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001241 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001242 }
1243 }
1244
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001245 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246
1247 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1248 {
1249 std::auto_ptr<Declaration> decl_ap;
1250 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001251 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1252 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253
1254 std::auto_ptr<Declaration> call_ap;
1255 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001256 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1257 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001259 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 }
1261
1262 ++blocks_added;
1263
Greg Claytondd7feaf2011-08-12 17:54:33 +00001264 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001266 blocks_added += ParseFunctionBlocks (sc,
1267 block,
1268 dwarf_cu,
1269 die->GetFirstChild(),
1270 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001271 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272 }
1273 }
1274 }
1275 break;
1276 default:
1277 break;
1278 }
1279
Greg Claytondd7feaf2011-08-12 17:54:33 +00001280 // Only parse siblings of the block if we are not at depth zero. A depth
1281 // of zero indicates we are currently parsing the top level
1282 // DW_TAG_subprogram DIE
1283
1284 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001286 else
1287 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 }
1289 return blocks_added;
1290}
1291
Greg Claytonf0705c82011-10-22 03:33:13 +00001292bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001293SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1294 const DWARFDebugInfoEntry *die,
1295 ClangASTContext::TemplateParameterInfos &template_param_infos)
1296{
1297 const dw_tag_t tag = die->Tag();
1298
1299 switch (tag)
1300 {
1301 case DW_TAG_template_type_parameter:
1302 case DW_TAG_template_value_parameter:
1303 {
1304 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1305
1306 DWARFDebugInfoEntry::Attributes attributes;
1307 const size_t num_attributes = die->GetAttributes (this,
1308 dwarf_cu,
1309 fixed_form_sizes,
1310 attributes);
1311 const char *name = NULL;
1312 Type *lldb_type = NULL;
1313 clang_type_t clang_type = NULL;
1314 uint64_t uval64 = 0;
1315 bool uval64_valid = false;
1316 if (num_attributes > 0)
1317 {
1318 DWARFFormValue form_value;
1319 for (size_t i=0; i<num_attributes; ++i)
1320 {
1321 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1322
1323 switch (attr)
1324 {
1325 case DW_AT_name:
1326 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1327 name = form_value.AsCString(&get_debug_str_data());
1328 break;
1329
1330 case DW_AT_type:
1331 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1332 {
1333 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1334 lldb_type = ResolveTypeUID(type_die_offset);
1335 if (lldb_type)
1336 clang_type = lldb_type->GetClangForwardType();
1337 }
1338 break;
1339
1340 case DW_AT_const_value:
1341 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1342 {
1343 uval64_valid = true;
1344 uval64 = form_value.Unsigned();
1345 }
1346 break;
1347 default:
1348 break;
1349 }
1350 }
1351
1352 if (name && lldb_type && clang_type)
1353 {
1354 bool is_signed = false;
1355 template_param_infos.names.push_back(name);
1356 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1357 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1358 {
1359 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1360 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1361 }
1362 else
1363 {
1364 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1365 }
1366 }
1367 else
1368 {
1369 return false;
1370 }
1371
1372 }
1373 }
1374 return true;
1375
1376 default:
1377 break;
1378 }
1379 return false;
1380}
1381
1382bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001383SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1384 const DWARFDebugInfoEntry *parent_die,
1385 ClangASTContext::TemplateParameterInfos &template_param_infos)
1386{
1387
1388 if (parent_die == NULL)
Filipe Cabecinhas52008c62012-05-23 16:24:11 +00001389 return false;
Greg Claytonf0705c82011-10-22 03:33:13 +00001390
Greg Claytonf0705c82011-10-22 03:33:13 +00001391 Args template_parameter_names;
1392 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1393 die != NULL;
1394 die = die->GetSibling())
1395 {
1396 const dw_tag_t tag = die->Tag();
1397
1398 switch (tag)
1399 {
1400 case DW_TAG_template_type_parameter:
1401 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001402 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001403 break;
1404
1405 default:
1406 break;
1407 }
1408 }
1409 if (template_param_infos.args.empty())
1410 return false;
1411 return template_param_infos.args.size() == template_param_infos.names.size();
1412}
1413
1414clang::ClassTemplateDecl *
1415SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001416 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001417 const char *parent_name,
1418 int tag_decl_kind,
1419 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1420{
1421 if (template_param_infos.IsValid())
1422 {
1423 std::string template_basename(parent_name);
1424 template_basename.erase (template_basename.find('<'));
1425 ClangASTContext &ast = GetClangASTContext();
1426
1427 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001428 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001429 template_basename.c_str(),
1430 tag_decl_kind,
1431 template_param_infos);
1432 }
1433 return NULL;
1434}
1435
Sean Callanana0b80ab2012-06-04 22:28:05 +00001436class SymbolFileDWARF::DelayedAddObjCClassProperty
1437{
1438public:
1439 DelayedAddObjCClassProperty
1440 (
1441 clang::ASTContext *ast,
1442 lldb::clang_type_t class_opaque_type,
1443 const char *property_name,
1444 lldb::clang_type_t property_opaque_type, // The property type is only required if you don't have an ivar decl
1445 clang::ObjCIvarDecl *ivar_decl,
1446 const char *property_setter_name,
1447 const char *property_getter_name,
1448 uint32_t property_attributes,
1449 uint64_t metadata = 0
1450 ) :
1451 m_ast (ast),
1452 m_class_opaque_type (class_opaque_type),
1453 m_property_name (property_name),
1454 m_property_opaque_type (property_opaque_type),
1455 m_ivar_decl (ivar_decl),
1456 m_property_setter_name (property_setter_name),
1457 m_property_getter_name (property_getter_name),
1458 m_property_attributes (property_attributes),
1459 m_metadata (metadata)
1460 {
1461 }
1462
1463 bool Finalize() const
1464 {
1465 return ClangASTContext::AddObjCClassProperty(m_ast,
1466 m_class_opaque_type,
1467 m_property_name,
1468 m_property_opaque_type,
1469 m_ivar_decl,
1470 m_property_setter_name,
1471 m_property_getter_name,
1472 m_property_attributes,
1473 m_metadata);
1474 }
1475private:
1476 clang::ASTContext *m_ast;
1477 lldb::clang_type_t m_class_opaque_type;
1478 const char *m_property_name;
1479 lldb::clang_type_t m_property_opaque_type;
1480 clang::ObjCIvarDecl *m_ivar_decl;
1481 const char *m_property_setter_name;
1482 const char *m_property_getter_name;
1483 uint32_t m_property_attributes;
1484 uint64_t m_metadata;
1485};
1486
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001487size_t
1488SymbolFileDWARF::ParseChildMembers
1489(
1490 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001491 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001492 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001493 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001494 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001495 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1496 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001497 DWARFDIECollection& member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00001498 DelayedPropertyList& delayed_properties,
Sean Callananc7fbf732010-08-06 00:32:49 +00001499 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001500 bool &is_a_class,
1501 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502)
1503{
1504 if (parent_die == NULL)
1505 return 0;
1506
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001507 size_t count = 0;
1508 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001509 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001510 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001511
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001512 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1513 {
1514 dw_tag_t tag = die->Tag();
1515
1516 switch (tag)
1517 {
1518 case DW_TAG_member:
Bill Wendling9e5bf872012-04-03 08:45:33 +00001519 case DW_TAG_APPLE_Property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520 {
1521 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001522 const size_t num_attributes = die->GetAttributes (this,
1523 dwarf_cu,
1524 fixed_form_sizes,
1525 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526 if (num_attributes > 0)
1527 {
1528 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001529 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001530 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001531 const char *prop_name = NULL;
1532 const char *prop_getter_name = NULL;
1533 const char *prop_setter_name = NULL;
1534 uint32_t prop_attributes = 0;
1535
1536
Greg Clayton24739922010-10-13 03:15:28 +00001537 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001538 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001539 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001540 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 size_t byte_size = 0;
1542 size_t bit_offset = 0;
1543 size_t bit_size = 0;
1544 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001545 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001546 {
1547 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1548 DWARFFormValue form_value;
1549 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1550 {
1551 switch (attr)
1552 {
1553 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1554 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1555 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1556 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1557 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1558 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1559 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1560 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1561 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001562 if (form_value.BlockData())
1563 {
1564 Value initialValue(0);
1565 Value memberOffset(0);
1566 const DataExtractor& debug_info_data = get_debug_info_data();
1567 uint32_t block_length = form_value.Unsigned();
1568 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1569 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1570 NULL, // clang::ASTContext *
1571 NULL, // ClangExpressionVariableList *
1572 NULL, // ClangExpressionDeclMap *
1573 NULL, // RegisterContext *
1574 debug_info_data,
1575 block_offset,
1576 block_length,
1577 eRegisterKindDWARF,
1578 &initialValue,
1579 memberOffset,
1580 NULL))
1581 {
1582 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1583 }
1584 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001585 break;
1586
Greg Clayton8cf05932010-07-22 18:30:50 +00001587 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001588 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001589 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1590 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1591 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1592 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1593
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001594 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001595 case DW_AT_declaration:
1596 case DW_AT_description:
1597 case DW_AT_mutable:
1598 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 case DW_AT_sibling:
1600 break;
1601 }
1602 }
1603 }
Sean Callanana6582262012-04-05 00:12:52 +00001604
1605 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001606 {
Sean Callanana6582262012-04-05 00:12:52 +00001607 ConstString fixed_getter;
1608 ConstString fixed_setter;
1609
1610 // Check if the property getter/setter were provided as full
1611 // names. We want basenames, so we extract them.
1612
1613 if (prop_getter_name && prop_getter_name[0] == '-')
1614 {
1615 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1616 NULL,
1617 &fixed_getter,
1618 NULL,
1619 NULL);
1620 prop_getter_name = fixed_getter.GetCString();
1621 }
1622
1623 if (prop_setter_name && prop_setter_name[0] == '-')
1624 {
1625 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1626 NULL,
1627 &fixed_setter,
1628 NULL,
1629 NULL);
1630 prop_setter_name = fixed_setter.GetCString();
1631 }
1632
1633 // If the names haven't been provided, they need to be
1634 // filled in.
1635
1636 if (!prop_getter_name)
1637 {
1638 prop_getter_name = prop_name;
1639 }
1640 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1641 {
1642 StreamString ss;
1643
1644 ss.Printf("set%c%s:",
1645 toupper(prop_name[0]),
1646 &prop_name[1]);
1647
1648 fixed_setter.SetCString(ss.GetData());
1649 prop_setter_name = fixed_setter.GetCString();
1650 }
Sean Callanan751aac62012-03-29 19:07:06 +00001651 }
1652
1653 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001654 // represents fields that are references with bad byte size
1655 // and bit size/offset information such as:
1656 //
1657 // DW_AT_byte_size( 0x00 )
1658 // DW_AT_bit_size( 0x40 )
1659 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1660 //
1661 // So check the bit offset to make sure it is sane, and if
1662 // the values are not sane, remove them. If we don't do this
1663 // then we will end up with a crash if we try to use this
1664 // type in an expression when clang becomes unhappy with its
1665 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001666
Greg Clayton44953932011-10-25 01:25:35 +00001667 if (bit_offset > 128)
1668 {
1669 bit_size = 0;
1670 bit_offset = 0;
1671 }
1672
1673 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001674 if (class_language == eLanguageTypeObjC ||
1675 class_language == eLanguageTypeObjC_plus_plus)
1676 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001677
1678 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1679 {
1680 // Not all compilers will mark the vtable pointer
1681 // member as artificial (llvm-gcc). We can't have
1682 // the virtual members in our classes otherwise it
1683 // throws off all child offsets since we end up
1684 // having and extra pointer sized member in our
1685 // class layouts.
1686 is_artificial = true;
1687 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688
Greg Clayton24739922010-10-13 03:15:28 +00001689 if (is_artificial == false)
1690 {
1691 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001692 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001693 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001694 {
Sean Callanan751aac62012-03-29 19:07:06 +00001695 if (member_type)
1696 {
1697 if (accessibility == eAccessNone)
1698 accessibility = default_accessibility;
1699 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700
Sean Callanan751aac62012-03-29 19:07:06 +00001701 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1702 name,
1703 member_type->GetClangLayoutType(),
1704 accessibility,
1705 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001706
1707 GetClangASTContext().SetMetadata((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callanan5b26f272012-02-04 08:49:35 +00001708 }
1709 else
1710 {
Sean Callanan751aac62012-03-29 19:07:06 +00001711 if (name)
1712 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1713 MakeUserID(die->GetOffset()),
1714 name,
1715 encoding_uid);
1716 else
1717 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1718 MakeUserID(die->GetOffset()),
1719 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001720 }
Sean Callanan751aac62012-03-29 19:07:06 +00001721
1722 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1723 {
1724 /////////////////////////////////////////////////////////////
1725 // How to locate a field given the DWARF debug information
1726 //
1727 // AT_byte_size indicates the size of the word in which the
1728 // bit offset must be interpreted.
1729 //
1730 // AT_data_member_location indicates the byte offset of the
1731 // word from the base address of the structure.
1732 //
1733 // AT_bit_offset indicates how many bits into the word
1734 // (according to the host endianness) the low-order bit of
1735 // the field starts. AT_bit_offset can be negative.
1736 //
1737 // AT_bit_size indicates the size of the field in bits.
1738 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001739
Sean Callanan751aac62012-03-29 19:07:06 +00001740 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1741
1742 uint64_t total_bit_offset = 0;
1743
1744 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1745
1746 if (object_endian == eByteOrderLittle)
1747 {
1748 total_bit_offset += byte_size * 8;
1749 total_bit_offset -= (bit_offset + bit_size);
1750 }
1751 else
1752 {
1753 total_bit_offset += bit_offset;
1754 }
1755
1756 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1757 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001758 }
Sean Callanan751aac62012-03-29 19:07:06 +00001759
Jim Inghame3ae82a2011-11-12 01:36:43 +00001760 if (prop_name != NULL)
1761 {
Sean Callanan751aac62012-03-29 19:07:06 +00001762 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001763
Sean Callanan751aac62012-03-29 19:07:06 +00001764 if (field_decl)
1765 {
1766 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1767 assert (ivar_decl != NULL);
1768 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001769
Sean Callanana0b80ab2012-06-04 22:28:05 +00001770 delayed_properties.push_back(DelayedAddObjCClassProperty(GetClangASTContext().getASTContext(),
1771 class_clang_type,
1772 prop_name,
1773 member_type->GetClangLayoutType(),
1774 ivar_decl,
1775 prop_setter_name,
1776 prop_getter_name,
1777 prop_attributes,
1778 MakeUserID(die->GetOffset())));
Sean Callanan60217122012-04-13 00:10:03 +00001779
Sean Callananad880762012-04-18 01:06:17 +00001780 if (ivar_decl)
1781 GetClangASTContext().SetMetadata((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001782 }
Greg Clayton24739922010-10-13 03:15:28 +00001783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001784 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001785 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001786 }
1787 break;
1788
1789 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001790 // Let the type parsing code handle this one for us.
1791 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792 break;
1793
1794 case DW_TAG_inheritance:
1795 {
1796 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001797 if (default_accessibility == eAccessNone)
1798 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001799 // TODO: implement DW_TAG_inheritance type parsing
1800 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001801 const size_t num_attributes = die->GetAttributes (this,
1802 dwarf_cu,
1803 fixed_form_sizes,
1804 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001805 if (num_attributes > 0)
1806 {
1807 Declaration decl;
1808 DWARFExpression location;
1809 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001810 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001811 bool is_virtual = false;
1812 bool is_base_of_class = true;
Greg Clayton23f59502012-07-17 03:23:13 +00001813 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814 uint32_t i;
1815 for (i=0; i<num_attributes; ++i)
1816 {
1817 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1818 DWARFFormValue form_value;
1819 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1820 {
1821 switch (attr)
1822 {
1823 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1824 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1825 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1826 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00001827// case DW_AT_data_member_location:
1828// if (form_value.BlockData())
1829// {
1830// Value initialValue(0);
1831// Value memberOffset(0);
1832// const DataExtractor& debug_info_data = get_debug_info_data();
1833// uint32_t block_length = form_value.Unsigned();
1834// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1835// if (DWARFExpression::Evaluate (NULL,
1836// NULL,
1837// NULL,
1838// NULL,
1839// NULL,
1840// debug_info_data,
1841// block_offset,
1842// block_length,
1843// eRegisterKindDWARF,
1844// &initialValue,
1845// memberOffset,
1846// NULL))
1847// {
1848// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1849// }
1850// }
1851// break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852
1853 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001854 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855 break;
1856
1857 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1858 default:
1859 case DW_AT_sibling:
1860 break;
1861 }
1862 }
1863 }
1864
Greg Clayton526e5af2010-11-13 03:52:47 +00001865 Type *base_class_type = ResolveTypeUID(encoding_uid);
1866 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001867
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001868 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1869 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001870 if (class_language == eLanguageTypeObjC)
1871 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001872 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001873 }
1874 else
1875 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001876 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001877 accessibility,
1878 is_virtual,
1879 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001880 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881 }
1882 }
1883 break;
1884
1885 default:
1886 break;
1887 }
1888 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00001889
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890 return count;
1891}
1892
1893
1894clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001895SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001896{
1897 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001898 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 {
1900 DWARFCompileUnitSP cu_sp;
1901 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1902 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001903 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001904 }
1905 return NULL;
1906}
1907
1908clang::DeclContext*
1909SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1910{
Greg Clayton81c22f62011-10-19 18:09:39 +00001911 if (UserIDMatches(type_uid))
1912 return GetClangDeclContextForDIEOffset (sc, type_uid);
1913 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001914}
1915
1916Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001917SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918{
Greg Clayton81c22f62011-10-19 18:09:39 +00001919 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001921 DWARFDebugInfo* debug_info = DebugInfo();
1922 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001923 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001924 DWARFCompileUnitSP cu_sp;
1925 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001926 const bool assert_not_being_parsed = true;
1927 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001928 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 }
1930 return NULL;
1931}
1932
Greg Claytoncab36a32011-12-08 05:16:30 +00001933Type*
1934SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001935{
Greg Claytoncab36a32011-12-08 05:16:30 +00001936 if (die != NULL)
1937 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001938 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1939 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001940 GetObjectFile()->GetModule()->LogMessage (log.get(),
1941 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1942 die->GetOffset(),
1943 DW_TAG_value_to_name(die->Tag()),
1944 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001945
Greg Claytoncab36a32011-12-08 05:16:30 +00001946 // We might be coming in in the middle of a type tree (a class
1947 // withing a class, an enum within a class), so parse any needed
1948 // parent DIEs before we get to this one...
1949 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1950 switch (decl_ctx_die->Tag())
1951 {
1952 case DW_TAG_structure_type:
1953 case DW_TAG_union_type:
1954 case DW_TAG_class_type:
1955 {
1956 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001957 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001958 GetObjectFile()->GetModule()->LogMessage (log.get(),
1959 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1960 die->GetOffset(),
1961 DW_TAG_value_to_name(die->Tag()),
1962 die->GetName(this, cu),
1963 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001964//
1965// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1966// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1967// {
1968// if (log)
1969// GetObjectFile()->GetModule()->LogMessage (log.get(),
1970// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1971// die->GetOffset(),
1972// DW_TAG_value_to_name(die->Tag()),
1973// die->GetName(this, cu),
1974// decl_ctx_die->GetOffset());
1975// // Ask the type to complete itself if it already hasn't since if we
1976// // want a function (method or static) from a class, the class must
1977// // create itself and add it's own methods and class functions.
1978// if (parent_type)
1979// parent_type->GetClangFullType();
1980// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001981 }
1982 break;
1983
1984 default:
1985 break;
1986 }
1987 return ResolveType (cu, die);
1988 }
1989 return NULL;
1990}
1991
Greg Clayton6beaaa62011-01-17 03:46:26 +00001992// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1993// SymbolFileDWARF objects to detect if this DWARF file is the one that
1994// can resolve a clang_type.
1995bool
1996SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1997{
1998 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1999 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
2000 return die != NULL;
2001}
2002
2003
Greg Clayton1be10fc2010-09-29 01:12:09 +00002004lldb::clang_type_t
2005SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
2006{
2007 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002008 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
2009 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002010 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00002011 {
2012 // We have already resolved this type...
2013 return clang_type;
2014 }
2015 // Once we start resolving this type, remove it from the forward declaration
2016 // map in case anyone child members or other types require this type to get resolved.
2017 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2018 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00002019 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00002020
Greg Clayton1be10fc2010-09-29 01:12:09 +00002021
Greg Clayton85ae2e12011-10-18 23:36:41 +00002022 // Disable external storage for this type so we don't get anymore
2023 // clang::ExternalASTSource queries for this type.
2024 ClangASTContext::SetHasExternalStorage (clang_type, false);
2025
Greg Clayton450e3f32010-10-12 02:24:53 +00002026 DWARFDebugInfo* debug_info = DebugInfo();
2027
Greg Clayton53eb1c22012-04-02 22:59:12 +00002028 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002029 Type *type = m_die_to_type.lookup (die);
2030
2031 const dw_tag_t tag = die->Tag();
2032
Greg Claytonbaf95da2012-03-30 23:50:54 +00002033 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00002034 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00002035 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00002036 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
2037 "0x%8.8llx: %s '%s' resolving forward declaration...",
2038 MakeUserID(die->GetOffset()),
2039 DW_TAG_value_to_name(tag),
2040 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00002041
Greg Claytonbaf95da2012-03-30 23:50:54 +00002042 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00002043 assert (clang_type);
2044 DWARFDebugInfoEntry::Attributes attributes;
2045
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002046 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002047
2048 switch (tag)
2049 {
2050 case DW_TAG_structure_type:
2051 case DW_TAG_union_type:
2052 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002053 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002054 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002055
Greg Clayton1be10fc2010-09-29 01:12:09 +00002056 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002057 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002058 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002059
Sean Callanan77a1fd32012-02-27 20:07:01 +00002060 LanguageType class_language = eLanguageTypeUnknown;
2061 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2062 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002063 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002064 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002065 // For objective C we don't start the definition when
2066 // the class is created.
2067 ast.StartTagDeclarationDefinition (clang_type);
2068 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002069
2070 int tag_decl_kind = -1;
2071 AccessType default_accessibility = eAccessNone;
2072 if (tag == DW_TAG_structure_type)
2073 {
2074 tag_decl_kind = clang::TTK_Struct;
2075 default_accessibility = eAccessPublic;
2076 }
2077 else if (tag == DW_TAG_union_type)
2078 {
2079 tag_decl_kind = clang::TTK_Union;
2080 default_accessibility = eAccessPublic;
2081 }
2082 else if (tag == DW_TAG_class_type)
2083 {
2084 tag_decl_kind = clang::TTK_Class;
2085 default_accessibility = eAccessPrivate;
2086 }
2087
Greg Clayton53eb1c22012-04-02 22:59:12 +00002088 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002089 std::vector<clang::CXXBaseSpecifier *> base_classes;
2090 std::vector<int> member_accessibilities;
2091 bool is_a_class = false;
2092 // Parse members and base classes first
2093 DWARFDIECollection member_function_dies;
Sean Callanana0b80ab2012-06-04 22:28:05 +00002094
2095 DelayedPropertyList delayed_properties;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002096
2097 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002098 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002099 die,
2100 clang_type,
2101 class_language,
2102 base_classes,
2103 member_accessibilities,
2104 member_function_dies,
Sean Callanana0b80ab2012-06-04 22:28:05 +00002105 delayed_properties,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002106 default_accessibility,
2107 is_a_class,
2108 layout_info);
2109
2110 // Now parse any methods if there were any...
2111 size_t num_functions = member_function_dies.Size();
2112 if (num_functions > 0)
2113 {
2114 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002115 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002116 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002117 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002118 }
2119
2120 if (class_language == eLanguageTypeObjC)
2121 {
Greg Clayton84db9102012-03-26 23:03:23 +00002122 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002123 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002124 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002125
Sean Callanan77a1fd32012-02-27 20:07:01 +00002126 DIEArray method_die_offsets;
2127 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002128 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002129 if (m_apple_objc_ap.get())
2130 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2131 }
2132 else
2133 {
2134 if (!m_indexed)
2135 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002136
Sean Callanan77a1fd32012-02-27 20:07:01 +00002137 ConstString class_name (class_str.c_str());
2138 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2139 }
2140
2141 if (!method_die_offsets.empty())
2142 {
2143 DWARFDebugInfo* debug_info = DebugInfo();
2144
2145 DWARFCompileUnit* method_cu = NULL;
2146 const size_t num_matches = method_die_offsets.size();
2147 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002148 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002149 const dw_offset_t die_offset = method_die_offsets[i];
2150 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2151
2152 if (method_die)
2153 ResolveType (method_cu, method_die);
2154 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002155 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002156 if (m_using_apple_tables)
2157 {
2158 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2159 die_offset, class_str.c_str());
2160 }
2161 }
2162 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002163 }
Sean Callanana0b80ab2012-06-04 22:28:05 +00002164
2165 for (DelayedPropertyList::const_iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2166 pi != pe;
2167 ++pi)
2168 pi->Finalize();
Greg Clayton450e3f32010-10-12 02:24:53 +00002169 }
2170 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002171
2172 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2173 // need to tell the clang type it is actually a class.
2174 if (class_language != eLanguageTypeObjC)
2175 {
2176 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2177 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2178 }
2179
2180 // Since DW_TAG_structure_type gets used for both classes
2181 // and structures, we may need to set any DW_TAG_member
2182 // fields to have a "private" access if none was specified.
2183 // When we parsed the child members we tracked that actual
2184 // accessibility value for each DW_TAG_member in the
2185 // "member_accessibilities" array. If the value for the
2186 // member is zero, then it was set to the "default_accessibility"
2187 // which for structs was "public". Below we correct this
2188 // by setting any fields to "private" that weren't correctly
2189 // set.
2190 if (is_a_class && !member_accessibilities.empty())
2191 {
2192 // This is a class and all members that didn't have
2193 // their access specified are private.
2194 ast.SetDefaultAccessForRecordFields (clang_type,
2195 eAccessPrivate,
2196 &member_accessibilities.front(),
2197 member_accessibilities.size());
2198 }
2199
2200 if (!base_classes.empty())
2201 {
2202 ast.SetBaseClassesForClassType (clang_type,
2203 &base_classes.front(),
2204 base_classes.size());
2205
2206 // Clang will copy each CXXBaseSpecifier in "base_classes"
2207 // so we have to free them all.
2208 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2209 base_classes.size());
2210 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002211 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002212 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002213
2214 ast.BuildIndirectFields (clang_type);
2215
Sean Callanan77a1fd32012-02-27 20:07:01 +00002216 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002217
Greg Claytoncaab74e2012-01-28 00:48:57 +00002218 if (!layout_info.field_offsets.empty())
2219 {
2220 if (type)
2221 layout_info.bit_size = type->GetByteSize() * 8;
2222 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002223 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Claytoncaab74e2012-01-28 00:48:57 +00002224 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2225 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2226 if (record_type)
2227 {
2228 const clang::RecordDecl *record_decl = record_type->getDecl();
2229
2230 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002231 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002232 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002233 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])",
Greg Claytoncaab74e2012-01-28 00:48:57 +00002234 clang_type,
2235 record_decl,
2236 layout_info.bit_size,
2237 layout_info.alignment,
2238 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002239
Greg Clayton821ac6d2012-01-28 02:22:27 +00002240 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2241 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2242 {
2243 GetObjectFile()->GetModule()->LogMessage (log.get(),
2244 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2245 clang_type,
2246 (uint32_t)pos->second,
2247 pos->first->getNameAsString().c_str());
2248 }
2249 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002250 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2251 }
2252 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002253 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002254
Greg Claytonc93237c2010-10-01 20:48:32 +00002255 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002256
2257 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002258 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002259 if (die->HasChildren())
2260 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002261 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2262 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002263 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002264 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002265 return clang_type;
2266
2267 default:
2268 assert(false && "not a forward clang type decl!");
2269 break;
2270 }
2271 return NULL;
2272}
2273
Greg Claytonc685f8e2010-09-15 04:15:46 +00002274Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002275SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002276{
2277 if (type_die != NULL)
2278 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002279 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002280
Greg Claytonc685f8e2010-09-15 04:15:46 +00002281 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002282 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002283
Greg Clayton24739922010-10-13 03:15:28 +00002284 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002285 {
2286 if (type != DIE_IS_BEING_PARSED)
2287 return type;
2288
2289 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002290 type_die->GetOffset(),
2291 DW_TAG_value_to_name(type_die->Tag()),
2292 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002293
2294 }
2295 else
2296 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002297 }
2298 return NULL;
2299}
2300
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002301CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002302SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002303{
2304 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002305 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002306 {
2307 // The symbol vendor doesn't know about this compile unit, we
2308 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002309 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002310 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002311 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002312}
2313
2314bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002315SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002316{
2317 sc.Clear();
2318 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002319 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002320
Greg Clayton81c22f62011-10-19 18:09:39 +00002321 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002322 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002323 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002324
2325 if (sc.function)
2326 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002327 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002328 return true;
2329 }
2330
2331 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002332}
2333
2334uint32_t
2335SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2336{
2337 Timer scoped_timer(__PRETTY_FUNCTION__,
2338 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002339 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002340 so_addr.GetOffset(),
2341 resolve_scope);
2342 uint32_t resolved = 0;
2343 if (resolve_scope & ( eSymbolContextCompUnit |
2344 eSymbolContextFunction |
2345 eSymbolContextBlock |
2346 eSymbolContextLineEntry))
2347 {
2348 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2349
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002350 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002351 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002352 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002353 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002354 if (cu_offset != DW_INVALID_OFFSET)
2355 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002356 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002357 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2358 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002359 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002360 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002361 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002362 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002363 resolved |= eSymbolContextCompUnit;
2364
2365 if (resolve_scope & eSymbolContextLineEntry)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002367 LineTable *line_table = sc.comp_unit->GetLineTable();
2368 if (line_table != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002369 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002370 if (so_addr.IsLinkedAddress())
2371 {
2372 Address linked_addr (so_addr);
2373 linked_addr.ResolveLinkedAddress();
2374 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2375 {
2376 resolved |= eSymbolContextLineEntry;
2377 }
2378 }
2379 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002380 {
2381 resolved |= eSymbolContextLineEntry;
2382 }
2383 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002384 }
2385
2386 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2387 {
2388 DWARFDebugInfoEntry *function_die = NULL;
2389 DWARFDebugInfoEntry *block_die = NULL;
2390 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002391 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002392 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2393 }
2394 else
2395 {
2396 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2397 }
2398
2399 if (function_die != NULL)
2400 {
2401 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2402 if (sc.function == NULL)
2403 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2404 }
2405 else
2406 {
2407 // We might have had a compile unit that had discontiguous
2408 // address ranges where the gaps are symbols that don't have
2409 // any debug info. Discontiguous compile unit address ranges
2410 // should only happen when there aren't other functions from
2411 // other compile units in these gaps. This helps keep the size
2412 // of the aranges down.
2413 sc.comp_unit = NULL;
2414 resolved &= ~eSymbolContextCompUnit;
2415 }
2416
2417 if (sc.function != NULL)
2418 {
2419 resolved |= eSymbolContextFunction;
2420
2421 if (resolve_scope & eSymbolContextBlock)
2422 {
2423 Block& block = sc.function->GetBlock (true);
2424
2425 if (block_die != NULL)
2426 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2427 else
2428 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2429 if (sc.block)
2430 resolved |= eSymbolContextBlock;
2431 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002432 }
2433 }
2434 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002435 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002436 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002437 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2438 cu_offset,
2439 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002440 }
2441 }
2442 }
2443 }
2444 }
2445 return resolved;
2446}
2447
2448
2449
2450uint32_t
2451SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2452{
2453 const uint32_t prev_size = sc_list.GetSize();
2454 if (resolve_scope & eSymbolContextCompUnit)
2455 {
2456 DWARFDebugInfo* debug_info = DebugInfo();
2457 if (debug_info)
2458 {
2459 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002460 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461
Greg Clayton53eb1c22012-04-02 22:59:12 +00002462 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002463 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002464 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002465 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2466 if (check_inlines || file_spec_matches_cu_file_spec)
2467 {
2468 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002469 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002470 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002471 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002472 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002473
Greg Clayton526a4ae2012-05-16 22:09:01 +00002474 // If we are looking for inline functions only and we don't
2475 // find it in the support files, we are done.
2476 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002477 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002478 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2479 if (file_idx == UINT32_MAX)
2480 continue;
2481 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002482
Greg Clayton526a4ae2012-05-16 22:09:01 +00002483 if (line != 0)
2484 {
2485 LineTable *line_table = sc.comp_unit->GetLineTable();
2486
2487 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002488 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002489 // We will have already looked up the file index if
2490 // we are searching for inline entries.
2491 if (!check_inlines)
2492 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002493
Greg Clayton526a4ae2012-05-16 22:09:01 +00002494 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002495 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002496 uint32_t found_line;
2497 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2498 found_line = sc.line_entry.line;
2499
2500 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002501 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002502 sc.function = NULL;
2503 sc.block = NULL;
2504 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002505 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002506 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2507 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002508 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002509 DWARFDebugInfoEntry *function_die = NULL;
2510 DWARFDebugInfoEntry *block_die = NULL;
2511 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002512
Greg Clayton526a4ae2012-05-16 22:09:01 +00002513 if (function_die != NULL)
2514 {
2515 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2516 if (sc.function == NULL)
2517 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2518 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002519
Greg Clayton526a4ae2012-05-16 22:09:01 +00002520 if (sc.function != NULL)
2521 {
2522 Block& block = sc.function->GetBlock (true);
2523
2524 if (block_die != NULL)
2525 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2526 else
2527 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2528 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002529 }
2530 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002531
Greg Clayton526a4ae2012-05-16 22:09:01 +00002532 sc_list.Append(sc);
2533 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2534 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002535 }
2536 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002537 else if (file_spec_matches_cu_file_spec && !check_inlines)
2538 {
2539 // only append the context if we aren't looking for inline call sites
2540 // by file and line and if the file spec matches that of the compile unit
2541 sc_list.Append(sc);
2542 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543 }
2544 else if (file_spec_matches_cu_file_spec && !check_inlines)
2545 {
2546 // only append the context if we aren't looking for inline call sites
2547 // by file and line and if the file spec matches that of the compile unit
2548 sc_list.Append(sc);
2549 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002550
Greg Clayton526a4ae2012-05-16 22:09:01 +00002551 if (!check_inlines)
2552 break;
2553 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002554 }
2555 }
2556 }
2557 }
2558 return sc_list.GetSize() - prev_size;
2559}
2560
2561void
2562SymbolFileDWARF::Index ()
2563{
2564 if (m_indexed)
2565 return;
2566 m_indexed = true;
2567 Timer scoped_timer (__PRETTY_FUNCTION__,
2568 "SymbolFileDWARF::Index (%s)",
2569 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2570
2571 DWARFDebugInfo* debug_info = DebugInfo();
2572 if (debug_info)
2573 {
2574 uint32_t cu_idx = 0;
2575 const uint32_t num_compile_units = GetNumCompileUnits();
2576 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2577 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002578 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002579
Greg Clayton53eb1c22012-04-02 22:59:12 +00002580 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002581
Greg Clayton53eb1c22012-04-02 22:59:12 +00002582 dwarf_cu->Index (cu_idx,
2583 m_function_basename_index,
2584 m_function_fullname_index,
2585 m_function_method_index,
2586 m_function_selector_index,
2587 m_objc_class_selectors_index,
2588 m_global_index,
2589 m_type_index,
2590 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002591
2592 // Keep memory down by clearing DIEs if this generate function
2593 // caused them to be parsed
2594 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002595 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002596 }
2597
Greg Claytond4a2b372011-09-12 23:21:58 +00002598 m_function_basename_index.Finalize();
2599 m_function_fullname_index.Finalize();
2600 m_function_method_index.Finalize();
2601 m_function_selector_index.Finalize();
2602 m_objc_class_selectors_index.Finalize();
2603 m_global_index.Finalize();
2604 m_type_index.Finalize();
2605 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002606
Greg Clayton24739922010-10-13 03:15:28 +00002607#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002608 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002609 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002610 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2611 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002612 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2613 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2614 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2615 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2616 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2617 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002618 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002619 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002620#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002621 }
2622}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002623
2624bool
2625SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2626{
2627 if (namespace_decl == NULL)
2628 {
2629 // Invalid namespace decl which means we aren't matching only things
2630 // in this symbol file, so return true to indicate it matches this
2631 // symbol file.
2632 return true;
2633 }
2634
2635 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2636
2637 if (namespace_ast == NULL)
2638 return true; // No AST in the "namespace_decl", return true since it
2639 // could then match any symbol file, including this one
2640
2641 if (namespace_ast == GetClangASTContext().getASTContext())
2642 return true; // The ASTs match, return true
2643
2644 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002645 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2646
2647 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002648 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002649
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002650 return false;
2651}
2652
Greg Clayton2506a7a2011-10-12 23:34:26 +00002653bool
2654SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2655 DWARFCompileUnit* cu,
2656 const DWARFDebugInfoEntry* die)
2657{
2658 // No namespace specified, so the answesr i
2659 if (namespace_decl == NULL)
2660 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002661
2662 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002663
Greg Clayton437a1352012-04-09 22:43:43 +00002664 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2665 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002666 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002667 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002668 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002669
Greg Clayton2506a7a2011-10-12 23:34:26 +00002670 if (clang_namespace_decl)
2671 {
2672 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002673 {
2674 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002675 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002676 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002677 }
2678
Greg Clayton437a1352012-04-09 22:43:43 +00002679 if (clang_namespace_decl == die_clang_decl_ctx)
2680 return true;
2681 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002682 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002683 }
2684 else
2685 {
2686 // We have a namespace_decl that was not NULL but it contained
2687 // a NULL "clang::NamespaceDecl", so this means the global namespace
2688 // So as long the the contained decl context DIE isn't a namespace
2689 // we should be ok.
2690 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2691 return true;
2692 }
2693 }
Sean Callananebe60672011-10-13 21:50:33 +00002694
2695 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002696 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002697
Greg Clayton2506a7a2011-10-12 23:34:26 +00002698 return false;
2699}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002700uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002701SymbolFileDWARF::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 +00002702{
Greg Clayton21f2a492011-10-06 00:09:08 +00002703 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2704
2705 if (log)
2706 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002707 GetObjectFile()->GetModule()->LogMessage (log.get(),
2708 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2709 name.GetCString(),
2710 namespace_decl,
2711 append,
2712 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002713 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002714
2715 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2716 return 0;
2717
Greg Claytonc685f8e2010-09-15 04:15:46 +00002718 DWARFDebugInfo* info = DebugInfo();
2719 if (info == NULL)
2720 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002721
2722 // If we aren't appending the results to this list, then clear the list
2723 if (!append)
2724 variables.Clear();
2725
2726 // Remember how many variables are in the list before we search in case
2727 // we are appending the results to a variable list.
2728 const uint32_t original_size = variables.GetSize();
2729
Greg Claytond4a2b372011-09-12 23:21:58 +00002730 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002731
Greg Clayton97fbc342011-10-20 22:30:33 +00002732 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002733 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002734 if (m_apple_names_ap.get())
2735 {
2736 const char *name_cstr = name.GetCString();
2737 const char *base_name_start;
2738 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002739
Greg Clayton97fbc342011-10-20 22:30:33 +00002740 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2741 base_name_start = name_cstr;
2742
2743 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2744 }
Greg Clayton7f995132011-10-04 22:41:51 +00002745 }
2746 else
2747 {
2748 // Index the DWARF if we haven't already
2749 if (!m_indexed)
2750 Index ();
2751
2752 m_global_index.Find (name, die_offsets);
2753 }
2754
Greg Clayton437a1352012-04-09 22:43:43 +00002755 const size_t num_die_matches = die_offsets.size();
2756 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002757 {
Greg Clayton7f995132011-10-04 22:41:51 +00002758 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002759 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002760 assert (sc.module_sp);
2761
Greg Claytond4a2b372011-09-12 23:21:58 +00002762 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002763 DWARFCompileUnit* dwarf_cu = NULL;
2764 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002765 bool done = false;
2766 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002767 {
2768 const dw_offset_t die_offset = die_offsets[i];
2769 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002770
Greg Clayton95d87902011-11-11 03:16:25 +00002771 if (die)
2772 {
Greg Clayton437a1352012-04-09 22:43:43 +00002773 switch (die->Tag())
2774 {
2775 default:
2776 case DW_TAG_subprogram:
2777 case DW_TAG_inlined_subroutine:
2778 case DW_TAG_try_block:
2779 case DW_TAG_catch_block:
2780 break;
2781
2782 case DW_TAG_variable:
2783 {
2784 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002785
2786 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2787 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002788
Greg Clayton437a1352012-04-09 22:43:43 +00002789 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002790
Greg Clayton437a1352012-04-09 22:43:43 +00002791 if (variables.GetSize() - original_size >= max_matches)
2792 done = true;
2793 }
2794 break;
2795 }
Greg Clayton95d87902011-11-11 03:16:25 +00002796 }
2797 else
2798 {
2799 if (m_using_apple_tables)
2800 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002801 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2802 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002803 }
2804 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002805 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002806 }
2807
2808 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002809 const uint32_t num_matches = variables.GetSize() - original_size;
2810 if (log && num_matches > 0)
2811 {
2812 GetObjectFile()->GetModule()->LogMessage (log.get(),
2813 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2814 name.GetCString(),
2815 namespace_decl,
2816 append,
2817 max_matches,
2818 num_matches);
2819 }
2820 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002821}
2822
2823uint32_t
2824SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2825{
Greg Clayton21f2a492011-10-06 00:09:08 +00002826 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2827
2828 if (log)
2829 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002830 GetObjectFile()->GetModule()->LogMessage (log.get(),
2831 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2832 regex.GetText(),
2833 append,
2834 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002835 }
2836
Greg Claytonc685f8e2010-09-15 04:15:46 +00002837 DWARFDebugInfo* info = DebugInfo();
2838 if (info == NULL)
2839 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002840
2841 // If we aren't appending the results to this list, then clear the list
2842 if (!append)
2843 variables.Clear();
2844
2845 // Remember how many variables are in the list before we search in case
2846 // we are appending the results to a variable list.
2847 const uint32_t original_size = variables.GetSize();
2848
Greg Clayton7f995132011-10-04 22:41:51 +00002849 DIEArray die_offsets;
2850
Greg Clayton97fbc342011-10-20 22:30:33 +00002851 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002852 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002853 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002854 {
2855 DWARFMappedHash::DIEInfoArray hash_data_array;
2856 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2857 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2858 }
Greg Clayton7f995132011-10-04 22:41:51 +00002859 }
2860 else
2861 {
2862 // Index the DWARF if we haven't already
2863 if (!m_indexed)
2864 Index ();
2865
2866 m_global_index.Find (regex, die_offsets);
2867 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002868
Greg Claytonc685f8e2010-09-15 04:15:46 +00002869 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002870 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002871 assert (sc.module_sp);
2872
Greg Claytond4a2b372011-09-12 23:21:58 +00002873 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002874 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002875 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002876 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002877 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002878 DWARFDebugInfo* debug_info = DebugInfo();
2879 for (size_t i=0; i<num_matches; ++i)
2880 {
2881 const dw_offset_t die_offset = die_offsets[i];
2882 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002883
2884 if (die)
2885 {
2886 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002887
Greg Clayton95d87902011-11-11 03:16:25 +00002888 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002889
Greg Clayton95d87902011-11-11 03:16:25 +00002890 if (variables.GetSize() - original_size >= max_matches)
2891 break;
2892 }
2893 else
2894 {
2895 if (m_using_apple_tables)
2896 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002897 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2898 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002899 }
2900 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002901 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002902 }
2903
2904 // Return the number of variable that were appended to the list
2905 return variables.GetSize() - original_size;
2906}
2907
Greg Claytonaa044962011-10-13 00:59:38 +00002908
Jim Ingham4cda6e02011-10-07 22:23:45 +00002909bool
2910SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2911 DWARFCompileUnit *&dwarf_cu,
2912 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002913{
Greg Claytonaa044962011-10-13 00:59:38 +00002914 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2915 return ResolveFunction (dwarf_cu, die, sc_list);
2916}
2917
2918
2919bool
2920SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2921 const DWARFDebugInfoEntry *die,
2922 SymbolContextList& sc_list)
2923{
Greg Clayton9e315582011-09-02 04:03:59 +00002924 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002925
2926 if (die == NULL)
2927 return false;
2928
Jim Ingham4cda6e02011-10-07 22:23:45 +00002929 // If we were passed a die that is not a function, just return false...
2930 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2931 return false;
2932
2933 const DWARFDebugInfoEntry* inlined_die = NULL;
2934 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002935 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002936 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002937
Jim Ingham4cda6e02011-10-07 22:23:45 +00002938 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002939 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002940 if (die->Tag() == DW_TAG_subprogram)
2941 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002942 }
2943 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002944 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002945 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002946 {
2947 Address addr;
2948 // Parse all blocks if needed
2949 if (inlined_die)
2950 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002951 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002952 assert (sc.block != NULL);
2953 if (sc.block->GetStartAddress (addr) == false)
2954 addr.Clear();
2955 }
2956 else
2957 {
2958 sc.block = NULL;
2959 addr = sc.function->GetAddressRange().GetBaseAddress();
2960 }
2961
2962 if (addr.IsValid())
2963 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002964 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002965 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002966 }
2967 }
2968
Greg Claytonaa044962011-10-13 00:59:38 +00002969 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002970}
2971
Greg Clayton7f995132011-10-04 22:41:51 +00002972void
2973SymbolFileDWARF::FindFunctions (const ConstString &name,
2974 const NameToDIE &name_to_die,
2975 SymbolContextList& sc_list)
2976{
Greg Claytond4a2b372011-09-12 23:21:58 +00002977 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002978 if (name_to_die.Find (name, die_offsets))
2979 {
2980 ParseFunctions (die_offsets, sc_list);
2981 }
2982}
2983
2984
2985void
2986SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2987 const NameToDIE &name_to_die,
2988 SymbolContextList& sc_list)
2989{
2990 DIEArray die_offsets;
2991 if (name_to_die.Find (regex, die_offsets))
2992 {
2993 ParseFunctions (die_offsets, sc_list);
2994 }
2995}
2996
2997
2998void
2999SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
3000 const DWARFMappedHash::MemoryTable &memory_table,
3001 SymbolContextList& sc_list)
3002{
3003 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00003004 DWARFMappedHash::DIEInfoArray hash_data_array;
3005 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00003006 {
Greg Claytond1767f02011-12-08 02:13:16 +00003007 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00003008 ParseFunctions (die_offsets, sc_list);
3009 }
3010}
3011
3012void
3013SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3014 SymbolContextList& sc_list)
3015{
3016 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003017 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00003018 {
Greg Clayton7f995132011-10-04 22:41:51 +00003019 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00003020
3021 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003022 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00003023 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003024 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00003025 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003026 }
3027 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00003028}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003029
Jim Ingham4cda6e02011-10-07 22:23:45 +00003030bool
3031SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3032 const DWARFCompileUnit *dwarf_cu,
3033 uint32_t name_type_mask,
3034 const char *partial_name,
3035 const char *base_name_start,
3036 const char *base_name_end)
3037{
3038 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
3039 if (name_type_mask == eFunctionNameTypeMethod
3040 || name_type_mask == eFunctionNameTypeBase)
3041 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003042 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3043 if (!containing_decl_ctx)
3044 return false;
3045
3046 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3047
3048 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
3049 return false;
3050 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
3051 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003052 }
3053
3054 // Now we need to check whether the name we got back for this type matches the extra specifications
3055 // that were in the name we're looking up:
3056 if (base_name_start != partial_name || *base_name_end != '\0')
3057 {
3058 // First see if the stuff to the left matches the full name. To do that let's see if
3059 // we can pull out the mips linkage name attribute:
3060
3061 Mangled best_name;
3062
3063 DWARFDebugInfoEntry::Attributes attributes;
3064 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3065 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3066 if (idx != UINT32_MAX)
3067 {
3068 DWARFFormValue form_value;
3069 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3070 {
3071 const char *name = form_value.AsCString(&get_debug_str_data());
3072 best_name.SetValue (name, true);
3073 }
3074 }
3075 if (best_name)
3076 {
3077 const char *demangled = best_name.GetDemangledName().GetCString();
3078 if (demangled)
3079 {
3080 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003081 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3082 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003083 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003084 else
3085 {
3086 // Sort out the case where our name is something like "Process::Destroy" and the match is
3087 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3088 // namespace boundaries...
3089
3090 if (partial_name[0] == ':' && partial_name[1] == ':')
3091 {
3092 // The partial name was already on a namespace boundary so all matches are good.
3093 return true;
3094 }
3095 else if (partial_in_demangled == demangled)
3096 {
3097 // They both start the same, so this is an good match.
3098 return true;
3099 }
3100 else
3101 {
3102 if (partial_in_demangled - demangled == 1)
3103 {
3104 // Only one character difference, can't be a namespace boundary...
3105 return false;
3106 }
3107 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3108 {
3109 // We are on a namespace boundary, so this is also good.
3110 return true;
3111 }
3112 else
3113 return false;
3114 }
3115 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003116 }
3117 }
3118 }
3119
3120 return true;
3121}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003122
Greg Clayton0c5cd902010-06-28 21:30:43 +00003123uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003124SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003125 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003126 uint32_t name_type_mask,
3127 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003128 bool append,
3129 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003130{
3131 Timer scoped_timer (__PRETTY_FUNCTION__,
3132 "SymbolFileDWARF::FindFunctions (name = '%s')",
3133 name.AsCString());
3134
Greg Clayton21f2a492011-10-06 00:09:08 +00003135 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3136
3137 if (log)
3138 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003139 GetObjectFile()->GetModule()->LogMessage (log.get(),
3140 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3141 name.GetCString(),
3142 name_type_mask,
3143 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003144 }
3145
Greg Clayton0c5cd902010-06-28 21:30:43 +00003146 // If we aren't appending the results to this list, then clear the list
3147 if (!append)
3148 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003149
3150 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3151 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003152
3153 // If name is empty then we won't find anything.
3154 if (name.IsEmpty())
3155 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003156
3157 // Remember how many sc_list are in the list before we search in case
3158 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003159
Greg Clayton9e315582011-09-02 04:03:59 +00003160 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003161
Jim Ingham4cda6e02011-10-07 22:23:45 +00003162 const char *name_cstr = name.GetCString();
3163 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3164 const char *base_name_start = name_cstr;
3165 const char *base_name_end = name_cstr + strlen(name_cstr);
3166
3167 if (name_type_mask & eFunctionNameTypeAuto)
3168 {
3169 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3170 effective_name_type_mask = eFunctionNameTypeFull;
3171 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3172 effective_name_type_mask = eFunctionNameTypeFull;
3173 else
3174 {
3175 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3176 effective_name_type_mask |= eFunctionNameTypeSelector;
3177
3178 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3179 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3180 }
3181 }
3182 else
3183 {
3184 effective_name_type_mask = name_type_mask;
3185 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3186 {
3187 // If they've asked for a CPP method or function name and it can't be that, we don't
3188 // even need to search for CPP methods or names.
3189 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3190 {
3191 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3192 if (effective_name_type_mask == eFunctionNameTypeNone)
3193 return 0;
3194 }
3195 }
3196
3197 if (effective_name_type_mask & eFunctionNameTypeSelector)
3198 {
3199 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3200 {
3201 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3202 if (effective_name_type_mask == eFunctionNameTypeNone)
3203 return 0;
3204 }
3205 }
3206 }
3207
3208 DWARFDebugInfo* info = DebugInfo();
3209 if (info == NULL)
3210 return 0;
3211
Greg Claytonaa044962011-10-13 00:59:38 +00003212 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003213 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003214 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003215 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003216 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003217
3218 DIEArray die_offsets;
3219
3220 uint32_t num_matches = 0;
3221
3222 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003223 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003224 // If they asked for the full name, match what they typed. At some point we may
3225 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3226 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003227 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003228 for (uint32_t i = 0; i < num_matches; i++)
3229 {
Greg Clayton95d87902011-11-11 03:16:25 +00003230 const dw_offset_t die_offset = die_offsets[i];
3231 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003232 if (die)
3233 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003234 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3235 continue;
3236
Sean Callanan9df05fb2012-02-10 22:52:19 +00003237 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3238 continue;
3239
Greg Claytonaa044962011-10-13 00:59:38 +00003240 ResolveFunction (dwarf_cu, die, sc_list);
3241 }
Greg Clayton95d87902011-11-11 03:16:25 +00003242 else
3243 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003244 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3245 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003246 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003247 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003248 }
3249 else
3250 {
3251 if (effective_name_type_mask & eFunctionNameTypeSelector)
3252 {
3253 if (namespace_decl && *namespace_decl)
3254 return 0; // no selectors in namespaces
3255
3256 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3257 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3258 // and if it is an ObjC method name, we're good.
3259
3260 for (uint32_t i = 0; i < num_matches; i++)
3261 {
Greg Clayton95d87902011-11-11 03:16:25 +00003262 const dw_offset_t die_offset = die_offsets[i];
3263 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003264 if (die)
3265 {
3266 const char *die_name = die->GetName(this, dwarf_cu);
3267 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003268 {
3269 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3270 continue;
3271
Greg Clayton97fbc342011-10-20 22:30:33 +00003272 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003273 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003274 }
Greg Clayton95d87902011-11-11 03:16:25 +00003275 else
3276 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003277 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3278 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003279 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003280 }
3281 die_offsets.clear();
3282 }
3283
3284 if (effective_name_type_mask & eFunctionNameTypeMethod
3285 || effective_name_type_mask & eFunctionNameTypeBase)
3286 {
3287 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3288 (namespace_decl && *namespace_decl))
3289 return 0; // no methods in namespaces
3290
3291 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3292 // extract the base name, look that up, and if there is any other information in the name we were
3293 // passed in we have to post-filter based on that.
3294
3295 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3296 std::string base_name(base_name_start, base_name_end - base_name_start);
3297 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3298
3299 for (uint32_t i = 0; i < num_matches; i++)
3300 {
Greg Clayton95d87902011-11-11 03:16:25 +00003301 const dw_offset_t die_offset = die_offsets[i];
3302 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003303 if (die)
3304 {
3305 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3306 continue;
3307
3308 if (!FunctionDieMatchesPartialName(die,
3309 dwarf_cu,
3310 effective_name_type_mask,
3311 name_cstr,
3312 base_name_start,
3313 base_name_end))
3314 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003315
3316 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3317 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003318
3319 // If we get to here, the die is good, and we should add it:
3320 ResolveFunction (dwarf_cu, die, sc_list);
3321 }
Greg Clayton95d87902011-11-11 03:16:25 +00003322 else
3323 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003324 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3325 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003326 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003327 }
3328 die_offsets.clear();
3329 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003330 }
3331 }
Greg Clayton7f995132011-10-04 22:41:51 +00003332 }
3333 else
3334 {
3335
3336 // Index the DWARF if we haven't already
3337 if (!m_indexed)
3338 Index ();
3339
Greg Clayton7f995132011-10-04 22:41:51 +00003340 if (name_type_mask & eFunctionNameTypeFull)
3341 FindFunctions (name, m_function_fullname_index, sc_list);
3342
Jim Ingham4cda6e02011-10-07 22:23:45 +00003343 std::string base_name(base_name_start, base_name_end - base_name_start);
3344 ConstString base_name_const(base_name.c_str());
3345 DIEArray die_offsets;
3346 DWARFCompileUnit *dwarf_cu = NULL;
3347
3348 if (effective_name_type_mask & eFunctionNameTypeBase)
3349 {
3350 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003351 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003352 {
Greg Claytonaa044962011-10-13 00:59:38 +00003353 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3354 if (die)
3355 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003356 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3357 continue;
3358
Greg Claytonaa044962011-10-13 00:59:38 +00003359 if (!FunctionDieMatchesPartialName(die,
3360 dwarf_cu,
3361 effective_name_type_mask,
3362 name_cstr,
3363 base_name_start,
3364 base_name_end))
3365 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003366
Sean Callanan9df05fb2012-02-10 22:52:19 +00003367 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3368 continue;
3369
Greg Claytonaa044962011-10-13 00:59:38 +00003370 // If we get to here, the die is good, and we should add it:
3371 ResolveFunction (dwarf_cu, die, sc_list);
3372 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003373 }
3374 die_offsets.clear();
3375 }
3376
Jim Inghamea8005a2011-10-11 01:18:11 +00003377 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003378 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003379 if (namespace_decl && *namespace_decl)
3380 return 0; // no methods in namespaces
3381
Jim Ingham4cda6e02011-10-07 22:23:45 +00003382 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3383 {
Greg Claytonaa044962011-10-13 00:59:38 +00003384 for (uint32_t i = 0; i < num_base; i++)
3385 {
3386 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3387 if (die)
3388 {
3389 if (!FunctionDieMatchesPartialName(die,
3390 dwarf_cu,
3391 effective_name_type_mask,
3392 name_cstr,
3393 base_name_start,
3394 base_name_end))
3395 continue;
3396
Sean Callanan9df05fb2012-02-10 22:52:19 +00003397 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3398 continue;
3399
Greg Claytonaa044962011-10-13 00:59:38 +00003400 // If we get to here, the die is good, and we should add it:
3401 ResolveFunction (dwarf_cu, die, sc_list);
3402 }
3403 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003404 }
3405 die_offsets.clear();
3406 }
Greg Clayton7f995132011-10-04 22:41:51 +00003407
Sean Callanan213fdb82011-10-13 01:49:10 +00003408 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003409 {
Greg Clayton7f995132011-10-04 22:41:51 +00003410 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003411 }
3412
Greg Clayton4d01ace2011-09-29 16:58:15 +00003413 }
3414
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003415 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003416 const uint32_t num_matches = sc_list.GetSize() - original_size;
3417
3418 if (log && num_matches > 0)
3419 {
3420 GetObjectFile()->GetModule()->LogMessage (log.get(),
3421 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3422 name.GetCString(),
3423 name_type_mask,
3424 append,
3425 num_matches);
3426 }
3427 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003428}
3429
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003431SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003432{
3433 Timer scoped_timer (__PRETTY_FUNCTION__,
3434 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3435 regex.GetText());
3436
Greg Clayton21f2a492011-10-06 00:09:08 +00003437 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3438
3439 if (log)
3440 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003441 GetObjectFile()->GetModule()->LogMessage (log.get(),
3442 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3443 regex.GetText(),
3444 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003445 }
3446
3447
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003448 // If we aren't appending the results to this list, then clear the list
3449 if (!append)
3450 sc_list.Clear();
3451
3452 // Remember how many sc_list are in the list before we search in case
3453 // we are appending the results to a variable list.
3454 uint32_t original_size = sc_list.GetSize();
3455
Greg Clayton97fbc342011-10-20 22:30:33 +00003456 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003457 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003458 if (m_apple_names_ap.get())
3459 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003460 }
3461 else
3462 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003463 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003464 if (!m_indexed)
3465 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003466
Greg Clayton7f995132011-10-04 22:41:51 +00003467 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003468
Greg Clayton7f995132011-10-04 22:41:51 +00003469 FindFunctions (regex, m_function_fullname_index, sc_list);
3470 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003471
3472 // Return the number of variable that were appended to the list
3473 return sc_list.GetSize() - original_size;
3474}
Jim Ingham318c9f22011-08-26 19:44:13 +00003475
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003476uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003477SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3478 const ConstString &name,
3479 const lldb_private::ClangNamespaceDecl *namespace_decl,
3480 bool append,
3481 uint32_t max_matches,
3482 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003483{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003484 DWARFDebugInfo* info = DebugInfo();
3485 if (info == NULL)
3486 return 0;
3487
Greg Clayton21f2a492011-10-06 00:09:08 +00003488 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3489
3490 if (log)
3491 {
Greg Clayton437a1352012-04-09 22:43:43 +00003492 if (namespace_decl)
3493 {
3494 GetObjectFile()->GetModule()->LogMessage (log.get(),
3495 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3496 name.GetCString(),
3497 namespace_decl->GetNamespaceDecl(),
3498 namespace_decl->GetQualifiedName().c_str(),
3499 append,
3500 max_matches);
3501 }
3502 else
3503 {
3504 GetObjectFile()->GetModule()->LogMessage (log.get(),
3505 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3506 name.GetCString(),
3507 append,
3508 max_matches);
3509 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003510 }
3511
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003512 // If we aren't appending the results to this list, then clear the list
3513 if (!append)
3514 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003515
3516 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3517 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003518
Greg Claytond4a2b372011-09-12 23:21:58 +00003519 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003520
Greg Clayton97fbc342011-10-20 22:30:33 +00003521 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003522 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003523 if (m_apple_types_ap.get())
3524 {
3525 const char *name_cstr = name.GetCString();
3526 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3527 }
Greg Clayton7f995132011-10-04 22:41:51 +00003528 }
3529 else
3530 {
3531 if (!m_indexed)
3532 Index ();
3533
3534 m_type_index.Find (name, die_offsets);
3535 }
3536
Greg Clayton437a1352012-04-09 22:43:43 +00003537 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003538
Greg Clayton437a1352012-04-09 22:43:43 +00003539 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003540 {
Greg Clayton7f995132011-10-04 22:41:51 +00003541 const uint32_t initial_types_size = types.GetSize();
3542 DWARFCompileUnit* dwarf_cu = NULL;
3543 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003544 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003545 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003546 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003547 const dw_offset_t die_offset = die_offsets[i];
3548 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3549
Greg Clayton95d87902011-11-11 03:16:25 +00003550 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003551 {
Greg Clayton95d87902011-11-11 03:16:25 +00003552 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3553 continue;
3554
3555 Type *matching_type = ResolveType (dwarf_cu, die);
3556 if (matching_type)
3557 {
3558 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003559 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003560 if (types.GetSize() >= max_matches)
3561 break;
3562 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003563 }
Greg Clayton95d87902011-11-11 03:16:25 +00003564 else
3565 {
3566 if (m_using_apple_tables)
3567 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003568 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3569 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003570 }
3571 }
3572
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003573 }
Greg Clayton437a1352012-04-09 22:43:43 +00003574 const uint32_t num_matches = types.GetSize() - initial_types_size;
3575 if (log && num_matches)
3576 {
3577 if (namespace_decl)
3578 {
3579 GetObjectFile()->GetModule()->LogMessage (log.get(),
3580 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3581 name.GetCString(),
3582 namespace_decl->GetNamespaceDecl(),
3583 namespace_decl->GetQualifiedName().c_str(),
3584 append,
3585 max_matches,
3586 num_matches);
3587 }
3588 else
3589 {
3590 GetObjectFile()->GetModule()->LogMessage (log.get(),
3591 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3592 name.GetCString(),
3593 append,
3594 max_matches,
3595 num_matches);
3596 }
3597 }
3598 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003599 }
Greg Clayton7f995132011-10-04 22:41:51 +00003600 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601}
3602
3603
Greg Clayton526e5af2010-11-13 03:52:47 +00003604ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003605SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003606 const ConstString &name,
3607 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003608{
Greg Clayton21f2a492011-10-06 00:09:08 +00003609 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3610
3611 if (log)
3612 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003613 GetObjectFile()->GetModule()->LogMessage (log.get(),
3614 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3615 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003616 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003617
3618 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3619 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003620
Greg Clayton526e5af2010-11-13 03:52:47 +00003621 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003622 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003623 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003624 {
Greg Clayton7f995132011-10-04 22:41:51 +00003625 DIEArray die_offsets;
3626
Greg Clayton526e5af2010-11-13 03:52:47 +00003627 // Index if we already haven't to make sure the compile units
3628 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003629 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003630 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003631 if (m_apple_namespaces_ap.get())
3632 {
3633 const char *name_cstr = name.GetCString();
3634 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3635 }
Greg Clayton7f995132011-10-04 22:41:51 +00003636 }
3637 else
3638 {
3639 if (!m_indexed)
3640 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003641
Greg Clayton7f995132011-10-04 22:41:51 +00003642 m_namespace_index.Find (name, die_offsets);
3643 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003644
3645 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003646 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003647 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003648 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003649 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003650 DWARFDebugInfo* debug_info = DebugInfo();
3651 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003652 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003653 const dw_offset_t die_offset = die_offsets[i];
3654 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003655
Greg Clayton95d87902011-11-11 03:16:25 +00003656 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003657 {
Greg Clayton95d87902011-11-11 03:16:25 +00003658 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3659 continue;
3660
3661 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3662 if (clang_namespace_decl)
3663 {
3664 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3665 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003666 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003667 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003668 }
Greg Clayton95d87902011-11-11 03:16:25 +00003669 else
3670 {
3671 if (m_using_apple_tables)
3672 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003673 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3674 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003675 }
3676 }
3677
Greg Clayton526e5af2010-11-13 03:52:47 +00003678 }
3679 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003680 }
Greg Clayton437a1352012-04-09 22:43:43 +00003681 if (log && namespace_decl.GetNamespaceDecl())
3682 {
3683 GetObjectFile()->GetModule()->LogMessage (log.get(),
3684 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3685 name.GetCString(),
3686 namespace_decl.GetNamespaceDecl(),
3687 namespace_decl.GetQualifiedName().c_str());
3688 }
3689
Greg Clayton526e5af2010-11-13 03:52:47 +00003690 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003691}
3692
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003693uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003694SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003695{
3696 // Remember how many sc_list are in the list before we search in case
3697 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003698 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003699
3700 const uint32_t num_die_offsets = die_offsets.size();
3701 // Parse all of the types we found from the pubtypes matches
3702 uint32_t i;
3703 uint32_t num_matches = 0;
3704 for (i = 0; i < num_die_offsets; ++i)
3705 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003706 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3707 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003708 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003709 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003710 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003711 ++num_matches;
3712 if (num_matches >= max_matches)
3713 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003714 }
3715 }
3716
3717 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003718 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003719}
3720
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003721
3722size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003723SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3724 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003725 DWARFCompileUnit* dwarf_cu,
3726 const DWARFDebugInfoEntry *parent_die,
3727 bool skip_artificial,
3728 bool &is_static,
3729 TypeList* type_list,
3730 std::vector<clang_type_t>& function_param_types,
3731 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003732 unsigned &type_quals,
3733 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003734{
3735 if (parent_die == NULL)
3736 return 0;
3737
Greg Claytond88d7592010-09-15 08:33:30 +00003738 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3739
Greg Clayton7fedea22010-11-16 02:10:54 +00003740 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003741 const DWARFDebugInfoEntry *die;
3742 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3743 {
3744 dw_tag_t tag = die->Tag();
3745 switch (tag)
3746 {
3747 case DW_TAG_formal_parameter:
3748 {
3749 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003750 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003751 if (num_attributes > 0)
3752 {
3753 const char *name = NULL;
3754 Declaration decl;
3755 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003756 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003757 // one of None, Auto, Register, Extern, Static, PrivateExtern
3758
Sean Callanane2ef6e32010-09-23 03:01:22 +00003759 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003760 uint32_t i;
3761 for (i=0; i<num_attributes; ++i)
3762 {
3763 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3764 DWARFFormValue form_value;
3765 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3766 {
3767 switch (attr)
3768 {
3769 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3770 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3771 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3772 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3773 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003774 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003775 case DW_AT_location:
3776 // if (form_value.BlockData())
3777 // {
3778 // const DataExtractor& debug_info_data = debug_info();
3779 // uint32_t block_length = form_value.Unsigned();
3780 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3781 // }
3782 // else
3783 // {
3784 // }
3785 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003786 case DW_AT_const_value:
3787 case DW_AT_default_value:
3788 case DW_AT_description:
3789 case DW_AT_endianity:
3790 case DW_AT_is_optional:
3791 case DW_AT_segment:
3792 case DW_AT_variable_parameter:
3793 default:
3794 case DW_AT_abstract_origin:
3795 case DW_AT_sibling:
3796 break;
3797 }
3798 }
3799 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003800
Greg Clayton0fffff52010-09-24 05:15:53 +00003801 bool skip = false;
3802 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003803 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003804 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003805 {
3806 // In order to determine if a C++ member function is
3807 // "const" we have to look at the const-ness of "this"...
3808 // Ugly, but that
3809 if (arg_idx == 0)
3810 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003811 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003812 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003813 // Often times compilers omit the "this" name for the
3814 // specification DIEs, so we can't rely upon the name
3815 // being in the formal parameter DIE...
3816 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003817 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003818 Type *this_type = ResolveTypeUID (param_type_die_offset);
3819 if (this_type)
3820 {
3821 uint32_t encoding_mask = this_type->GetEncodingMask();
3822 if (encoding_mask & Type::eEncodingIsPointerUID)
3823 {
3824 is_static = false;
3825
3826 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3827 type_quals |= clang::Qualifiers::Const;
3828 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3829 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003830 }
3831 }
3832 }
3833 }
3834 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003835 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003836 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003837 else
3838 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003839
Greg Clayton0fffff52010-09-24 05:15:53 +00003840 // HACK: Objective C formal parameters "self" and "_cmd"
3841 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00003842 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3843 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00003844 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003845 switch (comp_unit->GetLanguage())
3846 {
3847 case eLanguageTypeObjC:
3848 case eLanguageTypeObjC_plus_plus:
3849 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3850 skip = true;
3851 break;
3852 default:
3853 break;
3854 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003855 }
3856 }
3857 }
3858
3859 if (!skip)
3860 {
3861 Type *type = ResolveTypeUID(param_type_die_offset);
3862 if (type)
3863 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003864 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003865
Greg Clayton42ce2f32011-12-12 21:50:19 +00003866 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3867 type->GetClangForwardType(),
3868 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003869 assert(param_var_decl);
3870 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00003871
3872 GetClangASTContext().SetMetadata((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00003873 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003874 }
3875 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003876 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003877 }
3878 break;
3879
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003880 case DW_TAG_template_type_parameter:
3881 case DW_TAG_template_value_parameter:
3882 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3883 break;
3884
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003885 default:
3886 break;
3887 }
3888 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003889 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003890}
3891
3892size_t
3893SymbolFileDWARF::ParseChildEnumerators
3894(
3895 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003896 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003897 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003898 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003899 const DWARFDebugInfoEntry *parent_die
3900)
3901{
3902 if (parent_die == NULL)
3903 return 0;
3904
3905 size_t enumerators_added = 0;
3906 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003907 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3908
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003909 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3910 {
3911 const dw_tag_t tag = die->Tag();
3912 if (tag == DW_TAG_enumerator)
3913 {
3914 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003915 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003916 if (num_child_attributes > 0)
3917 {
3918 const char *name = NULL;
3919 bool got_value = false;
3920 int64_t enum_value = 0;
3921 Declaration decl;
3922
3923 uint32_t i;
3924 for (i=0; i<num_child_attributes; ++i)
3925 {
3926 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3927 DWARFFormValue form_value;
3928 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3929 {
3930 switch (attr)
3931 {
3932 case DW_AT_const_value:
3933 got_value = true;
3934 enum_value = form_value.Unsigned();
3935 break;
3936
3937 case DW_AT_name:
3938 name = form_value.AsCString(&get_debug_str_data());
3939 break;
3940
3941 case DW_AT_description:
3942 default:
3943 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3944 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3945 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3946 case DW_AT_sibling:
3947 break;
3948 }
3949 }
3950 }
3951
3952 if (name && name[0] && got_value)
3953 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003954 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3955 enumerator_clang_type,
3956 decl,
3957 name,
3958 enum_value,
3959 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003960 ++enumerators_added;
3961 }
3962 }
3963 }
3964 }
3965 return enumerators_added;
3966}
3967
3968void
3969SymbolFileDWARF::ParseChildArrayInfo
3970(
3971 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003972 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003973 const DWARFDebugInfoEntry *parent_die,
3974 int64_t& first_index,
3975 std::vector<uint64_t>& element_orders,
3976 uint32_t& byte_stride,
3977 uint32_t& bit_stride
3978)
3979{
3980 if (parent_die == NULL)
3981 return;
3982
3983 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003984 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003985 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3986 {
3987 const dw_tag_t tag = die->Tag();
3988 switch (tag)
3989 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003990 case DW_TAG_subrange_type:
3991 {
3992 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003993 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003994 if (num_child_attributes > 0)
3995 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003996 uint64_t num_elements = 0;
3997 uint64_t lower_bound = 0;
3998 uint64_t upper_bound = 0;
3999 uint32_t i;
4000 for (i=0; i<num_child_attributes; ++i)
4001 {
4002 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4003 DWARFFormValue form_value;
4004 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4005 {
4006 switch (attr)
4007 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004008 case DW_AT_name:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004009 break;
4010
4011 case DW_AT_count:
4012 num_elements = form_value.Unsigned();
4013 break;
4014
4015 case DW_AT_bit_stride:
4016 bit_stride = form_value.Unsigned();
4017 break;
4018
4019 case DW_AT_byte_stride:
4020 byte_stride = form_value.Unsigned();
4021 break;
4022
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004023 case DW_AT_lower_bound:
4024 lower_bound = form_value.Unsigned();
4025 break;
4026
4027 case DW_AT_upper_bound:
4028 upper_bound = form_value.Unsigned();
4029 break;
4030
4031 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004032 case DW_AT_abstract_origin:
4033 case DW_AT_accessibility:
4034 case DW_AT_allocated:
4035 case DW_AT_associated:
4036 case DW_AT_data_location:
4037 case DW_AT_declaration:
4038 case DW_AT_description:
4039 case DW_AT_sibling:
4040 case DW_AT_threads_scaled:
4041 case DW_AT_type:
4042 case DW_AT_visibility:
4043 break;
4044 }
4045 }
4046 }
4047
4048 if (upper_bound > lower_bound)
4049 num_elements = upper_bound - lower_bound + 1;
4050
4051 if (num_elements > 0)
4052 element_orders.push_back (num_elements);
4053 }
4054 }
4055 break;
4056 }
4057 }
4058}
4059
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004060TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004061SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004062{
4063 TypeSP type_sp;
4064 if (die != NULL)
4065 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004066 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004067 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004068 if (type_ptr == NULL)
4069 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004070 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004071 assert (lldb_cu);
4072 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004073 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004074 }
4075 else if (type_ptr != DIE_IS_BEING_PARSED)
4076 {
4077 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004078 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004079 }
4080
4081 }
4082 return type_sp;
4083}
4084
4085clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004086SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004087{
4088 if (die_offset != DW_INVALID_OFFSET)
4089 {
4090 DWARFCompileUnitSP cu_sp;
4091 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004092 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004093 }
4094 return NULL;
4095}
4096
Sean Callanan72e49402011-08-05 23:43:37 +00004097clang::DeclContext *
4098SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4099{
4100 if (die_offset != DW_INVALID_OFFSET)
4101 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004102 DWARFDebugInfo* debug_info = DebugInfo();
4103 if (debug_info)
4104 {
4105 DWARFCompileUnitSP cu_sp;
4106 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4107 if (die)
4108 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4109 }
Sean Callanan72e49402011-08-05 23:43:37 +00004110 }
4111 return NULL;
4112}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004113
Greg Clayton96d7d742010-11-10 23:42:09 +00004114clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004115SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004116{
Greg Clayton030a2042011-10-14 21:34:45 +00004117 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004118 {
Greg Clayton030a2042011-10-14 21:34:45 +00004119 // See if we already parsed this namespace DIE and associated it with a
4120 // uniqued namespace declaration
4121 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4122 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004123 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004124 else
4125 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004126 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4127 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004128 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4129 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4130 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004131 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004132 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004133 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004134 GetObjectFile()->GetModule()->LogMessage (log.get(),
4135 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4136 GetClangASTContext().getASTContext(),
4137 MakeUserID(die->GetOffset()),
4138 namespace_name,
4139 namespace_decl,
4140 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004141 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004142 else
4143 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004144 GetObjectFile()->GetModule()->LogMessage (log.get(),
4145 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4146 GetClangASTContext().getASTContext(),
4147 MakeUserID(die->GetOffset()),
4148 namespace_decl,
4149 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004150 }
Greg Clayton030a2042011-10-14 21:34:45 +00004151 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004152
4153 if (namespace_decl)
4154 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4155 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004156 }
4157 }
4158 return NULL;
4159}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004160
4161clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004162SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004163{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004164 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4165 if (clang_decl_ctx)
4166 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004167 // If this DIE has a specification, or an abstract origin, then trace to those.
4168
Greg Claytoncab36a32011-12-08 05:16:30 +00004169 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004170 if (die_offset != DW_INVALID_OFFSET)
4171 return GetClangDeclContextForDIEOffset (sc, die_offset);
4172
Greg Claytoncab36a32011-12-08 05:16:30 +00004173 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004174 if (die_offset != DW_INVALID_OFFSET)
4175 return GetClangDeclContextForDIEOffset (sc, die_offset);
4176
Greg Clayton3bffb082011-12-10 02:15:28 +00004177 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4178 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004179 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 +00004180 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004181 bool assert_not_being_parsed = true;
4182 ResolveTypeUID (cu, die, assert_not_being_parsed);
4183
Greg Clayton5cf58b92011-10-05 22:22:08 +00004184 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4185
4186 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004187}
4188
4189clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004190SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004191{
Greg Claytonca512b32011-01-14 04:54:56 +00004192 if (m_clang_tu_decl == NULL)
4193 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004194
Greg Clayton2bc22f82011-09-30 03:20:47 +00004195 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004196
4197 if (decl_ctx_die_copy)
4198 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004199
4200 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004201 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004202
Greg Clayton2bc22f82011-09-30 03:20:47 +00004203 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4204 if (pos != m_die_to_decl_ctx.end())
4205 return pos->second;
4206
4207 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004208 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004209 case DW_TAG_compile_unit:
4210 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004211
Greg Clayton2bc22f82011-09-30 03:20:47 +00004212 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004213 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004214 break;
4215
4216 case DW_TAG_structure_type:
4217 case DW_TAG_union_type:
4218 case DW_TAG_class_type:
4219 {
4220 Type* type = ResolveType (cu, decl_ctx_die);
4221 if (type)
4222 {
4223 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4224 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004225 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004226 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4227 if (decl_ctx)
4228 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004229 }
4230 }
Greg Claytonca512b32011-01-14 04:54:56 +00004231 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004232 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004233
Greg Clayton2bc22f82011-09-30 03:20:47 +00004234 default:
4235 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004236 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004237 }
Greg Clayton7a345282010-11-09 23:46:37 +00004238 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004239}
4240
Greg Clayton2bc22f82011-09-30 03:20:47 +00004241
4242const DWARFDebugInfoEntry *
4243SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4244{
4245 if (cu && die)
4246 {
4247 const DWARFDebugInfoEntry * const decl_die = die;
4248
4249 while (die != NULL)
4250 {
4251 // If this is the original DIE that we are searching for a declaration
4252 // for, then don't look in the cache as we don't want our own decl
4253 // context to be our decl context...
4254 if (decl_die != die)
4255 {
4256 switch (die->Tag())
4257 {
4258 case DW_TAG_compile_unit:
4259 case DW_TAG_namespace:
4260 case DW_TAG_structure_type:
4261 case DW_TAG_union_type:
4262 case DW_TAG_class_type:
4263 return die;
4264
4265 default:
4266 break;
4267 }
4268 }
4269
4270 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4271 if (die_offset != DW_INVALID_OFFSET)
4272 {
4273 DWARFCompileUnit *spec_cu = cu;
4274 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4275 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4276 if (spec_die_decl_ctx_die)
4277 return spec_die_decl_ctx_die;
4278 }
4279
4280 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4281 if (die_offset != DW_INVALID_OFFSET)
4282 {
4283 DWARFCompileUnit *abs_cu = cu;
4284 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4285 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4286 if (abs_die_decl_ctx_die)
4287 return abs_die_decl_ctx_die;
4288 }
4289
4290 die = die->GetParent();
4291 }
4292 }
4293 return NULL;
4294}
4295
4296
Greg Clayton901c5ca2011-12-03 04:40:03 +00004297Symbol *
4298SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4299{
4300 Symbol *objc_class_symbol = NULL;
4301 if (m_obj_file)
4302 {
4303 Symtab *symtab = m_obj_file->GetSymtab();
4304 if (symtab)
4305 {
4306 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4307 eSymbolTypeObjCClass,
4308 Symtab::eDebugNo,
4309 Symtab::eVisibilityAny);
4310 }
4311 }
4312 return objc_class_symbol;
4313}
4314
Greg Claytonc7f03b62012-01-12 04:33:28 +00004315// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4316// then we can end up looking through all class types for a complete type and never find
4317// the full definition. We need to know if this attribute is supported, so we determine
4318// this here and cache th result. We also need to worry about the debug map DWARF file
4319// if we are doing darwin DWARF in .o file debugging.
4320bool
4321SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4322{
4323 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4324 {
4325 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4326 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4327 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4328 else
4329 {
4330 DWARFDebugInfo* debug_info = DebugInfo();
4331 const uint32_t num_compile_units = GetNumCompileUnits();
4332 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4333 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004334 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4335 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004336 {
4337 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4338 break;
4339 }
4340 }
4341 }
4342 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4343 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4344 }
4345 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4346}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004347
4348// This function can be used when a DIE is found that is a forward declaration
4349// DIE and we want to try and find a type that has the complete definition.
4350TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004351SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4352 const ConstString &type_name,
4353 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004354{
4355
4356 TypeSP type_sp;
4357
Greg Claytonc7f03b62012-01-12 04:33:28 +00004358 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004359 return type_sp;
4360
4361 DIEArray die_offsets;
4362
4363 if (m_using_apple_tables)
4364 {
4365 if (m_apple_types_ap.get())
4366 {
4367 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004368 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004369 }
4370 }
4371 else
4372 {
4373 if (!m_indexed)
4374 Index ();
4375
4376 m_type_index.Find (type_name, die_offsets);
4377 }
4378
Greg Clayton901c5ca2011-12-03 04:40:03 +00004379 const size_t num_matches = die_offsets.size();
4380
Greg Clayton901c5ca2011-12-03 04:40:03 +00004381 DWARFCompileUnit* type_cu = NULL;
4382 const DWARFDebugInfoEntry* type_die = NULL;
4383 if (num_matches)
4384 {
4385 DWARFDebugInfo* debug_info = DebugInfo();
4386 for (size_t i=0; i<num_matches; ++i)
4387 {
4388 const dw_offset_t die_offset = die_offsets[i];
4389 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4390
4391 if (type_die)
4392 {
4393 bool try_resolving_type = false;
4394
4395 // Don't try and resolve the DIE we are looking for with the DIE itself!
4396 if (type_die != die)
4397 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004398 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004399 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004400 case DW_TAG_class_type:
4401 case DW_TAG_structure_type:
4402 try_resolving_type = true;
4403 break;
4404 default:
4405 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004406 }
4407 }
4408
4409 if (try_resolving_type)
4410 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004411 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004412 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004413
4414 if (try_resolving_type)
4415 {
4416 Type *resolved_type = ResolveType (type_cu, type_die, false);
4417 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4418 {
4419 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4420 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004421 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004422 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4423 MakeUserID(type_die->GetOffset()),
4424 MakeUserID(type_cu->GetOffset()));
4425
Greg Claytonc7f03b62012-01-12 04:33:28 +00004426 if (die)
4427 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004428 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004429 break;
4430 }
4431 }
4432 }
4433 }
4434 else
4435 {
4436 if (m_using_apple_tables)
4437 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004438 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4439 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004440 }
4441 }
4442
4443 }
4444 }
4445 return type_sp;
4446}
4447
Greg Claytona8022fa2012-04-24 21:22:41 +00004448
Greg Clayton80c26302012-02-05 06:12:47 +00004449//----------------------------------------------------------------------
4450// This function helps to ensure that the declaration contexts match for
4451// two different DIEs. Often times debug information will refer to a
4452// forward declaration of a type (the equivalent of "struct my_struct;".
4453// There will often be a declaration of that type elsewhere that has the
4454// full definition. When we go looking for the full type "my_struct", we
4455// will find one or more matches in the accelerator tables and we will
4456// then need to make sure the type was in the same declaration context
4457// as the original DIE. This function can efficiently compare two DIEs
4458// and will return true when the declaration context matches, and false
4459// when they don't.
4460//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004461bool
4462SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4463 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4464{
Greg Claytona8022fa2012-04-24 21:22:41 +00004465 if (die1 == die2)
4466 return true;
4467
4468#if defined (LLDB_CONFIGURATION_DEBUG)
4469 // You can't and shouldn't call this function with a compile unit from
4470 // two different SymbolFileDWARF instances.
4471 assert (DebugInfo()->ContainsCompileUnit (cu1));
4472 assert (DebugInfo()->ContainsCompileUnit (cu2));
4473#endif
4474
Greg Clayton890ff562012-02-02 05:48:16 +00004475 DWARFDIECollection decl_ctx_1;
4476 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004477 //The declaration DIE stack is a stack of the declaration context
4478 // DIEs all the way back to the compile unit. If a type "T" is
4479 // declared inside a class "B", and class "B" is declared inside
4480 // a class "A" and class "A" is in a namespace "lldb", and the
4481 // namespace is in a compile unit, there will be a stack of DIEs:
4482 //
4483 // [0] DW_TAG_class_type for "B"
4484 // [1] DW_TAG_class_type for "A"
4485 // [2] DW_TAG_namespace for "lldb"
4486 // [3] DW_TAG_compile_unit for the source file.
4487 //
4488 // We grab both contexts and make sure that everything matches
4489 // all the way back to the compiler unit.
4490
4491 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004492 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004493 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004494 // Make sure the context arrays have the same size, otherwise
4495 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004496 const size_t count1 = decl_ctx_1.Size();
4497 const size_t count2 = decl_ctx_2.Size();
4498 if (count1 != count2)
4499 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004500
4501 // Make sure the DW_TAG values match all the way back up the the
4502 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004503 const DWARFDebugInfoEntry *decl_ctx_die1;
4504 const DWARFDebugInfoEntry *decl_ctx_die2;
4505 size_t i;
4506 for (i=0; i<count1; i++)
4507 {
4508 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4509 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4510 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4511 return false;
4512 }
Greg Clayton890ff562012-02-02 05:48:16 +00004513#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004514
4515 // Make sure the top item in the decl context die array is always
4516 // DW_TAG_compile_unit. If it isn't then something went wrong in
4517 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004518 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004519
Greg Clayton890ff562012-02-02 05:48:16 +00004520#endif
4521 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004522 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004523 for (i=0; i<count1 - 1; i++)
4524 {
4525 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4526 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4527 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004528 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004529 // If the string was from a DW_FORM_strp, then the pointer will often
4530 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004531 if (name1 == name2)
4532 continue;
4533
4534 // Name pointers are not equal, so only compare the strings
4535 // if both are not NULL.
4536 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004537 {
Greg Clayton5569e642012-02-06 01:44:54 +00004538 // If the strings don't compare, we are done...
4539 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004540 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004541 }
4542 else
4543 {
4544 // One name was NULL while the other wasn't
4545 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004546 }
4547 }
Greg Clayton80c26302012-02-05 06:12:47 +00004548 // We made it through all of the checks and the declaration contexts
4549 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004550 return true;
4551}
Greg Clayton220a0072011-12-09 08:48:30 +00004552
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004553// This function can be used when a DIE is found that is a forward declaration
4554// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004555// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004556TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004557SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004558 const DWARFDebugInfoEntry *die,
4559 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004560{
4561 TypeSP type_sp;
4562
Greg Claytona8022fa2012-04-24 21:22:41 +00004563#if defined (LLDB_CONFIGURATION_DEBUG)
4564 // You can't and shouldn't call this function with a compile unit from
4565 // another SymbolFileDWARF instance.
4566 assert (DebugInfo()->ContainsCompileUnit (cu));
4567#endif
4568
Greg Clayton1a65ae12011-01-25 23:55:37 +00004569 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004570 return type_sp;
4571
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004572 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4573 if (log)
4574 {
4575 std::string qualified_name;
4576 die->GetQualifiedName(this, cu, qualified_name);
4577 GetObjectFile()->GetModule()->LogMessage (log.get(),
4578 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4579 die->GetOffset(),
4580 qualified_name.c_str(),
4581 type_name.GetCString());
4582 }
4583
Greg Clayton7f995132011-10-04 22:41:51 +00004584 DIEArray die_offsets;
4585
Greg Clayton97fbc342011-10-20 22:30:33 +00004586 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004587 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004588 if (m_apple_types_ap.get())
4589 {
Greg Claytond1767f02011-12-08 02:13:16 +00004590 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4591 {
Greg Claytonae920b62012-01-06 00:17:16 +00004592 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004593 }
4594 else
4595 {
4596 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4597 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004598 }
Greg Clayton7f995132011-10-04 22:41:51 +00004599 }
4600 else
4601 {
4602 if (!m_indexed)
4603 Index ();
4604
4605 m_type_index.Find (type_name, die_offsets);
4606 }
Greg Clayton7f995132011-10-04 22:41:51 +00004607
4608 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004609
Greg Clayton934cb052011-12-03 00:27:05 +00004610 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004611
4612 DWARFCompileUnit* type_cu = NULL;
4613 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004614 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004615 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004616 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004617 for (size_t i=0; i<num_matches; ++i)
4618 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004619 const dw_offset_t die_offset = die_offsets[i];
4620 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004621
Greg Clayton95d87902011-11-11 03:16:25 +00004622 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004623 {
Greg Clayton934cb052011-12-03 00:27:05 +00004624 bool try_resolving_type = false;
4625
4626 // Don't try and resolve the DIE we are looking for with the DIE itself!
4627 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004628 {
Greg Clayton934cb052011-12-03 00:27:05 +00004629 const dw_tag_t type_die_tag = type_die->Tag();
4630 // Make sure the tags match
4631 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004632 {
Greg Clayton934cb052011-12-03 00:27:05 +00004633 // The tags match, lets try resolving this type
4634 try_resolving_type = true;
4635 }
4636 else
4637 {
4638 // The tags don't match, but we need to watch our for a
4639 // forward declaration for a struct and ("struct foo")
4640 // ends up being a class ("class foo { ... };") or
4641 // vice versa.
4642 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004643 {
Greg Clayton934cb052011-12-03 00:27:05 +00004644 case DW_TAG_class_type:
4645 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4646 try_resolving_type = (die_tag == DW_TAG_structure_type);
4647 break;
4648 case DW_TAG_structure_type:
4649 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4650 try_resolving_type = (die_tag == DW_TAG_class_type);
4651 break;
4652 default:
4653 // Tags don't match, don't event try to resolve
4654 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004655 break;
4656 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004657 }
4658 }
Greg Clayton934cb052011-12-03 00:27:05 +00004659
4660 if (try_resolving_type)
4661 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004662 if (log)
4663 {
4664 std::string qualified_name;
4665 type_die->GetQualifiedName(this, cu, qualified_name);
4666 GetObjectFile()->GetModule()->LogMessage (log.get(),
4667 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4668 die->GetOffset(),
4669 type_name.GetCString(),
4670 type_die->GetOffset(),
4671 qualified_name.c_str());
4672 }
4673
Greg Clayton890ff562012-02-02 05:48:16 +00004674 // Make sure the decl contexts match all the way up
4675 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004676 {
Greg Clayton890ff562012-02-02 05:48:16 +00004677 Type *resolved_type = ResolveType (type_cu, type_die, false);
4678 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4679 {
4680 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4681 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004682 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004683 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4684 MakeUserID(type_die->GetOffset()),
4685 MakeUserID(type_cu->GetOffset()));
4686
4687 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004688 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004689 break;
4690 }
Greg Clayton934cb052011-12-03 00:27:05 +00004691 }
4692 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004693 else
4694 {
4695 if (log)
4696 {
4697 std::string qualified_name;
4698 type_die->GetQualifiedName(this, cu, qualified_name);
4699 GetObjectFile()->GetModule()->LogMessage (log.get(),
4700 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4701 die->GetOffset(),
4702 type_name.GetCString(),
4703 type_die->GetOffset(),
4704 qualified_name.c_str());
4705 }
4706 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004707 }
Greg Clayton95d87902011-11-11 03:16:25 +00004708 else
4709 {
4710 if (m_using_apple_tables)
4711 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004712 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4713 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004714 }
4715 }
4716
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004717 }
4718 }
4719 return type_sp;
4720}
4721
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004722TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004723SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4724{
4725 TypeSP type_sp;
4726
4727 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4728 if (dwarf_decl_ctx_count > 0)
4729 {
4730 const ConstString type_name(dwarf_decl_ctx[0].name);
4731 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4732
4733 if (type_name)
4734 {
4735 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4736 if (log)
4737 {
4738 GetObjectFile()->GetModule()->LogMessage (log.get(),
4739 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4740 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4741 dwarf_decl_ctx.GetQualifiedName());
4742 }
4743
4744 DIEArray die_offsets;
4745
4746 if (m_using_apple_tables)
4747 {
4748 if (m_apple_types_ap.get())
4749 {
4750 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4751 {
4752 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4753 }
4754 else
4755 {
4756 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4757 }
4758 }
4759 }
4760 else
4761 {
4762 if (!m_indexed)
4763 Index ();
4764
4765 m_type_index.Find (type_name, die_offsets);
4766 }
4767
4768 const size_t num_matches = die_offsets.size();
4769
4770
4771 DWARFCompileUnit* type_cu = NULL;
4772 const DWARFDebugInfoEntry* type_die = NULL;
4773 if (num_matches)
4774 {
4775 DWARFDebugInfo* debug_info = DebugInfo();
4776 for (size_t i=0; i<num_matches; ++i)
4777 {
4778 const dw_offset_t die_offset = die_offsets[i];
4779 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4780
4781 if (type_die)
4782 {
4783 bool try_resolving_type = false;
4784
4785 // Don't try and resolve the DIE we are looking for with the DIE itself!
4786 const dw_tag_t type_tag = type_die->Tag();
4787 // Make sure the tags match
4788 if (type_tag == tag)
4789 {
4790 // The tags match, lets try resolving this type
4791 try_resolving_type = true;
4792 }
4793 else
4794 {
4795 // The tags don't match, but we need to watch our for a
4796 // forward declaration for a struct and ("struct foo")
4797 // ends up being a class ("class foo { ... };") or
4798 // vice versa.
4799 switch (type_tag)
4800 {
4801 case DW_TAG_class_type:
4802 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4803 try_resolving_type = (tag == DW_TAG_structure_type);
4804 break;
4805 case DW_TAG_structure_type:
4806 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4807 try_resolving_type = (tag == DW_TAG_class_type);
4808 break;
4809 default:
4810 // Tags don't match, don't event try to resolve
4811 // using this type whose name matches....
4812 break;
4813 }
4814 }
4815
4816 if (try_resolving_type)
4817 {
4818 DWARFDeclContext type_dwarf_decl_ctx;
4819 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
4820
4821 if (log)
4822 {
4823 GetObjectFile()->GetModule()->LogMessage (log.get(),
4824 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
4825 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4826 dwarf_decl_ctx.GetQualifiedName(),
4827 type_die->GetOffset(),
4828 type_dwarf_decl_ctx.GetQualifiedName());
4829 }
4830
4831 // Make sure the decl contexts match all the way up
4832 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
4833 {
4834 Type *resolved_type = ResolveType (type_cu, type_die, false);
4835 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4836 {
4837 type_sp = resolved_type->shared_from_this();
4838 break;
4839 }
4840 }
4841 }
4842 else
4843 {
4844 if (log)
4845 {
4846 std::string qualified_name;
4847 type_die->GetQualifiedName(this, type_cu, qualified_name);
4848 GetObjectFile()->GetModule()->LogMessage (log.get(),
4849 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
4850 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4851 dwarf_decl_ctx.GetQualifiedName(),
4852 type_die->GetOffset(),
4853 qualified_name.c_str());
4854 }
4855 }
4856 }
4857 else
4858 {
4859 if (m_using_apple_tables)
4860 {
4861 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4862 die_offset, type_name.GetCString());
4863 }
4864 }
4865
4866 }
4867 }
4868 }
4869 }
4870 return type_sp;
4871}
4872
Greg Clayton4116e932012-05-15 02:33:01 +00004873bool
4874SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type,
4875 DWARFCompileUnit* src_cu,
4876 const DWARFDebugInfoEntry *src_class_die,
4877 DWARFCompileUnit* dst_cu,
4878 const DWARFDebugInfoEntry *dst_class_die)
4879{
4880 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
4881 return false;
4882 if (src_class_die->Tag() != dst_class_die->Tag())
4883 return false;
4884
4885 // We need to complete the class type so we can get all of the method types
4886 // parsed so we can then unique those types to their equivalent counterparts
4887 // in "dst_cu" and "dst_class_die"
4888 class_type->GetClangFullType();
4889
4890 const DWARFDebugInfoEntry *src_die;
4891 const DWARFDebugInfoEntry *dst_die;
4892 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
4893 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
4894 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
4895 {
4896 if (src_die->Tag() == DW_TAG_subprogram)
4897 {
4898 const char *src_name = src_die->GetMangledName (this, src_cu);
4899 if (src_name)
4900 src_name_to_die.Append(ConstString(src_name).GetCString(), src_die);
4901 }
4902 }
4903 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
4904 {
4905 if (dst_die->Tag() == DW_TAG_subprogram)
4906 {
4907 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4908 if (dst_name)
4909 dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die);
4910 }
4911 }
4912 const uint32_t src_size = src_name_to_die.GetSize ();
4913 const uint32_t dst_size = dst_name_to_die.GetSize ();
4914 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
4915
4916 if (src_size && dst_size)
4917 {
Sean Callanan210b8152012-07-07 00:29:33 +00004918 if (src_size != dst_size)
4919 {
4920 if (log)
4921 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)",
4922 src_class_die->GetOffset(),
4923 dst_class_die->GetOffset(),
4924 src_size,
4925 dst_size);
4926
4927 return false;
4928 }
4929
Greg Clayton4116e932012-05-15 02:33:01 +00004930 uint32_t idx;
4931 for (idx = 0; idx < src_size; ++idx)
4932 {
4933 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4934 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4935
4936 if (src_die->Tag() != dst_die->Tag())
4937 {
4938 if (log)
4939 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)",
4940 src_class_die->GetOffset(),
4941 dst_class_die->GetOffset(),
4942 src_die->GetOffset(),
4943 DW_TAG_value_to_name(src_die->Tag()),
4944 dst_die->GetOffset(),
4945 DW_TAG_value_to_name(src_die->Tag()));
4946 return false;
4947 }
4948
4949 const char *src_name = src_die->GetMangledName (this, src_cu);
4950 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4951
4952 // Make sure the names match
4953 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
4954 continue;
4955
4956 if (log)
4957 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)",
4958 src_class_die->GetOffset(),
4959 dst_class_die->GetOffset(),
4960 src_die->GetOffset(),
4961 src_name,
4962 dst_die->GetOffset(),
4963 dst_name);
4964
4965 return false;
4966 }
4967
4968 for (idx = 0; idx < src_size; ++idx)
4969 {
4970 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4971 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4972
4973 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
4974 if (src_decl_ctx)
4975 {
4976 if (log)
4977 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
4978 LinkDeclContextToDIE (src_decl_ctx, dst_die);
4979 }
4980 else
4981 {
4982 if (log)
4983 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());
4984 }
4985
4986 Type *src_child_type = m_die_to_type[src_die];
4987 if (src_child_type)
4988 {
4989 if (log)
4990 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());
4991 m_die_to_type[dst_die] = src_child_type;
4992 }
4993 else
4994 {
4995 if (log)
4996 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());
4997 }
4998 }
4999 return true;
5000 }
5001 else
5002 {
5003 if (log)
5004 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",
5005 src_class_die->GetOffset(),
5006 dst_class_die->GetOffset(),
5007 src_die->GetOffset(),
5008 src_size,
5009 dst_die->GetOffset(),
5010 dst_size);
5011 }
5012 return false;
5013}
Greg Claytona8022fa2012-04-24 21:22:41 +00005014
5015TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005016SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005017{
5018 TypeSP type_sp;
5019
Greg Clayton1be10fc2010-09-29 01:12:09 +00005020 if (type_is_new_ptr)
5021 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005022
5023#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5024 static DIEStack g_die_stack;
5025 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5026#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005027
Sean Callananc7fbf732010-08-06 00:32:49 +00005028 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005029 if (die != NULL)
5030 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005031 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005032 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005033 {
5034 const DWARFDebugInfoEntry *context_die;
5035 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5036
Greg Clayton1fba87112012-02-09 20:03:49 +00005037 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 +00005038 die->GetOffset(),
5039 context,
5040 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005041 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005042 die->GetName(this, dwarf_cu));
5043
5044#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5045 scoped_die_logger.Push (dwarf_cu, die);
5046 g_die_stack.LogDIEs(log.get(), this);
5047#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005048 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005049//
5050// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5051// if (log && dwarf_cu)
5052// {
5053// StreamString s;
5054// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005055// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005056//
5057// }
Jim Ingham16746d12011-08-25 23:21:43 +00005058
Greg Clayton594e5ed2010-09-27 21:07:38 +00005059 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005060 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005061 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005062 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005063 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005064 if (type_is_new_ptr)
5065 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005066
Greg Clayton594e5ed2010-09-27 21:07:38 +00005067 const dw_tag_t tag = die->Tag();
5068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005069 bool is_forward_declaration = false;
5070 DWARFDebugInfoEntry::Attributes attributes;
5071 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005072 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005073 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5074 size_t byte_size = 0;
5075 Declaration decl;
5076
Greg Clayton4957bf62010-09-30 21:49:03 +00005077 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005078 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005079
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005080 dw_attr_t attr;
5081
5082 switch (tag)
5083 {
5084 case DW_TAG_base_type:
5085 case DW_TAG_pointer_type:
5086 case DW_TAG_reference_type:
Sean Callanance8af862012-05-21 23:31:51 +00005087 case DW_TAG_rvalue_reference_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005088 case DW_TAG_typedef:
5089 case DW_TAG_const_type:
5090 case DW_TAG_restrict_type:
5091 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005092 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005093 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005094 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005095 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005096
Greg Claytond88d7592010-09-15 08:33:30 +00005097 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005098 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005099 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5100
5101 if (num_attributes > 0)
5102 {
5103 uint32_t i;
5104 for (i=0; i<num_attributes; ++i)
5105 {
5106 attr = attributes.AttributeAtIndex(i);
5107 DWARFFormValue form_value;
5108 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5109 {
5110 switch (attr)
5111 {
5112 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5113 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5114 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5115 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005116
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005117 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005118 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5119 // include the "&"...
5120 if (tag == DW_TAG_reference_type)
5121 {
5122 if (strchr (type_name_cstr, '&') == NULL)
5123 type_name_cstr = NULL;
5124 }
5125 if (type_name_cstr)
5126 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005127 break;
Greg Clayton23f59502012-07-17 03:23:13 +00005128 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005129 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5130 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5131 default:
5132 case DW_AT_sibling:
5133 break;
5134 }
5135 }
5136 }
5137 }
5138
Greg Clayton81c22f62011-10-19 18:09:39 +00005139 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 +00005140
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005141 switch (tag)
5142 {
5143 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005144 break;
5145
Greg Claytond4436412011-10-28 21:00:00 +00005146 case DW_TAG_unspecified_type:
5147 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5148 {
5149 resolve_state = Type::eResolveStateFull;
5150 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5151 break;
5152 }
5153 // Fall through to base type below in case we can handle the type there...
5154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005155 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005156 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005157 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5158 encoding,
5159 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005160 break;
5161
Sean Callanance8af862012-05-21 23:31:51 +00005162 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5163 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5164 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5165 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5166 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5167 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5168 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005169 }
5170
Greg Claytonc7f03b62012-01-12 04:33:28 +00005171 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005172 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005173 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
5174 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005175 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005176 static ConstString g_objc_type_name_id("id");
5177 static ConstString g_objc_type_name_Class("Class");
5178 static ConstString g_objc_type_name_selector("SEL");
5179
5180 if (type_name_const_str == g_objc_type_name_id)
5181 {
5182 if (log)
5183 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5184 die->GetOffset(),
5185 DW_TAG_value_to_name(die->Tag()),
5186 die->GetName(this, dwarf_cu));
5187 clang_type = ast.GetBuiltInType_objc_id();
5188 encoding_data_type = Type::eEncodingIsUID;
5189 encoding_uid = LLDB_INVALID_UID;
5190 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005191
Greg Claytonc7f03b62012-01-12 04:33:28 +00005192 }
5193 else if (type_name_const_str == g_objc_type_name_Class)
5194 {
5195 if (log)
5196 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5197 die->GetOffset(),
5198 DW_TAG_value_to_name(die->Tag()),
5199 die->GetName(this, dwarf_cu));
5200 clang_type = ast.GetBuiltInType_objc_Class();
5201 encoding_data_type = Type::eEncodingIsUID;
5202 encoding_uid = LLDB_INVALID_UID;
5203 resolve_state = Type::eResolveStateFull;
5204 }
5205 else if (type_name_const_str == g_objc_type_name_selector)
5206 {
5207 if (log)
5208 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5209 die->GetOffset(),
5210 DW_TAG_value_to_name(die->Tag()),
5211 die->GetName(this, dwarf_cu));
5212 clang_type = ast.GetBuiltInType_objc_selector();
5213 encoding_data_type = Type::eEncodingIsUID;
5214 encoding_uid = LLDB_INVALID_UID;
5215 resolve_state = Type::eResolveStateFull;
5216 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005217 }
5218 }
5219
Greg Clayton81c22f62011-10-19 18:09:39 +00005220 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005221 this,
5222 type_name_const_str,
5223 byte_size,
5224 NULL,
5225 encoding_uid,
5226 encoding_data_type,
5227 &decl,
5228 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005229 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005230
Greg Clayton594e5ed2010-09-27 21:07:38 +00005231 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005232
5233// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5234// if (encoding_type != NULL)
5235// {
5236// if (encoding_type != DIE_IS_BEING_PARSED)
5237// type_sp->SetEncodingType(encoding_type);
5238// else
5239// m_indirect_fixups.push_back(type_sp.get());
5240// }
5241 }
5242 break;
5243
5244 case DW_TAG_structure_type:
5245 case DW_TAG_union_type:
5246 case DW_TAG_class_type:
5247 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005248 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005249 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Greg Clayton23f59502012-07-17 03:23:13 +00005250 bool byte_size_valid = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005251
Greg Clayton9e409562010-07-28 02:04:09 +00005252 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005253 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005254 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005255 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005256 if (num_attributes > 0)
5257 {
5258 uint32_t i;
5259 for (i=0; i<num_attributes; ++i)
5260 {
5261 attr = attributes.AttributeAtIndex(i);
5262 DWARFFormValue form_value;
5263 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5264 {
5265 switch (attr)
5266 {
Greg Clayton9e409562010-07-28 02:04:09 +00005267 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005268 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5269 {
5270 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5271 // point to the compile unit file, so we clear this invalid value
5272 // so that we can still unique types efficiently.
5273 decl.SetFile(FileSpec ("<invalid>", false));
5274 }
5275 else
5276 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005277 break;
5278
5279 case DW_AT_decl_line:
5280 decl.SetLine(form_value.Unsigned());
5281 break;
5282
5283 case DW_AT_decl_column:
5284 decl.SetColumn(form_value.Unsigned());
5285 break;
5286
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005287 case DW_AT_name:
5288 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005289 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005290 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005291
5292 case DW_AT_byte_size:
5293 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005294 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005295 break;
5296
5297 case DW_AT_accessibility:
5298 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5299 break;
5300
5301 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005302 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005303 break;
5304
5305 case DW_AT_APPLE_runtime_class:
5306 class_language = (LanguageType)form_value.Signed();
5307 break;
5308
Greg Clayton18774842011-11-29 23:40:34 +00005309 case DW_AT_APPLE_objc_complete_type:
5310 is_complete_objc_class = form_value.Signed();
5311 break;
5312
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005313 case DW_AT_allocated:
5314 case DW_AT_associated:
5315 case DW_AT_data_location:
5316 case DW_AT_description:
5317 case DW_AT_start_scope:
5318 case DW_AT_visibility:
5319 default:
5320 case DW_AT_sibling:
5321 break;
5322 }
5323 }
5324 }
5325 }
5326
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005327 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005328
Greg Clayton123edca2012-03-02 00:07:15 +00005329 // Only try and unique the type if it has a name.
5330 if (type_name_const_str &&
5331 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005332 this,
5333 dwarf_cu,
5334 die,
5335 decl,
5336 byte_size_valid ? byte_size : -1,
5337 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005338 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005339 // We have already parsed this type or from another
5340 // compile unit. GCC loves to use the "one definition
5341 // rule" which can result in multiple definitions
5342 // of the same class over and over in each compile
5343 // unit.
5344 type_sp = unique_ast_entry.m_type_sp;
5345 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005346 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005347 m_die_to_type[die] = type_sp.get();
5348 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005349 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005350 }
5351
Greg Clayton81c22f62011-10-19 18:09:39 +00005352 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 +00005353
5354 int tag_decl_kind = -1;
5355 AccessType default_accessibility = eAccessNone;
5356 if (tag == DW_TAG_structure_type)
5357 {
5358 tag_decl_kind = clang::TTK_Struct;
5359 default_accessibility = eAccessPublic;
5360 }
5361 else if (tag == DW_TAG_union_type)
5362 {
5363 tag_decl_kind = clang::TTK_Union;
5364 default_accessibility = eAccessPublic;
5365 }
5366 else if (tag == DW_TAG_class_type)
5367 {
5368 tag_decl_kind = clang::TTK_Class;
5369 default_accessibility = eAccessPrivate;
5370 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005371
5372 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5373 die->HasChildren() == false &&
5374 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5375 {
5376 // Work around an issue with clang at the moment where
5377 // forward declarations for objective C classes are emitted
5378 // as:
5379 // DW_TAG_structure_type [2]
5380 // DW_AT_name( "ForwardObjcClass" )
5381 // DW_AT_byte_size( 0x00 )
5382 // DW_AT_decl_file( "..." )
5383 // DW_AT_decl_line( 1 )
5384 //
5385 // Note that there is no DW_AT_declaration and there are
5386 // no children, and the byte size is zero.
5387 is_forward_declaration = true;
5388 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005389
Sean Callanan7457f8d2012-04-25 01:03:57 +00005390 if (class_language == eLanguageTypeObjC ||
5391 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005392 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005393 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005394 {
5395 // We have a valid eSymbolTypeObjCClass class symbol whose
5396 // name matches the current objective C class that we
5397 // are trying to find and this DIE isn't the complete
5398 // definition (we checked is_complete_objc_class above and
5399 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005400 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005401
Greg Clayton901c5ca2011-12-03 04:40:03 +00005402 if (!type_sp && m_debug_map_symfile)
5403 {
5404 // We weren't able to find a full declaration in
5405 // this DWARF, see if we have a declaration anywhere
5406 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005407 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005408 }
5409
5410 if (type_sp)
5411 {
5412 if (log)
5413 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005414 GetObjectFile()->GetModule()->LogMessage (log.get(),
5415 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
5416 this,
5417 die->GetOffset(),
5418 DW_TAG_value_to_name(tag),
5419 type_name_cstr,
5420 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005421 }
5422
5423 // We found a real definition for this type elsewhere
5424 // so lets use it and cache the fact that we found
5425 // a complete type for this die
5426 m_die_to_type[die] = type_sp.get();
5427 return type_sp;
5428 }
5429 }
5430 }
5431
5432
5433 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005434 {
5435 // We have a forward declaration to a type and we need
5436 // to try and find a full declaration. We look in the
5437 // current type index just in case we have a forward
5438 // declaration followed by an actual declarations in the
5439 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005440 if (log)
5441 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005442 GetObjectFile()->GetModule()->LogMessage (log.get(),
5443 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5444 this,
5445 die->GetOffset(),
5446 DW_TAG_value_to_name(tag),
5447 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005448 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005449
Greg Claytona8022fa2012-04-24 21:22:41 +00005450 DWARFDeclContext die_decl_ctx;
5451 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5452
5453 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5454 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005455
5456 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00005457 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005458 // We weren't able to find a full declaration in
5459 // this DWARF, see if we have a declaration anywhere
5460 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005461 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005462 }
5463
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005464 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005465 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005466 if (log)
5467 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005468 GetObjectFile()->GetModule()->LogMessage (log.get(),
5469 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5470 this,
5471 die->GetOffset(),
5472 DW_TAG_value_to_name(tag),
5473 type_name_cstr,
5474 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005475 }
5476
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005477 // We found a real definition for this type elsewhere
5478 // so lets use it and cache the fact that we found
5479 // a complete type for this die
5480 m_die_to_type[die] = type_sp.get();
5481 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005482 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005483 }
5484 assert (tag_decl_kind != -1);
5485 bool clang_type_was_created = false;
5486 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5487 if (clang_type == NULL)
5488 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005489 const DWARFDebugInfoEntry *decl_ctx_die;
5490
5491 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005492 if (accessibility == eAccessNone && decl_ctx)
5493 {
5494 // Check the decl context that contains this class/struct/union.
5495 // If it is a class we must give it an accessability.
5496 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5497 if (DeclKindIsCXXClass (containing_decl_kind))
5498 accessibility = default_accessibility;
5499 }
5500
Greg Claytonf0705c82011-10-22 03:33:13 +00005501 if (type_name_cstr && strchr (type_name_cstr, '<'))
5502 {
5503 ClangASTContext::TemplateParameterInfos template_param_infos;
5504 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5505 {
5506 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005507 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005508 type_name_cstr,
5509 tag_decl_kind,
5510 template_param_infos);
5511
5512 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5513 class_template_decl,
5514 tag_decl_kind,
5515 template_param_infos);
5516 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5517 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005518
5519 GetClangASTContext().SetMetadata((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
5520 GetClangASTContext().SetMetadata((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005521 }
5522 }
5523
5524 if (!clang_type_was_created)
5525 {
5526 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005527 clang_type = ast.CreateRecordType (decl_ctx,
5528 accessibility,
5529 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005530 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005531 class_language,
Sean Callananad880762012-04-18 01:06:17 +00005532 MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005533 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005534 }
5535
5536 // Store a forward declaration to this class type in case any
5537 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005538 // types for function prototypes.
5539 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005540 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005541 this,
5542 type_name_const_str,
5543 byte_size,
5544 NULL,
5545 LLDB_INVALID_UID,
5546 Type::eEncodingIsUID,
5547 &decl,
5548 clang_type,
5549 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005550
5551 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005552
5553
5554 // Add our type to the unique type map so we don't
5555 // end up creating many copies of the same type over
5556 // and over in the ASTContext for our module
5557 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005558 unique_ast_entry.m_symfile = this;
5559 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005560 unique_ast_entry.m_die = die;
5561 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005562 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005563 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5564 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005565
Sean Callanan12014a02011-12-08 23:45:45 +00005566 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005567 {
5568 // Always start the definition for a class type so that
5569 // if the class has child classes or types that require
5570 // the class to be created for use as their decl contexts
5571 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005572 if (die->HasChildren() == false)
5573 {
5574 // No children for this struct/union/class, lets finish it
5575 ast.StartTagDeclarationDefinition (clang_type);
5576 ast.CompleteTagDeclarationDefinition (clang_type);
5577 }
5578 else if (clang_type_was_created)
5579 {
Greg Clayton219cf312012-03-30 00:51:13 +00005580 // Start the definition if the class is not objective C since
5581 // the underlying decls respond to isCompleteDefinition(). Objective
5582 // C decls dont' respond to isCompleteDefinition() so we can't
5583 // start the declaration definition right away. For C++ classs/union/structs
5584 // we want to start the definition in case the class is needed as the
5585 // declaration context for a contained class or type without the need
5586 // to complete that type..
5587
Sean Callanan7457f8d2012-04-25 01:03:57 +00005588 if (class_language != eLanguageTypeObjC &&
5589 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00005590 ast.StartTagDeclarationDefinition (clang_type);
5591
Sean Callanan12014a02011-12-08 23:45:45 +00005592 // Leave this as a forward declaration until we need
5593 // to know the details of the type. lldb_private::Type
5594 // will automatically call the SymbolFile virtual function
5595 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5596 // When the definition needs to be defined.
5597 m_forward_decl_die_to_clang_type[die] = clang_type;
5598 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5599 ClangASTContext::SetHasExternalStorage (clang_type, true);
5600 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005601 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005602
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005603 }
5604 break;
5605
5606 case DW_TAG_enumeration_type:
5607 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005608 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005609 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005611 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005612
Greg Claytond88d7592010-09-15 08:33:30 +00005613 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005614 if (num_attributes > 0)
5615 {
5616 uint32_t i;
5617
5618 for (i=0; i<num_attributes; ++i)
5619 {
5620 attr = attributes.AttributeAtIndex(i);
5621 DWARFFormValue form_value;
5622 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5623 {
5624 switch (attr)
5625 {
Greg Clayton7a345282010-11-09 23:46:37 +00005626 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5627 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5628 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005629 case DW_AT_name:
5630 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005631 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005632 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005633 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00005634 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
5635 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5636 case DW_AT_declaration: break; //is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005637 case DW_AT_allocated:
5638 case DW_AT_associated:
5639 case DW_AT_bit_stride:
5640 case DW_AT_byte_stride:
5641 case DW_AT_data_location:
5642 case DW_AT_description:
5643 case DW_AT_start_scope:
5644 case DW_AT_visibility:
5645 case DW_AT_specification:
5646 case DW_AT_abstract_origin:
5647 case DW_AT_sibling:
5648 break;
5649 }
5650 }
5651 }
5652
Greg Clayton81c22f62011-10-19 18:09:39 +00005653 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 +00005654
Greg Clayton1be10fc2010-09-29 01:12:09 +00005655 clang_type_t enumerator_clang_type = NULL;
5656 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5657 if (clang_type == NULL)
5658 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005659 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5660 DW_ATE_signed,
5661 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005662 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005663 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005664 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005665 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005666 }
5667 else
5668 {
5669 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5670 assert (enumerator_clang_type != NULL);
5671 }
5672
Greg Claytona2721472011-06-25 00:44:06 +00005673 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5674
Greg Clayton81c22f62011-10-19 18:09:39 +00005675 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005676 this,
5677 type_name_const_str,
5678 byte_size,
5679 NULL,
5680 encoding_uid,
5681 Type::eEncodingIsUID,
5682 &decl,
5683 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005684 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005685
Greg Clayton6beaaa62011-01-17 03:46:26 +00005686 ast.StartTagDeclarationDefinition (clang_type);
5687 if (die->HasChildren())
5688 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005689 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5690 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005691 }
5692 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005693 }
5694 }
5695 break;
5696
Jim Inghamb0be4422010-08-12 01:20:14 +00005697 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005698 case DW_TAG_subprogram:
5699 case DW_TAG_subroutine_type:
5700 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005701 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005702 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005703
Greg Clayton23f59502012-07-17 03:23:13 +00005704 //const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005705 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005706 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005707 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005708 bool is_static = false;
5709 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005710 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005711 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005712 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5713 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005715 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005716 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005717
5718
Greg Claytond88d7592010-09-15 08:33:30 +00005719 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005720 if (num_attributes > 0)
5721 {
5722 uint32_t i;
5723 for (i=0; i<num_attributes; ++i)
5724 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005725 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005726 DWARFFormValue form_value;
5727 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5728 {
5729 switch (attr)
5730 {
5731 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5732 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5733 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5734 case DW_AT_name:
5735 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005736 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005737 break;
5738
Greg Clayton23f59502012-07-17 03:23:13 +00005739 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005741 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton23f59502012-07-17 03:23:13 +00005742 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005743 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5744 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005745 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005746 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5747
Greg Claytonf51de672010-10-01 02:31:07 +00005748
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005749 case DW_AT_external:
5750 if (form_value.Unsigned())
5751 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005752 if (storage == clang::SC_None)
5753 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005754 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005755 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005756 }
5757 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005758
Greg Clayton72da3972011-08-16 18:40:23 +00005759 case DW_AT_specification:
5760 specification_die_offset = form_value.Reference(dwarf_cu);
5761 break;
5762
5763 case DW_AT_abstract_origin:
5764 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5765 break;
5766
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005767 case DW_AT_allocated:
5768 case DW_AT_associated:
5769 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005770 case DW_AT_calling_convention:
5771 case DW_AT_data_location:
5772 case DW_AT_elemental:
5773 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005774 case DW_AT_frame_base:
5775 case DW_AT_high_pc:
5776 case DW_AT_low_pc:
5777 case DW_AT_object_pointer:
5778 case DW_AT_prototyped:
5779 case DW_AT_pure:
5780 case DW_AT_ranges:
5781 case DW_AT_recursive:
5782 case DW_AT_return_addr:
5783 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005784 case DW_AT_start_scope:
5785 case DW_AT_static_link:
5786 case DW_AT_trampoline:
5787 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005788 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005789 case DW_AT_description:
5790 case DW_AT_sibling:
5791 break;
5792 }
5793 }
5794 }
Greg Clayton24739922010-10-13 03:15:28 +00005795 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005796
Greg Clayton81c22f62011-10-19 18:09:39 +00005797 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 +00005798
Greg Clayton24739922010-10-13 03:15:28 +00005799 clang_type_t return_clang_type = NULL;
5800 Type *func_type = NULL;
5801
5802 if (type_die_offset != DW_INVALID_OFFSET)
5803 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005804
Greg Clayton24739922010-10-13 03:15:28 +00005805 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005806 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005807 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005808 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005809
Greg Claytonf51de672010-10-01 02:31:07 +00005810
Greg Clayton24739922010-10-13 03:15:28 +00005811 std::vector<clang_type_t> function_param_types;
5812 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005813
Greg Clayton24739922010-10-13 03:15:28 +00005814 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005815
Greg Claytoncb5860a2011-10-13 23:49:28 +00005816 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5817 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005818 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5819
Greg Claytonf0705c82011-10-22 03:33:13 +00005820 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005821 // Start off static. This will be set to false in ParseChildParameters(...)
5822 // if we find a "this" paramters as the first parameter
5823 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005824 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005825 ClangASTContext::TemplateParameterInfos template_param_infos;
5826
Greg Clayton24739922010-10-13 03:15:28 +00005827 if (die->HasChildren())
5828 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005829 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005830 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005831 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005832 dwarf_cu,
5833 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005834 skip_artificial,
5835 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005836 type_list,
5837 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005838 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005839 type_quals,
5840 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005841 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005842
Greg Clayton24739922010-10-13 03:15:28 +00005843 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005844 clang_type = ast.CreateFunctionType (return_clang_type,
5845 &function_param_types[0],
5846 function_param_types.size(),
5847 is_variadic,
5848 type_quals);
5849
Greg Clayton24739922010-10-13 03:15:28 +00005850 if (type_name_cstr)
5851 {
5852 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005853 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005854 {
Greg Clayton7c810422012-01-18 23:40:49 +00005855 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005856 ConstString class_name_no_category;
5857 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005858 {
Greg Claytone42ae842012-01-19 03:24:53 +00005859 // Use the class name with no category if there is one
5860 if (class_name_no_category)
5861 class_name = class_name_no_category;
5862
Greg Clayton24739922010-10-13 03:15:28 +00005863 SymbolContext empty_sc;
5864 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005865 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005866 {
Greg Clayton24739922010-10-13 03:15:28 +00005867 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005868 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005869
5870 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005871 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005872 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5873 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5874 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005875 }
Greg Clayton24739922010-10-13 03:15:28 +00005876 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005877
Greg Clayton24739922010-10-13 03:15:28 +00005878 if (class_opaque_type)
5879 {
5880 // If accessibility isn't set to anything valid, assume public for
5881 // now...
5882 if (accessibility == eAccessNone)
5883 accessibility = eAccessPublic;
5884
5885 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005886 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5887 type_name_cstr,
5888 clang_type,
5889 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005890 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005891 type_handled = objc_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00005892 GetClangASTContext().SetMetadata((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00005893 }
5894 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005895 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005896 {
5897 // Look at the parent of this DIE and see if is is
5898 // a class or struct and see if this is actually a
5899 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005900 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005901 if (class_type)
5902 {
Greg Clayton4116e932012-05-15 02:33:01 +00005903 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
5904 {
5905 // We uniqued the parent class of this function to another class
5906 // so we now need to associate all dies under "decl_ctx_die" to
5907 // DIEs in the DIE for "class_type"...
5908 DWARFCompileUnitSP class_type_cu_sp;
5909 const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
5910 if (class_type_die)
5911 {
5912 if (CopyUniqueClassMethodTypes (class_type,
5913 class_type_cu_sp.get(),
5914 class_type_die,
5915 dwarf_cu,
5916 decl_ctx_die))
5917 {
5918 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00005919 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton4116e932012-05-15 02:33:01 +00005920 {
5921 type_sp = type_ptr->shared_from_this();
5922 break;
5923 }
5924 }
5925 }
5926 }
5927
Greg Clayton72da3972011-08-16 18:40:23 +00005928 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005929 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005930 // We have a specification which we are going to base our function
5931 // prototype off of, so we need this type to be completed so that the
5932 // m_die_to_decl_ctx for the method in the specification has a valid
5933 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005934 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005935 // If we have a specification, then the function type should have been
5936 // made with the specification and not with this die.
5937 DWARFCompileUnitSP spec_cu_sp;
5938 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005939 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005940 if (spec_clang_decl_ctx)
5941 {
5942 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5943 }
5944 else
Jim Inghamc1663042011-09-29 22:12:35 +00005945 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005946 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5947 MakeUserID(die->GetOffset()),
5948 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005949 }
Greg Clayton72da3972011-08-16 18:40:23 +00005950 type_handled = true;
5951 }
5952 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5953 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005954 // We have a specification which we are going to base our function
5955 // prototype off of, so we need this type to be completed so that the
5956 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5957 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005958 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005959
Greg Clayton72da3972011-08-16 18:40:23 +00005960 DWARFCompileUnitSP abs_cu_sp;
5961 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005962 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005963 if (abs_clang_decl_ctx)
5964 {
5965 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5966 }
5967 else
Jim Inghamc1663042011-09-29 22:12:35 +00005968 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005969 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5970 MakeUserID(die->GetOffset()),
5971 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005972 }
Greg Clayton72da3972011-08-16 18:40:23 +00005973 type_handled = true;
5974 }
5975 else
5976 {
5977 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5978 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005979 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005980 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005981 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005982 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5983 // in the DWARF for C++ methods... Default to public for now...
5984 if (accessibility == eAccessNone)
5985 accessibility = eAccessPublic;
5986
5987 if (!is_static && !die->HasChildren())
5988 {
5989 // We have a C++ member function with no children (this pointer!)
5990 // and clang will get mad if we try and make a function that isn't
5991 // well formed in the DWARF, so we will just skip it...
5992 type_handled = true;
5993 }
5994 else
5995 {
5996 clang::CXXMethodDecl *cxx_method_decl;
5997 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005998 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 +00005999 type_name_cstr,
6000 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00006001 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00006002 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
6003 m_obj_file->GetFileSpec().GetFilename().GetCString());
6004
Sean Callananc1b732d2011-11-01 18:07:13 +00006005 const bool is_attr_used = false;
6006
Greg Clayton20568dd2011-10-13 23:13:20 +00006007 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
6008 type_name_cstr,
6009 clang_type,
6010 accessibility,
6011 is_virtual,
6012 is_static,
6013 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00006014 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00006015 is_attr_used,
6016 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00006017 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6018
Greg Claytonf49e65a2011-11-10 18:31:53 +00006019 Host::SetCrashDescription (NULL);
6020
Greg Clayton20568dd2011-10-13 23:13:20 +00006021 type_handled = cxx_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00006022
6023 GetClangASTContext().SetMetadata((uintptr_t)cxx_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton20568dd2011-10-13 23:13:20 +00006024 }
Greg Clayton72da3972011-08-16 18:40:23 +00006025 }
6026 else
6027 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006028 // We were asked to parse the type for a method in a class, yet the
6029 // class hasn't been asked to complete itself through the
6030 // clang::ExternalASTSource protocol, so we need to just have the
6031 // class complete itself and do things the right way, then our
6032 // DIE should then have an entry in the m_die_to_type map. First
6033 // we need to modify the m_die_to_type so it doesn't think we are
6034 // trying to parse this DIE anymore...
6035 m_die_to_type[die] = NULL;
6036
6037 // Now we get the full type to force our class type to complete itself
6038 // using the clang::ExternalASTSource protocol which will parse all
6039 // base classes and all methods (including the method for this DIE).
6040 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006041
Greg Clayton20568dd2011-10-13 23:13:20 +00006042 // The type for this DIE should have been filled in the function call above
6043 type_ptr = m_die_to_type[die];
Greg Claytone5476db2012-06-01 20:32:35 +00006044 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
Greg Clayton20568dd2011-10-13 23:13:20 +00006045 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006046 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006047 break;
6048 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006049
6050 // FIXME This is fixing some even uglier behavior but we really need to
6051 // uniq the methods of each class as well as the class itself.
6052 // <rdar://problem/11240464>
6053 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006054 }
Greg Clayton931180e2011-01-27 06:44:37 +00006055 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006056 }
6057 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006058 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006059 }
Greg Clayton24739922010-10-13 03:15:28 +00006060
6061 if (!type_handled)
6062 {
6063 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006064 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6065 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006066 clang_type,
6067 storage,
6068 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006069
6070// if (template_param_infos.GetSize() > 0)
6071// {
6072// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6073// function_decl,
6074// type_name_cstr,
6075// template_param_infos);
6076//
6077// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6078// func_template_decl,
6079// template_param_infos);
6080// }
Greg Clayton24739922010-10-13 03:15:28 +00006081 // Add the decl to our DIE to decl context map
6082 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006083 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006084 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006085 ast.SetFunctionParameters (function_decl,
6086 &function_param_decls.front(),
6087 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006088
6089 GetClangASTContext().SetMetadata((uintptr_t)function_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00006090 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006091 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006092 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006093 this,
6094 type_name_const_str,
6095 0,
6096 NULL,
6097 LLDB_INVALID_UID,
6098 Type::eEncodingIsUID,
6099 &decl,
6100 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006101 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006102 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006103 }
6104 break;
6105
6106 case DW_TAG_array_type:
6107 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006108 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006109 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006110
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006111 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006112 int64_t first_index = 0;
6113 uint32_t byte_stride = 0;
6114 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006115 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006116
6117 if (num_attributes > 0)
6118 {
6119 uint32_t i;
6120 for (i=0; i<num_attributes; ++i)
6121 {
6122 attr = attributes.AttributeAtIndex(i);
6123 DWARFFormValue form_value;
6124 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6125 {
6126 switch (attr)
6127 {
6128 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6129 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6130 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6131 case DW_AT_name:
6132 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006133 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006134 break;
6135
6136 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006137 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006138 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6139 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00006140 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6141 case DW_AT_declaration: break; // is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006142 case DW_AT_allocated:
6143 case DW_AT_associated:
6144 case DW_AT_data_location:
6145 case DW_AT_description:
6146 case DW_AT_ordering:
6147 case DW_AT_start_scope:
6148 case DW_AT_visibility:
6149 case DW_AT_specification:
6150 case DW_AT_abstract_origin:
6151 case DW_AT_sibling:
6152 break;
6153 }
6154 }
6155 }
6156
Greg Clayton81c22f62011-10-19 18:09:39 +00006157 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 +00006158
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006159 Type *element_type = ResolveTypeUID(type_die_offset);
6160
6161 if (element_type)
6162 {
6163 std::vector<uint64_t> element_orders;
6164 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00006165 // We have an array that claims to have no members, lets give it at least one member...
6166 if (element_orders.empty())
6167 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006168 if (byte_stride == 0 && bit_stride == 0)
6169 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006170 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006171 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6172 uint64_t num_elements = 0;
6173 std::vector<uint64_t>::const_reverse_iterator pos;
6174 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6175 for (pos = element_orders.rbegin(); pos != end; ++pos)
6176 {
6177 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006178 clang_type = ast.CreateArrayType (array_element_type,
6179 num_elements,
6180 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006181 array_element_type = clang_type;
6182 array_element_bit_stride = array_element_bit_stride * num_elements;
6183 }
6184 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006185 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006186 this,
6187 empty_name,
6188 array_element_bit_stride / 8,
6189 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006190 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006191 Type::eEncodingIsUID,
6192 &decl,
6193 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006194 Type::eResolveStateFull));
6195 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006196 }
6197 }
6198 }
6199 break;
6200
Greg Clayton9b81a312010-06-12 01:20:30 +00006201 case DW_TAG_ptr_to_member_type:
6202 {
6203 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6204 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6205
Greg Claytond88d7592010-09-15 08:33:30 +00006206 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006207
6208 if (num_attributes > 0) {
6209 uint32_t i;
6210 for (i=0; i<num_attributes; ++i)
6211 {
6212 attr = attributes.AttributeAtIndex(i);
6213 DWARFFormValue form_value;
6214 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6215 {
6216 switch (attr)
6217 {
6218 case DW_AT_type:
6219 type_die_offset = form_value.Reference(dwarf_cu); break;
6220 case DW_AT_containing_type:
6221 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6222 }
6223 }
6224 }
6225
6226 Type *pointee_type = ResolveTypeUID(type_die_offset);
6227 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6228
Greg Clayton526e5af2010-11-13 03:52:47 +00006229 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6230 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006231
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006232 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6233 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006234
Greg Clayton526e5af2010-11-13 03:52:47 +00006235 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6236 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006237
Greg Clayton81c22f62011-10-19 18:09:39 +00006238 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006239 this,
6240 type_name_const_str,
6241 byte_size,
6242 NULL,
6243 LLDB_INVALID_UID,
6244 Type::eEncodingIsUID,
6245 NULL,
6246 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006247 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006248 }
6249
6250 break;
6251 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006252 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00006253 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006254 break;
6255 }
6256
6257 if (type_sp.get())
6258 {
6259 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6260 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6261
6262 SymbolContextScope * symbol_context_scope = NULL;
6263 if (sc_parent_tag == DW_TAG_compile_unit)
6264 {
6265 symbol_context_scope = sc.comp_unit;
6266 }
6267 else if (sc.function != NULL)
6268 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006269 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006270 if (symbol_context_scope == NULL)
6271 symbol_context_scope = sc.function;
6272 }
6273
6274 if (symbol_context_scope != NULL)
6275 {
6276 type_sp->SetSymbolContextScope(symbol_context_scope);
6277 }
6278
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006279 // We are ready to put this type into the uniqued list up at the module level
6280 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006281
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006282 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006283 }
6284 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006285 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006286 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006287 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006288 }
6289 }
6290 return type_sp;
6291}
6292
6293size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006294SymbolFileDWARF::ParseTypes
6295(
6296 const SymbolContext& sc,
6297 DWARFCompileUnit* dwarf_cu,
6298 const DWARFDebugInfoEntry *die,
6299 bool parse_siblings,
6300 bool parse_children
6301)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006302{
6303 size_t types_added = 0;
6304 while (die != NULL)
6305 {
6306 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006307 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006308 {
6309 if (type_is_new)
6310 ++types_added;
6311 }
6312
6313 if (parse_children && die->HasChildren())
6314 {
6315 if (die->Tag() == DW_TAG_subprogram)
6316 {
6317 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006318 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006319 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6320 }
6321 else
6322 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6323 }
6324
6325 if (parse_siblings)
6326 die = die->GetSibling();
6327 else
6328 die = NULL;
6329 }
6330 return types_added;
6331}
6332
6333
6334size_t
6335SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6336{
6337 assert(sc.comp_unit && sc.function);
6338 size_t functions_added = 0;
6339 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6340 if (dwarf_cu)
6341 {
6342 dw_offset_t function_die_offset = sc.function->GetID();
6343 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6344 if (function_die)
6345 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006346 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006347 }
6348 }
6349
6350 return functions_added;
6351}
6352
6353
6354size_t
6355SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6356{
6357 // At least a compile unit must be valid
6358 assert(sc.comp_unit);
6359 size_t types_added = 0;
6360 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6361 if (dwarf_cu)
6362 {
6363 if (sc.function)
6364 {
6365 dw_offset_t function_die_offset = sc.function->GetID();
6366 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6367 if (func_die && func_die->HasChildren())
6368 {
6369 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6370 }
6371 }
6372 else
6373 {
6374 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6375 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6376 {
6377 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6378 }
6379 }
6380 }
6381
6382 return types_added;
6383}
6384
6385size_t
6386SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6387{
6388 if (sc.comp_unit != NULL)
6389 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006390 DWARFDebugInfo* info = DebugInfo();
6391 if (info == NULL)
6392 return 0;
6393
6394 uint32_t cu_idx = UINT32_MAX;
6395 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006396
6397 if (dwarf_cu == NULL)
6398 return 0;
6399
6400 if (sc.function)
6401 {
6402 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006403
6404 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 +00006405 if (func_lo_pc != DW_INVALID_ADDRESS)
6406 {
6407 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006408
Greg Claytone38a5ed2012-01-05 03:57:59 +00006409 // Let all blocks know they have parse all their variables
6410 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6411 return num_variables;
6412 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006413 }
6414 else if (sc.comp_unit)
6415 {
6416 uint32_t vars_added = 0;
6417 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6418
6419 if (variables.get() == NULL)
6420 {
6421 variables.reset(new VariableList());
6422 sc.comp_unit->SetVariableList(variables);
6423
Greg Claytond4a2b372011-09-12 23:21:58 +00006424 DWARFCompileUnit* match_dwarf_cu = NULL;
6425 const DWARFDebugInfoEntry* die = NULL;
6426 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006427 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006428 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006429 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006430 {
6431 DWARFMappedHash::DIEInfoArray hash_data_array;
6432 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6433 dwarf_cu->GetNextCompileUnitOffset(),
6434 hash_data_array))
6435 {
6436 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6437 }
6438 }
Greg Clayton7f995132011-10-04 22:41:51 +00006439 }
6440 else
6441 {
6442 // Index if we already haven't to make sure the compile units
6443 // get indexed and make their global DIE index list
6444 if (!m_indexed)
6445 Index ();
6446
6447 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6448 dwarf_cu->GetNextCompileUnitOffset(),
6449 die_offsets);
6450 }
6451
6452 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006453 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006454 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006455 DWARFDebugInfo* debug_info = DebugInfo();
6456 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006457 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006458 const dw_offset_t die_offset = die_offsets[i];
6459 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006460 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006461 {
Greg Clayton95d87902011-11-11 03:16:25 +00006462 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6463 if (var_sp)
6464 {
6465 variables->AddVariableIfUnique (var_sp);
6466 ++vars_added;
6467 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006468 }
Greg Clayton95d87902011-11-11 03:16:25 +00006469 else
6470 {
6471 if (m_using_apple_tables)
6472 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006473 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 +00006474 }
6475 }
6476
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006477 }
6478 }
6479 }
6480 return vars_added;
6481 }
6482 }
6483 return 0;
6484}
6485
6486
6487VariableSP
6488SymbolFileDWARF::ParseVariableDIE
6489(
6490 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006491 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006492 const DWARFDebugInfoEntry *die,
6493 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006494)
6495{
6496
Greg Clayton83c5cd92010-11-14 22:13:40 +00006497 VariableSP var_sp (m_die_to_variable_sp[die]);
6498 if (var_sp)
6499 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006500
6501 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006502
6503 if ((tag == DW_TAG_variable) ||
6504 (tag == DW_TAG_constant) ||
6505 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006506 {
Greg Clayton7f995132011-10-04 22:41:51 +00006507 DWARFDebugInfoEntry::Attributes attributes;
6508 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6509 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006510 {
Greg Clayton7f995132011-10-04 22:41:51 +00006511 const char *name = NULL;
6512 const char *mangled = NULL;
6513 Declaration decl;
6514 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006515 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006516 DWARFExpression location;
6517 bool is_external = false;
6518 bool is_artificial = false;
6519 bool location_is_const_value_data = false;
Greg Clayton23f59502012-07-17 03:23:13 +00006520 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00006521
6522 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006523 {
Greg Clayton7f995132011-10-04 22:41:51 +00006524 dw_attr_t attr = attributes.AttributeAtIndex(i);
6525 DWARFFormValue form_value;
6526 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006527 {
Greg Clayton7f995132011-10-04 22:41:51 +00006528 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006529 {
Greg Clayton7f995132011-10-04 22:41:51 +00006530 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6531 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6532 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6533 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6534 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006535 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006536 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6537 case DW_AT_const_value:
6538 location_is_const_value_data = true;
6539 // Fall through...
6540 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006541 {
Greg Clayton7f995132011-10-04 22:41:51 +00006542 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006543 {
Greg Clayton7f995132011-10-04 22:41:51 +00006544 const DataExtractor& debug_info_data = get_debug_info_data();
6545
6546 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6547 uint32_t block_length = form_value.Unsigned();
6548 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6549 }
6550 else
6551 {
6552 const DataExtractor& debug_loc_data = get_debug_loc_data();
6553 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6554
6555 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6556 if (loc_list_length > 0)
6557 {
6558 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6559 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6560 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6561 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562 }
6563 }
Greg Clayton7f995132011-10-04 22:41:51 +00006564 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006565
Greg Clayton7f995132011-10-04 22:41:51 +00006566 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton23f59502012-07-17 03:23:13 +00006567 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006568 case DW_AT_declaration:
6569 case DW_AT_description:
6570 case DW_AT_endianity:
6571 case DW_AT_segment:
6572 case DW_AT_start_scope:
6573 case DW_AT_visibility:
6574 default:
6575 case DW_AT_abstract_origin:
6576 case DW_AT_sibling:
6577 case DW_AT_specification:
6578 break;
6579 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006580 }
6581 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006582
Greg Clayton7f995132011-10-04 22:41:51 +00006583 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006584 {
Greg Clayton7f995132011-10-04 22:41:51 +00006585 ValueType scope = eValueTypeInvalid;
6586
6587 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6588 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006589 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006590
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006591 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6592 // or static variable, so we have to do a little digging by
6593 // looking at the location of a varaible to see if it contains
6594 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6595 // somewhere because clang likes to combine small global variables
6596 // into the same symbol and have locations like:
6597 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6598 // So if we don't have a DW_TAG_formal_parameter, we can look at
6599 // the location to see if it contains a DW_OP_addr opcode, and
6600 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006601 if (tag == DW_TAG_formal_parameter)
6602 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006603 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006604 {
Greg Clayton96c09682012-01-04 22:56:43 +00006605 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006606 // Check if the location has a DW_OP_addr with any address value...
6607 addr_t location_has_op_addr = false;
6608 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006609 {
6610 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6611 if (op_error)
6612 {
6613 StreamString strm;
6614 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006615 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 +00006616 }
6617 }
Greg Claytond1767f02011-12-08 02:13:16 +00006618
6619 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006620 {
Greg Claytond1767f02011-12-08 02:13:16 +00006621 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006622 {
Greg Claytond1767f02011-12-08 02:13:16 +00006623 scope = eValueTypeVariableGlobal;
6624
6625 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006626 {
Greg Claytond1767f02011-12-08 02:13:16 +00006627 // When leaving the DWARF in the .o files on darwin,
6628 // when we have a global variable that wasn't initialized,
6629 // the .o file might not have allocated a virtual
6630 // address for the global variable. In this case it will
6631 // have created a symbol for the global variable
6632 // that is undefined and external and the value will
6633 // be the byte size of the variable. When we do the
6634 // address map in SymbolFileDWARFDebugMap we rely on
6635 // having an address, we need to do some magic here
6636 // so we can get the correct address for our global
6637 // variable. The address for all of these entries
6638 // will be zero, and there will be an undefined symbol
6639 // in this object file, and the executable will have
6640 // a matching symbol with a good address. So here we
6641 // dig up the correct address and replace it in the
6642 // location for the variable, and set the variable's
6643 // symbol context scope to be that of the main executable
6644 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006645 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006646 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006647
Greg Claytond1767f02011-12-08 02:13:16 +00006648 // we have a possible uninitialized extern global
6649 Symtab *symtab = m_obj_file->GetSymtab();
6650 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006651 {
Greg Claytond1767f02011-12-08 02:13:16 +00006652 ConstString const_name(name);
6653 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6654 eSymbolTypeUndefined,
6655 Symtab::eDebugNo,
6656 Symtab::eVisibilityExtern);
6657
6658 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006659 {
Greg Claytond1767f02011-12-08 02:13:16 +00006660 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6661 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006662 {
Greg Claytond1767f02011-12-08 02:13:16 +00006663 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6664 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6665 eSymbolTypeData,
6666 Symtab::eDebugYes,
6667 Symtab::eVisibilityExtern);
6668 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006669 {
Greg Claytone7612132012-03-07 21:03:09 +00006670 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006671 {
Greg Claytone7612132012-03-07 21:03:09 +00006672 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006673 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006674 {
Greg Claytond1767f02011-12-08 02:13:16 +00006675 if (location.Update_DW_OP_addr (defined_addr))
6676 {
6677 symbol_context_scope = defined_symbol;
6678 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006679 }
6680 }
6681 }
6682 }
6683 }
6684 }
6685 }
6686 }
6687 }
Greg Claytond1767f02011-12-08 02:13:16 +00006688 else
6689 {
6690 scope = eValueTypeVariableStatic;
6691 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006692 }
6693 else
Greg Claytond1767f02011-12-08 02:13:16 +00006694 {
6695 scope = eValueTypeVariableLocal;
6696 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006697 }
Greg Clayton7f995132011-10-04 22:41:51 +00006698
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006699 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006700 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006701 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006702 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006703 case DW_TAG_subprogram:
6704 case DW_TAG_inlined_subroutine:
6705 case DW_TAG_lexical_block:
6706 if (sc.function)
6707 {
6708 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6709 if (symbol_context_scope == NULL)
6710 symbol_context_scope = sc.function;
6711 }
6712 break;
6713
6714 default:
6715 symbol_context_scope = sc.comp_unit;
6716 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006717 }
Greg Clayton7f995132011-10-04 22:41:51 +00006718 }
6719
Greg Clayton5cf58b92011-10-05 22:22:08 +00006720 if (symbol_context_scope)
6721 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006722 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6723 name,
6724 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006725 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006726 scope,
6727 symbol_context_scope,
6728 &decl,
6729 location,
6730 is_external,
6731 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006732
6733 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6734 }
6735 else
6736 {
6737 // Not ready to parse this variable yet. It might be a global
6738 // or static variable that is in a function scope and the function
6739 // in the symbol context wasn't filled in yet
6740 return var_sp;
6741 }
Greg Clayton7f995132011-10-04 22:41:51 +00006742 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006743 }
Greg Clayton7f995132011-10-04 22:41:51 +00006744 // Cache var_sp even if NULL (the variable was just a specification or
6745 // was missing vital information to be able to be displayed in the debugger
6746 // (missing location due to optimization, etc)) so we don't re-parse
6747 // this DIE over and over later...
6748 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006749 }
6750 return var_sp;
6751}
6752
Greg Claytonc662ec82011-06-17 22:10:16 +00006753
6754const DWARFDebugInfoEntry *
6755SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6756 dw_offset_t spec_block_die_offset,
6757 DWARFCompileUnit **result_die_cu_handle)
6758{
6759 // Give the concrete function die specified by "func_die_offset", find the
6760 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6761 // to "spec_block_die_offset"
6762 DWARFDebugInfo* info = DebugInfo();
6763
6764 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6765 if (die)
6766 {
6767 assert (*result_die_cu_handle);
6768 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6769 }
6770 return NULL;
6771}
6772
6773
6774const DWARFDebugInfoEntry *
6775SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6776 const DWARFDebugInfoEntry *die,
6777 dw_offset_t spec_block_die_offset,
6778 DWARFCompileUnit **result_die_cu_handle)
6779{
6780 if (die)
6781 {
6782 switch (die->Tag())
6783 {
6784 case DW_TAG_subprogram:
6785 case DW_TAG_inlined_subroutine:
6786 case DW_TAG_lexical_block:
6787 {
6788 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6789 {
6790 *result_die_cu_handle = dwarf_cu;
6791 return die;
6792 }
6793
6794 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6795 {
6796 *result_die_cu_handle = dwarf_cu;
6797 return die;
6798 }
6799 }
6800 break;
6801 }
6802
6803 // Give the concrete function die specified by "func_die_offset", find the
6804 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6805 // to "spec_block_die_offset"
6806 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6807 {
6808 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6809 child_die,
6810 spec_block_die_offset,
6811 result_die_cu_handle);
6812 if (result_die)
6813 return result_die;
6814 }
6815 }
6816
6817 *result_die_cu_handle = NULL;
6818 return NULL;
6819}
6820
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006821size_t
6822SymbolFileDWARF::ParseVariables
6823(
6824 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006825 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006826 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006827 const DWARFDebugInfoEntry *orig_die,
6828 bool parse_siblings,
6829 bool parse_children,
6830 VariableList* cc_variable_list
6831)
6832{
6833 if (orig_die == NULL)
6834 return 0;
6835
Greg Claytonc662ec82011-06-17 22:10:16 +00006836 VariableListSP variable_list_sp;
6837
6838 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006839 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006840 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006841 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006842 dw_tag_t tag = die->Tag();
6843
6844 // Check to see if we have already parsed this variable or constant?
6845 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006846 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006847 if (cc_variable_list)
6848 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006849 }
6850 else
6851 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006852 // We haven't already parsed it, lets do that now.
6853 if ((tag == DW_TAG_variable) ||
6854 (tag == DW_TAG_constant) ||
6855 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006856 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006857 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006858 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006859 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6860 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6861 switch (parent_tag)
6862 {
6863 case DW_TAG_compile_unit:
6864 if (sc.comp_unit != NULL)
6865 {
6866 variable_list_sp = sc.comp_unit->GetVariableList(false);
6867 if (variable_list_sp.get() == NULL)
6868 {
6869 variable_list_sp.reset(new VariableList());
6870 sc.comp_unit->SetVariableList(variable_list_sp);
6871 }
6872 }
6873 else
6874 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006875 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6876 MakeUserID(sc_parent_die->GetOffset()),
6877 DW_TAG_value_to_name (parent_tag),
6878 MakeUserID(orig_die->GetOffset()),
6879 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006880 }
6881 break;
6882
6883 case DW_TAG_subprogram:
6884 case DW_TAG_inlined_subroutine:
6885 case DW_TAG_lexical_block:
6886 if (sc.function != NULL)
6887 {
6888 // Check to see if we already have parsed the variables for the given scope
6889
Greg Clayton81c22f62011-10-19 18:09:39 +00006890 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006891 if (block == NULL)
6892 {
6893 // This must be a specification or abstract origin with
6894 // a concrete block couterpart in the current function. We need
6895 // to find the concrete block so we can correctly add the
6896 // variable to it
6897 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6898 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6899 sc_parent_die->GetOffset(),
6900 &concrete_block_die_cu);
6901 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006902 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006903 }
6904
6905 if (block != NULL)
6906 {
6907 const bool can_create = false;
6908 variable_list_sp = block->GetBlockVariableList (can_create);
6909 if (variable_list_sp.get() == NULL)
6910 {
6911 variable_list_sp.reset(new VariableList());
6912 block->SetVariableList(variable_list_sp);
6913 }
6914 }
6915 }
6916 break;
6917
6918 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006919 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6920 MakeUserID(orig_die->GetOffset()),
6921 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006922 break;
6923 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006924 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006925
6926 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006927 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006928 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6929 if (var_sp)
6930 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006931 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006932 if (cc_variable_list)
6933 cc_variable_list->AddVariableIfUnique (var_sp);
6934 ++vars_added;
6935 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006936 }
6937 }
6938 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006939
6940 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6941
6942 if (!skip_children && parse_children && die->HasChildren())
6943 {
6944 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6945 }
6946
6947 if (parse_siblings)
6948 die = die->GetSibling();
6949 else
6950 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006951 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006952 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006953}
6954
6955//------------------------------------------------------------------
6956// PluginInterface protocol
6957//------------------------------------------------------------------
6958const char *
6959SymbolFileDWARF::GetPluginName()
6960{
6961 return "SymbolFileDWARF";
6962}
6963
6964const char *
6965SymbolFileDWARF::GetShortPluginName()
6966{
6967 return GetPluginNameStatic();
6968}
6969
6970uint32_t
6971SymbolFileDWARF::GetPluginVersion()
6972{
6973 return 1;
6974}
6975
6976void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006977SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6978{
6979 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6980 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6981 if (clang_type)
6982 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6983}
6984
6985void
6986SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6987{
6988 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6989 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6990 if (clang_type)
6991 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6992}
6993
Greg Claytona2721472011-06-25 00:44:06 +00006994void
Sean Callanancc427fa2011-07-30 02:42:06 +00006995SymbolFileDWARF::DumpIndexes ()
6996{
6997 StreamFile s(stdout, false);
6998
6999 s.Printf ("DWARF index for (%s) '%s/%s':",
7000 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7001 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
7002 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
7003 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7004 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7005 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7006 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7007 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7008 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7009 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7010 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7011}
7012
7013void
7014SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7015 const char *name,
7016 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00007017{
Sean Callanancc427fa2011-07-30 02:42:06 +00007018 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007019
7020 if (iter == m_decl_ctx_to_die.end())
7021 return;
7022
Greg Claytoncb5860a2011-10-13 23:49:28 +00007023 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007024 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007025 const DWARFDebugInfoEntry *context_die = *pos;
7026
7027 if (!results)
7028 return;
7029
7030 DWARFDebugInfo* info = DebugInfo();
7031
7032 DIEArray die_offsets;
7033
7034 DWARFCompileUnit* dwarf_cu = NULL;
7035 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007036
7037 if (m_using_apple_tables)
7038 {
7039 if (m_apple_types_ap.get())
7040 m_apple_types_ap->FindByName (name, die_offsets);
7041 }
7042 else
7043 {
7044 if (!m_indexed)
7045 Index ();
7046
7047 m_type_index.Find (ConstString(name), die_offsets);
7048 }
7049
Greg Clayton220a0072011-12-09 08:48:30 +00007050 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007051
7052 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007053 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007054 for (size_t i = 0; i < num_matches; ++i)
7055 {
7056 const dw_offset_t die_offset = die_offsets[i];
7057 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007058
Greg Claytoncb5860a2011-10-13 23:49:28 +00007059 if (die->GetParent() != context_die)
7060 continue;
7061
7062 Type *matching_type = ResolveType (dwarf_cu, die);
7063
Greg Clayton42ce2f32011-12-12 21:50:19 +00007064 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007065 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7066
7067 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7068 {
7069 clang::TagDecl *tag_decl = tag_type->getDecl();
7070 results->push_back(tag_decl);
7071 }
7072 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7073 {
7074 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7075 results->push_back(typedef_decl);
7076 }
Greg Claytona2721472011-06-25 00:44:06 +00007077 }
7078 }
7079 }
7080}
7081
7082void
7083SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007084 const clang::DeclContext *decl_context,
7085 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007086 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7087{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007088
7089 switch (decl_context->getDeclKind())
7090 {
7091 case clang::Decl::Namespace:
7092 case clang::Decl::TranslationUnit:
7093 {
7094 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7095 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7096 }
7097 break;
7098 default:
7099 break;
7100 }
Greg Claytona2721472011-06-25 00:44:06 +00007101}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007102
7103bool
7104SymbolFileDWARF::LayoutRecordType (void *baton,
7105 const clang::RecordDecl *record_decl,
7106 uint64_t &size,
7107 uint64_t &alignment,
7108 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7109 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7110 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7111{
7112 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7113 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7114}
7115
7116
7117bool
7118SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7119 uint64_t &bit_size,
7120 uint64_t &alignment,
7121 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7122 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7123 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7124{
7125 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7126 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7127 bool success = false;
7128 base_offsets.clear();
7129 vbase_offsets.clear();
7130 if (pos != m_record_decl_to_layout_map.end())
7131 {
7132 bit_size = pos->second.bit_size;
7133 alignment = pos->second.alignment;
7134 field_offsets.swap(pos->second.field_offsets);
7135 m_record_decl_to_layout_map.erase(pos);
7136 success = true;
7137 }
7138 else
7139 {
7140 bit_size = 0;
7141 alignment = 0;
7142 field_offsets.clear();
7143 }
7144
7145 if (log)
7146 GetObjectFile()->GetModule()->LogMessage (log.get(),
7147 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
7148 record_decl,
7149 bit_size,
7150 alignment,
7151 (uint32_t)field_offsets.size(),
7152 (uint32_t)base_offsets.size(),
7153 (uint32_t)vbase_offsets.size(),
7154 success);
7155 return success;
7156}
7157
7158
7159