blob: 428193aa7d210caeb4b7a5849016b58475789cf9 [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
1294 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1295
1296 Args template_parameter_names;
1297 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1298 die != NULL;
1299 die = die->GetSibling())
1300 {
1301 const dw_tag_t tag = die->Tag();
1302
1303 switch (tag)
1304 {
1305 case DW_TAG_template_type_parameter:
1306 case DW_TAG_template_value_parameter:
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00001307 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
Greg Claytonf0705c82011-10-22 03:33:13 +00001308 break;
1309
1310 default:
1311 break;
1312 }
1313 }
1314 if (template_param_infos.args.empty())
1315 return false;
1316 return template_param_infos.args.size() == template_param_infos.names.size();
1317}
1318
1319clang::ClassTemplateDecl *
1320SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001321 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001322 const char *parent_name,
1323 int tag_decl_kind,
1324 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1325{
1326 if (template_param_infos.IsValid())
1327 {
1328 std::string template_basename(parent_name);
1329 template_basename.erase (template_basename.find('<'));
1330 ClangASTContext &ast = GetClangASTContext();
1331
1332 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001333 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001334 template_basename.c_str(),
1335 tag_decl_kind,
1336 template_param_infos);
1337 }
1338 return NULL;
1339}
1340
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341size_t
1342SymbolFileDWARF::ParseChildMembers
1343(
1344 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001345 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001346 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001347 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001348 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1350 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001351 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001352 AccessType& default_accessibility,
Greg Claytoncaab74e2012-01-28 00:48:57 +00001353 bool &is_a_class,
1354 LayoutInfo &layout_info
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355)
1356{
1357 if (parent_die == NULL)
1358 return 0;
1359
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 size_t count = 0;
1361 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001362 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001363 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001364
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001365 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1366 {
1367 dw_tag_t tag = die->Tag();
1368
1369 switch (tag)
1370 {
1371 case DW_TAG_member:
1372 {
1373 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001374 const size_t num_attributes = die->GetAttributes (this,
1375 dwarf_cu,
1376 fixed_form_sizes,
1377 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 if (num_attributes > 0)
1379 {
1380 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001381 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001383 const char *prop_name = NULL;
1384 const char *prop_getter_name = NULL;
1385 const char *prop_setter_name = NULL;
1386 uint32_t prop_attributes = 0;
1387
1388
Greg Clayton24739922010-10-13 03:15:28 +00001389 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001390 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001391 AccessType accessibility = eAccessNone;
Greg Claytoncaab74e2012-01-28 00:48:57 +00001392 uint32_t member_byte_offset = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001393 size_t byte_size = 0;
1394 size_t bit_offset = 0;
1395 size_t bit_size = 0;
1396 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001397 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001398 {
1399 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1400 DWARFFormValue form_value;
1401 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1402 {
1403 switch (attr)
1404 {
1405 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1406 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1407 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1408 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1409 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1410 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1411 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1412 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1413 case DW_AT_data_member_location:
Greg Claytoncaab74e2012-01-28 00:48:57 +00001414 if (form_value.BlockData())
1415 {
1416 Value initialValue(0);
1417 Value memberOffset(0);
1418 const DataExtractor& debug_info_data = get_debug_info_data();
1419 uint32_t block_length = form_value.Unsigned();
1420 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1421 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1422 NULL, // clang::ASTContext *
1423 NULL, // ClangExpressionVariableList *
1424 NULL, // ClangExpressionDeclMap *
1425 NULL, // RegisterContext *
1426 debug_info_data,
1427 block_offset,
1428 block_length,
1429 eRegisterKindDWARF,
1430 &initialValue,
1431 memberOffset,
1432 NULL))
1433 {
1434 member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1435 }
1436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437 break;
1438
Greg Clayton8cf05932010-07-22 18:30:50 +00001439 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001440 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 case DW_AT_declaration:
1442 case DW_AT_description:
1443 case DW_AT_mutable:
1444 case DW_AT_visibility:
Jim Inghame3ae82a2011-11-12 01:36:43 +00001445
1446 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1447 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1448 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1449 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1450
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001451 default:
1452 case DW_AT_sibling:
1453 break;
1454 }
1455 }
1456 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001457
Greg Clayton44953932011-10-25 01:25:35 +00001458 // Clang has a DWARF generation bug where sometimes it
1459 // represents fields that are references with bad byte size
1460 // and bit size/offset information such as:
1461 //
1462 // DW_AT_byte_size( 0x00 )
1463 // DW_AT_bit_size( 0x40 )
1464 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1465 //
1466 // So check the bit offset to make sure it is sane, and if
1467 // the values are not sane, remove them. If we don't do this
1468 // then we will end up with a crash if we try to use this
1469 // type in an expression when clang becomes unhappy with its
1470 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001471
Greg Clayton44953932011-10-25 01:25:35 +00001472 if (bit_offset > 128)
1473 {
1474 bit_size = 0;
1475 bit_offset = 0;
1476 }
1477
1478 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001479 if (class_language == eLanguageTypeObjC ||
1480 class_language == eLanguageTypeObjC_plus_plus)
1481 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001482
1483 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1484 {
1485 // Not all compilers will mark the vtable pointer
1486 // member as artificial (llvm-gcc). We can't have
1487 // the virtual members in our classes otherwise it
1488 // throws off all child offsets since we end up
1489 // having and extra pointer sized member in our
1490 // class layouts.
1491 is_artificial = true;
1492 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493
Greg Clayton24739922010-10-13 03:15:28 +00001494 if (is_artificial == false)
1495 {
1496 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001497 clang::FieldDecl *field_decl = NULL;
Greg Claytond16e1e52011-07-12 17:06:17 +00001498 if (member_type)
1499 {
1500 if (accessibility == eAccessNone)
1501 accessibility = default_accessibility;
1502 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503
Jim Inghame3ae82a2011-11-12 01:36:43 +00001504 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Greg Clayton42ce2f32011-12-12 21:50:19 +00001505 name,
1506 member_type->GetClangLayoutType(),
1507 accessibility,
1508 bit_size);
Greg Claytond16e1e52011-07-12 17:06:17 +00001509 }
1510 else
1511 {
1512 if (name)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001513 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1514 MakeUserID(die->GetOffset()),
1515 name,
1516 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001517 else
Greg Claytone38a5ed2012-01-05 03:57:59 +00001518 GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1519 MakeUserID(die->GetOffset()),
1520 encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001521 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001522
Sean Callanan5b26f272012-02-04 08:49:35 +00001523 if (member_byte_offset != UINT32_MAX || bit_size != 0)
Greg Claytoncaab74e2012-01-28 00:48:57 +00001524 {
Sean Callanan5b26f272012-02-04 08:49:35 +00001525 /////////////////////////////////////////////////////////////
1526 // How to locate a field given the DWARF debug information
1527 //
1528 // AT_byte_size indicates the size of the word in which the
1529 // bit offset must be interpreted.
1530 //
1531 // AT_data_member_location indicates the byte offset of the
1532 // word from the base address of the structure.
1533 //
1534 // AT_bit_offset indicates how many bits into the word
1535 // (according to the host endianness) the low-order bit of
1536 // the field starts. AT_bit_offset can be negative.
1537 //
1538 // AT_bit_size indicates the size of the field in bits.
1539 /////////////////////////////////////////////////////////////
1540
1541 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1542
1543 uint64_t total_bit_offset = 0;
1544
1545 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1546
1547 if (object_endian == eByteOrderLittle)
1548 {
1549 total_bit_offset += byte_size * 8;
1550 total_bit_offset -= (bit_offset + bit_size);
1551 }
1552 else
1553 {
1554 total_bit_offset += bit_offset;
1555 }
1556
1557 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
Greg Claytoncaab74e2012-01-28 00:48:57 +00001558 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001559 if (prop_name != NULL)
1560 {
1561
1562 clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1563 assert (ivar_decl != NULL);
1564
1565
1566 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1567 prop_name,
1568 0,
1569 ivar_decl,
1570 prop_setter_name,
1571 prop_getter_name,
1572 prop_attributes);
1573 }
Greg Clayton24739922010-10-13 03:15:28 +00001574 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001576 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001577 }
1578 break;
1579
1580 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001581 // Let the type parsing code handle this one for us.
1582 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001583 break;
1584
1585 case DW_TAG_inheritance:
1586 {
1587 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001588 if (default_accessibility == eAccessNone)
1589 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001590 // TODO: implement DW_TAG_inheritance type parsing
1591 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001592 const size_t num_attributes = die->GetAttributes (this,
1593 dwarf_cu,
1594 fixed_form_sizes,
1595 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001596 if (num_attributes > 0)
1597 {
1598 Declaration decl;
1599 DWARFExpression location;
1600 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001601 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001602 bool is_virtual = false;
1603 bool is_base_of_class = true;
1604 off_t member_offset = 0;
1605 uint32_t i;
1606 for (i=0; i<num_attributes; ++i)
1607 {
1608 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1609 DWARFFormValue form_value;
1610 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1611 {
1612 switch (attr)
1613 {
1614 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1615 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1616 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1617 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1618 case DW_AT_data_member_location:
1619 if (form_value.BlockData())
1620 {
1621 Value initialValue(0);
1622 Value memberOffset(0);
1623 const DataExtractor& debug_info_data = get_debug_info_data();
1624 uint32_t block_length = form_value.Unsigned();
1625 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001626 if (DWARFExpression::Evaluate (NULL,
1627 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001628 NULL,
1629 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001630 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001631 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001632 block_offset,
1633 block_length,
1634 eRegisterKindDWARF,
1635 &initialValue,
1636 memberOffset,
1637 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638 {
1639 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1640 }
1641 }
1642 break;
1643
1644 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001645 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646 break;
1647
1648 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1649 default:
1650 case DW_AT_sibling:
1651 break;
1652 }
1653 }
1654 }
1655
Greg Clayton526e5af2010-11-13 03:52:47 +00001656 Type *base_class_type = ResolveTypeUID(encoding_uid);
1657 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001658
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001659 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1660 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001661 if (class_language == eLanguageTypeObjC)
1662 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001663 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001664 }
1665 else
1666 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001667 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001668 accessibility,
1669 is_virtual,
1670 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001671 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672 }
1673 }
1674 break;
1675
1676 default:
1677 break;
1678 }
1679 }
1680 return count;
1681}
1682
1683
1684clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001685SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686{
1687 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001688 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001689 {
1690 DWARFCompileUnitSP cu_sp;
1691 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1692 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001693 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001694 }
1695 return NULL;
1696}
1697
1698clang::DeclContext*
1699SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1700{
Greg Clayton81c22f62011-10-19 18:09:39 +00001701 if (UserIDMatches(type_uid))
1702 return GetClangDeclContextForDIEOffset (sc, type_uid);
1703 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704}
1705
1706Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001707SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708{
Greg Clayton81c22f62011-10-19 18:09:39 +00001709 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001710 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001711 DWARFDebugInfo* debug_info = DebugInfo();
1712 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001713 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001714 DWARFCompileUnitSP cu_sp;
1715 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001716 const bool assert_not_being_parsed = true;
1717 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001718 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719 }
1720 return NULL;
1721}
1722
Greg Claytoncab36a32011-12-08 05:16:30 +00001723Type*
1724SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001725{
Greg Claytoncab36a32011-12-08 05:16:30 +00001726 if (die != NULL)
1727 {
Greg Clayton3bffb082011-12-10 02:15:28 +00001728 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1729 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001730 GetObjectFile()->GetModule()->LogMessage (log.get(),
1731 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1732 die->GetOffset(),
1733 DW_TAG_value_to_name(die->Tag()),
1734 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001735
Greg Claytoncab36a32011-12-08 05:16:30 +00001736 // We might be coming in in the middle of a type tree (a class
1737 // withing a class, an enum within a class), so parse any needed
1738 // parent DIEs before we get to this one...
1739 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1740 switch (decl_ctx_die->Tag())
1741 {
1742 case DW_TAG_structure_type:
1743 case DW_TAG_union_type:
1744 case DW_TAG_class_type:
1745 {
1746 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001747 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001748 GetObjectFile()->GetModule()->LogMessage (log.get(),
1749 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1750 die->GetOffset(),
1751 DW_TAG_value_to_name(die->Tag()),
1752 die->GetName(this, cu),
1753 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001754
Greg Claytoncab36a32011-12-08 05:16:30 +00001755 Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
Sean Callanan5b26f272012-02-04 08:49:35 +00001756 if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
Greg Clayton3bffb082011-12-10 02:15:28 +00001757 {
1758 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001759 GetObjectFile()->GetModule()->LogMessage (log.get(),
1760 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1761 die->GetOffset(),
1762 DW_TAG_value_to_name(die->Tag()),
1763 die->GetName(this, cu),
1764 decl_ctx_die->GetOffset());
Greg Clayton3bffb082011-12-10 02:15:28 +00001765 // Ask the type to complete itself if it already hasn't since if we
1766 // want a function (method or static) from a class, the class must
1767 // create itself and add it's own methods and class functions.
1768 if (parent_type)
1769 parent_type->GetClangFullType();
1770 }
Greg Claytoncab36a32011-12-08 05:16:30 +00001771 }
1772 break;
1773
1774 default:
1775 break;
1776 }
1777 return ResolveType (cu, die);
1778 }
1779 return NULL;
1780}
1781
Greg Clayton6beaaa62011-01-17 03:46:26 +00001782// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1783// SymbolFileDWARF objects to detect if this DWARF file is the one that
1784// can resolve a clang_type.
1785bool
1786SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1787{
1788 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1789 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1790 return die != NULL;
1791}
1792
1793
Greg Clayton1be10fc2010-09-29 01:12:09 +00001794lldb::clang_type_t
1795SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1796{
1797 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001798 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1799 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001800 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001801 {
1802 // We have already resolved this type...
1803 return clang_type;
1804 }
1805 // Once we start resolving this type, remove it from the forward declaration
1806 // map in case anyone child members or other types require this type to get resolved.
1807 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1808 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001809 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001810
Greg Clayton1be10fc2010-09-29 01:12:09 +00001811
Greg Clayton85ae2e12011-10-18 23:36:41 +00001812 // Disable external storage for this type so we don't get anymore
1813 // clang::ExternalASTSource queries for this type.
1814 ClangASTContext::SetHasExternalStorage (clang_type, false);
1815
Greg Clayton450e3f32010-10-12 02:24:53 +00001816 DWARFDebugInfo* debug_info = DebugInfo();
1817
Greg Clayton96d7d742010-11-10 23:42:09 +00001818 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001819 Type *type = m_die_to_type.lookup (die);
1820
1821 const dw_tag_t tag = die->Tag();
1822
Greg Clayton3bffb082011-12-10 02:15:28 +00001823 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1824 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00001825 GetObjectFile()->GetModule()->LogMessage (log.get(),
1826 "0x%8.8llx: %s '%s' resolving forward declaration...\n",
1827 MakeUserID(die->GetOffset()),
1828 DW_TAG_value_to_name(tag),
1829 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001830 assert (clang_type);
1831 DWARFDebugInfoEntry::Attributes attributes;
1832
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001833 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001834
1835 switch (tag)
1836 {
1837 case DW_TAG_structure_type:
1838 case DW_TAG_union_type:
1839 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001840 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001841 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001842 LayoutInfo layout_info;
1843 if (die->HasChildren())
Greg Clayton1be10fc2010-09-29 01:12:09 +00001844 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001845
Greg Claytoncaab74e2012-01-28 00:48:57 +00001846 LanguageType class_language = eLanguageTypeUnknown;
1847 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1848 if (is_objc_class)
1849 class_language = eLanguageTypeObjC;
Greg Claytonc93237c2010-10-01 20:48:32 +00001850
Greg Claytoncaab74e2012-01-28 00:48:57 +00001851 int tag_decl_kind = -1;
1852 AccessType default_accessibility = eAccessNone;
1853 if (tag == DW_TAG_structure_type)
Greg Claytonc93237c2010-10-01 20:48:32 +00001854 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001855 tag_decl_kind = clang::TTK_Struct;
1856 default_accessibility = eAccessPublic;
Greg Claytonc93237c2010-10-01 20:48:32 +00001857 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001858 else if (tag == DW_TAG_union_type)
Greg Clayton450e3f32010-10-12 02:24:53 +00001859 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001860 tag_decl_kind = clang::TTK_Union;
1861 default_accessibility = eAccessPublic;
1862 }
1863 else if (tag == DW_TAG_class_type)
1864 {
1865 tag_decl_kind = clang::TTK_Class;
1866 default_accessibility = eAccessPrivate;
1867 }
1868
1869 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1870 std::vector<clang::CXXBaseSpecifier *> base_classes;
1871 std::vector<int> member_accessibilities;
1872 bool is_a_class = false;
1873 // Parse members and base classes first
1874 DWARFDIECollection member_function_dies;
1875
1876 ParseChildMembers (sc,
1877 curr_cu,
1878 die,
1879 clang_type,
1880 class_language,
1881 base_classes,
1882 member_accessibilities,
1883 member_function_dies,
1884 default_accessibility,
1885 is_a_class,
1886 layout_info);
1887
1888 // Now parse any methods if there were any...
1889 size_t num_functions = member_function_dies.Size();
1890 if (num_functions > 0)
1891 {
1892 for (size_t i=0; i<num_functions; ++i)
1893 {
1894 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
1895 }
1896 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001897
Greg Claytoncaab74e2012-01-28 00:48:57 +00001898 if (class_language == eLanguageTypeObjC)
1899 {
1900 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
1901 if (!class_str.empty())
Greg Clayton5009f9d2011-10-27 17:55:14 +00001902 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001903
1904 DIEArray method_die_offsets;
1905 if (m_using_apple_tables)
Greg Claytond4a2b372011-09-12 23:21:58 +00001906 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001907 if (m_apple_objc_ap.get())
1908 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
1909 }
1910 else
1911 {
1912 if (!m_indexed)
1913 Index ();
Greg Clayton450e3f32010-10-12 02:24:53 +00001914
Greg Claytoncaab74e2012-01-28 00:48:57 +00001915 ConstString class_name (class_str.c_str());
1916 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1917 }
1918
1919 if (!method_die_offsets.empty())
1920 {
1921 DWARFDebugInfo* debug_info = DebugInfo();
1922
1923 DWARFCompileUnit* method_cu = NULL;
1924 const size_t num_matches = method_die_offsets.size();
1925 for (size_t i=0; i<num_matches; ++i)
Greg Clayton95d87902011-11-11 03:16:25 +00001926 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001927 const dw_offset_t die_offset = method_die_offsets[i];
1928 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
1929
1930 if (method_die)
1931 ResolveType (method_cu, method_die);
1932 else
Greg Clayton95d87902011-11-11 03:16:25 +00001933 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00001934 if (m_using_apple_tables)
1935 {
1936 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
1937 die_offset, class_str.c_str());
1938 }
1939 }
1940 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001941 }
1942 }
1943 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00001944
1945 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1946 // need to tell the clang type it is actually a class.
1947 if (class_language != eLanguageTypeObjC)
1948 {
1949 if (is_a_class && tag_decl_kind != clang::TTK_Class)
1950 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
1951 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001952
Greg Claytoncaab74e2012-01-28 00:48:57 +00001953 // Since DW_TAG_structure_type gets used for both classes
1954 // and structures, we may need to set any DW_TAG_member
1955 // fields to have a "private" access if none was specified.
1956 // When we parsed the child members we tracked that actual
1957 // accessibility value for each DW_TAG_member in the
1958 // "member_accessibilities" array. If the value for the
1959 // member is zero, then it was set to the "default_accessibility"
1960 // which for structs was "public". Below we correct this
1961 // by setting any fields to "private" that weren't correctly
1962 // set.
1963 if (is_a_class && !member_accessibilities.empty())
1964 {
1965 // This is a class and all members that didn't have
1966 // their access specified are private.
1967 ast.SetDefaultAccessForRecordFields (clang_type,
1968 eAccessPrivate,
1969 &member_accessibilities.front(),
1970 member_accessibilities.size());
1971 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001972
Greg Claytoncaab74e2012-01-28 00:48:57 +00001973 if (!base_classes.empty())
1974 {
1975 ast.SetBaseClassesForClassType (clang_type,
1976 &base_classes.front(),
1977 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001978
Greg Claytoncaab74e2012-01-28 00:48:57 +00001979 // Clang will copy each CXXBaseSpecifier in "base_classes"
1980 // so we have to free them all.
1981 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1982 base_classes.size());
1983 }
1984
Greg Claytonc93237c2010-10-01 20:48:32 +00001985 }
Sean Callanan5b26f272012-02-04 08:49:35 +00001986
Greg Claytoncaab74e2012-01-28 00:48:57 +00001987 if (!layout_info.field_offsets.empty())
1988 {
1989 if (type)
1990 layout_info.bit_size = type->GetByteSize() * 8;
1991 if (layout_info.bit_size == 0)
1992 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_byte_size, 0) * 8;
1993 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
1994 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
1995 if (record_type)
1996 {
1997 const clang::RecordDecl *record_decl = record_type->getDecl();
1998
1999 if (log)
Greg Clayton821ac6d2012-01-28 02:22:27 +00002000 {
Greg Claytoncaab74e2012-01-28 00:48:57 +00002001 GetObjectFile()->GetModule()->LogMessage (log.get(),
Greg Clayton821ac6d2012-01-28 02:22:27 +00002002 "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 +00002003 clang_type,
2004 record_decl,
2005 layout_info.bit_size,
2006 layout_info.alignment,
2007 (uint32_t)layout_info.field_offsets.size());
2008
Greg Clayton821ac6d2012-01-28 02:22:27 +00002009 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2010 for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2011 {
2012 GetObjectFile()->GetModule()->LogMessage (log.get(),
2013 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2014 clang_type,
2015 (uint32_t)pos->second,
2016 pos->first->getNameAsString().c_str());
2017 }
2018 }
Greg Claytoncaab74e2012-01-28 00:48:57 +00002019 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2020 }
2021 }
Greg Claytonc93237c2010-10-01 20:48:32 +00002022 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002023 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00002024 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002025
2026 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002027 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002028 if (die->HasChildren())
2029 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002030 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
2031 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002032 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002033 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00002034 return clang_type;
2035
2036 default:
2037 assert(false && "not a forward clang type decl!");
2038 break;
2039 }
2040 return NULL;
2041}
2042
Greg Claytonc685f8e2010-09-15 04:15:46 +00002043Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00002044SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002045{
2046 if (type_die != NULL)
2047 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002048 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00002049
Greg Claytonc685f8e2010-09-15 04:15:46 +00002050 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002051 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00002052
Greg Clayton24739922010-10-13 03:15:28 +00002053 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00002054 {
2055 if (type != DIE_IS_BEING_PARSED)
2056 return type;
2057
2058 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
2059 type_die->GetOffset(),
2060 DW_TAG_value_to_name(type_die->Tag()),
2061 type_die->GetName(this, curr_cu));
2062
2063 }
2064 else
2065 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002066 }
2067 return NULL;
2068}
2069
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00002071SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002072{
2073 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002074 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002075 {
2076 // The symbol vendor doesn't know about this compile unit, we
2077 // need to parse and add it to the symbol vendor object.
2078 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00002079 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002080 if (dc_cu.get())
2081 {
2082 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00002083 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00002084 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002085
2086 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00002087
2088 if (m_debug_map_symfile)
2089 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090 }
2091 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002092 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002093}
2094
2095bool
Greg Clayton96d7d742010-11-10 23:42:09 +00002096SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002097{
2098 sc.Clear();
2099 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00002100 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002101
Greg Clayton81c22f62011-10-19 18:09:39 +00002102 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002103 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002104 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002105
2106 if (sc.function)
2107 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00002108 sc.module_sp = sc.function->CalculateSymbolContextModule()->shared_from_this();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002109 return true;
2110 }
2111
2112 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002113}
2114
2115uint32_t
2116SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2117{
2118 Timer scoped_timer(__PRETTY_FUNCTION__,
2119 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
2120 so_addr.GetSection(),
2121 so_addr.GetOffset(),
2122 resolve_scope);
2123 uint32_t resolved = 0;
2124 if (resolve_scope & ( eSymbolContextCompUnit |
2125 eSymbolContextFunction |
2126 eSymbolContextBlock |
2127 eSymbolContextLineEntry))
2128 {
2129 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2130
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002131 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00002132 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002133 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002134 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002135 if (cu_offset != DW_INVALID_OFFSET)
2136 {
2137 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002138 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2139 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002140 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002141 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002142 assert(sc.comp_unit != NULL);
2143 resolved |= eSymbolContextCompUnit;
2144
2145 if (resolve_scope & eSymbolContextLineEntry)
2146 {
2147 LineTable *line_table = sc.comp_unit->GetLineTable();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002148 if (line_table != NULL)
2149 {
2150 if (so_addr.IsLinkedAddress())
2151 {
2152 Address linked_addr (so_addr);
2153 linked_addr.ResolveLinkedAddress();
2154 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2155 {
2156 resolved |= eSymbolContextLineEntry;
2157 }
2158 }
2159 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2160 {
2161 resolved |= eSymbolContextLineEntry;
2162 }
2163 }
2164 }
2165
2166 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2167 {
2168 DWARFDebugInfoEntry *function_die = NULL;
2169 DWARFDebugInfoEntry *block_die = NULL;
2170 if (resolve_scope & eSymbolContextBlock)
2171 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002172 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002173 }
2174 else
2175 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002176 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002177 }
2178
2179 if (function_die != NULL)
2180 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002181 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002183 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002184 }
2185
2186 if (sc.function != NULL)
2187 {
2188 resolved |= eSymbolContextFunction;
2189
2190 if (resolve_scope & eSymbolContextBlock)
2191 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002192 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002193
2194 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002195 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002196 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002197 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002198 if (sc.block)
2199 resolved |= eSymbolContextBlock;
2200 }
2201 }
2202 }
2203 }
2204 }
2205 }
2206 }
2207 return resolved;
2208}
2209
2210
2211
2212uint32_t
2213SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2214{
2215 const uint32_t prev_size = sc_list.GetSize();
2216 if (resolve_scope & eSymbolContextCompUnit)
2217 {
2218 DWARFDebugInfo* debug_info = DebugInfo();
2219 if (debug_info)
2220 {
2221 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002222 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002223
Greg Clayton96d7d742010-11-10 23:42:09 +00002224 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002225 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002226 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002227 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2228 if (check_inlines || file_spec_matches_cu_file_spec)
2229 {
2230 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00002231 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002232 assert(sc.comp_unit != NULL);
2233
2234 uint32_t file_idx = UINT32_MAX;
2235
2236 // If we are looking for inline functions only and we don't
2237 // find it in the support files, we are done.
2238 if (check_inlines)
2239 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002240 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241 if (file_idx == UINT32_MAX)
2242 continue;
2243 }
2244
2245 if (line != 0)
2246 {
2247 LineTable *line_table = sc.comp_unit->GetLineTable();
2248
2249 if (line_table != NULL && line != 0)
2250 {
2251 // We will have already looked up the file index if
2252 // we are searching for inline entries.
2253 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002254 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002255
2256 if (file_idx != UINT32_MAX)
2257 {
2258 uint32_t found_line;
2259 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2260 found_line = sc.line_entry.line;
2261
Greg Clayton016a95e2010-09-14 02:20:48 +00002262 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002263 {
2264 sc.function = NULL;
2265 sc.block = NULL;
2266 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2267 {
2268 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2269 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2270 {
2271 DWARFDebugInfoEntry *function_die = NULL;
2272 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002273 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002274
2275 if (function_die != NULL)
2276 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002277 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002278 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002279 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280 }
2281
2282 if (sc.function != NULL)
2283 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002284 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002285
2286 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002287 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002288 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002289 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002290 }
2291 }
2292 }
2293
2294 sc_list.Append(sc);
2295 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2296 }
2297 }
2298 }
2299 else if (file_spec_matches_cu_file_spec && !check_inlines)
2300 {
2301 // only append the context if we aren't looking for inline call sites
2302 // by file and line and if the file spec matches that of the compile unit
2303 sc_list.Append(sc);
2304 }
2305 }
2306 else if (file_spec_matches_cu_file_spec && !check_inlines)
2307 {
2308 // only append the context if we aren't looking for inline call sites
2309 // by file and line and if the file spec matches that of the compile unit
2310 sc_list.Append(sc);
2311 }
2312
2313 if (!check_inlines)
2314 break;
2315 }
2316 }
2317 }
2318 }
2319 return sc_list.GetSize() - prev_size;
2320}
2321
2322void
2323SymbolFileDWARF::Index ()
2324{
2325 if (m_indexed)
2326 return;
2327 m_indexed = true;
2328 Timer scoped_timer (__PRETTY_FUNCTION__,
2329 "SymbolFileDWARF::Index (%s)",
2330 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2331
2332 DWARFDebugInfo* debug_info = DebugInfo();
2333 if (debug_info)
2334 {
2335 uint32_t cu_idx = 0;
2336 const uint32_t num_compile_units = GetNumCompileUnits();
2337 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2338 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002339 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002340
Greg Clayton96d7d742010-11-10 23:42:09 +00002341 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002342
Greg Clayton96d7d742010-11-10 23:42:09 +00002343 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002344 m_function_basename_index,
2345 m_function_fullname_index,
2346 m_function_method_index,
2347 m_function_selector_index,
2348 m_objc_class_selectors_index,
2349 m_global_index,
2350 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002351 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002352
2353 // Keep memory down by clearing DIEs if this generate function
2354 // caused them to be parsed
2355 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002356 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002357 }
2358
Greg Claytond4a2b372011-09-12 23:21:58 +00002359 m_function_basename_index.Finalize();
2360 m_function_fullname_index.Finalize();
2361 m_function_method_index.Finalize();
2362 m_function_selector_index.Finalize();
2363 m_objc_class_selectors_index.Finalize();
2364 m_global_index.Finalize();
2365 m_type_index.Finalize();
2366 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002367
Greg Clayton24739922010-10-13 03:15:28 +00002368#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002369 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002370 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002371 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2372 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002373 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2374 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2375 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2376 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2377 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2378 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002379 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002380 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002381#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002382 }
2383}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002384
2385bool
2386SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2387{
2388 if (namespace_decl == NULL)
2389 {
2390 // Invalid namespace decl which means we aren't matching only things
2391 // in this symbol file, so return true to indicate it matches this
2392 // symbol file.
2393 return true;
2394 }
2395
2396 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2397
2398 if (namespace_ast == NULL)
2399 return true; // No AST in the "namespace_decl", return true since it
2400 // could then match any symbol file, including this one
2401
2402 if (namespace_ast == GetClangASTContext().getASTContext())
2403 return true; // The ASTs match, return true
2404
2405 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002406 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2407
2408 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002409 GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002410
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002411 return false;
2412}
2413
Greg Clayton2506a7a2011-10-12 23:34:26 +00002414bool
2415SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2416 DWARFCompileUnit* cu,
2417 const DWARFDebugInfoEntry* die)
2418{
2419 // No namespace specified, so the answesr i
2420 if (namespace_decl == NULL)
2421 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002422
2423 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002424
Greg Clayton2506a7a2011-10-12 23:34:26 +00002425 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2426 if (decl_ctx_die)
2427 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002428
Greg Clayton2506a7a2011-10-12 23:34:26 +00002429 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2430 if (clang_namespace_decl)
2431 {
2432 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002433 {
2434 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002435 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002436 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002437 }
2438
Greg Clayton2506a7a2011-10-12 23:34:26 +00002439 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2440
2441 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002442 {
2443 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002444 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 +00002445
Greg Clayton2506a7a2011-10-12 23:34:26 +00002446 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002447 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002448
Greg Claytoncb5860a2011-10-13 23:49:28 +00002449 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002450 }
2451 else
2452 {
2453 // We have a namespace_decl that was not NULL but it contained
2454 // a NULL "clang::NamespaceDecl", so this means the global namespace
2455 // So as long the the contained decl context DIE isn't a namespace
2456 // we should be ok.
2457 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2458 return true;
2459 }
2460 }
Sean Callananebe60672011-10-13 21:50:33 +00002461
2462 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00002463 GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002464
Greg Clayton2506a7a2011-10-12 23:34:26 +00002465 return false;
2466}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002467uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002468SymbolFileDWARF::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 +00002469{
Greg Clayton21f2a492011-10-06 00:09:08 +00002470 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2471
2472 if (log)
2473 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002474 GetObjectFile()->GetModule()->LogMessage (log.get(),
2475 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2476 name.GetCString(),
2477 namespace_decl,
2478 append,
2479 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002480 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002481
2482 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2483 return 0;
2484
Greg Claytonc685f8e2010-09-15 04:15:46 +00002485 DWARFDebugInfo* info = DebugInfo();
2486 if (info == NULL)
2487 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002488
2489 // If we aren't appending the results to this list, then clear the list
2490 if (!append)
2491 variables.Clear();
2492
2493 // Remember how many variables are in the list before we search in case
2494 // we are appending the results to a variable list.
2495 const uint32_t original_size = variables.GetSize();
2496
Greg Claytond4a2b372011-09-12 23:21:58 +00002497 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002498
Greg Clayton97fbc342011-10-20 22:30:33 +00002499 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002500 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002501 if (m_apple_names_ap.get())
2502 {
2503 const char *name_cstr = name.GetCString();
2504 const char *base_name_start;
2505 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002506
Greg Clayton97fbc342011-10-20 22:30:33 +00002507 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2508 base_name_start = name_cstr;
2509
2510 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2511 }
Greg Clayton7f995132011-10-04 22:41:51 +00002512 }
2513 else
2514 {
2515 // Index the DWARF if we haven't already
2516 if (!m_indexed)
2517 Index ();
2518
2519 m_global_index.Find (name, die_offsets);
2520 }
2521
2522 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002523 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002524 {
Greg Clayton7f995132011-10-04 22:41:51 +00002525 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +00002526 sc.module_sp = m_obj_file->GetModule()->shared_from_this();
Greg Clayton7f995132011-10-04 22:41:51 +00002527 assert (sc.module_sp);
2528
Greg Claytond4a2b372011-09-12 23:21:58 +00002529 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002530 DWARFCompileUnit* dwarf_cu = NULL;
2531 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002532 for (size_t i=0; i<num_matches; ++i)
2533 {
2534 const dw_offset_t die_offset = die_offsets[i];
2535 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002536
Greg Clayton95d87902011-11-11 03:16:25 +00002537 if (die)
2538 {
2539 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2540 assert(sc.comp_unit != NULL);
2541
2542 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2543 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002544
Greg Clayton95d87902011-11-11 03:16:25 +00002545 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002546
Greg Clayton95d87902011-11-11 03:16:25 +00002547 if (variables.GetSize() - original_size >= max_matches)
2548 break;
2549 }
2550 else
2551 {
2552 if (m_using_apple_tables)
2553 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002554 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2555 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002556 }
2557 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002558 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002559 }
2560
2561 // Return the number of variable that were appended to the list
2562 return variables.GetSize() - original_size;
2563}
2564
2565uint32_t
2566SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2567{
Greg Clayton21f2a492011-10-06 00:09:08 +00002568 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2569
2570 if (log)
2571 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002572 GetObjectFile()->GetModule()->LogMessage (log.get(),
2573 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2574 regex.GetText(),
2575 append,
2576 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002577 }
2578
Greg Claytonc685f8e2010-09-15 04:15:46 +00002579 DWARFDebugInfo* info = DebugInfo();
2580 if (info == NULL)
2581 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002582
2583 // If we aren't appending the results to this list, then clear the list
2584 if (!append)
2585 variables.Clear();
2586
2587 // Remember how many variables are in the list before we search in case
2588 // we are appending the results to a variable list.
2589 const uint32_t original_size = variables.GetSize();
2590
Greg Clayton7f995132011-10-04 22:41:51 +00002591 DIEArray die_offsets;
2592
Greg Clayton97fbc342011-10-20 22:30:33 +00002593 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002594 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002595 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002596 {
2597 DWARFMappedHash::DIEInfoArray hash_data_array;
2598 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2599 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2600 }
Greg Clayton7f995132011-10-04 22:41:51 +00002601 }
2602 else
2603 {
2604 // Index the DWARF if we haven't already
2605 if (!m_indexed)
2606 Index ();
2607
2608 m_global_index.Find (regex, die_offsets);
2609 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002610
Greg Claytonc685f8e2010-09-15 04:15:46 +00002611 SymbolContext sc;
Greg Claytone1cd1be2012-01-29 20:56:30 +00002612 sc.module_sp = m_obj_file->GetModule()->shared_from_this();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002613 assert (sc.module_sp);
2614
Greg Claytond4a2b372011-09-12 23:21:58 +00002615 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002616 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002617 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002618 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002619 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002620 DWARFDebugInfo* debug_info = DebugInfo();
2621 for (size_t i=0; i<num_matches; ++i)
2622 {
2623 const dw_offset_t die_offset = die_offsets[i];
2624 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002625
2626 if (die)
2627 {
2628 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002629
Greg Clayton95d87902011-11-11 03:16:25 +00002630 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002631
Greg Clayton95d87902011-11-11 03:16:25 +00002632 if (variables.GetSize() - original_size >= max_matches)
2633 break;
2634 }
2635 else
2636 {
2637 if (m_using_apple_tables)
2638 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002639 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2640 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002641 }
2642 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002643 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002644 }
2645
2646 // Return the number of variable that were appended to the list
2647 return variables.GetSize() - original_size;
2648}
2649
Greg Claytonaa044962011-10-13 00:59:38 +00002650
Jim Ingham4cda6e02011-10-07 22:23:45 +00002651bool
2652SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2653 DWARFCompileUnit *&dwarf_cu,
2654 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002655{
Greg Claytonaa044962011-10-13 00:59:38 +00002656 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2657 return ResolveFunction (dwarf_cu, die, sc_list);
2658}
2659
2660
2661bool
2662SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2663 const DWARFDebugInfoEntry *die,
2664 SymbolContextList& sc_list)
2665{
Greg Clayton9e315582011-09-02 04:03:59 +00002666 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002667
2668 if (die == NULL)
2669 return false;
2670
Jim Ingham4cda6e02011-10-07 22:23:45 +00002671 // If we were passed a die that is not a function, just return false...
2672 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2673 return false;
2674
2675 const DWARFDebugInfoEntry* inlined_die = NULL;
2676 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002677 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002678 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002679
Jim Ingham4cda6e02011-10-07 22:23:45 +00002680 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002681 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002682 if (die->Tag() == DW_TAG_subprogram)
2683 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002684 }
2685 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002686 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002687 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002688 {
2689 Address addr;
2690 // Parse all blocks if needed
2691 if (inlined_die)
2692 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002693 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002694 assert (sc.block != NULL);
2695 if (sc.block->GetStartAddress (addr) == false)
2696 addr.Clear();
2697 }
2698 else
2699 {
2700 sc.block = NULL;
2701 addr = sc.function->GetAddressRange().GetBaseAddress();
2702 }
2703
2704 if (addr.IsValid())
2705 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002706 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002707 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002708 }
2709 }
2710
Greg Claytonaa044962011-10-13 00:59:38 +00002711 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002712}
2713
Greg Clayton7f995132011-10-04 22:41:51 +00002714void
2715SymbolFileDWARF::FindFunctions (const ConstString &name,
2716 const NameToDIE &name_to_die,
2717 SymbolContextList& sc_list)
2718{
Greg Claytond4a2b372011-09-12 23:21:58 +00002719 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002720 if (name_to_die.Find (name, die_offsets))
2721 {
2722 ParseFunctions (die_offsets, sc_list);
2723 }
2724}
2725
2726
2727void
2728SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2729 const NameToDIE &name_to_die,
2730 SymbolContextList& sc_list)
2731{
2732 DIEArray die_offsets;
2733 if (name_to_die.Find (regex, die_offsets))
2734 {
2735 ParseFunctions (die_offsets, sc_list);
2736 }
2737}
2738
2739
2740void
2741SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2742 const DWARFMappedHash::MemoryTable &memory_table,
2743 SymbolContextList& sc_list)
2744{
2745 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002746 DWARFMappedHash::DIEInfoArray hash_data_array;
2747 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002748 {
Greg Claytond1767f02011-12-08 02:13:16 +00002749 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002750 ParseFunctions (die_offsets, sc_list);
2751 }
2752}
2753
2754void
2755SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2756 SymbolContextList& sc_list)
2757{
2758 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002759 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002760 {
Greg Clayton7f995132011-10-04 22:41:51 +00002761 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002762
2763 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002764 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002765 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002766 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002767 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002768 }
2769 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002770}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002771
Jim Ingham4cda6e02011-10-07 22:23:45 +00002772bool
2773SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2774 const DWARFCompileUnit *dwarf_cu,
2775 uint32_t name_type_mask,
2776 const char *partial_name,
2777 const char *base_name_start,
2778 const char *base_name_end)
2779{
2780 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2781 if (name_type_mask == eFunctionNameTypeMethod
2782 || name_type_mask == eFunctionNameTypeBase)
2783 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002784 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2785 if (!containing_decl_ctx)
2786 return false;
2787
2788 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2789
2790 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2791 return false;
2792 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2793 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002794 }
2795
2796 // Now we need to check whether the name we got back for this type matches the extra specifications
2797 // that were in the name we're looking up:
2798 if (base_name_start != partial_name || *base_name_end != '\0')
2799 {
2800 // First see if the stuff to the left matches the full name. To do that let's see if
2801 // we can pull out the mips linkage name attribute:
2802
2803 Mangled best_name;
2804
2805 DWARFDebugInfoEntry::Attributes attributes;
2806 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2807 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2808 if (idx != UINT32_MAX)
2809 {
2810 DWARFFormValue form_value;
2811 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2812 {
2813 const char *name = form_value.AsCString(&get_debug_str_data());
2814 best_name.SetValue (name, true);
2815 }
2816 }
2817 if (best_name)
2818 {
2819 const char *demangled = best_name.GetDemangledName().GetCString();
2820 if (demangled)
2821 {
2822 std::string name_no_parens(partial_name, base_name_end - partial_name);
2823 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002824 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002825 }
2826 }
2827 }
2828
2829 return true;
2830}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002831
Greg Clayton0c5cd902010-06-28 21:30:43 +00002832uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002833SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002834 const lldb_private::ClangNamespaceDecl *namespace_decl,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002835 uint32_t name_type_mask,
2836 bool append,
2837 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002838{
2839 Timer scoped_timer (__PRETTY_FUNCTION__,
2840 "SymbolFileDWARF::FindFunctions (name = '%s')",
2841 name.AsCString());
2842
Greg Clayton21f2a492011-10-06 00:09:08 +00002843 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2844
2845 if (log)
2846 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002847 GetObjectFile()->GetModule()->LogMessage (log.get(),
2848 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2849 name.GetCString(),
2850 name_type_mask,
2851 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002852 }
2853
Greg Clayton0c5cd902010-06-28 21:30:43 +00002854 // If we aren't appending the results to this list, then clear the list
2855 if (!append)
2856 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002857
2858 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2859 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002860
2861 // If name is empty then we won't find anything.
2862 if (name.IsEmpty())
2863 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002864
2865 // Remember how many sc_list are in the list before we search in case
2866 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002867
Greg Clayton9e315582011-09-02 04:03:59 +00002868 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002869
Jim Ingham4cda6e02011-10-07 22:23:45 +00002870 const char *name_cstr = name.GetCString();
2871 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2872 const char *base_name_start = name_cstr;
2873 const char *base_name_end = name_cstr + strlen(name_cstr);
2874
2875 if (name_type_mask & eFunctionNameTypeAuto)
2876 {
2877 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2878 effective_name_type_mask = eFunctionNameTypeFull;
2879 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2880 effective_name_type_mask = eFunctionNameTypeFull;
2881 else
2882 {
2883 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2884 effective_name_type_mask |= eFunctionNameTypeSelector;
2885
2886 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2887 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2888 }
2889 }
2890 else
2891 {
2892 effective_name_type_mask = name_type_mask;
2893 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2894 {
2895 // If they've asked for a CPP method or function name and it can't be that, we don't
2896 // even need to search for CPP methods or names.
2897 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2898 {
2899 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2900 if (effective_name_type_mask == eFunctionNameTypeNone)
2901 return 0;
2902 }
2903 }
2904
2905 if (effective_name_type_mask & eFunctionNameTypeSelector)
2906 {
2907 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2908 {
2909 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2910 if (effective_name_type_mask == eFunctionNameTypeNone)
2911 return 0;
2912 }
2913 }
2914 }
2915
2916 DWARFDebugInfo* info = DebugInfo();
2917 if (info == NULL)
2918 return 0;
2919
Greg Claytonaa044962011-10-13 00:59:38 +00002920 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00002921 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002922 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002923 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002924 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002925
2926 DIEArray die_offsets;
2927
2928 uint32_t num_matches = 0;
2929
2930 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002931 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002932 // If they asked for the full name, match what they typed. At some point we may
2933 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2934 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002935 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002936 for (uint32_t i = 0; i < num_matches; i++)
2937 {
Greg Clayton95d87902011-11-11 03:16:25 +00002938 const dw_offset_t die_offset = die_offsets[i];
2939 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002940 if (die)
2941 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002942 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2943 continue;
2944
Greg Claytonaa044962011-10-13 00:59:38 +00002945 ResolveFunction (dwarf_cu, die, sc_list);
2946 }
Greg Clayton95d87902011-11-11 03:16:25 +00002947 else
2948 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002949 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2950 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002951 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002952 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002953 }
2954 else
2955 {
2956 if (effective_name_type_mask & eFunctionNameTypeSelector)
2957 {
2958 if (namespace_decl && *namespace_decl)
2959 return 0; // no selectors in namespaces
2960
2961 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2962 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2963 // and if it is an ObjC method name, we're good.
2964
2965 for (uint32_t i = 0; i < num_matches; i++)
2966 {
Greg Clayton95d87902011-11-11 03:16:25 +00002967 const dw_offset_t die_offset = die_offsets[i];
2968 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00002969 if (die)
2970 {
2971 const char *die_name = die->GetName(this, dwarf_cu);
2972 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
2973 ResolveFunction (dwarf_cu, die, sc_list);
2974 }
Greg Clayton95d87902011-11-11 03:16:25 +00002975 else
2976 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002977 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2978 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002979 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002980 }
2981 die_offsets.clear();
2982 }
2983
2984 if (effective_name_type_mask & eFunctionNameTypeMethod
2985 || effective_name_type_mask & eFunctionNameTypeBase)
2986 {
2987 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
2988 (namespace_decl && *namespace_decl))
2989 return 0; // no methods in namespaces
2990
2991 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2992 // extract the base name, look that up, and if there is any other information in the name we were
2993 // passed in we have to post-filter based on that.
2994
2995 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2996 std::string base_name(base_name_start, base_name_end - base_name_start);
2997 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
2998
2999 for (uint32_t i = 0; i < num_matches; i++)
3000 {
Greg Clayton95d87902011-11-11 03:16:25 +00003001 const dw_offset_t die_offset = die_offsets[i];
3002 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00003003 if (die)
3004 {
3005 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3006 continue;
3007
3008 if (!FunctionDieMatchesPartialName(die,
3009 dwarf_cu,
3010 effective_name_type_mask,
3011 name_cstr,
3012 base_name_start,
3013 base_name_end))
3014 continue;
3015
3016 // If we get to here, the die is good, and we should add it:
3017 ResolveFunction (dwarf_cu, die, sc_list);
3018 }
Greg Clayton95d87902011-11-11 03:16:25 +00003019 else
3020 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003021 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3022 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00003023 }
Greg Clayton97fbc342011-10-20 22:30:33 +00003024 }
3025 die_offsets.clear();
3026 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003027 }
3028 }
Greg Clayton7f995132011-10-04 22:41:51 +00003029 }
3030 else
3031 {
3032
3033 // Index the DWARF if we haven't already
3034 if (!m_indexed)
3035 Index ();
3036
Greg Clayton7f995132011-10-04 22:41:51 +00003037 if (name_type_mask & eFunctionNameTypeFull)
3038 FindFunctions (name, m_function_fullname_index, sc_list);
3039
Jim Ingham4cda6e02011-10-07 22:23:45 +00003040 std::string base_name(base_name_start, base_name_end - base_name_start);
3041 ConstString base_name_const(base_name.c_str());
3042 DIEArray die_offsets;
3043 DWARFCompileUnit *dwarf_cu = NULL;
3044
3045 if (effective_name_type_mask & eFunctionNameTypeBase)
3046 {
3047 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00003048 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003049 {
Greg Claytonaa044962011-10-13 00:59:38 +00003050 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3051 if (die)
3052 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003053 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3054 continue;
3055
Greg Claytonaa044962011-10-13 00:59:38 +00003056 if (!FunctionDieMatchesPartialName(die,
3057 dwarf_cu,
3058 effective_name_type_mask,
3059 name_cstr,
3060 base_name_start,
3061 base_name_end))
3062 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00003063
Greg Claytonaa044962011-10-13 00:59:38 +00003064 // If we get to here, the die is good, and we should add it:
3065 ResolveFunction (dwarf_cu, die, sc_list);
3066 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003067 }
3068 die_offsets.clear();
3069 }
3070
Jim Inghamea8005a2011-10-11 01:18:11 +00003071 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00003072 {
Sean Callanan213fdb82011-10-13 01:49:10 +00003073 if (namespace_decl && *namespace_decl)
3074 return 0; // no methods in namespaces
3075
Jim Ingham4cda6e02011-10-07 22:23:45 +00003076 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3077 {
Greg Claytonaa044962011-10-13 00:59:38 +00003078 for (uint32_t i = 0; i < num_base; i++)
3079 {
3080 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3081 if (die)
3082 {
3083 if (!FunctionDieMatchesPartialName(die,
3084 dwarf_cu,
3085 effective_name_type_mask,
3086 name_cstr,
3087 base_name_start,
3088 base_name_end))
3089 continue;
3090
3091 // If we get to here, the die is good, and we should add it:
3092 ResolveFunction (dwarf_cu, die, sc_list);
3093 }
3094 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00003095 }
3096 die_offsets.clear();
3097 }
Greg Clayton7f995132011-10-04 22:41:51 +00003098
Sean Callanan213fdb82011-10-13 01:49:10 +00003099 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00003100 {
Greg Clayton7f995132011-10-04 22:41:51 +00003101 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00003102 }
3103
Greg Clayton4d01ace2011-09-29 16:58:15 +00003104 }
3105
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003106 // Return the number of variable that were appended to the list
3107 return sc_list.GetSize() - original_size;
3108}
3109
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003110uint32_t
3111SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
3112{
3113 Timer scoped_timer (__PRETTY_FUNCTION__,
3114 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3115 regex.GetText());
3116
Greg Clayton21f2a492011-10-06 00:09:08 +00003117 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3118
3119 if (log)
3120 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003121 GetObjectFile()->GetModule()->LogMessage (log.get(),
3122 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3123 regex.GetText(),
3124 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00003125 }
3126
3127
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003128 // If we aren't appending the results to this list, then clear the list
3129 if (!append)
3130 sc_list.Clear();
3131
3132 // Remember how many sc_list are in the list before we search in case
3133 // we are appending the results to a variable list.
3134 uint32_t original_size = sc_list.GetSize();
3135
Greg Clayton97fbc342011-10-20 22:30:33 +00003136 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003137 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003138 if (m_apple_names_ap.get())
3139 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003140 }
3141 else
3142 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00003143 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00003144 if (!m_indexed)
3145 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003146
Greg Clayton7f995132011-10-04 22:41:51 +00003147 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003148
Greg Clayton7f995132011-10-04 22:41:51 +00003149 FindFunctions (regex, m_function_fullname_index, sc_list);
3150 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003151
3152 // Return the number of variable that were appended to the list
3153 return sc_list.GetSize() - original_size;
3154}
Jim Ingham318c9f22011-08-26 19:44:13 +00003155
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003156uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003157SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3158 const ConstString &name,
3159 const lldb_private::ClangNamespaceDecl *namespace_decl,
3160 bool append,
3161 uint32_t max_matches,
3162 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003163{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003164 DWARFDebugInfo* info = DebugInfo();
3165 if (info == NULL)
3166 return 0;
3167
Greg Clayton21f2a492011-10-06 00:09:08 +00003168 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3169
3170 if (log)
3171 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003172 GetObjectFile()->GetModule()->LogMessage (log.get(),
3173 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
3174 name.GetCString(),
3175 append,
3176 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003177 }
3178
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003179 // If we aren't appending the results to this list, then clear the list
3180 if (!append)
3181 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00003182
3183 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3184 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003185
Greg Claytond4a2b372011-09-12 23:21:58 +00003186 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00003187
Greg Clayton97fbc342011-10-20 22:30:33 +00003188 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003189 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003190 if (m_apple_types_ap.get())
3191 {
3192 const char *name_cstr = name.GetCString();
3193 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3194 }
Greg Clayton7f995132011-10-04 22:41:51 +00003195 }
3196 else
3197 {
3198 if (!m_indexed)
3199 Index ();
3200
3201 m_type_index.Find (name, die_offsets);
3202 }
3203
Greg Clayton7f995132011-10-04 22:41:51 +00003204 const size_t num_matches = die_offsets.size();
3205
Greg Claytond4a2b372011-09-12 23:21:58 +00003206 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003207 {
Greg Clayton7f995132011-10-04 22:41:51 +00003208 const uint32_t initial_types_size = types.GetSize();
3209 DWARFCompileUnit* dwarf_cu = NULL;
3210 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003211 DWARFDebugInfo* debug_info = DebugInfo();
3212 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003213 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003214 const dw_offset_t die_offset = die_offsets[i];
3215 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3216
Greg Clayton95d87902011-11-11 03:16:25 +00003217 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003218 {
Greg Clayton95d87902011-11-11 03:16:25 +00003219 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3220 continue;
3221
3222 Type *matching_type = ResolveType (dwarf_cu, die);
3223 if (matching_type)
3224 {
3225 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003226 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003227 if (types.GetSize() >= max_matches)
3228 break;
3229 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003230 }
Greg Clayton95d87902011-11-11 03:16:25 +00003231 else
3232 {
3233 if (m_using_apple_tables)
3234 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003235 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3236 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003237 }
3238 }
3239
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003240 }
Greg Clayton7f995132011-10-04 22:41:51 +00003241 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003242 }
Greg Clayton7f995132011-10-04 22:41:51 +00003243 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003244}
3245
3246
Greg Clayton526e5af2010-11-13 03:52:47 +00003247ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003248SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003249 const ConstString &name,
3250 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003251{
Greg Clayton21f2a492011-10-06 00:09:08 +00003252 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3253
3254 if (log)
3255 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003256 GetObjectFile()->GetModule()->LogMessage (log.get(),
3257 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3258 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003259 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003260
3261 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3262 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003263
Greg Clayton526e5af2010-11-13 03:52:47 +00003264 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003265 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003266 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003267 {
Greg Clayton7f995132011-10-04 22:41:51 +00003268 DIEArray die_offsets;
3269
Greg Clayton526e5af2010-11-13 03:52:47 +00003270 // Index if we already haven't to make sure the compile units
3271 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003272 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003273 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003274 if (m_apple_namespaces_ap.get())
3275 {
3276 const char *name_cstr = name.GetCString();
3277 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3278 }
Greg Clayton7f995132011-10-04 22:41:51 +00003279 }
3280 else
3281 {
3282 if (!m_indexed)
3283 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003284
Greg Clayton7f995132011-10-04 22:41:51 +00003285 m_namespace_index.Find (name, die_offsets);
3286 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003287
3288 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003289 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003290 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003291 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003292 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003293 DWARFDebugInfo* debug_info = DebugInfo();
3294 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003295 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003296 const dw_offset_t die_offset = die_offsets[i];
3297 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003298
Greg Clayton95d87902011-11-11 03:16:25 +00003299 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003300 {
Greg Clayton95d87902011-11-11 03:16:25 +00003301 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3302 continue;
3303
3304 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3305 if (clang_namespace_decl)
3306 {
3307 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3308 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
Greg Claytond1767f02011-12-08 02:13:16 +00003309 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003310 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003311 }
Greg Clayton95d87902011-11-11 03:16:25 +00003312 else
3313 {
3314 if (m_using_apple_tables)
3315 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003316 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3317 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003318 }
3319 }
3320
Greg Clayton526e5af2010-11-13 03:52:47 +00003321 }
3322 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003323 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003324 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003325}
3326
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003327uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003328SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003329{
3330 // Remember how many sc_list are in the list before we search in case
3331 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003332 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003333
3334 const uint32_t num_die_offsets = die_offsets.size();
3335 // Parse all of the types we found from the pubtypes matches
3336 uint32_t i;
3337 uint32_t num_matches = 0;
3338 for (i = 0; i < num_die_offsets; ++i)
3339 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003340 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3341 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003342 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003343 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003344 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003345 ++num_matches;
3346 if (num_matches >= max_matches)
3347 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003348 }
3349 }
3350
3351 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003352 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003353}
3354
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003355
3356size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003357SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3358 clang::DeclContext *containing_decl_ctx,
Greg Clayton5113dc82011-08-12 06:47:54 +00003359 DWARFCompileUnit* dwarf_cu,
3360 const DWARFDebugInfoEntry *parent_die,
3361 bool skip_artificial,
3362 bool &is_static,
3363 TypeList* type_list,
3364 std::vector<clang_type_t>& function_param_types,
3365 std::vector<clang::ParmVarDecl*>& function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003366 unsigned &type_quals,
3367 ClangASTContext::TemplateParameterInfos &template_param_infos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003368{
3369 if (parent_die == NULL)
3370 return 0;
3371
Greg Claytond88d7592010-09-15 08:33:30 +00003372 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3373
Greg Clayton7fedea22010-11-16 02:10:54 +00003374 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003375 const DWARFDebugInfoEntry *die;
3376 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3377 {
3378 dw_tag_t tag = die->Tag();
3379 switch (tag)
3380 {
3381 case DW_TAG_formal_parameter:
3382 {
3383 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003384 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003385 if (num_attributes > 0)
3386 {
3387 const char *name = NULL;
3388 Declaration decl;
3389 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003390 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003391 // one of None, Auto, Register, Extern, Static, PrivateExtern
3392
Sean Callanane2ef6e32010-09-23 03:01:22 +00003393 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003394 uint32_t i;
3395 for (i=0; i<num_attributes; ++i)
3396 {
3397 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3398 DWARFFormValue form_value;
3399 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3400 {
3401 switch (attr)
3402 {
3403 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3404 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3405 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3406 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3407 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003408 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003409 case DW_AT_location:
3410 // if (form_value.BlockData())
3411 // {
3412 // const DataExtractor& debug_info_data = debug_info();
3413 // uint32_t block_length = form_value.Unsigned();
3414 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3415 // }
3416 // else
3417 // {
3418 // }
3419 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003420 case DW_AT_const_value:
3421 case DW_AT_default_value:
3422 case DW_AT_description:
3423 case DW_AT_endianity:
3424 case DW_AT_is_optional:
3425 case DW_AT_segment:
3426 case DW_AT_variable_parameter:
3427 default:
3428 case DW_AT_abstract_origin:
3429 case DW_AT_sibling:
3430 break;
3431 }
3432 }
3433 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003434
Greg Clayton0fffff52010-09-24 05:15:53 +00003435 bool skip = false;
3436 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003437 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003438 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003439 {
3440 // In order to determine if a C++ member function is
3441 // "const" we have to look at the const-ness of "this"...
3442 // Ugly, but that
3443 if (arg_idx == 0)
3444 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003445 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003446 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003447 // Often times compilers omit the "this" name for the
3448 // specification DIEs, so we can't rely upon the name
3449 // being in the formal parameter DIE...
3450 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003451 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003452 Type *this_type = ResolveTypeUID (param_type_die_offset);
3453 if (this_type)
3454 {
3455 uint32_t encoding_mask = this_type->GetEncodingMask();
3456 if (encoding_mask & Type::eEncodingIsPointerUID)
3457 {
3458 is_static = false;
3459
3460 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3461 type_quals |= clang::Qualifiers::Const;
3462 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3463 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003464 }
3465 }
3466 }
3467 }
3468 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003469 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003470 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003471 else
3472 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003473
Greg Clayton0fffff52010-09-24 05:15:53 +00003474 // HACK: Objective C formal parameters "self" and "_cmd"
3475 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003476 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3477 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003478 {
3479 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3480 skip = true;
3481 }
3482 }
3483 }
3484
3485 if (!skip)
3486 {
3487 Type *type = ResolveTypeUID(param_type_die_offset);
3488 if (type)
3489 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003490 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003491
Greg Clayton42ce2f32011-12-12 21:50:19 +00003492 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3493 type->GetClangForwardType(),
3494 storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003495 assert(param_var_decl);
3496 function_param_decls.push_back(param_var_decl);
3497 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003498 }
3499 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003500 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003501 }
3502 break;
3503
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00003504 case DW_TAG_template_type_parameter:
3505 case DW_TAG_template_value_parameter:
3506 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3507 break;
3508
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003509 default:
3510 break;
3511 }
3512 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003513 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003514}
3515
3516size_t
3517SymbolFileDWARF::ParseChildEnumerators
3518(
3519 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003520 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003521 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003522 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003523 const DWARFDebugInfoEntry *parent_die
3524)
3525{
3526 if (parent_die == NULL)
3527 return 0;
3528
3529 size_t enumerators_added = 0;
3530 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003531 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3532
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003533 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3534 {
3535 const dw_tag_t tag = die->Tag();
3536 if (tag == DW_TAG_enumerator)
3537 {
3538 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003539 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003540 if (num_child_attributes > 0)
3541 {
3542 const char *name = NULL;
3543 bool got_value = false;
3544 int64_t enum_value = 0;
3545 Declaration decl;
3546
3547 uint32_t i;
3548 for (i=0; i<num_child_attributes; ++i)
3549 {
3550 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3551 DWARFFormValue form_value;
3552 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3553 {
3554 switch (attr)
3555 {
3556 case DW_AT_const_value:
3557 got_value = true;
3558 enum_value = form_value.Unsigned();
3559 break;
3560
3561 case DW_AT_name:
3562 name = form_value.AsCString(&get_debug_str_data());
3563 break;
3564
3565 case DW_AT_description:
3566 default:
3567 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3568 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3569 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3570 case DW_AT_sibling:
3571 break;
3572 }
3573 }
3574 }
3575
3576 if (name && name[0] && got_value)
3577 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003578 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3579 enumerator_clang_type,
3580 decl,
3581 name,
3582 enum_value,
3583 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003584 ++enumerators_added;
3585 }
3586 }
3587 }
3588 }
3589 return enumerators_added;
3590}
3591
3592void
3593SymbolFileDWARF::ParseChildArrayInfo
3594(
3595 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003596 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003597 const DWARFDebugInfoEntry *parent_die,
3598 int64_t& first_index,
3599 std::vector<uint64_t>& element_orders,
3600 uint32_t& byte_stride,
3601 uint32_t& bit_stride
3602)
3603{
3604 if (parent_die == NULL)
3605 return;
3606
3607 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003608 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003609 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3610 {
3611 const dw_tag_t tag = die->Tag();
3612 switch (tag)
3613 {
3614 case DW_TAG_enumerator:
3615 {
3616 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003617 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003618 if (num_child_attributes > 0)
3619 {
3620 const char *name = NULL;
3621 bool got_value = false;
3622 int64_t enum_value = 0;
3623
3624 uint32_t i;
3625 for (i=0; i<num_child_attributes; ++i)
3626 {
3627 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3628 DWARFFormValue form_value;
3629 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3630 {
3631 switch (attr)
3632 {
3633 case DW_AT_const_value:
3634 got_value = true;
3635 enum_value = form_value.Unsigned();
3636 break;
3637
3638 case DW_AT_name:
3639 name = form_value.AsCString(&get_debug_str_data());
3640 break;
3641
3642 case DW_AT_description:
3643 default:
3644 case DW_AT_decl_file:
3645 case DW_AT_decl_line:
3646 case DW_AT_decl_column:
3647 case DW_AT_sibling:
3648 break;
3649 }
3650 }
3651 }
3652 }
3653 }
3654 break;
3655
3656 case DW_TAG_subrange_type:
3657 {
3658 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003659 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003660 if (num_child_attributes > 0)
3661 {
3662 const char *name = NULL;
3663 bool got_value = false;
3664 uint64_t byte_size = 0;
3665 int64_t enum_value = 0;
3666 uint64_t num_elements = 0;
3667 uint64_t lower_bound = 0;
3668 uint64_t upper_bound = 0;
3669 uint32_t i;
3670 for (i=0; i<num_child_attributes; ++i)
3671 {
3672 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3673 DWARFFormValue form_value;
3674 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3675 {
3676 switch (attr)
3677 {
3678 case DW_AT_const_value:
3679 got_value = true;
3680 enum_value = form_value.Unsigned();
3681 break;
3682
3683 case DW_AT_name:
3684 name = form_value.AsCString(&get_debug_str_data());
3685 break;
3686
3687 case DW_AT_count:
3688 num_elements = form_value.Unsigned();
3689 break;
3690
3691 case DW_AT_bit_stride:
3692 bit_stride = form_value.Unsigned();
3693 break;
3694
3695 case DW_AT_byte_stride:
3696 byte_stride = form_value.Unsigned();
3697 break;
3698
3699 case DW_AT_byte_size:
3700 byte_size = form_value.Unsigned();
3701 break;
3702
3703 case DW_AT_lower_bound:
3704 lower_bound = form_value.Unsigned();
3705 break;
3706
3707 case DW_AT_upper_bound:
3708 upper_bound = form_value.Unsigned();
3709 break;
3710
3711 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003712 case DW_AT_abstract_origin:
3713 case DW_AT_accessibility:
3714 case DW_AT_allocated:
3715 case DW_AT_associated:
3716 case DW_AT_data_location:
3717 case DW_AT_declaration:
3718 case DW_AT_description:
3719 case DW_AT_sibling:
3720 case DW_AT_threads_scaled:
3721 case DW_AT_type:
3722 case DW_AT_visibility:
3723 break;
3724 }
3725 }
3726 }
3727
3728 if (upper_bound > lower_bound)
3729 num_elements = upper_bound - lower_bound + 1;
3730
3731 if (num_elements > 0)
3732 element_orders.push_back (num_elements);
3733 }
3734 }
3735 break;
3736 }
3737 }
3738}
3739
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003741SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003742{
3743 TypeSP type_sp;
3744 if (die != NULL)
3745 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003746 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003747 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003748 if (type_ptr == NULL)
3749 {
Greg Claytonca512b32011-01-14 04:54:56 +00003750 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3751 assert (lldb_cu);
3752 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003753 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003754 }
3755 else if (type_ptr != DIE_IS_BEING_PARSED)
3756 {
3757 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003758 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759 }
3760
3761 }
3762 return type_sp;
3763}
3764
3765clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003766SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003767{
3768 if (die_offset != DW_INVALID_OFFSET)
3769 {
3770 DWARFCompileUnitSP cu_sp;
3771 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003772 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003773 }
3774 return NULL;
3775}
3776
Sean Callanan72e49402011-08-05 23:43:37 +00003777clang::DeclContext *
3778SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3779{
3780 if (die_offset != DW_INVALID_OFFSET)
3781 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003782 DWARFDebugInfo* debug_info = DebugInfo();
3783 if (debug_info)
3784 {
3785 DWARFCompileUnitSP cu_sp;
3786 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3787 if (die)
3788 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3789 }
Sean Callanan72e49402011-08-05 23:43:37 +00003790 }
3791 return NULL;
3792}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003793
Greg Clayton96d7d742010-11-10 23:42:09 +00003794clang::NamespaceDecl *
3795SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3796{
Greg Clayton030a2042011-10-14 21:34:45 +00003797 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003798 {
Greg Clayton030a2042011-10-14 21:34:45 +00003799 // See if we already parsed this namespace DIE and associated it with a
3800 // uniqued namespace declaration
3801 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3802 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003803 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003804 else
3805 {
3806 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00003807 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3808 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3809 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3810 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00003811 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00003812 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00003813 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003814 GetObjectFile()->GetModule()->LogMessage (log.get(),
3815 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
3816 GetClangASTContext().getASTContext(),
3817 MakeUserID(die->GetOffset()),
3818 namespace_name,
3819 namespace_decl,
3820 namespace_decl->getOriginalNamespace());
Greg Clayton030a2042011-10-14 21:34:45 +00003821 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003822 else
3823 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003824 GetObjectFile()->GetModule()->LogMessage (log.get(),
3825 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
3826 GetClangASTContext().getASTContext(),
3827 MakeUserID(die->GetOffset()),
3828 namespace_decl,
3829 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00003830 }
Greg Clayton030a2042011-10-14 21:34:45 +00003831 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003832
3833 if (namespace_decl)
3834 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3835 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003836 }
3837 }
3838 return NULL;
3839}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003840
3841clang::DeclContext *
Greg Claytoncab36a32011-12-08 05:16:30 +00003842SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Sean Callanan72e49402011-08-05 23:43:37 +00003843{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003844 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3845 if (clang_decl_ctx)
3846 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003847 // If this DIE has a specification, or an abstract origin, then trace to those.
3848
Greg Claytoncab36a32011-12-08 05:16:30 +00003849 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003850 if (die_offset != DW_INVALID_OFFSET)
3851 return GetClangDeclContextForDIEOffset (sc, die_offset);
3852
Greg Claytoncab36a32011-12-08 05:16:30 +00003853 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Sean Callanan72e49402011-08-05 23:43:37 +00003854 if (die_offset != DW_INVALID_OFFSET)
3855 return GetClangDeclContextForDIEOffset (sc, die_offset);
3856
Greg Clayton3bffb082011-12-10 02:15:28 +00003857 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3858 if (log)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003859 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 +00003860 // This is the DIE we want. Parse it, then query our map.
Greg Claytoncab36a32011-12-08 05:16:30 +00003861 bool assert_not_being_parsed = true;
3862 ResolveTypeUID (cu, die, assert_not_being_parsed);
3863
Greg Clayton5cf58b92011-10-05 22:22:08 +00003864 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3865
3866 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003867}
3868
3869clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003870SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003871{
Greg Claytonca512b32011-01-14 04:54:56 +00003872 if (m_clang_tu_decl == NULL)
3873 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003874
Greg Clayton2bc22f82011-09-30 03:20:47 +00003875 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003876
3877 if (decl_ctx_die_copy)
3878 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003879
3880 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003881 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003882
Greg Clayton2bc22f82011-09-30 03:20:47 +00003883 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3884 if (pos != m_die_to_decl_ctx.end())
3885 return pos->second;
3886
3887 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003888 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003889 case DW_TAG_compile_unit:
3890 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003891
Greg Clayton2bc22f82011-09-30 03:20:47 +00003892 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003893 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003894 break;
3895
3896 case DW_TAG_structure_type:
3897 case DW_TAG_union_type:
3898 case DW_TAG_class_type:
3899 {
3900 Type* type = ResolveType (cu, decl_ctx_die);
3901 if (type)
3902 {
3903 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3904 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003905 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003906 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3907 if (decl_ctx)
3908 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003909 }
3910 }
Greg Claytonca512b32011-01-14 04:54:56 +00003911 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003912 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003913
Greg Clayton2bc22f82011-09-30 03:20:47 +00003914 default:
3915 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003916 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003917 }
Greg Clayton7a345282010-11-09 23:46:37 +00003918 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003919}
3920
Greg Clayton2bc22f82011-09-30 03:20:47 +00003921
3922const DWARFDebugInfoEntry *
3923SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3924{
3925 if (cu && die)
3926 {
3927 const DWARFDebugInfoEntry * const decl_die = die;
3928
3929 while (die != NULL)
3930 {
3931 // If this is the original DIE that we are searching for a declaration
3932 // for, then don't look in the cache as we don't want our own decl
3933 // context to be our decl context...
3934 if (decl_die != die)
3935 {
3936 switch (die->Tag())
3937 {
3938 case DW_TAG_compile_unit:
3939 case DW_TAG_namespace:
3940 case DW_TAG_structure_type:
3941 case DW_TAG_union_type:
3942 case DW_TAG_class_type:
3943 return die;
3944
3945 default:
3946 break;
3947 }
3948 }
3949
3950 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3951 if (die_offset != DW_INVALID_OFFSET)
3952 {
3953 DWARFCompileUnit *spec_cu = cu;
3954 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3955 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3956 if (spec_die_decl_ctx_die)
3957 return spec_die_decl_ctx_die;
3958 }
3959
3960 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3961 if (die_offset != DW_INVALID_OFFSET)
3962 {
3963 DWARFCompileUnit *abs_cu = cu;
3964 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3965 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3966 if (abs_die_decl_ctx_die)
3967 return abs_die_decl_ctx_die;
3968 }
3969
3970 die = die->GetParent();
3971 }
3972 }
3973 return NULL;
3974}
3975
3976
Greg Clayton901c5ca2011-12-03 04:40:03 +00003977Symbol *
3978SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3979{
3980 Symbol *objc_class_symbol = NULL;
3981 if (m_obj_file)
3982 {
3983 Symtab *symtab = m_obj_file->GetSymtab();
3984 if (symtab)
3985 {
3986 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3987 eSymbolTypeObjCClass,
3988 Symtab::eDebugNo,
3989 Symtab::eVisibilityAny);
3990 }
3991 }
3992 return objc_class_symbol;
3993}
3994
Greg Claytonc7f03b62012-01-12 04:33:28 +00003995// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3996// then we can end up looking through all class types for a complete type and never find
3997// the full definition. We need to know if this attribute is supported, so we determine
3998// this here and cache th result. We also need to worry about the debug map DWARF file
3999// if we are doing darwin DWARF in .o file debugging.
4000bool
4001SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4002{
4003 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4004 {
4005 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4006 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4007 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4008 else
4009 {
4010 DWARFDebugInfo* debug_info = DebugInfo();
4011 const uint32_t num_compile_units = GetNumCompileUnits();
4012 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4013 {
4014 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4015 if (curr_cu != cu && curr_cu->Supports_DW_AT_APPLE_objc_complete_type())
4016 {
4017 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4018 break;
4019 }
4020 }
4021 }
4022 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4023 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4024 }
4025 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4026}
Greg Clayton901c5ca2011-12-03 04:40:03 +00004027
4028// This function can be used when a DIE is found that is a forward declaration
4029// DIE and we want to try and find a type that has the complete definition.
4030TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00004031SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4032 const ConstString &type_name,
4033 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00004034{
4035
4036 TypeSP type_sp;
4037
Greg Claytonc7f03b62012-01-12 04:33:28 +00004038 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004039 return type_sp;
4040
4041 DIEArray die_offsets;
4042
4043 if (m_using_apple_tables)
4044 {
4045 if (m_apple_types_ap.get())
4046 {
4047 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00004048 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004049 }
4050 }
4051 else
4052 {
4053 if (!m_indexed)
4054 Index ();
4055
4056 m_type_index.Find (type_name, die_offsets);
4057 }
4058
Greg Clayton901c5ca2011-12-03 04:40:03 +00004059 const size_t num_matches = die_offsets.size();
4060
Greg Clayton901c5ca2011-12-03 04:40:03 +00004061 DWARFCompileUnit* type_cu = NULL;
4062 const DWARFDebugInfoEntry* type_die = NULL;
4063 if (num_matches)
4064 {
4065 DWARFDebugInfo* debug_info = DebugInfo();
4066 for (size_t i=0; i<num_matches; ++i)
4067 {
4068 const dw_offset_t die_offset = die_offsets[i];
4069 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4070
4071 if (type_die)
4072 {
4073 bool try_resolving_type = false;
4074
4075 // Don't try and resolve the DIE we are looking for with the DIE itself!
4076 if (type_die != die)
4077 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004078 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00004079 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004080 case DW_TAG_class_type:
4081 case DW_TAG_structure_type:
4082 try_resolving_type = true;
4083 break;
4084 default:
4085 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00004086 }
4087 }
4088
4089 if (try_resolving_type)
4090 {
Sean Callanana9bc0652012-01-19 02:17:40 +00004091 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00004092 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004093
4094 if (try_resolving_type)
4095 {
4096 Type *resolved_type = ResolveType (type_cu, type_die, false);
4097 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4098 {
4099 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4100 MakeUserID(die->GetOffset()),
4101 MakeUserID(curr_cu->GetOffset()),
4102 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4103 MakeUserID(type_die->GetOffset()),
4104 MakeUserID(type_cu->GetOffset()));
4105
Greg Claytonc7f03b62012-01-12 04:33:28 +00004106 if (die)
4107 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00004108 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00004109 break;
4110 }
4111 }
4112 }
4113 }
4114 else
4115 {
4116 if (m_using_apple_tables)
4117 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004118 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4119 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004120 }
4121 }
4122
4123 }
4124 }
4125 return type_sp;
4126}
4127
Greg Clayton80c26302012-02-05 06:12:47 +00004128//----------------------------------------------------------------------
4129// This function helps to ensure that the declaration contexts match for
4130// two different DIEs. Often times debug information will refer to a
4131// forward declaration of a type (the equivalent of "struct my_struct;".
4132// There will often be a declaration of that type elsewhere that has the
4133// full definition. When we go looking for the full type "my_struct", we
4134// will find one or more matches in the accelerator tables and we will
4135// then need to make sure the type was in the same declaration context
4136// as the original DIE. This function can efficiently compare two DIEs
4137// and will return true when the declaration context matches, and false
4138// when they don't.
4139//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00004140bool
4141SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4142 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4143{
4144 assert (die1 != die2);
4145 DWARFDIECollection decl_ctx_1;
4146 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00004147 //The declaration DIE stack is a stack of the declaration context
4148 // DIEs all the way back to the compile unit. If a type "T" is
4149 // declared inside a class "B", and class "B" is declared inside
4150 // a class "A" and class "A" is in a namespace "lldb", and the
4151 // namespace is in a compile unit, there will be a stack of DIEs:
4152 //
4153 // [0] DW_TAG_class_type for "B"
4154 // [1] DW_TAG_class_type for "A"
4155 // [2] DW_TAG_namespace for "lldb"
4156 // [3] DW_TAG_compile_unit for the source file.
4157 //
4158 // We grab both contexts and make sure that everything matches
4159 // all the way back to the compiler unit.
4160
4161 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00004162 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004163 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00004164 // Make sure the context arrays have the same size, otherwise
4165 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00004166 const size_t count1 = decl_ctx_1.Size();
4167 const size_t count2 = decl_ctx_2.Size();
4168 if (count1 != count2)
4169 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00004170
4171 // Make sure the DW_TAG values match all the way back up the the
4172 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00004173 const DWARFDebugInfoEntry *decl_ctx_die1;
4174 const DWARFDebugInfoEntry *decl_ctx_die2;
4175 size_t i;
4176 for (i=0; i<count1; i++)
4177 {
4178 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4179 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4180 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4181 return false;
4182 }
Greg Clayton890ff562012-02-02 05:48:16 +00004183#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00004184
4185 // Make sure the top item in the decl context die array is always
4186 // DW_TAG_compile_unit. If it isn't then something went wrong in
4187 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00004188 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00004189
Greg Clayton890ff562012-02-02 05:48:16 +00004190#endif
4191 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00004192 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00004193 for (i=0; i<count1 - 1; i++)
4194 {
4195 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4196 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4197 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00004198 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00004199 // If the string was from a DW_FORM_strp, then the pointer will often
4200 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00004201 if (name1 == name2)
4202 continue;
4203
4204 // Name pointers are not equal, so only compare the strings
4205 // if both are not NULL.
4206 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00004207 {
Greg Clayton5569e642012-02-06 01:44:54 +00004208 // If the strings don't compare, we are done...
4209 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00004210 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00004211 }
4212 else
4213 {
4214 // One name was NULL while the other wasn't
4215 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00004216 }
4217 }
Greg Clayton80c26302012-02-05 06:12:47 +00004218 // We made it through all of the checks and the declaration contexts
4219 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00004220 return true;
4221}
Greg Clayton220a0072011-12-09 08:48:30 +00004222
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004223// This function can be used when a DIE is found that is a forward declaration
4224// DIE and we want to try and find a type that has the complete definition.
4225TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00004226SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4227 const DWARFDebugInfoEntry *die,
4228 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004229{
4230 TypeSP type_sp;
4231
Greg Clayton1a65ae12011-01-25 23:55:37 +00004232 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004233 return type_sp;
4234
Greg Clayton7f995132011-10-04 22:41:51 +00004235 DIEArray die_offsets;
4236
Greg Clayton97fbc342011-10-20 22:30:33 +00004237 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004238 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004239 if (m_apple_types_ap.get())
4240 {
Greg Claytond1767f02011-12-08 02:13:16 +00004241 if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4242 {
Greg Claytonae920b62012-01-06 00:17:16 +00004243 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
Greg Claytond1767f02011-12-08 02:13:16 +00004244 }
4245 else
4246 {
4247 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4248 }
Greg Clayton97fbc342011-10-20 22:30:33 +00004249 }
Greg Clayton7f995132011-10-04 22:41:51 +00004250 }
4251 else
4252 {
4253 if (!m_indexed)
4254 Index ();
4255
4256 m_type_index.Find (type_name, die_offsets);
4257 }
Greg Clayton7f995132011-10-04 22:41:51 +00004258
4259 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00004260
Greg Clayton934cb052011-12-03 00:27:05 +00004261 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00004262
4263 DWARFCompileUnit* type_cu = NULL;
4264 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00004265 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004266 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004267 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004268 for (size_t i=0; i<num_matches; ++i)
4269 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004270 const dw_offset_t die_offset = die_offsets[i];
4271 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004272
Greg Clayton95d87902011-11-11 03:16:25 +00004273 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004274 {
Greg Clayton934cb052011-12-03 00:27:05 +00004275 bool try_resolving_type = false;
4276
4277 // Don't try and resolve the DIE we are looking for with the DIE itself!
4278 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004279 {
Greg Clayton934cb052011-12-03 00:27:05 +00004280 const dw_tag_t type_die_tag = type_die->Tag();
4281 // Make sure the tags match
4282 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004283 {
Greg Clayton934cb052011-12-03 00:27:05 +00004284 // The tags match, lets try resolving this type
4285 try_resolving_type = true;
4286 }
4287 else
4288 {
4289 // The tags don't match, but we need to watch our for a
4290 // forward declaration for a struct and ("struct foo")
4291 // ends up being a class ("class foo { ... };") or
4292 // vice versa.
4293 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00004294 {
Greg Clayton934cb052011-12-03 00:27:05 +00004295 case DW_TAG_class_type:
4296 // We had a "class foo", see if we ended up with a "struct foo { ... };"
4297 try_resolving_type = (die_tag == DW_TAG_structure_type);
4298 break;
4299 case DW_TAG_structure_type:
4300 // We had a "struct foo", see if we ended up with a "class foo { ... };"
4301 try_resolving_type = (die_tag == DW_TAG_class_type);
4302 break;
4303 default:
4304 // Tags don't match, don't event try to resolve
4305 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00004306 break;
4307 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004308 }
4309 }
Greg Clayton934cb052011-12-03 00:27:05 +00004310
4311 if (try_resolving_type)
4312 {
Greg Clayton890ff562012-02-02 05:48:16 +00004313 // Make sure the decl contexts match all the way up
4314 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
Greg Clayton934cb052011-12-03 00:27:05 +00004315 {
Greg Clayton890ff562012-02-02 05:48:16 +00004316 Type *resolved_type = ResolveType (type_cu, type_die, false);
4317 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4318 {
4319 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4320 MakeUserID(die->GetOffset()),
4321 MakeUserID(curr_cu->GetOffset()),
4322 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4323 MakeUserID(type_die->GetOffset()),
4324 MakeUserID(type_cu->GetOffset()));
4325
4326 m_die_to_type[die] = resolved_type;
Greg Claytonff7692a2012-02-02 18:16:59 +00004327 type_sp = resolved_type->shared_from_this();
Greg Clayton890ff562012-02-02 05:48:16 +00004328 break;
4329 }
Greg Clayton934cb052011-12-03 00:27:05 +00004330 }
4331 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004332 }
Greg Clayton95d87902011-11-11 03:16:25 +00004333 else
4334 {
4335 if (m_using_apple_tables)
4336 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004337 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4338 die_offset, type_name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00004339 }
4340 }
4341
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004342 }
4343 }
4344 return type_sp;
4345}
4346
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004347TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004348SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004349{
4350 TypeSP type_sp;
4351
Greg Clayton1be10fc2010-09-29 01:12:09 +00004352 if (type_is_new_ptr)
4353 *type_is_new_ptr = false;
Sean Callanan5b26f272012-02-04 08:49:35 +00004354
4355 static int depth = -1;
4356
4357 class DepthTaker {
4358 public:
4359 DepthTaker (int &depth) : m_depth(depth) { ++m_depth; }
4360 ~DepthTaker () { --m_depth; }
4361 int &m_depth;
4362 } depth_taker(depth);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004363
Sean Callananc7fbf732010-08-06 00:32:49 +00004364 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004365 if (die != NULL)
4366 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004367 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00004368 if (log)
Sean Callanan5b26f272012-02-04 08:49:35 +00004369 {
4370 const DWARFDebugInfoEntry *context_die;
4371 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4372
4373 std::string name_storage;
4374
4375 const char* qual_name = die->GetQualifiedName(this,
4376 dwarf_cu,
4377 name_storage);
4378
4379 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (depth = %d, die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s '%s'='%s')",
4380 depth,
4381 die->GetOffset(),
4382 context,
4383 context_die->GetOffset(),
Greg Clayton3bffb082011-12-10 02:15:28 +00004384 DW_TAG_value_to_name(die->Tag()),
Sean Callanan5b26f272012-02-04 08:49:35 +00004385 die->GetName(this, dwarf_cu),
4386 qual_name);
4387 }
Greg Clayton3bffb082011-12-10 02:15:28 +00004388//
4389// LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4390// if (log && dwarf_cu)
4391// {
4392// StreamString s;
4393// die->DumpLocation (this, dwarf_cu, s);
Greg Claytone38a5ed2012-01-05 03:57:59 +00004394// GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Greg Clayton3bffb082011-12-10 02:15:28 +00004395//
4396// }
Jim Ingham16746d12011-08-25 23:21:43 +00004397
Greg Clayton594e5ed2010-09-27 21:07:38 +00004398 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004399 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004400 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004401 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004402 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004403 if (type_is_new_ptr)
4404 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405
Greg Clayton594e5ed2010-09-27 21:07:38 +00004406 const dw_tag_t tag = die->Tag();
4407
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004408 bool is_forward_declaration = false;
4409 DWARFDebugInfoEntry::Attributes attributes;
4410 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004411 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004412 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4413 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004414 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004415 Declaration decl;
4416
Greg Clayton4957bf62010-09-30 21:49:03 +00004417 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004418 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004419
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004420 dw_attr_t attr;
4421
4422 switch (tag)
4423 {
4424 case DW_TAG_base_type:
4425 case DW_TAG_pointer_type:
4426 case DW_TAG_reference_type:
4427 case DW_TAG_typedef:
4428 case DW_TAG_const_type:
4429 case DW_TAG_restrict_type:
4430 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004431 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004432 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004433 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004434 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004435
Greg Claytond88d7592010-09-15 08:33:30 +00004436 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004437 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004438 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4439
4440 if (num_attributes > 0)
4441 {
4442 uint32_t i;
4443 for (i=0; i<num_attributes; ++i)
4444 {
4445 attr = attributes.AttributeAtIndex(i);
4446 DWARFFormValue form_value;
4447 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4448 {
4449 switch (attr)
4450 {
4451 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4452 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4453 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4454 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004455
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004456 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004457 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4458 // include the "&"...
4459 if (tag == DW_TAG_reference_type)
4460 {
4461 if (strchr (type_name_cstr, '&') == NULL)
4462 type_name_cstr = NULL;
4463 }
4464 if (type_name_cstr)
4465 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004466 break;
Greg Clayton36909642011-03-15 04:38:20 +00004467 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004468 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4469 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4470 default:
4471 case DW_AT_sibling:
4472 break;
4473 }
4474 }
4475 }
4476 }
4477
Greg Clayton81c22f62011-10-19 18:09:39 +00004478 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 +00004479
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004480 switch (tag)
4481 {
4482 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004483 break;
4484
Greg Claytond4436412011-10-28 21:00:00 +00004485 case DW_TAG_unspecified_type:
4486 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4487 {
4488 resolve_state = Type::eResolveStateFull;
4489 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4490 break;
4491 }
4492 // Fall through to base type below in case we can handle the type there...
4493
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004494 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004495 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004496 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4497 encoding,
4498 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004499 break;
4500
Greg Clayton526e5af2010-11-13 03:52:47 +00004501 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4502 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4503 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4504 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4505 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4506 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004507 }
4508
Greg Claytonc7f03b62012-01-12 04:33:28 +00004509 if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004510 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004511 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4512 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004513 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004514 static ConstString g_objc_type_name_id("id");
4515 static ConstString g_objc_type_name_Class("Class");
4516 static ConstString g_objc_type_name_selector("SEL");
4517
4518 if (type_name_const_str == g_objc_type_name_id)
4519 {
4520 if (log)
4521 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4522 die->GetOffset(),
4523 DW_TAG_value_to_name(die->Tag()),
4524 die->GetName(this, dwarf_cu));
4525 clang_type = ast.GetBuiltInType_objc_id();
4526 encoding_data_type = Type::eEncodingIsUID;
4527 encoding_uid = LLDB_INVALID_UID;
4528 resolve_state = Type::eResolveStateFull;
Greg Clayton526e5af2010-11-13 03:52:47 +00004529
Greg Claytonc7f03b62012-01-12 04:33:28 +00004530 }
4531 else if (type_name_const_str == g_objc_type_name_Class)
4532 {
4533 if (log)
4534 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4535 die->GetOffset(),
4536 DW_TAG_value_to_name(die->Tag()),
4537 die->GetName(this, dwarf_cu));
4538 clang_type = ast.GetBuiltInType_objc_Class();
4539 encoding_data_type = Type::eEncodingIsUID;
4540 encoding_uid = LLDB_INVALID_UID;
4541 resolve_state = Type::eResolveStateFull;
4542 }
4543 else if (type_name_const_str == g_objc_type_name_selector)
4544 {
4545 if (log)
4546 GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4547 die->GetOffset(),
4548 DW_TAG_value_to_name(die->Tag()),
4549 die->GetName(this, dwarf_cu));
4550 clang_type = ast.GetBuiltInType_objc_selector();
4551 encoding_data_type = Type::eEncodingIsUID;
4552 encoding_uid = LLDB_INVALID_UID;
4553 resolve_state = Type::eResolveStateFull;
4554 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004555 }
4556 }
4557
Greg Clayton81c22f62011-10-19 18:09:39 +00004558 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004559 this,
4560 type_name_const_str,
4561 byte_size,
4562 NULL,
4563 encoding_uid,
4564 encoding_data_type,
4565 &decl,
4566 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004567 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004568
Greg Clayton594e5ed2010-09-27 21:07:38 +00004569 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004570
4571// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4572// if (encoding_type != NULL)
4573// {
4574// if (encoding_type != DIE_IS_BEING_PARSED)
4575// type_sp->SetEncodingType(encoding_type);
4576// else
4577// m_indirect_fixups.push_back(type_sp.get());
4578// }
4579 }
4580 break;
4581
4582 case DW_TAG_structure_type:
4583 case DW_TAG_union_type:
4584 case DW_TAG_class_type:
4585 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004586 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004587 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004588
Greg Clayton9e409562010-07-28 02:04:09 +00004589 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004590 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004591 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004592 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004593 if (num_attributes > 0)
4594 {
4595 uint32_t i;
4596 for (i=0; i<num_attributes; ++i)
4597 {
4598 attr = attributes.AttributeAtIndex(i);
4599 DWARFFormValue form_value;
4600 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4601 {
4602 switch (attr)
4603 {
Greg Clayton9e409562010-07-28 02:04:09 +00004604 case DW_AT_decl_file:
Greg Claytonc7f03b62012-01-12 04:33:28 +00004605 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4606 {
4607 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4608 // point to the compile unit file, so we clear this invalid value
4609 // so that we can still unique types efficiently.
4610 decl.SetFile(FileSpec ("<invalid>", false));
4611 }
4612 else
4613 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
Greg Clayton9e409562010-07-28 02:04:09 +00004614 break;
4615
4616 case DW_AT_decl_line:
4617 decl.SetLine(form_value.Unsigned());
4618 break;
4619
4620 case DW_AT_decl_column:
4621 decl.SetColumn(form_value.Unsigned());
4622 break;
4623
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004624 case DW_AT_name:
4625 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004626 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004627 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004628
4629 case DW_AT_byte_size:
4630 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004631 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004632 break;
4633
4634 case DW_AT_accessibility:
4635 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4636 break;
4637
4638 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004639 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004640 break;
4641
4642 case DW_AT_APPLE_runtime_class:
4643 class_language = (LanguageType)form_value.Signed();
4644 break;
4645
Greg Clayton18774842011-11-29 23:40:34 +00004646 case DW_AT_APPLE_objc_complete_type:
4647 is_complete_objc_class = form_value.Signed();
4648 break;
4649
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004650 case DW_AT_allocated:
4651 case DW_AT_associated:
4652 case DW_AT_data_location:
4653 case DW_AT_description:
4654 case DW_AT_start_scope:
4655 case DW_AT_visibility:
4656 default:
4657 case DW_AT_sibling:
4658 break;
4659 }
4660 }
4661 }
4662 }
4663
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004664 UniqueDWARFASTType unique_ast_entry;
4665 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004666 {
Greg Claytone576ab22011-02-15 00:19:15 +00004667 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00004668 this,
4669 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00004670 die,
4671 decl,
Greg Clayton36909642011-03-15 04:38:20 +00004672 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00004673 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00004674 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004675 // We have already parsed this type or from another
4676 // compile unit. GCC loves to use the "one definition
4677 // rule" which can result in multiple definitions
4678 // of the same class over and over in each compile
4679 // unit.
4680 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004681 if (type_sp)
4682 {
Greg Clayton4272cc72011-02-02 02:24:04 +00004683 m_die_to_type[die] = type_sp.get();
4684 return type_sp;
4685 }
4686 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004687 }
4688
Greg Clayton81c22f62011-10-19 18:09:39 +00004689 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 +00004690
4691 int tag_decl_kind = -1;
4692 AccessType default_accessibility = eAccessNone;
4693 if (tag == DW_TAG_structure_type)
4694 {
4695 tag_decl_kind = clang::TTK_Struct;
4696 default_accessibility = eAccessPublic;
4697 }
4698 else if (tag == DW_TAG_union_type)
4699 {
4700 tag_decl_kind = clang::TTK_Union;
4701 default_accessibility = eAccessPublic;
4702 }
4703 else if (tag == DW_TAG_class_type)
4704 {
4705 tag_decl_kind = clang::TTK_Class;
4706 default_accessibility = eAccessPrivate;
4707 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00004708
4709 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4710 die->HasChildren() == false &&
4711 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4712 {
4713 // Work around an issue with clang at the moment where
4714 // forward declarations for objective C classes are emitted
4715 // as:
4716 // DW_TAG_structure_type [2]
4717 // DW_AT_name( "ForwardObjcClass" )
4718 // DW_AT_byte_size( 0x00 )
4719 // DW_AT_decl_file( "..." )
4720 // DW_AT_decl_line( 1 )
4721 //
4722 // Note that there is no DW_AT_declaration and there are
4723 // no children, and the byte size is zero.
4724 is_forward_declaration = true;
4725 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004726
Greg Clayton18774842011-11-29 23:40:34 +00004727 if (class_language == eLanguageTypeObjC)
4728 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00004729 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
Greg Clayton901c5ca2011-12-03 04:40:03 +00004730 {
4731 // We have a valid eSymbolTypeObjCClass class symbol whose
4732 // name matches the current objective C class that we
4733 // are trying to find and this DIE isn't the complete
4734 // definition (we checked is_complete_objc_class above and
4735 // know it is false), so the real definition is in here somewhere
Greg Claytonc7f03b62012-01-12 04:33:28 +00004736 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004737
Greg Clayton901c5ca2011-12-03 04:40:03 +00004738 if (!type_sp && m_debug_map_symfile)
4739 {
4740 // We weren't able to find a full declaration in
4741 // this DWARF, see if we have a declaration anywhere
4742 // else...
Greg Claytonc7f03b62012-01-12 04:33:28 +00004743 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00004744 }
4745
4746 if (type_sp)
4747 {
4748 if (log)
4749 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004750 GetObjectFile()->GetModule()->LogMessage (log.get(),
4751 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4752 this,
4753 die->GetOffset(),
4754 DW_TAG_value_to_name(tag),
4755 type_name_cstr,
4756 type_sp->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00004757 }
4758
4759 // We found a real definition for this type elsewhere
4760 // so lets use it and cache the fact that we found
4761 // a complete type for this die
4762 m_die_to_type[die] = type_sp.get();
4763 return type_sp;
4764 }
4765 }
4766 }
4767
4768
4769 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004770 {
4771 // We have a forward declaration to a type and we need
4772 // to try and find a full declaration. We look in the
4773 // current type index just in case we have a forward
4774 // declaration followed by an actual declarations in the
4775 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00004776 if (log)
4777 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004778 GetObjectFile()->GetModule()->LogMessage (log.get(),
4779 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
4780 this,
4781 die->GetOffset(),
4782 DW_TAG_value_to_name(tag),
4783 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00004784 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004785
4786 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4787
4788 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004789 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004790 // We weren't able to find a full declaration in
4791 // this DWARF, see if we have a declaration anywhere
4792 // else...
4793 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004794 }
4795
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004796 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004797 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00004798 if (log)
4799 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00004800 GetObjectFile()->GetModule()->LogMessage (log.get(),
4801 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
4802 this,
4803 die->GetOffset(),
4804 DW_TAG_value_to_name(tag),
4805 type_name_cstr,
4806 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00004807 }
4808
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004809 // We found a real definition for this type elsewhere
4810 // so lets use it and cache the fact that we found
4811 // a complete type for this die
4812 m_die_to_type[die] = type_sp.get();
4813 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004814 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004815 }
4816 assert (tag_decl_kind != -1);
4817 bool clang_type_was_created = false;
4818 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4819 if (clang_type == NULL)
4820 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004821 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton55561e92011-10-26 03:31:36 +00004822 if (accessibility == eAccessNone && decl_ctx)
4823 {
4824 // Check the decl context that contains this class/struct/union.
4825 // If it is a class we must give it an accessability.
4826 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4827 if (DeclKindIsCXXClass (containing_decl_kind))
4828 accessibility = default_accessibility;
4829 }
4830
Greg Claytonf0705c82011-10-22 03:33:13 +00004831 if (type_name_cstr && strchr (type_name_cstr, '<'))
4832 {
4833 ClangASTContext::TemplateParameterInfos template_param_infos;
4834 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4835 {
4836 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004837 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004838 type_name_cstr,
4839 tag_decl_kind,
4840 template_param_infos);
4841
4842 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4843 class_template_decl,
4844 tag_decl_kind,
4845 template_param_infos);
4846 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4847 clang_type_was_created = true;
4848 }
4849 }
4850
4851 if (!clang_type_was_created)
4852 {
4853 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004854 clang_type = ast.CreateRecordType (decl_ctx,
4855 accessibility,
4856 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004857 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004858 class_language);
4859 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004860 }
4861
4862 // Store a forward declaration to this class type in case any
4863 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004864 // types for function prototypes.
4865 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004866 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004867 this,
4868 type_name_const_str,
4869 byte_size,
4870 NULL,
4871 LLDB_INVALID_UID,
4872 Type::eEncodingIsUID,
4873 &decl,
4874 clang_type,
4875 Type::eResolveStateForward));
4876
4877
4878 // Add our type to the unique type map so we don't
4879 // end up creating many copies of the same type over
4880 // and over in the ASTContext for our module
4881 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004882 unique_ast_entry.m_symfile = this;
4883 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004884 unique_ast_entry.m_die = die;
4885 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00004886 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4887 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004888
Sean Callanan12014a02011-12-08 23:45:45 +00004889 if (!is_forward_declaration)
4890 {
4891 if (die->HasChildren() == false)
4892 {
4893 // No children for this struct/union/class, lets finish it
4894 ast.StartTagDeclarationDefinition (clang_type);
4895 ast.CompleteTagDeclarationDefinition (clang_type);
4896 }
4897 else if (clang_type_was_created)
4898 {
4899 // Leave this as a forward declaration until we need
4900 // to know the details of the type. lldb_private::Type
4901 // will automatically call the SymbolFile virtual function
4902 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
4903 // When the definition needs to be defined.
4904 m_forward_decl_die_to_clang_type[die] = clang_type;
4905 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
4906 ClangASTContext::SetHasExternalStorage (clang_type, true);
4907 }
Greg Claytonc615ce42010-11-09 04:42:43 +00004908 }
Greg Claytoncab36a32011-12-08 05:16:30 +00004909
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004910 }
4911 break;
4912
4913 case DW_TAG_enumeration_type:
4914 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004915 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004916 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004917
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004918 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004919
Greg Claytond88d7592010-09-15 08:33:30 +00004920 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004921 if (num_attributes > 0)
4922 {
4923 uint32_t i;
4924
4925 for (i=0; i<num_attributes; ++i)
4926 {
4927 attr = attributes.AttributeAtIndex(i);
4928 DWARFFormValue form_value;
4929 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4930 {
4931 switch (attr)
4932 {
Greg Clayton7a345282010-11-09 23:46:37 +00004933 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4934 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4935 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004936 case DW_AT_name:
4937 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004938 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004939 break;
Greg Clayton7a345282010-11-09 23:46:37 +00004940 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004941 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00004942 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4943 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004944 case DW_AT_allocated:
4945 case DW_AT_associated:
4946 case DW_AT_bit_stride:
4947 case DW_AT_byte_stride:
4948 case DW_AT_data_location:
4949 case DW_AT_description:
4950 case DW_AT_start_scope:
4951 case DW_AT_visibility:
4952 case DW_AT_specification:
4953 case DW_AT_abstract_origin:
4954 case DW_AT_sibling:
4955 break;
4956 }
4957 }
4958 }
4959
Greg Clayton81c22f62011-10-19 18:09:39 +00004960 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 +00004961
Greg Clayton1be10fc2010-09-29 01:12:09 +00004962 clang_type_t enumerator_clang_type = NULL;
4963 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4964 if (clang_type == NULL)
4965 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004966 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
4967 DW_ATE_signed,
4968 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00004969 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00004970 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00004971 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004972 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004973 }
4974 else
4975 {
4976 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
4977 assert (enumerator_clang_type != NULL);
4978 }
4979
Greg Claytona2721472011-06-25 00:44:06 +00004980 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
4981
Greg Clayton81c22f62011-10-19 18:09:39 +00004982 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004983 this,
4984 type_name_const_str,
4985 byte_size,
4986 NULL,
4987 encoding_uid,
4988 Type::eEncodingIsUID,
4989 &decl,
4990 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004991 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004992
Greg Clayton6beaaa62011-01-17 03:46:26 +00004993 ast.StartTagDeclarationDefinition (clang_type);
4994 if (die->HasChildren())
4995 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004996 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
4997 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00004998 }
4999 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005000 }
5001 }
5002 break;
5003
Jim Inghamb0be4422010-08-12 01:20:14 +00005004 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005005 case DW_TAG_subprogram:
5006 case DW_TAG_subroutine_type:
5007 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005008 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005009 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005010
5011 const char *mangled = NULL;
5012 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00005013 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005014 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00005015 bool is_static = false;
5016 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00005017 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00005018 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00005019 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5020 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00005021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005022 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00005023 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005024
5025
Greg Claytond88d7592010-09-15 08:33:30 +00005026 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005027 if (num_attributes > 0)
5028 {
5029 uint32_t i;
5030 for (i=0; i<num_attributes; ++i)
5031 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00005032 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005033 DWARFFormValue form_value;
5034 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5035 {
5036 switch (attr)
5037 {
5038 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5039 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5040 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5041 case DW_AT_name:
5042 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005043 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005044 break;
5045
5046 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5047 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005048 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005049 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00005050 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
5051 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00005052 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00005053 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5054
Greg Claytonf51de672010-10-01 02:31:07 +00005055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005056 case DW_AT_external:
5057 if (form_value.Unsigned())
5058 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00005059 if (storage == clang::SC_None)
5060 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005061 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00005062 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005063 }
5064 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005065
Greg Clayton72da3972011-08-16 18:40:23 +00005066 case DW_AT_specification:
5067 specification_die_offset = form_value.Reference(dwarf_cu);
5068 break;
5069
5070 case DW_AT_abstract_origin:
5071 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5072 break;
5073
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005074 case DW_AT_allocated:
5075 case DW_AT_associated:
5076 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005077 case DW_AT_calling_convention:
5078 case DW_AT_data_location:
5079 case DW_AT_elemental:
5080 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005081 case DW_AT_frame_base:
5082 case DW_AT_high_pc:
5083 case DW_AT_low_pc:
5084 case DW_AT_object_pointer:
5085 case DW_AT_prototyped:
5086 case DW_AT_pure:
5087 case DW_AT_ranges:
5088 case DW_AT_recursive:
5089 case DW_AT_return_addr:
5090 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005091 case DW_AT_start_scope:
5092 case DW_AT_static_link:
5093 case DW_AT_trampoline:
5094 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005095 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005096 case DW_AT_description:
5097 case DW_AT_sibling:
5098 break;
5099 }
5100 }
5101 }
Greg Clayton24739922010-10-13 03:15:28 +00005102 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005103
Greg Clayton81c22f62011-10-19 18:09:39 +00005104 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 +00005105
Greg Clayton24739922010-10-13 03:15:28 +00005106 clang_type_t return_clang_type = NULL;
5107 Type *func_type = NULL;
5108
5109 if (type_die_offset != DW_INVALID_OFFSET)
5110 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00005111
Greg Clayton24739922010-10-13 03:15:28 +00005112 if (func_type)
Greg Clayton42ce2f32011-12-12 21:50:19 +00005113 return_clang_type = func_type->GetClangForwardType();
Greg Clayton24739922010-10-13 03:15:28 +00005114 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005115 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005116
Greg Claytonf51de672010-10-01 02:31:07 +00005117
Greg Clayton24739922010-10-13 03:15:28 +00005118 std::vector<clang_type_t> function_param_types;
5119 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005120
Greg Clayton24739922010-10-13 03:15:28 +00005121 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00005122
Greg Claytoncb5860a2011-10-13 23:49:28 +00005123 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5124 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00005125 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5126
Greg Claytonf0705c82011-10-22 03:33:13 +00005127 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00005128 // Start off static. This will be set to false in ParseChildParameters(...)
5129 // if we find a "this" paramters as the first parameter
5130 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00005131 is_static = true;
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005132 ClangASTContext::TemplateParameterInfos template_param_infos;
5133
Greg Clayton24739922010-10-13 03:15:28 +00005134 if (die->HasChildren())
5135 {
Greg Clayton0fffff52010-09-24 05:15:53 +00005136 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005137 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00005138 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005139 dwarf_cu,
5140 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00005141 skip_artificial,
5142 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005143 type_list,
5144 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00005145 function_param_decls,
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005146 type_quals,
5147 template_param_infos);
Greg Clayton24739922010-10-13 03:15:28 +00005148 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005149
Greg Clayton24739922010-10-13 03:15:28 +00005150 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005151 clang_type = ast.CreateFunctionType (return_clang_type,
5152 &function_param_types[0],
5153 function_param_types.size(),
5154 is_variadic,
5155 type_quals);
5156
Greg Clayton24739922010-10-13 03:15:28 +00005157 if (type_name_cstr)
5158 {
Sean Callanan5b26f272012-02-04 08:49:35 +00005159 if (die->GetOffset() == 0xaeaba)
5160 fprintf(stderr, "This is the one!");
5161
Greg Clayton24739922010-10-13 03:15:28 +00005162 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00005163 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005164 {
Greg Clayton7c810422012-01-18 23:40:49 +00005165 ConstString class_name;
Greg Claytone42ae842012-01-19 03:24:53 +00005166 ConstString class_name_no_category;
5167 if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
Greg Clayton0fffff52010-09-24 05:15:53 +00005168 {
Greg Claytone42ae842012-01-19 03:24:53 +00005169 // Use the class name with no category if there is one
5170 if (class_name_no_category)
5171 class_name = class_name_no_category;
5172
Greg Clayton24739922010-10-13 03:15:28 +00005173 SymbolContext empty_sc;
5174 clang_type_t class_opaque_type = NULL;
Greg Clayton7c810422012-01-18 23:40:49 +00005175 if (class_name)
Greg Clayton0fffff52010-09-24 05:15:53 +00005176 {
Greg Clayton24739922010-10-13 03:15:28 +00005177 TypeList types;
Greg Clayton278a16b2012-01-19 00:52:59 +00005178 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
Greg Claytonc7f03b62012-01-12 04:33:28 +00005179
5180 if (complete_objc_class_type_sp)
Greg Clayton0fffff52010-09-24 05:15:53 +00005181 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00005182 clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5183 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5184 class_opaque_type = type_clang_forward_type;
Greg Clayton0fffff52010-09-24 05:15:53 +00005185 }
Greg Clayton24739922010-10-13 03:15:28 +00005186 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005187
Greg Clayton24739922010-10-13 03:15:28 +00005188 if (class_opaque_type)
5189 {
5190 // If accessibility isn't set to anything valid, assume public for
5191 // now...
5192 if (accessibility == eAccessNone)
5193 accessibility = eAccessPublic;
5194
5195 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005196 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5197 type_name_cstr,
5198 clang_type,
5199 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005200 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00005201 type_handled = objc_method_decl != NULL;
5202 }
5203 }
Greg Clayton5113dc82011-08-12 06:47:54 +00005204 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00005205 {
5206 // Look at the parent of this DIE and see if is is
5207 // a class or struct and see if this is actually a
5208 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00005209 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00005210 if (class_type)
5211 {
Greg Clayton72da3972011-08-16 18:40:23 +00005212 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00005213 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005214 // We have a specification which we are going to base our function
5215 // prototype off of, so we need this type to be completed so that the
5216 // m_die_to_decl_ctx for the method in the specification has a valid
5217 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005218 class_type->GetClangForwardType();
Greg Clayton72da3972011-08-16 18:40:23 +00005219 // If we have a specification, then the function type should have been
5220 // made with the specification and not with this die.
5221 DWARFCompileUnitSP spec_cu_sp;
5222 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005223 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
5224 if (spec_clang_decl_ctx)
5225 {
5226 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5227 }
5228 else
Jim Inghamc1663042011-09-29 22:12:35 +00005229 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005230 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5231 MakeUserID(die->GetOffset()),
5232 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005233 }
Greg Clayton72da3972011-08-16 18:40:23 +00005234 type_handled = true;
5235 }
5236 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5237 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005238 // We have a specification which we are going to base our function
5239 // prototype off of, so we need this type to be completed so that the
5240 // m_die_to_decl_ctx for the method in the abstract origin has a valid
5241 // clang decl context.
Greg Clayton8eb732e2011-12-13 04:34:06 +00005242 class_type->GetClangForwardType();
Greg Clayton5cf58b92011-10-05 22:22:08 +00005243
Greg Clayton72da3972011-08-16 18:40:23 +00005244 DWARFCompileUnitSP abs_cu_sp;
5245 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00005246 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
5247 if (abs_clang_decl_ctx)
5248 {
5249 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5250 }
5251 else
Jim Inghamc1663042011-09-29 22:12:35 +00005252 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005253 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5254 MakeUserID(die->GetOffset()),
5255 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00005256 }
Greg Clayton72da3972011-08-16 18:40:23 +00005257 type_handled = true;
5258 }
5259 else
5260 {
5261 clang_type_t class_opaque_type = class_type->GetClangForwardType();
5262 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00005263 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005264 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00005265 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005266 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5267 // in the DWARF for C++ methods... Default to public for now...
5268 if (accessibility == eAccessNone)
5269 accessibility = eAccessPublic;
5270
5271 if (!is_static && !die->HasChildren())
5272 {
5273 // We have a C++ member function with no children (this pointer!)
5274 // and clang will get mad if we try and make a function that isn't
5275 // well formed in the DWARF, so we will just skip it...
5276 type_handled = true;
5277 }
5278 else
5279 {
5280 clang::CXXMethodDecl *cxx_method_decl;
5281 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00005282 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 +00005283 type_name_cstr,
5284 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00005285 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00005286 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5287 m_obj_file->GetFileSpec().GetFilename().GetCString());
5288
Sean Callananc1b732d2011-11-01 18:07:13 +00005289 const bool is_attr_used = false;
5290
Greg Clayton20568dd2011-10-13 23:13:20 +00005291 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5292 type_name_cstr,
5293 clang_type,
5294 accessibility,
5295 is_virtual,
5296 is_static,
5297 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00005298 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00005299 is_attr_used,
5300 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00005301 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5302
Greg Claytonf49e65a2011-11-10 18:31:53 +00005303 Host::SetCrashDescription (NULL);
5304
Greg Clayton20568dd2011-10-13 23:13:20 +00005305 type_handled = cxx_method_decl != NULL;
5306 }
Greg Clayton72da3972011-08-16 18:40:23 +00005307 }
5308 else
5309 {
Greg Clayton20568dd2011-10-13 23:13:20 +00005310 // We were asked to parse the type for a method in a class, yet the
5311 // class hasn't been asked to complete itself through the
5312 // clang::ExternalASTSource protocol, so we need to just have the
5313 // class complete itself and do things the right way, then our
5314 // DIE should then have an entry in the m_die_to_type map. First
5315 // we need to modify the m_die_to_type so it doesn't think we are
5316 // trying to parse this DIE anymore...
5317 m_die_to_type[die] = NULL;
5318
5319 // Now we get the full type to force our class type to complete itself
5320 // using the clang::ExternalASTSource protocol which will parse all
5321 // base classes and all methods (including the method for this DIE).
5322 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00005323
Greg Clayton20568dd2011-10-13 23:13:20 +00005324 // The type for this DIE should have been filled in the function call above
5325 type_ptr = m_die_to_type[die];
5326 if (type_ptr)
5327 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005328 type_sp = type_ptr->shared_from_this();
Greg Clayton20568dd2011-10-13 23:13:20 +00005329 break;
5330 }
Greg Clayton72da3972011-08-16 18:40:23 +00005331 }
Greg Clayton931180e2011-01-27 06:44:37 +00005332 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005333 }
5334 }
Greg Clayton0fffff52010-09-24 05:15:53 +00005335 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005336 }
Greg Clayton24739922010-10-13 03:15:28 +00005337
5338 if (!type_handled)
5339 {
5340 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00005341 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5342 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005343 clang_type,
5344 storage,
5345 is_inline);
Greg Clayton3c2e3ae2012-02-06 06:42:51 +00005346
5347// if (template_param_infos.GetSize() > 0)
5348// {
5349// clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5350// function_decl,
5351// type_name_cstr,
5352// template_param_infos);
5353//
5354// ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5355// func_template_decl,
5356// template_param_infos);
5357// }
Greg Clayton24739922010-10-13 03:15:28 +00005358 // Add the decl to our DIE to decl context map
5359 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00005360 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00005361 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005362 ast.SetFunctionParameters (function_decl,
5363 &function_param_decls.front(),
5364 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00005365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005366 }
Greg Clayton81c22f62011-10-19 18:09:39 +00005367 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005368 this,
5369 type_name_const_str,
5370 0,
5371 NULL,
5372 LLDB_INVALID_UID,
5373 Type::eEncodingIsUID,
5374 &decl,
5375 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005376 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00005377 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005378 }
5379 break;
5380
5381 case DW_TAG_array_type:
5382 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005383 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00005384 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005385
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005386 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005387 int64_t first_index = 0;
5388 uint32_t byte_stride = 0;
5389 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00005390 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005391
5392 if (num_attributes > 0)
5393 {
5394 uint32_t i;
5395 for (i=0; i<num_attributes; ++i)
5396 {
5397 attr = attributes.AttributeAtIndex(i);
5398 DWARFFormValue form_value;
5399 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5400 {
5401 switch (attr)
5402 {
5403 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5404 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5405 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5406 case DW_AT_name:
5407 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005408 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005409 break;
5410
5411 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005412 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005413 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5414 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005415 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005416 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005417 case DW_AT_allocated:
5418 case DW_AT_associated:
5419 case DW_AT_data_location:
5420 case DW_AT_description:
5421 case DW_AT_ordering:
5422 case DW_AT_start_scope:
5423 case DW_AT_visibility:
5424 case DW_AT_specification:
5425 case DW_AT_abstract_origin:
5426 case DW_AT_sibling:
5427 break;
5428 }
5429 }
5430 }
5431
Greg Clayton81c22f62011-10-19 18:09:39 +00005432 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 +00005433
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005434 Type *element_type = ResolveTypeUID(type_die_offset);
5435
5436 if (element_type)
5437 {
5438 std::vector<uint64_t> element_orders;
5439 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005440 // We have an array that claims to have no members, lets give it at least one member...
5441 if (element_orders.empty())
5442 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005443 if (byte_stride == 0 && bit_stride == 0)
5444 byte_stride = element_type->GetByteSize();
Greg Clayton42ce2f32011-12-12 21:50:19 +00005445 clang_type_t array_element_type = element_type->GetClangForwardType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005446 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5447 uint64_t num_elements = 0;
5448 std::vector<uint64_t>::const_reverse_iterator pos;
5449 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5450 for (pos = element_orders.rbegin(); pos != end; ++pos)
5451 {
5452 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005453 clang_type = ast.CreateArrayType (array_element_type,
5454 num_elements,
5455 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005456 array_element_type = clang_type;
5457 array_element_bit_stride = array_element_bit_stride * num_elements;
5458 }
5459 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005460 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005461 this,
5462 empty_name,
5463 array_element_bit_stride / 8,
5464 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005465 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005466 Type::eEncodingIsUID,
5467 &decl,
5468 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005469 Type::eResolveStateFull));
5470 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005471 }
5472 }
5473 }
5474 break;
5475
Greg Clayton9b81a312010-06-12 01:20:30 +00005476 case DW_TAG_ptr_to_member_type:
5477 {
5478 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5479 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5480
Greg Claytond88d7592010-09-15 08:33:30 +00005481 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005482
5483 if (num_attributes > 0) {
5484 uint32_t i;
5485 for (i=0; i<num_attributes; ++i)
5486 {
5487 attr = attributes.AttributeAtIndex(i);
5488 DWARFFormValue form_value;
5489 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5490 {
5491 switch (attr)
5492 {
5493 case DW_AT_type:
5494 type_die_offset = form_value.Reference(dwarf_cu); break;
5495 case DW_AT_containing_type:
5496 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5497 }
5498 }
5499 }
5500
5501 Type *pointee_type = ResolveTypeUID(type_die_offset);
5502 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5503
Greg Clayton526e5af2010-11-13 03:52:47 +00005504 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5505 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005506
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005507 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5508 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005509
Greg Clayton526e5af2010-11-13 03:52:47 +00005510 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5511 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005512
Greg Clayton81c22f62011-10-19 18:09:39 +00005513 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005514 this,
5515 type_name_const_str,
5516 byte_size,
5517 NULL,
5518 LLDB_INVALID_UID,
5519 Type::eEncodingIsUID,
5520 NULL,
5521 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005522 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005523 }
5524
5525 break;
5526 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005527 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005528 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005529 break;
5530 }
5531
5532 if (type_sp.get())
5533 {
5534 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5535 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5536
5537 SymbolContextScope * symbol_context_scope = NULL;
5538 if (sc_parent_tag == DW_TAG_compile_unit)
5539 {
5540 symbol_context_scope = sc.comp_unit;
5541 }
5542 else if (sc.function != NULL)
5543 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005544 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005545 if (symbol_context_scope == NULL)
5546 symbol_context_scope = sc.function;
5547 }
5548
5549 if (symbol_context_scope != NULL)
5550 {
5551 type_sp->SetSymbolContextScope(symbol_context_scope);
5552 }
5553
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005554 // We are ready to put this type into the uniqued list up at the module level
5555 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005556
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005557 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005558 }
5559 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005560 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005561 {
Greg Claytone1cd1be2012-01-29 20:56:30 +00005562 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005563 }
5564 }
5565 return type_sp;
5566}
5567
5568size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005569SymbolFileDWARF::ParseTypes
5570(
5571 const SymbolContext& sc,
5572 DWARFCompileUnit* dwarf_cu,
5573 const DWARFDebugInfoEntry *die,
5574 bool parse_siblings,
5575 bool parse_children
5576)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005577{
5578 size_t types_added = 0;
5579 while (die != NULL)
5580 {
5581 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005582 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005583 {
5584 if (type_is_new)
5585 ++types_added;
5586 }
5587
5588 if (parse_children && die->HasChildren())
5589 {
5590 if (die->Tag() == DW_TAG_subprogram)
5591 {
5592 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005593 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005594 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5595 }
5596 else
5597 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5598 }
5599
5600 if (parse_siblings)
5601 die = die->GetSibling();
5602 else
5603 die = NULL;
5604 }
5605 return types_added;
5606}
5607
5608
5609size_t
5610SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5611{
5612 assert(sc.comp_unit && sc.function);
5613 size_t functions_added = 0;
5614 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5615 if (dwarf_cu)
5616 {
5617 dw_offset_t function_die_offset = sc.function->GetID();
5618 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5619 if (function_die)
5620 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005621 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005622 }
5623 }
5624
5625 return functions_added;
5626}
5627
5628
5629size_t
5630SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5631{
5632 // At least a compile unit must be valid
5633 assert(sc.comp_unit);
5634 size_t types_added = 0;
5635 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5636 if (dwarf_cu)
5637 {
5638 if (sc.function)
5639 {
5640 dw_offset_t function_die_offset = sc.function->GetID();
5641 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5642 if (func_die && func_die->HasChildren())
5643 {
5644 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5645 }
5646 }
5647 else
5648 {
5649 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5650 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5651 {
5652 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5653 }
5654 }
5655 }
5656
5657 return types_added;
5658}
5659
5660size_t
5661SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5662{
5663 if (sc.comp_unit != NULL)
5664 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005665 DWARFDebugInfo* info = DebugInfo();
5666 if (info == NULL)
5667 return 0;
5668
5669 uint32_t cu_idx = UINT32_MAX;
5670 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005671
5672 if (dwarf_cu == NULL)
5673 return 0;
5674
5675 if (sc.function)
5676 {
5677 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00005678
5679 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 +00005680 if (func_lo_pc != DW_INVALID_ADDRESS)
5681 {
5682 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00005683
Greg Claytone38a5ed2012-01-05 03:57:59 +00005684 // Let all blocks know they have parse all their variables
5685 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5686 return num_variables;
5687 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005688 }
5689 else if (sc.comp_unit)
5690 {
5691 uint32_t vars_added = 0;
5692 VariableListSP variables (sc.comp_unit->GetVariableList(false));
5693
5694 if (variables.get() == NULL)
5695 {
5696 variables.reset(new VariableList());
5697 sc.comp_unit->SetVariableList(variables);
5698
Greg Claytond4a2b372011-09-12 23:21:58 +00005699 DWARFCompileUnit* match_dwarf_cu = NULL;
5700 const DWARFDebugInfoEntry* die = NULL;
5701 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00005702 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005703 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005704 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00005705 {
5706 DWARFMappedHash::DIEInfoArray hash_data_array;
5707 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5708 dwarf_cu->GetNextCompileUnitOffset(),
5709 hash_data_array))
5710 {
5711 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
5712 }
5713 }
Greg Clayton7f995132011-10-04 22:41:51 +00005714 }
5715 else
5716 {
5717 // Index if we already haven't to make sure the compile units
5718 // get indexed and make their global DIE index list
5719 if (!m_indexed)
5720 Index ();
5721
5722 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5723 dwarf_cu->GetNextCompileUnitOffset(),
5724 die_offsets);
5725 }
5726
5727 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00005728 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005729 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005730 DWARFDebugInfo* debug_info = DebugInfo();
5731 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005732 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005733 const dw_offset_t die_offset = die_offsets[i];
5734 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00005735 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00005736 {
Greg Clayton95d87902011-11-11 03:16:25 +00005737 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5738 if (var_sp)
5739 {
5740 variables->AddVariableIfUnique (var_sp);
5741 ++vars_added;
5742 }
Greg Claytond4a2b372011-09-12 23:21:58 +00005743 }
Greg Clayton95d87902011-11-11 03:16:25 +00005744 else
5745 {
5746 if (m_using_apple_tables)
5747 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00005748 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 +00005749 }
5750 }
5751
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005752 }
5753 }
5754 }
5755 return vars_added;
5756 }
5757 }
5758 return 0;
5759}
5760
5761
5762VariableSP
5763SymbolFileDWARF::ParseVariableDIE
5764(
5765 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005766 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005767 const DWARFDebugInfoEntry *die,
5768 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005769)
5770{
5771
Greg Clayton83c5cd92010-11-14 22:13:40 +00005772 VariableSP var_sp (m_die_to_variable_sp[die]);
5773 if (var_sp)
5774 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005775
5776 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00005777
5778 if ((tag == DW_TAG_variable) ||
5779 (tag == DW_TAG_constant) ||
5780 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005781 {
Greg Clayton7f995132011-10-04 22:41:51 +00005782 DWARFDebugInfoEntry::Attributes attributes;
5783 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5784 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005785 {
Greg Clayton7f995132011-10-04 22:41:51 +00005786 const char *name = NULL;
5787 const char *mangled = NULL;
5788 Declaration decl;
5789 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00005790 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00005791 DWARFExpression location;
5792 bool is_external = false;
5793 bool is_artificial = false;
5794 bool location_is_const_value_data = false;
5795 AccessType accessibility = eAccessNone;
5796
5797 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005798 {
Greg Clayton7f995132011-10-04 22:41:51 +00005799 dw_attr_t attr = attributes.AttributeAtIndex(i);
5800 DWARFFormValue form_value;
5801 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005802 {
Greg Clayton7f995132011-10-04 22:41:51 +00005803 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005804 {
Greg Clayton7f995132011-10-04 22:41:51 +00005805 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5806 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5807 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5808 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
5809 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytond1767f02011-12-08 02:13:16 +00005810 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton7f995132011-10-04 22:41:51 +00005811 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5812 case DW_AT_const_value:
5813 location_is_const_value_data = true;
5814 // Fall through...
5815 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005816 {
Greg Clayton7f995132011-10-04 22:41:51 +00005817 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005818 {
Greg Clayton7f995132011-10-04 22:41:51 +00005819 const DataExtractor& debug_info_data = get_debug_info_data();
5820
5821 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5822 uint32_t block_length = form_value.Unsigned();
5823 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5824 }
5825 else
5826 {
5827 const DataExtractor& debug_loc_data = get_debug_loc_data();
5828 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5829
5830 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5831 if (loc_list_length > 0)
5832 {
5833 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5834 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5835 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5836 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005837 }
5838 }
Greg Clayton7f995132011-10-04 22:41:51 +00005839 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005840
Greg Clayton7f995132011-10-04 22:41:51 +00005841 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5842 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5843 case DW_AT_declaration:
5844 case DW_AT_description:
5845 case DW_AT_endianity:
5846 case DW_AT_segment:
5847 case DW_AT_start_scope:
5848 case DW_AT_visibility:
5849 default:
5850 case DW_AT_abstract_origin:
5851 case DW_AT_sibling:
5852 case DW_AT_specification:
5853 break;
5854 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005855 }
5856 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005857
Greg Clayton7f995132011-10-04 22:41:51 +00005858 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005859 {
Greg Clayton7f995132011-10-04 22:41:51 +00005860 ValueType scope = eValueTypeInvalid;
5861
5862 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5863 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005864 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00005865
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005866 // DWARF doesn't specify if a DW_TAG_variable is a local, global
5867 // or static variable, so we have to do a little digging by
5868 // looking at the location of a varaible to see if it contains
5869 // a DW_OP_addr opcode _somewhere_ in the definition. I say
5870 // somewhere because clang likes to combine small global variables
5871 // into the same symbol and have locations like:
5872 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
5873 // So if we don't have a DW_TAG_formal_parameter, we can look at
5874 // the location to see if it contains a DW_OP_addr opcode, and
5875 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00005876 if (tag == DW_TAG_formal_parameter)
5877 scope = eValueTypeVariableArgument;
Greg Claytond1767f02011-12-08 02:13:16 +00005878 else
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005879 {
Greg Clayton96c09682012-01-04 22:56:43 +00005880 bool op_error = false;
Greg Claytond1767f02011-12-08 02:13:16 +00005881 // Check if the location has a DW_OP_addr with any address value...
5882 addr_t location_has_op_addr = false;
5883 if (!location_is_const_value_data)
Greg Clayton96c09682012-01-04 22:56:43 +00005884 {
5885 location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
5886 if (op_error)
5887 {
5888 StreamString strm;
5889 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Claytone38a5ed2012-01-05 03:57:59 +00005890 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 +00005891 }
5892 }
Greg Claytond1767f02011-12-08 02:13:16 +00005893
5894 if (location_has_op_addr)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005895 {
Greg Claytond1767f02011-12-08 02:13:16 +00005896 if (is_external)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005897 {
Greg Claytond1767f02011-12-08 02:13:16 +00005898 scope = eValueTypeVariableGlobal;
5899
5900 if (m_debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005901 {
Greg Claytond1767f02011-12-08 02:13:16 +00005902 // When leaving the DWARF in the .o files on darwin,
5903 // when we have a global variable that wasn't initialized,
5904 // the .o file might not have allocated a virtual
5905 // address for the global variable. In this case it will
5906 // have created a symbol for the global variable
5907 // that is undefined and external and the value will
5908 // be the byte size of the variable. When we do the
5909 // address map in SymbolFileDWARFDebugMap we rely on
5910 // having an address, we need to do some magic here
5911 // so we can get the correct address for our global
5912 // variable. The address for all of these entries
5913 // will be zero, and there will be an undefined symbol
5914 // in this object file, and the executable will have
5915 // a matching symbol with a good address. So here we
5916 // dig up the correct address and replace it in the
5917 // location for the variable, and set the variable's
5918 // symbol context scope to be that of the main executable
5919 // so the file address will resolve correctly.
Greg Clayton96c09682012-01-04 22:56:43 +00005920 if (location.LocationContains_DW_OP_addr (0, op_error))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005921 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005922
Greg Claytond1767f02011-12-08 02:13:16 +00005923 // we have a possible uninitialized extern global
5924 Symtab *symtab = m_obj_file->GetSymtab();
5925 if (symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005926 {
Greg Claytond1767f02011-12-08 02:13:16 +00005927 ConstString const_name(name);
5928 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
5929 eSymbolTypeUndefined,
5930 Symtab::eDebugNo,
5931 Symtab::eVisibilityExtern);
5932
5933 if (undefined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005934 {
Greg Claytond1767f02011-12-08 02:13:16 +00005935 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
5936 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005937 {
Greg Claytond1767f02011-12-08 02:13:16 +00005938 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
5939 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
5940 eSymbolTypeData,
5941 Symtab::eDebugYes,
5942 Symtab::eVisibilityExtern);
5943 if (defined_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005944 {
Greg Claytond1767f02011-12-08 02:13:16 +00005945 const AddressRange *defined_range = defined_symbol->GetAddressRangePtr();
5946 if (defined_range)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005947 {
Greg Claytond1767f02011-12-08 02:13:16 +00005948 const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress();
5949 if (defined_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005950 {
Greg Claytond1767f02011-12-08 02:13:16 +00005951 if (location.Update_DW_OP_addr (defined_addr))
5952 {
5953 symbol_context_scope = defined_symbol;
5954 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005955 }
5956 }
5957 }
5958 }
5959 }
5960 }
5961 }
5962 }
5963 }
Greg Claytond1767f02011-12-08 02:13:16 +00005964 else
5965 {
5966 scope = eValueTypeVariableStatic;
5967 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005968 }
5969 else
Greg Claytond1767f02011-12-08 02:13:16 +00005970 {
5971 scope = eValueTypeVariableLocal;
5972 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005973 }
Greg Clayton7f995132011-10-04 22:41:51 +00005974
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005975 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00005976 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005977 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00005978 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005979 case DW_TAG_subprogram:
5980 case DW_TAG_inlined_subroutine:
5981 case DW_TAG_lexical_block:
5982 if (sc.function)
5983 {
5984 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
5985 if (symbol_context_scope == NULL)
5986 symbol_context_scope = sc.function;
5987 }
5988 break;
5989
5990 default:
5991 symbol_context_scope = sc.comp_unit;
5992 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005993 }
Greg Clayton7f995132011-10-04 22:41:51 +00005994 }
5995
Greg Clayton5cf58b92011-10-05 22:22:08 +00005996 if (symbol_context_scope)
5997 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005998 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
5999 name,
6000 mangled,
Greg Claytond1767f02011-12-08 02:13:16 +00006001 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
Greg Clayton81c22f62011-10-19 18:09:39 +00006002 scope,
6003 symbol_context_scope,
6004 &decl,
6005 location,
6006 is_external,
6007 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00006008
6009 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6010 }
6011 else
6012 {
6013 // Not ready to parse this variable yet. It might be a global
6014 // or static variable that is in a function scope and the function
6015 // in the symbol context wasn't filled in yet
6016 return var_sp;
6017 }
Greg Clayton7f995132011-10-04 22:41:51 +00006018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006019 }
Greg Clayton7f995132011-10-04 22:41:51 +00006020 // Cache var_sp even if NULL (the variable was just a specification or
6021 // was missing vital information to be able to be displayed in the debugger
6022 // (missing location due to optimization, etc)) so we don't re-parse
6023 // this DIE over and over later...
6024 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006025 }
6026 return var_sp;
6027}
6028
Greg Claytonc662ec82011-06-17 22:10:16 +00006029
6030const DWARFDebugInfoEntry *
6031SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6032 dw_offset_t spec_block_die_offset,
6033 DWARFCompileUnit **result_die_cu_handle)
6034{
6035 // Give the concrete function die specified by "func_die_offset", find the
6036 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6037 // to "spec_block_die_offset"
6038 DWARFDebugInfo* info = DebugInfo();
6039
6040 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6041 if (die)
6042 {
6043 assert (*result_die_cu_handle);
6044 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6045 }
6046 return NULL;
6047}
6048
6049
6050const DWARFDebugInfoEntry *
6051SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6052 const DWARFDebugInfoEntry *die,
6053 dw_offset_t spec_block_die_offset,
6054 DWARFCompileUnit **result_die_cu_handle)
6055{
6056 if (die)
6057 {
6058 switch (die->Tag())
6059 {
6060 case DW_TAG_subprogram:
6061 case DW_TAG_inlined_subroutine:
6062 case DW_TAG_lexical_block:
6063 {
6064 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6065 {
6066 *result_die_cu_handle = dwarf_cu;
6067 return die;
6068 }
6069
6070 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6071 {
6072 *result_die_cu_handle = dwarf_cu;
6073 return die;
6074 }
6075 }
6076 break;
6077 }
6078
6079 // Give the concrete function die specified by "func_die_offset", find the
6080 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6081 // to "spec_block_die_offset"
6082 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6083 {
6084 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6085 child_die,
6086 spec_block_die_offset,
6087 result_die_cu_handle);
6088 if (result_die)
6089 return result_die;
6090 }
6091 }
6092
6093 *result_die_cu_handle = NULL;
6094 return NULL;
6095}
6096
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006097size_t
6098SymbolFileDWARF::ParseVariables
6099(
6100 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00006101 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00006102 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006103 const DWARFDebugInfoEntry *orig_die,
6104 bool parse_siblings,
6105 bool parse_children,
6106 VariableList* cc_variable_list
6107)
6108{
6109 if (orig_die == NULL)
6110 return 0;
6111
Greg Claytonc662ec82011-06-17 22:10:16 +00006112 VariableListSP variable_list_sp;
6113
6114 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006115 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00006116 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006117 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006118 dw_tag_t tag = die->Tag();
6119
6120 // Check to see if we have already parsed this variable or constant?
6121 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006122 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006123 if (cc_variable_list)
6124 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006125 }
6126 else
6127 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006128 // We haven't already parsed it, lets do that now.
6129 if ((tag == DW_TAG_variable) ||
6130 (tag == DW_TAG_constant) ||
6131 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006132 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006133 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00006134 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006135 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6136 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6137 switch (parent_tag)
6138 {
6139 case DW_TAG_compile_unit:
6140 if (sc.comp_unit != NULL)
6141 {
6142 variable_list_sp = sc.comp_unit->GetVariableList(false);
6143 if (variable_list_sp.get() == NULL)
6144 {
6145 variable_list_sp.reset(new VariableList());
6146 sc.comp_unit->SetVariableList(variable_list_sp);
6147 }
6148 }
6149 else
6150 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00006151 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6152 MakeUserID(sc_parent_die->GetOffset()),
6153 DW_TAG_value_to_name (parent_tag),
6154 MakeUserID(orig_die->GetOffset()),
6155 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006156 }
6157 break;
6158
6159 case DW_TAG_subprogram:
6160 case DW_TAG_inlined_subroutine:
6161 case DW_TAG_lexical_block:
6162 if (sc.function != NULL)
6163 {
6164 // Check to see if we already have parsed the variables for the given scope
6165
Greg Clayton81c22f62011-10-19 18:09:39 +00006166 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006167 if (block == NULL)
6168 {
6169 // This must be a specification or abstract origin with
6170 // a concrete block couterpart in the current function. We need
6171 // to find the concrete block so we can correctly add the
6172 // variable to it
6173 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6174 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6175 sc_parent_die->GetOffset(),
6176 &concrete_block_die_cu);
6177 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00006178 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006179 }
6180
6181 if (block != NULL)
6182 {
6183 const bool can_create = false;
6184 variable_list_sp = block->GetBlockVariableList (can_create);
6185 if (variable_list_sp.get() == NULL)
6186 {
6187 variable_list_sp.reset(new VariableList());
6188 block->SetVariableList(variable_list_sp);
6189 }
6190 }
6191 }
6192 break;
6193
6194 default:
Greg Claytone38a5ed2012-01-05 03:57:59 +00006195 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6196 MakeUserID(orig_die->GetOffset()),
6197 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00006198 break;
6199 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00006200 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006201
6202 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006203 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00006204 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6205 if (var_sp)
6206 {
Greg Claytonc662ec82011-06-17 22:10:16 +00006207 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00006208 if (cc_variable_list)
6209 cc_variable_list->AddVariableIfUnique (var_sp);
6210 ++vars_added;
6211 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006212 }
6213 }
6214 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006215
6216 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6217
6218 if (!skip_children && parse_children && die->HasChildren())
6219 {
6220 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6221 }
6222
6223 if (parse_siblings)
6224 die = die->GetSibling();
6225 else
6226 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006227 }
Greg Claytonc662ec82011-06-17 22:10:16 +00006228 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006229}
6230
6231//------------------------------------------------------------------
6232// PluginInterface protocol
6233//------------------------------------------------------------------
6234const char *
6235SymbolFileDWARF::GetPluginName()
6236{
6237 return "SymbolFileDWARF";
6238}
6239
6240const char *
6241SymbolFileDWARF::GetShortPluginName()
6242{
6243 return GetPluginNameStatic();
6244}
6245
6246uint32_t
6247SymbolFileDWARF::GetPluginVersion()
6248{
6249 return 1;
6250}
6251
6252void
Greg Clayton6beaaa62011-01-17 03:46:26 +00006253SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6254{
6255 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6256 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6257 if (clang_type)
6258 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6259}
6260
6261void
6262SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6263{
6264 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6265 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6266 if (clang_type)
6267 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6268}
6269
Greg Claytona2721472011-06-25 00:44:06 +00006270void
Sean Callanancc427fa2011-07-30 02:42:06 +00006271SymbolFileDWARF::DumpIndexes ()
6272{
6273 StreamFile s(stdout, false);
6274
6275 s.Printf ("DWARF index for (%s) '%s/%s':",
6276 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6277 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6278 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6279 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
6280 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
6281 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
6282 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
6283 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
6284 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
6285 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
6286 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
6287}
6288
6289void
6290SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6291 const char *name,
6292 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00006293{
Sean Callanancc427fa2011-07-30 02:42:06 +00006294 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00006295
6296 if (iter == m_decl_ctx_to_die.end())
6297 return;
6298
Greg Claytoncb5860a2011-10-13 23:49:28 +00006299 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00006300 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006301 const DWARFDebugInfoEntry *context_die = *pos;
6302
6303 if (!results)
6304 return;
6305
6306 DWARFDebugInfo* info = DebugInfo();
6307
6308 DIEArray die_offsets;
6309
6310 DWARFCompileUnit* dwarf_cu = NULL;
6311 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton220a0072011-12-09 08:48:30 +00006312
6313 if (m_using_apple_tables)
6314 {
6315 if (m_apple_types_ap.get())
6316 m_apple_types_ap->FindByName (name, die_offsets);
6317 }
6318 else
6319 {
6320 if (!m_indexed)
6321 Index ();
6322
6323 m_type_index.Find (ConstString(name), die_offsets);
6324 }
6325
Greg Clayton220a0072011-12-09 08:48:30 +00006326 const size_t num_matches = die_offsets.size();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006327
6328 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00006329 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00006330 for (size_t i = 0; i < num_matches; ++i)
6331 {
6332 const dw_offset_t die_offset = die_offsets[i];
6333 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00006334
Greg Claytoncb5860a2011-10-13 23:49:28 +00006335 if (die->GetParent() != context_die)
6336 continue;
6337
6338 Type *matching_type = ResolveType (dwarf_cu, die);
6339
Greg Clayton42ce2f32011-12-12 21:50:19 +00006340 lldb::clang_type_t type = matching_type->GetClangForwardType();
Greg Claytoncb5860a2011-10-13 23:49:28 +00006341 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6342
6343 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6344 {
6345 clang::TagDecl *tag_decl = tag_type->getDecl();
6346 results->push_back(tag_decl);
6347 }
6348 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6349 {
6350 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6351 results->push_back(typedef_decl);
6352 }
Greg Claytona2721472011-06-25 00:44:06 +00006353 }
6354 }
6355 }
6356}
6357
6358void
6359SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00006360 const clang::DeclContext *decl_context,
6361 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00006362 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6363{
Greg Clayton85ae2e12011-10-18 23:36:41 +00006364
6365 switch (decl_context->getDeclKind())
6366 {
6367 case clang::Decl::Namespace:
6368 case clang::Decl::TranslationUnit:
6369 {
6370 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6371 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6372 }
6373 break;
6374 default:
6375 break;
6376 }
Greg Claytona2721472011-06-25 00:44:06 +00006377}
Greg Claytoncaab74e2012-01-28 00:48:57 +00006378
6379bool
6380SymbolFileDWARF::LayoutRecordType (void *baton,
6381 const clang::RecordDecl *record_decl,
6382 uint64_t &size,
6383 uint64_t &alignment,
6384 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6385 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6386 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6387{
6388 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6389 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6390}
6391
6392
6393bool
6394SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6395 uint64_t &bit_size,
6396 uint64_t &alignment,
6397 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6398 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6399 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6400{
6401 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6402 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6403 bool success = false;
6404 base_offsets.clear();
6405 vbase_offsets.clear();
6406 if (pos != m_record_decl_to_layout_map.end())
6407 {
6408 bit_size = pos->second.bit_size;
6409 alignment = pos->second.alignment;
6410 field_offsets.swap(pos->second.field_offsets);
6411 m_record_decl_to_layout_map.erase(pos);
6412 success = true;
6413 }
6414 else
6415 {
6416 bit_size = 0;
6417 alignment = 0;
6418 field_offsets.clear();
6419 }
6420
6421 if (log)
6422 GetObjectFile()->GetModule()->LogMessage (log.get(),
6423 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6424 record_decl,
6425 bit_size,
6426 alignment,
6427 (uint32_t)field_offsets.size(),
6428 (uint32_t)base_offsets.size(),
6429 (uint32_t)vbase_offsets.size(),
6430 success);
6431 return success;
6432}
6433
6434
6435