blob: c7480022dbe61c72f491a22abe4873eb5b8a4847 [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;
424 uint64_t debug_aranges_file_size = 0;
425 uint64_t debug_frame_file_size = 0;
426 uint64_t debug_info_file_size = 0;
427 uint64_t debug_line_file_size = 0;
428 uint64_t debug_loc_file_size = 0;
429 uint64_t debug_macinfo_file_size = 0;
430 uint64_t debug_pubnames_file_size = 0;
431 uint64_t debug_pubtypes_file_size = 0;
432 uint64_t debug_ranges_file_size = 0;
433 uint64_t debug_str_file_size = 0;
434
Greg Clayton6beaaa62011-01-17 03:46:26 +0000435 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436
437 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000438 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439
Greg Clayton4ceb9982010-07-21 22:54:26 +0000440 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 if (section != NULL)
442 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000443 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444
Greg Clayton4ceb9982010-07-21 22:54:26 +0000445 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000447 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 else
449 m_flags.Set (flagsGotDebugAbbrevData);
450
Greg Clayton4ceb9982010-07-21 22:54:26 +0000451 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000453 debug_aranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 else
455 m_flags.Set (flagsGotDebugArangesData);
456
Greg Clayton4ceb9982010-07-21 22:54:26 +0000457 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000459 debug_frame_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 else
461 m_flags.Set (flagsGotDebugFrameData);
462
Greg Clayton4ceb9982010-07-21 22:54:26 +0000463 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000465 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 else
467 m_flags.Set (flagsGotDebugLineData);
468
Greg Clayton4ceb9982010-07-21 22:54:26 +0000469 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000471 debug_loc_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 else
473 m_flags.Set (flagsGotDebugLocData);
474
Greg Clayton4ceb9982010-07-21 22:54:26 +0000475 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000477 debug_macinfo_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 else
479 m_flags.Set (flagsGotDebugMacInfoData);
480
Greg Clayton4ceb9982010-07-21 22:54:26 +0000481 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000483 debug_pubnames_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 else
485 m_flags.Set (flagsGotDebugPubNamesData);
486
Greg Clayton4ceb9982010-07-21 22:54:26 +0000487 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000489 debug_pubtypes_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 else
491 m_flags.Set (flagsGotDebugPubTypesData);
492
Greg Clayton4ceb9982010-07-21 22:54:26 +0000493 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000495 debug_ranges_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496 else
497 m_flags.Set (flagsGotDebugRangesData);
498
Greg Clayton4ceb9982010-07-21 22:54:26 +0000499 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000501 debug_str_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 else
503 m_flags.Set (flagsGotDebugStrData);
504 }
505
506 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
507 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
508
509 if (debug_line_file_size > 0)
510 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 }
512 return abilities;
513}
514
515const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000516SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517{
518 if (m_flags.IsClear (got_flag))
519 {
520 m_flags.Set (got_flag);
521 const SectionList *section_list = m_obj_file->GetSectionList();
522 if (section_list)
523 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000524 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
525 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 {
527 // See if we memory mapped the DWARF segment?
528 if (m_dwarf_data.GetByteSize())
529 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000530 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 }
532 else
533 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000534 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535 data.Clear();
536 }
537 }
538 }
539 }
540 return data;
541}
542
543const DataExtractor&
544SymbolFileDWARF::get_debug_abbrev_data()
545{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000546 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547}
548
549const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000550SymbolFileDWARF::get_debug_aranges_data()
551{
552 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
553}
554
555const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556SymbolFileDWARF::get_debug_frame_data()
557{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000558 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559}
560
561const DataExtractor&
562SymbolFileDWARF::get_debug_info_data()
563{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000564 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565}
566
567const DataExtractor&
568SymbolFileDWARF::get_debug_line_data()
569{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000570 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571}
572
573const DataExtractor&
574SymbolFileDWARF::get_debug_loc_data()
575{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000576 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577}
578
579const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580SymbolFileDWARF::get_debug_ranges_data()
581{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000582 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583}
584
585const DataExtractor&
586SymbolFileDWARF::get_debug_str_data()
587{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000588 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589}
590
Greg Claytonf9eec202011-09-01 23:16:13 +0000591const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000592SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000593{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000594 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000595}
596
597const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000598SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000599{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000600 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000601}
602
Greg Clayton7f995132011-10-04 22:41:51 +0000603const DataExtractor&
604SymbolFileDWARF::get_apple_namespaces_data()
605{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000606 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
607}
608
609const DataExtractor&
610SymbolFileDWARF::get_apple_objc_data()
611{
612 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000613}
614
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615
616DWARFDebugAbbrev*
617SymbolFileDWARF::DebugAbbrev()
618{
619 if (m_abbr.get() == NULL)
620 {
621 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
622 if (debug_abbrev_data.GetByteSize() > 0)
623 {
624 m_abbr.reset(new DWARFDebugAbbrev());
625 if (m_abbr.get())
626 m_abbr->Parse(debug_abbrev_data);
627 }
628 }
629 return m_abbr.get();
630}
631
632const DWARFDebugAbbrev*
633SymbolFileDWARF::DebugAbbrev() const
634{
635 return m_abbr.get();
636}
637
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638
639DWARFDebugInfo*
640SymbolFileDWARF::DebugInfo()
641{
642 if (m_info.get() == NULL)
643 {
644 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
645 if (get_debug_info_data().GetByteSize() > 0)
646 {
647 m_info.reset(new DWARFDebugInfo());
648 if (m_info.get())
649 {
650 m_info->SetDwarfData(this);
651 }
652 }
653 }
654 return m_info.get();
655}
656
657const DWARFDebugInfo*
658SymbolFileDWARF::DebugInfo() const
659{
660 return m_info.get();
661}
662
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663DWARFCompileUnit*
664SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
665{
666 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000667 if (info && UserIDMatches(cu_uid))
668 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669 return NULL;
670}
671
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672
673DWARFDebugRanges*
674SymbolFileDWARF::DebugRanges()
675{
676 if (m_ranges.get() == NULL)
677 {
678 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
679 if (get_debug_ranges_data().GetByteSize() > 0)
680 {
681 m_ranges.reset(new DWARFDebugRanges());
682 if (m_ranges.get())
683 m_ranges->Extract(this);
684 }
685 }
686 return m_ranges.get();
687}
688
689const DWARFDebugRanges*
690SymbolFileDWARF::DebugRanges() const
691{
692 return m_ranges.get();
693}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694
Greg Clayton53eb1c22012-04-02 22:59:12 +0000695lldb::CompUnitSP
696SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000698 CompUnitSP cu_sp;
699 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000701 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
702 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000704 // We already parsed this compile unit, had out a shared pointer to it
705 cu_sp = comp_unit->shared_from_this();
706 }
707 else
708 {
709 ModuleSP module_sp (m_obj_file->GetModule());
710 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000712 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
713 if (cu_die)
714 {
715 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
716 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
717 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
718 if (cu_die_name)
719 {
720 std::string ramapped_file;
721 FileSpec cu_file_spec;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000722
Greg Clayton53eb1c22012-04-02 22:59:12 +0000723 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
724 {
725 // If we have a full path to the compile unit, we don't need to resolve
726 // the file. This can be expensive e.g. when the source files are NFS mounted.
727 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
728 cu_file_spec.SetFile (ramapped_file.c_str(), false);
729 else
730 cu_file_spec.SetFile (cu_die_name, false);
731 }
732 else
733 {
734 std::string fullpath(cu_comp_dir);
735 if (*fullpath.rbegin() != '/')
736 fullpath += '/';
737 fullpath += cu_die_name;
738 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
739 cu_file_spec.SetFile (ramapped_file.c_str(), false);
740 else
741 cu_file_spec.SetFile (fullpath.c_str(), false);
742 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743
Greg Clayton53eb1c22012-04-02 22:59:12 +0000744 cu_sp.reset(new CompileUnit (module_sp,
745 dwarf_cu,
746 cu_file_spec,
747 MakeUserID(dwarf_cu->GetOffset()),
748 cu_language));
749 if (cu_sp)
750 {
751 dwarf_cu->SetUserData(cu_sp.get());
752
753 if (m_debug_map_symfile)
754 {
755 // Let the symbol file register the compile unit with
756 // the symbol vendor using its compile unit index
757 // when we are doing DWARF in .o files + debug map
758 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
759 }
760 else
761 {
762 // Figure out the compile unit index if we weren't given one
763 if (cu_idx == UINT32_MAX)
764 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
765
766 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
767 }
768 }
769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771 }
772 }
773 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000774 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775}
776
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777uint32_t
778SymbolFileDWARF::GetNumCompileUnits()
779{
780 DWARFDebugInfo* info = DebugInfo();
781 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783 return 0;
784}
785
786CompUnitSP
787SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
788{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000789 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 DWARFDebugInfo* info = DebugInfo();
791 if (info)
792 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000793 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
794 if (dwarf_cu)
795 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000797 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798}
799
800static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000801AddRangesToBlock (Block& block,
802 DWARFDebugRanges::RangeList& ranges,
803 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000805 const size_t num_ranges = ranges.GetSize();
806 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000808 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
809 const addr_t range_base = range.GetRangeBase();
810 assert (range_base >= block_base_addr);
811 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000813 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814}
815
816
817Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000818SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819{
820 DWARFDebugRanges::RangeList func_ranges;
821 const char *name = NULL;
822 const char *mangled = NULL;
823 int decl_file = 0;
824 int decl_line = 0;
825 int decl_column = 0;
826 int call_file = 0;
827 int call_line = 0;
828 int call_column = 0;
829 DWARFExpression frame_base;
830
Greg Claytonc93237c2010-10-01 20:48:32 +0000831 assert (die->Tag() == DW_TAG_subprogram);
832
833 if (die->Tag() != DW_TAG_subprogram)
834 return NULL;
835
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000836 if (die->GetDIENamesAndRanges (this,
837 dwarf_cu,
838 name,
839 mangled,
840 func_ranges,
841 decl_file,
842 decl_line,
843 decl_column,
844 call_file,
845 call_line,
846 call_column,
847 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 {
849 // Union of all ranges in the function DIE (if the function is discontiguous)
850 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000851 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
852 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
854 {
855 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
856 if (func_range.GetBaseAddress().IsValid())
857 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
858 }
859
860 if (func_range.GetBaseAddress().IsValid())
861 {
862 Mangled func_name;
863 if (mangled)
864 func_name.SetValue(mangled, true);
865 else if (name)
866 func_name.SetValue(name, false);
867
868 FunctionSP func_sp;
869 std::auto_ptr<Declaration> decl_ap;
870 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000871 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
872 decl_line,
873 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000875 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000876 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877
878 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
879
880 func_range.GetBaseAddress().ResolveLinkedAddress();
881
Greg Clayton81c22f62011-10-19 18:09:39 +0000882 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000883 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000884 func_user_id, // UserID is the DIE offset
885 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000886 func_name,
887 func_type,
888 func_range)); // first address range
889
890 if (func_sp.get() != NULL)
891 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000892 if (frame_base.IsValid())
893 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000894 sc.comp_unit->AddFunction(func_sp);
895 return func_sp.get();
896 }
897 }
898 }
899 return NULL;
900}
901
902size_t
903SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
904{
905 assert (sc.comp_unit);
906 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000907 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 if (dwarf_cu)
909 {
910 DWARFDIECollection function_dies;
911 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
912 size_t func_idx;
913 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
914 {
915 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000916 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000917 {
918 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
919 ++functions_added;
920 }
921 }
922 //FixupTypes();
923 }
924 return functions_added;
925}
926
927bool
928SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
929{
930 assert (sc.comp_unit);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000931 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
932 assert (dwarf_cu);
933 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000934
935 if (cu_die)
936 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000937 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
938 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 +0000939
940 // All file indexes in DWARF are one based and a file of index zero is
941 // supposed to be the compile unit itself.
942 support_files.Append (*sc.comp_unit);
943
Greg Claytond804d282012-03-15 21:01:31 +0000944 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 +0000945 }
946 return false;
947}
948
949struct ParseDWARFLineTableCallbackInfo
950{
951 LineTable* line_table;
952 const SectionList *section_list;
953 lldb::addr_t prev_sect_file_base_addr;
954 lldb::addr_t curr_sect_file_base_addr;
955 bool is_oso_for_debug_map;
956 bool prev_in_final_executable;
957 DWARFDebugLine::Row prev_row;
958 SectionSP prev_section_sp;
959 SectionSP curr_section_sp;
960};
961
962//----------------------------------------------------------------------
963// ParseStatementTableCallback
964//----------------------------------------------------------------------
965static void
966ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
967{
968 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
969 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
970 {
971 // Just started parsing the line table
972 }
973 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
974 {
975 // Done parsing line table, nothing to do for the cleanup
976 }
977 else
978 {
979 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
980 // We have a new row, lets append it
981
982 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
983 {
984 info->prev_section_sp = info->curr_section_sp;
985 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
986 // If this is an end sequence entry, then we subtract one from the
987 // address to make sure we get an address that is not the end of
988 // a section.
989 if (state.end_sequence && state.address != 0)
990 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
991 else
992 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
993
994 if (info->curr_section_sp.get())
995 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
996 else
997 info->curr_sect_file_base_addr = 0;
998 }
999 if (info->curr_section_sp.get())
1000 {
1001 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1002 // Check for the fancy section magic to determine if we
1003
1004 if (info->is_oso_for_debug_map)
1005 {
1006 // When this is a debug map object file that contains DWARF
1007 // (referenced from an N_OSO debug map nlist entry) we will have
1008 // a file address in the file range for our section from the
1009 // original .o file, and a load address in the executable that
1010 // contains the debug map.
1011 //
1012 // If the sections for the file range and load range are
1013 // different, we have a remapped section for the function and
1014 // this address is resolved. If they are the same, then the
1015 // function for this address didn't make it into the final
1016 // executable.
1017 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1018
1019 // If we are doing DWARF with debug map, then we need to carefully
1020 // add each line table entry as there may be gaps as functions
1021 // get moved around or removed.
1022 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1023 {
1024 if (info->prev_in_final_executable)
1025 {
1026 bool terminate_previous_entry = false;
1027 if (!curr_in_final_executable)
1028 {
1029 // Check for the case where the previous line entry
1030 // in a function made it into the final executable,
1031 // yet the current line entry falls in a function
1032 // that didn't. The line table used to be contiguous
1033 // through this address range but now it isn't. We
1034 // need to terminate the previous line entry so
1035 // that we can reconstruct the line range correctly
1036 // for it and to keep the line table correct.
1037 terminate_previous_entry = true;
1038 }
1039 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1040 {
1041 // Check for cases where the line entries used to be
1042 // contiguous address ranges, but now they aren't.
1043 // This can happen when order files specify the
1044 // ordering of the functions.
1045 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1046 Section *curr_sect = info->curr_section_sp.get();
1047 Section *prev_sect = info->prev_section_sp.get();
1048 assert (curr_sect->GetLinkedSection());
1049 assert (prev_sect->GetLinkedSection());
1050 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1051 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1052 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1053 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1054 if (object_file_addr_delta != linked_file_addr_delta)
1055 terminate_previous_entry = true;
1056 }
1057
1058 if (terminate_previous_entry)
1059 {
1060 line_table->InsertLineEntry (info->prev_section_sp,
1061 state.address - info->prev_sect_file_base_addr,
1062 info->prev_row.line,
1063 info->prev_row.column,
1064 info->prev_row.file,
1065 false, // is_stmt
1066 false, // basic_block
1067 false, // state.prologue_end
1068 false, // state.epilogue_begin
1069 true); // end_sequence);
1070 }
1071 }
1072 }
1073
1074 if (curr_in_final_executable)
1075 {
1076 line_table->InsertLineEntry (info->curr_section_sp,
1077 curr_line_section_offset,
1078 state.line,
1079 state.column,
1080 state.file,
1081 state.is_stmt,
1082 state.basic_block,
1083 state.prologue_end,
1084 state.epilogue_begin,
1085 state.end_sequence);
1086 info->prev_section_sp = info->curr_section_sp;
1087 }
1088 else
1089 {
1090 // If the current address didn't make it into the final
1091 // executable, the current section will be the __text
1092 // segment in the .o file, so we need to clear this so
1093 // we can catch the next function that did make it into
1094 // the final executable.
1095 info->prev_section_sp.reset();
1096 info->curr_section_sp.reset();
1097 }
1098
1099 info->prev_in_final_executable = curr_in_final_executable;
1100 }
1101 else
1102 {
1103 // We are not in an object file that contains DWARF for an
1104 // N_OSO, this is just a normal DWARF file. The DWARF spec
1105 // guarantees that the addresses will be in increasing order
1106 // so, since we store line tables in file address order, we
1107 // can always just append the line entry without needing to
1108 // search for the correct insertion point (we don't need to
1109 // use LineEntry::InsertLineEntry()).
1110 line_table->AppendLineEntry (info->curr_section_sp,
1111 curr_line_section_offset,
1112 state.line,
1113 state.column,
1114 state.file,
1115 state.is_stmt,
1116 state.basic_block,
1117 state.prologue_end,
1118 state.epilogue_begin,
1119 state.end_sequence);
1120 }
1121 }
1122
1123 info->prev_row = state;
1124 }
1125}
1126
1127bool
1128SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1129{
1130 assert (sc.comp_unit);
1131 if (sc.comp_unit->GetLineTable() != NULL)
1132 return true;
1133
1134 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1135 if (dwarf_cu)
1136 {
1137 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001138 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001140 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1141 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001143 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1144 if (line_table_ap.get())
1145 {
1146 ParseDWARFLineTableCallbackInfo info = {
1147 line_table_ap.get(),
1148 m_obj_file->GetSectionList(),
1149 0,
1150 0,
1151 m_debug_map_symfile != NULL,
1152 false,
1153 DWARFDebugLine::Row(),
1154 SectionSP(),
1155 SectionSP()
1156 };
1157 uint32_t offset = cu_line_offset;
1158 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1159 sc.comp_unit->SetLineTable(line_table_ap.release());
1160 return true;
1161 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 }
1163 }
1164 }
1165 return false;
1166}
1167
1168size_t
1169SymbolFileDWARF::ParseFunctionBlocks
1170(
1171 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001172 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001173 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001174 const DWARFDebugInfoEntry *die,
1175 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001176 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177)
1178{
1179 size_t blocks_added = 0;
1180 while (die != NULL)
1181 {
1182 dw_tag_t tag = die->Tag();
1183
1184 switch (tag)
1185 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001187 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 case DW_TAG_lexical_block:
1189 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001190 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001191 if (tag == DW_TAG_subprogram)
1192 {
1193 // Skip any DW_TAG_subprogram DIEs that are inside
1194 // of a normal or inlined functions. These will be
1195 // parsed on their own as separate entities.
1196
1197 if (depth > 0)
1198 break;
1199
1200 block = parent_block;
1201 }
1202 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001203 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001204 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001205 parent_block->AddChild(block_sp);
1206 block = block_sp.get();
1207 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001208 DWARFDebugRanges::RangeList ranges;
1209 const char *name = NULL;
1210 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 int decl_file = 0;
1213 int decl_line = 0;
1214 int decl_column = 0;
1215 int call_file = 0;
1216 int call_line = 0;
1217 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001218 if (die->GetDIENamesAndRanges (this,
1219 dwarf_cu,
1220 name,
1221 mangled_name,
1222 ranges,
1223 decl_file, decl_line, decl_column,
1224 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 {
1226 if (tag == DW_TAG_subprogram)
1227 {
1228 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001229 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001231 else if (tag == DW_TAG_inlined_subroutine)
1232 {
1233 // We get called here for inlined subroutines in two ways.
1234 // The first time is when we are making the Function object
1235 // for this inlined concrete instance. Since we're creating a top level block at
1236 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1237 // adjust the containing address.
1238 // The second time is when we are parsing the blocks inside the function that contains
1239 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1240 // function the offset will be for that function.
1241 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1242 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001243 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001244 }
1245 }
1246
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001247 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248
1249 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1250 {
1251 std::auto_ptr<Declaration> decl_ap;
1252 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001253 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1254 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255
1256 std::auto_ptr<Declaration> call_ap;
1257 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001258 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1259 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001261 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 }
1263
1264 ++blocks_added;
1265
Greg Claytondd7feaf2011-08-12 17:54:33 +00001266 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001268 blocks_added += ParseFunctionBlocks (sc,
1269 block,
1270 dwarf_cu,
1271 die->GetFirstChild(),
1272 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001273 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 }
1275 }
1276 }
1277 break;
1278 default:
1279 break;
1280 }
1281
Greg Claytondd7feaf2011-08-12 17:54:33 +00001282 // Only parse siblings of the block if we are not at depth zero. A depth
1283 // of zero indicates we are currently parsing the top level
1284 // DW_TAG_subprogram DIE
1285
1286 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001288 else
1289 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290 }
1291 return blocks_added;
1292}
1293
Greg Claytonf0705c82011-10-22 03:33:13 +00001294bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001295SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1296 const DWARFDebugInfoEntry *die,
1297 ClangASTContext::TemplateParameterInfos &template_param_infos)
1298{
1299 const dw_tag_t tag = die->Tag();
1300
1301 switch (tag)
1302 {
1303 case DW_TAG_template_type_parameter:
1304 case DW_TAG_template_value_parameter:
1305 {
1306 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1307
1308 DWARFDebugInfoEntry::Attributes attributes;
1309 const size_t num_attributes = die->GetAttributes (this,
1310 dwarf_cu,
1311 fixed_form_sizes,
1312 attributes);
1313 const char *name = NULL;
1314 Type *lldb_type = NULL;
1315 clang_type_t clang_type = NULL;
1316 uint64_t uval64 = 0;
1317 bool uval64_valid = false;
1318 if (num_attributes > 0)
1319 {
1320 DWARFFormValue form_value;
1321 for (size_t i=0; i<num_attributes; ++i)
1322 {
1323 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1324
1325 switch (attr)
1326 {
1327 case DW_AT_name:
1328 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1329 name = form_value.AsCString(&get_debug_str_data());
1330 break;
1331
1332 case DW_AT_type:
1333 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1334 {
1335 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1336 lldb_type = ResolveTypeUID(type_die_offset);
1337 if (lldb_type)
1338 clang_type = lldb_type->GetClangForwardType();
1339 }
1340 break;
1341
1342 case DW_AT_const_value:
1343 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1344 {
1345 uval64_valid = true;
1346 uval64 = form_value.Unsigned();
1347 }
1348 break;
1349 default:
1350 break;
1351 }
1352 }
1353
1354 if (name && lldb_type && clang_type)
1355 {
1356 bool is_signed = false;
1357 template_param_infos.names.push_back(name);
1358 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1359 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1360 {
1361 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1362 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1363 }
1364 else
1365 {
1366 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1367 }
1368 }
1369 else
1370 {
1371 return false;
1372 }
1373
1374 }
1375 }
1376 return true;
1377
1378 default:
1379 break;
1380 }
1381 return false;
1382}
1383
1384bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001385SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1386 const DWARFDebugInfoEntry *parent_die,
1387 ClangASTContext::TemplateParameterInfos &template_param_infos)
1388{
1389
1390 if (parent_die == NULL)
1391 return NULL;
1392
Greg Claytonf0705c82011-10-22 03:33:13 +00001393 Args template_parameter_names;
1394 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1395 die != NULL;
1396 die = die->GetSibling())
1397 {
1398 const dw_tag_t tag = die->Tag();
1399
1400 switch (tag)
1401 {
1402 case DW_TAG_template_type_parameter:
1403 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001404 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001405 break;
1406
1407 default:
1408 break;
1409 }
1410 }
1411 if (template_param_infos.args.empty())
1412 return false;
1413 return template_param_infos.args.size() == template_param_infos.names.size();
1414}
1415
1416clang::ClassTemplateDecl *
1417SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001418 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001419 const char *parent_name,
1420 int tag_decl_kind,
1421 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1422{
1423 if (template_param_infos.IsValid())
1424 {
1425 std::string template_basename(parent_name);
1426 template_basename.erase (template_basename.find('<'));
1427 ClangASTContext &ast = GetClangASTContext();
1428
1429 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001430 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001431 template_basename.c_str(),
1432 tag_decl_kind,
1433 template_param_infos);
1434 }
1435 return NULL;
1436}
1437
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438size_t
1439SymbolFileDWARF::ParseChildMembers
1440(
1441 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001442 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001444 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001445 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1447 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001448 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001449 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001450 bool &is_a_class,
1451 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452)
1453{
1454 if (parent_die == NULL)
1455 return 0;
1456
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 size_t count = 0;
1458 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001459 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001460 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001461
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1463 {
1464 dw_tag_t tag = die->Tag();
1465
1466 switch (tag)
1467 {
1468 case DW_TAG_member:
Bill Wendling9e5bf872012-04-03 08:45:33 +00001469 case DW_TAG_APPLE_Property:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 {
1471 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001472 const size_t num_attributes = die->GetAttributes (this,
1473 dwarf_cu,
1474 fixed_form_sizes,
1475 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 if (num_attributes > 0)
1477 {
1478 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001479 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001481 const char *prop_name = NULL;
1482 const char *prop_getter_name = NULL;
1483 const char *prop_setter_name = NULL;
1484 uint32_t prop_attributes = 0;
1485
1486
Greg Clayton24739922010-10-13 03:15:28 +00001487 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001489 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001490 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 size_t byte_size = 0;
1492 size_t bit_offset = 0;
1493 size_t bit_size = 0;
1494 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001495 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 {
1497 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1498 DWARFFormValue form_value;
1499 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1500 {
1501 switch (attr)
1502 {
1503 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1504 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1505 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1506 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1507 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1508 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1509 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1510 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1511 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001512 if (form_value.BlockData())
1513 {
1514 Value initialValue(0);
1515 Value memberOffset(0);
1516 const DataExtractor& debug_info_data = get_debug_info_data();
1517 uint32_t block_length = form_value.Unsigned();
1518 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1519 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1520 NULL, // clang::ASTContext *
1521 NULL, // ClangExpressionVariableList *
1522 NULL, // ClangExpressionDeclMap *
1523 NULL, // RegisterContext *
1524 debug_info_data,
1525 block_offset,
1526 block_length,
1527 eRegisterKindDWARF,
1528 &initialValue,
1529 memberOffset,
1530 NULL))
1531 {
1532 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1533 }
1534 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001535 break;
1536
Greg Clayton8cf05932010-07-22 18:30:50 +00001537 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton1b02c172012-03-14 21:00:47 +00001538 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001539 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1540 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1541 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1542 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1543
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544 default:
Greg Clayton1b02c172012-03-14 21:00:47 +00001545 case DW_AT_declaration:
1546 case DW_AT_description:
1547 case DW_AT_mutable:
1548 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549 case DW_AT_sibling:
1550 break;
1551 }
1552 }
1553 }
Sean Callanana6582262012-04-05 00:12:52 +00001554
1555 if (prop_name)
Sean Callanan751aac62012-03-29 19:07:06 +00001556 {
Sean Callanana6582262012-04-05 00:12:52 +00001557 ConstString fixed_getter;
1558 ConstString fixed_setter;
1559
1560 // Check if the property getter/setter were provided as full
1561 // names. We want basenames, so we extract them.
1562
1563 if (prop_getter_name && prop_getter_name[0] == '-')
1564 {
1565 ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1566 NULL,
1567 &fixed_getter,
1568 NULL,
1569 NULL);
1570 prop_getter_name = fixed_getter.GetCString();
1571 }
1572
1573 if (prop_setter_name && prop_setter_name[0] == '-')
1574 {
1575 ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1576 NULL,
1577 &fixed_setter,
1578 NULL,
1579 NULL);
1580 prop_setter_name = fixed_setter.GetCString();
1581 }
1582
1583 // If the names haven't been provided, they need to be
1584 // filled in.
1585
1586 if (!prop_getter_name)
1587 {
1588 prop_getter_name = prop_name;
1589 }
1590 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1591 {
1592 StreamString ss;
1593
1594 ss.Printf("set%c%s:",
1595 toupper(prop_name[0]),
1596 &prop_name[1]);
1597
1598 fixed_setter.SetCString(ss.GetData());
1599 prop_setter_name = fixed_setter.GetCString();
1600 }
Sean Callanan751aac62012-03-29 19:07:06 +00001601 }
1602
1603 // Clang has a DWARF generation bug where sometimes it
Greg Clayton44953932011-10-25 01:25:35 +00001604 // represents fields that are references with bad byte size
1605 // and bit size/offset information such as:
1606 //
1607 // DW_AT_byte_size( 0x00 )
1608 // DW_AT_bit_size( 0x40 )
1609 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1610 //
1611 // So check the bit offset to make sure it is sane, and if
1612 // the values are not sane, remove them. If we don't do this
1613 // then we will end up with a crash if we try to use this
1614 // type in an expression when clang becomes unhappy with its
1615 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001616
Greg Clayton44953932011-10-25 01:25:35 +00001617 if (bit_offset > 128)
1618 {
1619 bit_size = 0;
1620 bit_offset = 0;
1621 }
1622
1623 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001624 if (class_language == eLanguageTypeObjC ||
1625 class_language == eLanguageTypeObjC_plus_plus)
1626 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001627
1628 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1629 {
1630 // Not all compilers will mark the vtable pointer
1631 // member as artificial (llvm-gcc). We can't have
1632 // the virtual members in our classes otherwise it
1633 // throws off all child offsets since we end up
1634 // having and extra pointer sized member in our
1635 // class layouts.
1636 is_artificial = true;
1637 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638
Greg Clayton24739922010-10-13 03:15:28 +00001639 if (is_artificial == false)
1640 {
1641 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001642 clang::FieldDecl *field_decl = NULL;
Sean Callanan751aac62012-03-29 19:07:06 +00001643 if (tag == DW_TAG_member)
Greg Claytond16e1e52011-07-12 17:06:17 +00001644 {
Sean Callanan751aac62012-03-29 19:07:06 +00001645 if (member_type)
1646 {
1647 if (accessibility == eAccessNone)
1648 accessibility = default_accessibility;
1649 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650
Sean Callanan751aac62012-03-29 19:07:06 +00001651 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1652 name,
1653 member_type->GetClangLayoutType(),
1654 accessibility,
1655 bit_size);
Sean Callanan60217122012-04-13 00:10:03 +00001656
1657 GetClangASTContext().SetMetadata((uintptr_t)field_decl, MakeUserID(die->GetOffset()));
Sean Callanan5b26f272012-02-04 08:49:35 +00001658 }
1659 else
1660 {
Sean Callanan751aac62012-03-29 19:07:06 +00001661 if (name)
1662 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1663 MakeUserID(die->GetOffset()),
1664 name,
1665 encoding_uid);
1666 else
1667 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1668 MakeUserID(die->GetOffset()),
1669 encoding_uid);
Sean Callanan5b26f272012-02-04 08:49:35 +00001670 }
Sean Callanan751aac62012-03-29 19:07:06 +00001671
1672 if (member_byte_offset != UINT32_MAX || bit_size != 0)
1673 {
1674 /////////////////////////////////////////////////////////////
1675 // How to locate a field given the DWARF debug information
1676 //
1677 // AT_byte_size indicates the size of the word in which the
1678 // bit offset must be interpreted.
1679 //
1680 // AT_data_member_location indicates the byte offset of the
1681 // word from the base address of the structure.
1682 //
1683 // AT_bit_offset indicates how many bits into the word
1684 // (according to the host endianness) the low-order bit of
1685 // the field starts. AT_bit_offset can be negative.
1686 //
1687 // AT_bit_size indicates the size of the field in bits.
1688 /////////////////////////////////////////////////////////////
Sean Callanan5b26f272012-02-04 08:49:35 +00001689
Sean Callanan751aac62012-03-29 19:07:06 +00001690 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1691
1692 uint64_t total_bit_offset = 0;
1693
1694 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1695
1696 if (object_endian == eByteOrderLittle)
1697 {
1698 total_bit_offset += byte_size * 8;
1699 total_bit_offset -= (bit_offset + bit_size);
1700 }
1701 else
1702 {
1703 total_bit_offset += bit_offset;
1704 }
1705
1706 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1707 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001708 }
Sean Callanan751aac62012-03-29 19:07:06 +00001709
Jim Inghame3ae82a2011-11-12 01:36:43 +00001710 if (prop_name != NULL)
1711 {
Sean Callanan751aac62012-03-29 19:07:06 +00001712 clang::ObjCIvarDecl *ivar_decl = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001713
Sean Callanan751aac62012-03-29 19:07:06 +00001714 if (field_decl)
1715 {
1716 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1717 assert (ivar_decl != NULL);
1718 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001719
Jim Inghame3ae82a2011-11-12 01:36:43 +00001720 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1721 prop_name,
Sean Callanan751aac62012-03-29 19:07:06 +00001722 member_type->GetClangLayoutType(),
Jim Inghame3ae82a2011-11-12 01:36:43 +00001723 ivar_decl,
1724 prop_setter_name,
1725 prop_getter_name,
Sean Callananad880762012-04-18 01:06:17 +00001726 prop_attributes,
1727 MakeUserID(die->GetOffset()));
Sean Callanan60217122012-04-13 00:10:03 +00001728
Sean Callananad880762012-04-18 01:06:17 +00001729 if (ivar_decl)
1730 GetClangASTContext().SetMetadata((uintptr_t)ivar_decl, MakeUserID(die->GetOffset()));
Jim Inghame3ae82a2011-11-12 01:36:43 +00001731 }
Greg Clayton24739922010-10-13 03:15:28 +00001732 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001734 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 }
1736 break;
1737
1738 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001739 // Let the type parsing code handle this one for us.
1740 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 break;
1742
1743 case DW_TAG_inheritance:
1744 {
1745 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001746 if (default_accessibility == eAccessNone)
1747 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748 // TODO: implement DW_TAG_inheritance type parsing
1749 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001750 const size_t num_attributes = die->GetAttributes (this,
1751 dwarf_cu,
1752 fixed_form_sizes,
1753 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 if (num_attributes > 0)
1755 {
1756 Declaration decl;
1757 DWARFExpression location;
1758 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001759 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760 bool is_virtual = false;
1761 bool is_base_of_class = true;
1762 off_t member_offset = 0;
1763 uint32_t i;
1764 for (i=0; i<num_attributes; ++i)
1765 {
1766 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1767 DWARFFormValue form_value;
1768 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1769 {
1770 switch (attr)
1771 {
1772 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1773 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1774 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1775 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1776 case DW_AT_data_member_location:
1777 if (form_value.BlockData())
1778 {
1779 Value initialValue(0);
1780 Value memberOffset(0);
1781 const DataExtractor& debug_info_data = get_debug_info_data();
1782 uint32_t block_length = form_value.Unsigned();
1783 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001784 if (DWARFExpression::Evaluate (NULL,
1785 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001786 NULL,
1787 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001788 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001789 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001790 block_offset,
1791 block_length,
1792 eRegisterKindDWARF,
1793 &initialValue,
1794 memberOffset,
1795 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796 {
1797 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1798 }
1799 }
1800 break;
1801
1802 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001803 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804 break;
1805
1806 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1807 default:
1808 case DW_AT_sibling:
1809 break;
1810 }
1811 }
1812 }
1813
Greg Clayton526e5af2010-11-13 03:52:47 +00001814 Type *base_class_type = ResolveTypeUID(encoding_uid);
1815 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001816
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001817 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1818 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001819 if (class_language == eLanguageTypeObjC)
1820 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001821 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001822 }
1823 else
1824 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001825 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001826 accessibility,
1827 is_virtual,
1828 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001829 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 }
1831 }
1832 break;
1833
1834 default:
1835 break;
1836 }
1837 }
1838 return count;
1839}
1840
1841
1842clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001843SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844{
1845 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001846 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001847 {
1848 DWARFCompileUnitSP cu_sp;
1849 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1850 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001851 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001852 }
1853 return NULL;
1854}
1855
1856clang::DeclContext*
1857SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1858{
Greg Clayton81c22f62011-10-19 18:09:39 +00001859 if (UserIDMatches(type_uid))
1860 return GetClangDeclContextForDIEOffset (sc, type_uid);
1861 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862}
1863
1864Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001865SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866{
Greg Clayton81c22f62011-10-19 18:09:39 +00001867 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001869 DWARFDebugInfo* debug_info = DebugInfo();
1870 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001871 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001872 DWARFCompileUnitSP cu_sp;
1873 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001874 const bool assert_not_being_parsed = true;
1875 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001876 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001877 }
1878 return NULL;
1879}
1880
Greg Claytoncab36a32011-12-08 05:16:30 +00001881Type*
1882SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001883{
Greg Claytoncab36a32011-12-08 05:16:30 +00001884 if (die != NULL)
1885 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001886 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1887 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001888 GetObjectFile()->GetModule()->LogMessage (log.get(),
1889 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1890 die->GetOffset(),
1891 DW_TAG_value_to_name(die->Tag()),
1892 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001893
Greg Claytoncab36a32011-12-08 05:16:30 +00001894 // We might be coming in in the middle of a type tree (a class
1895 // withing a class, an enum within a class), so parse any needed
1896 // parent DIEs before we get to this one...
1897 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1898 switch (decl_ctx_die->Tag())
1899 {
1900 case DW_TAG_structure_type:
1901 case DW_TAG_union_type:
1902 case DW_TAG_class_type:
1903 {
1904 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001905 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001906 GetObjectFile()->GetModule()->LogMessage (log.get(),
1907 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1908 die->GetOffset(),
1909 DW_TAG_value_to_name(die->Tag()),
1910 die->GetName(this, cu),
1911 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001912//
1913// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1914// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1915// {
1916// if (log)
1917// GetObjectFile()->GetModule()->LogMessage (log.get(),
1918// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1919// die->GetOffset(),
1920// DW_TAG_value_to_name(die->Tag()),
1921// die->GetName(this, cu),
1922// decl_ctx_die->GetOffset());
1923// // Ask the type to complete itself if it already hasn't since if we
1924// // want a function (method or static) from a class, the class must
1925// // create itself and add it's own methods and class functions.
1926// if (parent_type)
1927// parent_type->GetClangFullType();
1928// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001929 }
1930 break;
1931
1932 default:
1933 break;
1934 }
1935 return ResolveType (cu, die);
1936 }
1937 return NULL;
1938}
1939
Greg Clayton6beaaa62011-01-17 03:46:26 +00001940// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1941// SymbolFileDWARF objects to detect if this DWARF file is the one that
1942// can resolve a clang_type.
1943bool
1944SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1945{
1946 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1947 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1948 return die != NULL;
1949}
1950
1951
Greg Clayton1be10fc2010-09-29 01:12:09 +00001952lldb::clang_type_t
1953SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1954{
1955 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001956 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1957 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001958 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001959 {
1960 // We have already resolved this type...
1961 return clang_type;
1962 }
1963 // Once we start resolving this type, remove it from the forward declaration
1964 // map in case anyone child members or other types require this type to get resolved.
1965 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1966 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001967 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001968
Greg Clayton1be10fc2010-09-29 01:12:09 +00001969
Greg Clayton85ae2e12011-10-18 23:36:41 +00001970 // Disable external storage for this type so we don't get anymore
1971 // clang::ExternalASTSource queries for this type.
1972 ClangASTContext::SetHasExternalStorage (clang_type, false);
1973
Greg Clayton450e3f32010-10-12 02:24:53 +00001974 DWARFDebugInfo* debug_info = DebugInfo();
1975
Greg Clayton53eb1c22012-04-02 22:59:12 +00001976 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001977 Type *type = m_die_to_type.lookup (die);
1978
1979 const dw_tag_t tag = die->Tag();
1980
Greg Claytonbaf95da2012-03-30 23:50:54 +00001981 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001982 if (log)
Greg Claytonbaf95da2012-03-30 23:50:54 +00001983 {
Greg Claytond61c0fc2012-04-23 22:55:20 +00001984 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log.get(),
1985 "0x%8.8llx: %s '%s' resolving forward declaration...",
1986 MakeUserID(die->GetOffset()),
1987 DW_TAG_value_to_name(tag),
1988 type->GetName().AsCString());
Greg Claytonbaf95da2012-03-30 23:50:54 +00001989
Greg Claytonbaf95da2012-03-30 23:50:54 +00001990 }
Greg Clayton1be10fc2010-09-29 01:12:09 +00001991 assert (clang_type);
1992 DWARFDebugInfoEntry::Attributes attributes;
1993
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001994 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001995
1996 switch (tag)
1997 {
1998 case DW_TAG_structure_type:
1999 case DW_TAG_union_type:
2000 case DW_TAG_class_type:
Greg Claytonc93237c2010-10-01 20:48:32 +00002001 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002002 LayoutInfo layout_info;
Sean Callanan77a1fd32012-02-27 20:07:01 +00002003
Greg Clayton1be10fc2010-09-29 01:12:09 +00002004 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002005 if (die->HasChildren())
Greg Claytonc93237c2010-10-01 20:48:32 +00002006 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002007
Sean Callanan77a1fd32012-02-27 20:07:01 +00002008 LanguageType class_language = eLanguageTypeUnknown;
2009 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2010 if (is_objc_class)
Greg Clayton219cf312012-03-30 00:51:13 +00002011 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002012 class_language = eLanguageTypeObjC;
Greg Clayton219cf312012-03-30 00:51:13 +00002013 // For objective C we don't start the definition when
2014 // the class is created.
2015 ast.StartTagDeclarationDefinition (clang_type);
2016 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002017
2018 int tag_decl_kind = -1;
2019 AccessType default_accessibility = eAccessNone;
2020 if (tag == DW_TAG_structure_type)
2021 {
2022 tag_decl_kind = clang::TTK_Struct;
2023 default_accessibility = eAccessPublic;
2024 }
2025 else if (tag == DW_TAG_union_type)
2026 {
2027 tag_decl_kind = clang::TTK_Union;
2028 default_accessibility = eAccessPublic;
2029 }
2030 else if (tag == DW_TAG_class_type)
2031 {
2032 tag_decl_kind = clang::TTK_Class;
2033 default_accessibility = eAccessPrivate;
2034 }
2035
Greg Clayton53eb1c22012-04-02 22:59:12 +00002036 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002037 std::vector<clang::CXXBaseSpecifier *> base_classes;
2038 std::vector<int> member_accessibilities;
2039 bool is_a_class = false;
2040 // Parse members and base classes first
2041 DWARFDIECollection member_function_dies;
2042
2043 ParseChildMembers (sc,
Greg Clayton53eb1c22012-04-02 22:59:12 +00002044 dwarf_cu,
Sean Callanan77a1fd32012-02-27 20:07:01 +00002045 die,
2046 clang_type,
2047 class_language,
2048 base_classes,
2049 member_accessibilities,
2050 member_function_dies,
2051 default_accessibility,
2052 is_a_class,
2053 layout_info);
2054
2055 // Now parse any methods if there were any...
2056 size_t num_functions = member_function_dies.Size();
2057 if (num_functions > 0)
2058 {
2059 for (size_t i=0; i<num_functions; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002060 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002061 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytoncaab74e2012-01-28 00:48:57 +00002062 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002063 }
2064
2065 if (class_language == eLanguageTypeObjC)
2066 {
Greg Clayton84db9102012-03-26 23:03:23 +00002067 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
Sean Callanan77a1fd32012-02-27 20:07:01 +00002068 if (!class_str.empty())
Greg Claytoncaab74e2012-01-28 00:48:57 +00002069 {
Greg Clayton450e3f32010-10-12 02:24:53 +00002070
Sean Callanan77a1fd32012-02-27 20:07:01 +00002071 DIEArray method_die_offsets;
2072 if (m_using_apple_tables)
Greg Clayton95d87902011-11-11 03:16:25 +00002073 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002074 if (m_apple_objc_ap.get())
2075 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2076 }
2077 else
2078 {
2079 if (!m_indexed)
2080 Index ();
Greg Claytoncaab74e2012-01-28 00:48:57 +00002081
Sean Callanan77a1fd32012-02-27 20:07:01 +00002082 ConstString class_name (class_str.c_str());
2083 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2084 }
2085
2086 if (!method_die_offsets.empty())
2087 {
2088 DWARFDebugInfo* debug_info = DebugInfo();
2089
2090 DWARFCompileUnit* method_cu = NULL;
2091 const size_t num_matches = method_die_offsets.size();
2092 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00002093 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002094 const dw_offset_t die_offset = method_die_offsets[i];
2095 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2096
2097 if (method_die)
2098 ResolveType (method_cu, method_die);
2099 else
Greg Claytoncaab74e2012-01-28 00:48:57 +00002100 {
Sean Callanan77a1fd32012-02-27 20:07:01 +00002101 if (m_using_apple_tables)
2102 {
2103 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2104 die_offset, class_str.c_str());
2105 }
2106 }
2107 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002108 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002109 }
2110 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002111
2112 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2113 // need to tell the clang type it is actually a class.
2114 if (class_language != eLanguageTypeObjC)
2115 {
2116 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2117 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2118 }
2119
2120 // Since DW_TAG_structure_type gets used for both classes
2121 // and structures, we may need to set any DW_TAG_member
2122 // fields to have a "private" access if none was specified.
2123 // When we parsed the child members we tracked that actual
2124 // accessibility value for each DW_TAG_member in the
2125 // "member_accessibilities" array. If the value for the
2126 // member is zero, then it was set to the "default_accessibility"
2127 // which for structs was "public". Below we correct this
2128 // by setting any fields to "private" that weren't correctly
2129 // set.
2130 if (is_a_class && !member_accessibilities.empty())
2131 {
2132 // This is a class and all members that didn't have
2133 // their access specified are private.
2134 ast.SetDefaultAccessForRecordFields (clang_type,
2135 eAccessPrivate,
2136 &member_accessibilities.front(),
2137 member_accessibilities.size());
2138 }
2139
2140 if (!base_classes.empty())
2141 {
2142 ast.SetBaseClassesForClassType (clang_type,
2143 &base_classes.front(),
2144 base_classes.size());
2145
2146 // Clang will copy each CXXBaseSpecifier in "base_classes"
2147 // so we have to free them all.
2148 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2149 base_classes.size());
2150 }
Greg Clayton450e3f32010-10-12 02:24:53 +00002151 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002152 }
Sean Callanane8c0cfb2012-03-02 01:03:45 +00002153
2154 ast.BuildIndirectFields (clang_type);
2155
Sean Callanan77a1fd32012-02-27 20:07:01 +00002156 ast.CompleteTagDeclarationDefinition (clang_type);
Sean Callanan5b26f272012-02-04 08:49:35 +00002157
Greg Claytoncaab74e2012-01-28 00:48:57 +00002158 if (!layout_info.field_offsets.empty())
2159 {
2160 if (type)
2161 layout_info.bit_size = type->GetByteSize() * 8;
2162 if (layout_info.bit_size == 0)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002163 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
Greg Claytoncaab74e2012-01-28 00:48:57 +00002164 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2165 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2166 if (record_type)
2167 {
2168 const clang::RecordDecl *record_decl = record_type->getDecl();
2169
2170 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002171 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002172 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002173 "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 +00002174 clang_type,
2175 record_decl,
2176 layout_info.bit_size,
2177 layout_info.alignment,
2178 (uint32_t)layout_info.field_offsets.size());
Sean Callanan77a1fd32012-02-27 20:07:01 +00002179
Greg Clayton821ac6d2012-01-28 02:22:27 +00002180 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2181 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2182 {
2183 GetObjectFile()->GetModule()->LogMessage (log.get(),
2184 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2185 clang_type,
2186 (uint32_t)pos->second,
2187 pos->first->getNameAsString().c_str());
2188 }
2189 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002190 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2191 }
2192 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002193 }
Sean Callanan77a1fd32012-02-27 20:07:01 +00002194
Greg Claytonc93237c2010-10-01 20:48:32 +00002195 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002196
2197 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002198 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002199 if (die->HasChildren())
2200 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002201 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2202 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002203 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002204 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002205 return clang_type;
2206
2207 default:
2208 assert(false && "not a forward clang type decl!");
2209 break;
2210 }
2211 return NULL;
2212}
2213
Greg Claytonc685f8e2010-09-15 04:15:46 +00002214Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002215SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002216{
2217 if (type_die != NULL)
2218 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002219 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002220
Greg Claytonc685f8e2010-09-15 04:15:46 +00002221 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002222 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002223
Greg Clayton24739922010-10-13 03:15:28 +00002224 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002225 {
2226 if (type != DIE_IS_BEING_PARSED)
2227 return type;
2228
2229 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00002230 type_die->GetOffset(),
2231 DW_TAG_value_to_name(type_die->Tag()),
2232 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00002233
2234 }
2235 else
2236 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002237 }
2238 return NULL;
2239}
2240
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00002242SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002243{
2244 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002245 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002246 {
2247 // The symbol vendor doesn't know about this compile unit, we
2248 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00002249 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002250 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00002251 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002252}
2253
2254bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00002255SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256{
2257 sc.Clear();
2258 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00002259 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002260
Greg Clayton81c22f62011-10-19 18:09:39 +00002261 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002263 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002264
2265 if (sc.function)
2266 {
Greg Claytone72dfb32012-02-24 01:59:29 +00002267 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002268 return true;
2269 }
2270
2271 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272}
2273
2274uint32_t
2275SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2276{
2277 Timer scoped_timer(__PRETTY_FUNCTION__,
2278 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
Greg Claytone72dfb32012-02-24 01:59:29 +00002279 so_addr.GetSection().get(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280 so_addr.GetOffset(),
2281 resolve_scope);
2282 uint32_t resolved = 0;
2283 if (resolve_scope & ( eSymbolContextCompUnit |
2284 eSymbolContextFunction |
2285 eSymbolContextBlock |
2286 eSymbolContextLineEntry))
2287 {
2288 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002290 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002291 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002292 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002293 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002294 if (cu_offset != DW_INVALID_OFFSET)
2295 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002296 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002297 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2298 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002299 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002300 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002301 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002302 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002303 resolved |= eSymbolContextCompUnit;
2304
2305 if (resolve_scope & eSymbolContextLineEntry)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002306 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002307 LineTable *line_table = sc.comp_unit->GetLineTable();
2308 if (line_table != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002309 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002310 if (so_addr.IsLinkedAddress())
2311 {
2312 Address linked_addr (so_addr);
2313 linked_addr.ResolveLinkedAddress();
2314 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2315 {
2316 resolved |= eSymbolContextLineEntry;
2317 }
2318 }
2319 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002320 {
2321 resolved |= eSymbolContextLineEntry;
2322 }
2323 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002324 }
2325
2326 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2327 {
2328 DWARFDebugInfoEntry *function_die = NULL;
2329 DWARFDebugInfoEntry *block_die = NULL;
2330 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002332 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2333 }
2334 else
2335 {
2336 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2337 }
2338
2339 if (function_die != NULL)
2340 {
2341 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2342 if (sc.function == NULL)
2343 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2344 }
2345 else
2346 {
2347 // We might have had a compile unit that had discontiguous
2348 // address ranges where the gaps are symbols that don't have
2349 // any debug info. Discontiguous compile unit address ranges
2350 // should only happen when there aren't other functions from
2351 // other compile units in these gaps. This helps keep the size
2352 // of the aranges down.
2353 sc.comp_unit = NULL;
2354 resolved &= ~eSymbolContextCompUnit;
2355 }
2356
2357 if (sc.function != NULL)
2358 {
2359 resolved |= eSymbolContextFunction;
2360
2361 if (resolve_scope & eSymbolContextBlock)
2362 {
2363 Block& block = sc.function->GetBlock (true);
2364
2365 if (block_die != NULL)
2366 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2367 else
2368 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2369 if (sc.block)
2370 resolved |= eSymbolContextBlock;
2371 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002372 }
2373 }
2374 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002375 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002376 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002377 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2378 cu_offset,
2379 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002380 }
2381 }
2382 }
2383 }
2384 }
2385 return resolved;
2386}
2387
2388
2389
2390uint32_t
2391SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2392{
2393 const uint32_t prev_size = sc_list.GetSize();
2394 if (resolve_scope & eSymbolContextCompUnit)
2395 {
2396 DWARFDebugInfo* debug_info = DebugInfo();
2397 if (debug_info)
2398 {
2399 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00002400 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002401
Greg Clayton53eb1c22012-04-02 22:59:12 +00002402 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002403 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002404 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002405 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2406 if (check_inlines || file_spec_matches_cu_file_spec)
2407 {
2408 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00002409 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00002410 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002411 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002412 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002413
Greg Clayton526a4ae2012-05-16 22:09:01 +00002414 // If we are looking for inline functions only and we don't
2415 // find it in the support files, we are done.
2416 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002417 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002418 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2419 if (file_idx == UINT32_MAX)
2420 continue;
2421 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002422
Greg Clayton526a4ae2012-05-16 22:09:01 +00002423 if (line != 0)
2424 {
2425 LineTable *line_table = sc.comp_unit->GetLineTable();
2426
2427 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002428 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002429 // We will have already looked up the file index if
2430 // we are searching for inline entries.
2431 if (!check_inlines)
2432 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002433
Greg Clayton526a4ae2012-05-16 22:09:01 +00002434 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002435 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002436 uint32_t found_line;
2437 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2438 found_line = sc.line_entry.line;
2439
2440 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002441 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002442 sc.function = NULL;
2443 sc.block = NULL;
2444 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002445 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002446 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2447 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002448 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002449 DWARFDebugInfoEntry *function_die = NULL;
2450 DWARFDebugInfoEntry *block_die = NULL;
2451 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002452
Greg Clayton526a4ae2012-05-16 22:09:01 +00002453 if (function_die != NULL)
2454 {
2455 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2456 if (sc.function == NULL)
2457 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2458 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002459
Greg Clayton526a4ae2012-05-16 22:09:01 +00002460 if (sc.function != NULL)
2461 {
2462 Block& block = sc.function->GetBlock (true);
2463
2464 if (block_die != NULL)
2465 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2466 else
2467 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2468 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002469 }
2470 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002471
Greg Clayton526a4ae2012-05-16 22:09:01 +00002472 sc_list.Append(sc);
2473 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2474 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002475 }
2476 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002477 else if (file_spec_matches_cu_file_spec && !check_inlines)
2478 {
2479 // only append the context if we aren't looking for inline call sites
2480 // by file and line and if the file spec matches that of the compile unit
2481 sc_list.Append(sc);
2482 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002483 }
2484 else if (file_spec_matches_cu_file_spec && !check_inlines)
2485 {
2486 // only append the context if we aren't looking for inline call sites
2487 // by file and line and if the file spec matches that of the compile unit
2488 sc_list.Append(sc);
2489 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490
Greg Clayton526a4ae2012-05-16 22:09:01 +00002491 if (!check_inlines)
2492 break;
2493 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002494 }
2495 }
2496 }
2497 }
2498 return sc_list.GetSize() - prev_size;
2499}
2500
2501void
2502SymbolFileDWARF::Index ()
2503{
2504 if (m_indexed)
2505 return;
2506 m_indexed = true;
2507 Timer scoped_timer (__PRETTY_FUNCTION__,
2508 "SymbolFileDWARF::Index (%s)",
2509 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2510
2511 DWARFDebugInfo* debug_info = DebugInfo();
2512 if (debug_info)
2513 {
2514 uint32_t cu_idx = 0;
2515 const uint32_t num_compile_units = GetNumCompileUnits();
2516 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2517 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002518 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002519
Greg Clayton53eb1c22012-04-02 22:59:12 +00002520 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002521
Greg Clayton53eb1c22012-04-02 22:59:12 +00002522 dwarf_cu->Index (cu_idx,
2523 m_function_basename_index,
2524 m_function_fullname_index,
2525 m_function_method_index,
2526 m_function_selector_index,
2527 m_objc_class_selectors_index,
2528 m_global_index,
2529 m_type_index,
2530 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002531
2532 // Keep memory down by clearing DIEs if this generate function
2533 // caused them to be parsed
2534 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002535 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002536 }
2537
Greg Claytond4a2b372011-09-12 23:21:58 +00002538 m_function_basename_index.Finalize();
2539 m_function_fullname_index.Finalize();
2540 m_function_method_index.Finalize();
2541 m_function_selector_index.Finalize();
2542 m_objc_class_selectors_index.Finalize();
2543 m_global_index.Finalize();
2544 m_type_index.Finalize();
2545 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002546
Greg Clayton24739922010-10-13 03:15:28 +00002547#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002548 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002549 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002550 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2551 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002552 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2553 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2554 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2555 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2556 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2557 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002558 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002559 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002560#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002561 }
2562}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002563
2564bool
2565SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2566{
2567 if (namespace_decl == NULL)
2568 {
2569 // Invalid namespace decl which means we aren't matching only things
2570 // in this symbol file, so return true to indicate it matches this
2571 // symbol file.
2572 return true;
2573 }
2574
2575 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2576
2577 if (namespace_ast == NULL)
2578 return true; // No AST in the "namespace_decl", return true since it
2579 // could then match any symbol file, including this one
2580
2581 if (namespace_ast == GetClangASTContext().getASTContext())
2582 return true; // The ASTs match, return true
2583
2584 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002585 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2586
2587 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002588 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002589
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002590 return false;
2591}
2592
Greg Clayton2506a7a2011-10-12 23:34:26 +00002593bool
2594SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2595 DWARFCompileUnit* cu,
2596 const DWARFDebugInfoEntry* die)
2597{
2598 // No namespace specified, so the answesr i
2599 if (namespace_decl == NULL)
2600 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002601
2602 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002603
Greg Clayton437a1352012-04-09 22:43:43 +00002604 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
2605 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002606 if (decl_ctx_die)
Greg Clayton437a1352012-04-09 22:43:43 +00002607 {
Greg Clayton2506a7a2011-10-12 23:34:26 +00002608 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
Greg Clayton437a1352012-04-09 22:43:43 +00002609
Greg Clayton2506a7a2011-10-12 23:34:26 +00002610 if (clang_namespace_decl)
2611 {
2612 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002613 {
2614 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002615 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002616 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002617 }
2618
Greg Clayton437a1352012-04-09 22:43:43 +00002619 if (clang_namespace_decl == die_clang_decl_ctx)
2620 return true;
2621 else
Greg Clayton2506a7a2011-10-12 23:34:26 +00002622 return false;
Greg Clayton2506a7a2011-10-12 23:34:26 +00002623 }
2624 else
2625 {
2626 // We have a namespace_decl that was not NULL but it contained
2627 // a NULL "clang::NamespaceDecl", so this means the global namespace
2628 // So as long the the contained decl context DIE isn't a namespace
2629 // we should be ok.
2630 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2631 return true;
2632 }
2633 }
Sean Callananebe60672011-10-13 21:50:33 +00002634
2635 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002636 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002637
Greg Clayton2506a7a2011-10-12 23:34:26 +00002638 return false;
2639}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002640uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002641SymbolFileDWARF::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 +00002642{
Greg Clayton21f2a492011-10-06 00:09:08 +00002643 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2644
2645 if (log)
2646 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002647 GetObjectFile()->GetModule()->LogMessage (log.get(),
2648 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2649 name.GetCString(),
2650 namespace_decl,
2651 append,
2652 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002653 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002654
2655 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2656 return 0;
2657
Greg Claytonc685f8e2010-09-15 04:15:46 +00002658 DWARFDebugInfo* info = DebugInfo();
2659 if (info == NULL)
2660 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002661
2662 // If we aren't appending the results to this list, then clear the list
2663 if (!append)
2664 variables.Clear();
2665
2666 // Remember how many variables are in the list before we search in case
2667 // we are appending the results to a variable list.
2668 const uint32_t original_size = variables.GetSize();
2669
Greg Claytond4a2b372011-09-12 23:21:58 +00002670 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002671
Greg Clayton97fbc342011-10-20 22:30:33 +00002672 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002673 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002674 if (m_apple_names_ap.get())
2675 {
2676 const char *name_cstr = name.GetCString();
2677 const char *base_name_start;
2678 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002679
Greg Clayton97fbc342011-10-20 22:30:33 +00002680 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2681 base_name_start = name_cstr;
2682
2683 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2684 }
Greg Clayton7f995132011-10-04 22:41:51 +00002685 }
2686 else
2687 {
2688 // Index the DWARF if we haven't already
2689 if (!m_indexed)
2690 Index ();
2691
2692 m_global_index.Find (name, die_offsets);
2693 }
2694
Greg Clayton437a1352012-04-09 22:43:43 +00002695 const size_t num_die_matches = die_offsets.size();
2696 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002697 {
Greg Clayton7f995132011-10-04 22:41:51 +00002698 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002699 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002700 assert (sc.module_sp);
2701
Greg Claytond4a2b372011-09-12 23:21:58 +00002702 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002703 DWARFCompileUnit* dwarf_cu = NULL;
2704 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002705 bool done = false;
2706 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002707 {
2708 const dw_offset_t die_offset = die_offsets[i];
2709 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002710
Greg Clayton95d87902011-11-11 03:16:25 +00002711 if (die)
2712 {
Greg Clayton437a1352012-04-09 22:43:43 +00002713 switch (die->Tag())
2714 {
2715 default:
2716 case DW_TAG_subprogram:
2717 case DW_TAG_inlined_subroutine:
2718 case DW_TAG_try_block:
2719 case DW_TAG_catch_block:
2720 break;
2721
2722 case DW_TAG_variable:
2723 {
2724 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Greg Clayton437a1352012-04-09 22:43:43 +00002725
2726 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2727 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002728
Greg Clayton437a1352012-04-09 22:43:43 +00002729 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002730
Greg Clayton437a1352012-04-09 22:43:43 +00002731 if (variables.GetSize() - original_size >= max_matches)
2732 done = true;
2733 }
2734 break;
2735 }
Greg Clayton95d87902011-11-11 03:16:25 +00002736 }
2737 else
2738 {
2739 if (m_using_apple_tables)
2740 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002741 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2742 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002743 }
2744 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002745 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002746 }
2747
2748 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002749 const uint32_t num_matches = variables.GetSize() - original_size;
2750 if (log && num_matches > 0)
2751 {
2752 GetObjectFile()->GetModule()->LogMessage (log.get(),
2753 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
2754 name.GetCString(),
2755 namespace_decl,
2756 append,
2757 max_matches,
2758 num_matches);
2759 }
2760 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002761}
2762
2763uint32_t
2764SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2765{
Greg Clayton21f2a492011-10-06 00:09:08 +00002766 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2767
2768 if (log)
2769 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002770 GetObjectFile()->GetModule()->LogMessage (log.get(),
2771 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2772 regex.GetText(),
2773 append,
2774 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002775 }
2776
Greg Claytonc685f8e2010-09-15 04:15:46 +00002777 DWARFDebugInfo* info = DebugInfo();
2778 if (info == NULL)
2779 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002780
2781 // If we aren't appending the results to this list, then clear the list
2782 if (!append)
2783 variables.Clear();
2784
2785 // Remember how many variables are in the list before we search in case
2786 // we are appending the results to a variable list.
2787 const uint32_t original_size = variables.GetSize();
2788
Greg Clayton7f995132011-10-04 22:41:51 +00002789 DIEArray die_offsets;
2790
Greg Clayton97fbc342011-10-20 22:30:33 +00002791 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002792 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002793 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002794 {
2795 DWARFMappedHash::DIEInfoArray hash_data_array;
2796 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2797 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2798 }
Greg Clayton7f995132011-10-04 22:41:51 +00002799 }
2800 else
2801 {
2802 // Index the DWARF if we haven't already
2803 if (!m_indexed)
2804 Index ();
2805
2806 m_global_index.Find (regex, die_offsets);
2807 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002808
Greg Claytonc685f8e2010-09-15 04:15:46 +00002809 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002810 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002811 assert (sc.module_sp);
2812
Greg Claytond4a2b372011-09-12 23:21:58 +00002813 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002814 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002815 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002816 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002817 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002818 DWARFDebugInfo* debug_info = DebugInfo();
2819 for (size_t i=0; i<num_matches; ++i)
2820 {
2821 const dw_offset_t die_offset = die_offsets[i];
2822 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002823
2824 if (die)
2825 {
2826 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002827
Greg Clayton95d87902011-11-11 03:16:25 +00002828 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002829
Greg Clayton95d87902011-11-11 03:16:25 +00002830 if (variables.GetSize() - original_size >= max_matches)
2831 break;
2832 }
2833 else
2834 {
2835 if (m_using_apple_tables)
2836 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002837 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2838 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002839 }
2840 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002841 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002842 }
2843
2844 // Return the number of variable that were appended to the list
2845 return variables.GetSize() - original_size;
2846}
2847
Greg Claytonaa044962011-10-13 00:59:38 +00002848
Jim Ingham4cda6e02011-10-07 22:23:45 +00002849bool
2850SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2851 DWARFCompileUnit *&dwarf_cu,
2852 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002853{
Greg Claytonaa044962011-10-13 00:59:38 +00002854 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2855 return ResolveFunction (dwarf_cu, die, sc_list);
2856}
2857
2858
2859bool
2860SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2861 const DWARFDebugInfoEntry *die,
2862 SymbolContextList& sc_list)
2863{
Greg Clayton9e315582011-09-02 04:03:59 +00002864 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002865
2866 if (die == NULL)
2867 return false;
2868
Jim Ingham4cda6e02011-10-07 22:23:45 +00002869 // If we were passed a die that is not a function, just return false...
2870 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2871 return false;
2872
2873 const DWARFDebugInfoEntry* inlined_die = NULL;
2874 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002875 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002876 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002877
Jim Ingham4cda6e02011-10-07 22:23:45 +00002878 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002879 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002880 if (die->Tag() == DW_TAG_subprogram)
2881 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002882 }
2883 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002884 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002885 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002886 {
2887 Address addr;
2888 // Parse all blocks if needed
2889 if (inlined_die)
2890 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002891 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002892 assert (sc.block != NULL);
2893 if (sc.block->GetStartAddress (addr) == false)
2894 addr.Clear();
2895 }
2896 else
2897 {
2898 sc.block = NULL;
2899 addr = sc.function->GetAddressRange().GetBaseAddress();
2900 }
2901
2902 if (addr.IsValid())
2903 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002904 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002905 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002906 }
2907 }
2908
Greg Claytonaa044962011-10-13 00:59:38 +00002909 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002910}
2911
Greg Clayton7f995132011-10-04 22:41:51 +00002912void
2913SymbolFileDWARF::FindFunctions (const ConstString &name,
2914 const NameToDIE &name_to_die,
2915 SymbolContextList& sc_list)
2916{
Greg Claytond4a2b372011-09-12 23:21:58 +00002917 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002918 if (name_to_die.Find (name, die_offsets))
2919 {
2920 ParseFunctions (die_offsets, sc_list);
2921 }
2922}
2923
2924
2925void
2926SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2927 const NameToDIE &name_to_die,
2928 SymbolContextList& sc_list)
2929{
2930 DIEArray die_offsets;
2931 if (name_to_die.Find (regex, die_offsets))
2932 {
2933 ParseFunctions (die_offsets, sc_list);
2934 }
2935}
2936
2937
2938void
2939SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2940 const DWARFMappedHash::MemoryTable &memory_table,
2941 SymbolContextList& sc_list)
2942{
2943 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002944 DWARFMappedHash::DIEInfoArray hash_data_array;
2945 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002946 {
Greg Claytond1767f02011-12-08 02:13:16 +00002947 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002948 ParseFunctions (die_offsets, sc_list);
2949 }
2950}
2951
2952void
2953SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2954 SymbolContextList& sc_list)
2955{
2956 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002957 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002958 {
Greg Clayton7f995132011-10-04 22:41:51 +00002959 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002960
2961 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002962 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002963 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002964 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002965 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002966 }
2967 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002968}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002969
Jim Ingham4cda6e02011-10-07 22:23:45 +00002970bool
2971SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2972 const DWARFCompileUnit *dwarf_cu,
2973 uint32_t name_type_mask,
2974 const char *partial_name,
2975 const char *base_name_start,
2976 const char *base_name_end)
2977{
2978 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2979 if (name_type_mask == eFunctionNameTypeMethod
2980 || name_type_mask == eFunctionNameTypeBase)
2981 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002982 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2983 if (!containing_decl_ctx)
2984 return false;
2985
2986 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2987
2988 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2989 return false;
2990 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2991 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002992 }
2993
2994 // Now we need to check whether the name we got back for this type matches the extra specifications
2995 // that were in the name we're looking up:
2996 if (base_name_start != partial_name || *base_name_end != '\0')
2997 {
2998 // First see if the stuff to the left matches the full name. To do that let's see if
2999 // we can pull out the mips linkage name attribute:
3000
3001 Mangled best_name;
3002
3003 DWARFDebugInfoEntry::Attributes attributes;
3004 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3005 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3006 if (idx != UINT32_MAX)
3007 {
3008 DWARFFormValue form_value;
3009 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3010 {
3011 const char *name = form_value.AsCString(&get_debug_str_data());
3012 best_name.SetValue (name, true);
3013 }
3014 }
3015 if (best_name)
3016 {
3017 const char *demangled = best_name.GetDemangledName().GetCString();
3018 if (demangled)
3019 {
3020 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00003021 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3022 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003023 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00003024 else
3025 {
3026 // Sort out the case where our name is something like "Process::Destroy" and the match is
3027 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3028 // namespace boundaries...
3029
3030 if (partial_name[0] == ':' && partial_name[1] == ':')
3031 {
3032 // The partial name was already on a namespace boundary so all matches are good.
3033 return true;
3034 }
3035 else if (partial_in_demangled == demangled)
3036 {
3037 // They both start the same, so this is an good match.
3038 return true;
3039 }
3040 else
3041 {
3042 if (partial_in_demangled - demangled == 1)
3043 {
3044 // Only one character difference, can't be a namespace boundary...
3045 return false;
3046 }
3047 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3048 {
3049 // We are on a namespace boundary, so this is also good.
3050 return true;
3051 }
3052 else
3053 return false;
3054 }
3055 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003056 }
3057 }
3058 }
3059
3060 return true;
3061}
Greg Claytonc685f8e2010-09-15 04:15:46 +00003062
Greg Clayton0c5cd902010-06-28 21:30:43 +00003063uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00003064SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00003065 const lldb_private::ClangNamespaceDecl *namespace_decl,
Sean Callanan9df05fb2012-02-10 22:52:19 +00003066 uint32_t name_type_mask,
3067 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00003068 bool append,
3069 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00003070{
3071 Timer scoped_timer (__PRETTY_FUNCTION__,
3072 "SymbolFileDWARF::FindFunctions (name = '%s')",
3073 name.AsCString());
3074
Greg Clayton21f2a492011-10-06 00:09:08 +00003075 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3076
3077 if (log)
3078 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003079 GetObjectFile()->GetModule()->LogMessage (log.get(),
3080 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3081 name.GetCString(),
3082 name_type_mask,
3083 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003084 }
3085
Greg Clayton0c5cd902010-06-28 21:30:43 +00003086 // If we aren't appending the results to this list, then clear the list
3087 if (!append)
3088 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003089
3090 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3091 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003092
3093 // If name is empty then we won't find anything.
3094 if (name.IsEmpty())
3095 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00003096
3097 // Remember how many sc_list are in the list before we search in case
3098 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00003099
Greg Clayton9e315582011-09-02 04:03:59 +00003100 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00003101
Jim Ingham4cda6e02011-10-07 22:23:45 +00003102 const char *name_cstr = name.GetCString();
3103 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3104 const char *base_name_start = name_cstr;
3105 const char *base_name_end = name_cstr + strlen(name_cstr);
3106
3107 if (name_type_mask & eFunctionNameTypeAuto)
3108 {
3109 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3110 effective_name_type_mask = eFunctionNameTypeFull;
3111 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3112 effective_name_type_mask = eFunctionNameTypeFull;
3113 else
3114 {
3115 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3116 effective_name_type_mask |= eFunctionNameTypeSelector;
3117
3118 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3119 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3120 }
3121 }
3122 else
3123 {
3124 effective_name_type_mask = name_type_mask;
3125 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3126 {
3127 // If they've asked for a CPP method or function name and it can't be that, we don't
3128 // even need to search for CPP methods or names.
3129 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3130 {
3131 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3132 if (effective_name_type_mask == eFunctionNameTypeNone)
3133 return 0;
3134 }
3135 }
3136
3137 if (effective_name_type_mask & eFunctionNameTypeSelector)
3138 {
3139 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3140 {
3141 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3142 if (effective_name_type_mask == eFunctionNameTypeNone)
3143 return 0;
3144 }
3145 }
3146 }
3147
3148 DWARFDebugInfo* info = DebugInfo();
3149 if (info == NULL)
3150 return 0;
3151
Greg Claytonaa044962011-10-13 00:59:38 +00003152 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00003153 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00003154 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003155 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00003156 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003157
3158 DIEArray die_offsets;
3159
3160 uint32_t num_matches = 0;
3161
3162 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00003163 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003164 // If they asked for the full name, match what they typed. At some point we may
3165 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3166 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00003167 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003168 for (uint32_t i = 0; i < num_matches; i++)
3169 {
Greg Clayton95d87902011-11-11 03:16:25 +00003170 const dw_offset_t die_offset = die_offsets[i];
3171 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00003172 if (die)
3173 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003174 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3175 continue;
3176
Sean Callanan9df05fb2012-02-10 22:52:19 +00003177 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3178 continue;
3179
Greg Claytonaa044962011-10-13 00:59:38 +00003180 ResolveFunction (dwarf_cu, die, sc_list);
3181 }
Greg Clayton95d87902011-11-11 03:16:25 +00003182 else
3183 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003184 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3185 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003186 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003187 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003188 }
3189 else
3190 {
3191 if (effective_name_type_mask & eFunctionNameTypeSelector)
3192 {
3193 if (namespace_decl && *namespace_decl)
3194 return 0; // no selectors in namespaces
3195
3196 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3197 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3198 // and if it is an ObjC method name, we're good.
3199
3200 for (uint32_t i = 0; i < num_matches; i++)
3201 {
Greg Clayton95d87902011-11-11 03:16:25 +00003202 const dw_offset_t die_offset = die_offsets[i];
3203 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003204 if (die)
3205 {
3206 const char *die_name = die->GetName(this, dwarf_cu);
3207 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Sean Callanan9df05fb2012-02-10 22:52:19 +00003208 {
3209 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3210 continue;
3211
Greg Clayton97fbc342011-10-20 22:30:33 +00003212 ResolveFunction (dwarf_cu, die, sc_list);
Sean Callanan9df05fb2012-02-10 22:52:19 +00003213 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003214 }
Greg Clayton95d87902011-11-11 03:16:25 +00003215 else
3216 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003217 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3218 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003219 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003220 }
3221 die_offsets.clear();
3222 }
3223
3224 if (effective_name_type_mask & eFunctionNameTypeMethod
3225 || effective_name_type_mask & eFunctionNameTypeBase)
3226 {
3227 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3228 (namespace_decl && *namespace_decl))
3229 return 0; // no methods in namespaces
3230
3231 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3232 // extract the base name, look that up, and if there is any other information in the name we were
3233 // passed in we have to post-filter based on that.
3234
3235 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3236 std::string base_name(base_name_start, base_name_end - base_name_start);
3237 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3238
3239 for (uint32_t i = 0; i < num_matches; i++)
3240 {
Greg Clayton95d87902011-11-11 03:16:25 +00003241 const dw_offset_t die_offset = die_offsets[i];
3242 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003243 if (die)
3244 {
3245 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3246 continue;
3247
3248 if (!FunctionDieMatchesPartialName(die,
3249 dwarf_cu,
3250 effective_name_type_mask,
3251 name_cstr,
3252 base_name_start,
3253 base_name_end))
3254 continue;
Sean Callanan9df05fb2012-02-10 22:52:19 +00003255
3256 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3257 continue;
Greg Clayton97fbc342011-10-20 22:30:33 +00003258
3259 // If we get to here, the die is good, and we should add it:
3260 ResolveFunction (dwarf_cu, die, sc_list);
3261 }
Greg Clayton95d87902011-11-11 03:16:25 +00003262 else
3263 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003264 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3265 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003266 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003267 }
3268 die_offsets.clear();
3269 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003270 }
3271 }
Greg Clayton7f995132011-10-04 22:41:51 +00003272 }
3273 else
3274 {
3275
3276 // Index the DWARF if we haven't already
3277 if (!m_indexed)
3278 Index ();
3279
Greg Clayton7f995132011-10-04 22:41:51 +00003280 if (name_type_mask & eFunctionNameTypeFull)
3281 FindFunctions (name, m_function_fullname_index, sc_list);
3282
Jim Ingham4cda6e02011-10-07 22:23:45 +00003283 std::string base_name(base_name_start, base_name_end - base_name_start);
3284 ConstString base_name_const(base_name.c_str());
3285 DIEArray die_offsets;
3286 DWARFCompileUnit *dwarf_cu = NULL;
3287
3288 if (effective_name_type_mask & eFunctionNameTypeBase)
3289 {
3290 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003291 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003292 {
Greg Claytonaa044962011-10-13 00:59:38 +00003293 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3294 if (die)
3295 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003296 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3297 continue;
3298
Greg Claytonaa044962011-10-13 00:59:38 +00003299 if (!FunctionDieMatchesPartialName(die,
3300 dwarf_cu,
3301 effective_name_type_mask,
3302 name_cstr,
3303 base_name_start,
3304 base_name_end))
3305 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003306
Sean Callanan9df05fb2012-02-10 22:52:19 +00003307 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3308 continue;
3309
Greg Claytonaa044962011-10-13 00:59:38 +00003310 // If we get to here, the die is good, and we should add it:
3311 ResolveFunction (dwarf_cu, die, sc_list);
3312 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003313 }
3314 die_offsets.clear();
3315 }
3316
Jim Inghamea8005a2011-10-11 01:18:11 +00003317 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003318 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003319 if (namespace_decl && *namespace_decl)
3320 return 0; // no methods in namespaces
3321
Jim Ingham4cda6e02011-10-07 22:23:45 +00003322 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3323 {
Greg Claytonaa044962011-10-13 00:59:38 +00003324 for (uint32_t i = 0; i < num_base; i++)
3325 {
3326 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3327 if (die)
3328 {
3329 if (!FunctionDieMatchesPartialName(die,
3330 dwarf_cu,
3331 effective_name_type_mask,
3332 name_cstr,
3333 base_name_start,
3334 base_name_end))
3335 continue;
3336
Sean Callanan9df05fb2012-02-10 22:52:19 +00003337 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3338 continue;
3339
Greg Claytonaa044962011-10-13 00:59:38 +00003340 // If we get to here, the die is good, and we should add it:
3341 ResolveFunction (dwarf_cu, die, sc_list);
3342 }
3343 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003344 }
3345 die_offsets.clear();
3346 }
Greg Clayton7f995132011-10-04 22:41:51 +00003347
Sean Callanan213fdb82011-10-13 01:49:10 +00003348 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003349 {
Greg Clayton7f995132011-10-04 22:41:51 +00003350 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003351 }
3352
Greg Clayton4d01ace2011-09-29 16:58:15 +00003353 }
3354
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003355 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00003356 const uint32_t num_matches = sc_list.GetSize() - original_size;
3357
3358 if (log && num_matches > 0)
3359 {
3360 GetObjectFile()->GetModule()->LogMessage (log.get(),
3361 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3362 name.GetCString(),
3363 name_type_mask,
3364 append,
3365 num_matches);
3366 }
3367 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003368}
3369
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003370uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00003371SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003372{
3373 Timer scoped_timer (__PRETTY_FUNCTION__,
3374 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3375 regex.GetText());
3376
Greg Clayton21f2a492011-10-06 00:09:08 +00003377 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3378
3379 if (log)
3380 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003381 GetObjectFile()->GetModule()->LogMessage (log.get(),
3382 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3383 regex.GetText(),
3384 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003385 }
3386
3387
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003388 // If we aren't appending the results to this list, then clear the list
3389 if (!append)
3390 sc_list.Clear();
3391
3392 // Remember how many sc_list are in the list before we search in case
3393 // we are appending the results to a variable list.
3394 uint32_t original_size = sc_list.GetSize();
3395
Greg Clayton97fbc342011-10-20 22:30:33 +00003396 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003397 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003398 if (m_apple_names_ap.get())
3399 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003400 }
3401 else
3402 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003403 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003404 if (!m_indexed)
3405 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003406
Greg Clayton7f995132011-10-04 22:41:51 +00003407 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003408
Greg Clayton7f995132011-10-04 22:41:51 +00003409 FindFunctions (regex, m_function_fullname_index, sc_list);
3410 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003411
3412 // Return the number of variable that were appended to the list
3413 return sc_list.GetSize() - original_size;
3414}
Jim Ingham318c9f22011-08-26 19:44:13 +00003415
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003416uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003417SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3418 const ConstString &name,
3419 const lldb_private::ClangNamespaceDecl *namespace_decl,
3420 bool append,
3421 uint32_t max_matches,
3422 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003423{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003424 DWARFDebugInfo* info = DebugInfo();
3425 if (info == NULL)
3426 return 0;
3427
Greg Clayton21f2a492011-10-06 00:09:08 +00003428 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3429
3430 if (log)
3431 {
Greg Clayton437a1352012-04-09 22:43:43 +00003432 if (namespace_decl)
3433 {
3434 GetObjectFile()->GetModule()->LogMessage (log.get(),
3435 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3436 name.GetCString(),
3437 namespace_decl->GetNamespaceDecl(),
3438 namespace_decl->GetQualifiedName().c_str(),
3439 append,
3440 max_matches);
3441 }
3442 else
3443 {
3444 GetObjectFile()->GetModule()->LogMessage (log.get(),
3445 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3446 name.GetCString(),
3447 append,
3448 max_matches);
3449 }
Greg Clayton21f2a492011-10-06 00:09:08 +00003450 }
3451
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003452 // If we aren't appending the results to this list, then clear the list
3453 if (!append)
3454 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003455
3456 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3457 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003458
Greg Claytond4a2b372011-09-12 23:21:58 +00003459 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003460
Greg Clayton97fbc342011-10-20 22:30:33 +00003461 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003462 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003463 if (m_apple_types_ap.get())
3464 {
3465 const char *name_cstr = name.GetCString();
3466 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3467 }
Greg Clayton7f995132011-10-04 22:41:51 +00003468 }
3469 else
3470 {
3471 if (!m_indexed)
3472 Index ();
3473
3474 m_type_index.Find (name, die_offsets);
3475 }
3476
Greg Clayton437a1352012-04-09 22:43:43 +00003477 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003478
Greg Clayton437a1352012-04-09 22:43:43 +00003479 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003480 {
Greg Clayton7f995132011-10-04 22:41:51 +00003481 const uint32_t initial_types_size = types.GetSize();
3482 DWARFCompileUnit* dwarf_cu = NULL;
3483 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003484 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003485 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003486 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003487 const dw_offset_t die_offset = die_offsets[i];
3488 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3489
Greg Clayton95d87902011-11-11 03:16:25 +00003490 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003491 {
Greg Clayton95d87902011-11-11 03:16:25 +00003492 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3493 continue;
3494
3495 Type *matching_type = ResolveType (dwarf_cu, die);
3496 if (matching_type)
3497 {
3498 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003499 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003500 if (types.GetSize() >= max_matches)
3501 break;
3502 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003503 }
Greg Clayton95d87902011-11-11 03:16:25 +00003504 else
3505 {
3506 if (m_using_apple_tables)
3507 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003508 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3509 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003510 }
3511 }
3512
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003513 }
Greg Clayton437a1352012-04-09 22:43:43 +00003514 const uint32_t num_matches = types.GetSize() - initial_types_size;
3515 if (log && num_matches)
3516 {
3517 if (namespace_decl)
3518 {
3519 GetObjectFile()->GetModule()->LogMessage (log.get(),
3520 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
3521 name.GetCString(),
3522 namespace_decl->GetNamespaceDecl(),
3523 namespace_decl->GetQualifiedName().c_str(),
3524 append,
3525 max_matches,
3526 num_matches);
3527 }
3528 else
3529 {
3530 GetObjectFile()->GetModule()->LogMessage (log.get(),
3531 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
3532 name.GetCString(),
3533 append,
3534 max_matches,
3535 num_matches);
3536 }
3537 }
3538 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003539 }
Greg Clayton7f995132011-10-04 22:41:51 +00003540 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003541}
3542
3543
Greg Clayton526e5af2010-11-13 03:52:47 +00003544ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003545SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003546 const ConstString &name,
3547 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003548{
Greg Clayton21f2a492011-10-06 00:09:08 +00003549 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3550
3551 if (log)
3552 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003553 GetObjectFile()->GetModule()->LogMessage (log.get(),
3554 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3555 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003556 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003557
3558 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3559 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003560
Greg Clayton526e5af2010-11-13 03:52:47 +00003561 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003562 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003563 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003564 {
Greg Clayton7f995132011-10-04 22:41:51 +00003565 DIEArray die_offsets;
3566
Greg Clayton526e5af2010-11-13 03:52:47 +00003567 // Index if we already haven't to make sure the compile units
3568 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003569 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003570 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003571 if (m_apple_namespaces_ap.get())
3572 {
3573 const char *name_cstr = name.GetCString();
3574 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3575 }
Greg Clayton7f995132011-10-04 22:41:51 +00003576 }
3577 else
3578 {
3579 if (!m_indexed)
3580 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003581
Greg Clayton7f995132011-10-04 22:41:51 +00003582 m_namespace_index.Find (name, die_offsets);
3583 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003584
3585 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003586 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003587 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003588 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003589 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003590 DWARFDebugInfo* debug_info = DebugInfo();
3591 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003592 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003593 const dw_offset_t die_offset = die_offsets[i];
3594 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003595
Greg Clayton95d87902011-11-11 03:16:25 +00003596 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003597 {
Greg Clayton95d87902011-11-11 03:16:25 +00003598 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3599 continue;
3600
3601 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3602 if (clang_namespace_decl)
3603 {
3604 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3605 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003606 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003607 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003608 }
Greg Clayton95d87902011-11-11 03:16:25 +00003609 else
3610 {
3611 if (m_using_apple_tables)
3612 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003613 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3614 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003615 }
3616 }
3617
Greg Clayton526e5af2010-11-13 03:52:47 +00003618 }
3619 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003620 }
Greg Clayton437a1352012-04-09 22:43:43 +00003621 if (log && namespace_decl.GetNamespaceDecl())
3622 {
3623 GetObjectFile()->GetModule()->LogMessage (log.get(),
3624 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
3625 name.GetCString(),
3626 namespace_decl.GetNamespaceDecl(),
3627 namespace_decl.GetQualifiedName().c_str());
3628 }
3629
Greg Clayton526e5af2010-11-13 03:52:47 +00003630 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003631}
3632
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003633uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003634SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003635{
3636 // Remember how many sc_list are in the list before we search in case
3637 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003638 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003639
3640 const uint32_t num_die_offsets = die_offsets.size();
3641 // Parse all of the types we found from the pubtypes matches
3642 uint32_t i;
3643 uint32_t num_matches = 0;
3644 for (i = 0; i < num_die_offsets; ++i)
3645 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003646 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3647 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003648 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003649 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003650 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003651 ++num_matches;
3652 if (num_matches >= max_matches)
3653 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003654 }
3655 }
3656
3657 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003658 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003659}
3660
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661
3662size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003663SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3664 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003665 DWARFCompileUnit* dwarf_cu,
3666 const DWARFDebugInfoEntry *parent_die,
3667 bool skip_artificial,
3668 bool &is_static,
3669 TypeList* type_list,
3670 std::vector<clang_type_t>& function_param_types,
3671 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003672 unsigned &type_quals,
3673 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003674{
3675 if (parent_die == NULL)
3676 return 0;
3677
Greg Claytond88d7592010-09-15 08:33:30 +00003678 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3679
Greg Clayton7fedea22010-11-16 02:10:54 +00003680 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003681 const DWARFDebugInfoEntry *die;
3682 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3683 {
3684 dw_tag_t tag = die->Tag();
3685 switch (tag)
3686 {
3687 case DW_TAG_formal_parameter:
3688 {
3689 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003690 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003691 if (num_attributes > 0)
3692 {
3693 const char *name = NULL;
3694 Declaration decl;
3695 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003696 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003697 // one of None, Auto, Register, Extern, Static, PrivateExtern
3698
Sean Callanane2ef6e32010-09-23 03:01:22 +00003699 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003700 uint32_t i;
3701 for (i=0; i<num_attributes; ++i)
3702 {
3703 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3704 DWARFFormValue form_value;
3705 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3706 {
3707 switch (attr)
3708 {
3709 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3710 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3711 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3712 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3713 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003714 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003715 case DW_AT_location:
3716 // if (form_value.BlockData())
3717 // {
3718 // const DataExtractor& debug_info_data = debug_info();
3719 // uint32_t block_length = form_value.Unsigned();
3720 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3721 // }
3722 // else
3723 // {
3724 // }
3725 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003726 case DW_AT_const_value:
3727 case DW_AT_default_value:
3728 case DW_AT_description:
3729 case DW_AT_endianity:
3730 case DW_AT_is_optional:
3731 case DW_AT_segment:
3732 case DW_AT_variable_parameter:
3733 default:
3734 case DW_AT_abstract_origin:
3735 case DW_AT_sibling:
3736 break;
3737 }
3738 }
3739 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003740
Greg Clayton0fffff52010-09-24 05:15:53 +00003741 bool skip = false;
3742 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003743 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003744 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003745 {
3746 // In order to determine if a C++ member function is
3747 // "const" we have to look at the const-ness of "this"...
3748 // Ugly, but that
3749 if (arg_idx == 0)
3750 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003751 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003752 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003753 // Often times compilers omit the "this" name for the
3754 // specification DIEs, so we can't rely upon the name
3755 // being in the formal parameter DIE...
3756 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003757 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003758 Type *this_type = ResolveTypeUID (param_type_die_offset);
3759 if (this_type)
3760 {
3761 uint32_t encoding_mask = this_type->GetEncodingMask();
3762 if (encoding_mask & Type::eEncodingIsPointerUID)
3763 {
3764 is_static = false;
3765
3766 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3767 type_quals |= clang::Qualifiers::Const;
3768 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3769 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003770 }
3771 }
3772 }
3773 }
3774 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003775 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003776 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003777 else
3778 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003779
Greg Clayton0fffff52010-09-24 05:15:53 +00003780 // HACK: Objective C formal parameters "self" and "_cmd"
3781 // are not marked as artificial in the DWARF...
Greg Clayton53eb1c22012-04-02 22:59:12 +00003782 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3783 if (comp_unit)
Greg Clayton0fffff52010-09-24 05:15:53 +00003784 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003785 switch (comp_unit->GetLanguage())
3786 {
3787 case eLanguageTypeObjC:
3788 case eLanguageTypeObjC_plus_plus:
3789 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3790 skip = true;
3791 break;
3792 default:
3793 break;
3794 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003795 }
3796 }
3797 }
3798
3799 if (!skip)
3800 {
3801 Type *type = ResolveTypeUID(param_type_die_offset);
3802 if (type)
3803 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003804 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003805
Greg Clayton42ce2f32011-12-12 21:50:19 +00003806 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3807 type->GetClangForwardType(),
3808 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003809 assert(param_var_decl);
3810 function_param_decls.push_back(param_var_decl);
Sean Callanan60217122012-04-13 00:10:03 +00003811
3812 GetClangASTContext().SetMetadata((uintptr_t)param_var_decl, MakeUserID(die->GetOffset()));
Greg Clayton0fffff52010-09-24 05:15:53 +00003813 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003814 }
3815 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003816 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003817 }
3818 break;
3819
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003820 case DW_TAG_template_type_parameter:
3821 case DW_TAG_template_value_parameter:
3822 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3823 break;
3824
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003825 default:
3826 break;
3827 }
3828 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003829 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003830}
3831
3832size_t
3833SymbolFileDWARF::ParseChildEnumerators
3834(
3835 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003836 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003837 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003838 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003839 const DWARFDebugInfoEntry *parent_die
3840)
3841{
3842 if (parent_die == NULL)
3843 return 0;
3844
3845 size_t enumerators_added = 0;
3846 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003847 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3848
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003849 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3850 {
3851 const dw_tag_t tag = die->Tag();
3852 if (tag == DW_TAG_enumerator)
3853 {
3854 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003855 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003856 if (num_child_attributes > 0)
3857 {
3858 const char *name = NULL;
3859 bool got_value = false;
3860 int64_t enum_value = 0;
3861 Declaration decl;
3862
3863 uint32_t i;
3864 for (i=0; i<num_child_attributes; ++i)
3865 {
3866 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3867 DWARFFormValue form_value;
3868 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3869 {
3870 switch (attr)
3871 {
3872 case DW_AT_const_value:
3873 got_value = true;
3874 enum_value = form_value.Unsigned();
3875 break;
3876
3877 case DW_AT_name:
3878 name = form_value.AsCString(&get_debug_str_data());
3879 break;
3880
3881 case DW_AT_description:
3882 default:
3883 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3884 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3885 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3886 case DW_AT_sibling:
3887 break;
3888 }
3889 }
3890 }
3891
3892 if (name && name[0] && got_value)
3893 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003894 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3895 enumerator_clang_type,
3896 decl,
3897 name,
3898 enum_value,
3899 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003900 ++enumerators_added;
3901 }
3902 }
3903 }
3904 }
3905 return enumerators_added;
3906}
3907
3908void
3909SymbolFileDWARF::ParseChildArrayInfo
3910(
3911 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003912 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003913 const DWARFDebugInfoEntry *parent_die,
3914 int64_t& first_index,
3915 std::vector<uint64_t>& element_orders,
3916 uint32_t& byte_stride,
3917 uint32_t& bit_stride
3918)
3919{
3920 if (parent_die == NULL)
3921 return;
3922
3923 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003924 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003925 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3926 {
3927 const dw_tag_t tag = die->Tag();
3928 switch (tag)
3929 {
3930 case DW_TAG_enumerator:
3931 {
3932 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003933 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003934 if (num_child_attributes > 0)
3935 {
3936 const char *name = NULL;
3937 bool got_value = false;
3938 int64_t enum_value = 0;
3939
3940 uint32_t i;
3941 for (i=0; i<num_child_attributes; ++i)
3942 {
3943 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3944 DWARFFormValue form_value;
3945 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3946 {
3947 switch (attr)
3948 {
3949 case DW_AT_const_value:
3950 got_value = true;
3951 enum_value = form_value.Unsigned();
3952 break;
3953
3954 case DW_AT_name:
3955 name = form_value.AsCString(&get_debug_str_data());
3956 break;
3957
3958 case DW_AT_description:
3959 default:
3960 case DW_AT_decl_file:
3961 case DW_AT_decl_line:
3962 case DW_AT_decl_column:
3963 case DW_AT_sibling:
3964 break;
3965 }
3966 }
3967 }
3968 }
3969 }
3970 break;
3971
3972 case DW_TAG_subrange_type:
3973 {
3974 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003975 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003976 if (num_child_attributes > 0)
3977 {
3978 const char *name = NULL;
3979 bool got_value = false;
3980 uint64_t byte_size = 0;
3981 int64_t enum_value = 0;
3982 uint64_t num_elements = 0;
3983 uint64_t lower_bound = 0;
3984 uint64_t upper_bound = 0;
3985 uint32_t i;
3986 for (i=0; i<num_child_attributes; ++i)
3987 {
3988 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3989 DWARFFormValue form_value;
3990 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3991 {
3992 switch (attr)
3993 {
3994 case DW_AT_const_value:
3995 got_value = true;
3996 enum_value = form_value.Unsigned();
3997 break;
3998
3999 case DW_AT_name:
4000 name = form_value.AsCString(&get_debug_str_data());
4001 break;
4002
4003 case DW_AT_count:
4004 num_elements = form_value.Unsigned();
4005 break;
4006
4007 case DW_AT_bit_stride:
4008 bit_stride = form_value.Unsigned();
4009 break;
4010
4011 case DW_AT_byte_stride:
4012 byte_stride = form_value.Unsigned();
4013 break;
4014
4015 case DW_AT_byte_size:
4016 byte_size = form_value.Unsigned();
4017 break;
4018
4019 case DW_AT_lower_bound:
4020 lower_bound = form_value.Unsigned();
4021 break;
4022
4023 case DW_AT_upper_bound:
4024 upper_bound = form_value.Unsigned();
4025 break;
4026
4027 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004028 case DW_AT_abstract_origin:
4029 case DW_AT_accessibility:
4030 case DW_AT_allocated:
4031 case DW_AT_associated:
4032 case DW_AT_data_location:
4033 case DW_AT_declaration:
4034 case DW_AT_description:
4035 case DW_AT_sibling:
4036 case DW_AT_threads_scaled:
4037 case DW_AT_type:
4038 case DW_AT_visibility:
4039 break;
4040 }
4041 }
4042 }
4043
4044 if (upper_bound > lower_bound)
4045 num_elements = upper_bound - lower_bound + 1;
4046
4047 if (num_elements > 0)
4048 element_orders.push_back (num_elements);
4049 }
4050 }
4051 break;
4052 }
4053 }
4054}
4055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004056TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00004057SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004058{
4059 TypeSP type_sp;
4060 if (die != NULL)
4061 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004062 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00004063 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004064 if (type_ptr == NULL)
4065 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004066 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00004067 assert (lldb_cu);
4068 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00004069 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004070 }
4071 else if (type_ptr != DIE_IS_BEING_PARSED)
4072 {
4073 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00004074 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004075 }
4076
4077 }
4078 return type_sp;
4079}
4080
4081clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00004082SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004083{
4084 if (die_offset != DW_INVALID_OFFSET)
4085 {
4086 DWARFCompileUnitSP cu_sp;
4087 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004088 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004089 }
4090 return NULL;
4091}
4092
Sean Callanan72e49402011-08-05 23:43:37 +00004093clang::DeclContext *
4094SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4095{
4096 if (die_offset != DW_INVALID_OFFSET)
4097 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004098 DWARFDebugInfo* debug_info = DebugInfo();
4099 if (debug_info)
4100 {
4101 DWARFCompileUnitSP cu_sp;
4102 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4103 if (die)
4104 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4105 }
Sean Callanan72e49402011-08-05 23:43:37 +00004106 }
4107 return NULL;
4108}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004109
Greg Clayton96d7d742010-11-10 23:42:09 +00004110clang::NamespaceDecl *
Greg Clayton53eb1c22012-04-02 22:59:12 +00004111SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
Greg Clayton96d7d742010-11-10 23:42:09 +00004112{
Greg Clayton030a2042011-10-14 21:34:45 +00004113 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00004114 {
Greg Clayton030a2042011-10-14 21:34:45 +00004115 // See if we already parsed this namespace DIE and associated it with a
4116 // uniqued namespace declaration
4117 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4118 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00004119 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00004120 else
4121 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004122 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4123 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00004124 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4125 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4126 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00004127 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00004128 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00004129 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004130 GetObjectFile()->GetModule()->LogMessage (log.get(),
4131 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4132 GetClangASTContext().getASTContext(),
4133 MakeUserID(die->GetOffset()),
4134 namespace_name,
4135 namespace_decl,
4136 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00004137 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004138 else
4139 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004140 GetObjectFile()->GetModule()->LogMessage (log.get(),
4141 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4142 GetClangASTContext().getASTContext(),
4143 MakeUserID(die->GetOffset()),
4144 namespace_decl,
4145 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00004146 }
Greg Clayton030a2042011-10-14 21:34:45 +00004147 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00004148
4149 if (namespace_decl)
4150 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4151 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00004152 }
4153 }
4154 return NULL;
4155}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156
4157clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00004158SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00004159{
Greg Clayton5cf58b92011-10-05 22:22:08 +00004160 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4161 if (clang_decl_ctx)
4162 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004163 // If this DIE has a specification, or an abstract origin, then trace to those.
4164
Greg Claytoncab36a32011-12-08 05:16:30 +00004165 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00004166 if (die_offset != DW_INVALID_OFFSET)
4167 return GetClangDeclContextForDIEOffset (sc, die_offset);
4168
Greg Claytoncab36a32011-12-08 05:16:30 +00004169 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, 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 Clayton3bffb082011-12-10 02:15:28 +00004173 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4174 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00004175 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 +00004176 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00004177 bool assert_not_being_parsed = true;
4178 ResolveTypeUID (cu, die, assert_not_being_parsed);
4179
Greg Clayton5cf58b92011-10-05 22:22:08 +00004180 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4181
4182 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00004183}
4184
4185clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00004186SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004187{
Greg Claytonca512b32011-01-14 04:54:56 +00004188 if (m_clang_tu_decl == NULL)
4189 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004190
Greg Clayton2bc22f82011-09-30 03:20:47 +00004191 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00004192
4193 if (decl_ctx_die_copy)
4194 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00004195
4196 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004197 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00004198
Greg Clayton2bc22f82011-09-30 03:20:47 +00004199 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4200 if (pos != m_die_to_decl_ctx.end())
4201 return pos->second;
4202
4203 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004205 case DW_TAG_compile_unit:
4206 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004207
Greg Clayton2bc22f82011-09-30 03:20:47 +00004208 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00004209 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00004210 break;
4211
4212 case DW_TAG_structure_type:
4213 case DW_TAG_union_type:
4214 case DW_TAG_class_type:
4215 {
4216 Type* type = ResolveType (cu, decl_ctx_die);
4217 if (type)
4218 {
4219 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4220 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00004221 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00004222 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4223 if (decl_ctx)
4224 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00004225 }
4226 }
Greg Claytonca512b32011-01-14 04:54:56 +00004227 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00004228 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004229
Greg Clayton2bc22f82011-09-30 03:20:47 +00004230 default:
4231 break;
Greg Claytonca512b32011-01-14 04:54:56 +00004232 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004233 }
Greg Clayton7a345282010-11-09 23:46:37 +00004234 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235}
4236
Greg Clayton2bc22f82011-09-30 03:20:47 +00004237
4238const DWARFDebugInfoEntry *
4239SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4240{
4241 if (cu && die)
4242 {
4243 const DWARFDebugInfoEntry * const decl_die = die;
4244
4245 while (die != NULL)
4246 {
4247 // If this is the original DIE that we are searching for a declaration
4248 // for, then don't look in the cache as we don't want our own decl
4249 // context to be our decl context...
4250 if (decl_die != die)
4251 {
4252 switch (die->Tag())
4253 {
4254 case DW_TAG_compile_unit:
4255 case DW_TAG_namespace:
4256 case DW_TAG_structure_type:
4257 case DW_TAG_union_type:
4258 case DW_TAG_class_type:
4259 return die;
4260
4261 default:
4262 break;
4263 }
4264 }
4265
4266 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4267 if (die_offset != DW_INVALID_OFFSET)
4268 {
4269 DWARFCompileUnit *spec_cu = cu;
4270 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4271 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4272 if (spec_die_decl_ctx_die)
4273 return spec_die_decl_ctx_die;
4274 }
4275
4276 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4277 if (die_offset != DW_INVALID_OFFSET)
4278 {
4279 DWARFCompileUnit *abs_cu = cu;
4280 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4281 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4282 if (abs_die_decl_ctx_die)
4283 return abs_die_decl_ctx_die;
4284 }
4285
4286 die = die->GetParent();
4287 }
4288 }
4289 return NULL;
4290}
4291
4292
Greg Clayton901c5ca2011-12-03 04:40:03 +00004293Symbol *
4294SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4295{
4296 Symbol *objc_class_symbol = NULL;
4297 if (m_obj_file)
4298 {
4299 Symtab *symtab = m_obj_file->GetSymtab();
4300 if (symtab)
4301 {
4302 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4303 eSymbolTypeObjCClass,
4304 Symtab::eDebugNo,
4305 Symtab::eVisibilityAny);
4306 }
4307 }
4308 return objc_class_symbol;
4309}
4310
Greg Claytonc7f03b62012-01-12 04:33:28 +00004311// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4312// then we can end up looking through all class types for a complete type and never find
4313// the full definition. We need to know if this attribute is supported, so we determine
4314// this here and cache th result. We also need to worry about the debug map DWARF file
4315// if we are doing darwin DWARF in .o file debugging.
4316bool
4317SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4318{
4319 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4320 {
4321 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4322 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4323 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4324 else
4325 {
4326 DWARFDebugInfo* debug_info = DebugInfo();
4327 const uint32_t num_compile_units = GetNumCompileUnits();
4328 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4329 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00004330 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4331 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004332 {
4333 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4334 break;
4335 }
4336 }
4337 }
4338 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4339 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4340 }
4341 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4342}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004343
4344// This function can be used when a DIE is found that is a forward declaration
4345// DIE and we want to try and find a type that has the complete definition.
4346TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004347SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4348 const ConstString &type_name,
4349 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004350{
4351
4352 TypeSP type_sp;
4353
Greg Claytonc7f03b62012-01-12 04:33:28 +00004354 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004355 return type_sp;
4356
4357 DIEArray die_offsets;
4358
4359 if (m_using_apple_tables)
4360 {
4361 if (m_apple_types_ap.get())
4362 {
4363 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004364 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004365 }
4366 }
4367 else
4368 {
4369 if (!m_indexed)
4370 Index ();
4371
4372 m_type_index.Find (type_name, die_offsets);
4373 }
4374
Greg Clayton901c5ca2011-12-03 04:40:03 +00004375 const size_t num_matches = die_offsets.size();
4376
Greg Clayton901c5ca2011-12-03 04:40:03 +00004377 DWARFCompileUnit* type_cu = NULL;
4378 const DWARFDebugInfoEntry* type_die = NULL;
4379 if (num_matches)
4380 {
4381 DWARFDebugInfo* debug_info = DebugInfo();
4382 for (size_t i=0; i<num_matches; ++i)
4383 {
4384 const dw_offset_t die_offset = die_offsets[i];
4385 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4386
4387 if (type_die)
4388 {
4389 bool try_resolving_type = false;
4390
4391 // Don't try and resolve the DIE we are looking for with the DIE itself!
4392 if (type_die != die)
4393 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004394 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004395 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004396 case DW_TAG_class_type:
4397 case DW_TAG_structure_type:
4398 try_resolving_type = true;
4399 break;
4400 default:
4401 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004402 }
4403 }
4404
4405 if (try_resolving_type)
4406 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004407 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004408 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004409
4410 if (try_resolving_type)
4411 {
4412 Type *resolved_type = ResolveType (type_cu, type_die, false);
4413 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4414 {
4415 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4416 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004417 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004418 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4419 MakeUserID(type_die->GetOffset()),
4420 MakeUserID(type_cu->GetOffset()));
4421
Greg Claytonc7f03b62012-01-12 04:33:28 +00004422 if (die)
4423 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004424 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004425 break;
4426 }
4427 }
4428 }
4429 }
4430 else
4431 {
4432 if (m_using_apple_tables)
4433 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004434 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4435 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004436 }
4437 }
4438
4439 }
4440 }
4441 return type_sp;
4442}
4443
Greg Claytona8022fa2012-04-24 21:22:41 +00004444
Greg Clayton80c26302012-02-05 06:12:47 +00004445//----------------------------------------------------------------------
4446// This function helps to ensure that the declaration contexts match for
4447// two different DIEs. Often times debug information will refer to a
4448// forward declaration of a type (the equivalent of "struct my_struct;".
4449// There will often be a declaration of that type elsewhere that has the
4450// full definition. When we go looking for the full type "my_struct", we
4451// will find one or more matches in the accelerator tables and we will
4452// then need to make sure the type was in the same declaration context
4453// as the original DIE. This function can efficiently compare two DIEs
4454// and will return true when the declaration context matches, and false
4455// when they don't.
4456//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004457bool
4458SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4459 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4460{
Greg Claytona8022fa2012-04-24 21:22:41 +00004461 if (die1 == die2)
4462 return true;
4463
4464#if defined (LLDB_CONFIGURATION_DEBUG)
4465 // You can't and shouldn't call this function with a compile unit from
4466 // two different SymbolFileDWARF instances.
4467 assert (DebugInfo()->ContainsCompileUnit (cu1));
4468 assert (DebugInfo()->ContainsCompileUnit (cu2));
4469#endif
4470
Greg Clayton890ff562012-02-02 05:48:16 +00004471 DWARFDIECollection decl_ctx_1;
4472 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004473 //The declaration DIE stack is a stack of the declaration context
4474 // DIEs all the way back to the compile unit. If a type "T" is
4475 // declared inside a class "B", and class "B" is declared inside
4476 // a class "A" and class "A" is in a namespace "lldb", and the
4477 // namespace is in a compile unit, there will be a stack of DIEs:
4478 //
4479 // [0] DW_TAG_class_type for "B"
4480 // [1] DW_TAG_class_type for "A"
4481 // [2] DW_TAG_namespace for "lldb"
4482 // [3] DW_TAG_compile_unit for the source file.
4483 //
4484 // We grab both contexts and make sure that everything matches
4485 // all the way back to the compiler unit.
4486
4487 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004488 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004489 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004490 // Make sure the context arrays have the same size, otherwise
4491 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004492 const size_t count1 = decl_ctx_1.Size();
4493 const size_t count2 = decl_ctx_2.Size();
4494 if (count1 != count2)
4495 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004496
4497 // Make sure the DW_TAG values match all the way back up the the
4498 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004499 const DWARFDebugInfoEntry *decl_ctx_die1;
4500 const DWARFDebugInfoEntry *decl_ctx_die2;
4501 size_t i;
4502 for (i=0; i<count1; i++)
4503 {
4504 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4505 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4506 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4507 return false;
4508 }
Greg Clayton890ff562012-02-02 05:48:16 +00004509#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004510
4511 // Make sure the top item in the decl context die array is always
4512 // DW_TAG_compile_unit. If it isn't then something went wrong in
4513 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004514 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004515
Greg Clayton890ff562012-02-02 05:48:16 +00004516#endif
4517 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004518 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004519 for (i=0; i<count1 - 1; i++)
4520 {
4521 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4522 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4523 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004524 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004525 // If the string was from a DW_FORM_strp, then the pointer will often
4526 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004527 if (name1 == name2)
4528 continue;
4529
4530 // Name pointers are not equal, so only compare the strings
4531 // if both are not NULL.
4532 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004533 {
Greg Clayton5569e642012-02-06 01:44:54 +00004534 // If the strings don't compare, we are done...
4535 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004536 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004537 }
4538 else
4539 {
4540 // One name was NULL while the other wasn't
4541 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004542 }
4543 }
Greg Clayton80c26302012-02-05 06:12:47 +00004544 // We made it through all of the checks and the declaration contexts
4545 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004546 return true;
4547}
Greg Clayton220a0072011-12-09 08:48:30 +00004548
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004549// This function can be used when a DIE is found that is a forward declaration
4550// DIE and we want to try and find a type that has the complete definition.
Greg Claytona8022fa2012-04-24 21:22:41 +00004551// "cu" and "die" must be from this SymbolFileDWARF
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004552TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004553SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
Greg Clayton7f995132011-10-04 22:41:51 +00004554 const DWARFDebugInfoEntry *die,
4555 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004556{
4557 TypeSP type_sp;
4558
Greg Claytona8022fa2012-04-24 21:22:41 +00004559#if defined (LLDB_CONFIGURATION_DEBUG)
4560 // You can't and shouldn't call this function with a compile unit from
4561 // another SymbolFileDWARF instance.
4562 assert (DebugInfo()->ContainsCompileUnit (cu));
4563#endif
4564
Greg Clayton1a65ae12011-01-25 23:55:37 +00004565 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004566 return type_sp;
4567
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004568 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4569 if (log)
4570 {
4571 std::string qualified_name;
4572 die->GetQualifiedName(this, cu, qualified_name);
4573 GetObjectFile()->GetModule()->LogMessage (log.get(),
4574 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
4575 die->GetOffset(),
4576 qualified_name.c_str(),
4577 type_name.GetCString());
4578 }
4579
Greg Clayton7f995132011-10-04 22:41:51 +00004580 DIEArray die_offsets;
4581
Greg Clayton97fbc342011-10-20 22:30:33 +00004582 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004583 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004584 if (m_apple_types_ap.get())
4585 {
Greg Claytond1767f02011-12-08 02:13:16 +00004586 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4587 {
Greg Claytonae920b62012-01-06 00:17:16 +00004588 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004589 }
4590 else
4591 {
4592 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4593 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004594 }
Greg Clayton7f995132011-10-04 22:41:51 +00004595 }
4596 else
4597 {
4598 if (!m_indexed)
4599 Index ();
4600
4601 m_type_index.Find (type_name, die_offsets);
4602 }
Greg Clayton7f995132011-10-04 22:41:51 +00004603
4604 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004605
Greg Clayton934cb052011-12-03 00:27:05 +00004606 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004607
4608 DWARFCompileUnit* type_cu = NULL;
4609 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004610 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004611 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004612 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004613 for (size_t i=0; i<num_matches; ++i)
4614 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004615 const dw_offset_t die_offset = die_offsets[i];
4616 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004617
Greg Clayton95d87902011-11-11 03:16:25 +00004618 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004619 {
Greg Clayton934cb052011-12-03 00:27:05 +00004620 bool try_resolving_type = false;
4621
4622 // Don't try and resolve the DIE we are looking for with the DIE itself!
4623 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004624 {
Greg Clayton934cb052011-12-03 00:27:05 +00004625 const dw_tag_t type_die_tag = type_die->Tag();
4626 // Make sure the tags match
4627 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004628 {
Greg Clayton934cb052011-12-03 00:27:05 +00004629 // The tags match, lets try resolving this type
4630 try_resolving_type = true;
4631 }
4632 else
4633 {
4634 // The tags don't match, but we need to watch our for a
4635 // forward declaration for a struct and ("struct foo")
4636 // ends up being a class ("class foo { ... };") or
4637 // vice versa.
4638 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004639 {
Greg Clayton934cb052011-12-03 00:27:05 +00004640 case DW_TAG_class_type:
4641 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4642 try_resolving_type = (die_tag == DW_TAG_structure_type);
4643 break;
4644 case DW_TAG_structure_type:
4645 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4646 try_resolving_type = (die_tag == DW_TAG_class_type);
4647 break;
4648 default:
4649 // Tags don't match, don't event try to resolve
4650 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004651 break;
4652 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004653 }
4654 }
Greg Clayton934cb052011-12-03 00:27:05 +00004655
4656 if (try_resolving_type)
4657 {
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004658 if (log)
4659 {
4660 std::string qualified_name;
4661 type_die->GetQualifiedName(this, cu, qualified_name);
4662 GetObjectFile()->GetModule()->LogMessage (log.get(),
4663 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
4664 die->GetOffset(),
4665 type_name.GetCString(),
4666 type_die->GetOffset(),
4667 qualified_name.c_str());
4668 }
4669
Greg Clayton890ff562012-02-02 05:48:16 +00004670 // Make sure the decl contexts match all the way up
4671 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004672 {
Greg Clayton890ff562012-02-02 05:48:16 +00004673 Type *resolved_type = ResolveType (type_cu, type_die, false);
4674 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4675 {
4676 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4677 MakeUserID(die->GetOffset()),
Greg Clayton53eb1c22012-04-02 22:59:12 +00004678 MakeUserID(dwarf_cu->GetOffset()),
Greg Clayton890ff562012-02-02 05:48:16 +00004679 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4680 MakeUserID(type_die->GetOffset()),
4681 MakeUserID(type_cu->GetOffset()));
4682
4683 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004684 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004685 break;
4686 }
Greg Clayton934cb052011-12-03 00:27:05 +00004687 }
4688 }
Greg Clayton9bbddbf2012-04-20 20:35:47 +00004689 else
4690 {
4691 if (log)
4692 {
4693 std::string qualified_name;
4694 type_die->GetQualifiedName(this, cu, qualified_name);
4695 GetObjectFile()->GetModule()->LogMessage (log.get(),
4696 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
4697 die->GetOffset(),
4698 type_name.GetCString(),
4699 type_die->GetOffset(),
4700 qualified_name.c_str());
4701 }
4702 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004703 }
Greg Clayton95d87902011-11-11 03:16:25 +00004704 else
4705 {
4706 if (m_using_apple_tables)
4707 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004708 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4709 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004710 }
4711 }
4712
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004713 }
4714 }
4715 return type_sp;
4716}
4717
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004718TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00004719SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
4720{
4721 TypeSP type_sp;
4722
4723 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
4724 if (dwarf_decl_ctx_count > 0)
4725 {
4726 const ConstString type_name(dwarf_decl_ctx[0].name);
4727 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
4728
4729 if (type_name)
4730 {
4731 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
4732 if (log)
4733 {
4734 GetObjectFile()->GetModule()->LogMessage (log.get(),
4735 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
4736 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4737 dwarf_decl_ctx.GetQualifiedName());
4738 }
4739
4740 DIEArray die_offsets;
4741
4742 if (m_using_apple_tables)
4743 {
4744 if (m_apple_types_ap.get())
4745 {
4746 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4747 {
4748 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
4749 }
4750 else
4751 {
4752 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4753 }
4754 }
4755 }
4756 else
4757 {
4758 if (!m_indexed)
4759 Index ();
4760
4761 m_type_index.Find (type_name, die_offsets);
4762 }
4763
4764 const size_t num_matches = die_offsets.size();
4765
4766
4767 DWARFCompileUnit* type_cu = NULL;
4768 const DWARFDebugInfoEntry* type_die = NULL;
4769 if (num_matches)
4770 {
4771 DWARFDebugInfo* debug_info = DebugInfo();
4772 for (size_t i=0; i<num_matches; ++i)
4773 {
4774 const dw_offset_t die_offset = die_offsets[i];
4775 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4776
4777 if (type_die)
4778 {
4779 bool try_resolving_type = false;
4780
4781 // Don't try and resolve the DIE we are looking for with the DIE itself!
4782 const dw_tag_t type_tag = type_die->Tag();
4783 // Make sure the tags match
4784 if (type_tag == tag)
4785 {
4786 // The tags match, lets try resolving this type
4787 try_resolving_type = true;
4788 }
4789 else
4790 {
4791 // The tags don't match, but we need to watch our for a
4792 // forward declaration for a struct and ("struct foo")
4793 // ends up being a class ("class foo { ... };") or
4794 // vice versa.
4795 switch (type_tag)
4796 {
4797 case DW_TAG_class_type:
4798 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4799 try_resolving_type = (tag == DW_TAG_structure_type);
4800 break;
4801 case DW_TAG_structure_type:
4802 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4803 try_resolving_type = (tag == DW_TAG_class_type);
4804 break;
4805 default:
4806 // Tags don't match, don't event try to resolve
4807 // using this type whose name matches....
4808 break;
4809 }
4810 }
4811
4812 if (try_resolving_type)
4813 {
4814 DWARFDeclContext type_dwarf_decl_ctx;
4815 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
4816
4817 if (log)
4818 {
4819 GetObjectFile()->GetModule()->LogMessage (log.get(),
4820 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
4821 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4822 dwarf_decl_ctx.GetQualifiedName(),
4823 type_die->GetOffset(),
4824 type_dwarf_decl_ctx.GetQualifiedName());
4825 }
4826
4827 // Make sure the decl contexts match all the way up
4828 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
4829 {
4830 Type *resolved_type = ResolveType (type_cu, type_die, false);
4831 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4832 {
4833 type_sp = resolved_type->shared_from_this();
4834 break;
4835 }
4836 }
4837 }
4838 else
4839 {
4840 if (log)
4841 {
4842 std::string qualified_name;
4843 type_die->GetQualifiedName(this, type_cu, qualified_name);
4844 GetObjectFile()->GetModule()->LogMessage (log.get(),
4845 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
4846 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
4847 dwarf_decl_ctx.GetQualifiedName(),
4848 type_die->GetOffset(),
4849 qualified_name.c_str());
4850 }
4851 }
4852 }
4853 else
4854 {
4855 if (m_using_apple_tables)
4856 {
4857 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4858 die_offset, type_name.GetCString());
4859 }
4860 }
4861
4862 }
4863 }
4864 }
4865 }
4866 return type_sp;
4867}
4868
Greg Clayton4116e932012-05-15 02:33:01 +00004869bool
4870SymbolFileDWARF::CopyUniqueClassMethodTypes (Type *class_type,
4871 DWARFCompileUnit* src_cu,
4872 const DWARFDebugInfoEntry *src_class_die,
4873 DWARFCompileUnit* dst_cu,
4874 const DWARFDebugInfoEntry *dst_class_die)
4875{
4876 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
4877 return false;
4878 if (src_class_die->Tag() != dst_class_die->Tag())
4879 return false;
4880
4881 // We need to complete the class type so we can get all of the method types
4882 // parsed so we can then unique those types to their equivalent counterparts
4883 // in "dst_cu" and "dst_class_die"
4884 class_type->GetClangFullType();
4885
4886 const DWARFDebugInfoEntry *src_die;
4887 const DWARFDebugInfoEntry *dst_die;
4888 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
4889 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
4890 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
4891 {
4892 if (src_die->Tag() == DW_TAG_subprogram)
4893 {
4894 const char *src_name = src_die->GetMangledName (this, src_cu);
4895 if (src_name)
4896 src_name_to_die.Append(ConstString(src_name).GetCString(), src_die);
4897 }
4898 }
4899 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
4900 {
4901 if (dst_die->Tag() == DW_TAG_subprogram)
4902 {
4903 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4904 if (dst_name)
4905 dst_name_to_die.Append(ConstString(dst_name).GetCString(), dst_die);
4906 }
4907 }
4908 const uint32_t src_size = src_name_to_die.GetSize ();
4909 const uint32_t dst_size = dst_name_to_die.GetSize ();
4910 LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
4911
4912 if (src_size && dst_size)
4913 {
4914 uint32_t idx;
4915 for (idx = 0; idx < src_size; ++idx)
4916 {
4917 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4918 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4919
4920 if (src_die->Tag() != dst_die->Tag())
4921 {
4922 if (log)
4923 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)",
4924 src_class_die->GetOffset(),
4925 dst_class_die->GetOffset(),
4926 src_die->GetOffset(),
4927 DW_TAG_value_to_name(src_die->Tag()),
4928 dst_die->GetOffset(),
4929 DW_TAG_value_to_name(src_die->Tag()));
4930 return false;
4931 }
4932
4933 const char *src_name = src_die->GetMangledName (this, src_cu);
4934 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
4935
4936 // Make sure the names match
4937 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
4938 continue;
4939
4940 if (log)
4941 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)",
4942 src_class_die->GetOffset(),
4943 dst_class_die->GetOffset(),
4944 src_die->GetOffset(),
4945 src_name,
4946 dst_die->GetOffset(),
4947 dst_name);
4948
4949 return false;
4950 }
4951
4952 for (idx = 0; idx < src_size; ++idx)
4953 {
4954 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4955 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4956
4957 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
4958 if (src_decl_ctx)
4959 {
4960 if (log)
4961 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x\n", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
4962 LinkDeclContextToDIE (src_decl_ctx, dst_die);
4963 }
4964 else
4965 {
4966 if (log)
4967 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());
4968 }
4969
4970 Type *src_child_type = m_die_to_type[src_die];
4971 if (src_child_type)
4972 {
4973 if (log)
4974 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());
4975 m_die_to_type[dst_die] = src_child_type;
4976 }
4977 else
4978 {
4979 if (log)
4980 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());
4981 }
4982 }
4983 return true;
4984 }
4985 else
4986 {
4987 if (log)
4988 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",
4989 src_class_die->GetOffset(),
4990 dst_class_die->GetOffset(),
4991 src_die->GetOffset(),
4992 src_size,
4993 dst_die->GetOffset(),
4994 dst_size);
4995 }
4996 return false;
4997}
Greg Claytona8022fa2012-04-24 21:22:41 +00004998
4999TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00005000SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005001{
5002 TypeSP type_sp;
5003
Greg Clayton1be10fc2010-09-29 01:12:09 +00005004 if (type_is_new_ptr)
5005 *type_is_new_ptr = false;
Greg Clayton1fba87112012-02-09 20:03:49 +00005006
5007#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5008 static DIEStack g_die_stack;
5009 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5010#endif
Greg Clayton1be10fc2010-09-29 01:12:09 +00005011
Sean Callananc7fbf732010-08-06 00:32:49 +00005012 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005013 if (die != NULL)
5014 {
Greg Clayton21f2a492011-10-06 00:09:08 +00005015 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00005016 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00005017 {
5018 const DWARFDebugInfoEntry *context_die;
5019 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5020
Greg Clayton1fba87112012-02-09 20:03:49 +00005021 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 +00005022 die->GetOffset(),
5023 context,
5024 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00005025 DW_TAG_value_to_name(die->Tag()),
Greg Clayton1fba87112012-02-09 20:03:49 +00005026 die->GetName(this, dwarf_cu));
5027
5028#if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5029 scoped_die_logger.Push (dwarf_cu, die);
5030 g_die_stack.LogDIEs(log.get(), this);
5031#endif
Sean Callanan5b26f272012-02-04 08:49:35 +00005032 }
Greg Clayton3bffb082011-12-10 02:15:28 +00005033//
5034// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5035// if (log && dwarf_cu)
5036// {
5037// StreamString s;
5038// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005039// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00005040//
5041// }
Jim Ingham16746d12011-08-25 23:21:43 +00005042
Greg Clayton594e5ed2010-09-27 21:07:38 +00005043 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005044 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00005045 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005046 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005047 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00005048 if (type_is_new_ptr)
5049 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005050
Greg Clayton594e5ed2010-09-27 21:07:38 +00005051 const dw_tag_t tag = die->Tag();
5052
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005053 bool is_forward_declaration = false;
5054 DWARFDebugInfoEntry::Attributes attributes;
5055 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00005056 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00005057 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5058 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00005059 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00005060 Declaration decl;
5061
Greg Clayton4957bf62010-09-30 21:49:03 +00005062 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005063 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005064
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005065 dw_attr_t attr;
5066
5067 switch (tag)
5068 {
5069 case DW_TAG_base_type:
5070 case DW_TAG_pointer_type:
5071 case DW_TAG_reference_type:
5072 case DW_TAG_typedef:
5073 case DW_TAG_const_type:
5074 case DW_TAG_restrict_type:
5075 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00005076 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005077 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005078 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005079 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005080
Greg Claytond88d7592010-09-15 08:33:30 +00005081 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005082 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005083 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5084
5085 if (num_attributes > 0)
5086 {
5087 uint32_t i;
5088 for (i=0; i<num_attributes; ++i)
5089 {
5090 attr = attributes.AttributeAtIndex(i);
5091 DWARFFormValue form_value;
5092 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5093 {
5094 switch (attr)
5095 {
5096 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5097 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5098 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5099 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00005100
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005101 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00005102 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5103 // include the "&"...
5104 if (tag == DW_TAG_reference_type)
5105 {
5106 if (strchr (type_name_cstr, '&') == NULL)
5107 type_name_cstr = NULL;
5108 }
5109 if (type_name_cstr)
5110 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005111 break;
Greg Clayton36909642011-03-15 04:38:20 +00005112 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005113 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5114 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5115 default:
5116 case DW_AT_sibling:
5117 break;
5118 }
5119 }
5120 }
5121 }
5122
Greg Clayton81c22f62011-10-19 18:09:39 +00005123 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 +00005124
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005125 switch (tag)
5126 {
5127 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00005128 break;
5129
Greg Claytond4436412011-10-28 21:00:00 +00005130 case DW_TAG_unspecified_type:
5131 if (strcmp(type_name_cstr, "nullptr_t") == 0)
5132 {
5133 resolve_state = Type::eResolveStateFull;
5134 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
5135 break;
5136 }
5137 // Fall through to base type below in case we can handle the type there...
5138
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005139 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00005140 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005141 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5142 encoding,
5143 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005144 break;
5145
Greg Clayton526e5af2010-11-13 03:52:47 +00005146 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5147 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5148 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5149 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5150 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5151 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005152 }
5153
Greg Claytonc7f03b62012-01-12 04:33:28 +00005154 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005155 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005156 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
5157 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005158 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005159 static ConstString g_objc_type_name_id("id");
5160 static ConstString g_objc_type_name_Class("Class");
5161 static ConstString g_objc_type_name_selector("SEL");
5162
5163 if (type_name_const_str == g_objc_type_name_id)
5164 {
5165 if (log)
5166 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5167 die->GetOffset(),
5168 DW_TAG_value_to_name(die->Tag()),
5169 die->GetName(this, dwarf_cu));
5170 clang_type = ast.GetBuiltInType_objc_id();
5171 encoding_data_type = Type::eEncodingIsUID;
5172 encoding_uid = LLDB_INVALID_UID;
5173 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00005174
Greg Claytonc7f03b62012-01-12 04:33:28 +00005175 }
5176 else if (type_name_const_str == g_objc_type_name_Class)
5177 {
5178 if (log)
5179 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5180 die->GetOffset(),
5181 DW_TAG_value_to_name(die->Tag()),
5182 die->GetName(this, dwarf_cu));
5183 clang_type = ast.GetBuiltInType_objc_Class();
5184 encoding_data_type = Type::eEncodingIsUID;
5185 encoding_uid = LLDB_INVALID_UID;
5186 resolve_state = Type::eResolveStateFull;
5187 }
5188 else if (type_name_const_str == g_objc_type_name_selector)
5189 {
5190 if (log)
5191 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5192 die->GetOffset(),
5193 DW_TAG_value_to_name(die->Tag()),
5194 die->GetName(this, dwarf_cu));
5195 clang_type = ast.GetBuiltInType_objc_selector();
5196 encoding_data_type = Type::eEncodingIsUID;
5197 encoding_uid = LLDB_INVALID_UID;
5198 resolve_state = Type::eResolveStateFull;
5199 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00005200 }
5201 }
5202
Greg Clayton81c22f62011-10-19 18:09:39 +00005203 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005204 this,
5205 type_name_const_str,
5206 byte_size,
5207 NULL,
5208 encoding_uid,
5209 encoding_data_type,
5210 &decl,
5211 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005212 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005213
Greg Clayton594e5ed2010-09-27 21:07:38 +00005214 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005215
5216// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5217// if (encoding_type != NULL)
5218// {
5219// if (encoding_type != DIE_IS_BEING_PARSED)
5220// type_sp->SetEncodingType(encoding_type);
5221// else
5222// m_indirect_fixups.push_back(type_sp.get());
5223// }
5224 }
5225 break;
5226
5227 case DW_TAG_structure_type:
5228 case DW_TAG_union_type:
5229 case DW_TAG_class_type:
5230 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005231 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005232 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005233
Greg Clayton9e409562010-07-28 02:04:09 +00005234 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00005235 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005236 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00005237 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005238 if (num_attributes > 0)
5239 {
5240 uint32_t i;
5241 for (i=0; i<num_attributes; ++i)
5242 {
5243 attr = attributes.AttributeAtIndex(i);
5244 DWARFFormValue form_value;
5245 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5246 {
5247 switch (attr)
5248 {
Greg Clayton9e409562010-07-28 02:04:09 +00005249 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00005250 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5251 {
5252 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5253 // point to the compile unit file, so we clear this invalid value
5254 // so that we can still unique types efficiently.
5255 decl.SetFile(FileSpec ("<invalid>", false));
5256 }
5257 else
5258 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00005259 break;
5260
5261 case DW_AT_decl_line:
5262 decl.SetLine(form_value.Unsigned());
5263 break;
5264
5265 case DW_AT_decl_column:
5266 decl.SetColumn(form_value.Unsigned());
5267 break;
5268
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005269 case DW_AT_name:
5270 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005271 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005272 break;
Greg Clayton9e409562010-07-28 02:04:09 +00005273
5274 case DW_AT_byte_size:
5275 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00005276 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00005277 break;
5278
5279 case DW_AT_accessibility:
5280 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5281 break;
5282
5283 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00005284 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00005285 break;
5286
5287 case DW_AT_APPLE_runtime_class:
5288 class_language = (LanguageType)form_value.Signed();
5289 break;
5290
Greg Clayton18774842011-11-29 23:40:34 +00005291 case DW_AT_APPLE_objc_complete_type:
5292 is_complete_objc_class = form_value.Signed();
5293 break;
5294
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005295 case DW_AT_allocated:
5296 case DW_AT_associated:
5297 case DW_AT_data_location:
5298 case DW_AT_description:
5299 case DW_AT_start_scope:
5300 case DW_AT_visibility:
5301 default:
5302 case DW_AT_sibling:
5303 break;
5304 }
5305 }
5306 }
5307 }
5308
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005309 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00005310
Greg Clayton123edca2012-03-02 00:07:15 +00005311 // Only try and unique the type if it has a name.
5312 if (type_name_const_str &&
5313 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Sean Callanan8e8072d2012-02-07 21:13:38 +00005314 this,
5315 dwarf_cu,
5316 die,
5317 decl,
5318 byte_size_valid ? byte_size : -1,
5319 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005320 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005321 // We have already parsed this type or from another
5322 // compile unit. GCC loves to use the "one definition
5323 // rule" which can result in multiple definitions
5324 // of the same class over and over in each compile
5325 // unit.
5326 type_sp = unique_ast_entry.m_type_sp;
5327 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00005328 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00005329 m_die_to_type[die] = type_sp.get();
5330 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005331 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005332 }
5333
Greg Clayton81c22f62011-10-19 18:09:39 +00005334 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 +00005335
5336 int tag_decl_kind = -1;
5337 AccessType default_accessibility = eAccessNone;
5338 if (tag == DW_TAG_structure_type)
5339 {
5340 tag_decl_kind = clang::TTK_Struct;
5341 default_accessibility = eAccessPublic;
5342 }
5343 else if (tag == DW_TAG_union_type)
5344 {
5345 tag_decl_kind = clang::TTK_Union;
5346 default_accessibility = eAccessPublic;
5347 }
5348 else if (tag == DW_TAG_class_type)
5349 {
5350 tag_decl_kind = clang::TTK_Class;
5351 default_accessibility = eAccessPrivate;
5352 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00005353
5354 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
5355 die->HasChildren() == false &&
5356 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
5357 {
5358 // Work around an issue with clang at the moment where
5359 // forward declarations for objective C classes are emitted
5360 // as:
5361 // DW_TAG_structure_type [2]
5362 // DW_AT_name( "ForwardObjcClass" )
5363 // DW_AT_byte_size( 0x00 )
5364 // DW_AT_decl_file( "..." )
5365 // DW_AT_decl_line( 1 )
5366 //
5367 // Note that there is no DW_AT_declaration and there are
5368 // no children, and the byte size is zero.
5369 is_forward_declaration = true;
5370 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005371
Sean Callanan7457f8d2012-04-25 01:03:57 +00005372 if (class_language == eLanguageTypeObjC ||
5373 class_language == eLanguageTypeObjC_plus_plus)
Greg Clayton18774842011-11-29 23:40:34 +00005374 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005375 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00005376 {
5377 // We have a valid eSymbolTypeObjCClass class symbol whose
5378 // name matches the current objective C class that we
5379 // are trying to find and this DIE isn't the complete
5380 // definition (we checked is_complete_objc_class above and
5381 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00005382 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005383
Greg Clayton901c5ca2011-12-03 04:40:03 +00005384 if (!type_sp && m_debug_map_symfile)
5385 {
5386 // We weren't able to find a full declaration in
5387 // this DWARF, see if we have a declaration anywhere
5388 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00005389 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00005390 }
5391
5392 if (type_sp)
5393 {
5394 if (log)
5395 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005396 GetObjectFile()->GetModule()->LogMessage (log.get(),
5397 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
5398 this,
5399 die->GetOffset(),
5400 DW_TAG_value_to_name(tag),
5401 type_name_cstr,
5402 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00005403 }
5404
5405 // We found a real definition for this type elsewhere
5406 // so lets use it and cache the fact that we found
5407 // a complete type for this die
5408 m_die_to_type[die] = type_sp.get();
5409 return type_sp;
5410 }
5411 }
5412 }
5413
5414
5415 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005416 {
5417 // We have a forward declaration to a type and we need
5418 // to try and find a full declaration. We look in the
5419 // current type index just in case we have a forward
5420 // declaration followed by an actual declarations in the
5421 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00005422 if (log)
5423 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005424 GetObjectFile()->GetModule()->LogMessage (log.get(),
5425 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5426 this,
5427 die->GetOffset(),
5428 DW_TAG_value_to_name(tag),
5429 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00005430 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005431
Greg Claytona8022fa2012-04-24 21:22:41 +00005432 DWARFDeclContext die_decl_ctx;
5433 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
5434
5435 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5436 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005437
5438 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00005439 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005440 // We weren't able to find a full declaration in
5441 // this DWARF, see if we have a declaration anywhere
5442 // else...
Greg Claytona8022fa2012-04-24 21:22:41 +00005443 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton4272cc72011-02-02 02:24:04 +00005444 }
5445
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005446 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00005447 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00005448 if (log)
5449 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005450 GetObjectFile()->GetModule()->LogMessage (log.get(),
5451 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5452 this,
5453 die->GetOffset(),
5454 DW_TAG_value_to_name(tag),
5455 type_name_cstr,
5456 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00005457 }
5458
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005459 // We found a real definition for this type elsewhere
5460 // so lets use it and cache the fact that we found
5461 // a complete type for this die
5462 m_die_to_type[die] = type_sp.get();
5463 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00005464 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005465 }
5466 assert (tag_decl_kind != -1);
5467 bool clang_type_was_created = false;
5468 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5469 if (clang_type == NULL)
5470 {
Sean Callanan4d04c6a2012-02-09 22:54:11 +00005471 const DWARFDebugInfoEntry *decl_ctx_die;
5472
5473 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton55561e92011-10-26 03:31:36 +00005474 if (accessibility == eAccessNone && decl_ctx)
5475 {
5476 // Check the decl context that contains this class/struct/union.
5477 // If it is a class we must give it an accessability.
5478 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5479 if (DeclKindIsCXXClass (containing_decl_kind))
5480 accessibility = default_accessibility;
5481 }
5482
Greg Claytonf0705c82011-10-22 03:33:13 +00005483 if (type_name_cstr && strchr (type_name_cstr, '<'))
5484 {
5485 ClangASTContext::TemplateParameterInfos template_param_infos;
5486 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5487 {
5488 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00005489 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00005490 type_name_cstr,
5491 tag_decl_kind,
5492 template_param_infos);
5493
5494 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5495 class_template_decl,
5496 tag_decl_kind,
5497 template_param_infos);
5498 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5499 clang_type_was_created = true;
Sean Callanan60217122012-04-13 00:10:03 +00005500
5501 GetClangASTContext().SetMetadata((uintptr_t)class_template_decl, MakeUserID(die->GetOffset()));
5502 GetClangASTContext().SetMetadata((uintptr_t)class_specialization_decl, MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005503 }
5504 }
5505
5506 if (!clang_type_was_created)
5507 {
5508 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00005509 clang_type = ast.CreateRecordType (decl_ctx,
5510 accessibility,
5511 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00005512 tag_decl_kind,
Sean Callanan60217122012-04-13 00:10:03 +00005513 class_language,
Sean Callananad880762012-04-18 01:06:17 +00005514 MakeUserID(die->GetOffset()));
Greg Claytonf0705c82011-10-22 03:33:13 +00005515 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005516 }
5517
5518 // Store a forward declaration to this class type in case any
5519 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00005520 // types for function prototypes.
5521 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00005522 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005523 this,
5524 type_name_const_str,
5525 byte_size,
5526 NULL,
5527 LLDB_INVALID_UID,
5528 Type::eEncodingIsUID,
5529 &decl,
5530 clang_type,
5531 Type::eResolveStateForward));
Sean Callanan72772842012-02-22 23:57:45 +00005532
5533 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005534
5535
5536 // Add our type to the unique type map so we don't
5537 // end up creating many copies of the same type over
5538 // and over in the ASTContext for our module
5539 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00005540 unique_ast_entry.m_symfile = this;
5541 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005542 unique_ast_entry.m_die = die;
5543 unique_ast_entry.m_declaration = decl;
Sean Callanan59700592012-02-13 22:30:16 +00005544 unique_ast_entry.m_byte_size = byte_size;
Greg Claytone576ab22011-02-15 00:19:15 +00005545 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5546 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005547
Sean Callanan12014a02011-12-08 23:45:45 +00005548 if (!is_forward_declaration)
Greg Clayton219cf312012-03-30 00:51:13 +00005549 {
5550 // Always start the definition for a class type so that
5551 // if the class has child classes or types that require
5552 // the class to be created for use as their decl contexts
5553 // the class will be ready to accept these child definitions.
Sean Callanan12014a02011-12-08 23:45:45 +00005554 if (die->HasChildren() == false)
5555 {
5556 // No children for this struct/union/class, lets finish it
5557 ast.StartTagDeclarationDefinition (clang_type);
5558 ast.CompleteTagDeclarationDefinition (clang_type);
5559 }
5560 else if (clang_type_was_created)
5561 {
Greg Clayton219cf312012-03-30 00:51:13 +00005562 // Start the definition if the class is not objective C since
5563 // the underlying decls respond to isCompleteDefinition(). Objective
5564 // C decls dont' respond to isCompleteDefinition() so we can't
5565 // start the declaration definition right away. For C++ classs/union/structs
5566 // we want to start the definition in case the class is needed as the
5567 // declaration context for a contained class or type without the need
5568 // to complete that type..
5569
Sean Callanan7457f8d2012-04-25 01:03:57 +00005570 if (class_language != eLanguageTypeObjC &&
5571 class_language != eLanguageTypeObjC_plus_plus)
Greg Clayton219cf312012-03-30 00:51:13 +00005572 ast.StartTagDeclarationDefinition (clang_type);
5573
Sean Callanan12014a02011-12-08 23:45:45 +00005574 // Leave this as a forward declaration until we need
5575 // to know the details of the type. lldb_private::Type
5576 // will automatically call the SymbolFile virtual function
5577 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5578 // When the definition needs to be defined.
5579 m_forward_decl_die_to_clang_type[die] = clang_type;
5580 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5581 ClangASTContext::SetHasExternalStorage (clang_type, true);
5582 }
Greg Claytonc615ce42010-11-09 04:42:43 +00005583 }
Greg Claytoncab36a32011-12-08 05:16:30 +00005584
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005585 }
5586 break;
5587
5588 case DW_TAG_enumeration_type:
5589 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005590 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005591 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005592
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005593 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005594
Greg Claytond88d7592010-09-15 08:33:30 +00005595 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005596 if (num_attributes > 0)
5597 {
5598 uint32_t i;
5599
5600 for (i=0; i<num_attributes; ++i)
5601 {
5602 attr = attributes.AttributeAtIndex(i);
5603 DWARFFormValue form_value;
5604 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5605 {
5606 switch (attr)
5607 {
Greg Clayton7a345282010-11-09 23:46:37 +00005608 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5609 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5610 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005611 case DW_AT_name:
5612 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005613 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005614 break;
Greg Clayton7a345282010-11-09 23:46:37 +00005615 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005616 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00005617 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5618 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005619 case DW_AT_allocated:
5620 case DW_AT_associated:
5621 case DW_AT_bit_stride:
5622 case DW_AT_byte_stride:
5623 case DW_AT_data_location:
5624 case DW_AT_description:
5625 case DW_AT_start_scope:
5626 case DW_AT_visibility:
5627 case DW_AT_specification:
5628 case DW_AT_abstract_origin:
5629 case DW_AT_sibling:
5630 break;
5631 }
5632 }
5633 }
5634
Greg Clayton81c22f62011-10-19 18:09:39 +00005635 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 +00005636
Greg Clayton1be10fc2010-09-29 01:12:09 +00005637 clang_type_t enumerator_clang_type = NULL;
5638 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5639 if (clang_type == NULL)
5640 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005641 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5642 DW_ATE_signed,
5643 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00005644 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00005645 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00005646 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005647 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00005648 }
5649 else
5650 {
5651 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5652 assert (enumerator_clang_type != NULL);
5653 }
5654
Greg Claytona2721472011-06-25 00:44:06 +00005655 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5656
Greg Clayton81c22f62011-10-19 18:09:39 +00005657 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005658 this,
5659 type_name_const_str,
5660 byte_size,
5661 NULL,
5662 encoding_uid,
5663 Type::eEncodingIsUID,
5664 &decl,
5665 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005666 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005667
Greg Clayton6beaaa62011-01-17 03:46:26 +00005668 ast.StartTagDeclarationDefinition (clang_type);
5669 if (die->HasChildren())
5670 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005671 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5672 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00005673 }
5674 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005675 }
5676 }
5677 break;
5678
Jim Inghamb0be4422010-08-12 01:20:14 +00005679 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005680 case DW_TAG_subprogram:
5681 case DW_TAG_subroutine_type:
5682 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005683 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005684 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005685
5686 const char *mangled = NULL;
5687 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005688 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005689 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005690 bool is_static = false;
5691 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005692 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005693 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005694 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5695 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005696
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005697 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005698 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005699
5700
Greg Claytond88d7592010-09-15 08:33:30 +00005701 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005702 if (num_attributes > 0)
5703 {
5704 uint32_t i;
5705 for (i=0; i<num_attributes; ++i)
5706 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005707 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005708 DWARFFormValue form_value;
5709 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5710 {
5711 switch (attr)
5712 {
5713 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5714 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5715 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5716 case DW_AT_name:
5717 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005718 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005719 break;
5720
5721 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5722 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005723 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005724 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005725 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5726 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005727 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005728 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5729
Greg Claytonf51de672010-10-01 02:31:07 +00005730
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005731 case DW_AT_external:
5732 if (form_value.Unsigned())
5733 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005734 if (storage == clang::SC_None)
5735 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005736 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005737 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005738 }
5739 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005740
Greg Clayton72da3972011-08-16 18:40:23 +00005741 case DW_AT_specification:
5742 specification_die_offset = form_value.Reference(dwarf_cu);
5743 break;
5744
5745 case DW_AT_abstract_origin:
5746 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5747 break;
5748
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005749 case DW_AT_allocated:
5750 case DW_AT_associated:
5751 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005752 case DW_AT_calling_convention:
5753 case DW_AT_data_location:
5754 case DW_AT_elemental:
5755 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005756 case DW_AT_frame_base:
5757 case DW_AT_high_pc:
5758 case DW_AT_low_pc:
5759 case DW_AT_object_pointer:
5760 case DW_AT_prototyped:
5761 case DW_AT_pure:
5762 case DW_AT_ranges:
5763 case DW_AT_recursive:
5764 case DW_AT_return_addr:
5765 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005766 case DW_AT_start_scope:
5767 case DW_AT_static_link:
5768 case DW_AT_trampoline:
5769 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005770 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005771 case DW_AT_description:
5772 case DW_AT_sibling:
5773 break;
5774 }
5775 }
5776 }
Greg Clayton24739922010-10-13 03:15:28 +00005777 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005778
Greg Clayton81c22f62011-10-19 18:09:39 +00005779 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 +00005780
Greg Clayton24739922010-10-13 03:15:28 +00005781 clang_type_t return_clang_type = NULL;
5782 Type *func_type = NULL;
5783
5784 if (type_die_offset != DW_INVALID_OFFSET)
5785 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005786
Greg Clayton24739922010-10-13 03:15:28 +00005787 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005788 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005789 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005790 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005791
Greg Claytonf51de672010-10-01 02:31:07 +00005792
Greg Clayton24739922010-10-13 03:15:28 +00005793 std::vector<clang_type_t> function_param_types;
5794 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005795
Greg Clayton24739922010-10-13 03:15:28 +00005796 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005797
Greg Claytoncb5860a2011-10-13 23:49:28 +00005798 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5799 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005800 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5801
Greg Claytonf0705c82011-10-22 03:33:13 +00005802 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005803 // Start off static. This will be set to false in ParseChildParameters(...)
5804 // if we find a "this" paramters as the first parameter
5805 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005806 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005807 ClangASTContext::TemplateParameterInfos template_param_infos;
5808
Greg Clayton24739922010-10-13 03:15:28 +00005809 if (die->HasChildren())
5810 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005811 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005812 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005813 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005814 dwarf_cu,
5815 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005816 skip_artificial,
5817 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005818 type_list,
5819 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005820 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005821 type_quals,
5822 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005823 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005824
Greg Clayton24739922010-10-13 03:15:28 +00005825 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005826 clang_type = ast.CreateFunctionType (return_clang_type,
5827 &function_param_types[0],
5828 function_param_types.size(),
5829 is_variadic,
5830 type_quals);
5831
Greg Clayton24739922010-10-13 03:15:28 +00005832 if (type_name_cstr)
5833 {
5834 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005835 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005836 {
Greg Clayton7c810422012-01-18 23:40:49 +00005837 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005838 ConstString class_name_no_category;
5839 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005840 {
Greg Claytone42ae842012-01-19 03:24:53 +00005841 // Use the class name with no category if there is one
5842 if (class_name_no_category)
5843 class_name = class_name_no_category;
5844
Greg Clayton24739922010-10-13 03:15:28 +00005845 SymbolContext empty_sc;
5846 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005847 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005848 {
Greg Clayton24739922010-10-13 03:15:28 +00005849 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005850 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005851
5852 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005853 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005854 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5855 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5856 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005857 }
Greg Clayton24739922010-10-13 03:15:28 +00005858 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005859
Greg Clayton24739922010-10-13 03:15:28 +00005860 if (class_opaque_type)
5861 {
5862 // If accessibility isn't set to anything valid, assume public for
5863 // now...
5864 if (accessibility == eAccessNone)
5865 accessibility = eAccessPublic;
5866
5867 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005868 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5869 type_name_cstr,
5870 clang_type,
5871 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005872 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005873 type_handled = objc_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00005874 GetClangASTContext().SetMetadata((uintptr_t)objc_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00005875 }
5876 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005877 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005878 {
5879 // Look at the parent of this DIE and see if is is
5880 // a class or struct and see if this is actually a
5881 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005882 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005883 if (class_type)
5884 {
Greg Clayton4116e932012-05-15 02:33:01 +00005885 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
5886 {
5887 // We uniqued the parent class of this function to another class
5888 // so we now need to associate all dies under "decl_ctx_die" to
5889 // DIEs in the DIE for "class_type"...
5890 DWARFCompileUnitSP class_type_cu_sp;
5891 const DWARFDebugInfoEntry *class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
5892 if (class_type_die)
5893 {
5894 if (CopyUniqueClassMethodTypes (class_type,
5895 class_type_cu_sp.get(),
5896 class_type_die,
5897 dwarf_cu,
5898 decl_ctx_die))
5899 {
5900 type_ptr = m_die_to_type[die];
5901 if (type_ptr)
5902 {
5903 type_sp = type_ptr->shared_from_this();
5904 break;
5905 }
5906 }
5907 }
5908 }
5909
Greg Clayton72da3972011-08-16 18:40:23 +00005910 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005911 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005912 // We have a specification which we are going to base our function
5913 // prototype off of, so we need this type to be completed so that the
5914 // m_die_to_decl_ctx for the method in the specification has a valid
5915 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005916 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005917 // If we have a specification, then the function type should have been
5918 // made with the specification and not with this die.
5919 DWARFCompileUnitSP spec_cu_sp;
5920 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005921 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005922 if (spec_clang_decl_ctx)
5923 {
5924 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5925 }
5926 else
Jim Inghamc1663042011-09-29 22:12:35 +00005927 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005928 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5929 MakeUserID(die->GetOffset()),
5930 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005931 }
Greg Clayton72da3972011-08-16 18:40:23 +00005932 type_handled = true;
5933 }
5934 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5935 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005936 // We have a specification which we are going to base our function
5937 // prototype off of, so we need this type to be completed so that the
5938 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5939 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005940 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005941
Greg Clayton72da3972011-08-16 18:40:23 +00005942 DWARFCompileUnitSP abs_cu_sp;
5943 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Eric Christopher6cc6e602012-03-25 19:37:33 +00005944 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005945 if (abs_clang_decl_ctx)
5946 {
5947 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5948 }
5949 else
Jim Inghamc1663042011-09-29 22:12:35 +00005950 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005951 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5952 MakeUserID(die->GetOffset()),
5953 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005954 }
Greg Clayton72da3972011-08-16 18:40:23 +00005955 type_handled = true;
5956 }
5957 else
5958 {
5959 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5960 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005961 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005962 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005963 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005964 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5965 // in the DWARF for C++ methods... Default to public for now...
5966 if (accessibility == eAccessNone)
5967 accessibility = eAccessPublic;
5968
5969 if (!is_static && !die->HasChildren())
5970 {
5971 // We have a C++ member function with no children (this pointer!)
5972 // and clang will get mad if we try and make a function that isn't
5973 // well formed in the DWARF, so we will just skip it...
5974 type_handled = true;
5975 }
5976 else
5977 {
5978 clang::CXXMethodDecl *cxx_method_decl;
5979 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005980 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 +00005981 type_name_cstr,
5982 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005983 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005984 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5985 m_obj_file->GetFileSpec().GetFilename().GetCString());
5986
Sean Callananc1b732d2011-11-01 18:07:13 +00005987 const bool is_attr_used = false;
5988
Greg Clayton20568dd2011-10-13 23:13:20 +00005989 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5990 type_name_cstr,
5991 clang_type,
5992 accessibility,
5993 is_virtual,
5994 is_static,
5995 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005996 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005997 is_attr_used,
5998 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005999 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6000
Greg Claytonf49e65a2011-11-10 18:31:53 +00006001 Host::SetCrashDescription (NULL);
6002
Greg Clayton20568dd2011-10-13 23:13:20 +00006003 type_handled = cxx_method_decl != NULL;
Sean Callanan60217122012-04-13 00:10:03 +00006004
6005 GetClangASTContext().SetMetadata((uintptr_t)cxx_method_decl, MakeUserID(die->GetOffset()));
Greg Clayton20568dd2011-10-13 23:13:20 +00006006 }
Greg Clayton72da3972011-08-16 18:40:23 +00006007 }
6008 else
6009 {
Greg Clayton20568dd2011-10-13 23:13:20 +00006010 // We were asked to parse the type for a method in a class, yet the
6011 // class hasn't been asked to complete itself through the
6012 // clang::ExternalASTSource protocol, so we need to just have the
6013 // class complete itself and do things the right way, then our
6014 // DIE should then have an entry in the m_die_to_type map. First
6015 // we need to modify the m_die_to_type so it doesn't think we are
6016 // trying to parse this DIE anymore...
6017 m_die_to_type[die] = NULL;
6018
6019 // Now we get the full type to force our class type to complete itself
6020 // using the clang::ExternalASTSource protocol which will parse all
6021 // base classes and all methods (including the method for this DIE).
6022 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00006023
Greg Clayton20568dd2011-10-13 23:13:20 +00006024 // The type for this DIE should have been filled in the function call above
6025 type_ptr = m_die_to_type[die];
6026 if (type_ptr)
6027 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006028 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00006029 break;
6030 }
Sean Callanan02eee4d2012-04-12 23:10:00 +00006031
6032 // FIXME This is fixing some even uglier behavior but we really need to
6033 // uniq the methods of each class as well as the class itself.
6034 // <rdar://problem/11240464>
6035 type_handled = true;
Greg Clayton72da3972011-08-16 18:40:23 +00006036 }
Greg Clayton931180e2011-01-27 06:44:37 +00006037 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006038 }
6039 }
Greg Clayton0fffff52010-09-24 05:15:53 +00006040 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006041 }
Greg Clayton24739922010-10-13 03:15:28 +00006042
6043 if (!type_handled)
6044 {
6045 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00006046 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
6047 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006048 clang_type,
6049 storage,
6050 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00006051
6052// if (template_param_infos.GetSize() > 0)
6053// {
6054// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6055// function_decl,
6056// type_name_cstr,
6057// template_param_infos);
6058//
6059// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6060// func_template_decl,
6061// template_param_infos);
6062// }
Greg Clayton24739922010-10-13 03:15:28 +00006063 // Add the decl to our DIE to decl context map
6064 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00006065 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00006066 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006067 ast.SetFunctionParameters (function_decl,
6068 &function_param_decls.front(),
6069 function_param_decls.size());
Sean Callanan60217122012-04-13 00:10:03 +00006070
6071 GetClangASTContext().SetMetadata((uintptr_t)function_decl, MakeUserID(die->GetOffset()));
Greg Clayton24739922010-10-13 03:15:28 +00006072 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006073 }
Greg Clayton81c22f62011-10-19 18:09:39 +00006074 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006075 this,
6076 type_name_const_str,
6077 0,
6078 NULL,
6079 LLDB_INVALID_UID,
6080 Type::eEncodingIsUID,
6081 &decl,
6082 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006083 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00006084 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006085 }
6086 break;
6087
6088 case DW_TAG_array_type:
6089 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006090 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00006091 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006092
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006093 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006094 int64_t first_index = 0;
6095 uint32_t byte_stride = 0;
6096 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00006097 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006098
6099 if (num_attributes > 0)
6100 {
6101 uint32_t i;
6102 for (i=0; i<num_attributes; ++i)
6103 {
6104 attr = attributes.AttributeAtIndex(i);
6105 DWARFFormValue form_value;
6106 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6107 {
6108 switch (attr)
6109 {
6110 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6111 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6112 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6113 case DW_AT_name:
6114 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00006115 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006116 break;
6117
6118 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00006119 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006120 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6121 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00006122 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00006123 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006124 case DW_AT_allocated:
6125 case DW_AT_associated:
6126 case DW_AT_data_location:
6127 case DW_AT_description:
6128 case DW_AT_ordering:
6129 case DW_AT_start_scope:
6130 case DW_AT_visibility:
6131 case DW_AT_specification:
6132 case DW_AT_abstract_origin:
6133 case DW_AT_sibling:
6134 break;
6135 }
6136 }
6137 }
6138
Greg Clayton81c22f62011-10-19 18:09:39 +00006139 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 +00006140
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006141 Type *element_type = ResolveTypeUID(type_die_offset);
6142
6143 if (element_type)
6144 {
6145 std::vector<uint64_t> element_orders;
6146 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00006147 // We have an array that claims to have no members, lets give it at least one member...
6148 if (element_orders.empty())
6149 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006150 if (byte_stride == 0 && bit_stride == 0)
6151 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00006152 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006153 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6154 uint64_t num_elements = 0;
6155 std::vector<uint64_t>::const_reverse_iterator pos;
6156 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6157 for (pos = element_orders.rbegin(); pos != end; ++pos)
6158 {
6159 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006160 clang_type = ast.CreateArrayType (array_element_type,
6161 num_elements,
6162 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006163 array_element_type = clang_type;
6164 array_element_bit_stride = array_element_bit_stride * num_elements;
6165 }
6166 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00006167 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006168 this,
6169 empty_name,
6170 array_element_bit_stride / 8,
6171 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00006172 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006173 Type::eEncodingIsUID,
6174 &decl,
6175 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006176 Type::eResolveStateFull));
6177 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006178 }
6179 }
6180 }
6181 break;
6182
Greg Clayton9b81a312010-06-12 01:20:30 +00006183 case DW_TAG_ptr_to_member_type:
6184 {
6185 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6186 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
6187
Greg Claytond88d7592010-09-15 08:33:30 +00006188 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00006189
6190 if (num_attributes > 0) {
6191 uint32_t i;
6192 for (i=0; i<num_attributes; ++i)
6193 {
6194 attr = attributes.AttributeAtIndex(i);
6195 DWARFFormValue form_value;
6196 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6197 {
6198 switch (attr)
6199 {
6200 case DW_AT_type:
6201 type_die_offset = form_value.Reference(dwarf_cu); break;
6202 case DW_AT_containing_type:
6203 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
6204 }
6205 }
6206 }
6207
6208 Type *pointee_type = ResolveTypeUID(type_die_offset);
6209 Type *class_type = ResolveTypeUID(containing_type_die_offset);
6210
Greg Clayton526e5af2010-11-13 03:52:47 +00006211 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
6212 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00006213
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006214 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
6215 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00006216
Greg Clayton526e5af2010-11-13 03:52:47 +00006217 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
6218 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00006219
Greg Clayton81c22f62011-10-19 18:09:39 +00006220 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00006221 this,
6222 type_name_const_str,
6223 byte_size,
6224 NULL,
6225 LLDB_INVALID_UID,
6226 Type::eEncodingIsUID,
6227 NULL,
6228 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00006229 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00006230 }
6231
6232 break;
6233 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006234 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00006235 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006236 break;
6237 }
6238
6239 if (type_sp.get())
6240 {
6241 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6242 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6243
6244 SymbolContextScope * symbol_context_scope = NULL;
6245 if (sc_parent_tag == DW_TAG_compile_unit)
6246 {
6247 symbol_context_scope = sc.comp_unit;
6248 }
6249 else if (sc.function != NULL)
6250 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006251 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006252 if (symbol_context_scope == NULL)
6253 symbol_context_scope = sc.function;
6254 }
6255
6256 if (symbol_context_scope != NULL)
6257 {
6258 type_sp->SetSymbolContextScope(symbol_context_scope);
6259 }
6260
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006261 // We are ready to put this type into the uniqued list up at the module level
6262 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00006263
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00006264 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006265 }
6266 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00006267 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006268 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00006269 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006270 }
6271 }
6272 return type_sp;
6273}
6274
6275size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00006276SymbolFileDWARF::ParseTypes
6277(
6278 const SymbolContext& sc,
6279 DWARFCompileUnit* dwarf_cu,
6280 const DWARFDebugInfoEntry *die,
6281 bool parse_siblings,
6282 bool parse_children
6283)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006284{
6285 size_t types_added = 0;
6286 while (die != NULL)
6287 {
6288 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00006289 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006290 {
6291 if (type_is_new)
6292 ++types_added;
6293 }
6294
6295 if (parse_children && die->HasChildren())
6296 {
6297 if (die->Tag() == DW_TAG_subprogram)
6298 {
6299 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00006300 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006301 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
6302 }
6303 else
6304 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
6305 }
6306
6307 if (parse_siblings)
6308 die = die->GetSibling();
6309 else
6310 die = NULL;
6311 }
6312 return types_added;
6313}
6314
6315
6316size_t
6317SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
6318{
6319 assert(sc.comp_unit && sc.function);
6320 size_t functions_added = 0;
6321 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6322 if (dwarf_cu)
6323 {
6324 dw_offset_t function_die_offset = sc.function->GetID();
6325 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
6326 if (function_die)
6327 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00006328 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006329 }
6330 }
6331
6332 return functions_added;
6333}
6334
6335
6336size_t
6337SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
6338{
6339 // At least a compile unit must be valid
6340 assert(sc.comp_unit);
6341 size_t types_added = 0;
6342 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
6343 if (dwarf_cu)
6344 {
6345 if (sc.function)
6346 {
6347 dw_offset_t function_die_offset = sc.function->GetID();
6348 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
6349 if (func_die && func_die->HasChildren())
6350 {
6351 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
6352 }
6353 }
6354 else
6355 {
6356 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
6357 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
6358 {
6359 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
6360 }
6361 }
6362 }
6363
6364 return types_added;
6365}
6366
6367size_t
6368SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
6369{
6370 if (sc.comp_unit != NULL)
6371 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00006372 DWARFDebugInfo* info = DebugInfo();
6373 if (info == NULL)
6374 return 0;
6375
6376 uint32_t cu_idx = UINT32_MAX;
6377 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006378
6379 if (dwarf_cu == NULL)
6380 return 0;
6381
6382 if (sc.function)
6383 {
6384 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00006385
6386 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 +00006387 if (func_lo_pc != DW_INVALID_ADDRESS)
6388 {
6389 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00006390
Greg Claytone38a5ed2012-01-05 03:57:59 +00006391 // Let all blocks know they have parse all their variables
6392 sc.function->GetBlock (false).SetDidParseVariables (true, true);
6393 return num_variables;
6394 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006395 }
6396 else if (sc.comp_unit)
6397 {
6398 uint32_t vars_added = 0;
6399 VariableListSP variables (sc.comp_unit->GetVariableList(false));
6400
6401 if (variables.get() == NULL)
6402 {
6403 variables.reset(new VariableList());
6404 sc.comp_unit->SetVariableList(variables);
6405
Greg Claytond4a2b372011-09-12 23:21:58 +00006406 DWARFCompileUnit* match_dwarf_cu = NULL;
6407 const DWARFDebugInfoEntry* die = NULL;
6408 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00006409 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00006410 {
Greg Clayton97fbc342011-10-20 22:30:33 +00006411 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00006412 {
6413 DWARFMappedHash::DIEInfoArray hash_data_array;
6414 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
6415 dwarf_cu->GetNextCompileUnitOffset(),
6416 hash_data_array))
6417 {
6418 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
6419 }
6420 }
Greg Clayton7f995132011-10-04 22:41:51 +00006421 }
6422 else
6423 {
6424 // Index if we already haven't to make sure the compile units
6425 // get indexed and make their global DIE index list
6426 if (!m_indexed)
6427 Index ();
6428
6429 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
6430 dwarf_cu->GetNextCompileUnitOffset(),
6431 die_offsets);
6432 }
6433
6434 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00006435 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006436 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006437 DWARFDebugInfo* debug_info = DebugInfo();
6438 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006439 {
Greg Claytond4a2b372011-09-12 23:21:58 +00006440 const dw_offset_t die_offset = die_offsets[i];
6441 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00006442 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00006443 {
Greg Clayton95d87902011-11-11 03:16:25 +00006444 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
6445 if (var_sp)
6446 {
6447 variables->AddVariableIfUnique (var_sp);
6448 ++vars_added;
6449 }
Greg Claytond4a2b372011-09-12 23:21:58 +00006450 }
Greg Clayton95d87902011-11-11 03:16:25 +00006451 else
6452 {
6453 if (m_using_apple_tables)
6454 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006455 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 +00006456 }
6457 }
6458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006459 }
6460 }
6461 }
6462 return vars_added;
6463 }
6464 }
6465 return 0;
6466}
6467
6468
6469VariableSP
6470SymbolFileDWARF::ParseVariableDIE
6471(
6472 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006473 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006474 const DWARFDebugInfoEntry *die,
6475 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006476)
6477{
6478
Greg Clayton83c5cd92010-11-14 22:13:40 +00006479 VariableSP var_sp (m_die_to_variable_sp[die]);
6480 if (var_sp)
6481 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006482
6483 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00006484
6485 if ((tag == DW_TAG_variable) ||
6486 (tag == DW_TAG_constant) ||
6487 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006488 {
Greg Clayton7f995132011-10-04 22:41:51 +00006489 DWARFDebugInfoEntry::Attributes attributes;
6490 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6491 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006492 {
Greg Clayton7f995132011-10-04 22:41:51 +00006493 const char *name = NULL;
6494 const char *mangled = NULL;
6495 Declaration decl;
6496 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00006497 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00006498 DWARFExpression location;
6499 bool is_external = false;
6500 bool is_artificial = false;
6501 bool location_is_const_value_data = false;
6502 AccessType accessibility = eAccessNone;
6503
6504 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006505 {
Greg Clayton7f995132011-10-04 22:41:51 +00006506 dw_attr_t attr = attributes.AttributeAtIndex(i);
6507 DWARFFormValue form_value;
6508 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006509 {
Greg Clayton7f995132011-10-04 22:41:51 +00006510 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006511 {
Greg Clayton7f995132011-10-04 22:41:51 +00006512 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6513 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6514 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6515 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
6516 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00006517 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00006518 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
6519 case DW_AT_const_value:
6520 location_is_const_value_data = true;
6521 // Fall through...
6522 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006523 {
Greg Clayton7f995132011-10-04 22:41:51 +00006524 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006525 {
Greg Clayton7f995132011-10-04 22:41:51 +00006526 const DataExtractor& debug_info_data = get_debug_info_data();
6527
6528 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6529 uint32_t block_length = form_value.Unsigned();
6530 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6531 }
6532 else
6533 {
6534 const DataExtractor& debug_loc_data = get_debug_loc_data();
6535 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6536
6537 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6538 if (loc_list_length > 0)
6539 {
6540 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6541 assert (func_low_pc != LLDB_INVALID_ADDRESS);
6542 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6543 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006544 }
6545 }
Greg Clayton7f995132011-10-04 22:41:51 +00006546 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006547
Greg Clayton7f995132011-10-04 22:41:51 +00006548 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
6549 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6550 case DW_AT_declaration:
6551 case DW_AT_description:
6552 case DW_AT_endianity:
6553 case DW_AT_segment:
6554 case DW_AT_start_scope:
6555 case DW_AT_visibility:
6556 default:
6557 case DW_AT_abstract_origin:
6558 case DW_AT_sibling:
6559 case DW_AT_specification:
6560 break;
6561 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006562 }
6563 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006564
Greg Clayton7f995132011-10-04 22:41:51 +00006565 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006566 {
Greg Clayton7f995132011-10-04 22:41:51 +00006567 ValueType scope = eValueTypeInvalid;
6568
6569 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6570 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006571 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00006572
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006573 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6574 // or static variable, so we have to do a little digging by
6575 // looking at the location of a varaible to see if it contains
6576 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6577 // somewhere because clang likes to combine small global variables
6578 // into the same symbol and have locations like:
6579 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6580 // So if we don't have a DW_TAG_formal_parameter, we can look at
6581 // the location to see if it contains a DW_OP_addr opcode, and
6582 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00006583 if (tag == DW_TAG_formal_parameter)
6584 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00006585 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006586 {
Greg Clayton96c09682012-01-04 22:56:43 +00006587 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00006588 // Check if the location has a DW_OP_addr with any address value...
6589 addr_t location_has_op_addr = false;
6590 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00006591 {
6592 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6593 if (op_error)
6594 {
6595 StreamString strm;
6596 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00006597 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 +00006598 }
6599 }
Greg Claytond1767f02011-12-08 02:13:16 +00006600
6601 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006602 {
Greg Claytond1767f02011-12-08 02:13:16 +00006603 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006604 {
Greg Claytond1767f02011-12-08 02:13:16 +00006605 scope = eValueTypeVariableGlobal;
6606
6607 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006608 {
Greg Claytond1767f02011-12-08 02:13:16 +00006609 // When leaving the DWARF in the .o files on darwin,
6610 // when we have a global variable that wasn't initialized,
6611 // the .o file might not have allocated a virtual
6612 // address for the global variable. In this case it will
6613 // have created a symbol for the global variable
6614 // that is undefined and external and the value will
6615 // be the byte size of the variable. When we do the
6616 // address map in SymbolFileDWARFDebugMap we rely on
6617 // having an address, we need to do some magic here
6618 // so we can get the correct address for our global
6619 // variable. The address for all of these entries
6620 // will be zero, and there will be an undefined symbol
6621 // in this object file, and the executable will have
6622 // a matching symbol with a good address. So here we
6623 // dig up the correct address and replace it in the
6624 // location for the variable, and set the variable's
6625 // symbol context scope to be that of the main executable
6626 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00006627 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006628 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006629
Greg Claytond1767f02011-12-08 02:13:16 +00006630 // we have a possible uninitialized extern global
6631 Symtab *symtab = m_obj_file->GetSymtab();
6632 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006633 {
Greg Claytond1767f02011-12-08 02:13:16 +00006634 ConstString const_name(name);
6635 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6636 eSymbolTypeUndefined,
6637 Symtab::eDebugNo,
6638 Symtab::eVisibilityExtern);
6639
6640 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006641 {
Greg Claytond1767f02011-12-08 02:13:16 +00006642 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6643 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006644 {
Greg Claytond1767f02011-12-08 02:13:16 +00006645 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6646 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6647 eSymbolTypeData,
6648 Symtab::eDebugYes,
6649 Symtab::eVisibilityExtern);
6650 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006651 {
Greg Claytone7612132012-03-07 21:03:09 +00006652 if (defined_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006653 {
Greg Claytone7612132012-03-07 21:03:09 +00006654 const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
Greg Claytond1767f02011-12-08 02:13:16 +00006655 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006656 {
Greg Claytond1767f02011-12-08 02:13:16 +00006657 if (location.Update_DW_OP_addr (defined_addr))
6658 {
6659 symbol_context_scope = defined_symbol;
6660 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006661 }
6662 }
6663 }
6664 }
6665 }
6666 }
6667 }
6668 }
6669 }
Greg Claytond1767f02011-12-08 02:13:16 +00006670 else
6671 {
6672 scope = eValueTypeVariableStatic;
6673 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006674 }
6675 else
Greg Claytond1767f02011-12-08 02:13:16 +00006676 {
6677 scope = eValueTypeVariableLocal;
6678 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006679 }
Greg Clayton7f995132011-10-04 22:41:51 +00006680
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006681 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00006682 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006683 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00006684 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00006685 case DW_TAG_subprogram:
6686 case DW_TAG_inlined_subroutine:
6687 case DW_TAG_lexical_block:
6688 if (sc.function)
6689 {
6690 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6691 if (symbol_context_scope == NULL)
6692 symbol_context_scope = sc.function;
6693 }
6694 break;
6695
6696 default:
6697 symbol_context_scope = sc.comp_unit;
6698 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00006699 }
Greg Clayton7f995132011-10-04 22:41:51 +00006700 }
6701
Greg Clayton5cf58b92011-10-05 22:22:08 +00006702 if (symbol_context_scope)
6703 {
Greg Clayton81c22f62011-10-19 18:09:39 +00006704 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6705 name,
6706 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006707 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006708 scope,
6709 symbol_context_scope,
6710 &decl,
6711 location,
6712 is_external,
6713 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006714
6715 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6716 }
6717 else
6718 {
6719 // Not ready to parse this variable yet. It might be a global
6720 // or static variable that is in a function scope and the function
6721 // in the symbol context wasn't filled in yet
6722 return var_sp;
6723 }
Greg Clayton7f995132011-10-04 22:41:51 +00006724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006725 }
Greg Clayton7f995132011-10-04 22:41:51 +00006726 // Cache var_sp even if NULL (the variable was just a specification or
6727 // was missing vital information to be able to be displayed in the debugger
6728 // (missing location due to optimization, etc)) so we don't re-parse
6729 // this DIE over and over later...
6730 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006731 }
6732 return var_sp;
6733}
6734
Greg Claytonc662ec82011-06-17 22:10:16 +00006735
6736const DWARFDebugInfoEntry *
6737SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6738 dw_offset_t spec_block_die_offset,
6739 DWARFCompileUnit **result_die_cu_handle)
6740{
6741 // Give the concrete function die specified by "func_die_offset", find the
6742 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6743 // to "spec_block_die_offset"
6744 DWARFDebugInfo* info = DebugInfo();
6745
6746 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6747 if (die)
6748 {
6749 assert (*result_die_cu_handle);
6750 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6751 }
6752 return NULL;
6753}
6754
6755
6756const DWARFDebugInfoEntry *
6757SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6758 const DWARFDebugInfoEntry *die,
6759 dw_offset_t spec_block_die_offset,
6760 DWARFCompileUnit **result_die_cu_handle)
6761{
6762 if (die)
6763 {
6764 switch (die->Tag())
6765 {
6766 case DW_TAG_subprogram:
6767 case DW_TAG_inlined_subroutine:
6768 case DW_TAG_lexical_block:
6769 {
6770 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6771 {
6772 *result_die_cu_handle = dwarf_cu;
6773 return die;
6774 }
6775
6776 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6777 {
6778 *result_die_cu_handle = dwarf_cu;
6779 return die;
6780 }
6781 }
6782 break;
6783 }
6784
6785 // Give the concrete function die specified by "func_die_offset", find the
6786 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6787 // to "spec_block_die_offset"
6788 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6789 {
6790 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6791 child_die,
6792 spec_block_die_offset,
6793 result_die_cu_handle);
6794 if (result_die)
6795 return result_die;
6796 }
6797 }
6798
6799 *result_die_cu_handle = NULL;
6800 return NULL;
6801}
6802
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006803size_t
6804SymbolFileDWARF::ParseVariables
6805(
6806 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006807 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006808 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006809 const DWARFDebugInfoEntry *orig_die,
6810 bool parse_siblings,
6811 bool parse_children,
6812 VariableList* cc_variable_list
6813)
6814{
6815 if (orig_die == NULL)
6816 return 0;
6817
Greg Claytonc662ec82011-06-17 22:10:16 +00006818 VariableListSP variable_list_sp;
6819
6820 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006821 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006822 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006823 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006824 dw_tag_t tag = die->Tag();
6825
6826 // Check to see if we have already parsed this variable or constant?
6827 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006828 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006829 if (cc_variable_list)
6830 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006831 }
6832 else
6833 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006834 // We haven't already parsed it, lets do that now.
6835 if ((tag == DW_TAG_variable) ||
6836 (tag == DW_TAG_constant) ||
6837 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006838 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006839 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006840 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006841 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6842 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6843 switch (parent_tag)
6844 {
6845 case DW_TAG_compile_unit:
6846 if (sc.comp_unit != NULL)
6847 {
6848 variable_list_sp = sc.comp_unit->GetVariableList(false);
6849 if (variable_list_sp.get() == NULL)
6850 {
6851 variable_list_sp.reset(new VariableList());
6852 sc.comp_unit->SetVariableList(variable_list_sp);
6853 }
6854 }
6855 else
6856 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006857 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6858 MakeUserID(sc_parent_die->GetOffset()),
6859 DW_TAG_value_to_name (parent_tag),
6860 MakeUserID(orig_die->GetOffset()),
6861 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006862 }
6863 break;
6864
6865 case DW_TAG_subprogram:
6866 case DW_TAG_inlined_subroutine:
6867 case DW_TAG_lexical_block:
6868 if (sc.function != NULL)
6869 {
6870 // Check to see if we already have parsed the variables for the given scope
6871
Greg Clayton81c22f62011-10-19 18:09:39 +00006872 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006873 if (block == NULL)
6874 {
6875 // This must be a specification or abstract origin with
6876 // a concrete block couterpart in the current function. We need
6877 // to find the concrete block so we can correctly add the
6878 // variable to it
6879 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6880 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6881 sc_parent_die->GetOffset(),
6882 &concrete_block_die_cu);
6883 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006884 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006885 }
6886
6887 if (block != NULL)
6888 {
6889 const bool can_create = false;
6890 variable_list_sp = block->GetBlockVariableList (can_create);
6891 if (variable_list_sp.get() == NULL)
6892 {
6893 variable_list_sp.reset(new VariableList());
6894 block->SetVariableList(variable_list_sp);
6895 }
6896 }
6897 }
6898 break;
6899
6900 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006901 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6902 MakeUserID(orig_die->GetOffset()),
6903 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006904 break;
6905 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006906 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006907
6908 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006909 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006910 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6911 if (var_sp)
6912 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006913 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006914 if (cc_variable_list)
6915 cc_variable_list->AddVariableIfUnique (var_sp);
6916 ++vars_added;
6917 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006918 }
6919 }
6920 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006921
6922 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6923
6924 if (!skip_children && parse_children && die->HasChildren())
6925 {
6926 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6927 }
6928
6929 if (parse_siblings)
6930 die = die->GetSibling();
6931 else
6932 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006933 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006934 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006935}
6936
6937//------------------------------------------------------------------
6938// PluginInterface protocol
6939//------------------------------------------------------------------
6940const char *
6941SymbolFileDWARF::GetPluginName()
6942{
6943 return "SymbolFileDWARF";
6944}
6945
6946const char *
6947SymbolFileDWARF::GetShortPluginName()
6948{
6949 return GetPluginNameStatic();
6950}
6951
6952uint32_t
6953SymbolFileDWARF::GetPluginVersion()
6954{
6955 return 1;
6956}
6957
6958void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006959SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6960{
6961 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6962 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6963 if (clang_type)
6964 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6965}
6966
6967void
6968SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6969{
6970 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6971 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6972 if (clang_type)
6973 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6974}
6975
Greg Claytona2721472011-06-25 00:44:06 +00006976void
Sean Callanancc427fa2011-07-30 02:42:06 +00006977SymbolFileDWARF::DumpIndexes ()
6978{
6979 StreamFile s(stdout, false);
6980
6981 s.Printf ("DWARF index for (%s) '%s/%s':",
6982 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6983 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6984 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6985 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6986 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6987 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6988 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6989 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6990 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6991 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6992 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6993}
6994
6995void
6996SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6997 const char *name,
6998 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006999{
Sean Callanancc427fa2011-07-30 02:42:06 +00007000 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00007001
7002 if (iter == m_decl_ctx_to_die.end())
7003 return;
7004
Greg Claytoncb5860a2011-10-13 23:49:28 +00007005 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00007006 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007007 const DWARFDebugInfoEntry *context_die = *pos;
7008
7009 if (!results)
7010 return;
7011
7012 DWARFDebugInfo* info = DebugInfo();
7013
7014 DIEArray die_offsets;
7015
7016 DWARFCompileUnit* dwarf_cu = NULL;
7017 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00007018
7019 if (m_using_apple_tables)
7020 {
7021 if (m_apple_types_ap.get())
7022 m_apple_types_ap->FindByName (name, die_offsets);
7023 }
7024 else
7025 {
7026 if (!m_indexed)
7027 Index ();
7028
7029 m_type_index.Find (ConstString(name), die_offsets);
7030 }
7031
Greg Clayton220a0072011-12-09 08:48:30 +00007032 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007033
7034 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00007035 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00007036 for (size_t i = 0; i < num_matches; ++i)
7037 {
7038 const dw_offset_t die_offset = die_offsets[i];
7039 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00007040
Greg Claytoncb5860a2011-10-13 23:49:28 +00007041 if (die->GetParent() != context_die)
7042 continue;
7043
7044 Type *matching_type = ResolveType (dwarf_cu, die);
7045
Greg Clayton42ce2f32011-12-12 21:50:19 +00007046 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00007047 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
7048
7049 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7050 {
7051 clang::TagDecl *tag_decl = tag_type->getDecl();
7052 results->push_back(tag_decl);
7053 }
7054 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7055 {
7056 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7057 results->push_back(typedef_decl);
7058 }
Greg Claytona2721472011-06-25 00:44:06 +00007059 }
7060 }
7061 }
7062}
7063
7064void
7065SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00007066 const clang::DeclContext *decl_context,
7067 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00007068 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7069{
Greg Clayton85ae2e12011-10-18 23:36:41 +00007070
7071 switch (decl_context->getDeclKind())
7072 {
7073 case clang::Decl::Namespace:
7074 case clang::Decl::TranslationUnit:
7075 {
7076 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7077 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7078 }
7079 break;
7080 default:
7081 break;
7082 }
Greg Claytona2721472011-06-25 00:44:06 +00007083}
Greg Claytoncaab74e2012-01-28 00:48:57 +00007084
7085bool
7086SymbolFileDWARF::LayoutRecordType (void *baton,
7087 const clang::RecordDecl *record_decl,
7088 uint64_t &size,
7089 uint64_t &alignment,
7090 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7091 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7092 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7093{
7094 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7095 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7096}
7097
7098
7099bool
7100SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7101 uint64_t &bit_size,
7102 uint64_t &alignment,
7103 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7104 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7105 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7106{
7107 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7108 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7109 bool success = false;
7110 base_offsets.clear();
7111 vbase_offsets.clear();
7112 if (pos != m_record_decl_to_layout_map.end())
7113 {
7114 bit_size = pos->second.bit_size;
7115 alignment = pos->second.alignment;
7116 field_offsets.swap(pos->second.field_offsets);
7117 m_record_decl_to_layout_map.erase(pos);
7118 success = true;
7119 }
7120 else
7121 {
7122 bit_size = 0;
7123 alignment = 0;
7124 field_offsets.clear();
7125 }
7126
7127 if (log)
7128 GetObjectFile()->GetModule()->LogMessage (log.get(),
7129 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
7130 record_decl,
7131 bit_size,
7132 alignment,
7133 (uint32_t)field_offsets.size(),
7134 (uint32_t)base_offsets.size(),
7135 (uint32_t)vbase_offsets.size(),
7136 success);
7137 return success;
7138}
7139
7140
7141