blob: 7004e8d9ceb5eac3afabdecd82079f12a868face [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "clang/Basic/Builtins.h"
19#include "clang/Basic/IdentifierTable.h"
20#include "clang/Basic/LangOptions.h"
21#include "clang/Basic/SourceManager.h"
22#include "clang/Basic/TargetInfo.h"
23#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000024#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025
Sean Callanancc427fa2011-07-30 02:42:06 +000026#include "llvm/Support/Casting.h"
27
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Core/Module.h"
29#include "lldb/Core/PluginManager.h"
30#include "lldb/Core/RegularExpression.h"
31#include "lldb/Core/Scalar.h"
32#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000033#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000034#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Core/Timer.h"
36#include "lldb/Core/Value.h"
37
Greg Clayton20568dd2011-10-13 23:13:20 +000038#include "lldb/Host/Host.h"
39
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000041#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042#include "lldb/Symbol/CompileUnit.h"
43#include "lldb/Symbol/LineTable.h"
44#include "lldb/Symbol/ObjectFile.h"
45#include "lldb/Symbol/SymbolVendor.h"
46#include "lldb/Symbol/VariableList.h"
47
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000048#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000049#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000050
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "DWARFCompileUnit.h"
52#include "DWARFDebugAbbrev.h"
53#include "DWARFDebugAranges.h"
54#include "DWARFDebugInfo.h"
55#include "DWARFDebugInfoEntry.h"
56#include "DWARFDebugLine.h"
57#include "DWARFDebugPubnames.h"
58#include "DWARFDebugRanges.h"
59#include "DWARFDIECollection.h"
60#include "DWARFFormValue.h"
61#include "DWARFLocationList.h"
62#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000063#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
65#include <map>
66
Greg Clayton62742b12010-11-11 01:09:45 +000067//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000068
69#ifdef ENABLE_DEBUG_PRINTF
70#include <stdio.h>
71#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
72#else
73#define DEBUG_PRINTF(fmt, ...)
74#endif
75
Greg Clayton594e5ed2010-09-27 21:07:38 +000076#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077
78using namespace lldb;
79using namespace lldb_private;
80
81
Sean Callananc7fbf732010-08-06 00:32:49 +000082static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000083DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084{
85 switch (dwarf_accessibility)
86 {
Sean Callananc7fbf732010-08-06 00:32:49 +000087 case DW_ACCESS_public: return eAccessPublic;
88 case DW_ACCESS_private: return eAccessPrivate;
89 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000090 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091 }
Sean Callananc7fbf732010-08-06 00:32:49 +000092 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093}
94
95void
96SymbolFileDWARF::Initialize()
97{
98 LogChannelDWARF::Initialize();
99 PluginManager::RegisterPlugin (GetPluginNameStatic(),
100 GetPluginDescriptionStatic(),
101 CreateInstance);
102}
103
104void
105SymbolFileDWARF::Terminate()
106{
107 PluginManager::UnregisterPlugin (CreateInstance);
108 LogChannelDWARF::Initialize();
109}
110
111
112const char *
113SymbolFileDWARF::GetPluginNameStatic()
114{
Greg Claytond4a2b372011-09-12 23:21:58 +0000115 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116}
117
118const char *
119SymbolFileDWARF::GetPluginDescriptionStatic()
120{
121 return "DWARF and DWARF3 debug symbol file reader.";
122}
123
124
125SymbolFile*
126SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
127{
128 return new SymbolFileDWARF(obj_file);
129}
130
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000131TypeList *
132SymbolFileDWARF::GetTypeList ()
133{
134 if (m_debug_map_symfile)
135 return m_debug_map_symfile->GetTypeList();
136 return m_obj_file->GetModule()->GetTypeList();
137
138}
139
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000140//----------------------------------------------------------------------
141// Gets the first parent that is a lexical block, function or inlined
142// subroutine, or compile unit.
143//----------------------------------------------------------------------
144static const DWARFDebugInfoEntry *
145GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
146{
147 const DWARFDebugInfoEntry *die;
148 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
149 {
150 dw_tag_t tag = die->Tag();
151
152 switch (tag)
153 {
154 case DW_TAG_compile_unit:
155 case DW_TAG_subprogram:
156 case DW_TAG_inlined_subroutine:
157 case DW_TAG_lexical_block:
158 return die;
159 }
160 }
161 return NULL;
162}
163
164
Greg Clayton450e3f32010-10-12 02:24:53 +0000165SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
166 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000167 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 +0000168 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000169 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000171 m_data_debug_abbrev (),
172 m_data_debug_aranges (),
173 m_data_debug_frame (),
174 m_data_debug_info (),
175 m_data_debug_line (),
176 m_data_debug_loc (),
177 m_data_debug_ranges (),
178 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000179 m_data_apple_names (),
180 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000181 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183 m_info(),
184 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000185 m_apple_names_ap (),
186 m_apple_types_ap (),
187 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000188 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000189 m_function_basename_index(),
190 m_function_fullname_index(),
191 m_function_method_index(),
192 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000193 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000194 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000195 m_type_index(),
196 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000197 m_indexed (false),
198 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000199 m_using_apple_tables (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000200 m_ranges(),
201 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202{
203}
204
205SymbolFileDWARF::~SymbolFileDWARF()
206{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000207 if (m_is_external_ast_source)
208 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
209}
210
211static const ConstString &
212GetDWARFMachOSegmentName ()
213{
214 static ConstString g_dwarf_section_name ("__DWARF");
215 return g_dwarf_section_name;
216}
217
Greg Claytone576ab22011-02-15 00:19:15 +0000218UniqueDWARFASTTypeMap &
219SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
220{
221 if (m_debug_map_symfile)
222 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
223 return m_unique_ast_type_map;
224}
225
Greg Clayton6beaaa62011-01-17 03:46:26 +0000226ClangASTContext &
227SymbolFileDWARF::GetClangASTContext ()
228{
229 if (m_debug_map_symfile)
230 return m_debug_map_symfile->GetClangASTContext ();
231
232 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
233 if (!m_is_external_ast_source)
234 {
235 m_is_external_ast_source = true;
236 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
237 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
238 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000239 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000240 this));
241
242 ast.SetExternalSource (ast_source_ap);
243 }
244 return ast;
245}
246
247void
248SymbolFileDWARF::InitializeObject()
249{
250 // Install our external AST source callbacks so we can complete Clang types.
251 Module *module = m_obj_file->GetModule();
252 if (module)
253 {
254 const SectionList *section_list = m_obj_file->GetSectionList();
255
256 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
257
258 // Memory map the DWARF mach-o segment so we have everything mmap'ed
259 // to keep our heap memory usage down.
260 if (section)
261 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
262 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000263 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000264 if (m_data_apple_names.GetByteSize() > 0)
265 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000266 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
267 if (m_apple_names_ap->IsValid())
268 m_using_apple_tables = true;
269 else
Greg Clayton7f995132011-10-04 22:41:51 +0000270 m_apple_names_ap.reset();
271 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000272 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000273 if (m_data_apple_types.GetByteSize() > 0)
274 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000275 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
276 if (m_apple_types_ap->IsValid())
277 m_using_apple_tables = true;
278 else
Greg Clayton7f995132011-10-04 22:41:51 +0000279 m_apple_types_ap.reset();
280 }
281
282 get_apple_namespaces_data();
283 if (m_data_apple_namespaces.GetByteSize() > 0)
284 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000285 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
286 if (m_apple_namespaces_ap->IsValid())
287 m_using_apple_tables = true;
288 else
Greg Clayton7f995132011-10-04 22:41:51 +0000289 m_apple_namespaces_ap.reset();
290 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000291
Greg Clayton5009f9d2011-10-27 17:55:14 +0000292 get_apple_objc_data();
293 if (m_data_apple_objc.GetByteSize() > 0)
294 {
295 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
296 if (m_apple_objc_ap->IsValid())
297 m_using_apple_tables = true;
298 else
299 m_apple_objc_ap.reset();
300 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301}
302
303bool
304SymbolFileDWARF::SupportedVersion(uint16_t version)
305{
306 return version == 2 || version == 3;
307}
308
309uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000310SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311{
312 uint32_t abilities = 0;
313 if (m_obj_file != NULL)
314 {
315 const Section* section = NULL;
316 const SectionList *section_list = m_obj_file->GetSectionList();
317 if (section_list == NULL)
318 return 0;
319
320 uint64_t debug_abbrev_file_size = 0;
321 uint64_t debug_aranges_file_size = 0;
322 uint64_t debug_frame_file_size = 0;
323 uint64_t debug_info_file_size = 0;
324 uint64_t debug_line_file_size = 0;
325 uint64_t debug_loc_file_size = 0;
326 uint64_t debug_macinfo_file_size = 0;
327 uint64_t debug_pubnames_file_size = 0;
328 uint64_t debug_pubtypes_file_size = 0;
329 uint64_t debug_ranges_file_size = 0;
330 uint64_t debug_str_file_size = 0;
331
Greg Clayton6beaaa62011-01-17 03:46:26 +0000332 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333
334 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000335 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336
Greg Clayton4ceb9982010-07-21 22:54:26 +0000337 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000338 if (section != NULL)
339 {
340 debug_info_file_size = section->GetByteSize();
341
Greg Clayton4ceb9982010-07-21 22:54:26 +0000342 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 if (section)
344 debug_abbrev_file_size = section->GetByteSize();
345 else
346 m_flags.Set (flagsGotDebugAbbrevData);
347
Greg Clayton4ceb9982010-07-21 22:54:26 +0000348 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349 if (section)
350 debug_aranges_file_size = section->GetByteSize();
351 else
352 m_flags.Set (flagsGotDebugArangesData);
353
Greg Clayton4ceb9982010-07-21 22:54:26 +0000354 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355 if (section)
356 debug_frame_file_size = section->GetByteSize();
357 else
358 m_flags.Set (flagsGotDebugFrameData);
359
Greg Clayton4ceb9982010-07-21 22:54:26 +0000360 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 if (section)
362 debug_line_file_size = section->GetByteSize();
363 else
364 m_flags.Set (flagsGotDebugLineData);
365
Greg Clayton4ceb9982010-07-21 22:54:26 +0000366 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367 if (section)
368 debug_loc_file_size = section->GetByteSize();
369 else
370 m_flags.Set (flagsGotDebugLocData);
371
Greg Clayton4ceb9982010-07-21 22:54:26 +0000372 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 if (section)
374 debug_macinfo_file_size = section->GetByteSize();
375 else
376 m_flags.Set (flagsGotDebugMacInfoData);
377
Greg Clayton4ceb9982010-07-21 22:54:26 +0000378 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 if (section)
380 debug_pubnames_file_size = section->GetByteSize();
381 else
382 m_flags.Set (flagsGotDebugPubNamesData);
383
Greg Clayton4ceb9982010-07-21 22:54:26 +0000384 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 if (section)
386 debug_pubtypes_file_size = section->GetByteSize();
387 else
388 m_flags.Set (flagsGotDebugPubTypesData);
389
Greg Clayton4ceb9982010-07-21 22:54:26 +0000390 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391 if (section)
392 debug_ranges_file_size = section->GetByteSize();
393 else
394 m_flags.Set (flagsGotDebugRangesData);
395
Greg Clayton4ceb9982010-07-21 22:54:26 +0000396 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397 if (section)
398 debug_str_file_size = section->GetByteSize();
399 else
400 m_flags.Set (flagsGotDebugStrData);
401 }
402
403 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
404 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
405
406 if (debug_line_file_size > 0)
407 abilities |= LineTables;
408
409 if (debug_aranges_file_size > 0)
410 abilities |= AddressAcceleratorTable;
411
412 if (debug_pubnames_file_size > 0)
413 abilities |= FunctionAcceleratorTable;
414
415 if (debug_pubtypes_file_size > 0)
416 abilities |= TypeAcceleratorTable;
417
418 if (debug_macinfo_file_size > 0)
419 abilities |= MacroInformation;
420
421 if (debug_frame_file_size > 0)
422 abilities |= CallFrameInformation;
423 }
424 return abilities;
425}
426
427const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000428SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429{
430 if (m_flags.IsClear (got_flag))
431 {
432 m_flags.Set (got_flag);
433 const SectionList *section_list = m_obj_file->GetSectionList();
434 if (section_list)
435 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000436 Section *section = section_list->FindSectionByType(sect_type, true).get();
437 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 {
439 // See if we memory mapped the DWARF segment?
440 if (m_dwarf_data.GetByteSize())
441 {
442 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
443 }
444 else
445 {
446 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
447 data.Clear();
448 }
449 }
450 }
451 }
452 return data;
453}
454
455const DataExtractor&
456SymbolFileDWARF::get_debug_abbrev_data()
457{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459}
460
461const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000462SymbolFileDWARF::get_debug_aranges_data()
463{
464 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
465}
466
467const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468SymbolFileDWARF::get_debug_frame_data()
469{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000470 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471}
472
473const DataExtractor&
474SymbolFileDWARF::get_debug_info_data()
475{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000476 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477}
478
479const DataExtractor&
480SymbolFileDWARF::get_debug_line_data()
481{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000482 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
485const DataExtractor&
486SymbolFileDWARF::get_debug_loc_data()
487{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000488 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489}
490
491const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492SymbolFileDWARF::get_debug_ranges_data()
493{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000494 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495}
496
497const DataExtractor&
498SymbolFileDWARF::get_debug_str_data()
499{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000500 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501}
502
Greg Claytonf9eec202011-09-01 23:16:13 +0000503const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000504SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000505{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000506 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000507}
508
509const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000510SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000511{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000512 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000513}
514
Greg Clayton7f995132011-10-04 22:41:51 +0000515const DataExtractor&
516SymbolFileDWARF::get_apple_namespaces_data()
517{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000518 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
519}
520
521const DataExtractor&
522SymbolFileDWARF::get_apple_objc_data()
523{
524 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000525}
526
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527
528DWARFDebugAbbrev*
529SymbolFileDWARF::DebugAbbrev()
530{
531 if (m_abbr.get() == NULL)
532 {
533 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
534 if (debug_abbrev_data.GetByteSize() > 0)
535 {
536 m_abbr.reset(new DWARFDebugAbbrev());
537 if (m_abbr.get())
538 m_abbr->Parse(debug_abbrev_data);
539 }
540 }
541 return m_abbr.get();
542}
543
544const DWARFDebugAbbrev*
545SymbolFileDWARF::DebugAbbrev() const
546{
547 return m_abbr.get();
548}
549
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550
551DWARFDebugInfo*
552SymbolFileDWARF::DebugInfo()
553{
554 if (m_info.get() == NULL)
555 {
556 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
557 if (get_debug_info_data().GetByteSize() > 0)
558 {
559 m_info.reset(new DWARFDebugInfo());
560 if (m_info.get())
561 {
562 m_info->SetDwarfData(this);
563 }
564 }
565 }
566 return m_info.get();
567}
568
569const DWARFDebugInfo*
570SymbolFileDWARF::DebugInfo() const
571{
572 return m_info.get();
573}
574
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575DWARFCompileUnit*
576SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
577{
578 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000579 if (info && UserIDMatches(cu_uid))
580 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581 return NULL;
582}
583
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584
585DWARFDebugRanges*
586SymbolFileDWARF::DebugRanges()
587{
588 if (m_ranges.get() == NULL)
589 {
590 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
591 if (get_debug_ranges_data().GetByteSize() > 0)
592 {
593 m_ranges.reset(new DWARFDebugRanges());
594 if (m_ranges.get())
595 m_ranges->Extract(this);
596 }
597 }
598 return m_ranges.get();
599}
600
601const DWARFDebugRanges*
602SymbolFileDWARF::DebugRanges() const
603{
604 return m_ranges.get();
605}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606
607bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000608SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609{
Greg Clayton96d7d742010-11-10 23:42:09 +0000610 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000612 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613 if (cu_die)
614 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000615 const char * cu_die_name = cu_die->GetName(this, curr_cu);
616 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000617 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618 if (cu_die_name)
619 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000620 FileSpec cu_file_spec;
621
Greg Clayton7bd65b92011-02-09 23:39:34 +0000622 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000624 // If we have a full path to the compile unit, we don't need to resolve
625 // the file. This can be expensive e.g. when the source files are NFS mounted.
626 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 }
628 else
629 {
630 std::string fullpath(cu_comp_dir);
631 if (*fullpath.rbegin() != '/')
632 fullpath += '/';
633 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000634 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635 }
636
Greg Clayton81c22f62011-10-19 18:09:39 +0000637 compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
638 curr_cu,
639 cu_file_spec,
640 MakeUserID(curr_cu->GetOffset()),
641 cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 if (compile_unit_sp.get())
643 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000644 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645 return true;
646 }
647 }
648 }
649 }
650 return false;
651}
652
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653uint32_t
654SymbolFileDWARF::GetNumCompileUnits()
655{
656 DWARFDebugInfo* info = DebugInfo();
657 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659 return 0;
660}
661
662CompUnitSP
663SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
664{
665 CompUnitSP comp_unit;
666 DWARFDebugInfo* info = DebugInfo();
667 if (info)
668 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000669 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
670 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671 {
672 // Our symbol vendor shouldn't be asking us to add a compile unit that
673 // has already been added to it, which this DWARF plug-in knows as it
674 // stores the lldb compile unit (CompileUnit) pointer in each
675 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000676 assert(curr_cu->GetUserData() == NULL);
677 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678 }
679 }
680 return comp_unit;
681}
682
683static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000684AddRangesToBlock (Block& block,
685 DWARFDebugRanges::RangeList& ranges,
686 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000688 const size_t num_ranges = ranges.GetSize();
689 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000691 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
692 const addr_t range_base = range.GetRangeBase();
693 assert (range_base >= block_base_addr);
694 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000696 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697}
698
699
700Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000701SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702{
703 DWARFDebugRanges::RangeList func_ranges;
704 const char *name = NULL;
705 const char *mangled = NULL;
706 int decl_file = 0;
707 int decl_line = 0;
708 int decl_column = 0;
709 int call_file = 0;
710 int call_line = 0;
711 int call_column = 0;
712 DWARFExpression frame_base;
713
Greg Claytonc93237c2010-10-01 20:48:32 +0000714 assert (die->Tag() == DW_TAG_subprogram);
715
716 if (die->Tag() != DW_TAG_subprogram)
717 return NULL;
718
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
720 {
721 // Union of all ranges in the function DIE (if the function is discontiguous)
722 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000723 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
724 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
726 {
727 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
728 if (func_range.GetBaseAddress().IsValid())
729 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
730 }
731
732 if (func_range.GetBaseAddress().IsValid())
733 {
734 Mangled func_name;
735 if (mangled)
736 func_name.SetValue(mangled, true);
737 else if (name)
738 func_name.SetValue(name, false);
739
740 FunctionSP func_sp;
741 std::auto_ptr<Declaration> decl_ap;
742 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000743 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
744 decl_line,
745 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000747 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000748 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749
750 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
751
752 func_range.GetBaseAddress().ResolveLinkedAddress();
753
Greg Clayton81c22f62011-10-19 18:09:39 +0000754 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000756 func_user_id, // UserID is the DIE offset
757 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000758 func_name,
759 func_type,
760 func_range)); // first address range
761
762 if (func_sp.get() != NULL)
763 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000764 if (frame_base.IsValid())
765 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766 sc.comp_unit->AddFunction(func_sp);
767 return func_sp.get();
768 }
769 }
770 }
771 return NULL;
772}
773
774size_t
775SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
776{
777 assert (sc.comp_unit);
778 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000779 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 if (dwarf_cu)
781 {
782 DWARFDIECollection function_dies;
783 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
784 size_t func_idx;
785 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
786 {
787 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000788 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789 {
790 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
791 ++functions_added;
792 }
793 }
794 //FixupTypes();
795 }
796 return functions_added;
797}
798
799bool
800SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
801{
802 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000803 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
804 assert (curr_cu);
805 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806
807 if (cu_die)
808 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000809 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
810 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 +0000811
812 // All file indexes in DWARF are one based and a file of index zero is
813 // supposed to be the compile unit itself.
814 support_files.Append (*sc.comp_unit);
815
816 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
817 }
818 return false;
819}
820
821struct ParseDWARFLineTableCallbackInfo
822{
823 LineTable* line_table;
824 const SectionList *section_list;
825 lldb::addr_t prev_sect_file_base_addr;
826 lldb::addr_t curr_sect_file_base_addr;
827 bool is_oso_for_debug_map;
828 bool prev_in_final_executable;
829 DWARFDebugLine::Row prev_row;
830 SectionSP prev_section_sp;
831 SectionSP curr_section_sp;
832};
833
834//----------------------------------------------------------------------
835// ParseStatementTableCallback
836//----------------------------------------------------------------------
837static void
838ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
839{
840 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
841 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
842 {
843 // Just started parsing the line table
844 }
845 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
846 {
847 // Done parsing line table, nothing to do for the cleanup
848 }
849 else
850 {
851 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
852 // We have a new row, lets append it
853
854 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
855 {
856 info->prev_section_sp = info->curr_section_sp;
857 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
858 // If this is an end sequence entry, then we subtract one from the
859 // address to make sure we get an address that is not the end of
860 // a section.
861 if (state.end_sequence && state.address != 0)
862 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
863 else
864 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
865
866 if (info->curr_section_sp.get())
867 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
868 else
869 info->curr_sect_file_base_addr = 0;
870 }
871 if (info->curr_section_sp.get())
872 {
873 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
874 // Check for the fancy section magic to determine if we
875
876 if (info->is_oso_for_debug_map)
877 {
878 // When this is a debug map object file that contains DWARF
879 // (referenced from an N_OSO debug map nlist entry) we will have
880 // a file address in the file range for our section from the
881 // original .o file, and a load address in the executable that
882 // contains the debug map.
883 //
884 // If the sections for the file range and load range are
885 // different, we have a remapped section for the function and
886 // this address is resolved. If they are the same, then the
887 // function for this address didn't make it into the final
888 // executable.
889 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
890
891 // If we are doing DWARF with debug map, then we need to carefully
892 // add each line table entry as there may be gaps as functions
893 // get moved around or removed.
894 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
895 {
896 if (info->prev_in_final_executable)
897 {
898 bool terminate_previous_entry = false;
899 if (!curr_in_final_executable)
900 {
901 // Check for the case where the previous line entry
902 // in a function made it into the final executable,
903 // yet the current line entry falls in a function
904 // that didn't. The line table used to be contiguous
905 // through this address range but now it isn't. We
906 // need to terminate the previous line entry so
907 // that we can reconstruct the line range correctly
908 // for it and to keep the line table correct.
909 terminate_previous_entry = true;
910 }
911 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
912 {
913 // Check for cases where the line entries used to be
914 // contiguous address ranges, but now they aren't.
915 // This can happen when order files specify the
916 // ordering of the functions.
917 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
918 Section *curr_sect = info->curr_section_sp.get();
919 Section *prev_sect = info->prev_section_sp.get();
920 assert (curr_sect->GetLinkedSection());
921 assert (prev_sect->GetLinkedSection());
922 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
923 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
924 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
925 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
926 if (object_file_addr_delta != linked_file_addr_delta)
927 terminate_previous_entry = true;
928 }
929
930 if (terminate_previous_entry)
931 {
932 line_table->InsertLineEntry (info->prev_section_sp,
933 state.address - info->prev_sect_file_base_addr,
934 info->prev_row.line,
935 info->prev_row.column,
936 info->prev_row.file,
937 false, // is_stmt
938 false, // basic_block
939 false, // state.prologue_end
940 false, // state.epilogue_begin
941 true); // end_sequence);
942 }
943 }
944 }
945
946 if (curr_in_final_executable)
947 {
948 line_table->InsertLineEntry (info->curr_section_sp,
949 curr_line_section_offset,
950 state.line,
951 state.column,
952 state.file,
953 state.is_stmt,
954 state.basic_block,
955 state.prologue_end,
956 state.epilogue_begin,
957 state.end_sequence);
958 info->prev_section_sp = info->curr_section_sp;
959 }
960 else
961 {
962 // If the current address didn't make it into the final
963 // executable, the current section will be the __text
964 // segment in the .o file, so we need to clear this so
965 // we can catch the next function that did make it into
966 // the final executable.
967 info->prev_section_sp.reset();
968 info->curr_section_sp.reset();
969 }
970
971 info->prev_in_final_executable = curr_in_final_executable;
972 }
973 else
974 {
975 // We are not in an object file that contains DWARF for an
976 // N_OSO, this is just a normal DWARF file. The DWARF spec
977 // guarantees that the addresses will be in increasing order
978 // so, since we store line tables in file address order, we
979 // can always just append the line entry without needing to
980 // search for the correct insertion point (we don't need to
981 // use LineEntry::InsertLineEntry()).
982 line_table->AppendLineEntry (info->curr_section_sp,
983 curr_line_section_offset,
984 state.line,
985 state.column,
986 state.file,
987 state.is_stmt,
988 state.basic_block,
989 state.prologue_end,
990 state.epilogue_begin,
991 state.end_sequence);
992 }
993 }
994
995 info->prev_row = state;
996 }
997}
998
999bool
1000SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1001{
1002 assert (sc.comp_unit);
1003 if (sc.comp_unit->GetLineTable() != NULL)
1004 return true;
1005
1006 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1007 if (dwarf_cu)
1008 {
1009 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001010 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001011 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001012 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1013 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001015 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1016 if (line_table_ap.get())
1017 {
1018 ParseDWARFLineTableCallbackInfo info = {
1019 line_table_ap.get(),
1020 m_obj_file->GetSectionList(),
1021 0,
1022 0,
1023 m_debug_map_symfile != NULL,
1024 false,
1025 DWARFDebugLine::Row(),
1026 SectionSP(),
1027 SectionSP()
1028 };
1029 uint32_t offset = cu_line_offset;
1030 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1031 sc.comp_unit->SetLineTable(line_table_ap.release());
1032 return true;
1033 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001034 }
1035 }
1036 }
1037 return false;
1038}
1039
1040size_t
1041SymbolFileDWARF::ParseFunctionBlocks
1042(
1043 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001044 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001045 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046 const DWARFDebugInfoEntry *die,
1047 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001048 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049)
1050{
1051 size_t blocks_added = 0;
1052 while (die != NULL)
1053 {
1054 dw_tag_t tag = die->Tag();
1055
1056 switch (tag)
1057 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001058 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001059 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 case DW_TAG_lexical_block:
1061 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001062 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001063 if (tag == DW_TAG_subprogram)
1064 {
1065 // Skip any DW_TAG_subprogram DIEs that are inside
1066 // of a normal or inlined functions. These will be
1067 // parsed on their own as separate entities.
1068
1069 if (depth > 0)
1070 break;
1071
1072 block = parent_block;
1073 }
1074 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001075 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001076 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001077 parent_block->AddChild(block_sp);
1078 block = block_sp.get();
1079 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001080 DWARFDebugRanges::RangeList ranges;
1081 const char *name = NULL;
1082 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001083
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 int decl_file = 0;
1085 int decl_line = 0;
1086 int decl_column = 0;
1087 int call_file = 0;
1088 int call_line = 0;
1089 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001090 if (die->GetDIENamesAndRanges (this,
1091 dwarf_cu,
1092 name,
1093 mangled_name,
1094 ranges,
1095 decl_file, decl_line, decl_column,
1096 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 {
1098 if (tag == DW_TAG_subprogram)
1099 {
1100 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001101 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001103 else if (tag == DW_TAG_inlined_subroutine)
1104 {
1105 // We get called here for inlined subroutines in two ways.
1106 // The first time is when we are making the Function object
1107 // for this inlined concrete instance. Since we're creating a top level block at
1108 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1109 // adjust the containing address.
1110 // The second time is when we are parsing the blocks inside the function that contains
1111 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1112 // function the offset will be for that function.
1113 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1114 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001115 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001116 }
1117 }
1118
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001119 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120
1121 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1122 {
1123 std::auto_ptr<Declaration> decl_ap;
1124 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001125 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1126 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001127
1128 std::auto_ptr<Declaration> call_ap;
1129 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001130 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1131 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001132
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001133 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 }
1135
1136 ++blocks_added;
1137
Greg Claytondd7feaf2011-08-12 17:54:33 +00001138 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001140 blocks_added += ParseFunctionBlocks (sc,
1141 block,
1142 dwarf_cu,
1143 die->GetFirstChild(),
1144 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001145 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 }
1147 }
1148 }
1149 break;
1150 default:
1151 break;
1152 }
1153
Greg Claytondd7feaf2011-08-12 17:54:33 +00001154 // Only parse siblings of the block if we are not at depth zero. A depth
1155 // of zero indicates we are currently parsing the top level
1156 // DW_TAG_subprogram DIE
1157
1158 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001159 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001160 else
1161 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 }
1163 return blocks_added;
1164}
1165
Greg Claytonf0705c82011-10-22 03:33:13 +00001166bool
1167SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1168 const DWARFDebugInfoEntry *parent_die,
1169 ClangASTContext::TemplateParameterInfos &template_param_infos)
1170{
1171
1172 if (parent_die == NULL)
1173 return NULL;
1174
1175 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1176
1177 Args template_parameter_names;
1178 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1179 die != NULL;
1180 die = die->GetSibling())
1181 {
1182 const dw_tag_t tag = die->Tag();
1183
1184 switch (tag)
1185 {
1186 case DW_TAG_template_type_parameter:
1187 case DW_TAG_template_value_parameter:
1188 {
1189 DWARFDebugInfoEntry::Attributes attributes;
1190 const size_t num_attributes = die->GetAttributes (this,
1191 dwarf_cu,
1192 fixed_form_sizes,
1193 attributes);
1194 const char *name = NULL;
1195 Type *lldb_type = NULL;
1196 clang_type_t clang_type = NULL;
1197 uint64_t uval64 = 0;
1198 bool uval64_valid = false;
1199 if (num_attributes > 0)
1200 {
1201 DWARFFormValue form_value;
1202 for (size_t i=0; i<num_attributes; ++i)
1203 {
1204 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1205
1206 switch (attr)
1207 {
1208 case DW_AT_name:
1209 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1210 name = form_value.AsCString(&get_debug_str_data());
1211 break;
1212
1213 case DW_AT_type:
1214 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1215 {
1216 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1217 lldb_type = ResolveTypeUID(type_die_offset);
1218 if (lldb_type)
1219 clang_type = lldb_type->GetClangForwardType();
1220 }
1221 break;
1222
1223 case DW_AT_const_value:
1224 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1225 {
1226 uval64_valid = true;
1227 uval64 = form_value.Unsigned();
1228 }
1229 break;
1230 default:
1231 break;
1232 }
1233 }
1234
1235 if (name && lldb_type && clang_type)
1236 {
1237 bool is_signed = false;
1238 template_param_infos.names.push_back(name);
1239 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1240 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1241 {
1242 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1243 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1244 }
1245 else
1246 {
1247 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1248 }
1249 }
1250 else
1251 {
1252 return false;
1253 }
1254
1255 }
1256 }
1257 break;
1258
1259 default:
1260 break;
1261 }
1262 }
1263 if (template_param_infos.args.empty())
1264 return false;
1265 return template_param_infos.args.size() == template_param_infos.names.size();
1266}
1267
1268clang::ClassTemplateDecl *
1269SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001270 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001271 const char *parent_name,
1272 int tag_decl_kind,
1273 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1274{
1275 if (template_param_infos.IsValid())
1276 {
1277 std::string template_basename(parent_name);
1278 template_basename.erase (template_basename.find('<'));
1279 ClangASTContext &ast = GetClangASTContext();
1280
1281 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001282 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001283 template_basename.c_str(),
1284 tag_decl_kind,
1285 template_param_infos);
1286 }
1287 return NULL;
1288}
1289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290size_t
1291SymbolFileDWARF::ParseChildMembers
1292(
1293 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001294 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001295 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001296 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001297 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1299 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001300 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001301 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 bool &is_a_class
1303)
1304{
1305 if (parent_die == NULL)
1306 return 0;
1307
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 size_t count = 0;
1309 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001310 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001311 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001312
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1314 {
1315 dw_tag_t tag = die->Tag();
1316
1317 switch (tag)
1318 {
1319 case DW_TAG_member:
1320 {
1321 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001322 const size_t num_attributes = die->GetAttributes (this,
1323 dwarf_cu,
1324 fixed_form_sizes,
1325 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 if (num_attributes > 0)
1327 {
1328 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001329 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 const char *name = NULL;
Jim Inghame3ae82a2011-11-12 01:36:43 +00001331 const char *prop_name = NULL;
1332 const char *prop_getter_name = NULL;
1333 const char *prop_setter_name = NULL;
1334 uint32_t prop_attributes = 0;
1335
1336
Greg Clayton24739922010-10-13 03:15:28 +00001337 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001338 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001339 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001340 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341 size_t byte_size = 0;
1342 size_t bit_offset = 0;
1343 size_t bit_size = 0;
1344 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001345 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001346 {
1347 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1348 DWARFFormValue form_value;
1349 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1350 {
1351 switch (attr)
1352 {
1353 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1354 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1355 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1356 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1357 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1358 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1359 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1360 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1361 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001362// if (form_value.BlockData())
1363// {
1364// Value initialValue(0);
1365// Value memberOffset(0);
1366// const DataExtractor& debug_info_data = get_debug_info_data();
1367// uint32_t block_length = form_value.Unsigned();
1368// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1369// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1370// {
1371// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1372// }
1373// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374 break;
1375
Greg Clayton8cf05932010-07-22 18:30:50 +00001376 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001377 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 case DW_AT_declaration:
1379 case DW_AT_description:
1380 case DW_AT_mutable:
1381 case DW_AT_visibility:
Jim Inghame3ae82a2011-11-12 01:36:43 +00001382
1383 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1384 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1385 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1386 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1387
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 default:
1389 case DW_AT_sibling:
1390 break;
1391 }
1392 }
1393 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001394
Greg Clayton44953932011-10-25 01:25:35 +00001395 // Clang has a DWARF generation bug where sometimes it
1396 // represents fields that are references with bad byte size
1397 // and bit size/offset information such as:
1398 //
1399 // DW_AT_byte_size( 0x00 )
1400 // DW_AT_bit_size( 0x40 )
1401 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1402 //
1403 // So check the bit offset to make sure it is sane, and if
1404 // the values are not sane, remove them. If we don't do this
1405 // then we will end up with a crash if we try to use this
1406 // type in an expression when clang becomes unhappy with its
1407 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001408
Greg Clayton44953932011-10-25 01:25:35 +00001409 if (bit_offset > 128)
1410 {
1411 bit_size = 0;
1412 bit_offset = 0;
1413 }
1414
1415 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001416 if (class_language == eLanguageTypeObjC ||
1417 class_language == eLanguageTypeObjC_plus_plus)
1418 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001419
1420 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1421 {
1422 // Not all compilers will mark the vtable pointer
1423 // member as artificial (llvm-gcc). We can't have
1424 // the virtual members in our classes otherwise it
1425 // throws off all child offsets since we end up
1426 // having and extra pointer sized member in our
1427 // class layouts.
1428 is_artificial = true;
1429 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430
Greg Clayton24739922010-10-13 03:15:28 +00001431 if (is_artificial == false)
1432 {
1433 Type *member_type = ResolveTypeUID(encoding_uid);
Jim Inghame3ae82a2011-11-12 01:36:43 +00001434 clang::FieldDecl *field_decl = NULL;
Greg Claytond16e1e52011-07-12 17:06:17 +00001435 if (member_type)
1436 {
1437 if (accessibility == eAccessNone)
1438 accessibility = default_accessibility;
1439 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001440
Jim Inghame3ae82a2011-11-12 01:36:43 +00001441 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
Greg Claytond16e1e52011-07-12 17:06:17 +00001442 name,
1443 member_type->GetClangLayoutType(),
1444 accessibility,
1445 bit_size);
1446 }
1447 else
1448 {
1449 if (name)
Greg Clayton81c22f62011-10-19 18:09:39 +00001450 ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1451 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001452 name,
1453 encoding_uid);
1454 else
Greg Clayton81c22f62011-10-19 18:09:39 +00001455 ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1456 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001457 encoding_uid);
1458 }
Jim Inghame3ae82a2011-11-12 01:36:43 +00001459
1460 if (prop_name != NULL)
1461 {
1462
1463 clang::ObjCIvarDecl *ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1464 assert (ivar_decl != NULL);
1465
1466
1467 GetClangASTContext().AddObjCClassProperty (class_clang_type,
1468 prop_name,
1469 0,
1470 ivar_decl,
1471 prop_setter_name,
1472 prop_getter_name,
1473 prop_attributes);
1474 }
Greg Clayton24739922010-10-13 03:15:28 +00001475 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001477 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478 }
1479 break;
1480
1481 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001482 // Let the type parsing code handle this one for us.
1483 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 break;
1485
1486 case DW_TAG_inheritance:
1487 {
1488 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001489 if (default_accessibility == eAccessNone)
1490 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 // TODO: implement DW_TAG_inheritance type parsing
1492 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001493 const size_t num_attributes = die->GetAttributes (this,
1494 dwarf_cu,
1495 fixed_form_sizes,
1496 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 if (num_attributes > 0)
1498 {
1499 Declaration decl;
1500 DWARFExpression location;
1501 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001502 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503 bool is_virtual = false;
1504 bool is_base_of_class = true;
1505 off_t member_offset = 0;
1506 uint32_t i;
1507 for (i=0; i<num_attributes; ++i)
1508 {
1509 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1510 DWARFFormValue form_value;
1511 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1512 {
1513 switch (attr)
1514 {
1515 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1516 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1517 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1518 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1519 case DW_AT_data_member_location:
1520 if (form_value.BlockData())
1521 {
1522 Value initialValue(0);
1523 Value memberOffset(0);
1524 const DataExtractor& debug_info_data = get_debug_info_data();
1525 uint32_t block_length = form_value.Unsigned();
1526 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001527 if (DWARFExpression::Evaluate (NULL,
1528 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001529 NULL,
1530 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001531 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001532 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001533 block_offset,
1534 block_length,
1535 eRegisterKindDWARF,
1536 &initialValue,
1537 memberOffset,
1538 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001539 {
1540 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1541 }
1542 }
1543 break;
1544
1545 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001546 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001547 break;
1548
1549 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1550 default:
1551 case DW_AT_sibling:
1552 break;
1553 }
1554 }
1555 }
1556
Greg Clayton526e5af2010-11-13 03:52:47 +00001557 Type *base_class_type = ResolveTypeUID(encoding_uid);
1558 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001559
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001560 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1561 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001562 if (class_language == eLanguageTypeObjC)
1563 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001564 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001565 }
1566 else
1567 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001568 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001569 accessibility,
1570 is_virtual,
1571 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001572 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001573 }
1574 }
1575 break;
1576
1577 default:
1578 break;
1579 }
1580 }
1581 return count;
1582}
1583
1584
1585clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001586SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001587{
1588 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001589 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001590 {
1591 DWARFCompileUnitSP cu_sp;
1592 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1593 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001594 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001595 }
1596 return NULL;
1597}
1598
1599clang::DeclContext*
1600SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1601{
Greg Clayton81c22f62011-10-19 18:09:39 +00001602 if (UserIDMatches(type_uid))
1603 return GetClangDeclContextForDIEOffset (sc, type_uid);
1604 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605}
1606
1607Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001608SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609{
Greg Clayton81c22f62011-10-19 18:09:39 +00001610 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001612 DWARFDebugInfo* debug_info = DebugInfo();
1613 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001614 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001615 DWARFCompileUnitSP cu_sp;
1616 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1617 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001618 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001619 // We might be coming in in the middle of a type tree (a class
1620 // withing a class, an enum within a class), so parse any needed
1621 // parent DIEs before we get to this one...
1622 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu_sp.get(), type_die);
1623 switch (decl_ctx_die->Tag())
1624 {
1625 case DW_TAG_structure_type:
1626 case DW_TAG_union_type:
1627 case DW_TAG_class_type:
1628 ResolveType(cu_sp.get(), decl_ctx_die);
1629 break;
1630 }
1631 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001632 }
Greg Claytonca512b32011-01-14 04:54:56 +00001633 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001634 }
1635 return NULL;
1636}
1637
Greg Clayton6beaaa62011-01-17 03:46:26 +00001638// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1639// SymbolFileDWARF objects to detect if this DWARF file is the one that
1640// can resolve a clang_type.
1641bool
1642SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1643{
1644 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1645 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1646 return die != NULL;
1647}
1648
1649
Greg Clayton1be10fc2010-09-29 01:12:09 +00001650lldb::clang_type_t
1651SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1652{
1653 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001654 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1655 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001656 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001657 {
1658 // We have already resolved this type...
1659 return clang_type;
1660 }
1661 // Once we start resolving this type, remove it from the forward declaration
1662 // map in case anyone child members or other types require this type to get resolved.
1663 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1664 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001665 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001666
Greg Clayton1be10fc2010-09-29 01:12:09 +00001667
Greg Clayton85ae2e12011-10-18 23:36:41 +00001668 // Disable external storage for this type so we don't get anymore
1669 // clang::ExternalASTSource queries for this type.
1670 ClangASTContext::SetHasExternalStorage (clang_type, false);
1671
Greg Clayton450e3f32010-10-12 02:24:53 +00001672 DWARFDebugInfo* debug_info = DebugInfo();
1673
Greg Clayton96d7d742010-11-10 23:42:09 +00001674 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001675 Type *type = m_die_to_type.lookup (die);
1676
1677 const dw_tag_t tag = die->Tag();
1678
Greg Clayton81c22f62011-10-19 18:09:39 +00001679 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") - resolve forward declaration...\n",
1680 MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001681 DW_TAG_value_to_name(tag),
1682 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001683 assert (clang_type);
1684 DWARFDebugInfoEntry::Attributes attributes;
1685
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001686 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001687
1688 switch (tag)
1689 {
1690 case DW_TAG_structure_type:
1691 case DW_TAG_union_type:
1692 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001693 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001694 if (die->HasChildren())
1695 {
1696 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001697 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1698 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001699 class_language = eLanguageTypeObjC;
1700
1701 int tag_decl_kind = -1;
1702 AccessType default_accessibility = eAccessNone;
1703 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001704 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001705 tag_decl_kind = clang::TTK_Struct;
1706 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001707 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001708 else if (tag == DW_TAG_union_type)
1709 {
1710 tag_decl_kind = clang::TTK_Union;
1711 default_accessibility = eAccessPublic;
1712 }
1713 else if (tag == DW_TAG_class_type)
1714 {
1715 tag_decl_kind = clang::TTK_Class;
1716 default_accessibility = eAccessPrivate;
1717 }
1718
Greg Clayton96d7d742010-11-10 23:42:09 +00001719 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001720 std::vector<clang::CXXBaseSpecifier *> base_classes;
1721 std::vector<int> member_accessibilities;
1722 bool is_a_class = false;
1723 // Parse members and base classes first
1724 DWARFDIECollection member_function_dies;
1725
1726 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001727 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001728 die,
1729 clang_type,
1730 class_language,
1731 base_classes,
1732 member_accessibilities,
1733 member_function_dies,
1734 default_accessibility,
1735 is_a_class);
1736
1737 // Now parse any methods if there were any...
1738 size_t num_functions = member_function_dies.Size();
1739 if (num_functions > 0)
1740 {
1741 for (size_t i=0; i<num_functions; ++i)
1742 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001743 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001744 }
1745 }
1746
Greg Clayton450e3f32010-10-12 02:24:53 +00001747 if (class_language == eLanguageTypeObjC)
1748 {
Greg Claytone3055942011-06-30 02:28:26 +00001749 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001750 if (!class_str.empty())
1751 {
1752
Greg Claytond4a2b372011-09-12 23:21:58 +00001753 DIEArray method_die_offsets;
Greg Clayton5009f9d2011-10-27 17:55:14 +00001754 if (m_using_apple_tables)
1755 {
1756 if (m_apple_objc_ap.get())
1757 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
1758 }
1759 else
1760 {
1761 if (!m_indexed)
1762 Index ();
1763
1764 ConstString class_name (class_str.c_str());
1765 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1766 }
1767
1768 if (!method_die_offsets.empty())
Greg Clayton450e3f32010-10-12 02:24:53 +00001769 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001770 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton450e3f32010-10-12 02:24:53 +00001771
Greg Claytond4a2b372011-09-12 23:21:58 +00001772 DWARFCompileUnit* method_cu = NULL;
1773 const size_t num_matches = method_die_offsets.size();
1774 for (size_t i=0; i<num_matches; ++i)
1775 {
1776 const dw_offset_t die_offset = method_die_offsets[i];
1777 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Greg Clayton450e3f32010-10-12 02:24:53 +00001778
Greg Clayton95d87902011-11-11 03:16:25 +00001779 if (method_die)
1780 ResolveType (method_cu, method_die);
1781 else
1782 {
1783 if (m_using_apple_tables)
1784 {
1785 ReportError (".apple_objc accelerator table had bad die 0x%8.8x for '%s'\n",
1786 die_offset, class_str.c_str());
1787 }
1788 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001789 }
1790 }
1791 }
1792 }
1793
Greg Claytonc93237c2010-10-01 20:48:32 +00001794 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1795 // need to tell the clang type it is actually a class.
1796 if (class_language != eLanguageTypeObjC)
1797 {
1798 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001799 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001800 }
1801
1802 // Since DW_TAG_structure_type gets used for both classes
1803 // and structures, we may need to set any DW_TAG_member
1804 // fields to have a "private" access if none was specified.
1805 // When we parsed the child members we tracked that actual
1806 // accessibility value for each DW_TAG_member in the
1807 // "member_accessibilities" array. If the value for the
1808 // member is zero, then it was set to the "default_accessibility"
1809 // which for structs was "public". Below we correct this
1810 // by setting any fields to "private" that weren't correctly
1811 // set.
1812 if (is_a_class && !member_accessibilities.empty())
1813 {
1814 // This is a class and all members that didn't have
1815 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001816 ast.SetDefaultAccessForRecordFields (clang_type,
1817 eAccessPrivate,
1818 &member_accessibilities.front(),
1819 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001820 }
1821
1822 if (!base_classes.empty())
1823 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001824 ast.SetBaseClassesForClassType (clang_type,
1825 &base_classes.front(),
1826 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001827
1828 // Clang will copy each CXXBaseSpecifier in "base_classes"
1829 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001830 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1831 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001832 }
1833
1834 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001835 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001836 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001837
1838 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001839 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001840 if (die->HasChildren())
1841 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001842 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1843 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001844 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001845 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001846 return clang_type;
1847
1848 default:
1849 assert(false && "not a forward clang type decl!");
1850 break;
1851 }
1852 return NULL;
1853}
1854
Greg Claytonc685f8e2010-09-15 04:15:46 +00001855Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001856SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001857{
1858 if (type_die != NULL)
1859 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001860 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001861 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001862 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001863 if (assert_not_being_parsed)
1864 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001865 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001866 }
1867 return NULL;
1868}
1869
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001871SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872{
1873 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001874 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 {
1876 // The symbol vendor doesn't know about this compile unit, we
1877 // need to parse and add it to the symbol vendor object.
1878 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001879 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880 if (dc_cu.get())
1881 {
1882 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001883 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001884 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885
1886 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001887
1888 if (m_debug_map_symfile)
1889 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890 }
1891 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001892 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001893}
1894
1895bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001896SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897{
1898 sc.Clear();
1899 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001900 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901
Greg Clayton81c22f62011-10-19 18:09:39 +00001902 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001903 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001904 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00001905
1906 if (sc.function)
1907 {
1908 sc.module_sp = sc.function->CalculateSymbolContextModule();
1909 return true;
1910 }
1911
1912 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001913}
1914
1915uint32_t
1916SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1917{
1918 Timer scoped_timer(__PRETTY_FUNCTION__,
1919 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1920 so_addr.GetSection(),
1921 so_addr.GetOffset(),
1922 resolve_scope);
1923 uint32_t resolved = 0;
1924 if (resolve_scope & ( eSymbolContextCompUnit |
1925 eSymbolContextFunction |
1926 eSymbolContextBlock |
1927 eSymbolContextLineEntry))
1928 {
1929 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1930
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001932 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001934 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001935 if (cu_offset != DW_INVALID_OFFSET)
1936 {
1937 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001938 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1939 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001941 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942 assert(sc.comp_unit != NULL);
1943 resolved |= eSymbolContextCompUnit;
1944
1945 if (resolve_scope & eSymbolContextLineEntry)
1946 {
1947 LineTable *line_table = sc.comp_unit->GetLineTable();
1948 if (line_table == NULL)
1949 {
1950 if (ParseCompileUnitLineTable(sc))
1951 line_table = sc.comp_unit->GetLineTable();
1952 }
1953 if (line_table != NULL)
1954 {
1955 if (so_addr.IsLinkedAddress())
1956 {
1957 Address linked_addr (so_addr);
1958 linked_addr.ResolveLinkedAddress();
1959 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1960 {
1961 resolved |= eSymbolContextLineEntry;
1962 }
1963 }
1964 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1965 {
1966 resolved |= eSymbolContextLineEntry;
1967 }
1968 }
1969 }
1970
1971 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1972 {
1973 DWARFDebugInfoEntry *function_die = NULL;
1974 DWARFDebugInfoEntry *block_die = NULL;
1975 if (resolve_scope & eSymbolContextBlock)
1976 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001977 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978 }
1979 else
1980 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001981 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982 }
1983
1984 if (function_die != NULL)
1985 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001986 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001988 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001989 }
1990
1991 if (sc.function != NULL)
1992 {
1993 resolved |= eSymbolContextFunction;
1994
1995 if (resolve_scope & eSymbolContextBlock)
1996 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001997 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001998
1999 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002000 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002002 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003 if (sc.block)
2004 resolved |= eSymbolContextBlock;
2005 }
2006 }
2007 }
2008 }
2009 }
2010 }
2011 }
2012 return resolved;
2013}
2014
2015
2016
2017uint32_t
2018SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2019{
2020 const uint32_t prev_size = sc_list.GetSize();
2021 if (resolve_scope & eSymbolContextCompUnit)
2022 {
2023 DWARFDebugInfo* debug_info = DebugInfo();
2024 if (debug_info)
2025 {
2026 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002027 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002028
Greg Clayton96d7d742010-11-10 23:42:09 +00002029 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002030 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002031 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002032 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2033 if (check_inlines || file_spec_matches_cu_file_spec)
2034 {
2035 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00002036 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002037 assert(sc.comp_unit != NULL);
2038
2039 uint32_t file_idx = UINT32_MAX;
2040
2041 // If we are looking for inline functions only and we don't
2042 // find it in the support files, we are done.
2043 if (check_inlines)
2044 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002045 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002046 if (file_idx == UINT32_MAX)
2047 continue;
2048 }
2049
2050 if (line != 0)
2051 {
2052 LineTable *line_table = sc.comp_unit->GetLineTable();
2053
2054 if (line_table != NULL && line != 0)
2055 {
2056 // We will have already looked up the file index if
2057 // we are searching for inline entries.
2058 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002059 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002060
2061 if (file_idx != UINT32_MAX)
2062 {
2063 uint32_t found_line;
2064 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2065 found_line = sc.line_entry.line;
2066
Greg Clayton016a95e2010-09-14 02:20:48 +00002067 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068 {
2069 sc.function = NULL;
2070 sc.block = NULL;
2071 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2072 {
2073 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2074 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2075 {
2076 DWARFDebugInfoEntry *function_die = NULL;
2077 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002078 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002079
2080 if (function_die != NULL)
2081 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002082 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002083 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002084 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002085 }
2086
2087 if (sc.function != NULL)
2088 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002089 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090
2091 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002092 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002093 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002094 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002095 }
2096 }
2097 }
2098
2099 sc_list.Append(sc);
2100 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2101 }
2102 }
2103 }
2104 else if (file_spec_matches_cu_file_spec && !check_inlines)
2105 {
2106 // only append the context if we aren't looking for inline call sites
2107 // by file and line and if the file spec matches that of the compile unit
2108 sc_list.Append(sc);
2109 }
2110 }
2111 else if (file_spec_matches_cu_file_spec && !check_inlines)
2112 {
2113 // only append the context if we aren't looking for inline call sites
2114 // by file and line and if the file spec matches that of the compile unit
2115 sc_list.Append(sc);
2116 }
2117
2118 if (!check_inlines)
2119 break;
2120 }
2121 }
2122 }
2123 }
2124 return sc_list.GetSize() - prev_size;
2125}
2126
2127void
2128SymbolFileDWARF::Index ()
2129{
2130 if (m_indexed)
2131 return;
2132 m_indexed = true;
2133 Timer scoped_timer (__PRETTY_FUNCTION__,
2134 "SymbolFileDWARF::Index (%s)",
2135 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2136
2137 DWARFDebugInfo* debug_info = DebugInfo();
2138 if (debug_info)
2139 {
2140 uint32_t cu_idx = 0;
2141 const uint32_t num_compile_units = GetNumCompileUnits();
2142 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2143 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002144 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002145
Greg Clayton96d7d742010-11-10 23:42:09 +00002146 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002147
Greg Clayton96d7d742010-11-10 23:42:09 +00002148 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002149 m_function_basename_index,
2150 m_function_fullname_index,
2151 m_function_method_index,
2152 m_function_selector_index,
2153 m_objc_class_selectors_index,
2154 m_global_index,
2155 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002156 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002157
2158 // Keep memory down by clearing DIEs if this generate function
2159 // caused them to be parsed
2160 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002161 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002162 }
2163
Greg Claytond4a2b372011-09-12 23:21:58 +00002164 m_function_basename_index.Finalize();
2165 m_function_fullname_index.Finalize();
2166 m_function_method_index.Finalize();
2167 m_function_selector_index.Finalize();
2168 m_objc_class_selectors_index.Finalize();
2169 m_global_index.Finalize();
2170 m_type_index.Finalize();
2171 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002172
Greg Clayton24739922010-10-13 03:15:28 +00002173#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002174 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002175 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002176 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2177 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002178 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2179 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2180 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2181 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2182 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2183 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002184 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002185 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002186#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002187 }
2188}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002189
2190bool
2191SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2192{
2193 if (namespace_decl == NULL)
2194 {
2195 // Invalid namespace decl which means we aren't matching only things
2196 // in this symbol file, so return true to indicate it matches this
2197 // symbol file.
2198 return true;
2199 }
2200
2201 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2202
2203 if (namespace_ast == NULL)
2204 return true; // No AST in the "namespace_decl", return true since it
2205 // could then match any symbol file, including this one
2206
2207 if (namespace_ast == GetClangASTContext().getASTContext())
2208 return true; // The ASTs match, return true
2209
2210 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002211 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2212
2213 if (log)
Greg Clayton18774842011-11-29 23:40:34 +00002214 LogMessage(log.get(), "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002215
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002216 return false;
2217}
2218
Greg Clayton2506a7a2011-10-12 23:34:26 +00002219bool
2220SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2221 DWARFCompileUnit* cu,
2222 const DWARFDebugInfoEntry* die)
2223{
2224 // No namespace specified, so the answesr i
2225 if (namespace_decl == NULL)
2226 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002227
2228 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002229
Greg Clayton2506a7a2011-10-12 23:34:26 +00002230 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2231 if (decl_ctx_die)
2232 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002233
Greg Clayton2506a7a2011-10-12 23:34:26 +00002234 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2235 if (clang_namespace_decl)
2236 {
2237 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002238 {
2239 if (log)
Greg Clayton18774842011-11-29 23:40:34 +00002240 LogMessage(log.get(), "Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002241 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002242 }
2243
Greg Clayton2506a7a2011-10-12 23:34:26 +00002244 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2245
2246 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002247 {
2248 if (log)
Greg Clayton18774842011-11-29 23:40:34 +00002249 LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace");
Sean Callananebe60672011-10-13 21:50:33 +00002250
Greg Clayton2506a7a2011-10-12 23:34:26 +00002251 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002252 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002253
Greg Claytoncb5860a2011-10-13 23:49:28 +00002254 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002255 }
2256 else
2257 {
2258 // We have a namespace_decl that was not NULL but it contained
2259 // a NULL "clang::NamespaceDecl", so this means the global namespace
2260 // So as long the the contained decl context DIE isn't a namespace
2261 // we should be ok.
2262 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2263 return true;
2264 }
2265 }
Sean Callananebe60672011-10-13 21:50:33 +00002266
2267 if (log)
Greg Clayton18774842011-11-29 23:40:34 +00002268 LogMessage(log.get(), "Found a match, but its parent doesn't exist");
Sean Callananebe60672011-10-13 21:50:33 +00002269
Greg Clayton2506a7a2011-10-12 23:34:26 +00002270 return false;
2271}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002273SymbolFileDWARF::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 +00002274{
Greg Clayton21f2a492011-10-06 00:09:08 +00002275 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2276
2277 if (log)
2278 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00002279 LogMessage (log.get(),
2280 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2281 name.GetCString(),
2282 namespace_decl,
2283 append,
2284 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002285 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002286
2287 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2288 return 0;
2289
Greg Claytonc685f8e2010-09-15 04:15:46 +00002290 DWARFDebugInfo* info = DebugInfo();
2291 if (info == NULL)
2292 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002293
2294 // If we aren't appending the results to this list, then clear the list
2295 if (!append)
2296 variables.Clear();
2297
2298 // Remember how many variables are in the list before we search in case
2299 // we are appending the results to a variable list.
2300 const uint32_t original_size = variables.GetSize();
2301
Greg Claytond4a2b372011-09-12 23:21:58 +00002302 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002303
Greg Clayton97fbc342011-10-20 22:30:33 +00002304 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002305 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002306 if (m_apple_names_ap.get())
2307 {
2308 const char *name_cstr = name.GetCString();
2309 const char *base_name_start;
2310 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002311
Greg Clayton97fbc342011-10-20 22:30:33 +00002312 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2313 base_name_start = name_cstr;
2314
2315 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2316 }
Greg Clayton7f995132011-10-04 22:41:51 +00002317 }
2318 else
2319 {
2320 // Index the DWARF if we haven't already
2321 if (!m_indexed)
2322 Index ();
2323
2324 m_global_index.Find (name, die_offsets);
2325 }
2326
2327 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002328 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002329 {
Greg Clayton7f995132011-10-04 22:41:51 +00002330 SymbolContext sc;
2331 sc.module_sp = m_obj_file->GetModule();
2332 assert (sc.module_sp);
2333
Greg Claytond4a2b372011-09-12 23:21:58 +00002334 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002335 DWARFCompileUnit* dwarf_cu = NULL;
2336 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002337 for (size_t i=0; i<num_matches; ++i)
2338 {
2339 const dw_offset_t die_offset = die_offsets[i];
2340 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002341
Greg Clayton95d87902011-11-11 03:16:25 +00002342 if (die)
2343 {
2344 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2345 assert(sc.comp_unit != NULL);
2346
2347 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2348 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002349
Greg Clayton95d87902011-11-11 03:16:25 +00002350 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351
Greg Clayton95d87902011-11-11 03:16:25 +00002352 if (variables.GetSize() - original_size >= max_matches)
2353 break;
2354 }
2355 else
2356 {
2357 if (m_using_apple_tables)
2358 {
2359 ReportError (".apple_names accelerator table had bad die 0x%8.8x for '%s'\n",
2360 die_offset, name.GetCString());
2361 }
2362 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002363 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002364 }
2365
2366 // Return the number of variable that were appended to the list
2367 return variables.GetSize() - original_size;
2368}
2369
2370uint32_t
2371SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2372{
Greg Clayton21f2a492011-10-06 00:09:08 +00002373 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2374
2375 if (log)
2376 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00002377 LogMessage (log.get(),
2378 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2379 regex.GetText(),
2380 append,
2381 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002382 }
2383
Greg Claytonc685f8e2010-09-15 04:15:46 +00002384 DWARFDebugInfo* info = DebugInfo();
2385 if (info == NULL)
2386 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002387
2388 // If we aren't appending the results to this list, then clear the list
2389 if (!append)
2390 variables.Clear();
2391
2392 // Remember how many variables are in the list before we search in case
2393 // we are appending the results to a variable list.
2394 const uint32_t original_size = variables.GetSize();
2395
Greg Clayton7f995132011-10-04 22:41:51 +00002396 DIEArray die_offsets;
2397
Greg Clayton97fbc342011-10-20 22:30:33 +00002398 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002399 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002400 if (m_apple_names_ap.get())
2401 m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002402 }
2403 else
2404 {
2405 // Index the DWARF if we haven't already
2406 if (!m_indexed)
2407 Index ();
2408
2409 m_global_index.Find (regex, die_offsets);
2410 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002411
Greg Claytonc685f8e2010-09-15 04:15:46 +00002412 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002413 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002414 assert (sc.module_sp);
2415
Greg Claytond4a2b372011-09-12 23:21:58 +00002416 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002417 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002418 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002419 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002420 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002421 DWARFDebugInfo* debug_info = DebugInfo();
2422 for (size_t i=0; i<num_matches; ++i)
2423 {
2424 const dw_offset_t die_offset = die_offsets[i];
2425 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002426
2427 if (die)
2428 {
2429 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002430
Greg Clayton95d87902011-11-11 03:16:25 +00002431 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002432
Greg Clayton95d87902011-11-11 03:16:25 +00002433 if (variables.GetSize() - original_size >= max_matches)
2434 break;
2435 }
2436 else
2437 {
2438 if (m_using_apple_tables)
2439 {
2440 ReportError (".apple_names accelerator table had bad die 0x%8.8x for regex '%s'\n",
2441 die_offset, regex.GetText());
2442 }
2443 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002444 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002445 }
2446
2447 // Return the number of variable that were appended to the list
2448 return variables.GetSize() - original_size;
2449}
2450
Greg Claytonaa044962011-10-13 00:59:38 +00002451
Jim Ingham4cda6e02011-10-07 22:23:45 +00002452bool
2453SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2454 DWARFCompileUnit *&dwarf_cu,
2455 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002456{
Greg Claytonaa044962011-10-13 00:59:38 +00002457 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2458 return ResolveFunction (dwarf_cu, die, sc_list);
2459}
2460
2461
2462bool
2463SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2464 const DWARFDebugInfoEntry *die,
2465 SymbolContextList& sc_list)
2466{
Greg Clayton9e315582011-09-02 04:03:59 +00002467 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002468
2469 if (die == NULL)
2470 return false;
2471
Jim Ingham4cda6e02011-10-07 22:23:45 +00002472 // If we were passed a die that is not a function, just return false...
2473 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2474 return false;
2475
2476 const DWARFDebugInfoEntry* inlined_die = NULL;
2477 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002478 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002479 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002480
Jim Ingham4cda6e02011-10-07 22:23:45 +00002481 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002482 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002483 if (die->Tag() == DW_TAG_subprogram)
2484 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002485 }
2486 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002487 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002488 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002489 {
2490 Address addr;
2491 // Parse all blocks if needed
2492 if (inlined_die)
2493 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002494 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002495 assert (sc.block != NULL);
2496 if (sc.block->GetStartAddress (addr) == false)
2497 addr.Clear();
2498 }
2499 else
2500 {
2501 sc.block = NULL;
2502 addr = sc.function->GetAddressRange().GetBaseAddress();
2503 }
2504
2505 if (addr.IsValid())
2506 {
2507
2508 // We found the function, so we should find the line table
2509 // and line table entry as well
2510 LineTable *line_table = sc.comp_unit->GetLineTable();
2511 if (line_table == NULL)
2512 {
2513 if (ParseCompileUnitLineTable(sc))
2514 line_table = sc.comp_unit->GetLineTable();
2515 }
2516 if (line_table != NULL)
2517 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2518
2519 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002520 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002521 }
2522 }
2523
Greg Claytonaa044962011-10-13 00:59:38 +00002524 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002525}
2526
Greg Clayton7f995132011-10-04 22:41:51 +00002527void
2528SymbolFileDWARF::FindFunctions (const ConstString &name,
2529 const NameToDIE &name_to_die,
2530 SymbolContextList& sc_list)
2531{
Greg Claytond4a2b372011-09-12 23:21:58 +00002532 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002533 if (name_to_die.Find (name, die_offsets))
2534 {
2535 ParseFunctions (die_offsets, sc_list);
2536 }
2537}
2538
2539
2540void
2541SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2542 const NameToDIE &name_to_die,
2543 SymbolContextList& sc_list)
2544{
2545 DIEArray die_offsets;
2546 if (name_to_die.Find (regex, die_offsets))
2547 {
2548 ParseFunctions (die_offsets, sc_list);
2549 }
2550}
2551
2552
2553void
2554SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2555 const DWARFMappedHash::MemoryTable &memory_table,
2556 SymbolContextList& sc_list)
2557{
2558 DIEArray die_offsets;
2559 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, die_offsets))
2560 {
2561 ParseFunctions (die_offsets, sc_list);
2562 }
2563}
2564
2565void
2566SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2567 SymbolContextList& sc_list)
2568{
2569 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002570 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002571 {
Greg Clayton7f995132011-10-04 22:41:51 +00002572 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002573
2574 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002575 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002576 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002577 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002578 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002579 }
2580 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002581}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002582
Jim Ingham4cda6e02011-10-07 22:23:45 +00002583bool
2584SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2585 const DWARFCompileUnit *dwarf_cu,
2586 uint32_t name_type_mask,
2587 const char *partial_name,
2588 const char *base_name_start,
2589 const char *base_name_end)
2590{
2591 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2592 if (name_type_mask == eFunctionNameTypeMethod
2593 || name_type_mask == eFunctionNameTypeBase)
2594 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002595 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2596 if (!containing_decl_ctx)
2597 return false;
2598
2599 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2600
2601 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2602 return false;
2603 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2604 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002605 }
2606
2607 // Now we need to check whether the name we got back for this type matches the extra specifications
2608 // that were in the name we're looking up:
2609 if (base_name_start != partial_name || *base_name_end != '\0')
2610 {
2611 // First see if the stuff to the left matches the full name. To do that let's see if
2612 // we can pull out the mips linkage name attribute:
2613
2614 Mangled best_name;
2615
2616 DWARFDebugInfoEntry::Attributes attributes;
2617 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2618 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2619 if (idx != UINT32_MAX)
2620 {
2621 DWARFFormValue form_value;
2622 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2623 {
2624 const char *name = form_value.AsCString(&get_debug_str_data());
2625 best_name.SetValue (name, true);
2626 }
2627 }
2628 if (best_name)
2629 {
2630 const char *demangled = best_name.GetDemangledName().GetCString();
2631 if (demangled)
2632 {
2633 std::string name_no_parens(partial_name, base_name_end - partial_name);
2634 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002635 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002636 }
2637 }
2638 }
2639
2640 return true;
2641}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002642
Greg Clayton0c5cd902010-06-28 21:30:43 +00002643uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002644SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002645 const lldb_private::ClangNamespaceDecl *namespace_decl,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002646 uint32_t name_type_mask,
2647 bool append,
2648 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002649{
2650 Timer scoped_timer (__PRETTY_FUNCTION__,
2651 "SymbolFileDWARF::FindFunctions (name = '%s')",
2652 name.AsCString());
2653
Greg Clayton21f2a492011-10-06 00:09:08 +00002654 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2655
2656 if (log)
2657 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00002658 LogMessage (log.get(),
2659 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2660 name.GetCString(),
2661 name_type_mask,
2662 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002663 }
2664
Greg Clayton0c5cd902010-06-28 21:30:43 +00002665 // If we aren't appending the results to this list, then clear the list
2666 if (!append)
2667 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002668
2669 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2670 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002671
2672 // If name is empty then we won't find anything.
2673 if (name.IsEmpty())
2674 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002675
2676 // Remember how many sc_list are in the list before we search in case
2677 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002678
Greg Clayton9e315582011-09-02 04:03:59 +00002679 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002680
Jim Ingham4cda6e02011-10-07 22:23:45 +00002681 const char *name_cstr = name.GetCString();
2682 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2683 const char *base_name_start = name_cstr;
2684 const char *base_name_end = name_cstr + strlen(name_cstr);
2685
2686 if (name_type_mask & eFunctionNameTypeAuto)
2687 {
2688 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2689 effective_name_type_mask = eFunctionNameTypeFull;
2690 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2691 effective_name_type_mask = eFunctionNameTypeFull;
2692 else
2693 {
2694 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2695 effective_name_type_mask |= eFunctionNameTypeSelector;
2696
2697 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2698 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2699 }
2700 }
2701 else
2702 {
2703 effective_name_type_mask = name_type_mask;
2704 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2705 {
2706 // If they've asked for a CPP method or function name and it can't be that, we don't
2707 // even need to search for CPP methods or names.
2708 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2709 {
2710 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2711 if (effective_name_type_mask == eFunctionNameTypeNone)
2712 return 0;
2713 }
2714 }
2715
2716 if (effective_name_type_mask & eFunctionNameTypeSelector)
2717 {
2718 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2719 {
2720 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2721 if (effective_name_type_mask == eFunctionNameTypeNone)
2722 return 0;
2723 }
2724 }
2725 }
2726
2727 DWARFDebugInfo* info = DebugInfo();
2728 if (info == NULL)
2729 return 0;
2730
Greg Claytonaa044962011-10-13 00:59:38 +00002731 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00002732 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002733 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002734 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002735 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002736
2737 DIEArray die_offsets;
2738
2739 uint32_t num_matches = 0;
2740
2741 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002742 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002743 // If they asked for the full name, match what they typed. At some point we may
2744 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2745 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002746 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002747 for (uint32_t i = 0; i < num_matches; i++)
2748 {
Greg Clayton95d87902011-11-11 03:16:25 +00002749 const dw_offset_t die_offset = die_offsets[i];
2750 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002751 if (die)
2752 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002753 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2754 continue;
2755
Greg Claytonaa044962011-10-13 00:59:38 +00002756 ResolveFunction (dwarf_cu, die, sc_list);
2757 }
Greg Clayton95d87902011-11-11 03:16:25 +00002758 else
2759 {
2760 ReportError (".apple_names accelerator table had bad die 0x%8.8x for '%s'\n",
2761 die_offset, name_cstr);
2762 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002763 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002764 }
2765 else
2766 {
2767 if (effective_name_type_mask & eFunctionNameTypeSelector)
2768 {
2769 if (namespace_decl && *namespace_decl)
2770 return 0; // no selectors in namespaces
2771
2772 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2773 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2774 // and if it is an ObjC method name, we're good.
2775
2776 for (uint32_t i = 0; i < num_matches; i++)
2777 {
Greg Clayton95d87902011-11-11 03:16:25 +00002778 const dw_offset_t die_offset = die_offsets[i];
2779 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00002780 if (die)
2781 {
2782 const char *die_name = die->GetName(this, dwarf_cu);
2783 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
2784 ResolveFunction (dwarf_cu, die, sc_list);
2785 }
Greg Clayton95d87902011-11-11 03:16:25 +00002786 else
2787 {
2788 ReportError (".apple_names accelerator table had bad die 0x%8.8x for '%s'\n",
2789 die_offset, name_cstr);
2790 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002791 }
2792 die_offsets.clear();
2793 }
2794
2795 if (effective_name_type_mask & eFunctionNameTypeMethod
2796 || effective_name_type_mask & eFunctionNameTypeBase)
2797 {
2798 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
2799 (namespace_decl && *namespace_decl))
2800 return 0; // no methods in namespaces
2801
2802 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2803 // extract the base name, look that up, and if there is any other information in the name we were
2804 // passed in we have to post-filter based on that.
2805
2806 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2807 std::string base_name(base_name_start, base_name_end - base_name_start);
2808 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
2809
2810 for (uint32_t i = 0; i < num_matches; i++)
2811 {
Greg Clayton95d87902011-11-11 03:16:25 +00002812 const dw_offset_t die_offset = die_offsets[i];
2813 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton97fbc342011-10-20 22:30:33 +00002814 if (die)
2815 {
2816 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2817 continue;
2818
2819 if (!FunctionDieMatchesPartialName(die,
2820 dwarf_cu,
2821 effective_name_type_mask,
2822 name_cstr,
2823 base_name_start,
2824 base_name_end))
2825 continue;
2826
2827 // If we get to here, the die is good, and we should add it:
2828 ResolveFunction (dwarf_cu, die, sc_list);
2829 }
Greg Clayton95d87902011-11-11 03:16:25 +00002830 else
2831 {
2832 ReportError (".apple_names accelerator table had bad die 0x%8.8x for '%s'\n",
2833 die_offset, name_cstr);
2834 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002835 }
2836 die_offsets.clear();
2837 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002838 }
2839 }
Greg Clayton7f995132011-10-04 22:41:51 +00002840 }
2841 else
2842 {
2843
2844 // Index the DWARF if we haven't already
2845 if (!m_indexed)
2846 Index ();
2847
Greg Clayton7f995132011-10-04 22:41:51 +00002848 if (name_type_mask & eFunctionNameTypeFull)
2849 FindFunctions (name, m_function_fullname_index, sc_list);
2850
Jim Ingham4cda6e02011-10-07 22:23:45 +00002851 std::string base_name(base_name_start, base_name_end - base_name_start);
2852 ConstString base_name_const(base_name.c_str());
2853 DIEArray die_offsets;
2854 DWARFCompileUnit *dwarf_cu = NULL;
2855
2856 if (effective_name_type_mask & eFunctionNameTypeBase)
2857 {
2858 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002859 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002860 {
Greg Claytonaa044962011-10-13 00:59:38 +00002861 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2862 if (die)
2863 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002864 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2865 continue;
2866
Greg Claytonaa044962011-10-13 00:59:38 +00002867 if (!FunctionDieMatchesPartialName(die,
2868 dwarf_cu,
2869 effective_name_type_mask,
2870 name_cstr,
2871 base_name_start,
2872 base_name_end))
2873 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002874
Greg Claytonaa044962011-10-13 00:59:38 +00002875 // If we get to here, the die is good, and we should add it:
2876 ResolveFunction (dwarf_cu, die, sc_list);
2877 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002878 }
2879 die_offsets.clear();
2880 }
2881
Jim Inghamea8005a2011-10-11 01:18:11 +00002882 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002883 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002884 if (namespace_decl && *namespace_decl)
2885 return 0; // no methods in namespaces
2886
Jim Ingham4cda6e02011-10-07 22:23:45 +00002887 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
2888 {
Greg Claytonaa044962011-10-13 00:59:38 +00002889 for (uint32_t i = 0; i < num_base; i++)
2890 {
2891 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2892 if (die)
2893 {
2894 if (!FunctionDieMatchesPartialName(die,
2895 dwarf_cu,
2896 effective_name_type_mask,
2897 name_cstr,
2898 base_name_start,
2899 base_name_end))
2900 continue;
2901
2902 // If we get to here, the die is good, and we should add it:
2903 ResolveFunction (dwarf_cu, die, sc_list);
2904 }
2905 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002906 }
2907 die_offsets.clear();
2908 }
Greg Clayton7f995132011-10-04 22:41:51 +00002909
Sean Callanan213fdb82011-10-13 01:49:10 +00002910 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002911 {
Greg Clayton7f995132011-10-04 22:41:51 +00002912 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002913 }
2914
Greg Clayton4d01ace2011-09-29 16:58:15 +00002915 }
2916
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917 // Return the number of variable that were appended to the list
2918 return sc_list.GetSize() - original_size;
2919}
2920
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002921uint32_t
2922SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2923{
2924 Timer scoped_timer (__PRETTY_FUNCTION__,
2925 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2926 regex.GetText());
2927
Greg Clayton21f2a492011-10-06 00:09:08 +00002928 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2929
2930 if (log)
2931 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00002932 LogMessage (log.get(),
2933 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2934 regex.GetText(),
2935 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002936 }
2937
2938
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002939 // If we aren't appending the results to this list, then clear the list
2940 if (!append)
2941 sc_list.Clear();
2942
2943 // Remember how many sc_list are in the list before we search in case
2944 // we are appending the results to a variable list.
2945 uint32_t original_size = sc_list.GetSize();
2946
Greg Clayton97fbc342011-10-20 22:30:33 +00002947 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002948 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002949 if (m_apple_names_ap.get())
2950 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002951 }
2952 else
2953 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002954 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002955 if (!m_indexed)
2956 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002957
Greg Clayton7f995132011-10-04 22:41:51 +00002958 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002959
Greg Clayton7f995132011-10-04 22:41:51 +00002960 FindFunctions (regex, m_function_fullname_index, sc_list);
2961 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002962
2963 // Return the number of variable that were appended to the list
2964 return sc_list.GetSize() - original_size;
2965}
Jim Ingham318c9f22011-08-26 19:44:13 +00002966
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002967uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002968SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002969{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002970 DWARFDebugInfo* info = DebugInfo();
2971 if (info == NULL)
2972 return 0;
2973
Greg Clayton21f2a492011-10-06 00:09:08 +00002974 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2975
2976 if (log)
2977 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00002978 LogMessage (log.get(),
2979 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
2980 name.GetCString(),
2981 append,
2982 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002983 }
2984
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985 // If we aren't appending the results to this list, then clear the list
2986 if (!append)
2987 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002988
2989 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2990 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991
Greg Claytond4a2b372011-09-12 23:21:58 +00002992 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002993
Greg Clayton97fbc342011-10-20 22:30:33 +00002994 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002995 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002996 if (m_apple_types_ap.get())
2997 {
2998 const char *name_cstr = name.GetCString();
2999 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3000 }
Greg Clayton7f995132011-10-04 22:41:51 +00003001 }
3002 else
3003 {
3004 if (!m_indexed)
3005 Index ();
3006
3007 m_type_index.Find (name, die_offsets);
3008 }
3009
3010
3011 const size_t num_matches = die_offsets.size();
3012
Greg Claytond4a2b372011-09-12 23:21:58 +00003013 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003014 {
Greg Clayton7f995132011-10-04 22:41:51 +00003015 const uint32_t initial_types_size = types.GetSize();
3016 DWARFCompileUnit* dwarf_cu = NULL;
3017 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003018 DWARFDebugInfo* debug_info = DebugInfo();
3019 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003020 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003021 const dw_offset_t die_offset = die_offsets[i];
3022 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3023
Greg Clayton95d87902011-11-11 03:16:25 +00003024 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003025 {
Greg Clayton95d87902011-11-11 03:16:25 +00003026 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3027 continue;
3028
3029 Type *matching_type = ResolveType (dwarf_cu, die);
3030 if (matching_type)
3031 {
3032 // We found a type pointer, now find the shared pointer form our type list
3033 types.InsertUnique (TypeSP (matching_type));
3034 if (types.GetSize() >= max_matches)
3035 break;
3036 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003037 }
Greg Clayton95d87902011-11-11 03:16:25 +00003038 else
3039 {
3040 if (m_using_apple_tables)
3041 {
3042 ReportError (".apple_types accelerator table had bad die 0x%8.8x for '%s'\n",
3043 die_offset, name.GetCString());
3044 }
3045 }
3046
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003047 }
Greg Clayton7f995132011-10-04 22:41:51 +00003048 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003049 }
Greg Clayton7f995132011-10-04 22:41:51 +00003050 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003051}
3052
3053
Greg Clayton526e5af2010-11-13 03:52:47 +00003054ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00003055SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003056 const ConstString &name,
3057 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003058{
Greg Clayton21f2a492011-10-06 00:09:08 +00003059 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3060
3061 if (log)
3062 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00003063 LogMessage (log.get(),
3064 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
Greg Clayton21f2a492011-10-06 00:09:08 +00003065 name.GetCString());
3066 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003067
3068 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3069 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003070
Greg Clayton526e5af2010-11-13 03:52:47 +00003071 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003072 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003073 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003074 {
Greg Clayton7f995132011-10-04 22:41:51 +00003075 DIEArray die_offsets;
3076
Greg Clayton526e5af2010-11-13 03:52:47 +00003077 // Index if we already haven't to make sure the compile units
3078 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003079 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003080 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003081 if (m_apple_namespaces_ap.get())
3082 {
3083 const char *name_cstr = name.GetCString();
3084 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3085 }
Greg Clayton7f995132011-10-04 22:41:51 +00003086 }
3087 else
3088 {
3089 if (!m_indexed)
3090 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003091
Greg Clayton7f995132011-10-04 22:41:51 +00003092 m_namespace_index.Find (name, die_offsets);
3093 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003094
3095 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003096 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003097 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003098 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003099 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003100 DWARFDebugInfo* debug_info = DebugInfo();
3101 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003102 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003103 const dw_offset_t die_offset = die_offsets[i];
3104 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003105
Greg Clayton95d87902011-11-11 03:16:25 +00003106 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003107 {
Greg Clayton95d87902011-11-11 03:16:25 +00003108 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3109 continue;
3110
3111 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3112 if (clang_namespace_decl)
3113 {
3114 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3115 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
3116 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003117 }
Greg Clayton95d87902011-11-11 03:16:25 +00003118 else
3119 {
3120 if (m_using_apple_tables)
3121 {
3122 ReportError (".apple_namespaces accelerator table had bad die 0x%8.8x for '%s'\n",
3123 die_offset, name.GetCString());
3124 }
3125 }
3126
Greg Clayton526e5af2010-11-13 03:52:47 +00003127 }
3128 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003129 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003130 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003131}
3132
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003133uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003134SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003135{
3136 // Remember how many sc_list are in the list before we search in case
3137 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003138 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003139
3140 const uint32_t num_die_offsets = die_offsets.size();
3141 // Parse all of the types we found from the pubtypes matches
3142 uint32_t i;
3143 uint32_t num_matches = 0;
3144 for (i = 0; i < num_die_offsets; ++i)
3145 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003146 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3147 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003148 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003149 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton85ae2e12011-10-18 23:36:41 +00003150 types.InsertUnique (TypeSP (matching_type));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003151 ++num_matches;
3152 if (num_matches >= max_matches)
3153 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003154 }
3155 }
3156
3157 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003158 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003159}
3160
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003161
3162size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003163SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3164 clang::DeclContext *containing_decl_ctx,
3165 TypeSP& type_sp,
3166 DWARFCompileUnit* dwarf_cu,
3167 const DWARFDebugInfoEntry *parent_die,
3168 bool skip_artificial,
3169 bool &is_static,
3170 TypeList* type_list,
3171 std::vector<clang_type_t>& function_param_types,
3172 std::vector<clang::ParmVarDecl*>& function_param_decls,
3173 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003174{
3175 if (parent_die == NULL)
3176 return 0;
3177
Greg Claytond88d7592010-09-15 08:33:30 +00003178 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3179
Greg Clayton7fedea22010-11-16 02:10:54 +00003180 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003181 const DWARFDebugInfoEntry *die;
3182 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3183 {
3184 dw_tag_t tag = die->Tag();
3185 switch (tag)
3186 {
3187 case DW_TAG_formal_parameter:
3188 {
3189 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003190 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003191 if (num_attributes > 0)
3192 {
3193 const char *name = NULL;
3194 Declaration decl;
3195 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003196 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197 // one of None, Auto, Register, Extern, Static, PrivateExtern
3198
Sean Callanane2ef6e32010-09-23 03:01:22 +00003199 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003200 uint32_t i;
3201 for (i=0; i<num_attributes; ++i)
3202 {
3203 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3204 DWARFFormValue form_value;
3205 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3206 {
3207 switch (attr)
3208 {
3209 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3210 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3211 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3212 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3213 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003214 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003215 case DW_AT_location:
3216 // if (form_value.BlockData())
3217 // {
3218 // const DataExtractor& debug_info_data = debug_info();
3219 // uint32_t block_length = form_value.Unsigned();
3220 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3221 // }
3222 // else
3223 // {
3224 // }
3225 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003226 case DW_AT_const_value:
3227 case DW_AT_default_value:
3228 case DW_AT_description:
3229 case DW_AT_endianity:
3230 case DW_AT_is_optional:
3231 case DW_AT_segment:
3232 case DW_AT_variable_parameter:
3233 default:
3234 case DW_AT_abstract_origin:
3235 case DW_AT_sibling:
3236 break;
3237 }
3238 }
3239 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003240
Greg Clayton0fffff52010-09-24 05:15:53 +00003241 bool skip = false;
3242 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003243 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003244 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003245 {
3246 // In order to determine if a C++ member function is
3247 // "const" we have to look at the const-ness of "this"...
3248 // Ugly, but that
3249 if (arg_idx == 0)
3250 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003251 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003252 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003253 // Often times compilers omit the "this" name for the
3254 // specification DIEs, so we can't rely upon the name
3255 // being in the formal parameter DIE...
3256 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003257 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003258 Type *this_type = ResolveTypeUID (param_type_die_offset);
3259 if (this_type)
3260 {
3261 uint32_t encoding_mask = this_type->GetEncodingMask();
3262 if (encoding_mask & Type::eEncodingIsPointerUID)
3263 {
3264 is_static = false;
3265
3266 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3267 type_quals |= clang::Qualifiers::Const;
3268 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3269 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003270 }
3271 }
3272 }
3273 }
3274 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003275 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003276 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003277 else
3278 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003279
Greg Clayton0fffff52010-09-24 05:15:53 +00003280 // HACK: Objective C formal parameters "self" and "_cmd"
3281 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003282 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3283 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003284 {
3285 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3286 skip = true;
3287 }
3288 }
3289 }
3290
3291 if (!skip)
3292 {
3293 Type *type = ResolveTypeUID(param_type_die_offset);
3294 if (type)
3295 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003296 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003297
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003298 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003299 assert(param_var_decl);
3300 function_param_decls.push_back(param_var_decl);
3301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003302 }
3303 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003304 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003305 }
3306 break;
3307
3308 default:
3309 break;
3310 }
3311 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003312 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003313}
3314
3315size_t
3316SymbolFileDWARF::ParseChildEnumerators
3317(
3318 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003319 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003320 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003321 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003322 const DWARFDebugInfoEntry *parent_die
3323)
3324{
3325 if (parent_die == NULL)
3326 return 0;
3327
3328 size_t enumerators_added = 0;
3329 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003330 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3331
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003332 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3333 {
3334 const dw_tag_t tag = die->Tag();
3335 if (tag == DW_TAG_enumerator)
3336 {
3337 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003338 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003339 if (num_child_attributes > 0)
3340 {
3341 const char *name = NULL;
3342 bool got_value = false;
3343 int64_t enum_value = 0;
3344 Declaration decl;
3345
3346 uint32_t i;
3347 for (i=0; i<num_child_attributes; ++i)
3348 {
3349 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3350 DWARFFormValue form_value;
3351 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3352 {
3353 switch (attr)
3354 {
3355 case DW_AT_const_value:
3356 got_value = true;
3357 enum_value = form_value.Unsigned();
3358 break;
3359
3360 case DW_AT_name:
3361 name = form_value.AsCString(&get_debug_str_data());
3362 break;
3363
3364 case DW_AT_description:
3365 default:
3366 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3367 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3368 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3369 case DW_AT_sibling:
3370 break;
3371 }
3372 }
3373 }
3374
3375 if (name && name[0] && got_value)
3376 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003377 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3378 enumerator_clang_type,
3379 decl,
3380 name,
3381 enum_value,
3382 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003383 ++enumerators_added;
3384 }
3385 }
3386 }
3387 }
3388 return enumerators_added;
3389}
3390
3391void
3392SymbolFileDWARF::ParseChildArrayInfo
3393(
3394 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003395 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003396 const DWARFDebugInfoEntry *parent_die,
3397 int64_t& first_index,
3398 std::vector<uint64_t>& element_orders,
3399 uint32_t& byte_stride,
3400 uint32_t& bit_stride
3401)
3402{
3403 if (parent_die == NULL)
3404 return;
3405
3406 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003407 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003408 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3409 {
3410 const dw_tag_t tag = die->Tag();
3411 switch (tag)
3412 {
3413 case DW_TAG_enumerator:
3414 {
3415 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003416 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003417 if (num_child_attributes > 0)
3418 {
3419 const char *name = NULL;
3420 bool got_value = false;
3421 int64_t enum_value = 0;
3422
3423 uint32_t i;
3424 for (i=0; i<num_child_attributes; ++i)
3425 {
3426 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3427 DWARFFormValue form_value;
3428 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3429 {
3430 switch (attr)
3431 {
3432 case DW_AT_const_value:
3433 got_value = true;
3434 enum_value = form_value.Unsigned();
3435 break;
3436
3437 case DW_AT_name:
3438 name = form_value.AsCString(&get_debug_str_data());
3439 break;
3440
3441 case DW_AT_description:
3442 default:
3443 case DW_AT_decl_file:
3444 case DW_AT_decl_line:
3445 case DW_AT_decl_column:
3446 case DW_AT_sibling:
3447 break;
3448 }
3449 }
3450 }
3451 }
3452 }
3453 break;
3454
3455 case DW_TAG_subrange_type:
3456 {
3457 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003458 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003459 if (num_child_attributes > 0)
3460 {
3461 const char *name = NULL;
3462 bool got_value = false;
3463 uint64_t byte_size = 0;
3464 int64_t enum_value = 0;
3465 uint64_t num_elements = 0;
3466 uint64_t lower_bound = 0;
3467 uint64_t upper_bound = 0;
3468 uint32_t i;
3469 for (i=0; i<num_child_attributes; ++i)
3470 {
3471 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3472 DWARFFormValue form_value;
3473 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3474 {
3475 switch (attr)
3476 {
3477 case DW_AT_const_value:
3478 got_value = true;
3479 enum_value = form_value.Unsigned();
3480 break;
3481
3482 case DW_AT_name:
3483 name = form_value.AsCString(&get_debug_str_data());
3484 break;
3485
3486 case DW_AT_count:
3487 num_elements = form_value.Unsigned();
3488 break;
3489
3490 case DW_AT_bit_stride:
3491 bit_stride = form_value.Unsigned();
3492 break;
3493
3494 case DW_AT_byte_stride:
3495 byte_stride = form_value.Unsigned();
3496 break;
3497
3498 case DW_AT_byte_size:
3499 byte_size = form_value.Unsigned();
3500 break;
3501
3502 case DW_AT_lower_bound:
3503 lower_bound = form_value.Unsigned();
3504 break;
3505
3506 case DW_AT_upper_bound:
3507 upper_bound = form_value.Unsigned();
3508 break;
3509
3510 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003511 case DW_AT_abstract_origin:
3512 case DW_AT_accessibility:
3513 case DW_AT_allocated:
3514 case DW_AT_associated:
3515 case DW_AT_data_location:
3516 case DW_AT_declaration:
3517 case DW_AT_description:
3518 case DW_AT_sibling:
3519 case DW_AT_threads_scaled:
3520 case DW_AT_type:
3521 case DW_AT_visibility:
3522 break;
3523 }
3524 }
3525 }
3526
3527 if (upper_bound > lower_bound)
3528 num_elements = upper_bound - lower_bound + 1;
3529
3530 if (num_elements > 0)
3531 element_orders.push_back (num_elements);
3532 }
3533 }
3534 break;
3535 }
3536 }
3537}
3538
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003539TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003540SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003541{
3542 TypeSP type_sp;
3543 if (die != NULL)
3544 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003545 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003546 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003547 if (type_ptr == NULL)
3548 {
Greg Claytonca512b32011-01-14 04:54:56 +00003549 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3550 assert (lldb_cu);
3551 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003552 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003553 }
3554 else if (type_ptr != DIE_IS_BEING_PARSED)
3555 {
3556 // Grab the existing type from the master types lists
Greg Clayton85ae2e12011-10-18 23:36:41 +00003557 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003558 }
3559
3560 }
3561 return type_sp;
3562}
3563
3564clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003565SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003566{
3567 if (die_offset != DW_INVALID_OFFSET)
3568 {
3569 DWARFCompileUnitSP cu_sp;
3570 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003571 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003572 }
3573 return NULL;
3574}
3575
Sean Callanan72e49402011-08-05 23:43:37 +00003576clang::DeclContext *
3577SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3578{
3579 if (die_offset != DW_INVALID_OFFSET)
3580 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003581 DWARFDebugInfo* debug_info = DebugInfo();
3582 if (debug_info)
3583 {
3584 DWARFCompileUnitSP cu_sp;
3585 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3586 if (die)
3587 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3588 }
Sean Callanan72e49402011-08-05 23:43:37 +00003589 }
3590 return NULL;
3591}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003592
Greg Clayton96d7d742010-11-10 23:42:09 +00003593clang::NamespaceDecl *
3594SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3595{
Greg Clayton030a2042011-10-14 21:34:45 +00003596 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003597 {
Greg Clayton030a2042011-10-14 21:34:45 +00003598 // See if we already parsed this namespace DIE and associated it with a
3599 // uniqued namespace declaration
3600 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3601 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003602 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003603 else
3604 {
3605 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00003606 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3607 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3608 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3609 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00003610 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00003611 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00003612 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00003613 LogMessage (log.get(),
3614 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
Greg Clayton030a2042011-10-14 21:34:45 +00003615 GetClangASTContext().getASTContext(),
Greg Clayton81c22f62011-10-19 18:09:39 +00003616 MakeUserID(die->GetOffset()),
Greg Clayton030a2042011-10-14 21:34:45 +00003617 namespace_name,
3618 namespace_decl,
Greg Clayton030a2042011-10-14 21:34:45 +00003619 namespace_decl->getOriginalNamespace());
3620 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003621 else
3622 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00003623 LogMessage (log.get(),
3624 "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
3625 GetClangASTContext().getASTContext(),
3626 MakeUserID(die->GetOffset()),
3627 namespace_decl,
3628 namespace_decl->getOriginalNamespace());
Greg Clayton9d3d6882011-10-31 23:51:19 +00003629 }
Greg Clayton030a2042011-10-14 21:34:45 +00003630 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003631
3632 if (namespace_decl)
3633 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3634 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003635 }
3636 }
3637 return NULL;
3638}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003639
3640clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003641SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3642{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003643 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3644 if (clang_decl_ctx)
3645 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003646 // If this DIE has a specification, or an abstract origin, then trace to those.
3647
3648 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
3649 if (die_offset != DW_INVALID_OFFSET)
3650 return GetClangDeclContextForDIEOffset (sc, die_offset);
3651
3652 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3653 if (die_offset != DW_INVALID_OFFSET)
3654 return GetClangDeclContextForDIEOffset (sc, die_offset);
3655
3656 // This is the DIE we want. Parse it, then query our map.
3657
3658 ParseType(sc, curr_cu, die, NULL);
3659
Greg Clayton5cf58b92011-10-05 22:22:08 +00003660 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3661
3662 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003663}
3664
3665clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003666SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003667{
Greg Claytonca512b32011-01-14 04:54:56 +00003668 if (m_clang_tu_decl == NULL)
3669 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003670
Greg Clayton2bc22f82011-09-30 03:20:47 +00003671 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003672
3673 if (decl_ctx_die_copy)
3674 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003675
3676 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003677 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003678
Greg Clayton2bc22f82011-09-30 03:20:47 +00003679 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3680 if (pos != m_die_to_decl_ctx.end())
3681 return pos->second;
3682
3683 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003684 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003685 case DW_TAG_compile_unit:
3686 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003687
Greg Clayton2bc22f82011-09-30 03:20:47 +00003688 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003689 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003690 break;
3691
3692 case DW_TAG_structure_type:
3693 case DW_TAG_union_type:
3694 case DW_TAG_class_type:
3695 {
3696 Type* type = ResolveType (cu, decl_ctx_die);
3697 if (type)
3698 {
3699 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3700 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003701 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003702 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3703 if (decl_ctx)
3704 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003705 }
3706 }
Greg Claytonca512b32011-01-14 04:54:56 +00003707 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003708 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003709
Greg Clayton2bc22f82011-09-30 03:20:47 +00003710 default:
3711 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003713 }
Greg Clayton7a345282010-11-09 23:46:37 +00003714 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003715}
3716
Greg Clayton2bc22f82011-09-30 03:20:47 +00003717
3718const DWARFDebugInfoEntry *
3719SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3720{
3721 if (cu && die)
3722 {
3723 const DWARFDebugInfoEntry * const decl_die = die;
3724
3725 while (die != NULL)
3726 {
3727 // If this is the original DIE that we are searching for a declaration
3728 // for, then don't look in the cache as we don't want our own decl
3729 // context to be our decl context...
3730 if (decl_die != die)
3731 {
3732 switch (die->Tag())
3733 {
3734 case DW_TAG_compile_unit:
3735 case DW_TAG_namespace:
3736 case DW_TAG_structure_type:
3737 case DW_TAG_union_type:
3738 case DW_TAG_class_type:
3739 return die;
3740
3741 default:
3742 break;
3743 }
3744 }
3745
3746 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3747 if (die_offset != DW_INVALID_OFFSET)
3748 {
3749 DWARFCompileUnit *spec_cu = cu;
3750 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3751 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3752 if (spec_die_decl_ctx_die)
3753 return spec_die_decl_ctx_die;
3754 }
3755
3756 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3757 if (die_offset != DW_INVALID_OFFSET)
3758 {
3759 DWARFCompileUnit *abs_cu = cu;
3760 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3761 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3762 if (abs_die_decl_ctx_die)
3763 return abs_die_decl_ctx_die;
3764 }
3765
3766 die = die->GetParent();
3767 }
3768 }
3769 return NULL;
3770}
3771
3772
Greg Clayton901c5ca2011-12-03 04:40:03 +00003773Symbol *
3774SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3775{
3776 Symbol *objc_class_symbol = NULL;
3777 if (m_obj_file)
3778 {
3779 Symtab *symtab = m_obj_file->GetSymtab();
3780 if (symtab)
3781 {
3782 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3783 eSymbolTypeObjCClass,
3784 Symtab::eDebugNo,
3785 Symtab::eVisibilityAny);
3786 }
3787 }
3788 return objc_class_symbol;
3789}
3790
3791
3792// This function can be used when a DIE is found that is a forward declaration
3793// DIE and we want to try and find a type that has the complete definition.
3794TypeSP
3795SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (DWARFCompileUnit* cu,
3796 const DWARFDebugInfoEntry *die,
3797 const ConstString &type_name)
3798{
3799
3800 TypeSP type_sp;
3801
3802 if (cu == NULL || die == NULL || !type_name || !GetObjCClassSymbol (type_name))
3803 return type_sp;
3804
3805 DIEArray die_offsets;
3806
3807 if (m_using_apple_tables)
3808 {
3809 if (m_apple_types_ap.get())
3810 {
3811 const char *name_cstr = type_name.GetCString();
3812 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3813 }
3814 }
3815 else
3816 {
3817 if (!m_indexed)
3818 Index ();
3819
3820 m_type_index.Find (type_name, die_offsets);
3821 }
3822
3823
3824 const size_t num_matches = die_offsets.size();
3825
3826 const dw_tag_t die_tag = die->Tag();
3827
3828 DWARFCompileUnit* type_cu = NULL;
3829 const DWARFDebugInfoEntry* type_die = NULL;
3830 if (num_matches)
3831 {
3832 DWARFDebugInfo* debug_info = DebugInfo();
3833 for (size_t i=0; i<num_matches; ++i)
3834 {
3835 const dw_offset_t die_offset = die_offsets[i];
3836 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
3837
3838 if (type_die)
3839 {
3840 bool try_resolving_type = false;
3841
3842 // Don't try and resolve the DIE we are looking for with the DIE itself!
3843 if (type_die != die)
3844 {
3845 const dw_tag_t type_die_tag = type_die->Tag();
3846 // Make sure the tags match
3847 if (type_die_tag == die_tag)
3848 {
3849 // The tags match, lets try resolving this type
3850 try_resolving_type = true;
3851 }
3852 else
3853 {
3854 // The tags don't match, but we need to watch our for a
3855 // forward declaration for a struct and ("struct foo")
3856 // ends up being a class ("class foo { ... };") or
3857 // vice versa.
3858 switch (type_die_tag)
3859 {
3860 case DW_TAG_class_type:
3861 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3862 try_resolving_type = (die_tag == DW_TAG_structure_type);
3863 break;
3864 case DW_TAG_structure_type:
3865 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3866 try_resolving_type = (die_tag == DW_TAG_class_type);
3867 break;
3868 default:
3869 // Tags don't match, don't event try to resolve
3870 // using this type whose name matches....
3871 break;
3872 }
3873 }
3874 }
3875
3876 if (try_resolving_type)
3877 {
3878 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
3879
3880 if (try_resolving_type)
3881 {
3882 Type *resolved_type = ResolveType (type_cu, type_die, false);
3883 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3884 {
3885 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
3886 MakeUserID(die->GetOffset()),
3887 MakeUserID(curr_cu->GetOffset()),
3888 m_obj_file->GetFileSpec().GetFilename().AsCString(),
3889 MakeUserID(type_die->GetOffset()),
3890 MakeUserID(type_cu->GetOffset()));
3891
3892 m_die_to_type[die] = resolved_type;
3893 type_sp = resolved_type;
3894 break;
3895 }
3896 }
3897 }
3898 }
3899 else
3900 {
3901 if (m_using_apple_tables)
3902 {
3903 ReportError (".apple_types accelerator table had bad die 0x%8.8x for '%s'\n",
3904 die_offset, type_name.GetCString());
3905 }
3906 }
3907
3908 }
3909 }
3910 return type_sp;
3911}
3912
Greg Clayton2bc22f82011-09-30 03:20:47 +00003913
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003914// This function can be used when a DIE is found that is a forward declaration
3915// DIE and we want to try and find a type that has the complete definition.
3916TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00003917SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
3918 const DWARFDebugInfoEntry *die,
3919 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003920{
3921 TypeSP type_sp;
3922
Greg Clayton1a65ae12011-01-25 23:55:37 +00003923 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003924 return type_sp;
3925
Greg Clayton7f995132011-10-04 22:41:51 +00003926 DIEArray die_offsets;
3927
Greg Clayton97fbc342011-10-20 22:30:33 +00003928 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003929 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003930 if (m_apple_types_ap.get())
3931 {
3932 const char *name_cstr = type_name.GetCString();
3933 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3934 }
Greg Clayton7f995132011-10-04 22:41:51 +00003935 }
3936 else
3937 {
3938 if (!m_indexed)
3939 Index ();
3940
3941 m_type_index.Find (type_name, die_offsets);
3942 }
3943
3944
3945 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00003946
Greg Clayton934cb052011-12-03 00:27:05 +00003947 const dw_tag_t die_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00003948
3949 DWARFCompileUnit* type_cu = NULL;
3950 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003951 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003952 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003953 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003954 for (size_t i=0; i<num_matches; ++i)
3955 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003956 const dw_offset_t die_offset = die_offsets[i];
3957 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003958
Greg Clayton95d87902011-11-11 03:16:25 +00003959 if (type_die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003960 {
Greg Clayton934cb052011-12-03 00:27:05 +00003961 bool try_resolving_type = false;
3962
3963 // Don't try and resolve the DIE we are looking for with the DIE itself!
3964 if (type_die != die)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003965 {
Greg Clayton934cb052011-12-03 00:27:05 +00003966 const dw_tag_t type_die_tag = type_die->Tag();
3967 // Make sure the tags match
3968 if (type_die_tag == die_tag)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003969 {
Greg Clayton934cb052011-12-03 00:27:05 +00003970 // The tags match, lets try resolving this type
3971 try_resolving_type = true;
3972 }
3973 else
3974 {
3975 // The tags don't match, but we need to watch our for a
3976 // forward declaration for a struct and ("struct foo")
3977 // ends up being a class ("class foo { ... };") or
3978 // vice versa.
3979 switch (type_die_tag)
Greg Clayton95d87902011-11-11 03:16:25 +00003980 {
Greg Clayton934cb052011-12-03 00:27:05 +00003981 case DW_TAG_class_type:
3982 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3983 try_resolving_type = (die_tag == DW_TAG_structure_type);
3984 break;
3985 case DW_TAG_structure_type:
3986 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3987 try_resolving_type = (die_tag == DW_TAG_class_type);
3988 break;
3989 default:
3990 // Tags don't match, don't event try to resolve
3991 // using this type whose name matches....
Greg Clayton95d87902011-11-11 03:16:25 +00003992 break;
3993 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003994 }
3995 }
Greg Clayton934cb052011-12-03 00:27:05 +00003996
3997 if (try_resolving_type)
3998 {
3999 Type *resolved_type = ResolveType (type_cu, type_die, false);
4000 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4001 {
4002 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4003 MakeUserID(die->GetOffset()),
4004 MakeUserID(curr_cu->GetOffset()),
4005 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4006 MakeUserID(type_die->GetOffset()),
4007 MakeUserID(type_cu->GetOffset()));
4008
4009 m_die_to_type[die] = resolved_type;
4010 type_sp = resolved_type;
4011 break;
4012 }
4013 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004014 }
Greg Clayton95d87902011-11-11 03:16:25 +00004015 else
4016 {
4017 if (m_using_apple_tables)
4018 {
4019 ReportError (".apple_types accelerator table had bad die 0x%8.8x for '%s'\n",
4020 die_offset, type_name.GetCString());
4021 }
4022 }
4023
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00004024 }
4025 }
4026 return type_sp;
4027}
4028
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004029TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00004030SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004031{
4032 TypeSP type_sp;
4033
Greg Clayton1be10fc2010-09-29 01:12:09 +00004034 if (type_is_new_ptr)
4035 *type_is_new_ptr = false;
4036
Sean Callananc7fbf732010-08-06 00:32:49 +00004037 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004038 if (die != NULL)
4039 {
Greg Clayton21f2a492011-10-06 00:09:08 +00004040 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Jim Ingham16746d12011-08-25 23:21:43 +00004041 if (log && dwarf_cu)
4042 {
Jim Ingham318c9f22011-08-26 19:44:13 +00004043 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00004044 die->DumpLocation (this, dwarf_cu, s);
Greg Clayton18774842011-11-29 23:40:34 +00004045 LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
Jim Ingham318c9f22011-08-26 19:44:13 +00004046
Jim Ingham16746d12011-08-25 23:21:43 +00004047 }
4048
Greg Clayton594e5ed2010-09-27 21:07:38 +00004049 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004050 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00004051 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004052 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004053 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00004054 if (type_is_new_ptr)
4055 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004056
Greg Clayton594e5ed2010-09-27 21:07:38 +00004057 const dw_tag_t tag = die->Tag();
4058
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004059 bool is_forward_declaration = false;
4060 DWARFDebugInfoEntry::Attributes attributes;
4061 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00004062 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00004063 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4064 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00004065 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00004066 Declaration decl;
4067
Greg Clayton4957bf62010-09-30 21:49:03 +00004068 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004069 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004071 dw_attr_t attr;
4072
4073 switch (tag)
4074 {
4075 case DW_TAG_base_type:
4076 case DW_TAG_pointer_type:
4077 case DW_TAG_reference_type:
4078 case DW_TAG_typedef:
4079 case DW_TAG_const_type:
4080 case DW_TAG_restrict_type:
4081 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00004082 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004083 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004084 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004085 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004086
Greg Claytond88d7592010-09-15 08:33:30 +00004087 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004088 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004089 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4090
4091 if (num_attributes > 0)
4092 {
4093 uint32_t i;
4094 for (i=0; i<num_attributes; ++i)
4095 {
4096 attr = attributes.AttributeAtIndex(i);
4097 DWARFFormValue form_value;
4098 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4099 {
4100 switch (attr)
4101 {
4102 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4103 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4104 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4105 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00004106
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004107 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00004108 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4109 // include the "&"...
4110 if (tag == DW_TAG_reference_type)
4111 {
4112 if (strchr (type_name_cstr, '&') == NULL)
4113 type_name_cstr = NULL;
4114 }
4115 if (type_name_cstr)
4116 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004117 break;
Greg Clayton36909642011-03-15 04:38:20 +00004118 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004119 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
4120 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
4121 default:
4122 case DW_AT_sibling:
4123 break;
4124 }
4125 }
4126 }
4127 }
4128
Greg Clayton81c22f62011-10-19 18:09:39 +00004129 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 +00004130
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004131 switch (tag)
4132 {
4133 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00004134 break;
4135
Greg Claytond4436412011-10-28 21:00:00 +00004136 case DW_TAG_unspecified_type:
4137 if (strcmp(type_name_cstr, "nullptr_t") == 0)
4138 {
4139 resolve_state = Type::eResolveStateFull;
4140 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4141 break;
4142 }
4143 // Fall through to base type below in case we can handle the type there...
4144
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004145 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00004146 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004147 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4148 encoding,
4149 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004150 break;
4151
Greg Clayton526e5af2010-11-13 03:52:47 +00004152 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
4153 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
4154 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
4155 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
4156 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
4157 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004158 }
4159
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004160 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4161 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
4162 {
4163 static ConstString g_objc_type_name_id("id");
4164 static ConstString g_objc_type_name_Class("Class");
4165 static ConstString g_objc_type_name_selector("SEL");
4166
Greg Clayton24739922010-10-13 03:15:28 +00004167 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004168 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004169 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00004170 resolve_state = Type::eResolveStateFull;
4171
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004172 }
Greg Clayton24739922010-10-13 03:15:28 +00004173 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004174 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004175 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00004176 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004177 }
Greg Clayton24739922010-10-13 03:15:28 +00004178 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004179 {
Sean Callananf6c73082010-12-06 23:53:20 +00004180 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00004181 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00004182 }
4183 }
4184
Greg Clayton81c22f62011-10-19 18:09:39 +00004185 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004186 this,
4187 type_name_const_str,
4188 byte_size,
4189 NULL,
4190 encoding_uid,
4191 encoding_data_type,
4192 &decl,
4193 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004194 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004195
Greg Clayton594e5ed2010-09-27 21:07:38 +00004196 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004197
4198// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4199// if (encoding_type != NULL)
4200// {
4201// if (encoding_type != DIE_IS_BEING_PARSED)
4202// type_sp->SetEncodingType(encoding_type);
4203// else
4204// m_indirect_fixups.push_back(type_sp.get());
4205// }
4206 }
4207 break;
4208
4209 case DW_TAG_structure_type:
4210 case DW_TAG_union_type:
4211 case DW_TAG_class_type:
4212 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004213 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004214 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004215
Greg Clayton9e409562010-07-28 02:04:09 +00004216 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton18774842011-11-29 23:40:34 +00004217 bool is_complete_objc_class = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00004219 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004220 if (num_attributes > 0)
4221 {
4222 uint32_t i;
4223 for (i=0; i<num_attributes; ++i)
4224 {
4225 attr = attributes.AttributeAtIndex(i);
4226 DWARFFormValue form_value;
4227 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4228 {
4229 switch (attr)
4230 {
Greg Clayton9e409562010-07-28 02:04:09 +00004231 case DW_AT_decl_file:
4232 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
4233 break;
4234
4235 case DW_AT_decl_line:
4236 decl.SetLine(form_value.Unsigned());
4237 break;
4238
4239 case DW_AT_decl_column:
4240 decl.SetColumn(form_value.Unsigned());
4241 break;
4242
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004243 case DW_AT_name:
4244 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004245 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004246 break;
Greg Clayton9e409562010-07-28 02:04:09 +00004247
4248 case DW_AT_byte_size:
4249 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004250 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004251 break;
4252
4253 case DW_AT_accessibility:
4254 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4255 break;
4256
4257 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004258 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004259 break;
4260
4261 case DW_AT_APPLE_runtime_class:
4262 class_language = (LanguageType)form_value.Signed();
4263 break;
4264
Greg Clayton18774842011-11-29 23:40:34 +00004265 case DW_AT_APPLE_objc_complete_type:
4266 is_complete_objc_class = form_value.Signed();
4267 break;
4268
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004269 case DW_AT_allocated:
4270 case DW_AT_associated:
4271 case DW_AT_data_location:
4272 case DW_AT_description:
4273 case DW_AT_start_scope:
4274 case DW_AT_visibility:
4275 default:
4276 case DW_AT_sibling:
4277 break;
4278 }
4279 }
4280 }
4281 }
4282
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004283 UniqueDWARFASTType unique_ast_entry;
4284 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004285 {
Greg Claytone576ab22011-02-15 00:19:15 +00004286 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00004287 this,
4288 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00004289 die,
4290 decl,
Greg Clayton36909642011-03-15 04:38:20 +00004291 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00004292 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00004293 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004294 // We have already parsed this type or from another
4295 // compile unit. GCC loves to use the "one definition
4296 // rule" which can result in multiple definitions
4297 // of the same class over and over in each compile
4298 // unit.
4299 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004300 if (type_sp)
4301 {
Greg Clayton4272cc72011-02-02 02:24:04 +00004302 m_die_to_type[die] = type_sp.get();
4303 return type_sp;
4304 }
4305 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004306 }
4307
Greg Clayton81c22f62011-10-19 18:09:39 +00004308 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 +00004309
4310 int tag_decl_kind = -1;
4311 AccessType default_accessibility = eAccessNone;
4312 if (tag == DW_TAG_structure_type)
4313 {
4314 tag_decl_kind = clang::TTK_Struct;
4315 default_accessibility = eAccessPublic;
4316 }
4317 else if (tag == DW_TAG_union_type)
4318 {
4319 tag_decl_kind = clang::TTK_Union;
4320 default_accessibility = eAccessPublic;
4321 }
4322 else if (tag == DW_TAG_class_type)
4323 {
4324 tag_decl_kind = clang::TTK_Class;
4325 default_accessibility = eAccessPrivate;
4326 }
Greg Clayton3a5f29a2011-11-30 02:48:28 +00004327
4328 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4329 die->HasChildren() == false &&
4330 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4331 {
4332 // Work around an issue with clang at the moment where
4333 // forward declarations for objective C classes are emitted
4334 // as:
4335 // DW_TAG_structure_type [2]
4336 // DW_AT_name( "ForwardObjcClass" )
4337 // DW_AT_byte_size( 0x00 )
4338 // DW_AT_decl_file( "..." )
4339 // DW_AT_decl_line( 1 )
4340 //
4341 // Note that there is no DW_AT_declaration and there are
4342 // no children, and the byte size is zero.
4343 is_forward_declaration = true;
4344 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004345
Greg Clayton18774842011-11-29 23:40:34 +00004346 if (class_language == eLanguageTypeObjC)
4347 {
Greg Clayton901c5ca2011-12-03 04:40:03 +00004348 if (!is_complete_objc_class)
4349 {
4350 // We have a valid eSymbolTypeObjCClass class symbol whose
4351 // name matches the current objective C class that we
4352 // are trying to find and this DIE isn't the complete
4353 // definition (we checked is_complete_objc_class above and
4354 // know it is false), so the real definition is in here somewhere
4355 type_sp = FindCompleteObjCDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004356
Greg Clayton901c5ca2011-12-03 04:40:03 +00004357 if (!type_sp && m_debug_map_symfile)
4358 {
4359 // We weren't able to find a full declaration in
4360 // this DWARF, see if we have a declaration anywhere
4361 // else...
4362 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4363 }
4364
4365 if (type_sp)
4366 {
4367 if (log)
4368 {
4369 LogMessage (log.get(),
4370 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4371 this,
4372 die->GetOffset(),
4373 DW_TAG_value_to_name(tag),
4374 type_name_cstr,
4375 type_sp->GetID());
4376 }
4377
4378 // We found a real definition for this type elsewhere
4379 // so lets use it and cache the fact that we found
4380 // a complete type for this die
4381 m_die_to_type[die] = type_sp.get();
4382 return type_sp;
4383 }
4384 }
4385 }
4386
4387
4388 if (is_forward_declaration)
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004389 {
4390 // We have a forward declaration to a type and we need
4391 // to try and find a full declaration. We look in the
4392 // current type index just in case we have a forward
4393 // declaration followed by an actual declarations in the
4394 // DWARF. If this fails, we need to look elsewhere...
Greg Claytonc982b3d2011-11-28 01:45:00 +00004395 if (log)
4396 {
4397 LogMessage (log.get(),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004398 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
Greg Claytonc982b3d2011-11-28 01:45:00 +00004399 this,
4400 die->GetOffset(),
4401 DW_TAG_value_to_name(tag),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004402 type_name_cstr);
Greg Claytonc982b3d2011-11-28 01:45:00 +00004403 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004404
4405 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4406
4407 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004408 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004409 // We weren't able to find a full declaration in
4410 // this DWARF, see if we have a declaration anywhere
4411 // else...
4412 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004413 }
4414
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004415 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004416 {
Greg Claytonc982b3d2011-11-28 01:45:00 +00004417 if (log)
4418 {
Greg Clayton18774842011-11-29 23:40:34 +00004419 LogMessage (log.get(),
Greg Clayton901c5ca2011-12-03 04:40:03 +00004420 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
Greg Clayton18774842011-11-29 23:40:34 +00004421 this,
4422 die->GetOffset(),
4423 DW_TAG_value_to_name(tag),
4424 type_name_cstr,
Greg Clayton18774842011-11-29 23:40:34 +00004425 type_sp->GetID());
Greg Claytonc982b3d2011-11-28 01:45:00 +00004426 }
4427
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004428 // We found a real definition for this type elsewhere
4429 // so lets use it and cache the fact that we found
4430 // a complete type for this die
4431 m_die_to_type[die] = type_sp.get();
4432 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004433 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004434 }
4435 assert (tag_decl_kind != -1);
4436 bool clang_type_was_created = false;
4437 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4438 if (clang_type == NULL)
4439 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004440 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton55561e92011-10-26 03:31:36 +00004441 if (accessibility == eAccessNone && decl_ctx)
4442 {
4443 // Check the decl context that contains this class/struct/union.
4444 // If it is a class we must give it an accessability.
4445 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4446 if (DeclKindIsCXXClass (containing_decl_kind))
4447 accessibility = default_accessibility;
4448 }
4449
Greg Claytonf0705c82011-10-22 03:33:13 +00004450 if (type_name_cstr && strchr (type_name_cstr, '<'))
4451 {
4452 ClangASTContext::TemplateParameterInfos template_param_infos;
4453 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4454 {
4455 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004456 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004457 type_name_cstr,
4458 tag_decl_kind,
4459 template_param_infos);
4460
4461 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4462 class_template_decl,
4463 tag_decl_kind,
4464 template_param_infos);
4465 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4466 clang_type_was_created = true;
4467 }
4468 }
4469
4470 if (!clang_type_was_created)
4471 {
4472 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004473 clang_type = ast.CreateRecordType (decl_ctx,
4474 accessibility,
4475 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004476 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004477 class_language);
4478 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004479 }
4480
4481 // Store a forward declaration to this class type in case any
4482 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004483 // types for function prototypes.
4484 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004485 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004486 this,
4487 type_name_const_str,
4488 byte_size,
4489 NULL,
4490 LLDB_INVALID_UID,
4491 Type::eEncodingIsUID,
4492 &decl,
4493 clang_type,
4494 Type::eResolveStateForward));
4495
4496
4497 // Add our type to the unique type map so we don't
4498 // end up creating many copies of the same type over
4499 // and over in the ASTContext for our module
4500 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004501 unique_ast_entry.m_symfile = this;
4502 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004503 unique_ast_entry.m_die = die;
4504 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00004505 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4506 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004507
4508 if (die->HasChildren() == false && is_forward_declaration == false)
4509 {
4510 // No children for this struct/union/class, lets finish it
4511 ast.StartTagDeclarationDefinition (clang_type);
4512 ast.CompleteTagDeclarationDefinition (clang_type);
4513 }
4514 else if (clang_type_was_created)
4515 {
4516 // Leave this as a forward declaration until we need
4517 // to know the details of the type. lldb_private::Type
4518 // will automatically call the SymbolFile virtual function
4519 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
4520 // When the definition needs to be defined.
4521 m_forward_decl_die_to_clang_type[die] = clang_type;
4522 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
4523 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00004524 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004525 }
4526 break;
4527
4528 case DW_TAG_enumeration_type:
4529 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004530 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004531 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004532
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004533 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004534
Greg Claytond88d7592010-09-15 08:33:30 +00004535 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004536 if (num_attributes > 0)
4537 {
4538 uint32_t i;
4539
4540 for (i=0; i<num_attributes; ++i)
4541 {
4542 attr = attributes.AttributeAtIndex(i);
4543 DWARFFormValue form_value;
4544 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4545 {
4546 switch (attr)
4547 {
Greg Clayton7a345282010-11-09 23:46:37 +00004548 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4549 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4550 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004551 case DW_AT_name:
4552 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004553 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004554 break;
Greg Clayton7a345282010-11-09 23:46:37 +00004555 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004556 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00004557 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4558 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004559 case DW_AT_allocated:
4560 case DW_AT_associated:
4561 case DW_AT_bit_stride:
4562 case DW_AT_byte_stride:
4563 case DW_AT_data_location:
4564 case DW_AT_description:
4565 case DW_AT_start_scope:
4566 case DW_AT_visibility:
4567 case DW_AT_specification:
4568 case DW_AT_abstract_origin:
4569 case DW_AT_sibling:
4570 break;
4571 }
4572 }
4573 }
4574
Greg Clayton81c22f62011-10-19 18:09:39 +00004575 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 +00004576
Greg Clayton1be10fc2010-09-29 01:12:09 +00004577 clang_type_t enumerator_clang_type = NULL;
4578 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4579 if (clang_type == NULL)
4580 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004581 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
4582 DW_ATE_signed,
4583 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00004584 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00004585 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00004586 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004587 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004588 }
4589 else
4590 {
4591 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
4592 assert (enumerator_clang_type != NULL);
4593 }
4594
Greg Claytona2721472011-06-25 00:44:06 +00004595 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
4596
Greg Clayton81c22f62011-10-19 18:09:39 +00004597 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004598 this,
4599 type_name_const_str,
4600 byte_size,
4601 NULL,
4602 encoding_uid,
4603 Type::eEncodingIsUID,
4604 &decl,
4605 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004606 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004607
Greg Clayton6beaaa62011-01-17 03:46:26 +00004608 ast.StartTagDeclarationDefinition (clang_type);
4609 if (die->HasChildren())
4610 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004611 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
4612 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00004613 }
4614 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004615 }
4616 }
4617 break;
4618
Jim Inghamb0be4422010-08-12 01:20:14 +00004619 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004620 case DW_TAG_subprogram:
4621 case DW_TAG_subroutine_type:
4622 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004623 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004624 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004625
4626 const char *mangled = NULL;
4627 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004628 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004629 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00004630 bool is_static = false;
4631 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00004632 bool is_explicit = false;
Sean Callanandbb58392011-11-02 01:38:59 +00004633 bool is_artificial = false;
Greg Clayton72da3972011-08-16 18:40:23 +00004634 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
4635 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00004636
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004637 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00004638 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004639
4640
Greg Claytond88d7592010-09-15 08:33:30 +00004641 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004642 if (num_attributes > 0)
4643 {
4644 uint32_t i;
4645 for (i=0; i<num_attributes; ++i)
4646 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004647 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004648 DWARFFormValue form_value;
4649 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4650 {
4651 switch (attr)
4652 {
4653 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4654 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4655 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4656 case DW_AT_name:
4657 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004658 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004659 break;
4660
4661 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
4662 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004663 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00004664 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004665 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
4666 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00004667 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
Sean Callanandbb58392011-11-02 01:38:59 +00004668 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
4669
Greg Claytonf51de672010-10-01 02:31:07 +00004670
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004671 case DW_AT_external:
4672 if (form_value.Unsigned())
4673 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00004674 if (storage == clang::SC_None)
4675 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004676 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00004677 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004678 }
4679 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004680
Greg Clayton72da3972011-08-16 18:40:23 +00004681 case DW_AT_specification:
4682 specification_die_offset = form_value.Reference(dwarf_cu);
4683 break;
4684
4685 case DW_AT_abstract_origin:
4686 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
4687 break;
4688
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004689 case DW_AT_allocated:
4690 case DW_AT_associated:
4691 case DW_AT_address_class:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004692 case DW_AT_calling_convention:
4693 case DW_AT_data_location:
4694 case DW_AT_elemental:
4695 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004696 case DW_AT_frame_base:
4697 case DW_AT_high_pc:
4698 case DW_AT_low_pc:
4699 case DW_AT_object_pointer:
4700 case DW_AT_prototyped:
4701 case DW_AT_pure:
4702 case DW_AT_ranges:
4703 case DW_AT_recursive:
4704 case DW_AT_return_addr:
4705 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004706 case DW_AT_start_scope:
4707 case DW_AT_static_link:
4708 case DW_AT_trampoline:
4709 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004710 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004711 case DW_AT_description:
4712 case DW_AT_sibling:
4713 break;
4714 }
4715 }
4716 }
Greg Clayton24739922010-10-13 03:15:28 +00004717 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004718
Greg Clayton81c22f62011-10-19 18:09:39 +00004719 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 +00004720
Greg Clayton24739922010-10-13 03:15:28 +00004721 clang_type_t return_clang_type = NULL;
4722 Type *func_type = NULL;
4723
4724 if (type_die_offset != DW_INVALID_OFFSET)
4725 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00004726
Greg Clayton24739922010-10-13 03:15:28 +00004727 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00004728 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00004729 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004730 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004731
Greg Claytonf51de672010-10-01 02:31:07 +00004732
Greg Clayton24739922010-10-13 03:15:28 +00004733 std::vector<clang_type_t> function_param_types;
4734 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004735
Greg Clayton24739922010-10-13 03:15:28 +00004736 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00004737
Greg Claytoncb5860a2011-10-13 23:49:28 +00004738 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
4739 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00004740 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
4741
Greg Claytonf0705c82011-10-22 03:33:13 +00004742 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00004743 // Start off static. This will be set to false in ParseChildParameters(...)
4744 // if we find a "this" paramters as the first parameter
4745 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00004746 is_static = true;
4747
Greg Clayton24739922010-10-13 03:15:28 +00004748 if (die->HasChildren())
4749 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004750 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004751 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00004752 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004753 type_sp,
4754 dwarf_cu,
4755 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00004756 skip_artificial,
4757 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004758 type_list,
4759 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00004760 function_param_decls,
4761 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00004762 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004763
Greg Clayton24739922010-10-13 03:15:28 +00004764 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004765 clang_type = ast.CreateFunctionType (return_clang_type,
4766 &function_param_types[0],
4767 function_param_types.size(),
4768 is_variadic,
4769 type_quals);
4770
Greg Clayton24739922010-10-13 03:15:28 +00004771 if (type_name_cstr)
4772 {
4773 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00004774 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004775 {
Jim Inghamb7f6b2f2011-09-08 22:13:49 +00004776 if (ObjCLanguageRuntime::IsPossibleObjCMethodName (type_name_cstr))
Greg Clayton0fffff52010-09-24 05:15:53 +00004777 {
Greg Clayton24739922010-10-13 03:15:28 +00004778 // We need to find the DW_TAG_class_type or
4779 // DW_TAG_struct_type by name so we can add this
4780 // as a member function of the class.
4781 const char *class_name_start = type_name_cstr + 2;
4782 const char *class_name_end = ::strchr (class_name_start, ' ');
4783 SymbolContext empty_sc;
4784 clang_type_t class_opaque_type = NULL;
4785 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00004786 {
Greg Clayton24739922010-10-13 03:15:28 +00004787 ConstString class_name (class_name_start, class_name_end - class_name_start);
4788 TypeList types;
Sean Callanan213fdb82011-10-13 01:49:10 +00004789 const uint32_t match_count = FindTypes (empty_sc, class_name, NULL, true, UINT32_MAX, types);
Greg Clayton24739922010-10-13 03:15:28 +00004790 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00004791 {
Greg Clayton24739922010-10-13 03:15:28 +00004792 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00004793 {
Greg Clayton24739922010-10-13 03:15:28 +00004794 Type *type = types.GetTypeAtIndex (i).get();
4795 clang_type_t type_clang_forward_type = type->GetClangForwardType();
4796 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00004797 {
Greg Clayton24739922010-10-13 03:15:28 +00004798 class_opaque_type = type_clang_forward_type;
4799 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004800 }
4801 }
4802 }
Greg Clayton24739922010-10-13 03:15:28 +00004803 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004804
Greg Clayton24739922010-10-13 03:15:28 +00004805 if (class_opaque_type)
4806 {
4807 // If accessibility isn't set to anything valid, assume public for
4808 // now...
4809 if (accessibility == eAccessNone)
4810 accessibility = eAccessPublic;
4811
4812 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004813 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
4814 type_name_cstr,
4815 clang_type,
4816 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004817 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00004818 type_handled = objc_method_decl != NULL;
4819 }
4820 }
Greg Clayton5113dc82011-08-12 06:47:54 +00004821 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00004822 {
4823 // Look at the parent of this DIE and see if is is
4824 // a class or struct and see if this is actually a
4825 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00004826 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00004827 if (class_type)
4828 {
Greg Clayton72da3972011-08-16 18:40:23 +00004829 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00004830 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004831 // We have a specification which we are going to base our function
4832 // prototype off of, so we need this type to be completed so that the
4833 // m_die_to_decl_ctx for the method in the specification has a valid
4834 // clang decl context.
4835 class_type->GetClangFullType();
Greg Clayton72da3972011-08-16 18:40:23 +00004836 // If we have a specification, then the function type should have been
4837 // made with the specification and not with this die.
4838 DWARFCompileUnitSP spec_cu_sp;
4839 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004840 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
4841 if (spec_clang_decl_ctx)
4842 {
4843 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
4844 }
4845 else
Jim Inghamc1663042011-09-29 22:12:35 +00004846 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004847 ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
4848 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004849 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004850 }
Greg Clayton72da3972011-08-16 18:40:23 +00004851 type_handled = true;
4852 }
4853 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
4854 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004855 // We have a specification which we are going to base our function
4856 // prototype off of, so we need this type to be completed so that the
4857 // m_die_to_decl_ctx for the method in the abstract origin has a valid
4858 // clang decl context.
4859 class_type->GetClangFullType();
4860
Greg Clayton72da3972011-08-16 18:40:23 +00004861 DWARFCompileUnitSP abs_cu_sp;
4862 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004863 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
4864 if (abs_clang_decl_ctx)
4865 {
4866 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
4867 }
4868 else
Jim Inghamc1663042011-09-29 22:12:35 +00004869 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004870 ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
4871 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004872 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004873 }
Greg Clayton72da3972011-08-16 18:40:23 +00004874 type_handled = true;
4875 }
4876 else
4877 {
4878 clang_type_t class_opaque_type = class_type->GetClangForwardType();
4879 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00004880 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004881 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00004882 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004883 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
4884 // in the DWARF for C++ methods... Default to public for now...
4885 if (accessibility == eAccessNone)
4886 accessibility = eAccessPublic;
4887
4888 if (!is_static && !die->HasChildren())
4889 {
4890 // We have a C++ member function with no children (this pointer!)
4891 // and clang will get mad if we try and make a function that isn't
4892 // well formed in the DWARF, so we will just skip it...
4893 type_handled = true;
4894 }
4895 else
4896 {
4897 clang::CXXMethodDecl *cxx_method_decl;
4898 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00004899 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 +00004900 type_name_cstr,
4901 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00004902 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00004903 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
4904 m_obj_file->GetFileSpec().GetFilename().GetCString());
4905
Sean Callananc1b732d2011-11-01 18:07:13 +00004906 const bool is_attr_used = false;
4907
Greg Clayton20568dd2011-10-13 23:13:20 +00004908 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
4909 type_name_cstr,
4910 clang_type,
4911 accessibility,
4912 is_virtual,
4913 is_static,
4914 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00004915 is_explicit,
Sean Callanandbb58392011-11-02 01:38:59 +00004916 is_attr_used,
4917 is_artificial);
Greg Clayton20568dd2011-10-13 23:13:20 +00004918 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
4919
Greg Claytonf49e65a2011-11-10 18:31:53 +00004920 Host::SetCrashDescription (NULL);
4921
Greg Clayton20568dd2011-10-13 23:13:20 +00004922 type_handled = cxx_method_decl != NULL;
4923 }
Greg Clayton72da3972011-08-16 18:40:23 +00004924 }
4925 else
4926 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004927 // We were asked to parse the type for a method in a class, yet the
4928 // class hasn't been asked to complete itself through the
4929 // clang::ExternalASTSource protocol, so we need to just have the
4930 // class complete itself and do things the right way, then our
4931 // DIE should then have an entry in the m_die_to_type map. First
4932 // we need to modify the m_die_to_type so it doesn't think we are
4933 // trying to parse this DIE anymore...
4934 m_die_to_type[die] = NULL;
4935
4936 // Now we get the full type to force our class type to complete itself
4937 // using the clang::ExternalASTSource protocol which will parse all
4938 // base classes and all methods (including the method for this DIE).
4939 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004940
Greg Clayton20568dd2011-10-13 23:13:20 +00004941 // The type for this DIE should have been filled in the function call above
4942 type_ptr = m_die_to_type[die];
4943 if (type_ptr)
4944 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00004945 type_sp = type_ptr;
Greg Clayton20568dd2011-10-13 23:13:20 +00004946 break;
4947 }
Greg Clayton72da3972011-08-16 18:40:23 +00004948 }
Greg Clayton931180e2011-01-27 06:44:37 +00004949 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004950 }
4951 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004952 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004953 }
Greg Clayton24739922010-10-13 03:15:28 +00004954
4955 if (!type_handled)
4956 {
4957 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00004958 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
4959 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004960 clang_type,
4961 storage,
4962 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00004963
4964 // Add the decl to our DIE to decl context map
4965 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00004966 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00004967 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004968 ast.SetFunctionParameters (function_decl,
4969 &function_param_decls.front(),
4970 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00004971 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004972 }
Greg Clayton81c22f62011-10-19 18:09:39 +00004973 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004974 this,
4975 type_name_const_str,
4976 0,
4977 NULL,
4978 LLDB_INVALID_UID,
4979 Type::eEncodingIsUID,
4980 &decl,
4981 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004982 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00004983 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004984 }
4985 break;
4986
4987 case DW_TAG_array_type:
4988 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004989 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004990 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004991
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004992 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004993 int64_t first_index = 0;
4994 uint32_t byte_stride = 0;
4995 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00004996 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004997
4998 if (num_attributes > 0)
4999 {
5000 uint32_t i;
5001 for (i=0; i<num_attributes; ++i)
5002 {
5003 attr = attributes.AttributeAtIndex(i);
5004 DWARFFormValue form_value;
5005 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5006 {
5007 switch (attr)
5008 {
5009 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5010 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5011 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5012 case DW_AT_name:
5013 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00005014 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005015 break;
5016
5017 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00005018 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005019 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
5020 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00005021 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00005022 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005023 case DW_AT_allocated:
5024 case DW_AT_associated:
5025 case DW_AT_data_location:
5026 case DW_AT_description:
5027 case DW_AT_ordering:
5028 case DW_AT_start_scope:
5029 case DW_AT_visibility:
5030 case DW_AT_specification:
5031 case DW_AT_abstract_origin:
5032 case DW_AT_sibling:
5033 break;
5034 }
5035 }
5036 }
5037
Greg Clayton81c22f62011-10-19 18:09:39 +00005038 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 +00005039
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005040 Type *element_type = ResolveTypeUID(type_die_offset);
5041
5042 if (element_type)
5043 {
5044 std::vector<uint64_t> element_orders;
5045 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00005046 // We have an array that claims to have no members, lets give it at least one member...
5047 if (element_orders.empty())
5048 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005049 if (byte_stride == 0 && bit_stride == 0)
5050 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00005051 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005052 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5053 uint64_t num_elements = 0;
5054 std::vector<uint64_t>::const_reverse_iterator pos;
5055 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5056 for (pos = element_orders.rbegin(); pos != end; ++pos)
5057 {
5058 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005059 clang_type = ast.CreateArrayType (array_element_type,
5060 num_elements,
5061 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005062 array_element_type = clang_type;
5063 array_element_bit_stride = array_element_bit_stride * num_elements;
5064 }
5065 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00005066 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005067 this,
5068 empty_name,
5069 array_element_bit_stride / 8,
5070 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00005071 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005072 Type::eEncodingIsUID,
5073 &decl,
5074 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005075 Type::eResolveStateFull));
5076 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005077 }
5078 }
5079 }
5080 break;
5081
Greg Clayton9b81a312010-06-12 01:20:30 +00005082 case DW_TAG_ptr_to_member_type:
5083 {
5084 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5085 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5086
Greg Claytond88d7592010-09-15 08:33:30 +00005087 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00005088
5089 if (num_attributes > 0) {
5090 uint32_t i;
5091 for (i=0; i<num_attributes; ++i)
5092 {
5093 attr = attributes.AttributeAtIndex(i);
5094 DWARFFormValue form_value;
5095 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5096 {
5097 switch (attr)
5098 {
5099 case DW_AT_type:
5100 type_die_offset = form_value.Reference(dwarf_cu); break;
5101 case DW_AT_containing_type:
5102 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5103 }
5104 }
5105 }
5106
5107 Type *pointee_type = ResolveTypeUID(type_die_offset);
5108 Type *class_type = ResolveTypeUID(containing_type_die_offset);
5109
Greg Clayton526e5af2010-11-13 03:52:47 +00005110 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5111 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00005112
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005113 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5114 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00005115
Greg Clayton526e5af2010-11-13 03:52:47 +00005116 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5117 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00005118
Greg Clayton81c22f62011-10-19 18:09:39 +00005119 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00005120 this,
5121 type_name_const_str,
5122 byte_size,
5123 NULL,
5124 LLDB_INVALID_UID,
5125 Type::eEncodingIsUID,
5126 NULL,
5127 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00005128 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00005129 }
5130
5131 break;
5132 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005133 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00005134 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005135 break;
5136 }
5137
5138 if (type_sp.get())
5139 {
5140 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5141 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5142
5143 SymbolContextScope * symbol_context_scope = NULL;
5144 if (sc_parent_tag == DW_TAG_compile_unit)
5145 {
5146 symbol_context_scope = sc.comp_unit;
5147 }
5148 else if (sc.function != NULL)
5149 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005150 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005151 if (symbol_context_scope == NULL)
5152 symbol_context_scope = sc.function;
5153 }
5154
5155 if (symbol_context_scope != NULL)
5156 {
5157 type_sp->SetSymbolContextScope(symbol_context_scope);
5158 }
5159
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005160 // We are ready to put this type into the uniqued list up at the module level
5161 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00005162
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00005163 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005164 }
5165 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00005166 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005167 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00005168 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005169 }
5170 }
5171 return type_sp;
5172}
5173
5174size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00005175SymbolFileDWARF::ParseTypes
5176(
5177 const SymbolContext& sc,
5178 DWARFCompileUnit* dwarf_cu,
5179 const DWARFDebugInfoEntry *die,
5180 bool parse_siblings,
5181 bool parse_children
5182)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005183{
5184 size_t types_added = 0;
5185 while (die != NULL)
5186 {
5187 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00005188 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005189 {
5190 if (type_is_new)
5191 ++types_added;
5192 }
5193
5194 if (parse_children && die->HasChildren())
5195 {
5196 if (die->Tag() == DW_TAG_subprogram)
5197 {
5198 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00005199 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005200 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5201 }
5202 else
5203 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5204 }
5205
5206 if (parse_siblings)
5207 die = die->GetSibling();
5208 else
5209 die = NULL;
5210 }
5211 return types_added;
5212}
5213
5214
5215size_t
5216SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5217{
5218 assert(sc.comp_unit && sc.function);
5219 size_t functions_added = 0;
5220 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5221 if (dwarf_cu)
5222 {
5223 dw_offset_t function_die_offset = sc.function->GetID();
5224 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5225 if (function_die)
5226 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00005227 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005228 }
5229 }
5230
5231 return functions_added;
5232}
5233
5234
5235size_t
5236SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5237{
5238 // At least a compile unit must be valid
5239 assert(sc.comp_unit);
5240 size_t types_added = 0;
5241 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5242 if (dwarf_cu)
5243 {
5244 if (sc.function)
5245 {
5246 dw_offset_t function_die_offset = sc.function->GetID();
5247 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5248 if (func_die && func_die->HasChildren())
5249 {
5250 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5251 }
5252 }
5253 else
5254 {
5255 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5256 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5257 {
5258 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5259 }
5260 }
5261 }
5262
5263 return types_added;
5264}
5265
5266size_t
5267SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5268{
5269 if (sc.comp_unit != NULL)
5270 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00005271 DWARFDebugInfo* info = DebugInfo();
5272 if (info == NULL)
5273 return 0;
5274
5275 uint32_t cu_idx = UINT32_MAX;
5276 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005277
5278 if (dwarf_cu == NULL)
5279 return 0;
5280
5281 if (sc.function)
5282 {
5283 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00005284
5285 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
5286 assert (func_lo_pc != DW_INVALID_ADDRESS);
5287
Greg Claytonc662ec82011-06-17 22:10:16 +00005288 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
5289
5290 // Let all blocks know they have parse all their variables
5291 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5292
5293 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005294 }
5295 else if (sc.comp_unit)
5296 {
5297 uint32_t vars_added = 0;
5298 VariableListSP variables (sc.comp_unit->GetVariableList(false));
5299
5300 if (variables.get() == NULL)
5301 {
5302 variables.reset(new VariableList());
5303 sc.comp_unit->SetVariableList(variables);
5304
Greg Claytond4a2b372011-09-12 23:21:58 +00005305 DWARFCompileUnit* match_dwarf_cu = NULL;
5306 const DWARFDebugInfoEntry* die = NULL;
5307 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00005308 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00005309 {
Greg Clayton97fbc342011-10-20 22:30:33 +00005310 if (m_apple_names_ap.get())
5311 m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5312 dwarf_cu->GetNextCompileUnitOffset(),
5313 die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00005314 }
5315 else
5316 {
5317 // Index if we already haven't to make sure the compile units
5318 // get indexed and make their global DIE index list
5319 if (!m_indexed)
5320 Index ();
5321
5322 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5323 dwarf_cu->GetNextCompileUnitOffset(),
5324 die_offsets);
5325 }
5326
5327 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00005328 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005329 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005330 DWARFDebugInfo* debug_info = DebugInfo();
5331 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005332 {
Greg Claytond4a2b372011-09-12 23:21:58 +00005333 const dw_offset_t die_offset = die_offsets[i];
5334 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00005335 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00005336 {
Greg Clayton95d87902011-11-11 03:16:25 +00005337 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5338 if (var_sp)
5339 {
5340 variables->AddVariableIfUnique (var_sp);
5341 ++vars_added;
5342 }
Greg Claytond4a2b372011-09-12 23:21:58 +00005343 }
Greg Clayton95d87902011-11-11 03:16:25 +00005344 else
5345 {
5346 if (m_using_apple_tables)
5347 {
5348 ReportError (".apple_names accelerator table had bad die 0x%8.8x\n", die_offset);
5349 }
5350 }
5351
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005352 }
5353 }
5354 }
5355 return vars_added;
5356 }
5357 }
5358 return 0;
5359}
5360
5361
5362VariableSP
5363SymbolFileDWARF::ParseVariableDIE
5364(
5365 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005366 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005367 const DWARFDebugInfoEntry *die,
5368 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005369)
5370{
5371
Greg Clayton83c5cd92010-11-14 22:13:40 +00005372 VariableSP var_sp (m_die_to_variable_sp[die]);
5373 if (var_sp)
5374 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005375
5376 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00005377
5378 if ((tag == DW_TAG_variable) ||
5379 (tag == DW_TAG_constant) ||
5380 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005381 {
Greg Clayton7f995132011-10-04 22:41:51 +00005382 DWARFDebugInfoEntry::Attributes attributes;
5383 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5384 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005385 {
Greg Clayton7f995132011-10-04 22:41:51 +00005386 const char *name = NULL;
5387 const char *mangled = NULL;
5388 Declaration decl;
5389 uint32_t i;
5390 Type *var_type = NULL;
5391 DWARFExpression location;
5392 bool is_external = false;
5393 bool is_artificial = false;
5394 bool location_is_const_value_data = false;
5395 AccessType accessibility = eAccessNone;
5396
5397 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005398 {
Greg Clayton7f995132011-10-04 22:41:51 +00005399 dw_attr_t attr = attributes.AttributeAtIndex(i);
5400 DWARFFormValue form_value;
5401 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005402 {
Greg Clayton7f995132011-10-04 22:41:51 +00005403 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005404 {
Greg Clayton7f995132011-10-04 22:41:51 +00005405 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5406 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5407 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5408 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
5409 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5410 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
5411 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5412 case DW_AT_const_value:
5413 location_is_const_value_data = true;
5414 // Fall through...
5415 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005416 {
Greg Clayton7f995132011-10-04 22:41:51 +00005417 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005418 {
Greg Clayton7f995132011-10-04 22:41:51 +00005419 const DataExtractor& debug_info_data = get_debug_info_data();
5420
5421 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5422 uint32_t block_length = form_value.Unsigned();
5423 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5424 }
5425 else
5426 {
5427 const DataExtractor& debug_loc_data = get_debug_loc_data();
5428 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5429
5430 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5431 if (loc_list_length > 0)
5432 {
5433 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5434 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5435 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005437 }
5438 }
Greg Clayton7f995132011-10-04 22:41:51 +00005439 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005440
Greg Clayton7f995132011-10-04 22:41:51 +00005441 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5442 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5443 case DW_AT_declaration:
5444 case DW_AT_description:
5445 case DW_AT_endianity:
5446 case DW_AT_segment:
5447 case DW_AT_start_scope:
5448 case DW_AT_visibility:
5449 default:
5450 case DW_AT_abstract_origin:
5451 case DW_AT_sibling:
5452 case DW_AT_specification:
5453 break;
5454 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005455 }
5456 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005457
Greg Clayton7f995132011-10-04 22:41:51 +00005458 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005459 {
Greg Clayton7f995132011-10-04 22:41:51 +00005460 assert(var_type != DIE_IS_BEING_PARSED);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005461
Greg Clayton7f995132011-10-04 22:41:51 +00005462 ValueType scope = eValueTypeInvalid;
5463
5464 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5465 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005466 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00005467
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005468 // DWARF doesn't specify if a DW_TAG_variable is a local, global
5469 // or static variable, so we have to do a little digging by
5470 // looking at the location of a varaible to see if it contains
5471 // a DW_OP_addr opcode _somewhere_ in the definition. I say
5472 // somewhere because clang likes to combine small global variables
5473 // into the same symbol and have locations like:
5474 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
5475 // So if we don't have a DW_TAG_formal_parameter, we can look at
5476 // the location to see if it contains a DW_OP_addr opcode, and
5477 // then we can correctly classify our variables.
Greg Clayton7f995132011-10-04 22:41:51 +00005478 if (tag == DW_TAG_formal_parameter)
5479 scope = eValueTypeVariableArgument;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005480 else if (location.LocationContains_DW_OP_addr ())
5481 {
5482 if (is_external)
5483 {
5484 if (m_debug_map_symfile)
5485 {
5486 // When leaving the DWARF in the .o files on darwin,
5487 // when we have a global variable that wasn't initialized,
5488 // the .o file might not have allocated a virtual
5489 // address for the global variable. In this case it will
5490 // have created a symbol for the global variable
5491 // that is undefined and external and the value will
5492 // be the byte size of the variable. When we do the
5493 // address map in SymbolFileDWARFDebugMap we rely on
5494 // having an address, we need to do some magic here
5495 // so we can get the correct address for our global
5496 // variable. The address for all of these entries
5497 // will be zero, and there will be an undefined symbol
5498 // in this object file, and the executable will have
5499 // a matching symbol with a good address. So here we
5500 // dig up the correct address and replace it in the
5501 // location for the variable, and set the variable's
5502 // symbol context scope to be that of the main executable
5503 // so the file address will resolve correctly.
5504 if (location.LocationContains_DW_OP_addr (0))
5505 {
5506
5507 // we have a possible uninitialized extern global
5508 Symtab *symtab = m_obj_file->GetSymtab();
5509 if (symtab)
5510 {
5511 ConstString const_name(name);
5512 Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
5513 eSymbolTypeUndefined,
5514 Symtab::eDebugNo,
5515 Symtab::eVisibilityExtern);
5516
5517 if (undefined_symbol)
5518 {
5519 ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
5520 if (debug_map_objfile)
5521 {
5522 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
5523 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
5524 eSymbolTypeData,
5525 Symtab::eDebugYes,
5526 Symtab::eVisibilityExtern);
5527 if (defined_symbol)
5528 {
5529 const AddressRange *defined_range = defined_symbol->GetAddressRangePtr();
5530 if (defined_range)
5531 {
5532 const addr_t defined_addr = defined_range->GetBaseAddress().GetFileAddress();
5533 if (defined_addr != LLDB_INVALID_ADDRESS)
5534 {
5535 if (location.Update_DW_OP_addr (defined_addr))
5536 {
5537 symbol_context_scope = defined_symbol;
5538 }
5539 }
5540 }
5541 }
5542 }
5543 }
5544 }
5545 }
5546 }
5547 scope = eValueTypeVariableGlobal;
5548 }
5549 else
5550 scope = eValueTypeVariableStatic;
5551 }
Greg Clayton7f995132011-10-04 22:41:51 +00005552 else
5553 scope = eValueTypeVariableLocal;
5554
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005555 if (symbol_context_scope == NULL)
Greg Clayton7f995132011-10-04 22:41:51 +00005556 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005557 switch (parent_tag)
Greg Clayton5cf58b92011-10-05 22:22:08 +00005558 {
Greg Clayton2fc93ea2011-11-13 04:15:56 +00005559 case DW_TAG_subprogram:
5560 case DW_TAG_inlined_subroutine:
5561 case DW_TAG_lexical_block:
5562 if (sc.function)
5563 {
5564 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
5565 if (symbol_context_scope == NULL)
5566 symbol_context_scope = sc.function;
5567 }
5568 break;
5569
5570 default:
5571 symbol_context_scope = sc.comp_unit;
5572 break;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005573 }
Greg Clayton7f995132011-10-04 22:41:51 +00005574 }
5575
Greg Clayton5cf58b92011-10-05 22:22:08 +00005576 if (symbol_context_scope)
5577 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005578 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
5579 name,
5580 mangled,
5581 var_type,
5582 scope,
5583 symbol_context_scope,
5584 &decl,
5585 location,
5586 is_external,
5587 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00005588
5589 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
5590 }
5591 else
5592 {
5593 // Not ready to parse this variable yet. It might be a global
5594 // or static variable that is in a function scope and the function
5595 // in the symbol context wasn't filled in yet
5596 return var_sp;
5597 }
Greg Clayton7f995132011-10-04 22:41:51 +00005598 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005599 }
Greg Clayton7f995132011-10-04 22:41:51 +00005600 // Cache var_sp even if NULL (the variable was just a specification or
5601 // was missing vital information to be able to be displayed in the debugger
5602 // (missing location due to optimization, etc)) so we don't re-parse
5603 // this DIE over and over later...
5604 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005605 }
5606 return var_sp;
5607}
5608
Greg Claytonc662ec82011-06-17 22:10:16 +00005609
5610const DWARFDebugInfoEntry *
5611SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
5612 dw_offset_t spec_block_die_offset,
5613 DWARFCompileUnit **result_die_cu_handle)
5614{
5615 // Give the concrete function die specified by "func_die_offset", find the
5616 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5617 // to "spec_block_die_offset"
5618 DWARFDebugInfo* info = DebugInfo();
5619
5620 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
5621 if (die)
5622 {
5623 assert (*result_die_cu_handle);
5624 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
5625 }
5626 return NULL;
5627}
5628
5629
5630const DWARFDebugInfoEntry *
5631SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
5632 const DWARFDebugInfoEntry *die,
5633 dw_offset_t spec_block_die_offset,
5634 DWARFCompileUnit **result_die_cu_handle)
5635{
5636 if (die)
5637 {
5638 switch (die->Tag())
5639 {
5640 case DW_TAG_subprogram:
5641 case DW_TAG_inlined_subroutine:
5642 case DW_TAG_lexical_block:
5643 {
5644 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
5645 {
5646 *result_die_cu_handle = dwarf_cu;
5647 return die;
5648 }
5649
5650 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
5651 {
5652 *result_die_cu_handle = dwarf_cu;
5653 return die;
5654 }
5655 }
5656 break;
5657 }
5658
5659 // Give the concrete function die specified by "func_die_offset", find the
5660 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5661 // to "spec_block_die_offset"
5662 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
5663 {
5664 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
5665 child_die,
5666 spec_block_die_offset,
5667 result_die_cu_handle);
5668 if (result_die)
5669 return result_die;
5670 }
5671 }
5672
5673 *result_die_cu_handle = NULL;
5674 return NULL;
5675}
5676
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005677size_t
5678SymbolFileDWARF::ParseVariables
5679(
5680 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005681 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005682 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005683 const DWARFDebugInfoEntry *orig_die,
5684 bool parse_siblings,
5685 bool parse_children,
5686 VariableList* cc_variable_list
5687)
5688{
5689 if (orig_die == NULL)
5690 return 0;
5691
Greg Claytonc662ec82011-06-17 22:10:16 +00005692 VariableListSP variable_list_sp;
5693
5694 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005695 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00005696 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005697 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005698 dw_tag_t tag = die->Tag();
5699
5700 // Check to see if we have already parsed this variable or constant?
5701 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005702 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005703 if (cc_variable_list)
5704 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005705 }
5706 else
5707 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005708 // We haven't already parsed it, lets do that now.
5709 if ((tag == DW_TAG_variable) ||
5710 (tag == DW_TAG_constant) ||
5711 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005712 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005713 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00005714 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005715 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
5716 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5717 switch (parent_tag)
5718 {
5719 case DW_TAG_compile_unit:
5720 if (sc.comp_unit != NULL)
5721 {
5722 variable_list_sp = sc.comp_unit->GetVariableList(false);
5723 if (variable_list_sp.get() == NULL)
5724 {
5725 variable_list_sp.reset(new VariableList());
5726 sc.comp_unit->SetVariableList(variable_list_sp);
5727 }
5728 }
5729 else
5730 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005731 ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
5732 MakeUserID(sc_parent_die->GetOffset()),
5733 DW_TAG_value_to_name (parent_tag),
5734 MakeUserID(orig_die->GetOffset()),
5735 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005736 }
5737 break;
5738
5739 case DW_TAG_subprogram:
5740 case DW_TAG_inlined_subroutine:
5741 case DW_TAG_lexical_block:
5742 if (sc.function != NULL)
5743 {
5744 // Check to see if we already have parsed the variables for the given scope
5745
Greg Clayton81c22f62011-10-19 18:09:39 +00005746 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005747 if (block == NULL)
5748 {
5749 // This must be a specification or abstract origin with
5750 // a concrete block couterpart in the current function. We need
5751 // to find the concrete block so we can correctly add the
5752 // variable to it
5753 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
5754 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
5755 sc_parent_die->GetOffset(),
5756 &concrete_block_die_cu);
5757 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00005758 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005759 }
5760
5761 if (block != NULL)
5762 {
5763 const bool can_create = false;
5764 variable_list_sp = block->GetBlockVariableList (can_create);
5765 if (variable_list_sp.get() == NULL)
5766 {
5767 variable_list_sp.reset(new VariableList());
5768 block->SetVariableList(variable_list_sp);
5769 }
5770 }
5771 }
5772 break;
5773
5774 default:
Greg Clayton81c22f62011-10-19 18:09:39 +00005775 ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
5776 MakeUserID(orig_die->GetOffset()),
5777 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005778 break;
5779 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00005780 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005781
5782 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005783 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00005784 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
5785 if (var_sp)
5786 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005787 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00005788 if (cc_variable_list)
5789 cc_variable_list->AddVariableIfUnique (var_sp);
5790 ++vars_added;
5791 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005792 }
5793 }
5794 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005795
5796 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
5797
5798 if (!skip_children && parse_children && die->HasChildren())
5799 {
5800 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
5801 }
5802
5803 if (parse_siblings)
5804 die = die->GetSibling();
5805 else
5806 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005807 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005808 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005809}
5810
5811//------------------------------------------------------------------
5812// PluginInterface protocol
5813//------------------------------------------------------------------
5814const char *
5815SymbolFileDWARF::GetPluginName()
5816{
5817 return "SymbolFileDWARF";
5818}
5819
5820const char *
5821SymbolFileDWARF::GetShortPluginName()
5822{
5823 return GetPluginNameStatic();
5824}
5825
5826uint32_t
5827SymbolFileDWARF::GetPluginVersion()
5828{
5829 return 1;
5830}
5831
5832void
Greg Clayton6beaaa62011-01-17 03:46:26 +00005833SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
5834{
5835 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5836 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5837 if (clang_type)
5838 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5839}
5840
5841void
5842SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
5843{
5844 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5845 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5846 if (clang_type)
5847 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5848}
5849
Greg Claytona2721472011-06-25 00:44:06 +00005850void
Sean Callanancc427fa2011-07-30 02:42:06 +00005851SymbolFileDWARF::DumpIndexes ()
5852{
5853 StreamFile s(stdout, false);
5854
5855 s.Printf ("DWARF index for (%s) '%s/%s':",
5856 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
5857 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
5858 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
5859 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
5860 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
5861 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
5862 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
5863 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
5864 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
5865 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
5866 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
5867}
5868
5869void
5870SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
5871 const char *name,
5872 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00005873{
Sean Callanancc427fa2011-07-30 02:42:06 +00005874 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00005875
5876 if (iter == m_decl_ctx_to_die.end())
5877 return;
5878
Greg Claytoncb5860a2011-10-13 23:49:28 +00005879 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00005880 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005881 const DWARFDebugInfoEntry *context_die = *pos;
5882
5883 if (!results)
5884 return;
5885
5886 DWARFDebugInfo* info = DebugInfo();
5887
5888 DIEArray die_offsets;
5889
5890 DWARFCompileUnit* dwarf_cu = NULL;
5891 const DWARFDebugInfoEntry* die = NULL;
5892 size_t num_matches = m_type_index.Find (ConstString(name), die_offsets);
5893
5894 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00005895 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005896 for (size_t i = 0; i < num_matches; ++i)
5897 {
5898 const dw_offset_t die_offset = die_offsets[i];
5899 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00005900
Greg Claytoncb5860a2011-10-13 23:49:28 +00005901 if (die->GetParent() != context_die)
5902 continue;
5903
5904 Type *matching_type = ResolveType (dwarf_cu, die);
5905
5906 lldb::clang_type_t type = matching_type->GetClangFullType();
5907 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
5908
5909 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
5910 {
5911 clang::TagDecl *tag_decl = tag_type->getDecl();
5912 results->push_back(tag_decl);
5913 }
5914 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
5915 {
5916 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
5917 results->push_back(typedef_decl);
5918 }
Greg Claytona2721472011-06-25 00:44:06 +00005919 }
5920 }
5921 }
5922}
5923
5924void
5925SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00005926 const clang::DeclContext *decl_context,
5927 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00005928 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
5929{
Greg Clayton85ae2e12011-10-18 23:36:41 +00005930
5931 switch (decl_context->getDeclKind())
5932 {
5933 case clang::Decl::Namespace:
5934 case clang::Decl::TranslationUnit:
5935 {
5936 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5937 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
5938 }
5939 break;
5940 default:
5941 break;
5942 }
Greg Claytona2721472011-06-25 00:44:06 +00005943}