blob: 80b6b06dcd8c65a6e87661901cc3667ae372e6f3 [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"
60#include "DWARFDIECollection.h"
61#include "DWARFFormValue.h"
62#include "DWARFLocationList.h"
63#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000064#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
66#include <map>
67
Greg Clayton62742b12010-11-11 01:09:45 +000068//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000069
70#ifdef ENABLE_DEBUG_PRINTF
71#include <stdio.h>
72#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
73#else
74#define DEBUG_PRINTF(fmt, ...)
75#endif
76
Greg Clayton594e5ed2010-09-27 21:07:38 +000077#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
79using namespace lldb;
80using namespace lldb_private;
81
Greg Clayton3bffb082011-12-10 02:15:28 +000082static inline bool
Sean Callanan5b26f272012-02-04 08:49:35 +000083child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
Greg Clayton3bffb082011-12-10 02:15:28 +000084{
Sean Callanan5b26f272012-02-04 08:49:35 +000085 switch (tag)
86 {
87 default:
88 break;
89 case DW_TAG_subprogram:
90 case DW_TAG_inlined_subroutine:
91 case DW_TAG_class_type:
92 case DW_TAG_structure_type:
93 case DW_TAG_union_type:
94 return true;
95 }
96 return false;
Greg Clayton3bffb082011-12-10 02:15:28 +000097}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098
Sean Callananc7fbf732010-08-06 00:32:49 +000099static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +0000100DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101{
102 switch (dwarf_accessibility)
103 {
Sean Callananc7fbf732010-08-06 00:32:49 +0000104 case DW_ACCESS_public: return eAccessPublic;
105 case DW_ACCESS_private: return eAccessPrivate;
106 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +0000107 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108 }
Sean Callananc7fbf732010-08-06 00:32:49 +0000109 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
112void
113SymbolFileDWARF::Initialize()
114{
115 LogChannelDWARF::Initialize();
116 PluginManager::RegisterPlugin (GetPluginNameStatic(),
117 GetPluginDescriptionStatic(),
118 CreateInstance);
119}
120
121void
122SymbolFileDWARF::Terminate()
123{
124 PluginManager::UnregisterPlugin (CreateInstance);
125 LogChannelDWARF::Initialize();
126}
127
128
129const char *
130SymbolFileDWARF::GetPluginNameStatic()
131{
Greg Claytond4a2b372011-09-12 23:21:58 +0000132 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133}
134
135const char *
136SymbolFileDWARF::GetPluginDescriptionStatic()
137{
138 return "DWARF and DWARF3 debug symbol file reader.";
139}
140
141
142SymbolFile*
143SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
144{
145 return new SymbolFileDWARF(obj_file);
146}
147
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000148TypeList *
149SymbolFileDWARF::GetTypeList ()
150{
151 if (m_debug_map_symfile)
152 return m_debug_map_symfile->GetTypeList();
153 return m_obj_file->GetModule()->GetTypeList();
154
155}
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157//----------------------------------------------------------------------
158// Gets the first parent that is a lexical block, function or inlined
159// subroutine, or compile unit.
160//----------------------------------------------------------------------
161static const DWARFDebugInfoEntry *
162GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
163{
164 const DWARFDebugInfoEntry *die;
165 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
166 {
167 dw_tag_t tag = die->Tag();
168
169 switch (tag)
170 {
171 case DW_TAG_compile_unit:
172 case DW_TAG_subprogram:
173 case DW_TAG_inlined_subroutine:
174 case DW_TAG_lexical_block:
175 return die;
176 }
177 }
178 return NULL;
179}
180
181
Greg Clayton450e3f32010-10-12 02:24:53 +0000182SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
183 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000184 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 +0000185 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000186 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000188 m_data_debug_abbrev (),
189 m_data_debug_aranges (),
190 m_data_debug_frame (),
191 m_data_debug_info (),
192 m_data_debug_line (),
193 m_data_debug_loc (),
194 m_data_debug_ranges (),
195 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000196 m_data_apple_names (),
197 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000198 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 m_info(),
201 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000202 m_apple_names_ap (),
203 m_apple_types_ap (),
204 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000205 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000206 m_function_basename_index(),
207 m_function_fullname_index(),
208 m_function_method_index(),
209 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000210 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000211 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000212 m_type_index(),
213 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000214 m_indexed (false),
215 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000216 m_using_apple_tables (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000217 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000218 m_ranges(),
219 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220{
221}
222
223SymbolFileDWARF::~SymbolFileDWARF()
224{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000225 if (m_is_external_ast_source)
226 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
227}
228
229static const ConstString &
230GetDWARFMachOSegmentName ()
231{
232 static ConstString g_dwarf_section_name ("__DWARF");
233 return g_dwarf_section_name;
234}
235
Greg Claytone576ab22011-02-15 00:19:15 +0000236UniqueDWARFASTTypeMap &
237SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
238{
239 if (m_debug_map_symfile)
240 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
241 return m_unique_ast_type_map;
242}
243
Greg Clayton6beaaa62011-01-17 03:46:26 +0000244ClangASTContext &
245SymbolFileDWARF::GetClangASTContext ()
246{
247 if (m_debug_map_symfile)
248 return m_debug_map_symfile->GetClangASTContext ();
249
250 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
251 if (!m_is_external_ast_source)
252 {
253 m_is_external_ast_source = true;
254 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
255 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
256 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000257 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000258 SymbolFileDWARF::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000259 this));
Greg Clayton6beaaa62011-01-17 03:46:26 +0000260 ast.SetExternalSource (ast_source_ap);
261 }
262 return ast;
263}
264
265void
266SymbolFileDWARF::InitializeObject()
267{
268 // Install our external AST source callbacks so we can complete Clang types.
269 Module *module = m_obj_file->GetModule();
270 if (module)
271 {
272 const SectionList *section_list = m_obj_file->GetSectionList();
273
274 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
275
276 // Memory map the DWARF mach-o segment so we have everything mmap'ed
277 // to keep our heap memory usage down.
278 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000279 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000280 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000281 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000282 if (m_data_apple_names.GetByteSize() > 0)
283 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000284 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
285 if (m_apple_names_ap->IsValid())
286 m_using_apple_tables = true;
287 else
Greg Clayton7f995132011-10-04 22:41:51 +0000288 m_apple_names_ap.reset();
289 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000290 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000291 if (m_data_apple_types.GetByteSize() > 0)
292 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000293 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
294 if (m_apple_types_ap->IsValid())
295 m_using_apple_tables = true;
296 else
Greg Clayton7f995132011-10-04 22:41:51 +0000297 m_apple_types_ap.reset();
298 }
299
300 get_apple_namespaces_data();
301 if (m_data_apple_namespaces.GetByteSize() > 0)
302 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000303 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
304 if (m_apple_namespaces_ap->IsValid())
305 m_using_apple_tables = true;
306 else
Greg Clayton7f995132011-10-04 22:41:51 +0000307 m_apple_namespaces_ap.reset();
308 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000309
Greg Clayton5009f9d2011-10-27 17:55:14 +0000310 get_apple_objc_data();
311 if (m_data_apple_objc.GetByteSize() > 0)
312 {
313 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
314 if (m_apple_objc_ap->IsValid())
315 m_using_apple_tables = true;
316 else
317 m_apple_objc_ap.reset();
318 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319}
320
321bool
322SymbolFileDWARF::SupportedVersion(uint16_t version)
323{
324 return version == 2 || version == 3;
325}
326
327uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000328SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329{
330 uint32_t abilities = 0;
331 if (m_obj_file != NULL)
332 {
333 const Section* section = NULL;
334 const SectionList *section_list = m_obj_file->GetSectionList();
335 if (section_list == NULL)
336 return 0;
337
338 uint64_t debug_abbrev_file_size = 0;
339 uint64_t debug_aranges_file_size = 0;
340 uint64_t debug_frame_file_size = 0;
341 uint64_t debug_info_file_size = 0;
342 uint64_t debug_line_file_size = 0;
343 uint64_t debug_loc_file_size = 0;
344 uint64_t debug_macinfo_file_size = 0;
345 uint64_t debug_pubnames_file_size = 0;
346 uint64_t debug_pubtypes_file_size = 0;
347 uint64_t debug_ranges_file_size = 0;
348 uint64_t debug_str_file_size = 0;
349
Greg Clayton6beaaa62011-01-17 03:46:26 +0000350 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351
352 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000353 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354
Greg Clayton4ceb9982010-07-21 22:54:26 +0000355 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 if (section != NULL)
357 {
358 debug_info_file_size = section->GetByteSize();
359
Greg Clayton4ceb9982010-07-21 22:54:26 +0000360 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 if (section)
362 debug_abbrev_file_size = section->GetByteSize();
363 else
364 m_flags.Set (flagsGotDebugAbbrevData);
365
Greg Clayton4ceb9982010-07-21 22:54:26 +0000366 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367 if (section)
368 debug_aranges_file_size = section->GetByteSize();
369 else
370 m_flags.Set (flagsGotDebugArangesData);
371
Greg Clayton4ceb9982010-07-21 22:54:26 +0000372 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 if (section)
374 debug_frame_file_size = section->GetByteSize();
375 else
376 m_flags.Set (flagsGotDebugFrameData);
377
Greg Clayton4ceb9982010-07-21 22:54:26 +0000378 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 if (section)
380 debug_line_file_size = section->GetByteSize();
381 else
382 m_flags.Set (flagsGotDebugLineData);
383
Greg Clayton4ceb9982010-07-21 22:54:26 +0000384 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 if (section)
386 debug_loc_file_size = section->GetByteSize();
387 else
388 m_flags.Set (flagsGotDebugLocData);
389
Greg Clayton4ceb9982010-07-21 22:54:26 +0000390 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391 if (section)
392 debug_macinfo_file_size = section->GetByteSize();
393 else
394 m_flags.Set (flagsGotDebugMacInfoData);
395
Greg Clayton4ceb9982010-07-21 22:54:26 +0000396 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397 if (section)
398 debug_pubnames_file_size = section->GetByteSize();
399 else
400 m_flags.Set (flagsGotDebugPubNamesData);
401
Greg Clayton4ceb9982010-07-21 22:54:26 +0000402 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 if (section)
404 debug_pubtypes_file_size = section->GetByteSize();
405 else
406 m_flags.Set (flagsGotDebugPubTypesData);
407
Greg Clayton4ceb9982010-07-21 22:54:26 +0000408 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 if (section)
410 debug_ranges_file_size = section->GetByteSize();
411 else
412 m_flags.Set (flagsGotDebugRangesData);
413
Greg Clayton4ceb9982010-07-21 22:54:26 +0000414 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 if (section)
416 debug_str_file_size = section->GetByteSize();
417 else
418 m_flags.Set (flagsGotDebugStrData);
419 }
420
421 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
422 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
423
424 if (debug_line_file_size > 0)
425 abilities |= LineTables;
426
427 if (debug_aranges_file_size > 0)
428 abilities |= AddressAcceleratorTable;
429
430 if (debug_pubnames_file_size > 0)
431 abilities |= FunctionAcceleratorTable;
432
433 if (debug_pubtypes_file_size > 0)
434 abilities |= TypeAcceleratorTable;
435
436 if (debug_macinfo_file_size > 0)
437 abilities |= MacroInformation;
438
439 if (debug_frame_file_size > 0)
440 abilities |= CallFrameInformation;
441 }
442 return abilities;
443}
444
445const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000446SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447{
448 if (m_flags.IsClear (got_flag))
449 {
450 m_flags.Set (got_flag);
451 const SectionList *section_list = m_obj_file->GetSectionList();
452 if (section_list)
453 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000454 Section *section = section_list->FindSectionByType(sect_type, true).get();
455 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 {
457 // See if we memory mapped the DWARF segment?
458 if (m_dwarf_data.GetByteSize())
459 {
460 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
461 }
462 else
463 {
Greg Claytonc9660542012-02-05 02:38:54 +0000464 if (m_obj_file->ReadSectionData (section, data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 data.Clear();
466 }
467 }
468 }
469 }
470 return data;
471}
472
473const DataExtractor&
474SymbolFileDWARF::get_debug_abbrev_data()
475{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000476 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477}
478
479const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000480SymbolFileDWARF::get_debug_aranges_data()
481{
482 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
483}
484
485const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486SymbolFileDWARF::get_debug_frame_data()
487{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000488 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489}
490
491const DataExtractor&
492SymbolFileDWARF::get_debug_info_data()
493{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000494 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495}
496
497const DataExtractor&
498SymbolFileDWARF::get_debug_line_data()
499{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000500 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501}
502
503const DataExtractor&
504SymbolFileDWARF::get_debug_loc_data()
505{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000506 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507}
508
509const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510SymbolFileDWARF::get_debug_ranges_data()
511{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000512 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513}
514
515const DataExtractor&
516SymbolFileDWARF::get_debug_str_data()
517{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000518 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519}
520
Greg Claytonf9eec202011-09-01 23:16:13 +0000521const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000522SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000523{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000524 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000525}
526
527const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000528SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000529{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000530 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000531}
532
Greg Clayton7f995132011-10-04 22:41:51 +0000533const DataExtractor&
534SymbolFileDWARF::get_apple_namespaces_data()
535{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000536 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
537}
538
539const DataExtractor&
540SymbolFileDWARF::get_apple_objc_data()
541{
542 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000543}
544
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545
546DWARFDebugAbbrev*
547SymbolFileDWARF::DebugAbbrev()
548{
549 if (m_abbr.get() == NULL)
550 {
551 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
552 if (debug_abbrev_data.GetByteSize() > 0)
553 {
554 m_abbr.reset(new DWARFDebugAbbrev());
555 if (m_abbr.get())
556 m_abbr->Parse(debug_abbrev_data);
557 }
558 }
559 return m_abbr.get();
560}
561
562const DWARFDebugAbbrev*
563SymbolFileDWARF::DebugAbbrev() const
564{
565 return m_abbr.get();
566}
567
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568
569DWARFDebugInfo*
570SymbolFileDWARF::DebugInfo()
571{
572 if (m_info.get() == NULL)
573 {
574 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
575 if (get_debug_info_data().GetByteSize() > 0)
576 {
577 m_info.reset(new DWARFDebugInfo());
578 if (m_info.get())
579 {
580 m_info->SetDwarfData(this);
581 }
582 }
583 }
584 return m_info.get();
585}
586
587const DWARFDebugInfo*
588SymbolFileDWARF::DebugInfo() const
589{
590 return m_info.get();
591}
592
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593DWARFCompileUnit*
594SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
595{
596 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000597 if (info && UserIDMatches(cu_uid))
598 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599 return NULL;
600}
601
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602
603DWARFDebugRanges*
604SymbolFileDWARF::DebugRanges()
605{
606 if (m_ranges.get() == NULL)
607 {
608 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
609 if (get_debug_ranges_data().GetByteSize() > 0)
610 {
611 m_ranges.reset(new DWARFDebugRanges());
612 if (m_ranges.get())
613 m_ranges->Extract(this);
614 }
615 }
616 return m_ranges.get();
617}
618
619const DWARFDebugRanges*
620SymbolFileDWARF::DebugRanges() const
621{
622 return m_ranges.get();
623}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624
625bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000626SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627{
Greg Clayton96d7d742010-11-10 23:42:09 +0000628 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000630 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631 if (cu_die)
632 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000633 const char * cu_die_name = cu_die->GetName(this, curr_cu);
634 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000635 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 if (cu_die_name)
637 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000638 FileSpec cu_file_spec;
639
Greg Clayton7bd65b92011-02-09 23:39:34 +0000640 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000642 // If we have a full path to the compile unit, we don't need to resolve
643 // the file. This can be expensive e.g. when the source files are NFS mounted.
644 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645 }
646 else
647 {
648 std::string fullpath(cu_comp_dir);
649 if (*fullpath.rbegin() != '/')
650 fullpath += '/';
651 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000652 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 }
654
Greg Clayton81c22f62011-10-19 18:09:39 +0000655 compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
656 curr_cu,
657 cu_file_spec,
658 MakeUserID(curr_cu->GetOffset()),
659 cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 if (compile_unit_sp.get())
661 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000662 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 return true;
664 }
665 }
666 }
667 }
668 return false;
669}
670
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671uint32_t
672SymbolFileDWARF::GetNumCompileUnits()
673{
674 DWARFDebugInfo* info = DebugInfo();
675 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 return 0;
678}
679
680CompUnitSP
681SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
682{
683 CompUnitSP comp_unit;
684 DWARFDebugInfo* info = DebugInfo();
685 if (info)
686 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000687 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
688 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 {
690 // Our symbol vendor shouldn't be asking us to add a compile unit that
691 // has already been added to it, which this DWARF plug-in knows as it
692 // stores the lldb compile unit (CompileUnit) pointer in each
693 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000694 assert(curr_cu->GetUserData() == NULL);
695 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 }
697 }
698 return comp_unit;
699}
700
701static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000702AddRangesToBlock (Block& block,
703 DWARFDebugRanges::RangeList& ranges,
704 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000706 const size_t num_ranges = ranges.GetSize();
707 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000709 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
710 const addr_t range_base = range.GetRangeBase();
711 assert (range_base >= block_base_addr);
712 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000714 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715}
716
717
718Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000719SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720{
721 DWARFDebugRanges::RangeList func_ranges;
722 const char *name = NULL;
723 const char *mangled = NULL;
724 int decl_file = 0;
725 int decl_line = 0;
726 int decl_column = 0;
727 int call_file = 0;
728 int call_line = 0;
729 int call_column = 0;
730 DWARFExpression frame_base;
731
Greg Claytonc93237c2010-10-01 20:48:32 +0000732 assert (die->Tag() == DW_TAG_subprogram);
733
734 if (die->Tag() != DW_TAG_subprogram)
735 return NULL;
736
Greg Clayton3c2e3ae2012-02-06 06:42:51 +0000737 if (die->GetDIENamesAndRanges (this,
738 dwarf_cu,
739 name,
740 mangled,
741 func_ranges,
742 decl_file,
743 decl_line,
744 decl_column,
745 call_file,
746 call_line,
747 call_column,
748 &frame_base))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749 {
750 // Union of all ranges in the function DIE (if the function is discontiguous)
751 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000752 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
753 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
755 {
756 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
757 if (func_range.GetBaseAddress().IsValid())
758 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
759 }
760
761 if (func_range.GetBaseAddress().IsValid())
762 {
763 Mangled func_name;
764 if (mangled)
765 func_name.SetValue(mangled, true);
766 else if (name)
767 func_name.SetValue(name, false);
768
769 FunctionSP func_sp;
770 std::auto_ptr<Declaration> decl_ap;
771 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000772 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
773 decl_line,
774 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000776 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000777 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778
779 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
780
781 func_range.GetBaseAddress().ResolveLinkedAddress();
782
Greg Clayton81c22f62011-10-19 18:09:39 +0000783 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000785 func_user_id, // UserID is the DIE offset
786 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000787 func_name,
788 func_type,
789 func_range)); // first address range
790
791 if (func_sp.get() != NULL)
792 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000793 if (frame_base.IsValid())
794 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000795 sc.comp_unit->AddFunction(func_sp);
796 return func_sp.get();
797 }
798 }
799 }
800 return NULL;
801}
802
803size_t
804SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
805{
806 assert (sc.comp_unit);
807 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000808 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809 if (dwarf_cu)
810 {
811 DWARFDIECollection function_dies;
812 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
813 size_t func_idx;
814 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
815 {
816 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000817 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818 {
819 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
820 ++functions_added;
821 }
822 }
823 //FixupTypes();
824 }
825 return functions_added;
826}
827
828bool
829SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
830{
831 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000832 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
833 assert (curr_cu);
834 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835
836 if (cu_die)
837 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000838 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
839 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840
841 // All file indexes in DWARF are one based and a file of index zero is
842 // supposed to be the compile unit itself.
843 support_files.Append (*sc.comp_unit);
844
845 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
846 }
847 return false;
848}
849
850struct ParseDWARFLineTableCallbackInfo
851{
852 LineTable* line_table;
853 const SectionList *section_list;
854 lldb::addr_t prev_sect_file_base_addr;
855 lldb::addr_t curr_sect_file_base_addr;
856 bool is_oso_for_debug_map;
857 bool prev_in_final_executable;
858 DWARFDebugLine::Row prev_row;
859 SectionSP prev_section_sp;
860 SectionSP curr_section_sp;
861};
862
863//----------------------------------------------------------------------
864// ParseStatementTableCallback
865//----------------------------------------------------------------------
866static void
867ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
868{
869 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
870 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
871 {
872 // Just started parsing the line table
873 }
874 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
875 {
876 // Done parsing line table, nothing to do for the cleanup
877 }
878 else
879 {
880 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
881 // We have a new row, lets append it
882
883 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
884 {
885 info->prev_section_sp = info->curr_section_sp;
886 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
887 // If this is an end sequence entry, then we subtract one from the
888 // address to make sure we get an address that is not the end of
889 // a section.
890 if (state.end_sequence && state.address != 0)
891 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
892 else
893 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
894
895 if (info->curr_section_sp.get())
896 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
897 else
898 info->curr_sect_file_base_addr = 0;
899 }
900 if (info->curr_section_sp.get())
901 {
902 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
903 // Check for the fancy section magic to determine if we
904
905 if (info->is_oso_for_debug_map)
906 {
907 // When this is a debug map object file that contains DWARF
908 // (referenced from an N_OSO debug map nlist entry) we will have
909 // a file address in the file range for our section from the
910 // original .o file, and a load address in the executable that
911 // contains the debug map.
912 //
913 // If the sections for the file range and load range are
914 // different, we have a remapped section for the function and
915 // this address is resolved. If they are the same, then the
916 // function for this address didn't make it into the final
917 // executable.
918 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
919
920 // If we are doing DWARF with debug map, then we need to carefully
921 // add each line table entry as there may be gaps as functions
922 // get moved around or removed.
923 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
924 {
925 if (info->prev_in_final_executable)
926 {
927 bool terminate_previous_entry = false;
928 if (!curr_in_final_executable)
929 {
930 // Check for the case where the previous line entry
931 // in a function made it into the final executable,
932 // yet the current line entry falls in a function
933 // that didn't. The line table used to be contiguous
934 // through this address range but now it isn't. We
935 // need to terminate the previous line entry so
936 // that we can reconstruct the line range correctly
937 // for it and to keep the line table correct.
938 terminate_previous_entry = true;
939 }
940 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
941 {
942 // Check for cases where the line entries used to be
943 // contiguous address ranges, but now they aren't.
944 // This can happen when order files specify the
945 // ordering of the functions.
946 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
947 Section *curr_sect = info->curr_section_sp.get();
948 Section *prev_sect = info->prev_section_sp.get();
949 assert (curr_sect->GetLinkedSection());
950 assert (prev_sect->GetLinkedSection());
951 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
952 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
953 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
954 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
955 if (object_file_addr_delta != linked_file_addr_delta)
956 terminate_previous_entry = true;
957 }
958
959 if (terminate_previous_entry)
960 {
961 line_table->InsertLineEntry (info->prev_section_sp,
962 state.address - info->prev_sect_file_base_addr,
963 info->prev_row.line,
964 info->prev_row.column,
965 info->prev_row.file,
966 false, // is_stmt
967 false, // basic_block
968 false, // state.prologue_end
969 false, // state.epilogue_begin
970 true); // end_sequence);
971 }
972 }
973 }
974
975 if (curr_in_final_executable)
976 {
977 line_table->InsertLineEntry (info->curr_section_sp,
978 curr_line_section_offset,
979 state.line,
980 state.column,
981 state.file,
982 state.is_stmt,
983 state.basic_block,
984 state.prologue_end,
985 state.epilogue_begin,
986 state.end_sequence);
987 info->prev_section_sp = info->curr_section_sp;
988 }
989 else
990 {
991 // If the current address didn't make it into the final
992 // executable, the current section will be the __text
993 // segment in the .o file, so we need to clear this so
994 // we can catch the next function that did make it into
995 // the final executable.
996 info->prev_section_sp.reset();
997 info->curr_section_sp.reset();
998 }
999
1000 info->prev_in_final_executable = curr_in_final_executable;
1001 }
1002 else
1003 {
1004 // We are not in an object file that contains DWARF for an
1005 // N_OSO, this is just a normal DWARF file. The DWARF spec
1006 // guarantees that the addresses will be in increasing order
1007 // so, since we store line tables in file address order, we
1008 // can always just append the line entry without needing to
1009 // search for the correct insertion point (we don't need to
1010 // use LineEntry::InsertLineEntry()).
1011 line_table->AppendLineEntry (info->curr_section_sp,
1012 curr_line_section_offset,
1013 state.line,
1014 state.column,
1015 state.file,
1016 state.is_stmt,
1017 state.basic_block,
1018 state.prologue_end,
1019 state.epilogue_begin,
1020 state.end_sequence);
1021 }
1022 }
1023
1024 info->prev_row = state;
1025 }
1026}
1027
1028bool
1029SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1030{
1031 assert (sc.comp_unit);
1032 if (sc.comp_unit->GetLineTable() != NULL)
1033 return true;
1034
1035 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1036 if (dwarf_cu)
1037 {
1038 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001039 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001041 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1042 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001044 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1045 if (line_table_ap.get())
1046 {
1047 ParseDWARFLineTableCallbackInfo info = {
1048 line_table_ap.get(),
1049 m_obj_file->GetSectionList(),
1050 0,
1051 0,
1052 m_debug_map_symfile != NULL,
1053 false,
1054 DWARFDebugLine::Row(),
1055 SectionSP(),
1056 SectionSP()
1057 };
1058 uint32_t offset = cu_line_offset;
1059 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1060 sc.comp_unit->SetLineTable(line_table_ap.release());
1061 return true;
1062 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 }
1064 }
1065 }
1066 return false;
1067}
1068
1069size_t
1070SymbolFileDWARF::ParseFunctionBlocks
1071(
1072 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001073 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001074 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075 const DWARFDebugInfoEntry *die,
1076 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001077 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078)
1079{
1080 size_t blocks_added = 0;
1081 while (die != NULL)
1082 {
1083 dw_tag_t tag = die->Tag();
1084
1085 switch (tag)
1086 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001088 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089 case DW_TAG_lexical_block:
1090 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001091 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001092 if (tag == DW_TAG_subprogram)
1093 {
1094 // Skip any DW_TAG_subprogram DIEs that are inside
1095 // of a normal or inlined functions. These will be
1096 // parsed on their own as separate entities.
1097
1098 if (depth > 0)
1099 break;
1100
1101 block = parent_block;
1102 }
1103 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001104 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001105 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001106 parent_block->AddChild(block_sp);
1107 block = block_sp.get();
1108 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001109 DWARFDebugRanges::RangeList ranges;
1110 const char *name = NULL;
1111 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001113 int decl_file = 0;
1114 int decl_line = 0;
1115 int decl_column = 0;
1116 int call_file = 0;
1117 int call_line = 0;
1118 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001119 if (die->GetDIENamesAndRanges (this,
1120 dwarf_cu,
1121 name,
1122 mangled_name,
1123 ranges,
1124 decl_file, decl_line, decl_column,
1125 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126 {
1127 if (tag == DW_TAG_subprogram)
1128 {
1129 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001130 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001131 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001132 else if (tag == DW_TAG_inlined_subroutine)
1133 {
1134 // We get called here for inlined subroutines in two ways.
1135 // The first time is when we are making the Function object
1136 // for this inlined concrete instance. Since we're creating a top level block at
1137 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1138 // adjust the containing address.
1139 // The second time is when we are parsing the blocks inside the function that contains
1140 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1141 // function the offset will be for that function.
1142 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1143 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001144 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001145 }
1146 }
1147
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001148 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149
1150 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1151 {
1152 std::auto_ptr<Declaration> decl_ap;
1153 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001154 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1155 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156
1157 std::auto_ptr<Declaration> call_ap;
1158 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001159 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1160 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001162 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163 }
1164
1165 ++blocks_added;
1166
Greg Claytondd7feaf2011-08-12 17:54:33 +00001167 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001169 blocks_added += ParseFunctionBlocks (sc,
1170 block,
1171 dwarf_cu,
1172 die->GetFirstChild(),
1173 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001174 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 }
1176 }
1177 }
1178 break;
1179 default:
1180 break;
1181 }
1182
Greg Claytondd7feaf2011-08-12 17:54:33 +00001183 // Only parse siblings of the block if we are not at depth zero. A depth
1184 // of zero indicates we are currently parsing the top level
1185 // DW_TAG_subprogram DIE
1186
1187 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001189 else
1190 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191 }
1192 return blocks_added;
1193}
1194
Greg Claytonf0705c82011-10-22 03:33:13 +00001195bool
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001196SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1197 const DWARFDebugInfoEntry *die,
1198 ClangASTContext::TemplateParameterInfos &template_param_infos)
1199{
1200 const dw_tag_t tag = die->Tag();
1201
1202 switch (tag)
1203 {
1204 case DW_TAG_template_type_parameter:
1205 case DW_TAG_template_value_parameter:
1206 {
1207 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1208
1209 DWARFDebugInfoEntry::Attributes attributes;
1210 const size_t num_attributes = die->GetAttributes (this,
1211 dwarf_cu,
1212 fixed_form_sizes,
1213 attributes);
1214 const char *name = NULL;
1215 Type *lldb_type = NULL;
1216 clang_type_t clang_type = NULL;
1217 uint64_t uval64 = 0;
1218 bool uval64_valid = false;
1219 if (num_attributes > 0)
1220 {
1221 DWARFFormValue form_value;
1222 for (size_t i=0; i<num_attributes; ++i)
1223 {
1224 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1225
1226 switch (attr)
1227 {
1228 case DW_AT_name:
1229 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1230 name = form_value.AsCString(&get_debug_str_data());
1231 break;
1232
1233 case DW_AT_type:
1234 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1235 {
1236 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1237 lldb_type = ResolveTypeUID(type_die_offset);
1238 if (lldb_type)
1239 clang_type = lldb_type->GetClangForwardType();
1240 }
1241 break;
1242
1243 case DW_AT_const_value:
1244 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1245 {
1246 uval64_valid = true;
1247 uval64 = form_value.Unsigned();
1248 }
1249 break;
1250 default:
1251 break;
1252 }
1253 }
1254
1255 if (name && lldb_type && clang_type)
1256 {
1257 bool is_signed = false;
1258 template_param_infos.names.push_back(name);
1259 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1260 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1261 {
1262 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1263 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1264 }
1265 else
1266 {
1267 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1268 }
1269 }
1270 else
1271 {
1272 return false;
1273 }
1274
1275 }
1276 }
1277 return true;
1278
1279 default:
1280 break;
1281 }
1282 return false;
1283}
1284
1285bool
Greg Claytonf0705c82011-10-22 03:33:13 +00001286SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1287 const DWARFDebugInfoEntry *parent_die,
1288 ClangASTContext::TemplateParameterInfos &template_param_infos)
1289{
1290
1291 if (parent_die == NULL)
1292 return NULL;
1293
Greg Claytonf0705c82011-10-22 03:33:13 +00001294 Args template_parameter_names;
1295 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1296 die != NULL;
1297 die = die->GetSibling())
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:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001305 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001306 break;
1307
1308 default:
1309 break;
1310 }
1311 }
1312 if (template_param_infos.args.empty())
1313 return false;
1314 return template_param_infos.args.size() == template_param_infos.names.size();
1315}
1316
1317clang::ClassTemplateDecl *
1318SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001319 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001320 const char *parent_name,
1321 int tag_decl_kind,
1322 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1323{
1324 if (template_param_infos.IsValid())
1325 {
1326 std::string template_basename(parent_name);
1327 template_basename.erase (template_basename.find('<'));
1328 ClangASTContext &ast = GetClangASTContext();
1329
1330 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001331 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001332 template_basename.c_str(),
1333 tag_decl_kind,
1334 template_param_infos);
1335 }
1336 return NULL;
1337}
1338
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339size_t
1340SymbolFileDWARF::ParseChildMembers
1341(
1342 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001343 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001344 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001345 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001346 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001347 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1348 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001349 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001350 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001351 bool &is_a_class,
1352 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001353)
1354{
1355 if (parent_die == NULL)
1356 return 0;
1357
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 size_t count = 0;
1359 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001360 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001361 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001362
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001363 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1364 {
1365 dw_tag_t tag = die->Tag();
1366
1367 switch (tag)
1368 {
1369 case DW_TAG_member:
1370 {
1371 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001372 const size_t num_attributes = die->GetAttributes (this,
1373 dwarf_cu,
1374 fixed_form_sizes,
1375 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001376 if (num_attributes > 0)
1377 {
1378 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001379 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001381 const char *prop_name = NULL;
1382 const char *prop_getter_name = NULL;
1383 const char *prop_setter_name = NULL;
1384 uint32_t prop_attributes = 0;
1385
1386
Greg Clayton24739922010-10-13 03:15:28 +00001387 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001389 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001390 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 size_t byte_size = 0;
1392 size_t bit_offset = 0;
1393 size_t bit_size = 0;
1394 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001395 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001396 {
1397 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1398 DWARFFormValue form_value;
1399 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1400 {
1401 switch (attr)
1402 {
1403 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1404 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1405 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1406 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1407 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1408 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1409 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1410 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1411 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001412 if (form_value.BlockData())
1413 {
1414 Value initialValue(0);
1415 Value memberOffset(0);
1416 const DataExtractor& debug_info_data = get_debug_info_data();
1417 uint32_t block_length = form_value.Unsigned();
1418 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1419 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1420 NULL, // clang::ASTContext *
1421 NULL, // ClangExpressionVariableList *
1422 NULL, // ClangExpressionDeclMap *
1423 NULL, // RegisterContext *
1424 debug_info_data,
1425 block_offset,
1426 block_length,
1427 eRegisterKindDWARF,
1428 &initialValue,
1429 memberOffset,
1430 NULL))
1431 {
1432 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1433 }
1434 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 break;
1436
Greg Clayton8cf05932010-07-22 18:30:50 +00001437 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001438 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 case DW_AT_declaration:
1440 case DW_AT_description:
1441 case DW_AT_mutable:
1442 case DW_AT_visibility:
Jim Inghame3ae82a2011-11-12 01:36:43 +00001443
1444 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1445 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1446 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1447 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1448
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 default:
1450 case DW_AT_sibling:
1451 break;
1452 }
1453 }
1454 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001455
Greg Clayton44953932011-10-25 01:25:35 +00001456 // Clang has a DWARF generation bug where sometimes it
1457 // represents fields that are references with bad byte size
1458 // and bit size/offset information such as:
1459 //
1460 // DW_AT_byte_size( 0x00 )
1461 // DW_AT_bit_size( 0x40 )
1462 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1463 //
1464 // So check the bit offset to make sure it is sane, and if
1465 // the values are not sane, remove them. If we don't do this
1466 // then we will end up with a crash if we try to use this
1467 // type in an expression when clang becomes unhappy with its
1468 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001469
Greg Clayton44953932011-10-25 01:25:35 +00001470 if (bit_offset > 128)
1471 {
1472 bit_size = 0;
1473 bit_offset = 0;
1474 }
1475
1476 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001477 if (class_language == eLanguageTypeObjC ||
1478 class_language == eLanguageTypeObjC_plus_plus)
1479 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001480
1481 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1482 {
1483 // Not all compilers will mark the vtable pointer
1484 // member as artificial (llvm-gcc). We can't have
1485 // the virtual members in our classes otherwise it
1486 // throws off all child offsets since we end up
1487 // having and extra pointer sized member in our
1488 // class layouts.
1489 is_artificial = true;
1490 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491
Greg Clayton24739922010-10-13 03:15:28 +00001492 if (is_artificial == false)
1493 {
1494 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001495 clang::FieldDecl *field_decl = NULL;
Greg Claytond16e1e52011-07-12 17:06:17 +00001496 if (member_type)
1497 {
1498 if (accessibility == eAccessNone)
1499 accessibility = default_accessibility;
1500 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001501
Jim Inghame3ae82a2011-11-12 01:36:43 +00001502 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Greg Clayton42ce2f32011-12-12 21:50:19 +00001503 name,
1504 member_type->GetClangLayoutType(),
1505 accessibility,
1506 bit_size);
Greg Claytond16e1e52011-07-12 17:06:17 +00001507 }
1508 else
1509 {
1510 if (name)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001511 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1512 MakeUserID(die->GetOffset()),
1513 name,
1514 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001515 else
Greg Claytone38a5ed2012-01-05 03:57:59 +00001516 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1517 MakeUserID(die->GetOffset()),
1518 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001519 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001520
Sean Callanan5b26f272012-02-04 08:49:35 +00001521 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Claytoncaab74e2012-01-28 00:48:57 +00001522 {
Sean Callanan5b26f272012-02-04 08:49:35 +00001523 /////////////////////////////////////////////////////////////
1524 // How to locate a field given the DWARF debug information
1525 //
1526 // AT_byte_size indicates the size of the word in which the
1527 // bit offset must be interpreted.
1528 //
1529 // AT_data_member_location indicates the byte offset of the
1530 // word from the base address of the structure.
1531 //
1532 // AT_bit_offset indicates how many bits into the word
1533 // (according to the host endianness) the low-order bit of
1534 // the field starts. AT_bit_offset can be negative.
1535 //
1536 // AT_bit_size indicates the size of the field in bits.
1537 /////////////////////////////////////////////////////////////
1538
1539 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1540
1541 uint64_t total_bit_offset = 0;
1542
1543 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1544
1545 if (object_endian == eByteOrderLittle)
1546 {
1547 total_bit_offset += byte_size * 8;
1548 total_bit_offset -= (bit_offset + bit_size);
1549 }
1550 else
1551 {
1552 total_bit_offset += bit_offset;
1553 }
1554
1555 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
Greg Claytoncaab74e2012-01-28 00:48:57 +00001556 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001557 if (prop_name != NULL)
1558 {
1559
1560 clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1561 assert (ivar_decl != NULL);
1562
1563
1564 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1565 prop_name,
1566 0,
1567 ivar_decl,
1568 prop_setter_name,
1569 prop_getter_name,
1570 prop_attributes);
1571 }
Greg Clayton24739922010-10-13 03:15:28 +00001572 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001573 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001574 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575 }
1576 break;
1577
1578 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001579 // Let the type parsing code handle this one for us.
1580 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001581 break;
1582
1583 case DW_TAG_inheritance:
1584 {
1585 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001586 if (default_accessibility == eAccessNone)
1587 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588 // TODO: implement DW_TAG_inheritance type parsing
1589 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001590 const size_t num_attributes = die->GetAttributes (this,
1591 dwarf_cu,
1592 fixed_form_sizes,
1593 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001594 if (num_attributes > 0)
1595 {
1596 Declaration decl;
1597 DWARFExpression location;
1598 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001599 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001600 bool is_virtual = false;
1601 bool is_base_of_class = true;
1602 off_t member_offset = 0;
1603 uint32_t i;
1604 for (i=0; i<num_attributes; ++i)
1605 {
1606 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1607 DWARFFormValue form_value;
1608 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1609 {
1610 switch (attr)
1611 {
1612 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1613 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1614 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1615 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1616 case DW_AT_data_member_location:
1617 if (form_value.BlockData())
1618 {
1619 Value initialValue(0);
1620 Value memberOffset(0);
1621 const DataExtractor& debug_info_data = get_debug_info_data();
1622 uint32_t block_length = form_value.Unsigned();
1623 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001624 if (DWARFExpression::Evaluate (NULL,
1625 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001626 NULL,
1627 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001628 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001629 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001630 block_offset,
1631 block_length,
1632 eRegisterKindDWARF,
1633 &initialValue,
1634 memberOffset,
1635 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001636 {
1637 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1638 }
1639 }
1640 break;
1641
1642 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001643 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 break;
1645
1646 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1647 default:
1648 case DW_AT_sibling:
1649 break;
1650 }
1651 }
1652 }
1653
Greg Clayton526e5af2010-11-13 03:52:47 +00001654 Type *base_class_type = ResolveTypeUID(encoding_uid);
1655 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001656
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001657 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1658 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001659 if (class_language == eLanguageTypeObjC)
1660 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001661 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001662 }
1663 else
1664 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001665 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001666 accessibility,
1667 is_virtual,
1668 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001669 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001670 }
1671 }
1672 break;
1673
1674 default:
1675 break;
1676 }
1677 }
1678 return count;
1679}
1680
1681
1682clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001683SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001684{
1685 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001686 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001687 {
1688 DWARFCompileUnitSP cu_sp;
1689 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1690 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001691 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001692 }
1693 return NULL;
1694}
1695
1696clang::DeclContext*
1697SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1698{
Greg Clayton81c22f62011-10-19 18:09:39 +00001699 if (UserIDMatches(type_uid))
1700 return GetClangDeclContextForDIEOffset (sc, type_uid);
1701 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702}
1703
1704Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001705SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706{
Greg Clayton81c22f62011-10-19 18:09:39 +00001707 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001709 DWARFDebugInfo* debug_info = DebugInfo();
1710 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001711 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001712 DWARFCompileUnitSP cu_sp;
1713 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001714 const bool assert_not_being_parsed = true;
1715 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001716 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001717 }
1718 return NULL;
1719}
1720
Greg Claytoncab36a32011-12-08 05:16:30 +00001721Type*
1722SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001723{
Greg Claytoncab36a32011-12-08 05:16:30 +00001724 if (die != NULL)
1725 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001726 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1727 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001728 GetObjectFile()->GetModule()->LogMessage (log.get(),
1729 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1730 die->GetOffset(),
1731 DW_TAG_value_to_name(die->Tag()),
1732 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001733
Greg Claytoncab36a32011-12-08 05:16:30 +00001734 // We might be coming in in the middle of a type tree (a class
1735 // withing a class, an enum within a class), so parse any needed
1736 // parent DIEs before we get to this one...
1737 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1738 switch (decl_ctx_die->Tag())
1739 {
1740 case DW_TAG_structure_type:
1741 case DW_TAG_union_type:
1742 case DW_TAG_class_type:
1743 {
1744 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001745 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001746 GetObjectFile()->GetModule()->LogMessage (log.get(),
1747 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1748 die->GetOffset(),
1749 DW_TAG_value_to_name(die->Tag()),
1750 die->GetName(this, cu),
1751 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001752
Greg Claytoncab36a32011-12-08 05:16:30 +00001753 Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
Sean Callanan5b26f272012-02-04 08:49:35 +00001754 if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
Greg Clayton3bffb082011-12-10 02:15:28 +00001755 {
1756 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001757 GetObjectFile()->GetModule()->LogMessage (log.get(),
1758 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1759 die->GetOffset(),
1760 DW_TAG_value_to_name(die->Tag()),
1761 die->GetName(this, cu),
1762 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001763 // Ask the type to complete itself if it already hasn't since if we
1764 // want a function (method or static) from a class, the class must
1765 // create itself and add it's own methods and class functions.
1766 if (parent_type)
1767 parent_type->GetClangFullType();
1768 }
Greg Claytoncab36a32011-12-08 05:16:30 +00001769 }
1770 break;
1771
1772 default:
1773 break;
1774 }
1775 return ResolveType (cu, die);
1776 }
1777 return NULL;
1778}
1779
Greg Clayton6beaaa62011-01-17 03:46:26 +00001780// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1781// SymbolFileDWARF objects to detect if this DWARF file is the one that
1782// can resolve a clang_type.
1783bool
1784SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1785{
1786 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1787 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1788 return die != NULL;
1789}
1790
1791
Greg Clayton1be10fc2010-09-29 01:12:09 +00001792lldb::clang_type_t
1793SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1794{
1795 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001796 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1797 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001798 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001799 {
1800 // We have already resolved this type...
1801 return clang_type;
1802 }
1803 // Once we start resolving this type, remove it from the forward declaration
1804 // map in case anyone child members or other types require this type to get resolved.
1805 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1806 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001807 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001808
Greg Clayton1be10fc2010-09-29 01:12:09 +00001809
Greg Clayton85ae2e12011-10-18 23:36:41 +00001810 // Disable external storage for this type so we don't get anymore
1811 // clang::ExternalASTSource queries for this type.
1812 ClangASTContext::SetHasExternalStorage (clang_type, false);
1813
Greg Clayton450e3f32010-10-12 02:24:53 +00001814 DWARFDebugInfo* debug_info = DebugInfo();
1815
Greg Clayton96d7d742010-11-10 23:42:09 +00001816 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001817 Type *type = m_die_to_type.lookup (die);
1818
1819 const dw_tag_t tag = die->Tag();
1820
Greg Clayton3bffb082011-12-10 02:15:28 +00001821 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1822 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001823 GetObjectFile()->GetModule()->LogMessage (log.get(),
1824 "0x%8.8llx: %s '%s' resolving forward declaration...\n",
1825 MakeUserID(die->GetOffset()),
1826 DW_TAG_value_to_name(tag),
1827 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001828 assert (clang_type);
1829 DWARFDebugInfoEntry::Attributes attributes;
1830
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001831 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001832
1833 switch (tag)
1834 {
1835 case DW_TAG_structure_type:
1836 case DW_TAG_union_type:
1837 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001838 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001839 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001840 LayoutInfo layout_info;
1841 if (die->HasChildren())
Greg Clayton1be10fc2010-09-29 01:12:09 +00001842 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001843
Greg Claytoncaab74e2012-01-28 00:48:57 +00001844 LanguageType class_language = eLanguageTypeUnknown;
1845 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1846 if (is_objc_class)
1847 class_language = eLanguageTypeObjC;
Greg Claytonc93237c2010-10-01 20:48:32 +00001848
Greg Claytoncaab74e2012-01-28 00:48:57 +00001849 int tag_decl_kind = -1;
1850 AccessType default_accessibility = eAccessNone;
1851 if (tag == DW_TAG_structure_type)
Greg Claytonc93237c2010-10-01 20:48:32 +00001852 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001853 tag_decl_kind = clang::TTK_Struct;
1854 default_accessibility = eAccessPublic;
Greg Claytonc93237c2010-10-01 20:48:32 +00001855 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001856 else if (tag == DW_TAG_union_type)
Greg Clayton450e3f32010-10-12 02:24:53 +00001857 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001858 tag_decl_kind = clang::TTK_Union;
1859 default_accessibility = eAccessPublic;
1860 }
1861 else if (tag == DW_TAG_class_type)
1862 {
1863 tag_decl_kind = clang::TTK_Class;
1864 default_accessibility = eAccessPrivate;
1865 }
1866
1867 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1868 std::vector<clang::CXXBaseSpecifier *> base_classes;
1869 std::vector<int> member_accessibilities;
1870 bool is_a_class = false;
1871 // Parse members and base classes first
1872 DWARFDIECollection member_function_dies;
1873
1874 ParseChildMembers (sc,
1875 curr_cu,
1876 die,
1877 clang_type,
1878 class_language,
1879 base_classes,
1880 member_accessibilities,
1881 member_function_dies,
1882 default_accessibility,
1883 is_a_class,
1884 layout_info);
1885
1886 // Now parse any methods if there were any...
1887 size_t num_functions = member_function_dies.Size();
1888 if (num_functions > 0)
1889 {
1890 for (size_t i=0; i<num_functions; ++i)
1891 {
1892 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
1893 }
1894 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001895
Greg Claytoncaab74e2012-01-28 00:48:57 +00001896 if (class_language == eLanguageTypeObjC)
1897 {
1898 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
1899 if (!class_str.empty())
Greg Clayton5009f9d2011-10-27 17:55:14 +00001900 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001901
1902 DIEArray method_die_offsets;
1903 if (m_using_apple_tables)
Greg Claytond4a2b372011-09-12 23:21:58 +00001904 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001905 if (m_apple_objc_ap.get())
1906 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
1907 }
1908 else
1909 {
1910 if (!m_indexed)
1911 Index ();
Greg Clayton450e3f32010-10-12 02:24:53 +00001912
Greg Claytoncaab74e2012-01-28 00:48:57 +00001913 ConstString class_name (class_str.c_str());
1914 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1915 }
1916
1917 if (!method_die_offsets.empty())
1918 {
1919 DWARFDebugInfo* debug_info = DebugInfo();
1920
1921 DWARFCompileUnit* method_cu = NULL;
1922 const size_t num_matches = method_die_offsets.size();
1923 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00001924 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001925 const dw_offset_t die_offset = method_die_offsets[i];
1926 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
1927
1928 if (method_die)
1929 ResolveType (method_cu, method_die);
1930 else
Greg Clayton95d87902011-11-11 03:16:25 +00001931 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001932 if (m_using_apple_tables)
1933 {
1934 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
1935 die_offset, class_str.c_str());
1936 }
1937 }
1938 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001939 }
1940 }
1941 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001942
1943 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1944 // need to tell the clang type it is actually a class.
1945 if (class_language != eLanguageTypeObjC)
1946 {
1947 if (is_a_class && tag_decl_kind != clang::TTK_Class)
1948 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
1949 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001950
Greg Claytoncaab74e2012-01-28 00:48:57 +00001951 // Since DW_TAG_structure_type gets used for both classes
1952 // and structures, we may need to set any DW_TAG_member
1953 // fields to have a "private" access if none was specified.
1954 // When we parsed the child members we tracked that actual
1955 // accessibility value for each DW_TAG_member in the
1956 // "member_accessibilities" array. If the value for the
1957 // member is zero, then it was set to the "default_accessibility"
1958 // which for structs was "public". Below we correct this
1959 // by setting any fields to "private" that weren't correctly
1960 // set.
1961 if (is_a_class && !member_accessibilities.empty())
1962 {
1963 // This is a class and all members that didn't have
1964 // their access specified are private.
1965 ast.SetDefaultAccessForRecordFields (clang_type,
1966 eAccessPrivate,
1967 &member_accessibilities.front(),
1968 member_accessibilities.size());
1969 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001970
Greg Claytoncaab74e2012-01-28 00:48:57 +00001971 if (!base_classes.empty())
1972 {
1973 ast.SetBaseClassesForClassType (clang_type,
1974 &base_classes.front(),
1975 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001976
Greg Claytoncaab74e2012-01-28 00:48:57 +00001977 // Clang will copy each CXXBaseSpecifier in "base_classes"
1978 // so we have to free them all.
1979 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1980 base_classes.size());
1981 }
1982
Greg Claytonc93237c2010-10-01 20:48:32 +00001983 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001984
Greg Claytoncaab74e2012-01-28 00:48:57 +00001985 if (!layout_info.field_offsets.empty())
1986 {
1987 if (type)
1988 layout_info.bit_size = type->GetByteSize() * 8;
1989 if (layout_info.bit_size == 0)
1990 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8;
1991 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
1992 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
1993 if (record_type)
1994 {
1995 const clang::RecordDecl *record_decl = record_type->getDecl();
1996
1997 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00001998 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001999 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002000 "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 +00002001 clang_type,
2002 record_decl,
2003 layout_info.bit_size,
2004 layout_info.alignment,
2005 (uint32_t)layout_info.field_offsets.size());
2006
Greg Clayton821ac6d2012-01-28 02:22:27 +00002007 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2008 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2009 {
2010 GetObjectFile()->GetModule()->LogMessage (log.get(),
2011 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2012 clang_type,
2013 (uint32_t)pos->second,
2014 pos->first->getNameAsString().c_str());
2015 }
2016 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002017 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2018 }
2019 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002020 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002021 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00002022 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002023
2024 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002025 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002026 if (die->HasChildren())
2027 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002028 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
2029 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002030 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002031 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002032 return clang_type;
2033
2034 default:
2035 assert(false && "not a forward clang type decl!");
2036 break;
2037 }
2038 return NULL;
2039}
2040
Greg Claytonc685f8e2010-09-15 04:15:46 +00002041Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00002042SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002043{
2044 if (type_die != NULL)
2045 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002046 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002047
Greg Claytonc685f8e2010-09-15 04:15:46 +00002048 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002049 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002050
Greg Clayton24739922010-10-13 03:15:28 +00002051 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002052 {
2053 if (type != DIE_IS_BEING_PARSED)
2054 return type;
2055
2056 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
2057 type_die->GetOffset(),
2058 DW_TAG_value_to_name(type_die->Tag()),
2059 type_die->GetName(this, curr_cu));
2060
2061 }
2062 else
2063 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002064 }
2065 return NULL;
2066}
2067
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00002069SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070{
2071 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002072 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073 {
2074 // The symbol vendor doesn't know about this compile unit, we
2075 // need to parse and add it to the symbol vendor object.
2076 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00002077 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002078 if (dc_cu.get())
2079 {
2080 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00002081 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00002082 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002083
2084 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00002085
2086 if (m_debug_map_symfile)
2087 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002088 }
2089 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002090 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002091}
2092
2093bool
Greg Clayton96d7d742010-11-10 23:42:09 +00002094SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002095{
2096 sc.Clear();
2097 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002098 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002099
Greg Clayton81c22f62011-10-19 18:09:39 +00002100 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002101 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002102 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002103
2104 if (sc.function)
2105 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00002106 sc.module_sp = sc.function->CalculateSymbolContextModule()->shared_from_this();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002107 return true;
2108 }
2109
2110 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002111}
2112
2113uint32_t
2114SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2115{
2116 Timer scoped_timer(__PRETTY_FUNCTION__,
2117 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
2118 so_addr.GetSection(),
2119 so_addr.GetOffset(),
2120 resolve_scope);
2121 uint32_t resolved = 0;
2122 if (resolve_scope & ( eSymbolContextCompUnit |
2123 eSymbolContextFunction |
2124 eSymbolContextBlock |
2125 eSymbolContextLineEntry))
2126 {
2127 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2128
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002129 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002130 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002131 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002132 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002133 if (cu_offset != DW_INVALID_OFFSET)
2134 {
2135 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002136 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2137 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002138 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002139 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002140 assert(sc.comp_unit != NULL);
2141 resolved |= eSymbolContextCompUnit;
2142
2143 if (resolve_scope & eSymbolContextLineEntry)
2144 {
2145 LineTable *line_table = sc.comp_unit->GetLineTable();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002146 if (line_table != NULL)
2147 {
2148 if (so_addr.IsLinkedAddress())
2149 {
2150 Address linked_addr (so_addr);
2151 linked_addr.ResolveLinkedAddress();
2152 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2153 {
2154 resolved |= eSymbolContextLineEntry;
2155 }
2156 }
2157 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2158 {
2159 resolved |= eSymbolContextLineEntry;
2160 }
2161 }
2162 }
2163
2164 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2165 {
2166 DWARFDebugInfoEntry *function_die = NULL;
2167 DWARFDebugInfoEntry *block_die = NULL;
2168 if (resolve_scope & eSymbolContextBlock)
2169 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002170 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002171 }
2172 else
2173 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002174 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002175 }
2176
2177 if (function_die != NULL)
2178 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002179 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002180 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002181 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182 }
2183
2184 if (sc.function != NULL)
2185 {
2186 resolved |= eSymbolContextFunction;
2187
2188 if (resolve_scope & eSymbolContextBlock)
2189 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002190 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002191
2192 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002193 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002194 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002195 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002196 if (sc.block)
2197 resolved |= eSymbolContextBlock;
2198 }
2199 }
2200 }
2201 }
2202 }
2203 }
2204 }
2205 return resolved;
2206}
2207
2208
2209
2210uint32_t
2211SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2212{
2213 const uint32_t prev_size = sc_list.GetSize();
2214 if (resolve_scope & eSymbolContextCompUnit)
2215 {
2216 DWARFDebugInfo* debug_info = DebugInfo();
2217 if (debug_info)
2218 {
2219 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002220 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002221
Greg Clayton96d7d742010-11-10 23:42:09 +00002222 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002223 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002224 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002225 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2226 if (check_inlines || file_spec_matches_cu_file_spec)
2227 {
2228 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00002229 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002230 assert(sc.comp_unit != NULL);
2231
2232 uint32_t file_idx = UINT32_MAX;
2233
2234 // If we are looking for inline functions only and we don't
2235 // find it in the support files, we are done.
2236 if (check_inlines)
2237 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002238 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002239 if (file_idx == UINT32_MAX)
2240 continue;
2241 }
2242
2243 if (line != 0)
2244 {
2245 LineTable *line_table = sc.comp_unit->GetLineTable();
2246
2247 if (line_table != NULL && line != 0)
2248 {
2249 // We will have already looked up the file index if
2250 // we are searching for inline entries.
2251 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002252 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002253
2254 if (file_idx != UINT32_MAX)
2255 {
2256 uint32_t found_line;
2257 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2258 found_line = sc.line_entry.line;
2259
Greg Clayton016a95e2010-09-14 02:20:48 +00002260 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002261 {
2262 sc.function = NULL;
2263 sc.block = NULL;
2264 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2265 {
2266 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2267 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2268 {
2269 DWARFDebugInfoEntry *function_die = NULL;
2270 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002271 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272
2273 if (function_die != NULL)
2274 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002275 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002276 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002277 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002278 }
2279
2280 if (sc.function != NULL)
2281 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002282 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283
2284 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002285 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002286 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002287 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002288 }
2289 }
2290 }
2291
2292 sc_list.Append(sc);
2293 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2294 }
2295 }
2296 }
2297 else if (file_spec_matches_cu_file_spec && !check_inlines)
2298 {
2299 // only append the context if we aren't looking for inline call sites
2300 // by file and line and if the file spec matches that of the compile unit
2301 sc_list.Append(sc);
2302 }
2303 }
2304 else if (file_spec_matches_cu_file_spec && !check_inlines)
2305 {
2306 // only append the context if we aren't looking for inline call sites
2307 // by file and line and if the file spec matches that of the compile unit
2308 sc_list.Append(sc);
2309 }
2310
2311 if (!check_inlines)
2312 break;
2313 }
2314 }
2315 }
2316 }
2317 return sc_list.GetSize() - prev_size;
2318}
2319
2320void
2321SymbolFileDWARF::Index ()
2322{
2323 if (m_indexed)
2324 return;
2325 m_indexed = true;
2326 Timer scoped_timer (__PRETTY_FUNCTION__,
2327 "SymbolFileDWARF::Index (%s)",
2328 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2329
2330 DWARFDebugInfo* debug_info = DebugInfo();
2331 if (debug_info)
2332 {
2333 uint32_t cu_idx = 0;
2334 const uint32_t num_compile_units = GetNumCompileUnits();
2335 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2336 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002337 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002338
Greg Clayton96d7d742010-11-10 23:42:09 +00002339 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002340
Greg Clayton96d7d742010-11-10 23:42:09 +00002341 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002342 m_function_basename_index,
2343 m_function_fullname_index,
2344 m_function_method_index,
2345 m_function_selector_index,
2346 m_objc_class_selectors_index,
2347 m_global_index,
2348 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002349 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002350
2351 // Keep memory down by clearing DIEs if this generate function
2352 // caused them to be parsed
2353 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002354 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002355 }
2356
Greg Claytond4a2b372011-09-12 23:21:58 +00002357 m_function_basename_index.Finalize();
2358 m_function_fullname_index.Finalize();
2359 m_function_method_index.Finalize();
2360 m_function_selector_index.Finalize();
2361 m_objc_class_selectors_index.Finalize();
2362 m_global_index.Finalize();
2363 m_type_index.Finalize();
2364 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002365
Greg Clayton24739922010-10-13 03:15:28 +00002366#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002367 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002368 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002369 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2370 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002371 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2372 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2373 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2374 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2375 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2376 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002377 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002378 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002379#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002380 }
2381}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002382
2383bool
2384SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2385{
2386 if (namespace_decl == NULL)
2387 {
2388 // Invalid namespace decl which means we aren't matching only things
2389 // in this symbol file, so return true to indicate it matches this
2390 // symbol file.
2391 return true;
2392 }
2393
2394 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2395
2396 if (namespace_ast == NULL)
2397 return true; // No AST in the "namespace_decl", return true since it
2398 // could then match any symbol file, including this one
2399
2400 if (namespace_ast == GetClangASTContext().getASTContext())
2401 return true; // The ASTs match, return true
2402
2403 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002404 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2405
2406 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002407 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002408
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002409 return false;
2410}
2411
Greg Clayton2506a7a2011-10-12 23:34:26 +00002412bool
2413SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2414 DWARFCompileUnit* cu,
2415 const DWARFDebugInfoEntry* die)
2416{
2417 // No namespace specified, so the answesr i
2418 if (namespace_decl == NULL)
2419 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002420
2421 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002422
Greg Clayton2506a7a2011-10-12 23:34:26 +00002423 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2424 if (decl_ctx_die)
2425 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002426
Greg Clayton2506a7a2011-10-12 23:34:26 +00002427 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2428 if (clang_namespace_decl)
2429 {
2430 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002431 {
2432 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002433 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002434 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002435 }
2436
Greg Clayton2506a7a2011-10-12 23:34:26 +00002437 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2438
2439 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002440 {
2441 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002442 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace");
Sean Callananebe60672011-10-13 21:50:33 +00002443
Greg Clayton2506a7a2011-10-12 23:34:26 +00002444 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002445 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002446
Greg Claytoncb5860a2011-10-13 23:49:28 +00002447 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002448 }
2449 else
2450 {
2451 // We have a namespace_decl that was not NULL but it contained
2452 // a NULL "clang::NamespaceDecl", so this means the global namespace
2453 // So as long the the contained decl context DIE isn't a namespace
2454 // we should be ok.
2455 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2456 return true;
2457 }
2458 }
Sean Callananebe60672011-10-13 21:50:33 +00002459
2460 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002461 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002462
Greg Clayton2506a7a2011-10-12 23:34:26 +00002463 return false;
2464}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002465uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002466SymbolFileDWARF::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 +00002467{
Greg Clayton21f2a492011-10-06 00:09:08 +00002468 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2469
2470 if (log)
2471 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002472 GetObjectFile()->GetModule()->LogMessage (log.get(),
2473 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2474 name.GetCString(),
2475 namespace_decl,
2476 append,
2477 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002478 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002479
2480 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2481 return 0;
2482
Greg Claytonc685f8e2010-09-15 04:15:46 +00002483 DWARFDebugInfo* info = DebugInfo();
2484 if (info == NULL)
2485 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002486
2487 // If we aren't appending the results to this list, then clear the list
2488 if (!append)
2489 variables.Clear();
2490
2491 // Remember how many variables are in the list before we search in case
2492 // we are appending the results to a variable list.
2493 const uint32_t original_size = variables.GetSize();
2494
Greg Claytond4a2b372011-09-12 23:21:58 +00002495 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002496
Greg Clayton97fbc342011-10-20 22:30:33 +00002497 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002498 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002499 if (m_apple_names_ap.get())
2500 {
2501 const char *name_cstr = name.GetCString();
2502 const char *base_name_start;
2503 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002504
Greg Clayton97fbc342011-10-20 22:30:33 +00002505 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2506 base_name_start = name_cstr;
2507
2508 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2509 }
Greg Clayton7f995132011-10-04 22:41:51 +00002510 }
2511 else
2512 {
2513 // Index the DWARF if we haven't already
2514 if (!m_indexed)
2515 Index ();
2516
2517 m_global_index.Find (name, die_offsets);
2518 }
2519
2520 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002521 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002522 {
Greg Clayton7f995132011-10-04 22:41:51 +00002523 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +00002524 sc.module_sp = m_obj_file->GetModule()->shared_from_this();
Greg Clayton7f995132011-10-04 22:41:51 +00002525 assert (sc.module_sp);
2526
Greg Claytond4a2b372011-09-12 23:21:58 +00002527 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002528 DWARFCompileUnit* dwarf_cu = NULL;
2529 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002530 for (size_t i=0; i<num_matches; ++i)
2531 {
2532 const dw_offset_t die_offset = die_offsets[i];
2533 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002534
Greg Clayton95d87902011-11-11 03:16:25 +00002535 if (die)
2536 {
2537 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2538 assert(sc.comp_unit != NULL);
2539
2540 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2541 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002542
Greg Clayton95d87902011-11-11 03:16:25 +00002543 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002544
Greg Clayton95d87902011-11-11 03:16:25 +00002545 if (variables.GetSize() - original_size >= max_matches)
2546 break;
2547 }
2548 else
2549 {
2550 if (m_using_apple_tables)
2551 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002552 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2553 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002554 }
2555 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002556 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002557 }
2558
2559 // Return the number of variable that were appended to the list
2560 return variables.GetSize() - original_size;
2561}
2562
2563uint32_t
2564SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2565{
Greg Clayton21f2a492011-10-06 00:09:08 +00002566 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2567
2568 if (log)
2569 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002570 GetObjectFile()->GetModule()->LogMessage (log.get(),
2571 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2572 regex.GetText(),
2573 append,
2574 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002575 }
2576
Greg Claytonc685f8e2010-09-15 04:15:46 +00002577 DWARFDebugInfo* info = DebugInfo();
2578 if (info == NULL)
2579 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002580
2581 // If we aren't appending the results to this list, then clear the list
2582 if (!append)
2583 variables.Clear();
2584
2585 // Remember how many variables are in the list before we search in case
2586 // we are appending the results to a variable list.
2587 const uint32_t original_size = variables.GetSize();
2588
Greg Clayton7f995132011-10-04 22:41:51 +00002589 DIEArray die_offsets;
2590
Greg Clayton97fbc342011-10-20 22:30:33 +00002591 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002592 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002593 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002594 {
2595 DWARFMappedHash::DIEInfoArray hash_data_array;
2596 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2597 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2598 }
Greg Clayton7f995132011-10-04 22:41:51 +00002599 }
2600 else
2601 {
2602 // Index the DWARF if we haven't already
2603 if (!m_indexed)
2604 Index ();
2605
2606 m_global_index.Find (regex, die_offsets);
2607 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002608
Greg Claytonc685f8e2010-09-15 04:15:46 +00002609 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +00002610 sc.module_sp = m_obj_file->GetModule()->shared_from_this();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002611 assert (sc.module_sp);
2612
Greg Claytond4a2b372011-09-12 23:21:58 +00002613 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002614 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002615 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002616 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002617 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002618 DWARFDebugInfo* debug_info = DebugInfo();
2619 for (size_t i=0; i<num_matches; ++i)
2620 {
2621 const dw_offset_t die_offset = die_offsets[i];
2622 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002623
2624 if (die)
2625 {
2626 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002627
Greg Clayton95d87902011-11-11 03:16:25 +00002628 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002629
Greg Clayton95d87902011-11-11 03:16:25 +00002630 if (variables.GetSize() - original_size >= max_matches)
2631 break;
2632 }
2633 else
2634 {
2635 if (m_using_apple_tables)
2636 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002637 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2638 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002639 }
2640 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002641 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002642 }
2643
2644 // Return the number of variable that were appended to the list
2645 return variables.GetSize() - original_size;
2646}
2647
Greg Claytonaa044962011-10-13 00:59:38 +00002648
Jim Ingham4cda6e02011-10-07 22:23:45 +00002649bool
2650SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2651 DWARFCompileUnit *&dwarf_cu,
2652 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002653{
Greg Claytonaa044962011-10-13 00:59:38 +00002654 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2655 return ResolveFunction (dwarf_cu, die, sc_list);
2656}
2657
2658
2659bool
2660SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2661 const DWARFDebugInfoEntry *die,
2662 SymbolContextList& sc_list)
2663{
Greg Clayton9e315582011-09-02 04:03:59 +00002664 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002665
2666 if (die == NULL)
2667 return false;
2668
Jim Ingham4cda6e02011-10-07 22:23:45 +00002669 // If we were passed a die that is not a function, just return false...
2670 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2671 return false;
2672
2673 const DWARFDebugInfoEntry* inlined_die = NULL;
2674 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002675 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002676 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002677
Jim Ingham4cda6e02011-10-07 22:23:45 +00002678 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002679 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002680 if (die->Tag() == DW_TAG_subprogram)
2681 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002682 }
2683 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002684 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002685 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002686 {
2687 Address addr;
2688 // Parse all blocks if needed
2689 if (inlined_die)
2690 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002691 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002692 assert (sc.block != NULL);
2693 if (sc.block->GetStartAddress (addr) == false)
2694 addr.Clear();
2695 }
2696 else
2697 {
2698 sc.block = NULL;
2699 addr = sc.function->GetAddressRange().GetBaseAddress();
2700 }
2701
2702 if (addr.IsValid())
2703 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002704 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002705 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002706 }
2707 }
2708
Greg Claytonaa044962011-10-13 00:59:38 +00002709 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002710}
2711
Greg Clayton7f995132011-10-04 22:41:51 +00002712void
2713SymbolFileDWARF::FindFunctions (const ConstString &name,
2714 const NameToDIE &name_to_die,
2715 SymbolContextList& sc_list)
2716{
Greg Claytond4a2b372011-09-12 23:21:58 +00002717 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002718 if (name_to_die.Find (name, die_offsets))
2719 {
2720 ParseFunctions (die_offsets, sc_list);
2721 }
2722}
2723
2724
2725void
2726SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2727 const NameToDIE &name_to_die,
2728 SymbolContextList& sc_list)
2729{
2730 DIEArray die_offsets;
2731 if (name_to_die.Find (regex, die_offsets))
2732 {
2733 ParseFunctions (die_offsets, sc_list);
2734 }
2735}
2736
2737
2738void
2739SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2740 const DWARFMappedHash::MemoryTable &memory_table,
2741 SymbolContextList& sc_list)
2742{
2743 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002744 DWARFMappedHash::DIEInfoArray hash_data_array;
2745 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002746 {
Greg Claytond1767f02011-12-08 02:13:16 +00002747 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002748 ParseFunctions (die_offsets, sc_list);
2749 }
2750}
2751
2752void
2753SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2754 SymbolContextList& sc_list)
2755{
2756 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002757 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002758 {
Greg Clayton7f995132011-10-04 22:41:51 +00002759 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002760
2761 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002762 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002763 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002764 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002765 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002766 }
2767 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002768}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002769
Jim Ingham4cda6e02011-10-07 22:23:45 +00002770bool
2771SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2772 const DWARFCompileUnit *dwarf_cu,
2773 uint32_t name_type_mask,
2774 const char *partial_name,
2775 const char *base_name_start,
2776 const char *base_name_end)
2777{
2778 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2779 if (name_type_mask == eFunctionNameTypeMethod
2780 || name_type_mask == eFunctionNameTypeBase)
2781 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002782 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2783 if (!containing_decl_ctx)
2784 return false;
2785
2786 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2787
2788 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2789 return false;
2790 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2791 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002792 }
2793
2794 // Now we need to check whether the name we got back for this type matches the extra specifications
2795 // that were in the name we're looking up:
2796 if (base_name_start != partial_name || *base_name_end != '\0')
2797 {
2798 // First see if the stuff to the left matches the full name. To do that let's see if
2799 // we can pull out the mips linkage name attribute:
2800
2801 Mangled best_name;
2802
2803 DWARFDebugInfoEntry::Attributes attributes;
2804 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2805 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2806 if (idx != UINT32_MAX)
2807 {
2808 DWARFFormValue form_value;
2809 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2810 {
2811 const char *name = form_value.AsCString(&get_debug_str_data());
2812 best_name.SetValue (name, true);
2813 }
2814 }
2815 if (best_name)
2816 {
2817 const char *demangled = best_name.GetDemangledName().GetCString();
2818 if (demangled)
2819 {
2820 std::string name_no_parens(partial_name, base_name_end - partial_name);
2821 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002822 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002823 }
2824 }
2825 }
2826
2827 return true;
2828}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002829
Greg Clayton0c5cd902010-06-28 21:30:43 +00002830uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002831SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002832 const lldb_private::ClangNamespaceDecl *namespace_decl,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002833 uint32_t name_type_mask,
2834 bool append,
2835 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002836{
2837 Timer scoped_timer (__PRETTY_FUNCTION__,
2838 "SymbolFileDWARF::FindFunctions (name = '%s')",
2839 name.AsCString());
2840
Greg Clayton21f2a492011-10-06 00:09:08 +00002841 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2842
2843 if (log)
2844 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002845 GetObjectFile()->GetModule()->LogMessage (log.get(),
2846 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2847 name.GetCString(),
2848 name_type_mask,
2849 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002850 }
2851
Greg Clayton0c5cd902010-06-28 21:30:43 +00002852 // If we aren't appending the results to this list, then clear the list
2853 if (!append)
2854 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002855
2856 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2857 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002858
2859 // If name is empty then we won't find anything.
2860 if (name.IsEmpty())
2861 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002862
2863 // Remember how many sc_list are in the list before we search in case
2864 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002865
Greg Clayton9e315582011-09-02 04:03:59 +00002866 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002867
Jim Ingham4cda6e02011-10-07 22:23:45 +00002868 const char *name_cstr = name.GetCString();
2869 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2870 const char *base_name_start = name_cstr;
2871 const char *base_name_end = name_cstr + strlen(name_cstr);
2872
2873 if (name_type_mask & eFunctionNameTypeAuto)
2874 {
2875 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2876 effective_name_type_mask = eFunctionNameTypeFull;
2877 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2878 effective_name_type_mask = eFunctionNameTypeFull;
2879 else
2880 {
2881 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2882 effective_name_type_mask |= eFunctionNameTypeSelector;
2883
2884 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2885 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2886 }
2887 }
2888 else
2889 {
2890 effective_name_type_mask = name_type_mask;
2891 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2892 {
2893 // If they've asked for a CPP method or function name and it can't be that, we don't
2894 // even need to search for CPP methods or names.
2895 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2896 {
2897 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2898 if (effective_name_type_mask == eFunctionNameTypeNone)
2899 return 0;
2900 }
2901 }
2902
2903 if (effective_name_type_mask & eFunctionNameTypeSelector)
2904 {
2905 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2906 {
2907 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2908 if (effective_name_type_mask == eFunctionNameTypeNone)
2909 return 0;
2910 }
2911 }
2912 }
2913
2914 DWARFDebugInfo* info = DebugInfo();
2915 if (info == NULL)
2916 return 0;
2917
Greg Claytonaa044962011-10-13 00:59:38 +00002918 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00002919 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002920 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002921 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002922 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002923
2924 DIEArray die_offsets;
2925
2926 uint32_t num_matches = 0;
2927
2928 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002929 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002930 // If they asked for the full name, match what they typed. At some point we may
2931 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2932 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002933 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002934 for (uint32_t i = 0; i < num_matches; i++)
2935 {
Greg Clayton95d87902011-11-11 03:16:25 +00002936 const dw_offset_t die_offset = die_offsets[i];
2937 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002938 if (die)
2939 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002940 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2941 continue;
2942
Greg Claytonaa044962011-10-13 00:59:38 +00002943 ResolveFunction (dwarf_cu, die, sc_list);
2944 }
Greg Clayton95d87902011-11-11 03:16:25 +00002945 else
2946 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002947 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2948 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002949 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002950 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002951 }
2952 else
2953 {
2954 if (effective_name_type_mask & eFunctionNameTypeSelector)
2955 {
2956 if (namespace_decl && *namespace_decl)
2957 return 0; // no selectors in namespaces
2958
2959 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2960 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2961 // and if it is an ObjC method name, we're good.
2962
2963 for (uint32_t i = 0; i < num_matches; i++)
2964 {
Greg Clayton95d87902011-11-11 03:16:25 +00002965 const dw_offset_t die_offset = die_offsets[i];
2966 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00002967 if (die)
2968 {
2969 const char *die_name = die->GetName(this, dwarf_cu);
2970 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
2971 ResolveFunction (dwarf_cu, die, sc_list);
2972 }
Greg Clayton95d87902011-11-11 03:16:25 +00002973 else
2974 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002975 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2976 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002977 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002978 }
2979 die_offsets.clear();
2980 }
2981
2982 if (effective_name_type_mask & eFunctionNameTypeMethod
2983 || effective_name_type_mask & eFunctionNameTypeBase)
2984 {
2985 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
2986 (namespace_decl && *namespace_decl))
2987 return 0; // no methods in namespaces
2988
2989 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2990 // extract the base name, look that up, and if there is any other information in the name we were
2991 // passed in we have to post-filter based on that.
2992
2993 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2994 std::string base_name(base_name_start, base_name_end - base_name_start);
2995 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
2996
2997 for (uint32_t i = 0; i < num_matches; i++)
2998 {
Greg Clayton95d87902011-11-11 03:16:25 +00002999 const dw_offset_t die_offset = die_offsets[i];
3000 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003001 if (die)
3002 {
3003 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3004 continue;
3005
3006 if (!FunctionDieMatchesPartialName(die,
3007 dwarf_cu,
3008 effective_name_type_mask,
3009 name_cstr,
3010 base_name_start,
3011 base_name_end))
3012 continue;
3013
3014 // If we get to here, the die is good, and we should add it:
3015 ResolveFunction (dwarf_cu, die, sc_list);
3016 }
Greg Clayton95d87902011-11-11 03:16:25 +00003017 else
3018 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003019 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3020 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003021 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003022 }
3023 die_offsets.clear();
3024 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003025 }
3026 }
Greg Clayton7f995132011-10-04 22:41:51 +00003027 }
3028 else
3029 {
3030
3031 // Index the DWARF if we haven't already
3032 if (!m_indexed)
3033 Index ();
3034
Greg Clayton7f995132011-10-04 22:41:51 +00003035 if (name_type_mask & eFunctionNameTypeFull)
3036 FindFunctions (name, m_function_fullname_index, sc_list);
3037
Jim Ingham4cda6e02011-10-07 22:23:45 +00003038 std::string base_name(base_name_start, base_name_end - base_name_start);
3039 ConstString base_name_const(base_name.c_str());
3040 DIEArray die_offsets;
3041 DWARFCompileUnit *dwarf_cu = NULL;
3042
3043 if (effective_name_type_mask & eFunctionNameTypeBase)
3044 {
3045 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003046 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003047 {
Greg Claytonaa044962011-10-13 00:59:38 +00003048 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3049 if (die)
3050 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003051 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3052 continue;
3053
Greg Claytonaa044962011-10-13 00:59:38 +00003054 if (!FunctionDieMatchesPartialName(die,
3055 dwarf_cu,
3056 effective_name_type_mask,
3057 name_cstr,
3058 base_name_start,
3059 base_name_end))
3060 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003061
Greg Claytonaa044962011-10-13 00:59:38 +00003062 // If we get to here, the die is good, and we should add it:
3063 ResolveFunction (dwarf_cu, die, sc_list);
3064 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003065 }
3066 die_offsets.clear();
3067 }
3068
Jim Inghamea8005a2011-10-11 01:18:11 +00003069 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003070 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003071 if (namespace_decl && *namespace_decl)
3072 return 0; // no methods in namespaces
3073
Jim Ingham4cda6e02011-10-07 22:23:45 +00003074 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3075 {
Greg Claytonaa044962011-10-13 00:59:38 +00003076 for (uint32_t i = 0; i < num_base; i++)
3077 {
3078 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3079 if (die)
3080 {
3081 if (!FunctionDieMatchesPartialName(die,
3082 dwarf_cu,
3083 effective_name_type_mask,
3084 name_cstr,
3085 base_name_start,
3086 base_name_end))
3087 continue;
3088
3089 // If we get to here, the die is good, and we should add it:
3090 ResolveFunction (dwarf_cu, die, sc_list);
3091 }
3092 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003093 }
3094 die_offsets.clear();
3095 }
Greg Clayton7f995132011-10-04 22:41:51 +00003096
Sean Callanan213fdb82011-10-13 01:49:10 +00003097 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003098 {
Greg Clayton7f995132011-10-04 22:41:51 +00003099 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003100 }
3101
Greg Clayton4d01ace2011-09-29 16:58:15 +00003102 }
3103
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003104 // Return the number of variable that were appended to the list
3105 return sc_list.GetSize() - original_size;
3106}
3107
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003108uint32_t
3109SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
3110{
3111 Timer scoped_timer (__PRETTY_FUNCTION__,
3112 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3113 regex.GetText());
3114
Greg Clayton21f2a492011-10-06 00:09:08 +00003115 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3116
3117 if (log)
3118 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003119 GetObjectFile()->GetModule()->LogMessage (log.get(),
3120 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3121 regex.GetText(),
3122 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003123 }
3124
3125
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003126 // If we aren't appending the results to this list, then clear the list
3127 if (!append)
3128 sc_list.Clear();
3129
3130 // Remember how many sc_list are in the list before we search in case
3131 // we are appending the results to a variable list.
3132 uint32_t original_size = sc_list.GetSize();
3133
Greg Clayton97fbc342011-10-20 22:30:33 +00003134 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003135 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003136 if (m_apple_names_ap.get())
3137 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003138 }
3139 else
3140 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003141 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003142 if (!m_indexed)
3143 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003144
Greg Clayton7f995132011-10-04 22:41:51 +00003145 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003146
Greg Clayton7f995132011-10-04 22:41:51 +00003147 FindFunctions (regex, m_function_fullname_index, sc_list);
3148 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003149
3150 // Return the number of variable that were appended to the list
3151 return sc_list.GetSize() - original_size;
3152}
Jim Ingham318c9f22011-08-26 19:44:13 +00003153
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003154uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003155SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3156 const ConstString &name,
3157 const lldb_private::ClangNamespaceDecl *namespace_decl,
3158 bool append,
3159 uint32_t max_matches,
3160 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003161{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003162 DWARFDebugInfo* info = DebugInfo();
3163 if (info == NULL)
3164 return 0;
3165
Greg Clayton21f2a492011-10-06 00:09:08 +00003166 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3167
3168 if (log)
3169 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003170 GetObjectFile()->GetModule()->LogMessage (log.get(),
3171 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
3172 name.GetCString(),
3173 append,
3174 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003175 }
3176
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003177 // If we aren't appending the results to this list, then clear the list
3178 if (!append)
3179 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003180
3181 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3182 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003183
Greg Claytond4a2b372011-09-12 23:21:58 +00003184 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003185
Greg Clayton97fbc342011-10-20 22:30:33 +00003186 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003187 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003188 if (m_apple_types_ap.get())
3189 {
3190 const char *name_cstr = name.GetCString();
3191 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3192 }
Greg Clayton7f995132011-10-04 22:41:51 +00003193 }
3194 else
3195 {
3196 if (!m_indexed)
3197 Index ();
3198
3199 m_type_index.Find (name, die_offsets);
3200 }
3201
Greg Clayton7f995132011-10-04 22:41:51 +00003202 const size_t num_matches = die_offsets.size();
3203
Greg Claytond4a2b372011-09-12 23:21:58 +00003204 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003205 {
Greg Clayton7f995132011-10-04 22:41:51 +00003206 const uint32_t initial_types_size = types.GetSize();
3207 DWARFCompileUnit* dwarf_cu = NULL;
3208 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003209 DWARFDebugInfo* debug_info = DebugInfo();
3210 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003212 const dw_offset_t die_offset = die_offsets[i];
3213 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3214
Greg Clayton95d87902011-11-11 03:16:25 +00003215 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003216 {
Greg Clayton95d87902011-11-11 03:16:25 +00003217 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3218 continue;
3219
3220 Type *matching_type = ResolveType (dwarf_cu, die);
3221 if (matching_type)
3222 {
3223 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003224 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003225 if (types.GetSize() >= max_matches)
3226 break;
3227 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003228 }
Greg Clayton95d87902011-11-11 03:16:25 +00003229 else
3230 {
3231 if (m_using_apple_tables)
3232 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003233 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3234 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003235 }
3236 }
3237
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003238 }
Greg Clayton7f995132011-10-04 22:41:51 +00003239 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003240 }
Greg Clayton7f995132011-10-04 22:41:51 +00003241 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003242}
3243
3244
Greg Clayton526e5af2010-11-13 03:52:47 +00003245ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003246SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003247 const ConstString &name,
3248 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003249{
Greg Clayton21f2a492011-10-06 00:09:08 +00003250 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3251
3252 if (log)
3253 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003254 GetObjectFile()->GetModule()->LogMessage (log.get(),
3255 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3256 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003257 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003258
3259 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3260 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003261
Greg Clayton526e5af2010-11-13 03:52:47 +00003262 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003263 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003264 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003265 {
Greg Clayton7f995132011-10-04 22:41:51 +00003266 DIEArray die_offsets;
3267
Greg Clayton526e5af2010-11-13 03:52:47 +00003268 // Index if we already haven't to make sure the compile units
3269 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003270 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003271 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003272 if (m_apple_namespaces_ap.get())
3273 {
3274 const char *name_cstr = name.GetCString();
3275 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3276 }
Greg Clayton7f995132011-10-04 22:41:51 +00003277 }
3278 else
3279 {
3280 if (!m_indexed)
3281 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003282
Greg Clayton7f995132011-10-04 22:41:51 +00003283 m_namespace_index.Find (name, die_offsets);
3284 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003285
3286 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003287 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003288 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003289 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003290 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003291 DWARFDebugInfo* debug_info = DebugInfo();
3292 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003293 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003294 const dw_offset_t die_offset = die_offsets[i];
3295 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003296
Greg Clayton95d87902011-11-11 03:16:25 +00003297 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003298 {
Greg Clayton95d87902011-11-11 03:16:25 +00003299 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3300 continue;
3301
3302 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3303 if (clang_namespace_decl)
3304 {
3305 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3306 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003307 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003308 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003309 }
Greg Clayton95d87902011-11-11 03:16:25 +00003310 else
3311 {
3312 if (m_using_apple_tables)
3313 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003314 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3315 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003316 }
3317 }
3318
Greg Clayton526e5af2010-11-13 03:52:47 +00003319 }
3320 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003321 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003322 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003323}
3324
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003325uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003326SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003327{
3328 // Remember how many sc_list are in the list before we search in case
3329 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003330 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003331
3332 const uint32_t num_die_offsets = die_offsets.size();
3333 // Parse all of the types we found from the pubtypes matches
3334 uint32_t i;
3335 uint32_t num_matches = 0;
3336 for (i = 0; i < num_die_offsets; ++i)
3337 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003338 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3339 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003340 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003341 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003342 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003343 ++num_matches;
3344 if (num_matches >= max_matches)
3345 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003346 }
3347 }
3348
3349 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003350 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003351}
3352
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003353
3354size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003355SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3356 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003357 DWARFCompileUnit* dwarf_cu,
3358 const DWARFDebugInfoEntry *parent_die,
3359 bool skip_artificial,
3360 bool &is_static,
3361 TypeList* type_list,
3362 std::vector<clang_type_t>& function_param_types,
3363 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003364 unsigned &type_quals,
3365 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003366{
3367 if (parent_die == NULL)
3368 return 0;
3369
Greg Claytond88d7592010-09-15 08:33:30 +00003370 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3371
Greg Clayton7fedea22010-11-16 02:10:54 +00003372 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003373 const DWARFDebugInfoEntry *die;
3374 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3375 {
3376 dw_tag_t tag = die->Tag();
3377 switch (tag)
3378 {
3379 case DW_TAG_formal_parameter:
3380 {
3381 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003382 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003383 if (num_attributes > 0)
3384 {
3385 const char *name = NULL;
3386 Declaration decl;
3387 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003388 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003389 // one of None, Auto, Register, Extern, Static, PrivateExtern
3390
Sean Callanane2ef6e32010-09-23 03:01:22 +00003391 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003392 uint32_t i;
3393 for (i=0; i<num_attributes; ++i)
3394 {
3395 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3396 DWARFFormValue form_value;
3397 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3398 {
3399 switch (attr)
3400 {
3401 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3402 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3403 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3404 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3405 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003406 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003407 case DW_AT_location:
3408 // if (form_value.BlockData())
3409 // {
3410 // const DataExtractor& debug_info_data = debug_info();
3411 // uint32_t block_length = form_value.Unsigned();
3412 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3413 // }
3414 // else
3415 // {
3416 // }
3417 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003418 case DW_AT_const_value:
3419 case DW_AT_default_value:
3420 case DW_AT_description:
3421 case DW_AT_endianity:
3422 case DW_AT_is_optional:
3423 case DW_AT_segment:
3424 case DW_AT_variable_parameter:
3425 default:
3426 case DW_AT_abstract_origin:
3427 case DW_AT_sibling:
3428 break;
3429 }
3430 }
3431 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003432
Greg Clayton0fffff52010-09-24 05:15:53 +00003433 bool skip = false;
3434 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003435 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003436 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003437 {
3438 // In order to determine if a C++ member function is
3439 // "const" we have to look at the const-ness of "this"...
3440 // Ugly, but that
3441 if (arg_idx == 0)
3442 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003443 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003444 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003445 // Often times compilers omit the "this" name for the
3446 // specification DIEs, so we can't rely upon the name
3447 // being in the formal parameter DIE...
3448 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003449 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003450 Type *this_type = ResolveTypeUID (param_type_die_offset);
3451 if (this_type)
3452 {
3453 uint32_t encoding_mask = this_type->GetEncodingMask();
3454 if (encoding_mask & Type::eEncodingIsPointerUID)
3455 {
3456 is_static = false;
3457
3458 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3459 type_quals |= clang::Qualifiers::Const;
3460 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3461 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003462 }
3463 }
3464 }
3465 }
3466 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003467 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003468 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003469 else
3470 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003471
Greg Clayton0fffff52010-09-24 05:15:53 +00003472 // HACK: Objective C formal parameters "self" and "_cmd"
3473 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003474 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3475 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003476 {
3477 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3478 skip = true;
3479 }
3480 }
3481 }
3482
3483 if (!skip)
3484 {
3485 Type *type = ResolveTypeUID(param_type_die_offset);
3486 if (type)
3487 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003488 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003489
Greg Clayton42ce2f32011-12-12 21:50:19 +00003490 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3491 type->GetClangForwardType(),
3492 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003493 assert(param_var_decl);
3494 function_param_decls.push_back(param_var_decl);
3495 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003496 }
3497 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003498 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003499 }
3500 break;
3501
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003502 case DW_TAG_template_type_parameter:
3503 case DW_TAG_template_value_parameter:
3504 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3505 break;
3506
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003507 default:
3508 break;
3509 }
3510 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003511 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003512}
3513
3514size_t
3515SymbolFileDWARF::ParseChildEnumerators
3516(
3517 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003518 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003519 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003520 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003521 const DWARFDebugInfoEntry *parent_die
3522)
3523{
3524 if (parent_die == NULL)
3525 return 0;
3526
3527 size_t enumerators_added = 0;
3528 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003529 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3530
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003531 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3532 {
3533 const dw_tag_t tag = die->Tag();
3534 if (tag == DW_TAG_enumerator)
3535 {
3536 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003537 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003538 if (num_child_attributes > 0)
3539 {
3540 const char *name = NULL;
3541 bool got_value = false;
3542 int64_t enum_value = 0;
3543 Declaration decl;
3544
3545 uint32_t i;
3546 for (i=0; i<num_child_attributes; ++i)
3547 {
3548 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3549 DWARFFormValue form_value;
3550 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3551 {
3552 switch (attr)
3553 {
3554 case DW_AT_const_value:
3555 got_value = true;
3556 enum_value = form_value.Unsigned();
3557 break;
3558
3559 case DW_AT_name:
3560 name = form_value.AsCString(&get_debug_str_data());
3561 break;
3562
3563 case DW_AT_description:
3564 default:
3565 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3566 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3567 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3568 case DW_AT_sibling:
3569 break;
3570 }
3571 }
3572 }
3573
3574 if (name && name[0] && got_value)
3575 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003576 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3577 enumerator_clang_type,
3578 decl,
3579 name,
3580 enum_value,
3581 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003582 ++enumerators_added;
3583 }
3584 }
3585 }
3586 }
3587 return enumerators_added;
3588}
3589
3590void
3591SymbolFileDWARF::ParseChildArrayInfo
3592(
3593 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003594 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003595 const DWARFDebugInfoEntry *parent_die,
3596 int64_t& first_index,
3597 std::vector<uint64_t>& element_orders,
3598 uint32_t& byte_stride,
3599 uint32_t& bit_stride
3600)
3601{
3602 if (parent_die == NULL)
3603 return;
3604
3605 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003606 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003607 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3608 {
3609 const dw_tag_t tag = die->Tag();
3610 switch (tag)
3611 {
3612 case DW_TAG_enumerator:
3613 {
3614 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003615 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003616 if (num_child_attributes > 0)
3617 {
3618 const char *name = NULL;
3619 bool got_value = false;
3620 int64_t enum_value = 0;
3621
3622 uint32_t i;
3623 for (i=0; i<num_child_attributes; ++i)
3624 {
3625 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3626 DWARFFormValue form_value;
3627 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3628 {
3629 switch (attr)
3630 {
3631 case DW_AT_const_value:
3632 got_value = true;
3633 enum_value = form_value.Unsigned();
3634 break;
3635
3636 case DW_AT_name:
3637 name = form_value.AsCString(&get_debug_str_data());
3638 break;
3639
3640 case DW_AT_description:
3641 default:
3642 case DW_AT_decl_file:
3643 case DW_AT_decl_line:
3644 case DW_AT_decl_column:
3645 case DW_AT_sibling:
3646 break;
3647 }
3648 }
3649 }
3650 }
3651 }
3652 break;
3653
3654 case DW_TAG_subrange_type:
3655 {
3656 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003657 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003658 if (num_child_attributes > 0)
3659 {
3660 const char *name = NULL;
3661 bool got_value = false;
3662 uint64_t byte_size = 0;
3663 int64_t enum_value = 0;
3664 uint64_t num_elements = 0;
3665 uint64_t lower_bound = 0;
3666 uint64_t upper_bound = 0;
3667 uint32_t i;
3668 for (i=0; i<num_child_attributes; ++i)
3669 {
3670 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3671 DWARFFormValue form_value;
3672 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3673 {
3674 switch (attr)
3675 {
3676 case DW_AT_const_value:
3677 got_value = true;
3678 enum_value = form_value.Unsigned();
3679 break;
3680
3681 case DW_AT_name:
3682 name = form_value.AsCString(&get_debug_str_data());
3683 break;
3684
3685 case DW_AT_count:
3686 num_elements = form_value.Unsigned();
3687 break;
3688
3689 case DW_AT_bit_stride:
3690 bit_stride = form_value.Unsigned();
3691 break;
3692
3693 case DW_AT_byte_stride:
3694 byte_stride = form_value.Unsigned();
3695 break;
3696
3697 case DW_AT_byte_size:
3698 byte_size = form_value.Unsigned();
3699 break;
3700
3701 case DW_AT_lower_bound:
3702 lower_bound = form_value.Unsigned();
3703 break;
3704
3705 case DW_AT_upper_bound:
3706 upper_bound = form_value.Unsigned();
3707 break;
3708
3709 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003710 case DW_AT_abstract_origin:
3711 case DW_AT_accessibility:
3712 case DW_AT_allocated:
3713 case DW_AT_associated:
3714 case DW_AT_data_location:
3715 case DW_AT_declaration:
3716 case DW_AT_description:
3717 case DW_AT_sibling:
3718 case DW_AT_threads_scaled:
3719 case DW_AT_type:
3720 case DW_AT_visibility:
3721 break;
3722 }
3723 }
3724 }
3725
3726 if (upper_bound > lower_bound)
3727 num_elements = upper_bound - lower_bound + 1;
3728
3729 if (num_elements > 0)
3730 element_orders.push_back (num_elements);
3731 }
3732 }
3733 break;
3734 }
3735 }
3736}
3737
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003738TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003739SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740{
3741 TypeSP type_sp;
3742 if (die != NULL)
3743 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003744 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003745 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003746 if (type_ptr == NULL)
3747 {
Greg Claytonca512b32011-01-14 04:54:56 +00003748 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3749 assert (lldb_cu);
3750 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003751 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003752 }
3753 else if (type_ptr != DIE_IS_BEING_PARSED)
3754 {
3755 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003756 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003757 }
3758
3759 }
3760 return type_sp;
3761}
3762
3763clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003764SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003765{
3766 if (die_offset != DW_INVALID_OFFSET)
3767 {
3768 DWARFCompileUnitSP cu_sp;
3769 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003770 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003771 }
3772 return NULL;
3773}
3774
Sean Callanan72e49402011-08-05 23:43:37 +00003775clang::DeclContext *
3776SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3777{
3778 if (die_offset != DW_INVALID_OFFSET)
3779 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003780 DWARFDebugInfo* debug_info = DebugInfo();
3781 if (debug_info)
3782 {
3783 DWARFCompileUnitSP cu_sp;
3784 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3785 if (die)
3786 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3787 }
Sean Callanan72e49402011-08-05 23:43:37 +00003788 }
3789 return NULL;
3790}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003791
Greg Clayton96d7d742010-11-10 23:42:09 +00003792clang::NamespaceDecl *
3793SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3794{
Greg Clayton030a2042011-10-14 21:34:45 +00003795 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003796 {
Greg Clayton030a2042011-10-14 21:34:45 +00003797 // See if we already parsed this namespace DIE and associated it with a
3798 // uniqued namespace declaration
3799 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3800 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003801 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003802 else
3803 {
3804 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00003805 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3806 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3807 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3808 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00003809 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00003810 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00003811 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003812 GetObjectFile()->GetModule()->LogMessage (log.get(),
3813 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
3814 GetClangASTContext().getASTContext(),
3815 MakeUserID(die->GetOffset()),
3816 namespace_name,
3817 namespace_decl,
3818 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00003819 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003820 else
3821 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003822 GetObjectFile()->GetModule()->LogMessage (log.get(),
3823 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
3824 GetClangASTContext().getASTContext(),
3825 MakeUserID(die->GetOffset()),
3826 namespace_decl,
3827 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00003828 }
Greg Clayton030a2042011-10-14 21:34:45 +00003829 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003830
3831 if (namespace_decl)
3832 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3833 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003834 }
3835 }
3836 return NULL;
3837}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003838
3839clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00003840SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00003841{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003842 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3843 if (clang_decl_ctx)
3844 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003845 // If this DIE has a specification, or an abstract origin, then trace to those.
3846
Greg Claytoncab36a32011-12-08 05:16:30 +00003847 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003848 if (die_offset != DW_INVALID_OFFSET)
3849 return GetClangDeclContextForDIEOffset (sc, die_offset);
3850
Greg Claytoncab36a32011-12-08 05:16:30 +00003851 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003852 if (die_offset != DW_INVALID_OFFSET)
3853 return GetClangDeclContextForDIEOffset (sc, die_offset);
3854
Greg Clayton3bffb082011-12-10 02:15:28 +00003855 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3856 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003857 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 +00003858 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00003859 bool assert_not_being_parsed = true;
3860 ResolveTypeUID (cu, die, assert_not_being_parsed);
3861
Greg Clayton5cf58b92011-10-05 22:22:08 +00003862 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3863
3864 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003865}
3866
3867clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003868SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003869{
Greg Claytonca512b32011-01-14 04:54:56 +00003870 if (m_clang_tu_decl == NULL)
3871 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003872
Greg Clayton2bc22f82011-09-30 03:20:47 +00003873 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003874
3875 if (decl_ctx_die_copy)
3876 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003877
3878 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003879 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003880
Greg Clayton2bc22f82011-09-30 03:20:47 +00003881 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3882 if (pos != m_die_to_decl_ctx.end())
3883 return pos->second;
3884
3885 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003886 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003887 case DW_TAG_compile_unit:
3888 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003889
Greg Clayton2bc22f82011-09-30 03:20:47 +00003890 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003891 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003892 break;
3893
3894 case DW_TAG_structure_type:
3895 case DW_TAG_union_type:
3896 case DW_TAG_class_type:
3897 {
3898 Type* type = ResolveType (cu, decl_ctx_die);
3899 if (type)
3900 {
3901 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3902 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003903 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003904 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3905 if (decl_ctx)
3906 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003907 }
3908 }
Greg Claytonca512b32011-01-14 04:54:56 +00003909 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003910 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003911
Greg Clayton2bc22f82011-09-30 03:20:47 +00003912 default:
3913 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003914 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003915 }
Greg Clayton7a345282010-11-09 23:46:37 +00003916 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003917}
3918
Greg Clayton2bc22f82011-09-30 03:20:47 +00003919
3920const DWARFDebugInfoEntry *
3921SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3922{
3923 if (cu && die)
3924 {
3925 const DWARFDebugInfoEntry * const decl_die = die;
3926
3927 while (die != NULL)
3928 {
3929 // If this is the original DIE that we are searching for a declaration
3930 // for, then don't look in the cache as we don't want our own decl
3931 // context to be our decl context...
3932 if (decl_die != die)
3933 {
3934 switch (die->Tag())
3935 {
3936 case DW_TAG_compile_unit:
3937 case DW_TAG_namespace:
3938 case DW_TAG_structure_type:
3939 case DW_TAG_union_type:
3940 case DW_TAG_class_type:
3941 return die;
3942
3943 default:
3944 break;
3945 }
3946 }
3947
3948 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3949 if (die_offset != DW_INVALID_OFFSET)
3950 {
3951 DWARFCompileUnit *spec_cu = cu;
3952 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3953 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3954 if (spec_die_decl_ctx_die)
3955 return spec_die_decl_ctx_die;
3956 }
3957
3958 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3959 if (die_offset != DW_INVALID_OFFSET)
3960 {
3961 DWARFCompileUnit *abs_cu = cu;
3962 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3963 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3964 if (abs_die_decl_ctx_die)
3965 return abs_die_decl_ctx_die;
3966 }
3967
3968 die = die->GetParent();
3969 }
3970 }
3971 return NULL;
3972}
3973
3974
Greg Clayton901c5ca2011-12-03 04:40:03 +00003975Symbol *
3976SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3977{
3978 Symbol *objc_class_symbol = NULL;
3979 if (m_obj_file)
3980 {
3981 Symtab *symtab = m_obj_file->GetSymtab();
3982 if (symtab)
3983 {
3984 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3985 eSymbolTypeObjCClass,
3986 Symtab::eDebugNo,
3987 Symtab::eVisibilityAny);
3988 }
3989 }
3990 return objc_class_symbol;
3991}
3992
Greg Claytonc7f03b62012-01-12 04:33:28 +00003993// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3994// then we can end up looking through all class types for a complete type and never find
3995// the full definition. We need to know if this attribute is supported, so we determine
3996// this here and cache th result. We also need to worry about the debug map DWARF file
3997// if we are doing darwin DWARF in .o file debugging.
3998bool
3999SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4000{
4001 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4002 {
4003 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4004 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4005 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4006 else
4007 {
4008 DWARFDebugInfo* debug_info = DebugInfo();
4009 const uint32_t num_compile_units = GetNumCompileUnits();
4010 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4011 {
4012 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4013 if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type())
4014 {
4015 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4016 break;
4017 }
4018 }
4019 }
4020 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4021 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4022 }
4023 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4024}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004025
4026// This function can be used when a DIE is found that is a forward declaration
4027// DIE and we want to try and find a type that has the complete definition.
4028TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004029SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4030 const ConstString &type_name,
4031 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004032{
4033
4034 TypeSP type_sp;
4035
Greg Claytonc7f03b62012-01-12 04:33:28 +00004036 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004037 return type_sp;
4038
4039 DIEArray die_offsets;
4040
4041 if (m_using_apple_tables)
4042 {
4043 if (m_apple_types_ap.get())
4044 {
4045 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004046 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004047 }
4048 }
4049 else
4050 {
4051 if (!m_indexed)
4052 Index ();
4053
4054 m_type_index.Find (type_name, die_offsets);
4055 }
4056
Greg Clayton901c5ca2011-12-03 04:40:03 +00004057 const size_t num_matches = die_offsets.size();
4058
Greg Clayton901c5ca2011-12-03 04:40:03 +00004059 DWARFCompileUnit* type_cu = NULL;
4060 const DWARFDebugInfoEntry* type_die = NULL;
4061 if (num_matches)
4062 {
4063 DWARFDebugInfo* debug_info = DebugInfo();
4064 for (size_t i=0; i<num_matches; ++i)
4065 {
4066 const dw_offset_t die_offset = die_offsets[i];
4067 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4068
4069 if (type_die)
4070 {
4071 bool try_resolving_type = false;
4072
4073 // Don't try and resolve the DIE we are looking for with the DIE itself!
4074 if (type_die != die)
4075 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004076 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004077 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004078 case DW_TAG_class_type:
4079 case DW_TAG_structure_type:
4080 try_resolving_type = true;
4081 break;
4082 default:
4083 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004084 }
4085 }
4086
4087 if (try_resolving_type)
4088 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004089 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004090 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004091
4092 if (try_resolving_type)
4093 {
4094 Type *resolved_type = ResolveType (type_cu, type_die, false);
4095 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4096 {
4097 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4098 MakeUserID(die->GetOffset()),
4099 MakeUserID(curr_cu->GetOffset()),
4100 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4101 MakeUserID(type_die->GetOffset()),
4102 MakeUserID(type_cu->GetOffset()));
4103
Greg Claytonc7f03b62012-01-12 04:33:28 +00004104 if (die)
4105 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004106 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004107 break;
4108 }
4109 }
4110 }
4111 }
4112 else
4113 {
4114 if (m_using_apple_tables)
4115 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004116 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4117 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004118 }
4119 }
4120
4121 }
4122 }
4123 return type_sp;
4124}
4125
Greg Clayton80c26302012-02-05 06:12:47 +00004126//----------------------------------------------------------------------
4127// This function helps to ensure that the declaration contexts match for
4128// two different DIEs. Often times debug information will refer to a
4129// forward declaration of a type (the equivalent of "struct my_struct;".
4130// There will often be a declaration of that type elsewhere that has the
4131// full definition. When we go looking for the full type "my_struct", we
4132// will find one or more matches in the accelerator tables and we will
4133// then need to make sure the type was in the same declaration context
4134// as the original DIE. This function can efficiently compare two DIEs
4135// and will return true when the declaration context matches, and false
4136// when they don't.
4137//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004138bool
4139SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4140 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4141{
4142 assert (die1 != die2);
4143 DWARFDIECollection decl_ctx_1;
4144 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004145 //The declaration DIE stack is a stack of the declaration context
4146 // DIEs all the way back to the compile unit. If a type "T" is
4147 // declared inside a class "B", and class "B" is declared inside
4148 // a class "A" and class "A" is in a namespace "lldb", and the
4149 // namespace is in a compile unit, there will be a stack of DIEs:
4150 //
4151 // [0] DW_TAG_class_type for "B"
4152 // [1] DW_TAG_class_type for "A"
4153 // [2] DW_TAG_namespace for "lldb"
4154 // [3] DW_TAG_compile_unit for the source file.
4155 //
4156 // We grab both contexts and make sure that everything matches
4157 // all the way back to the compiler unit.
4158
4159 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004160 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004161 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004162 // Make sure the context arrays have the same size, otherwise
4163 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004164 const size_t count1 = decl_ctx_1.Size();
4165 const size_t count2 = decl_ctx_2.Size();
4166 if (count1 != count2)
4167 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004168
4169 // Make sure the DW_TAG values match all the way back up the the
4170 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004171 const DWARFDebugInfoEntry *decl_ctx_die1;
4172 const DWARFDebugInfoEntry *decl_ctx_die2;
4173 size_t i;
4174 for (i=0; i<count1; i++)
4175 {
4176 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4177 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4178 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4179 return false;
4180 }
Greg Clayton890ff562012-02-02 05:48:16 +00004181#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004182
4183 // Make sure the top item in the decl context die array is always
4184 // DW_TAG_compile_unit. If it isn't then something went wrong in
4185 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004186 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004187
Greg Clayton890ff562012-02-02 05:48:16 +00004188#endif
4189 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004190 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004191 for (i=0; i<count1 - 1; i++)
4192 {
4193 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4194 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4195 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004196 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004197 // If the string was from a DW_FORM_strp, then the pointer will often
4198 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004199 if (name1 == name2)
4200 continue;
4201
4202 // Name pointers are not equal, so only compare the strings
4203 // if both are not NULL.
4204 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004205 {
Greg Clayton5569e642012-02-06 01:44:54 +00004206 // If the strings don't compare, we are done...
4207 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004208 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004209 }
4210 else
4211 {
4212 // One name was NULL while the other wasn't
4213 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004214 }
4215 }
Greg Clayton80c26302012-02-05 06:12:47 +00004216 // We made it through all of the checks and the declaration contexts
4217 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004218 return true;
4219}
Greg Clayton220a0072011-12-09 08:48:30 +00004220
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004221// This function can be used when a DIE is found that is a forward declaration
4222// DIE and we want to try and find a type that has the complete definition.
4223TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00004224SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4225 const DWARFDebugInfoEntry *die,
4226 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004227{
4228 TypeSP type_sp;
4229
Greg Clayton1a65ae12011-01-25 23:55:37 +00004230 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004231 return type_sp;
4232
Greg Clayton7f995132011-10-04 22:41:51 +00004233 DIEArray die_offsets;
4234
Greg Clayton97fbc342011-10-20 22:30:33 +00004235 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004236 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004237 if (m_apple_types_ap.get())
4238 {
Greg Claytond1767f02011-12-08 02:13:16 +00004239 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4240 {
Greg Claytonae920b62012-01-06 00:17:16 +00004241 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004242 }
4243 else
4244 {
4245 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4246 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004247 }
Greg Clayton7f995132011-10-04 22:41:51 +00004248 }
4249 else
4250 {
4251 if (!m_indexed)
4252 Index ();
4253
4254 m_type_index.Find (type_name, die_offsets);
4255 }
Greg Clayton7f995132011-10-04 22:41:51 +00004256
4257 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004258
Greg Clayton934cb052011-12-03 00:27:05 +00004259 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004260
4261 DWARFCompileUnit* type_cu = NULL;
4262 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004263 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004264 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004265 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004266 for (size_t i=0; i<num_matches; ++i)
4267 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004268 const dw_offset_t die_offset = die_offsets[i];
4269 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004270
Greg Clayton95d87902011-11-11 03:16:25 +00004271 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004272 {
Greg Clayton934cb052011-12-03 00:27:05 +00004273 bool try_resolving_type = false;
4274
4275 // Don't try and resolve the DIE we are looking for with the DIE itself!
4276 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004277 {
Greg Clayton934cb052011-12-03 00:27:05 +00004278 const dw_tag_t type_die_tag = type_die->Tag();
4279 // Make sure the tags match
4280 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004281 {
Greg Clayton934cb052011-12-03 00:27:05 +00004282 // The tags match, lets try resolving this type
4283 try_resolving_type = true;
4284 }
4285 else
4286 {
4287 // The tags don't match, but we need to watch our for a
4288 // forward declaration for a struct and ("struct foo")
4289 // ends up being a class ("class foo { ... };") or
4290 // vice versa.
4291 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004292 {
Greg Clayton934cb052011-12-03 00:27:05 +00004293 case DW_TAG_class_type:
4294 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4295 try_resolving_type = (die_tag == DW_TAG_structure_type);
4296 break;
4297 case DW_TAG_structure_type:
4298 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4299 try_resolving_type = (die_tag == DW_TAG_class_type);
4300 break;
4301 default:
4302 // Tags don't match, don't event try to resolve
4303 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004304 break;
4305 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004306 }
4307 }
Greg Clayton934cb052011-12-03 00:27:05 +00004308
4309 if (try_resolving_type)
4310 {
Greg Clayton890ff562012-02-02 05:48:16 +00004311 // Make sure the decl contexts match all the way up
4312 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004313 {
Greg Clayton890ff562012-02-02 05:48:16 +00004314 Type *resolved_type = ResolveType (type_cu, type_die, false);
4315 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4316 {
4317 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4318 MakeUserID(die->GetOffset()),
4319 MakeUserID(curr_cu->GetOffset()),
4320 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4321 MakeUserID(type_die->GetOffset()),
4322 MakeUserID(type_cu->GetOffset()));
4323
4324 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004325 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004326 break;
4327 }
Greg Clayton934cb052011-12-03 00:27:05 +00004328 }
4329 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004330 }
Greg Clayton95d87902011-11-11 03:16:25 +00004331 else
4332 {
4333 if (m_using_apple_tables)
4334 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004335 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4336 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004337 }
4338 }
4339
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004340 }
4341 }
4342 return type_sp;
4343}
4344
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004345TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004346SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004347{
4348 TypeSP type_sp;
4349
Greg Clayton1be10fc2010-09-29 01:12:09 +00004350 if (type_is_new_ptr)
4351 *type_is_new_ptr = false;
Sean Callanan5b26f272012-02-04 08:49:35 +00004352
4353 static int depth = -1;
4354
4355 class DepthTaker {
4356 public:
4357 DepthTaker (int &depth) : m_depth(depth) { ++m_depth; }
4358 ~DepthTaker () { --m_depth; }
4359 int &m_depth;
4360 } depth_taker(depth);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004361
Sean Callananc7fbf732010-08-06 00:32:49 +00004362 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004363 if (die != NULL)
4364 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004365 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004366 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00004367 {
4368 const DWARFDebugInfoEntry *context_die;
4369 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4370
4371 std::string name_storage;
4372
4373 const char* qual_name = die->GetQualifiedName(this,
4374 dwarf_cu,
4375 name_storage);
4376
4377 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (depth = %d, die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s '%s'='%s')",
4378 depth,
4379 die->GetOffset(),
4380 context,
4381 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00004382 DW_TAG_value_to_name(die->Tag()),
Sean Callanan5b26f272012-02-04 08:49:35 +00004383 die->GetName(this, dwarf_cu),
4384 qual_name);
4385 }
Greg Clayton3bffb082011-12-10 02:15:28 +00004386//
4387// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4388// if (log && dwarf_cu)
4389// {
4390// StreamString s;
4391// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00004392// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00004393//
4394// }
Jim Ingham16746d12011-08-25 23:21:43 +00004395
Greg Clayton594e5ed2010-09-27 21:07:38 +00004396 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004397 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004398 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004399 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004400 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004401 if (type_is_new_ptr)
4402 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004403
Greg Clayton594e5ed2010-09-27 21:07:38 +00004404 const dw_tag_t tag = die->Tag();
4405
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004406 bool is_forward_declaration = false;
4407 DWARFDebugInfoEntry::Attributes attributes;
4408 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004409 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004410 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4411 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004412 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004413 Declaration decl;
4414
Greg Clayton4957bf62010-09-30 21:49:03 +00004415 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004416 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004417
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004418 dw_attr_t attr;
4419
4420 switch (tag)
4421 {
4422 case DW_TAG_base_type:
4423 case DW_TAG_pointer_type:
4424 case DW_TAG_reference_type:
4425 case DW_TAG_typedef:
4426 case DW_TAG_const_type:
4427 case DW_TAG_restrict_type:
4428 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004429 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004430 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004432 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004433
Greg Claytond88d7592010-09-15 08:33:30 +00004434 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004436 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4437
4438 if (num_attributes > 0)
4439 {
4440 uint32_t i;
4441 for (i=0; i<num_attributes; ++i)
4442 {
4443 attr = attributes.AttributeAtIndex(i);
4444 DWARFFormValue form_value;
4445 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4446 {
4447 switch (attr)
4448 {
4449 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4450 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4451 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4452 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004453
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004454 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004455 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4456 // include the "&"...
4457 if (tag == DW_TAG_reference_type)
4458 {
4459 if (strchr (type_name_cstr, '&') == NULL)
4460 type_name_cstr = NULL;
4461 }
4462 if (type_name_cstr)
4463 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004464 break;
Greg Clayton36909642011-03-15 04:38:20 +00004465 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004466 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4467 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4468 default:
4469 case DW_AT_sibling:
4470 break;
4471 }
4472 }
4473 }
4474 }
4475
Greg Clayton81c22f62011-10-19 18:09:39 +00004476 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 +00004477
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004478 switch (tag)
4479 {
4480 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004481 break;
4482
Greg Claytond4436412011-10-28 21:00:00 +00004483 case DW_TAG_unspecified_type:
4484 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4485 {
4486 resolve_state = Type::eResolveStateFull;
4487 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4488 break;
4489 }
4490 // Fall through to base type below in case we can handle the type there...
4491
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004492 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004493 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004494 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4495 encoding,
4496 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004497 break;
4498
Greg Clayton526e5af2010-11-13 03:52:47 +00004499 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4500 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4501 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4502 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4503 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4504 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004505 }
4506
Greg Claytonc7f03b62012-01-12 04:33:28 +00004507 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004508 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004509 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4510 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004511 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004512 static ConstString g_objc_type_name_id("id");
4513 static ConstString g_objc_type_name_Class("Class");
4514 static ConstString g_objc_type_name_selector("SEL");
4515
4516 if (type_name_const_str == g_objc_type_name_id)
4517 {
4518 if (log)
4519 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4520 die->GetOffset(),
4521 DW_TAG_value_to_name(die->Tag()),
4522 die->GetName(this, dwarf_cu));
4523 clang_type = ast.GetBuiltInType_objc_id();
4524 encoding_data_type = Type::eEncodingIsUID;
4525 encoding_uid = LLDB_INVALID_UID;
4526 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00004527
Greg Claytonc7f03b62012-01-12 04:33:28 +00004528 }
4529 else if (type_name_const_str == g_objc_type_name_Class)
4530 {
4531 if (log)
4532 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4533 die->GetOffset(),
4534 DW_TAG_value_to_name(die->Tag()),
4535 die->GetName(this, dwarf_cu));
4536 clang_type = ast.GetBuiltInType_objc_Class();
4537 encoding_data_type = Type::eEncodingIsUID;
4538 encoding_uid = LLDB_INVALID_UID;
4539 resolve_state = Type::eResolveStateFull;
4540 }
4541 else if (type_name_const_str == g_objc_type_name_selector)
4542 {
4543 if (log)
4544 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4545 die->GetOffset(),
4546 DW_TAG_value_to_name(die->Tag()),
4547 die->GetName(this, dwarf_cu));
4548 clang_type = ast.GetBuiltInType_objc_selector();
4549 encoding_data_type = Type::eEncodingIsUID;
4550 encoding_uid = LLDB_INVALID_UID;
4551 resolve_state = Type::eResolveStateFull;
4552 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004553 }
4554 }
4555
Greg Clayton81c22f62011-10-19 18:09:39 +00004556 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004557 this,
4558 type_name_const_str,
4559 byte_size,
4560 NULL,
4561 encoding_uid,
4562 encoding_data_type,
4563 &decl,
4564 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004565 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004566
Greg Clayton594e5ed2010-09-27 21:07:38 +00004567 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004568
4569// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4570// if (encoding_type != NULL)
4571// {
4572// if (encoding_type != DIE_IS_BEING_PARSED)
4573// type_sp->SetEncodingType(encoding_type);
4574// else
4575// m_indirect_fixups.push_back(type_sp.get());
4576// }
4577 }
4578 break;
4579
4580 case DW_TAG_structure_type:
4581 case DW_TAG_union_type:
4582 case DW_TAG_class_type:
4583 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004584 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004585 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004586
Greg Clayton9e409562010-07-28 02:04:09 +00004587 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004588 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004589 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004590 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004591 if (num_attributes > 0)
4592 {
4593 uint32_t i;
4594 for (i=0; i<num_attributes; ++i)
4595 {
4596 attr = attributes.AttributeAtIndex(i);
4597 DWARFFormValue form_value;
4598 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4599 {
4600 switch (attr)
4601 {
Greg Clayton9e409562010-07-28 02:04:09 +00004602 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00004603 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4604 {
4605 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4606 // point to the compile unit file, so we clear this invalid value
4607 // so that we can still unique types efficiently.
4608 decl.SetFile(FileSpec ("<invalid>", false));
4609 }
4610 else
4611 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00004612 break;
4613
4614 case DW_AT_decl_line:
4615 decl.SetLine(form_value.Unsigned());
4616 break;
4617
4618 case DW_AT_decl_column:
4619 decl.SetColumn(form_value.Unsigned());
4620 break;
4621
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004622 case DW_AT_name:
4623 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004624 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004625 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004626
4627 case DW_AT_byte_size:
4628 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004629 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004630 break;
4631
4632 case DW_AT_accessibility:
4633 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4634 break;
4635
4636 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004637 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004638 break;
4639
4640 case DW_AT_APPLE_runtime_class:
4641 class_language = (LanguageType)form_value.Signed();
4642 break;
4643
Greg Clayton18774842011-11-29 23:40:34 +00004644 case DW_AT_APPLE_objc_complete_type:
4645 is_complete_objc_class = form_value.Signed();
4646 break;
4647
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004648 case DW_AT_allocated:
4649 case DW_AT_associated:
4650 case DW_AT_data_location:
4651 case DW_AT_description:
4652 case DW_AT_start_scope:
4653 case DW_AT_visibility:
4654 default:
4655 case DW_AT_sibling:
4656 break;
4657 }
4658 }
4659 }
4660 }
4661
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004662 UniqueDWARFASTType unique_ast_entry;
Sean Callanan8e8072d2012-02-07 21:13:38 +00004663
4664 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
4665 this,
4666 dwarf_cu,
4667 die,
4668 decl,
4669 byte_size_valid ? byte_size : -1,
4670 unique_ast_entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004671 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004672 // We have already parsed this type or from another
4673 // compile unit. GCC loves to use the "one definition
4674 // rule" which can result in multiple definitions
4675 // of the same class over and over in each compile
4676 // unit.
4677 type_sp = unique_ast_entry.m_type_sp;
4678 if (type_sp)
Greg Claytonc615ce42010-11-09 04:42:43 +00004679 {
Sean Callanan8e8072d2012-02-07 21:13:38 +00004680 m_die_to_type[die] = type_sp.get();
4681 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004682 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004683 }
4684
Greg Clayton81c22f62011-10-19 18:09:39 +00004685 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 +00004686
4687 int tag_decl_kind = -1;
4688 AccessType default_accessibility = eAccessNone;
4689 if (tag == DW_TAG_structure_type)
4690 {
4691 tag_decl_kind = clang::TTK_Struct;
4692 default_accessibility = eAccessPublic;
4693 }
4694 else if (tag == DW_TAG_union_type)
4695 {
4696 tag_decl_kind = clang::TTK_Union;
4697 default_accessibility = eAccessPublic;
4698 }
4699 else if (tag == DW_TAG_class_type)
4700 {
4701 tag_decl_kind = clang::TTK_Class;
4702 default_accessibility = eAccessPrivate;
4703 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00004704
4705 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4706 die->HasChildren() == false &&
4707 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4708 {
4709 // Work around an issue with clang at the moment where
4710 // forward declarations for objective C classes are emitted
4711 // as:
4712 // DW_TAG_structure_type [2]
4713 // DW_AT_name( "ForwardObjcClass" )
4714 // DW_AT_byte_size( 0x00 )
4715 // DW_AT_decl_file( "..." )
4716 // DW_AT_decl_line( 1 )
4717 //
4718 // Note that there is no DW_AT_declaration and there are
4719 // no children, and the byte size is zero.
4720 is_forward_declaration = true;
4721 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004722
Greg Clayton18774842011-11-29 23:40:34 +00004723 if (class_language == eLanguageTypeObjC)
4724 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004725 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004726 {
4727 // We have a valid eSymbolTypeObjCClass class symbol whose
4728 // name matches the current objective C class that we
4729 // are trying to find and this DIE isn't the complete
4730 // definition (we checked is_complete_objc_class above and
4731 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00004732 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004733
Greg Clayton901c5ca2011-12-03 04:40:03 +00004734 if (!type_sp && m_debug_map_symfile)
4735 {
4736 // We weren't able to find a full declaration in
4737 // this DWARF, see if we have a declaration anywhere
4738 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00004739 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004740 }
4741
4742 if (type_sp)
4743 {
4744 if (log)
4745 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004746 GetObjectFile()->GetModule()->LogMessage (log.get(),
4747 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4748 this,
4749 die->GetOffset(),
4750 DW_TAG_value_to_name(tag),
4751 type_name_cstr,
4752 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004753 }
4754
4755 // We found a real definition for this type elsewhere
4756 // so lets use it and cache the fact that we found
4757 // a complete type for this die
4758 m_die_to_type[die] = type_sp.get();
4759 return type_sp;
4760 }
4761 }
4762 }
4763
4764
4765 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004766 {
4767 // We have a forward declaration to a type and we need
4768 // to try and find a full declaration. We look in the
4769 // current type index just in case we have a forward
4770 // declaration followed by an actual declarations in the
4771 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00004772 if (log)
4773 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004774 GetObjectFile()->GetModule()->LogMessage (log.get(),
4775 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
4776 this,
4777 die->GetOffset(),
4778 DW_TAG_value_to_name(tag),
4779 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00004780 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004781
4782 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4783
4784 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004785 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004786 // We weren't able to find a full declaration in
4787 // this DWARF, see if we have a declaration anywhere
4788 // else...
4789 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004790 }
4791
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004792 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004793 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00004794 if (log)
4795 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004796 GetObjectFile()->GetModule()->LogMessage (log.get(),
4797 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
4798 this,
4799 die->GetOffset(),
4800 DW_TAG_value_to_name(tag),
4801 type_name_cstr,
4802 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00004803 }
4804
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004805 // We found a real definition for this type elsewhere
4806 // so lets use it and cache the fact that we found
4807 // a complete type for this die
4808 m_die_to_type[die] = type_sp.get();
4809 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004810 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004811 }
4812 assert (tag_decl_kind != -1);
4813 bool clang_type_was_created = false;
4814 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4815 if (clang_type == NULL)
4816 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004817 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton55561e92011-10-26 03:31:36 +00004818 if (accessibility == eAccessNone && decl_ctx)
4819 {
4820 // Check the decl context that contains this class/struct/union.
4821 // If it is a class we must give it an accessability.
4822 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4823 if (DeclKindIsCXXClass (containing_decl_kind))
4824 accessibility = default_accessibility;
4825 }
4826
Greg Claytonf0705c82011-10-22 03:33:13 +00004827 if (type_name_cstr && strchr (type_name_cstr, '<'))
4828 {
4829 ClangASTContext::TemplateParameterInfos template_param_infos;
4830 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4831 {
4832 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004833 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004834 type_name_cstr,
4835 tag_decl_kind,
4836 template_param_infos);
4837
4838 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4839 class_template_decl,
4840 tag_decl_kind,
4841 template_param_infos);
4842 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4843 clang_type_was_created = true;
4844 }
4845 }
4846
4847 if (!clang_type_was_created)
4848 {
4849 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004850 clang_type = ast.CreateRecordType (decl_ctx,
4851 accessibility,
4852 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004853 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004854 class_language);
4855 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004856 }
4857
4858 // Store a forward declaration to this class type in case any
4859 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004860 // types for function prototypes.
4861 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004862 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004863 this,
4864 type_name_const_str,
4865 byte_size,
4866 NULL,
4867 LLDB_INVALID_UID,
4868 Type::eEncodingIsUID,
4869 &decl,
4870 clang_type,
4871 Type::eResolveStateForward));
4872
4873
4874 // Add our type to the unique type map so we don't
4875 // end up creating many copies of the same type over
4876 // and over in the ASTContext for our module
4877 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004878 unique_ast_entry.m_symfile = this;
4879 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004880 unique_ast_entry.m_die = die;
4881 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00004882 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4883 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004884
Sean Callanan12014a02011-12-08 23:45:45 +00004885 if (!is_forward_declaration)
4886 {
4887 if (die->HasChildren() == false)
4888 {
4889 // No children for this struct/union/class, lets finish it
4890 ast.StartTagDeclarationDefinition (clang_type);
4891 ast.CompleteTagDeclarationDefinition (clang_type);
4892 }
4893 else if (clang_type_was_created)
4894 {
4895 // Leave this as a forward declaration until we need
4896 // to know the details of the type. lldb_private::Type
4897 // will automatically call the SymbolFile virtual function
4898 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
4899 // When the definition needs to be defined.
4900 m_forward_decl_die_to_clang_type[die] = clang_type;
4901 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
4902 ClangASTContext::SetHasExternalStorage (clang_type, true);
4903 }
Greg Claytonc615ce42010-11-09 04:42:43 +00004904 }
Greg Claytoncab36a32011-12-08 05:16:30 +00004905
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004906 }
4907 break;
4908
4909 case DW_TAG_enumeration_type:
4910 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004911 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004912 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004913
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004914 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004915
Greg Claytond88d7592010-09-15 08:33:30 +00004916 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004917 if (num_attributes > 0)
4918 {
4919 uint32_t i;
4920
4921 for (i=0; i<num_attributes; ++i)
4922 {
4923 attr = attributes.AttributeAtIndex(i);
4924 DWARFFormValue form_value;
4925 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4926 {
4927 switch (attr)
4928 {
Greg Clayton7a345282010-11-09 23:46:37 +00004929 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4930 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4931 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004932 case DW_AT_name:
4933 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004934 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004935 break;
Greg Clayton7a345282010-11-09 23:46:37 +00004936 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004937 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00004938 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4939 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004940 case DW_AT_allocated:
4941 case DW_AT_associated:
4942 case DW_AT_bit_stride:
4943 case DW_AT_byte_stride:
4944 case DW_AT_data_location:
4945 case DW_AT_description:
4946 case DW_AT_start_scope:
4947 case DW_AT_visibility:
4948 case DW_AT_specification:
4949 case DW_AT_abstract_origin:
4950 case DW_AT_sibling:
4951 break;
4952 }
4953 }
4954 }
4955
Greg Clayton81c22f62011-10-19 18:09:39 +00004956 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 +00004957
Greg Clayton1be10fc2010-09-29 01:12:09 +00004958 clang_type_t enumerator_clang_type = NULL;
4959 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4960 if (clang_type == NULL)
4961 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004962 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
4963 DW_ATE_signed,
4964 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00004965 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00004966 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00004967 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004968 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004969 }
4970 else
4971 {
4972 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
4973 assert (enumerator_clang_type != NULL);
4974 }
4975
Greg Claytona2721472011-06-25 00:44:06 +00004976 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
4977
Greg Clayton81c22f62011-10-19 18:09:39 +00004978 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004979 this,
4980 type_name_const_str,
4981 byte_size,
4982 NULL,
4983 encoding_uid,
4984 Type::eEncodingIsUID,
4985 &decl,
4986 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004987 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004988
Greg Clayton6beaaa62011-01-17 03:46:26 +00004989 ast.StartTagDeclarationDefinition (clang_type);
4990 if (die->HasChildren())
4991 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004992 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
4993 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00004994 }
4995 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004996 }
4997 }
4998 break;
4999
Jim Inghamb0be4422010-08-12 01:20:14 +00005000 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005001 case DW_TAG_subprogram:
5002 case DW_TAG_subroutine_type:
5003 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005004 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005005 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005006
5007 const char *mangled = NULL;
5008 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005009 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005010 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005011 bool is_static = false;
5012 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005013 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005014 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005015 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5016 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005017
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005018 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005019 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005020
5021
Greg Claytond88d7592010-09-15 08:33:30 +00005022 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005023 if (num_attributes > 0)
5024 {
5025 uint32_t i;
5026 for (i=0; i<num_attributes; ++i)
5027 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005028 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005029 DWARFFormValue form_value;
5030 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5031 {
5032 switch (attr)
5033 {
5034 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5035 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5036 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5037 case DW_AT_name:
5038 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005039 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005040 break;
5041
5042 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5043 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005044 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005045 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005046 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5047 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005048 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005049 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5050
Greg Claytonf51de672010-10-01 02:31:07 +00005051
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005052 case DW_AT_external:
5053 if (form_value.Unsigned())
5054 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005055 if (storage == clang::SC_None)
5056 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005057 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005058 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005059 }
5060 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005061
Greg Clayton72da3972011-08-16 18:40:23 +00005062 case DW_AT_specification:
5063 specification_die_offset = form_value.Reference(dwarf_cu);
5064 break;
5065
5066 case DW_AT_abstract_origin:
5067 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5068 break;
5069
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005070 case DW_AT_allocated:
5071 case DW_AT_associated:
5072 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005073 case DW_AT_calling_convention:
5074 case DW_AT_data_location:
5075 case DW_AT_elemental:
5076 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005077 case DW_AT_frame_base:
5078 case DW_AT_high_pc:
5079 case DW_AT_low_pc:
5080 case DW_AT_object_pointer:
5081 case DW_AT_prototyped:
5082 case DW_AT_pure:
5083 case DW_AT_ranges:
5084 case DW_AT_recursive:
5085 case DW_AT_return_addr:
5086 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005087 case DW_AT_start_scope:
5088 case DW_AT_static_link:
5089 case DW_AT_trampoline:
5090 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005091 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005092 case DW_AT_description:
5093 case DW_AT_sibling:
5094 break;
5095 }
5096 }
5097 }
Greg Clayton24739922010-10-13 03:15:28 +00005098 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005099
Greg Clayton81c22f62011-10-19 18:09:39 +00005100 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 +00005101
Greg Clayton24739922010-10-13 03:15:28 +00005102 clang_type_t return_clang_type = NULL;
5103 Type *func_type = NULL;
5104
5105 if (type_die_offset != DW_INVALID_OFFSET)
5106 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005107
Greg Clayton24739922010-10-13 03:15:28 +00005108 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005109 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005110 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005111 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005112
Greg Claytonf51de672010-10-01 02:31:07 +00005113
Greg Clayton24739922010-10-13 03:15:28 +00005114 std::vector<clang_type_t> function_param_types;
5115 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005116
Greg Clayton24739922010-10-13 03:15:28 +00005117 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005118
Greg Claytoncb5860a2011-10-13 23:49:28 +00005119 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5120 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005121 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5122
Greg Claytonf0705c82011-10-22 03:33:13 +00005123 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005124 // Start off static. This will be set to false in ParseChildParameters(...)
5125 // if we find a "this" paramters as the first parameter
5126 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005127 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005128 ClangASTContext::TemplateParameterInfos template_param_infos;
5129
Greg Clayton24739922010-10-13 03:15:28 +00005130 if (die->HasChildren())
5131 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005132 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005133 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005134 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005135 dwarf_cu,
5136 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005137 skip_artificial,
5138 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005139 type_list,
5140 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005141 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005142 type_quals,
5143 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005144 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005145
Greg Clayton24739922010-10-13 03:15:28 +00005146 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005147 clang_type = ast.CreateFunctionType (return_clang_type,
5148 &function_param_types[0],
5149 function_param_types.size(),
5150 is_variadic,
5151 type_quals);
5152
Greg Clayton24739922010-10-13 03:15:28 +00005153 if (type_name_cstr)
5154 {
5155 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005156 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005157 {
Greg Clayton7c810422012-01-18 23:40:49 +00005158 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005159 ConstString class_name_no_category;
5160 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005161 {
Greg Claytone42ae842012-01-19 03:24:53 +00005162 // Use the class name with no category if there is one
5163 if (class_name_no_category)
5164 class_name = class_name_no_category;
5165
Greg Clayton24739922010-10-13 03:15:28 +00005166 SymbolContext empty_sc;
5167 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005168 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005169 {
Greg Clayton24739922010-10-13 03:15:28 +00005170 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005171 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005172
5173 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005174 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005175 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5176 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5177 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005178 }
Greg Clayton24739922010-10-13 03:15:28 +00005179 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005180
Greg Clayton24739922010-10-13 03:15:28 +00005181 if (class_opaque_type)
5182 {
5183 // If accessibility isn't set to anything valid, assume public for
5184 // now...
5185 if (accessibility == eAccessNone)
5186 accessibility = eAccessPublic;
5187
5188 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005189 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5190 type_name_cstr,
5191 clang_type,
5192 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005193 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005194 type_handled = objc_method_decl != NULL;
5195 }
5196 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005197 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005198 {
5199 // Look at the parent of this DIE and see if is is
5200 // a class or struct and see if this is actually a
5201 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005202 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005203 if (class_type)
5204 {
Greg Clayton72da3972011-08-16 18:40:23 +00005205 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005206 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005207 // We have a specification which we are going to base our function
5208 // prototype off of, so we need this type to be completed so that the
5209 // m_die_to_decl_ctx for the method in the specification has a valid
5210 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005211 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005212 // If we have a specification, then the function type should have been
5213 // made with the specification and not with this die.
5214 DWARFCompileUnitSP spec_cu_sp;
5215 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005216 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
5217 if (spec_clang_decl_ctx)
5218 {
5219 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5220 }
5221 else
Jim Inghamc1663042011-09-29 22:12:35 +00005222 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005223 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5224 MakeUserID(die->GetOffset()),
5225 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005226 }
Greg Clayton72da3972011-08-16 18:40:23 +00005227 type_handled = true;
5228 }
5229 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5230 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005231 // We have a specification which we are going to base our function
5232 // prototype off of, so we need this type to be completed so that the
5233 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5234 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005235 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005236
Greg Clayton72da3972011-08-16 18:40:23 +00005237 DWARFCompileUnitSP abs_cu_sp;
5238 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005239 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
5240 if (abs_clang_decl_ctx)
5241 {
5242 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5243 }
5244 else
Jim Inghamc1663042011-09-29 22:12:35 +00005245 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005246 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5247 MakeUserID(die->GetOffset()),
5248 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005249 }
Greg Clayton72da3972011-08-16 18:40:23 +00005250 type_handled = true;
5251 }
5252 else
5253 {
5254 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5255 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005256 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005257 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005258 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005259 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5260 // in the DWARF for C++ methods... Default to public for now...
5261 if (accessibility == eAccessNone)
5262 accessibility = eAccessPublic;
5263
5264 if (!is_static && !die->HasChildren())
5265 {
5266 // We have a C++ member function with no children (this pointer!)
5267 // and clang will get mad if we try and make a function that isn't
5268 // well formed in the DWARF, so we will just skip it...
5269 type_handled = true;
5270 }
5271 else
5272 {
5273 clang::CXXMethodDecl *cxx_method_decl;
5274 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005275 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 +00005276 type_name_cstr,
5277 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005278 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005279 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5280 m_obj_file->GetFileSpec().GetFilename().GetCString());
5281
Sean Callananc1b732d2011-11-01 18:07:13 +00005282 const bool is_attr_used = false;
5283
Greg Clayton20568dd2011-10-13 23:13:20 +00005284 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5285 type_name_cstr,
5286 clang_type,
5287 accessibility,
5288 is_virtual,
5289 is_static,
5290 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005291 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005292 is_attr_used,
5293 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005294 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5295
Greg Claytonf49e65a2011-11-10 18:31:53 +00005296 Host::SetCrashDescription (NULL);
5297
Greg Clayton20568dd2011-10-13 23:13:20 +00005298 type_handled = cxx_method_decl != NULL;
5299 }
Greg Clayton72da3972011-08-16 18:40:23 +00005300 }
5301 else
5302 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005303 // We were asked to parse the type for a method in a class, yet the
5304 // class hasn't been asked to complete itself through the
5305 // clang::ExternalASTSource protocol, so we need to just have the
5306 // class complete itself and do things the right way, then our
5307 // DIE should then have an entry in the m_die_to_type map. First
5308 // we need to modify the m_die_to_type so it doesn't think we are
5309 // trying to parse this DIE anymore...
5310 m_die_to_type[die] = NULL;
5311
5312 // Now we get the full type to force our class type to complete itself
5313 // using the clang::ExternalASTSource protocol which will parse all
5314 // base classes and all methods (including the method for this DIE).
5315 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005316
Greg Clayton20568dd2011-10-13 23:13:20 +00005317 // The type for this DIE should have been filled in the function call above
5318 type_ptr = m_die_to_type[die];
5319 if (type_ptr)
5320 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005321 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00005322 break;
5323 }
Greg Clayton72da3972011-08-16 18:40:23 +00005324 }
Greg Clayton931180e2011-01-27 06:44:37 +00005325 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005326 }
5327 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005328 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005329 }
Greg Clayton24739922010-10-13 03:15:28 +00005330
5331 if (!type_handled)
5332 {
5333 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00005334 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5335 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005336 clang_type,
5337 storage,
5338 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005339
5340// if (template_param_infos.GetSize() > 0)
5341// {
5342// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5343// function_decl,
5344// type_name_cstr,
5345// template_param_infos);
5346//
5347// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5348// func_template_decl,
5349// template_param_infos);
5350// }
Greg Clayton24739922010-10-13 03:15:28 +00005351 // Add the decl to our DIE to decl context map
5352 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00005353 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00005354 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005355 ast.SetFunctionParameters (function_decl,
5356 &function_param_decls.front(),
5357 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00005358 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005359 }
Greg Clayton81c22f62011-10-19 18:09:39 +00005360 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005361 this,
5362 type_name_const_str,
5363 0,
5364 NULL,
5365 LLDB_INVALID_UID,
5366 Type::eEncodingIsUID,
5367 &decl,
5368 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005369 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00005370 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005371 }
5372 break;
5373
5374 case DW_TAG_array_type:
5375 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005376 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005377 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005378
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005379 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005380 int64_t first_index = 0;
5381 uint32_t byte_stride = 0;
5382 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00005383 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005384
5385 if (num_attributes > 0)
5386 {
5387 uint32_t i;
5388 for (i=0; i<num_attributes; ++i)
5389 {
5390 attr = attributes.AttributeAtIndex(i);
5391 DWARFFormValue form_value;
5392 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5393 {
5394 switch (attr)
5395 {
5396 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5397 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5398 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5399 case DW_AT_name:
5400 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005401 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005402 break;
5403
5404 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005405 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005406 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5407 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005408 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005409 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005410 case DW_AT_allocated:
5411 case DW_AT_associated:
5412 case DW_AT_data_location:
5413 case DW_AT_description:
5414 case DW_AT_ordering:
5415 case DW_AT_start_scope:
5416 case DW_AT_visibility:
5417 case DW_AT_specification:
5418 case DW_AT_abstract_origin:
5419 case DW_AT_sibling:
5420 break;
5421 }
5422 }
5423 }
5424
Greg Clayton81c22f62011-10-19 18:09:39 +00005425 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 +00005426
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005427 Type *element_type = ResolveTypeUID(type_die_offset);
5428
5429 if (element_type)
5430 {
5431 std::vector<uint64_t> element_orders;
5432 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005433 // We have an array that claims to have no members, lets give it at least one member...
5434 if (element_orders.empty())
5435 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005436 if (byte_stride == 0 && bit_stride == 0)
5437 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00005438 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005439 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5440 uint64_t num_elements = 0;
5441 std::vector<uint64_t>::const_reverse_iterator pos;
5442 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5443 for (pos = element_orders.rbegin(); pos != end; ++pos)
5444 {
5445 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005446 clang_type = ast.CreateArrayType (array_element_type,
5447 num_elements,
5448 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005449 array_element_type = clang_type;
5450 array_element_bit_stride = array_element_bit_stride * num_elements;
5451 }
5452 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005453 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005454 this,
5455 empty_name,
5456 array_element_bit_stride / 8,
5457 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005458 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005459 Type::eEncodingIsUID,
5460 &decl,
5461 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005462 Type::eResolveStateFull));
5463 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005464 }
5465 }
5466 }
5467 break;
5468
Greg Clayton9b81a312010-06-12 01:20:30 +00005469 case DW_TAG_ptr_to_member_type:
5470 {
5471 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5472 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5473
Greg Claytond88d7592010-09-15 08:33:30 +00005474 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005475
5476 if (num_attributes > 0) {
5477 uint32_t i;
5478 for (i=0; i<num_attributes; ++i)
5479 {
5480 attr = attributes.AttributeAtIndex(i);
5481 DWARFFormValue form_value;
5482 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5483 {
5484 switch (attr)
5485 {
5486 case DW_AT_type:
5487 type_die_offset = form_value.Reference(dwarf_cu); break;
5488 case DW_AT_containing_type:
5489 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5490 }
5491 }
5492 }
5493
5494 Type *pointee_type = ResolveTypeUID(type_die_offset);
5495 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5496
Greg Clayton526e5af2010-11-13 03:52:47 +00005497 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5498 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005499
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005500 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5501 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005502
Greg Clayton526e5af2010-11-13 03:52:47 +00005503 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5504 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005505
Greg Clayton81c22f62011-10-19 18:09:39 +00005506 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005507 this,
5508 type_name_const_str,
5509 byte_size,
5510 NULL,
5511 LLDB_INVALID_UID,
5512 Type::eEncodingIsUID,
5513 NULL,
5514 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005515 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005516 }
5517
5518 break;
5519 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005520 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005521 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005522 break;
5523 }
5524
5525 if (type_sp.get())
5526 {
5527 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5528 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5529
5530 SymbolContextScope * symbol_context_scope = NULL;
5531 if (sc_parent_tag == DW_TAG_compile_unit)
5532 {
5533 symbol_context_scope = sc.comp_unit;
5534 }
5535 else if (sc.function != NULL)
5536 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005537 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005538 if (symbol_context_scope == NULL)
5539 symbol_context_scope = sc.function;
5540 }
5541
5542 if (symbol_context_scope != NULL)
5543 {
5544 type_sp->SetSymbolContextScope(symbol_context_scope);
5545 }
5546
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005547 // We are ready to put this type into the uniqued list up at the module level
5548 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005549
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005550 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005551 }
5552 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005553 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005554 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005555 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005556 }
5557 }
5558 return type_sp;
5559}
5560
5561size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005562SymbolFileDWARF::ParseTypes
5563(
5564 const SymbolContext& sc,
5565 DWARFCompileUnit* dwarf_cu,
5566 const DWARFDebugInfoEntry *die,
5567 bool parse_siblings,
5568 bool parse_children
5569)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005570{
5571 size_t types_added = 0;
5572 while (die != NULL)
5573 {
5574 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005575 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005576 {
5577 if (type_is_new)
5578 ++types_added;
5579 }
5580
5581 if (parse_children && die->HasChildren())
5582 {
5583 if (die->Tag() == DW_TAG_subprogram)
5584 {
5585 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005586 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005587 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5588 }
5589 else
5590 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5591 }
5592
5593 if (parse_siblings)
5594 die = die->GetSibling();
5595 else
5596 die = NULL;
5597 }
5598 return types_added;
5599}
5600
5601
5602size_t
5603SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5604{
5605 assert(sc.comp_unit && sc.function);
5606 size_t functions_added = 0;
5607 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5608 if (dwarf_cu)
5609 {
5610 dw_offset_t function_die_offset = sc.function->GetID();
5611 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5612 if (function_die)
5613 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005614 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005615 }
5616 }
5617
5618 return functions_added;
5619}
5620
5621
5622size_t
5623SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5624{
5625 // At least a compile unit must be valid
5626 assert(sc.comp_unit);
5627 size_t types_added = 0;
5628 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5629 if (dwarf_cu)
5630 {
5631 if (sc.function)
5632 {
5633 dw_offset_t function_die_offset = sc.function->GetID();
5634 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5635 if (func_die && func_die->HasChildren())
5636 {
5637 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5638 }
5639 }
5640 else
5641 {
5642 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5643 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5644 {
5645 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5646 }
5647 }
5648 }
5649
5650 return types_added;
5651}
5652
5653size_t
5654SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5655{
5656 if (sc.comp_unit != NULL)
5657 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005658 DWARFDebugInfo* info = DebugInfo();
5659 if (info == NULL)
5660 return 0;
5661
5662 uint32_t cu_idx = UINT32_MAX;
5663 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005664
5665 if (dwarf_cu == NULL)
5666 return 0;
5667
5668 if (sc.function)
5669 {
5670 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00005671
5672 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 +00005673 if (func_lo_pc != DW_INVALID_ADDRESS)
5674 {
5675 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00005676
Greg Claytone38a5ed2012-01-05 03:57:59 +00005677 // Let all blocks know they have parse all their variables
5678 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5679 return num_variables;
5680 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005681 }
5682 else if (sc.comp_unit)
5683 {
5684 uint32_t vars_added = 0;
5685 VariableListSP variables (sc.comp_unit->GetVariableList(false));
5686
5687 if (variables.get() == NULL)
5688 {
5689 variables.reset(new VariableList());
5690 sc.comp_unit->SetVariableList(variables);
5691
Greg Claytond4a2b372011-09-12 23:21:58 +00005692 DWARFCompileUnit* match_dwarf_cu = NULL;
5693 const DWARFDebugInfoEntry* die = NULL;
5694 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00005695 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005696 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005697 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00005698 {
5699 DWARFMappedHash::DIEInfoArray hash_data_array;
5700 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5701 dwarf_cu->GetNextCompileUnitOffset(),
5702 hash_data_array))
5703 {
5704 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
5705 }
5706 }
Greg Clayton7f995132011-10-04 22:41:51 +00005707 }
5708 else
5709 {
5710 // Index if we already haven't to make sure the compile units
5711 // get indexed and make their global DIE index list
5712 if (!m_indexed)
5713 Index ();
5714
5715 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5716 dwarf_cu->GetNextCompileUnitOffset(),
5717 die_offsets);
5718 }
5719
5720 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00005721 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005722 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005723 DWARFDebugInfo* debug_info = DebugInfo();
5724 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005725 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005726 const dw_offset_t die_offset = die_offsets[i];
5727 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00005728 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00005729 {
Greg Clayton95d87902011-11-11 03:16:25 +00005730 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5731 if (var_sp)
5732 {
5733 variables->AddVariableIfUnique (var_sp);
5734 ++vars_added;
5735 }
Greg Claytond4a2b372011-09-12 23:21:58 +00005736 }
Greg Clayton95d87902011-11-11 03:16:25 +00005737 else
5738 {
5739 if (m_using_apple_tables)
5740 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005741 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 +00005742 }
5743 }
5744
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005745 }
5746 }
5747 }
5748 return vars_added;
5749 }
5750 }
5751 return 0;
5752}
5753
5754
5755VariableSP
5756SymbolFileDWARF::ParseVariableDIE
5757(
5758 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005759 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005760 const DWARFDebugInfoEntry *die,
5761 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005762)
5763{
5764
Greg Clayton83c5cd92010-11-14 22:13:40 +00005765 VariableSP var_sp (m_die_to_variable_sp[die]);
5766 if (var_sp)
5767 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005768
5769 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00005770
5771 if ((tag == DW_TAG_variable) ||
5772 (tag == DW_TAG_constant) ||
5773 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005774 {
Greg Clayton7f995132011-10-04 22:41:51 +00005775 DWARFDebugInfoEntry::Attributes attributes;
5776 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5777 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005778 {
Greg Clayton7f995132011-10-04 22:41:51 +00005779 const char *name = NULL;
5780 const char *mangled = NULL;
5781 Declaration decl;
5782 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00005783 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00005784 DWARFExpression location;
5785 bool is_external = false;
5786 bool is_artificial = false;
5787 bool location_is_const_value_data = false;
5788 AccessType accessibility = eAccessNone;
5789
5790 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005791 {
Greg Clayton7f995132011-10-04 22:41:51 +00005792 dw_attr_t attr = attributes.AttributeAtIndex(i);
5793 DWARFFormValue form_value;
5794 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005795 {
Greg Clayton7f995132011-10-04 22:41:51 +00005796 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005797 {
Greg Clayton7f995132011-10-04 22:41:51 +00005798 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5799 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5800 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5801 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
5802 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00005803 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00005804 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5805 case DW_AT_const_value:
5806 location_is_const_value_data = true;
5807 // Fall through...
5808 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005809 {
Greg Clayton7f995132011-10-04 22:41:51 +00005810 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005811 {
Greg Clayton7f995132011-10-04 22:41:51 +00005812 const DataExtractor& debug_info_data = get_debug_info_data();
5813
5814 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5815 uint32_t block_length = form_value.Unsigned();
5816 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5817 }
5818 else
5819 {
5820 const DataExtractor& debug_loc_data = get_debug_loc_data();
5821 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5822
5823 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5824 if (loc_list_length > 0)
5825 {
5826 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5827 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5828 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5829 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005830 }
5831 }
Greg Clayton7f995132011-10-04 22:41:51 +00005832 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005833
Greg Clayton7f995132011-10-04 22:41:51 +00005834 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5835 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5836 case DW_AT_declaration:
5837 case DW_AT_description:
5838 case DW_AT_endianity:
5839 case DW_AT_segment:
5840 case DW_AT_start_scope:
5841 case DW_AT_visibility:
5842 default:
5843 case DW_AT_abstract_origin:
5844 case DW_AT_sibling:
5845 case DW_AT_specification:
5846 break;
5847 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005848 }
5849 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005850
Greg Clayton7f995132011-10-04 22:41:51 +00005851 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005852 {
Greg Clayton7f995132011-10-04 22:41:51 +00005853 ValueType scope = eValueTypeInvalid;
5854
5855 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5856 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005857 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00005858
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005859 // DWARF doesn't specify if a DW_TAG_variable is a local, global
5860 // or static variable, so we have to do a little digging by
5861 // looking at the location of a varaible to see if it contains
5862 // a DW_OP_addr opcode _somewhere_ in the definition. I say
5863 // somewhere because clang likes to combine small global variables
5864 // into the same symbol and have locations like:
5865 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
5866 // So if we don't have a DW_TAG_formal_parameter, we can look at
5867 // the location to see if it contains a DW_OP_addr opcode, and
5868 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00005869 if (tag == DW_TAG_formal_parameter)
5870 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00005871 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005872 {
Greg Clayton96c09682012-01-04 22:56:43 +00005873 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00005874 // Check if the location has a DW_OP_addr with any address value...
5875 addr_t location_has_op_addr = false;
5876 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00005877 {
5878 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
5879 if (op_error)
5880 {
5881 StreamString strm;
5882 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005883 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 +00005884 }
5885 }
Greg Claytond1767f02011-12-08 02:13:16 +00005886
5887 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005888 {
Greg Claytond1767f02011-12-08 02:13:16 +00005889 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005890 {
Greg Claytond1767f02011-12-08 02:13:16 +00005891 scope = eValueTypeVariableGlobal;
5892
5893 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005894 {
Greg Claytond1767f02011-12-08 02:13:16 +00005895 // When leaving the DWARF in the .o files on darwin,
5896 // when we have a global variable that wasn't initialized,
5897 // the .o file might not have allocated a virtual
5898 // address for the global variable. In this case it will
5899 // have created a symbol for the global variable
5900 // that is undefined and external and the value will
5901 // be the byte size of the variable. When we do the
5902 // address map in SymbolFileDWARFDebugMap we rely on
5903 // having an address, we need to do some magic here
5904 // so we can get the correct address for our global
5905 // variable. The address for all of these entries
5906 // will be zero, and there will be an undefined symbol
5907 // in this object file, and the executable will have
5908 // a matching symbol with a good address. So here we
5909 // dig up the correct address and replace it in the
5910 // location for the variable, and set the variable's
5911 // symbol context scope to be that of the main executable
5912 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00005913 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005914 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005915
Greg Claytond1767f02011-12-08 02:13:16 +00005916 // we have a possible uninitialized extern global
5917 Symtab *symtab = m_obj_file->GetSymtab();
5918 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005919 {
Greg Claytond1767f02011-12-08 02:13:16 +00005920 ConstString const_name(name);
5921 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
5922 eSymbolTypeUndefined,
5923 Symtab::eDebugNo,
5924 Symtab::eVisibilityExtern);
5925
5926 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005927 {
Greg Claytond1767f02011-12-08 02:13:16 +00005928 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
5929 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005930 {
Greg Claytond1767f02011-12-08 02:13:16 +00005931 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
5932 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
5933 eSymbolTypeData,
5934 Symtab::eDebugYes,
5935 Symtab::eVisibilityExtern);
5936 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005937 {
Greg Claytond1767f02011-12-08 02:13:16 +00005938 const AddressRange *defined_range = defined_symbol->GetAddressRangePtr();
5939 if (defined_range)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005940 {
Greg Claytond1767f02011-12-08 02:13:16 +00005941 const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress();
5942 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005943 {
Greg Claytond1767f02011-12-08 02:13:16 +00005944 if (location.Update_DW_OP_addr (defined_addr))
5945 {
5946 symbol_context_scope = defined_symbol;
5947 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005948 }
5949 }
5950 }
5951 }
5952 }
5953 }
5954 }
5955 }
5956 }
Greg Claytond1767f02011-12-08 02:13:16 +00005957 else
5958 {
5959 scope = eValueTypeVariableStatic;
5960 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005961 }
5962 else
Greg Claytond1767f02011-12-08 02:13:16 +00005963 {
5964 scope = eValueTypeVariableLocal;
5965 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005966 }
Greg Clayton7f995132011-10-04 22:41:51 +00005967
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005968 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00005969 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005970 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00005971 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005972 case DW_TAG_subprogram:
5973 case DW_TAG_inlined_subroutine:
5974 case DW_TAG_lexical_block:
5975 if (sc.function)
5976 {
5977 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
5978 if (symbol_context_scope == NULL)
5979 symbol_context_scope = sc.function;
5980 }
5981 break;
5982
5983 default:
5984 symbol_context_scope = sc.comp_unit;
5985 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005986 }
Greg Clayton7f995132011-10-04 22:41:51 +00005987 }
5988
Greg Clayton5cf58b92011-10-05 22:22:08 +00005989 if (symbol_context_scope)
5990 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005991 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
5992 name,
5993 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00005994 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00005995 scope,
5996 symbol_context_scope,
5997 &decl,
5998 location,
5999 is_external,
6000 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006001
6002 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6003 }
6004 else
6005 {
6006 // Not ready to parse this variable yet. It might be a global
6007 // or static variable that is in a function scope and the function
6008 // in the symbol context wasn't filled in yet
6009 return var_sp;
6010 }
Greg Clayton7f995132011-10-04 22:41:51 +00006011 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006012 }
Greg Clayton7f995132011-10-04 22:41:51 +00006013 // Cache var_sp even if NULL (the variable was just a specification or
6014 // was missing vital information to be able to be displayed in the debugger
6015 // (missing location due to optimization, etc)) so we don't re-parse
6016 // this DIE over and over later...
6017 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006018 }
6019 return var_sp;
6020}
6021
Greg Claytonc662ec82011-06-17 22:10:16 +00006022
6023const DWARFDebugInfoEntry *
6024SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6025 dw_offset_t spec_block_die_offset,
6026 DWARFCompileUnit **result_die_cu_handle)
6027{
6028 // Give the concrete function die specified by "func_die_offset", find the
6029 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6030 // to "spec_block_die_offset"
6031 DWARFDebugInfo* info = DebugInfo();
6032
6033 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6034 if (die)
6035 {
6036 assert (*result_die_cu_handle);
6037 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6038 }
6039 return NULL;
6040}
6041
6042
6043const DWARFDebugInfoEntry *
6044SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6045 const DWARFDebugInfoEntry *die,
6046 dw_offset_t spec_block_die_offset,
6047 DWARFCompileUnit **result_die_cu_handle)
6048{
6049 if (die)
6050 {
6051 switch (die->Tag())
6052 {
6053 case DW_TAG_subprogram:
6054 case DW_TAG_inlined_subroutine:
6055 case DW_TAG_lexical_block:
6056 {
6057 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6058 {
6059 *result_die_cu_handle = dwarf_cu;
6060 return die;
6061 }
6062
6063 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6064 {
6065 *result_die_cu_handle = dwarf_cu;
6066 return die;
6067 }
6068 }
6069 break;
6070 }
6071
6072 // Give the concrete function die specified by "func_die_offset", find the
6073 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6074 // to "spec_block_die_offset"
6075 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6076 {
6077 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6078 child_die,
6079 spec_block_die_offset,
6080 result_die_cu_handle);
6081 if (result_die)
6082 return result_die;
6083 }
6084 }
6085
6086 *result_die_cu_handle = NULL;
6087 return NULL;
6088}
6089
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006090size_t
6091SymbolFileDWARF::ParseVariables
6092(
6093 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006094 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006095 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006096 const DWARFDebugInfoEntry *orig_die,
6097 bool parse_siblings,
6098 bool parse_children,
6099 VariableList* cc_variable_list
6100)
6101{
6102 if (orig_die == NULL)
6103 return 0;
6104
Greg Claytonc662ec82011-06-17 22:10:16 +00006105 VariableListSP variable_list_sp;
6106
6107 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006108 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006109 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006110 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006111 dw_tag_t tag = die->Tag();
6112
6113 // Check to see if we have already parsed this variable or constant?
6114 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006115 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006116 if (cc_variable_list)
6117 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006118 }
6119 else
6120 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006121 // We haven't already parsed it, lets do that now.
6122 if ((tag == DW_TAG_variable) ||
6123 (tag == DW_TAG_constant) ||
6124 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006125 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006126 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006127 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006128 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6129 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6130 switch (parent_tag)
6131 {
6132 case DW_TAG_compile_unit:
6133 if (sc.comp_unit != NULL)
6134 {
6135 variable_list_sp = sc.comp_unit->GetVariableList(false);
6136 if (variable_list_sp.get() == NULL)
6137 {
6138 variable_list_sp.reset(new VariableList());
6139 sc.comp_unit->SetVariableList(variable_list_sp);
6140 }
6141 }
6142 else
6143 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006144 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6145 MakeUserID(sc_parent_die->GetOffset()),
6146 DW_TAG_value_to_name (parent_tag),
6147 MakeUserID(orig_die->GetOffset()),
6148 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006149 }
6150 break;
6151
6152 case DW_TAG_subprogram:
6153 case DW_TAG_inlined_subroutine:
6154 case DW_TAG_lexical_block:
6155 if (sc.function != NULL)
6156 {
6157 // Check to see if we already have parsed the variables for the given scope
6158
Greg Clayton81c22f62011-10-19 18:09:39 +00006159 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006160 if (block == NULL)
6161 {
6162 // This must be a specification or abstract origin with
6163 // a concrete block couterpart in the current function. We need
6164 // to find the concrete block so we can correctly add the
6165 // variable to it
6166 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6167 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6168 sc_parent_die->GetOffset(),
6169 &concrete_block_die_cu);
6170 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006171 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006172 }
6173
6174 if (block != NULL)
6175 {
6176 const bool can_create = false;
6177 variable_list_sp = block->GetBlockVariableList (can_create);
6178 if (variable_list_sp.get() == NULL)
6179 {
6180 variable_list_sp.reset(new VariableList());
6181 block->SetVariableList(variable_list_sp);
6182 }
6183 }
6184 }
6185 break;
6186
6187 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006188 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6189 MakeUserID(orig_die->GetOffset()),
6190 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006191 break;
6192 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006193 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006194
6195 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006196 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006197 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6198 if (var_sp)
6199 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006200 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006201 if (cc_variable_list)
6202 cc_variable_list->AddVariableIfUnique (var_sp);
6203 ++vars_added;
6204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006205 }
6206 }
6207 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006208
6209 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6210
6211 if (!skip_children && parse_children && die->HasChildren())
6212 {
6213 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6214 }
6215
6216 if (parse_siblings)
6217 die = die->GetSibling();
6218 else
6219 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006220 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006221 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006222}
6223
6224//------------------------------------------------------------------
6225// PluginInterface protocol
6226//------------------------------------------------------------------
6227const char *
6228SymbolFileDWARF::GetPluginName()
6229{
6230 return "SymbolFileDWARF";
6231}
6232
6233const char *
6234SymbolFileDWARF::GetShortPluginName()
6235{
6236 return GetPluginNameStatic();
6237}
6238
6239uint32_t
6240SymbolFileDWARF::GetPluginVersion()
6241{
6242 return 1;
6243}
6244
6245void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006246SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6247{
6248 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6249 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6250 if (clang_type)
6251 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6252}
6253
6254void
6255SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6256{
6257 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6258 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6259 if (clang_type)
6260 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6261}
6262
Greg Claytona2721472011-06-25 00:44:06 +00006263void
Sean Callanancc427fa2011-07-30 02:42:06 +00006264SymbolFileDWARF::DumpIndexes ()
6265{
6266 StreamFile s(stdout, false);
6267
6268 s.Printf ("DWARF index for (%s) '%s/%s':",
6269 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6270 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6271 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6272 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6273 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6274 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6275 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6276 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6277 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6278 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6279 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6280}
6281
6282void
6283SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6284 const char *name,
6285 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006286{
Sean Callanancc427fa2011-07-30 02:42:06 +00006287 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00006288
6289 if (iter == m_decl_ctx_to_die.end())
6290 return;
6291
Greg Claytoncb5860a2011-10-13 23:49:28 +00006292 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00006293 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006294 const DWARFDebugInfoEntry *context_die = *pos;
6295
6296 if (!results)
6297 return;
6298
6299 DWARFDebugInfo* info = DebugInfo();
6300
6301 DIEArray die_offsets;
6302
6303 DWARFCompileUnit* dwarf_cu = NULL;
6304 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00006305
6306 if (m_using_apple_tables)
6307 {
6308 if (m_apple_types_ap.get())
6309 m_apple_types_ap->FindByName (name, die_offsets);
6310 }
6311 else
6312 {
6313 if (!m_indexed)
6314 Index ();
6315
6316 m_type_index.Find (ConstString(name), die_offsets);
6317 }
6318
Greg Clayton220a0072011-12-09 08:48:30 +00006319 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006320
6321 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00006322 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006323 for (size_t i = 0; i < num_matches; ++i)
6324 {
6325 const dw_offset_t die_offset = die_offsets[i];
6326 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00006327
Greg Claytoncb5860a2011-10-13 23:49:28 +00006328 if (die->GetParent() != context_die)
6329 continue;
6330
6331 Type *matching_type = ResolveType (dwarf_cu, die);
6332
Greg Clayton42ce2f32011-12-12 21:50:19 +00006333 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006334 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6335
6336 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6337 {
6338 clang::TagDecl *tag_decl = tag_type->getDecl();
6339 results->push_back(tag_decl);
6340 }
6341 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6342 {
6343 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6344 results->push_back(typedef_decl);
6345 }
Greg Claytona2721472011-06-25 00:44:06 +00006346 }
6347 }
6348 }
6349}
6350
6351void
6352SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00006353 const clang::DeclContext *decl_context,
6354 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00006355 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6356{
Greg Clayton85ae2e12011-10-18 23:36:41 +00006357
6358 switch (decl_context->getDeclKind())
6359 {
6360 case clang::Decl::Namespace:
6361 case clang::Decl::TranslationUnit:
6362 {
6363 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6364 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6365 }
6366 break;
6367 default:
6368 break;
6369 }
Greg Claytona2721472011-06-25 00:44:06 +00006370}
Greg Claytoncaab74e2012-01-28 00:48:57 +00006371
6372bool
6373SymbolFileDWARF::LayoutRecordType (void *baton,
6374 const clang::RecordDecl *record_decl,
6375 uint64_t &size,
6376 uint64_t &alignment,
6377 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6378 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6379 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6380{
6381 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6382 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6383}
6384
6385
6386bool
6387SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6388 uint64_t &bit_size,
6389 uint64_t &alignment,
6390 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6391 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6392 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6393{
6394 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6395 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6396 bool success = false;
6397 base_offsets.clear();
6398 vbase_offsets.clear();
6399 if (pos != m_record_decl_to_layout_map.end())
6400 {
6401 bit_size = pos->second.bit_size;
6402 alignment = pos->second.alignment;
6403 field_offsets.swap(pos->second.field_offsets);
6404 m_record_decl_to_layout_map.erase(pos);
6405 success = true;
6406 }
6407 else
6408 {
6409 bit_size = 0;
6410 alignment = 0;
6411 field_offsets.clear();
6412 }
6413
6414 if (log)
6415 GetObjectFile()->GetModule()->LogMessage (log.get(),
6416 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6417 record_decl,
6418 bit_size,
6419 alignment,
6420 (uint32_t)field_offsets.size(),
6421 (uint32_t)base_offsets.size(),
6422 (uint32_t)vbase_offsets.size(),
6423 success);
6424 return success;
6425}
6426
6427
6428