blob: 1b8e776b6d4feb1ccb2eed20ff7326f595c73da9 [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"
17#include "clang/Basic/Builtins.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/Basic/LangOptions.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000023#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Sean Callanancc427fa2011-07-30 02:42:06 +000025#include "llvm/Support/Casting.h"
26
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/PluginManager.h"
29#include "lldb/Core/RegularExpression.h"
30#include "lldb/Core/Scalar.h"
31#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000032#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000033#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/Timer.h"
35#include "lldb/Core/Value.h"
36
Greg Clayton20568dd2011-10-13 23:13:20 +000037#include "lldb/Host/Host.h"
38
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000040#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/CompileUnit.h"
42#include "lldb/Symbol/LineTable.h"
43#include "lldb/Symbol/ObjectFile.h"
44#include "lldb/Symbol/SymbolVendor.h"
45#include "lldb/Symbol/VariableList.h"
46
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000047#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000048#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "DWARFCompileUnit.h"
51#include "DWARFDebugAbbrev.h"
52#include "DWARFDebugAranges.h"
53#include "DWARFDebugInfo.h"
54#include "DWARFDebugInfoEntry.h"
55#include "DWARFDebugLine.h"
56#include "DWARFDebugPubnames.h"
57#include "DWARFDebugRanges.h"
58#include "DWARFDIECollection.h"
59#include "DWARFFormValue.h"
60#include "DWARFLocationList.h"
61#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000062#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64#include <map>
65
Greg Clayton62742b12010-11-11 01:09:45 +000066//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000067
68#ifdef ENABLE_DEBUG_PRINTF
69#include <stdio.h>
70#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
71#else
72#define DEBUG_PRINTF(fmt, ...)
73#endif
74
Greg Clayton594e5ed2010-09-27 21:07:38 +000075#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
77using namespace lldb;
78using namespace lldb_private;
79
80
Sean Callananc7fbf732010-08-06 00:32:49 +000081static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000082DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083{
84 switch (dwarf_accessibility)
85 {
Sean Callananc7fbf732010-08-06 00:32:49 +000086 case DW_ACCESS_public: return eAccessPublic;
87 case DW_ACCESS_private: return eAccessPrivate;
88 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000089 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090 }
Sean Callananc7fbf732010-08-06 00:32:49 +000091 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092}
93
94void
95SymbolFileDWARF::Initialize()
96{
97 LogChannelDWARF::Initialize();
98 PluginManager::RegisterPlugin (GetPluginNameStatic(),
99 GetPluginDescriptionStatic(),
100 CreateInstance);
101}
102
103void
104SymbolFileDWARF::Terminate()
105{
106 PluginManager::UnregisterPlugin (CreateInstance);
107 LogChannelDWARF::Initialize();
108}
109
110
111const char *
112SymbolFileDWARF::GetPluginNameStatic()
113{
Greg Claytond4a2b372011-09-12 23:21:58 +0000114 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115}
116
117const char *
118SymbolFileDWARF::GetPluginDescriptionStatic()
119{
120 return "DWARF and DWARF3 debug symbol file reader.";
121}
122
123
124SymbolFile*
125SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
126{
127 return new SymbolFileDWARF(obj_file);
128}
129
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000130TypeList *
131SymbolFileDWARF::GetTypeList ()
132{
133 if (m_debug_map_symfile)
134 return m_debug_map_symfile->GetTypeList();
135 return m_obj_file->GetModule()->GetTypeList();
136
137}
138
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139//----------------------------------------------------------------------
140// Gets the first parent that is a lexical block, function or inlined
141// subroutine, or compile unit.
142//----------------------------------------------------------------------
143static const DWARFDebugInfoEntry *
144GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
145{
146 const DWARFDebugInfoEntry *die;
147 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
148 {
149 dw_tag_t tag = die->Tag();
150
151 switch (tag)
152 {
153 case DW_TAG_compile_unit:
154 case DW_TAG_subprogram:
155 case DW_TAG_inlined_subroutine:
156 case DW_TAG_lexical_block:
157 return die;
158 }
159 }
160 return NULL;
161}
162
163
Greg Clayton450e3f32010-10-12 02:24:53 +0000164SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
165 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000166 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 +0000167 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000168 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000170 m_data_debug_abbrev (),
171 m_data_debug_aranges (),
172 m_data_debug_frame (),
173 m_data_debug_info (),
174 m_data_debug_line (),
175 m_data_debug_loc (),
176 m_data_debug_ranges (),
177 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000178 m_data_apple_names (),
179 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000180 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 m_info(),
183 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000184 m_apple_names_ap (),
185 m_apple_types_ap (),
186 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000187 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000188 m_function_basename_index(),
189 m_function_fullname_index(),
190 m_function_method_index(),
191 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000192 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000193 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000194 m_type_index(),
195 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000196 m_indexed (false),
197 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000198 m_using_apple_tables (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000199 m_ranges(),
200 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201{
202}
203
204SymbolFileDWARF::~SymbolFileDWARF()
205{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000206 if (m_is_external_ast_source)
207 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
208}
209
210static const ConstString &
211GetDWARFMachOSegmentName ()
212{
213 static ConstString g_dwarf_section_name ("__DWARF");
214 return g_dwarf_section_name;
215}
216
Greg Claytone576ab22011-02-15 00:19:15 +0000217UniqueDWARFASTTypeMap &
218SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
219{
220 if (m_debug_map_symfile)
221 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
222 return m_unique_ast_type_map;
223}
224
Greg Clayton6beaaa62011-01-17 03:46:26 +0000225ClangASTContext &
226SymbolFileDWARF::GetClangASTContext ()
227{
228 if (m_debug_map_symfile)
229 return m_debug_map_symfile->GetClangASTContext ();
230
231 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
232 if (!m_is_external_ast_source)
233 {
234 m_is_external_ast_source = true;
235 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
236 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
237 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000238 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000239 this));
240
241 ast.SetExternalSource (ast_source_ap);
242 }
243 return ast;
244}
245
246void
247SymbolFileDWARF::InitializeObject()
248{
249 // Install our external AST source callbacks so we can complete Clang types.
250 Module *module = m_obj_file->GetModule();
251 if (module)
252 {
253 const SectionList *section_list = m_obj_file->GetSectionList();
254
255 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
256
257 // Memory map the DWARF mach-o segment so we have everything mmap'ed
258 // to keep our heap memory usage down.
259 if (section)
260 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
261 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000262 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000263 if (m_data_apple_names.GetByteSize() > 0)
264 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000265 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
266 if (m_apple_names_ap->IsValid())
267 m_using_apple_tables = true;
268 else
Greg Clayton7f995132011-10-04 22:41:51 +0000269 m_apple_names_ap.reset();
270 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000271 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000272 if (m_data_apple_types.GetByteSize() > 0)
273 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000274 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
275 if (m_apple_types_ap->IsValid())
276 m_using_apple_tables = true;
277 else
Greg Clayton7f995132011-10-04 22:41:51 +0000278 m_apple_types_ap.reset();
279 }
280
281 get_apple_namespaces_data();
282 if (m_data_apple_namespaces.GetByteSize() > 0)
283 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000284 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
285 if (m_apple_namespaces_ap->IsValid())
286 m_using_apple_tables = true;
287 else
Greg Clayton7f995132011-10-04 22:41:51 +0000288 m_apple_namespaces_ap.reset();
289 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000290
Greg Clayton5009f9d2011-10-27 17:55:14 +0000291 get_apple_objc_data();
292 if (m_data_apple_objc.GetByteSize() > 0)
293 {
294 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
295 if (m_apple_objc_ap->IsValid())
296 m_using_apple_tables = true;
297 else
298 m_apple_objc_ap.reset();
299 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300}
301
302bool
303SymbolFileDWARF::SupportedVersion(uint16_t version)
304{
305 return version == 2 || version == 3;
306}
307
308uint32_t
309SymbolFileDWARF::GetAbilities ()
310{
311 uint32_t abilities = 0;
312 if (m_obj_file != NULL)
313 {
314 const Section* section = NULL;
315 const SectionList *section_list = m_obj_file->GetSectionList();
316 if (section_list == NULL)
317 return 0;
318
319 uint64_t debug_abbrev_file_size = 0;
320 uint64_t debug_aranges_file_size = 0;
321 uint64_t debug_frame_file_size = 0;
322 uint64_t debug_info_file_size = 0;
323 uint64_t debug_line_file_size = 0;
324 uint64_t debug_loc_file_size = 0;
325 uint64_t debug_macinfo_file_size = 0;
326 uint64_t debug_pubnames_file_size = 0;
327 uint64_t debug_pubtypes_file_size = 0;
328 uint64_t debug_ranges_file_size = 0;
329 uint64_t debug_str_file_size = 0;
330
Greg Clayton6beaaa62011-01-17 03:46:26 +0000331 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332
333 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000334 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335
Greg Clayton4ceb9982010-07-21 22:54:26 +0000336 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337 if (section != NULL)
338 {
339 debug_info_file_size = section->GetByteSize();
340
Greg Clayton4ceb9982010-07-21 22:54:26 +0000341 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342 if (section)
343 debug_abbrev_file_size = section->GetByteSize();
344 else
345 m_flags.Set (flagsGotDebugAbbrevData);
346
Greg Clayton4ceb9982010-07-21 22:54:26 +0000347 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 if (section)
349 debug_aranges_file_size = section->GetByteSize();
350 else
351 m_flags.Set (flagsGotDebugArangesData);
352
Greg Clayton4ceb9982010-07-21 22:54:26 +0000353 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 if (section)
355 debug_frame_file_size = section->GetByteSize();
356 else
357 m_flags.Set (flagsGotDebugFrameData);
358
Greg Clayton4ceb9982010-07-21 22:54:26 +0000359 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 if (section)
361 debug_line_file_size = section->GetByteSize();
362 else
363 m_flags.Set (flagsGotDebugLineData);
364
Greg Clayton4ceb9982010-07-21 22:54:26 +0000365 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 if (section)
367 debug_loc_file_size = section->GetByteSize();
368 else
369 m_flags.Set (flagsGotDebugLocData);
370
Greg Clayton4ceb9982010-07-21 22:54:26 +0000371 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 if (section)
373 debug_macinfo_file_size = section->GetByteSize();
374 else
375 m_flags.Set (flagsGotDebugMacInfoData);
376
Greg Clayton4ceb9982010-07-21 22:54:26 +0000377 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378 if (section)
379 debug_pubnames_file_size = section->GetByteSize();
380 else
381 m_flags.Set (flagsGotDebugPubNamesData);
382
Greg Clayton4ceb9982010-07-21 22:54:26 +0000383 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 if (section)
385 debug_pubtypes_file_size = section->GetByteSize();
386 else
387 m_flags.Set (flagsGotDebugPubTypesData);
388
Greg Clayton4ceb9982010-07-21 22:54:26 +0000389 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 if (section)
391 debug_ranges_file_size = section->GetByteSize();
392 else
393 m_flags.Set (flagsGotDebugRangesData);
394
Greg Clayton4ceb9982010-07-21 22:54:26 +0000395 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 if (section)
397 debug_str_file_size = section->GetByteSize();
398 else
399 m_flags.Set (flagsGotDebugStrData);
400 }
401
402 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
403 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
404
405 if (debug_line_file_size > 0)
406 abilities |= LineTables;
407
408 if (debug_aranges_file_size > 0)
409 abilities |= AddressAcceleratorTable;
410
411 if (debug_pubnames_file_size > 0)
412 abilities |= FunctionAcceleratorTable;
413
414 if (debug_pubtypes_file_size > 0)
415 abilities |= TypeAcceleratorTable;
416
417 if (debug_macinfo_file_size > 0)
418 abilities |= MacroInformation;
419
420 if (debug_frame_file_size > 0)
421 abilities |= CallFrameInformation;
422 }
423 return abilities;
424}
425
426const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000427SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428{
429 if (m_flags.IsClear (got_flag))
430 {
431 m_flags.Set (got_flag);
432 const SectionList *section_list = m_obj_file->GetSectionList();
433 if (section_list)
434 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000435 Section *section = section_list->FindSectionByType(sect_type, true).get();
436 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 {
438 // See if we memory mapped the DWARF segment?
439 if (m_dwarf_data.GetByteSize())
440 {
441 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
442 }
443 else
444 {
445 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
446 data.Clear();
447 }
448 }
449 }
450 }
451 return data;
452}
453
454const DataExtractor&
455SymbolFileDWARF::get_debug_abbrev_data()
456{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000457 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458}
459
460const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000461SymbolFileDWARF::get_debug_aranges_data()
462{
463 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
464}
465
466const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467SymbolFileDWARF::get_debug_frame_data()
468{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000469 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470}
471
472const DataExtractor&
473SymbolFileDWARF::get_debug_info_data()
474{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000475 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476}
477
478const DataExtractor&
479SymbolFileDWARF::get_debug_line_data()
480{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000481 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482}
483
484const DataExtractor&
485SymbolFileDWARF::get_debug_loc_data()
486{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000487 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488}
489
490const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491SymbolFileDWARF::get_debug_ranges_data()
492{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000493 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494}
495
496const DataExtractor&
497SymbolFileDWARF::get_debug_str_data()
498{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000499 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500}
501
Greg Claytonf9eec202011-09-01 23:16:13 +0000502const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000503SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000504{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000505 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000506}
507
508const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000509SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000510{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000511 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000512}
513
Greg Clayton7f995132011-10-04 22:41:51 +0000514const DataExtractor&
515SymbolFileDWARF::get_apple_namespaces_data()
516{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000517 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
518}
519
520const DataExtractor&
521SymbolFileDWARF::get_apple_objc_data()
522{
523 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000524}
525
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526
527DWARFDebugAbbrev*
528SymbolFileDWARF::DebugAbbrev()
529{
530 if (m_abbr.get() == NULL)
531 {
532 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
533 if (debug_abbrev_data.GetByteSize() > 0)
534 {
535 m_abbr.reset(new DWARFDebugAbbrev());
536 if (m_abbr.get())
537 m_abbr->Parse(debug_abbrev_data);
538 }
539 }
540 return m_abbr.get();
541}
542
543const DWARFDebugAbbrev*
544SymbolFileDWARF::DebugAbbrev() const
545{
546 return m_abbr.get();
547}
548
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549
550DWARFDebugInfo*
551SymbolFileDWARF::DebugInfo()
552{
553 if (m_info.get() == NULL)
554 {
555 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
556 if (get_debug_info_data().GetByteSize() > 0)
557 {
558 m_info.reset(new DWARFDebugInfo());
559 if (m_info.get())
560 {
561 m_info->SetDwarfData(this);
562 }
563 }
564 }
565 return m_info.get();
566}
567
568const DWARFDebugInfo*
569SymbolFileDWARF::DebugInfo() const
570{
571 return m_info.get();
572}
573
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574DWARFCompileUnit*
575SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
576{
577 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000578 if (info && UserIDMatches(cu_uid))
579 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 return NULL;
581}
582
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583
584DWARFDebugRanges*
585SymbolFileDWARF::DebugRanges()
586{
587 if (m_ranges.get() == NULL)
588 {
589 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
590 if (get_debug_ranges_data().GetByteSize() > 0)
591 {
592 m_ranges.reset(new DWARFDebugRanges());
593 if (m_ranges.get())
594 m_ranges->Extract(this);
595 }
596 }
597 return m_ranges.get();
598}
599
600const DWARFDebugRanges*
601SymbolFileDWARF::DebugRanges() const
602{
603 return m_ranges.get();
604}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605
606bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000607SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608{
Greg Clayton96d7d742010-11-10 23:42:09 +0000609 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000611 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000612 if (cu_die)
613 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000614 const char * cu_die_name = cu_die->GetName(this, curr_cu);
615 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000616 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617 if (cu_die_name)
618 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000619 FileSpec cu_file_spec;
620
Greg Clayton7bd65b92011-02-09 23:39:34 +0000621 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000622 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000623 // If we have a full path to the compile unit, we don't need to resolve
624 // the file. This can be expensive e.g. when the source files are NFS mounted.
625 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626 }
627 else
628 {
629 std::string fullpath(cu_comp_dir);
630 if (*fullpath.rbegin() != '/')
631 fullpath += '/';
632 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000633 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 }
635
Greg Clayton81c22f62011-10-19 18:09:39 +0000636 compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
637 curr_cu,
638 cu_file_spec,
639 MakeUserID(curr_cu->GetOffset()),
640 cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 if (compile_unit_sp.get())
642 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000643 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 return true;
645 }
646 }
647 }
648 }
649 return false;
650}
651
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652uint32_t
653SymbolFileDWARF::GetNumCompileUnits()
654{
655 DWARFDebugInfo* info = DebugInfo();
656 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 return 0;
659}
660
661CompUnitSP
662SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
663{
664 CompUnitSP comp_unit;
665 DWARFDebugInfo* info = DebugInfo();
666 if (info)
667 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000668 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
669 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 {
671 // Our symbol vendor shouldn't be asking us to add a compile unit that
672 // has already been added to it, which this DWARF plug-in knows as it
673 // stores the lldb compile unit (CompileUnit) pointer in each
674 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000675 assert(curr_cu->GetUserData() == NULL);
676 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 }
678 }
679 return comp_unit;
680}
681
682static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000683AddRangesToBlock (Block& block,
684 DWARFDebugRanges::RangeList& ranges,
685 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000687 const size_t num_ranges = ranges.GetSize();
688 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000690 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
691 const addr_t range_base = range.GetRangeBase();
692 assert (range_base >= block_base_addr);
693 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000695 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696}
697
698
699Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000700SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701{
702 DWARFDebugRanges::RangeList func_ranges;
703 const char *name = NULL;
704 const char *mangled = NULL;
705 int decl_file = 0;
706 int decl_line = 0;
707 int decl_column = 0;
708 int call_file = 0;
709 int call_line = 0;
710 int call_column = 0;
711 DWARFExpression frame_base;
712
Greg Claytonc93237c2010-10-01 20:48:32 +0000713 assert (die->Tag() == DW_TAG_subprogram);
714
715 if (die->Tag() != DW_TAG_subprogram)
716 return NULL;
717
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
719 {
720 // Union of all ranges in the function DIE (if the function is discontiguous)
721 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000722 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
723 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
725 {
726 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
727 if (func_range.GetBaseAddress().IsValid())
728 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
729 }
730
731 if (func_range.GetBaseAddress().IsValid())
732 {
733 Mangled func_name;
734 if (mangled)
735 func_name.SetValue(mangled, true);
736 else if (name)
737 func_name.SetValue(name, false);
738
739 FunctionSP func_sp;
740 std::auto_ptr<Declaration> decl_ap;
741 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000742 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
743 decl_line,
744 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000746 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000747 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748
749 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
750
751 func_range.GetBaseAddress().ResolveLinkedAddress();
752
Greg Clayton81c22f62011-10-19 18:09:39 +0000753 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000755 func_user_id, // UserID is the DIE offset
756 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 func_name,
758 func_type,
759 func_range)); // first address range
760
761 if (func_sp.get() != NULL)
762 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000763 if (frame_base.IsValid())
764 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765 sc.comp_unit->AddFunction(func_sp);
766 return func_sp.get();
767 }
768 }
769 }
770 return NULL;
771}
772
773size_t
774SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
775{
776 assert (sc.comp_unit);
777 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000778 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 if (dwarf_cu)
780 {
781 DWARFDIECollection function_dies;
782 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
783 size_t func_idx;
784 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
785 {
786 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000787 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788 {
789 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
790 ++functions_added;
791 }
792 }
793 //FixupTypes();
794 }
795 return functions_added;
796}
797
798bool
799SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
800{
801 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000802 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
803 assert (curr_cu);
804 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805
806 if (cu_die)
807 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000808 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
809 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 +0000810
811 // All file indexes in DWARF are one based and a file of index zero is
812 // supposed to be the compile unit itself.
813 support_files.Append (*sc.comp_unit);
814
815 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
816 }
817 return false;
818}
819
820struct ParseDWARFLineTableCallbackInfo
821{
822 LineTable* line_table;
823 const SectionList *section_list;
824 lldb::addr_t prev_sect_file_base_addr;
825 lldb::addr_t curr_sect_file_base_addr;
826 bool is_oso_for_debug_map;
827 bool prev_in_final_executable;
828 DWARFDebugLine::Row prev_row;
829 SectionSP prev_section_sp;
830 SectionSP curr_section_sp;
831};
832
833//----------------------------------------------------------------------
834// ParseStatementTableCallback
835//----------------------------------------------------------------------
836static void
837ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
838{
839 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
840 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
841 {
842 // Just started parsing the line table
843 }
844 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
845 {
846 // Done parsing line table, nothing to do for the cleanup
847 }
848 else
849 {
850 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
851 // We have a new row, lets append it
852
853 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
854 {
855 info->prev_section_sp = info->curr_section_sp;
856 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
857 // If this is an end sequence entry, then we subtract one from the
858 // address to make sure we get an address that is not the end of
859 // a section.
860 if (state.end_sequence && state.address != 0)
861 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
862 else
863 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
864
865 if (info->curr_section_sp.get())
866 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
867 else
868 info->curr_sect_file_base_addr = 0;
869 }
870 if (info->curr_section_sp.get())
871 {
872 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
873 // Check for the fancy section magic to determine if we
874
875 if (info->is_oso_for_debug_map)
876 {
877 // When this is a debug map object file that contains DWARF
878 // (referenced from an N_OSO debug map nlist entry) we will have
879 // a file address in the file range for our section from the
880 // original .o file, and a load address in the executable that
881 // contains the debug map.
882 //
883 // If the sections for the file range and load range are
884 // different, we have a remapped section for the function and
885 // this address is resolved. If they are the same, then the
886 // function for this address didn't make it into the final
887 // executable.
888 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
889
890 // If we are doing DWARF with debug map, then we need to carefully
891 // add each line table entry as there may be gaps as functions
892 // get moved around or removed.
893 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
894 {
895 if (info->prev_in_final_executable)
896 {
897 bool terminate_previous_entry = false;
898 if (!curr_in_final_executable)
899 {
900 // Check for the case where the previous line entry
901 // in a function made it into the final executable,
902 // yet the current line entry falls in a function
903 // that didn't. The line table used to be contiguous
904 // through this address range but now it isn't. We
905 // need to terminate the previous line entry so
906 // that we can reconstruct the line range correctly
907 // for it and to keep the line table correct.
908 terminate_previous_entry = true;
909 }
910 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
911 {
912 // Check for cases where the line entries used to be
913 // contiguous address ranges, but now they aren't.
914 // This can happen when order files specify the
915 // ordering of the functions.
916 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
917 Section *curr_sect = info->curr_section_sp.get();
918 Section *prev_sect = info->prev_section_sp.get();
919 assert (curr_sect->GetLinkedSection());
920 assert (prev_sect->GetLinkedSection());
921 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
922 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
923 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
924 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
925 if (object_file_addr_delta != linked_file_addr_delta)
926 terminate_previous_entry = true;
927 }
928
929 if (terminate_previous_entry)
930 {
931 line_table->InsertLineEntry (info->prev_section_sp,
932 state.address - info->prev_sect_file_base_addr,
933 info->prev_row.line,
934 info->prev_row.column,
935 info->prev_row.file,
936 false, // is_stmt
937 false, // basic_block
938 false, // state.prologue_end
939 false, // state.epilogue_begin
940 true); // end_sequence);
941 }
942 }
943 }
944
945 if (curr_in_final_executable)
946 {
947 line_table->InsertLineEntry (info->curr_section_sp,
948 curr_line_section_offset,
949 state.line,
950 state.column,
951 state.file,
952 state.is_stmt,
953 state.basic_block,
954 state.prologue_end,
955 state.epilogue_begin,
956 state.end_sequence);
957 info->prev_section_sp = info->curr_section_sp;
958 }
959 else
960 {
961 // If the current address didn't make it into the final
962 // executable, the current section will be the __text
963 // segment in the .o file, so we need to clear this so
964 // we can catch the next function that did make it into
965 // the final executable.
966 info->prev_section_sp.reset();
967 info->curr_section_sp.reset();
968 }
969
970 info->prev_in_final_executable = curr_in_final_executable;
971 }
972 else
973 {
974 // We are not in an object file that contains DWARF for an
975 // N_OSO, this is just a normal DWARF file. The DWARF spec
976 // guarantees that the addresses will be in increasing order
977 // so, since we store line tables in file address order, we
978 // can always just append the line entry without needing to
979 // search for the correct insertion point (we don't need to
980 // use LineEntry::InsertLineEntry()).
981 line_table->AppendLineEntry (info->curr_section_sp,
982 curr_line_section_offset,
983 state.line,
984 state.column,
985 state.file,
986 state.is_stmt,
987 state.basic_block,
988 state.prologue_end,
989 state.epilogue_begin,
990 state.end_sequence);
991 }
992 }
993
994 info->prev_row = state;
995 }
996}
997
998bool
999SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1000{
1001 assert (sc.comp_unit);
1002 if (sc.comp_unit->GetLineTable() != NULL)
1003 return true;
1004
1005 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1006 if (dwarf_cu)
1007 {
1008 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1009 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1010 if (cu_line_offset != DW_INVALID_OFFSET)
1011 {
1012 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1013 if (line_table_ap.get())
1014 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00001015 ParseDWARFLineTableCallbackInfo info = {
1016 line_table_ap.get(),
1017 m_obj_file->GetSectionList(),
1018 0,
1019 0,
1020 m_debug_map_symfile != NULL,
1021 false,
1022 DWARFDebugLine::Row(),
1023 SectionSP(),
1024 SectionSP()
1025 };
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 uint32_t offset = cu_line_offset;
1027 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1028 sc.comp_unit->SetLineTable(line_table_ap.release());
1029 return true;
1030 }
1031 }
1032 }
1033 return false;
1034}
1035
1036size_t
1037SymbolFileDWARF::ParseFunctionBlocks
1038(
1039 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001040 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001041 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042 const DWARFDebugInfoEntry *die,
1043 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001044 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045)
1046{
1047 size_t blocks_added = 0;
1048 while (die != NULL)
1049 {
1050 dw_tag_t tag = die->Tag();
1051
1052 switch (tag)
1053 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001055 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056 case DW_TAG_lexical_block:
1057 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001058 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001059 if (tag == DW_TAG_subprogram)
1060 {
1061 // Skip any DW_TAG_subprogram DIEs that are inside
1062 // of a normal or inlined functions. These will be
1063 // parsed on their own as separate entities.
1064
1065 if (depth > 0)
1066 break;
1067
1068 block = parent_block;
1069 }
1070 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001071 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001072 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001073 parent_block->AddChild(block_sp);
1074 block = block_sp.get();
1075 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001076 DWARFDebugRanges::RangeList ranges;
1077 const char *name = NULL;
1078 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080 int decl_file = 0;
1081 int decl_line = 0;
1082 int decl_column = 0;
1083 int call_file = 0;
1084 int call_line = 0;
1085 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001086 if (die->GetDIENamesAndRanges (this,
1087 dwarf_cu,
1088 name,
1089 mangled_name,
1090 ranges,
1091 decl_file, decl_line, decl_column,
1092 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001093 {
1094 if (tag == DW_TAG_subprogram)
1095 {
1096 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001097 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001098 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001099 else if (tag == DW_TAG_inlined_subroutine)
1100 {
1101 // We get called here for inlined subroutines in two ways.
1102 // The first time is when we are making the Function object
1103 // for this inlined concrete instance. Since we're creating a top level block at
1104 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1105 // adjust the containing address.
1106 // The second time is when we are parsing the blocks inside the function that contains
1107 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1108 // function the offset will be for that function.
1109 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1110 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001111 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001112 }
1113 }
1114
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001115 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116
1117 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1118 {
1119 std::auto_ptr<Declaration> decl_ap;
1120 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001121 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1122 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001123
1124 std::auto_ptr<Declaration> call_ap;
1125 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001126 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1127 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001128
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001129 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130 }
1131
1132 ++blocks_added;
1133
Greg Claytondd7feaf2011-08-12 17:54:33 +00001134 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001136 blocks_added += ParseFunctionBlocks (sc,
1137 block,
1138 dwarf_cu,
1139 die->GetFirstChild(),
1140 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001141 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 }
1143 }
1144 }
1145 break;
1146 default:
1147 break;
1148 }
1149
Greg Claytondd7feaf2011-08-12 17:54:33 +00001150 // Only parse siblings of the block if we are not at depth zero. A depth
1151 // of zero indicates we are currently parsing the top level
1152 // DW_TAG_subprogram DIE
1153
1154 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001156 else
1157 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158 }
1159 return blocks_added;
1160}
1161
Greg Claytonf0705c82011-10-22 03:33:13 +00001162bool
1163SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1164 const DWARFDebugInfoEntry *parent_die,
1165 ClangASTContext::TemplateParameterInfos &template_param_infos)
1166{
1167
1168 if (parent_die == NULL)
1169 return NULL;
1170
1171 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1172
1173 Args template_parameter_names;
1174 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1175 die != NULL;
1176 die = die->GetSibling())
1177 {
1178 const dw_tag_t tag = die->Tag();
1179
1180 switch (tag)
1181 {
1182 case DW_TAG_template_type_parameter:
1183 case DW_TAG_template_value_parameter:
1184 {
1185 DWARFDebugInfoEntry::Attributes attributes;
1186 const size_t num_attributes = die->GetAttributes (this,
1187 dwarf_cu,
1188 fixed_form_sizes,
1189 attributes);
1190 const char *name = NULL;
1191 Type *lldb_type = NULL;
1192 clang_type_t clang_type = NULL;
1193 uint64_t uval64 = 0;
1194 bool uval64_valid = false;
1195 if (num_attributes > 0)
1196 {
1197 DWARFFormValue form_value;
1198 for (size_t i=0; i<num_attributes; ++i)
1199 {
1200 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1201
1202 switch (attr)
1203 {
1204 case DW_AT_name:
1205 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1206 name = form_value.AsCString(&get_debug_str_data());
1207 break;
1208
1209 case DW_AT_type:
1210 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1211 {
1212 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1213 lldb_type = ResolveTypeUID(type_die_offset);
1214 if (lldb_type)
1215 clang_type = lldb_type->GetClangForwardType();
1216 }
1217 break;
1218
1219 case DW_AT_const_value:
1220 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1221 {
1222 uval64_valid = true;
1223 uval64 = form_value.Unsigned();
1224 }
1225 break;
1226 default:
1227 break;
1228 }
1229 }
1230
1231 if (name && lldb_type && clang_type)
1232 {
1233 bool is_signed = false;
1234 template_param_infos.names.push_back(name);
1235 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1236 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1237 {
1238 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1239 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1240 }
1241 else
1242 {
1243 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1244 }
1245 }
1246 else
1247 {
1248 return false;
1249 }
1250
1251 }
1252 }
1253 break;
1254
1255 default:
1256 break;
1257 }
1258 }
1259 if (template_param_infos.args.empty())
1260 return false;
1261 return template_param_infos.args.size() == template_param_infos.names.size();
1262}
1263
1264clang::ClassTemplateDecl *
1265SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001266 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001267 const char *parent_name,
1268 int tag_decl_kind,
1269 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1270{
1271 if (template_param_infos.IsValid())
1272 {
1273 std::string template_basename(parent_name);
1274 template_basename.erase (template_basename.find('<'));
1275 ClangASTContext &ast = GetClangASTContext();
1276
1277 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001278 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001279 template_basename.c_str(),
1280 tag_decl_kind,
1281 template_param_infos);
1282 }
1283 return NULL;
1284}
1285
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286size_t
1287SymbolFileDWARF::ParseChildMembers
1288(
1289 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001290 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001292 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001293 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1295 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001296 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001297 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298 bool &is_a_class
1299)
1300{
1301 if (parent_die == NULL)
1302 return 0;
1303
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 size_t count = 0;
1305 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001306 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001307 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001308
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1310 {
1311 dw_tag_t tag = die->Tag();
1312
1313 switch (tag)
1314 {
1315 case DW_TAG_member:
1316 {
1317 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001318 const size_t num_attributes = die->GetAttributes (this,
1319 dwarf_cu,
1320 fixed_form_sizes,
1321 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322 if (num_attributes > 0)
1323 {
1324 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001325 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001327 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001329 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001330 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001331 size_t byte_size = 0;
1332 size_t bit_offset = 0;
1333 size_t bit_size = 0;
1334 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001335 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336 {
1337 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1338 DWARFFormValue form_value;
1339 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1340 {
1341 switch (attr)
1342 {
1343 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1344 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1345 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1346 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1347 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1348 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1349 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1350 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1351 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001352// if (form_value.BlockData())
1353// {
1354// Value initialValue(0);
1355// Value memberOffset(0);
1356// const DataExtractor& debug_info_data = get_debug_info_data();
1357// uint32_t block_length = form_value.Unsigned();
1358// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1359// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1360// {
1361// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1362// }
1363// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 break;
1365
Greg Clayton8cf05932010-07-22 18:30:50 +00001366 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001367 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001368 case DW_AT_declaration:
1369 case DW_AT_description:
1370 case DW_AT_mutable:
1371 case DW_AT_visibility:
1372 default:
1373 case DW_AT_sibling:
1374 break;
1375 }
1376 }
1377 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001378
Greg Clayton44953932011-10-25 01:25:35 +00001379 // Clang has a DWARF generation bug where sometimes it
1380 // represents fields that are references with bad byte size
1381 // and bit size/offset information such as:
1382 //
1383 // DW_AT_byte_size( 0x00 )
1384 // DW_AT_bit_size( 0x40 )
1385 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1386 //
1387 // So check the bit offset to make sure it is sane, and if
1388 // the values are not sane, remove them. If we don't do this
1389 // then we will end up with a crash if we try to use this
1390 // type in an expression when clang becomes unhappy with its
1391 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001392
Greg Clayton44953932011-10-25 01:25:35 +00001393 if (bit_offset > 128)
1394 {
1395 bit_size = 0;
1396 bit_offset = 0;
1397 }
1398
1399 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001400 if (class_language == eLanguageTypeObjC ||
1401 class_language == eLanguageTypeObjC_plus_plus)
1402 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001403
1404 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1405 {
1406 // Not all compilers will mark the vtable pointer
1407 // member as artificial (llvm-gcc). We can't have
1408 // the virtual members in our classes otherwise it
1409 // throws off all child offsets since we end up
1410 // having and extra pointer sized member in our
1411 // class layouts.
1412 is_artificial = true;
1413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414
Greg Clayton24739922010-10-13 03:15:28 +00001415 if (is_artificial == false)
1416 {
1417 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001418 if (member_type)
1419 {
1420 if (accessibility == eAccessNone)
1421 accessibility = default_accessibility;
1422 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423
Greg Claytond16e1e52011-07-12 17:06:17 +00001424 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1425 name,
1426 member_type->GetClangLayoutType(),
1427 accessibility,
1428 bit_size);
1429 }
1430 else
1431 {
1432 if (name)
Greg Clayton81c22f62011-10-19 18:09:39 +00001433 ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1434 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001435 name,
1436 encoding_uid);
1437 else
Greg Clayton81c22f62011-10-19 18:09:39 +00001438 ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1439 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001440 encoding_uid);
1441 }
Greg Clayton24739922010-10-13 03:15:28 +00001442 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001444 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 }
1446 break;
1447
1448 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001449 // Let the type parsing code handle this one for us.
1450 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001451 break;
1452
1453 case DW_TAG_inheritance:
1454 {
1455 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001456 if (default_accessibility == eAccessNone)
1457 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458 // TODO: implement DW_TAG_inheritance type parsing
1459 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001460 const size_t num_attributes = die->GetAttributes (this,
1461 dwarf_cu,
1462 fixed_form_sizes,
1463 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464 if (num_attributes > 0)
1465 {
1466 Declaration decl;
1467 DWARFExpression location;
1468 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001469 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 bool is_virtual = false;
1471 bool is_base_of_class = true;
1472 off_t member_offset = 0;
1473 uint32_t i;
1474 for (i=0; i<num_attributes; ++i)
1475 {
1476 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1477 DWARFFormValue form_value;
1478 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1479 {
1480 switch (attr)
1481 {
1482 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1483 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1484 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1485 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1486 case DW_AT_data_member_location:
1487 if (form_value.BlockData())
1488 {
1489 Value initialValue(0);
1490 Value memberOffset(0);
1491 const DataExtractor& debug_info_data = get_debug_info_data();
1492 uint32_t block_length = form_value.Unsigned();
1493 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001494 if (DWARFExpression::Evaluate (NULL,
1495 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001496 NULL,
1497 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001498 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001499 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001500 block_offset,
1501 block_length,
1502 eRegisterKindDWARF,
1503 &initialValue,
1504 memberOffset,
1505 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506 {
1507 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1508 }
1509 }
1510 break;
1511
1512 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001513 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001514 break;
1515
1516 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1517 default:
1518 case DW_AT_sibling:
1519 break;
1520 }
1521 }
1522 }
1523
Greg Clayton526e5af2010-11-13 03:52:47 +00001524 Type *base_class_type = ResolveTypeUID(encoding_uid);
1525 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001526
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001527 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1528 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001529 if (class_language == eLanguageTypeObjC)
1530 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001531 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001532 }
1533 else
1534 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001535 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001536 accessibility,
1537 is_virtual,
1538 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001539 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001540 }
1541 }
1542 break;
1543
1544 default:
1545 break;
1546 }
1547 }
1548 return count;
1549}
1550
1551
1552clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001553SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001554{
1555 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001556 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001557 {
1558 DWARFCompileUnitSP cu_sp;
1559 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1560 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001561 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001562 }
1563 return NULL;
1564}
1565
1566clang::DeclContext*
1567SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1568{
Greg Clayton81c22f62011-10-19 18:09:39 +00001569 if (UserIDMatches(type_uid))
1570 return GetClangDeclContextForDIEOffset (sc, type_uid);
1571 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001572}
1573
1574Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001575SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001576{
Greg Clayton81c22f62011-10-19 18:09:39 +00001577 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001578 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001579 DWARFDebugInfo* debug_info = DebugInfo();
1580 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001581 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001582 DWARFCompileUnitSP cu_sp;
1583 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1584 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001585 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001586 // We might be coming in in the middle of a type tree (a class
1587 // withing a class, an enum within a class), so parse any needed
1588 // parent DIEs before we get to this one...
1589 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu_sp.get(), type_die);
1590 switch (decl_ctx_die->Tag())
1591 {
1592 case DW_TAG_structure_type:
1593 case DW_TAG_union_type:
1594 case DW_TAG_class_type:
1595 ResolveType(cu_sp.get(), decl_ctx_die);
1596 break;
1597 }
1598 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001599 }
Greg Claytonca512b32011-01-14 04:54:56 +00001600 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001601 }
1602 return NULL;
1603}
1604
Greg Clayton6beaaa62011-01-17 03:46:26 +00001605// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1606// SymbolFileDWARF objects to detect if this DWARF file is the one that
1607// can resolve a clang_type.
1608bool
1609SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1610{
1611 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1612 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1613 return die != NULL;
1614}
1615
1616
Greg Clayton1be10fc2010-09-29 01:12:09 +00001617lldb::clang_type_t
1618SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1619{
1620 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001621 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1622 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001623 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001624 {
1625 // We have already resolved this type...
1626 return clang_type;
1627 }
1628 // Once we start resolving this type, remove it from the forward declaration
1629 // map in case anyone child members or other types require this type to get resolved.
1630 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1631 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001632 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001633
Greg Clayton1be10fc2010-09-29 01:12:09 +00001634
Greg Clayton85ae2e12011-10-18 23:36:41 +00001635 // Disable external storage for this type so we don't get anymore
1636 // clang::ExternalASTSource queries for this type.
1637 ClangASTContext::SetHasExternalStorage (clang_type, false);
1638
Greg Clayton450e3f32010-10-12 02:24:53 +00001639 DWARFDebugInfo* debug_info = DebugInfo();
1640
Greg Clayton96d7d742010-11-10 23:42:09 +00001641 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001642 Type *type = m_die_to_type.lookup (die);
1643
1644 const dw_tag_t tag = die->Tag();
1645
Greg Clayton81c22f62011-10-19 18:09:39 +00001646 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") - resolve forward declaration...\n",
1647 MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001648 DW_TAG_value_to_name(tag),
1649 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001650 assert (clang_type);
1651 DWARFDebugInfoEntry::Attributes attributes;
1652
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001653 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001654
1655 switch (tag)
1656 {
1657 case DW_TAG_structure_type:
1658 case DW_TAG_union_type:
1659 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001660 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001661 if (die->HasChildren())
1662 {
1663 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001664 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1665 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001666 class_language = eLanguageTypeObjC;
1667
1668 int tag_decl_kind = -1;
1669 AccessType default_accessibility = eAccessNone;
1670 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001671 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001672 tag_decl_kind = clang::TTK_Struct;
1673 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001674 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001675 else if (tag == DW_TAG_union_type)
1676 {
1677 tag_decl_kind = clang::TTK_Union;
1678 default_accessibility = eAccessPublic;
1679 }
1680 else if (tag == DW_TAG_class_type)
1681 {
1682 tag_decl_kind = clang::TTK_Class;
1683 default_accessibility = eAccessPrivate;
1684 }
1685
Greg Clayton96d7d742010-11-10 23:42:09 +00001686 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001687 std::vector<clang::CXXBaseSpecifier *> base_classes;
1688 std::vector<int> member_accessibilities;
1689 bool is_a_class = false;
1690 // Parse members and base classes first
1691 DWARFDIECollection member_function_dies;
1692
1693 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001694 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001695 die,
1696 clang_type,
1697 class_language,
1698 base_classes,
1699 member_accessibilities,
1700 member_function_dies,
1701 default_accessibility,
1702 is_a_class);
1703
1704 // Now parse any methods if there were any...
1705 size_t num_functions = member_function_dies.Size();
1706 if (num_functions > 0)
1707 {
1708 for (size_t i=0; i<num_functions; ++i)
1709 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001710 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001711 }
1712 }
1713
Greg Clayton450e3f32010-10-12 02:24:53 +00001714 if (class_language == eLanguageTypeObjC)
1715 {
Greg Claytone3055942011-06-30 02:28:26 +00001716 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001717 if (!class_str.empty())
1718 {
1719
Greg Claytond4a2b372011-09-12 23:21:58 +00001720 DIEArray method_die_offsets;
Greg Clayton5009f9d2011-10-27 17:55:14 +00001721 if (m_using_apple_tables)
1722 {
1723 if (m_apple_objc_ap.get())
1724 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
1725 }
1726 else
1727 {
1728 if (!m_indexed)
1729 Index ();
1730
1731 ConstString class_name (class_str.c_str());
1732 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1733 }
1734
1735 if (!method_die_offsets.empty())
Greg Clayton450e3f32010-10-12 02:24:53 +00001736 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001737 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton450e3f32010-10-12 02:24:53 +00001738
Greg Claytond4a2b372011-09-12 23:21:58 +00001739 DWARFCompileUnit* method_cu = NULL;
1740 const size_t num_matches = method_die_offsets.size();
1741 for (size_t i=0; i<num_matches; ++i)
1742 {
1743 const dw_offset_t die_offset = method_die_offsets[i];
1744 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Greg Clayton450e3f32010-10-12 02:24:53 +00001745
1746 ResolveType (method_cu, method_die);
1747 }
1748 }
1749 }
1750 }
1751
Greg Claytonc93237c2010-10-01 20:48:32 +00001752 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1753 // need to tell the clang type it is actually a class.
1754 if (class_language != eLanguageTypeObjC)
1755 {
1756 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001757 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001758 }
1759
1760 // Since DW_TAG_structure_type gets used for both classes
1761 // and structures, we may need to set any DW_TAG_member
1762 // fields to have a "private" access if none was specified.
1763 // When we parsed the child members we tracked that actual
1764 // accessibility value for each DW_TAG_member in the
1765 // "member_accessibilities" array. If the value for the
1766 // member is zero, then it was set to the "default_accessibility"
1767 // which for structs was "public". Below we correct this
1768 // by setting any fields to "private" that weren't correctly
1769 // set.
1770 if (is_a_class && !member_accessibilities.empty())
1771 {
1772 // This is a class and all members that didn't have
1773 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001774 ast.SetDefaultAccessForRecordFields (clang_type,
1775 eAccessPrivate,
1776 &member_accessibilities.front(),
1777 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001778 }
1779
1780 if (!base_classes.empty())
1781 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001782 ast.SetBaseClassesForClassType (clang_type,
1783 &base_classes.front(),
1784 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001785
1786 // Clang will copy each CXXBaseSpecifier in "base_classes"
1787 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001788 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1789 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001790 }
1791
1792 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001793 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001794 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001795
1796 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001797 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001798 if (die->HasChildren())
1799 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001800 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1801 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001802 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001803 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001804 return clang_type;
1805
1806 default:
1807 assert(false && "not a forward clang type decl!");
1808 break;
1809 }
1810 return NULL;
1811}
1812
Greg Claytonc685f8e2010-09-15 04:15:46 +00001813Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001814SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001815{
1816 if (type_die != NULL)
1817 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001818 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001819 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001820 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001821 if (assert_not_being_parsed)
1822 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001823 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001824 }
1825 return NULL;
1826}
1827
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001828CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001829SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830{
1831 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001832 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001833 {
1834 // The symbol vendor doesn't know about this compile unit, we
1835 // need to parse and add it to the symbol vendor object.
1836 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001837 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001838 if (dc_cu.get())
1839 {
1840 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001841 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001842 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843
1844 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001845
1846 if (m_debug_map_symfile)
1847 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 }
1849 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001850 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851}
1852
1853bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001854SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855{
1856 sc.Clear();
1857 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001858 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859
Greg Clayton81c22f62011-10-19 18:09:39 +00001860 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001862 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00001863
1864 if (sc.function)
1865 {
1866 sc.module_sp = sc.function->CalculateSymbolContextModule();
1867 return true;
1868 }
1869
1870 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001871}
1872
1873uint32_t
1874SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1875{
1876 Timer scoped_timer(__PRETTY_FUNCTION__,
1877 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1878 so_addr.GetSection(),
1879 so_addr.GetOffset(),
1880 resolve_scope);
1881 uint32_t resolved = 0;
1882 if (resolve_scope & ( eSymbolContextCompUnit |
1883 eSymbolContextFunction |
1884 eSymbolContextBlock |
1885 eSymbolContextLineEntry))
1886 {
1887 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1888
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001889 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001890 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001891 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001892 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001893 if (cu_offset != DW_INVALID_OFFSET)
1894 {
1895 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001896 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1897 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001898 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001899 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001900 assert(sc.comp_unit != NULL);
1901 resolved |= eSymbolContextCompUnit;
1902
1903 if (resolve_scope & eSymbolContextLineEntry)
1904 {
1905 LineTable *line_table = sc.comp_unit->GetLineTable();
1906 if (line_table == NULL)
1907 {
1908 if (ParseCompileUnitLineTable(sc))
1909 line_table = sc.comp_unit->GetLineTable();
1910 }
1911 if (line_table != NULL)
1912 {
1913 if (so_addr.IsLinkedAddress())
1914 {
1915 Address linked_addr (so_addr);
1916 linked_addr.ResolveLinkedAddress();
1917 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1918 {
1919 resolved |= eSymbolContextLineEntry;
1920 }
1921 }
1922 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1923 {
1924 resolved |= eSymbolContextLineEntry;
1925 }
1926 }
1927 }
1928
1929 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1930 {
1931 DWARFDebugInfoEntry *function_die = NULL;
1932 DWARFDebugInfoEntry *block_die = NULL;
1933 if (resolve_scope & eSymbolContextBlock)
1934 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001935 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936 }
1937 else
1938 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001939 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 }
1941
1942 if (function_die != NULL)
1943 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001944 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001946 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947 }
1948
1949 if (sc.function != NULL)
1950 {
1951 resolved |= eSymbolContextFunction;
1952
1953 if (resolve_scope & eSymbolContextBlock)
1954 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001955 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956
1957 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00001958 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959 else
Greg Clayton81c22f62011-10-19 18:09:39 +00001960 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001961 if (sc.block)
1962 resolved |= eSymbolContextBlock;
1963 }
1964 }
1965 }
1966 }
1967 }
1968 }
1969 }
1970 return resolved;
1971}
1972
1973
1974
1975uint32_t
1976SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1977{
1978 const uint32_t prev_size = sc_list.GetSize();
1979 if (resolve_scope & eSymbolContextCompUnit)
1980 {
1981 DWARFDebugInfo* debug_info = DebugInfo();
1982 if (debug_info)
1983 {
1984 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001985 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001986
Greg Clayton96d7d742010-11-10 23:42:09 +00001987 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001988 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001989 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001990 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1991 if (check_inlines || file_spec_matches_cu_file_spec)
1992 {
1993 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001994 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995 assert(sc.comp_unit != NULL);
1996
1997 uint32_t file_idx = UINT32_MAX;
1998
1999 // If we are looking for inline functions only and we don't
2000 // find it in the support files, we are done.
2001 if (check_inlines)
2002 {
Jim Ingham87df91b2011-09-23 00:54:11 +00002003 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 if (file_idx == UINT32_MAX)
2005 continue;
2006 }
2007
2008 if (line != 0)
2009 {
2010 LineTable *line_table = sc.comp_unit->GetLineTable();
2011
2012 if (line_table != NULL && line != 0)
2013 {
2014 // We will have already looked up the file index if
2015 // we are searching for inline entries.
2016 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00002017 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018
2019 if (file_idx != UINT32_MAX)
2020 {
2021 uint32_t found_line;
2022 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2023 found_line = sc.line_entry.line;
2024
Greg Clayton016a95e2010-09-14 02:20:48 +00002025 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002026 {
2027 sc.function = NULL;
2028 sc.block = NULL;
2029 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2030 {
2031 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2032 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2033 {
2034 DWARFDebugInfoEntry *function_die = NULL;
2035 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002036 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002037
2038 if (function_die != NULL)
2039 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002040 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002041 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002042 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002043 }
2044
2045 if (sc.function != NULL)
2046 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002047 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002048
2049 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002050 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002051 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002052 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002053 }
2054 }
2055 }
2056
2057 sc_list.Append(sc);
2058 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2059 }
2060 }
2061 }
2062 else if (file_spec_matches_cu_file_spec && !check_inlines)
2063 {
2064 // only append the context if we aren't looking for inline call sites
2065 // by file and line and if the file spec matches that of the compile unit
2066 sc_list.Append(sc);
2067 }
2068 }
2069 else if (file_spec_matches_cu_file_spec && !check_inlines)
2070 {
2071 // only append the context if we aren't looking for inline call sites
2072 // by file and line and if the file spec matches that of the compile unit
2073 sc_list.Append(sc);
2074 }
2075
2076 if (!check_inlines)
2077 break;
2078 }
2079 }
2080 }
2081 }
2082 return sc_list.GetSize() - prev_size;
2083}
2084
2085void
2086SymbolFileDWARF::Index ()
2087{
2088 if (m_indexed)
2089 return;
2090 m_indexed = true;
2091 Timer scoped_timer (__PRETTY_FUNCTION__,
2092 "SymbolFileDWARF::Index (%s)",
2093 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2094
2095 DWARFDebugInfo* debug_info = DebugInfo();
2096 if (debug_info)
2097 {
2098 uint32_t cu_idx = 0;
2099 const uint32_t num_compile_units = GetNumCompileUnits();
2100 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2101 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002102 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002103
Greg Clayton96d7d742010-11-10 23:42:09 +00002104 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002105
Greg Clayton96d7d742010-11-10 23:42:09 +00002106 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002107 m_function_basename_index,
2108 m_function_fullname_index,
2109 m_function_method_index,
2110 m_function_selector_index,
2111 m_objc_class_selectors_index,
2112 m_global_index,
2113 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002114 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115
2116 // Keep memory down by clearing DIEs if this generate function
2117 // caused them to be parsed
2118 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002119 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002120 }
2121
Greg Claytond4a2b372011-09-12 23:21:58 +00002122 m_function_basename_index.Finalize();
2123 m_function_fullname_index.Finalize();
2124 m_function_method_index.Finalize();
2125 m_function_selector_index.Finalize();
2126 m_objc_class_selectors_index.Finalize();
2127 m_global_index.Finalize();
2128 m_type_index.Finalize();
2129 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002130
Greg Clayton24739922010-10-13 03:15:28 +00002131#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002132 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002133 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002134 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2135 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002136 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2137 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2138 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2139 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2140 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2141 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002142 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002143 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002144#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002145 }
2146}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002147
2148bool
2149SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2150{
2151 if (namespace_decl == NULL)
2152 {
2153 // Invalid namespace decl which means we aren't matching only things
2154 // in this symbol file, so return true to indicate it matches this
2155 // symbol file.
2156 return true;
2157 }
2158
2159 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2160
2161 if (namespace_ast == NULL)
2162 return true; // No AST in the "namespace_decl", return true since it
2163 // could then match any symbol file, including this one
2164
2165 if (namespace_ast == GetClangASTContext().getASTContext())
2166 return true; // The ASTs match, return true
2167
2168 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002169 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2170
2171 if (log)
2172 log->Printf("Valid namespace does not match symbol file");
2173
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002174 return false;
2175}
2176
Greg Clayton2506a7a2011-10-12 23:34:26 +00002177bool
2178SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2179 DWARFCompileUnit* cu,
2180 const DWARFDebugInfoEntry* die)
2181{
2182 // No namespace specified, so the answesr i
2183 if (namespace_decl == NULL)
2184 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002185
2186 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002187
Greg Clayton2506a7a2011-10-12 23:34:26 +00002188 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2189 if (decl_ctx_die)
2190 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002191
Greg Clayton2506a7a2011-10-12 23:34:26 +00002192 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2193 if (clang_namespace_decl)
2194 {
2195 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002196 {
2197 if (log)
2198 log->Printf("Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002199 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002200 }
2201
Greg Clayton2506a7a2011-10-12 23:34:26 +00002202 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2203
2204 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002205 {
2206 if (log)
2207 log->Printf("Found a match in a namespace, but its parent is not the requested namespace");
2208
Greg Clayton2506a7a2011-10-12 23:34:26 +00002209 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002210 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002211
Greg Claytoncb5860a2011-10-13 23:49:28 +00002212 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002213 }
2214 else
2215 {
2216 // We have a namespace_decl that was not NULL but it contained
2217 // a NULL "clang::NamespaceDecl", so this means the global namespace
2218 // So as long the the contained decl context DIE isn't a namespace
2219 // we should be ok.
2220 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2221 return true;
2222 }
2223 }
Sean Callananebe60672011-10-13 21:50:33 +00002224
2225 if (log)
2226 log->Printf("Found a match, but its parent doesn't exist");
2227
Greg Clayton2506a7a2011-10-12 23:34:26 +00002228 return false;
2229}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002230uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002231SymbolFileDWARF::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 +00002232{
Greg Clayton21f2a492011-10-06 00:09:08 +00002233 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2234
2235 if (log)
2236 {
2237 log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", name=\"%s\", append=%u, max_matches=%u, variables)",
2238 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2239 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2240 name.GetCString(), append, max_matches);
2241 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002242
2243 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2244 return 0;
2245
Greg Claytonc685f8e2010-09-15 04:15:46 +00002246 DWARFDebugInfo* info = DebugInfo();
2247 if (info == NULL)
2248 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249
2250 // If we aren't appending the results to this list, then clear the list
2251 if (!append)
2252 variables.Clear();
2253
2254 // Remember how many variables are in the list before we search in case
2255 // we are appending the results to a variable list.
2256 const uint32_t original_size = variables.GetSize();
2257
Greg Claytond4a2b372011-09-12 23:21:58 +00002258 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002259
Greg Clayton97fbc342011-10-20 22:30:33 +00002260 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002261 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002262 if (m_apple_names_ap.get())
2263 {
2264 const char *name_cstr = name.GetCString();
2265 const char *base_name_start;
2266 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002267
Greg Clayton97fbc342011-10-20 22:30:33 +00002268 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2269 base_name_start = name_cstr;
2270
2271 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2272 }
Greg Clayton7f995132011-10-04 22:41:51 +00002273 }
2274 else
2275 {
2276 // Index the DWARF if we haven't already
2277 if (!m_indexed)
2278 Index ();
2279
2280 m_global_index.Find (name, die_offsets);
2281 }
2282
2283 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002284 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002285 {
Greg Clayton7f995132011-10-04 22:41:51 +00002286 SymbolContext sc;
2287 sc.module_sp = m_obj_file->GetModule();
2288 assert (sc.module_sp);
2289
Greg Claytond4a2b372011-09-12 23:21:58 +00002290 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002291 DWARFCompileUnit* dwarf_cu = NULL;
2292 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002293 for (size_t i=0; i<num_matches; ++i)
2294 {
2295 const dw_offset_t die_offset = die_offsets[i];
2296 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002297
Greg Claytond4a2b372011-09-12 23:21:58 +00002298 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2299 assert(sc.comp_unit != NULL);
Sean Callanan213fdb82011-10-13 01:49:10 +00002300
2301 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2302 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002303
Greg Claytond4a2b372011-09-12 23:21:58 +00002304 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002305
Greg Claytond4a2b372011-09-12 23:21:58 +00002306 if (variables.GetSize() - original_size >= max_matches)
2307 break;
2308 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002309 }
2310
2311 // Return the number of variable that were appended to the list
2312 return variables.GetSize() - original_size;
2313}
2314
2315uint32_t
2316SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2317{
Greg Clayton21f2a492011-10-06 00:09:08 +00002318 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2319
2320 if (log)
2321 {
2322 log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", regex=\"%s\", append=%u, max_matches=%u, variables)",
2323 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2324 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2325 regex.GetText(), append, max_matches);
2326 }
2327
Greg Claytonc685f8e2010-09-15 04:15:46 +00002328 DWARFDebugInfo* info = DebugInfo();
2329 if (info == NULL)
2330 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002331
2332 // If we aren't appending the results to this list, then clear the list
2333 if (!append)
2334 variables.Clear();
2335
2336 // Remember how many variables are in the list before we search in case
2337 // we are appending the results to a variable list.
2338 const uint32_t original_size = variables.GetSize();
2339
Greg Clayton7f995132011-10-04 22:41:51 +00002340 DIEArray die_offsets;
2341
Greg Clayton97fbc342011-10-20 22:30:33 +00002342 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002343 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002344 if (m_apple_names_ap.get())
2345 m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002346 }
2347 else
2348 {
2349 // Index the DWARF if we haven't already
2350 if (!m_indexed)
2351 Index ();
2352
2353 m_global_index.Find (regex, die_offsets);
2354 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002355
Greg Claytonc685f8e2010-09-15 04:15:46 +00002356 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002357 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002358 assert (sc.module_sp);
2359
Greg Claytond4a2b372011-09-12 23:21:58 +00002360 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002361 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002362 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002363 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002364 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002365 DWARFDebugInfo* debug_info = DebugInfo();
2366 for (size_t i=0; i<num_matches; ++i)
2367 {
2368 const dw_offset_t die_offset = die_offsets[i];
2369 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2370 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002371
Greg Claytond4a2b372011-09-12 23:21:58 +00002372 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002373
Greg Claytond4a2b372011-09-12 23:21:58 +00002374 if (variables.GetSize() - original_size >= max_matches)
2375 break;
2376 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002377 }
2378
2379 // Return the number of variable that were appended to the list
2380 return variables.GetSize() - original_size;
2381}
2382
Greg Claytonaa044962011-10-13 00:59:38 +00002383
Jim Ingham4cda6e02011-10-07 22:23:45 +00002384bool
2385SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2386 DWARFCompileUnit *&dwarf_cu,
2387 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002388{
Greg Claytonaa044962011-10-13 00:59:38 +00002389 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2390 return ResolveFunction (dwarf_cu, die, sc_list);
2391}
2392
2393
2394bool
2395SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2396 const DWARFDebugInfoEntry *die,
2397 SymbolContextList& sc_list)
2398{
Greg Clayton9e315582011-09-02 04:03:59 +00002399 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002400
2401 if (die == NULL)
2402 return false;
2403
Jim Ingham4cda6e02011-10-07 22:23:45 +00002404 // If we were passed a die that is not a function, just return false...
2405 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2406 return false;
2407
2408 const DWARFDebugInfoEntry* inlined_die = NULL;
2409 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002410 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002411 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002412
Jim Ingham4cda6e02011-10-07 22:23:45 +00002413 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002414 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002415 if (die->Tag() == DW_TAG_subprogram)
2416 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002417 }
2418 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002419 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002420 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002421 {
2422 Address addr;
2423 // Parse all blocks if needed
2424 if (inlined_die)
2425 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002426 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002427 assert (sc.block != NULL);
2428 if (sc.block->GetStartAddress (addr) == false)
2429 addr.Clear();
2430 }
2431 else
2432 {
2433 sc.block = NULL;
2434 addr = sc.function->GetAddressRange().GetBaseAddress();
2435 }
2436
2437 if (addr.IsValid())
2438 {
2439
2440 // We found the function, so we should find the line table
2441 // and line table entry as well
2442 LineTable *line_table = sc.comp_unit->GetLineTable();
2443 if (line_table == NULL)
2444 {
2445 if (ParseCompileUnitLineTable(sc))
2446 line_table = sc.comp_unit->GetLineTable();
2447 }
2448 if (line_table != NULL)
2449 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2450
2451 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002452 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002453 }
2454 }
2455
Greg Claytonaa044962011-10-13 00:59:38 +00002456 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002457}
2458
Greg Clayton7f995132011-10-04 22:41:51 +00002459void
2460SymbolFileDWARF::FindFunctions (const ConstString &name,
2461 const NameToDIE &name_to_die,
2462 SymbolContextList& sc_list)
2463{
Greg Claytond4a2b372011-09-12 23:21:58 +00002464 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002465 if (name_to_die.Find (name, die_offsets))
2466 {
2467 ParseFunctions (die_offsets, sc_list);
2468 }
2469}
2470
2471
2472void
2473SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2474 const NameToDIE &name_to_die,
2475 SymbolContextList& sc_list)
2476{
2477 DIEArray die_offsets;
2478 if (name_to_die.Find (regex, die_offsets))
2479 {
2480 ParseFunctions (die_offsets, sc_list);
2481 }
2482}
2483
2484
2485void
2486SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2487 const DWARFMappedHash::MemoryTable &memory_table,
2488 SymbolContextList& sc_list)
2489{
2490 DIEArray die_offsets;
2491 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, die_offsets))
2492 {
2493 ParseFunctions (die_offsets, sc_list);
2494 }
2495}
2496
2497void
2498SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2499 SymbolContextList& sc_list)
2500{
2501 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002502 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002503 {
Greg Clayton7f995132011-10-04 22:41:51 +00002504 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002505
2506 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002507 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002508 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002509 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002510 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002511 }
2512 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002513}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002514
Jim Ingham4cda6e02011-10-07 22:23:45 +00002515bool
2516SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2517 const DWARFCompileUnit *dwarf_cu,
2518 uint32_t name_type_mask,
2519 const char *partial_name,
2520 const char *base_name_start,
2521 const char *base_name_end)
2522{
2523 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2524 if (name_type_mask == eFunctionNameTypeMethod
2525 || name_type_mask == eFunctionNameTypeBase)
2526 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002527 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2528 if (!containing_decl_ctx)
2529 return false;
2530
2531 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2532
2533 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2534 return false;
2535 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2536 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002537 }
2538
2539 // Now we need to check whether the name we got back for this type matches the extra specifications
2540 // that were in the name we're looking up:
2541 if (base_name_start != partial_name || *base_name_end != '\0')
2542 {
2543 // First see if the stuff to the left matches the full name. To do that let's see if
2544 // we can pull out the mips linkage name attribute:
2545
2546 Mangled best_name;
2547
2548 DWARFDebugInfoEntry::Attributes attributes;
2549 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2550 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2551 if (idx != UINT32_MAX)
2552 {
2553 DWARFFormValue form_value;
2554 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2555 {
2556 const char *name = form_value.AsCString(&get_debug_str_data());
2557 best_name.SetValue (name, true);
2558 }
2559 }
2560 if (best_name)
2561 {
2562 const char *demangled = best_name.GetDemangledName().GetCString();
2563 if (demangled)
2564 {
2565 std::string name_no_parens(partial_name, base_name_end - partial_name);
2566 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002567 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002568 }
2569 }
2570 }
2571
2572 return true;
2573}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002574
Greg Clayton0c5cd902010-06-28 21:30:43 +00002575uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002576SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002577 const lldb_private::ClangNamespaceDecl *namespace_decl,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002578 uint32_t name_type_mask,
2579 bool append,
2580 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002581{
2582 Timer scoped_timer (__PRETTY_FUNCTION__,
2583 "SymbolFileDWARF::FindFunctions (name = '%s')",
2584 name.AsCString());
2585
Greg Clayton21f2a492011-10-06 00:09:08 +00002586 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2587
2588 if (log)
2589 {
2590 log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2591 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2592 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2593 name.GetCString(), name_type_mask, append);
2594 }
2595
Greg Clayton0c5cd902010-06-28 21:30:43 +00002596 // If we aren't appending the results to this list, then clear the list
2597 if (!append)
2598 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002599
2600 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2601 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002602
2603 // If name is empty then we won't find anything.
2604 if (name.IsEmpty())
2605 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002606
2607 // Remember how many sc_list are in the list before we search in case
2608 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002609
Greg Clayton9e315582011-09-02 04:03:59 +00002610 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002611
Jim Ingham4cda6e02011-10-07 22:23:45 +00002612 const char *name_cstr = name.GetCString();
2613 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2614 const char *base_name_start = name_cstr;
2615 const char *base_name_end = name_cstr + strlen(name_cstr);
2616
2617 if (name_type_mask & eFunctionNameTypeAuto)
2618 {
2619 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2620 effective_name_type_mask = eFunctionNameTypeFull;
2621 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2622 effective_name_type_mask = eFunctionNameTypeFull;
2623 else
2624 {
2625 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2626 effective_name_type_mask |= eFunctionNameTypeSelector;
2627
2628 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2629 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2630 }
2631 }
2632 else
2633 {
2634 effective_name_type_mask = name_type_mask;
2635 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2636 {
2637 // If they've asked for a CPP method or function name and it can't be that, we don't
2638 // even need to search for CPP methods or names.
2639 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2640 {
2641 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2642 if (effective_name_type_mask == eFunctionNameTypeNone)
2643 return 0;
2644 }
2645 }
2646
2647 if (effective_name_type_mask & eFunctionNameTypeSelector)
2648 {
2649 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2650 {
2651 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2652 if (effective_name_type_mask == eFunctionNameTypeNone)
2653 return 0;
2654 }
2655 }
2656 }
2657
2658 DWARFDebugInfo* info = DebugInfo();
2659 if (info == NULL)
2660 return 0;
2661
Greg Claytonaa044962011-10-13 00:59:38 +00002662 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00002663 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002664 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002665 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002666 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002667
2668 DIEArray die_offsets;
2669
2670 uint32_t num_matches = 0;
2671
2672 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002673 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002674 // If they asked for the full name, match what they typed. At some point we may
2675 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2676 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002677 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002678 for (uint32_t i = 0; i < num_matches; i++)
2679 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002680 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002681 if (die)
2682 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002683 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2684 continue;
2685
Greg Claytonaa044962011-10-13 00:59:38 +00002686 ResolveFunction (dwarf_cu, die, sc_list);
2687 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002688 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002689 }
2690 else
2691 {
2692 if (effective_name_type_mask & eFunctionNameTypeSelector)
2693 {
2694 if (namespace_decl && *namespace_decl)
2695 return 0; // no selectors in namespaces
2696
2697 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2698 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2699 // and if it is an ObjC method name, we're good.
2700
2701 for (uint32_t i = 0; i < num_matches; i++)
2702 {
2703 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2704 if (die)
2705 {
2706 const char *die_name = die->GetName(this, dwarf_cu);
2707 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
2708 ResolveFunction (dwarf_cu, die, sc_list);
2709 }
2710 }
2711 die_offsets.clear();
2712 }
2713
2714 if (effective_name_type_mask & eFunctionNameTypeMethod
2715 || effective_name_type_mask & eFunctionNameTypeBase)
2716 {
2717 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
2718 (namespace_decl && *namespace_decl))
2719 return 0; // no methods in namespaces
2720
2721 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2722 // extract the base name, look that up, and if there is any other information in the name we were
2723 // passed in we have to post-filter based on that.
2724
2725 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2726 std::string base_name(base_name_start, base_name_end - base_name_start);
2727 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
2728
2729 for (uint32_t i = 0; i < num_matches; i++)
2730 {
2731 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2732 if (die)
2733 {
2734 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2735 continue;
2736
2737 if (!FunctionDieMatchesPartialName(die,
2738 dwarf_cu,
2739 effective_name_type_mask,
2740 name_cstr,
2741 base_name_start,
2742 base_name_end))
2743 continue;
2744
2745 // If we get to here, the die is good, and we should add it:
2746 ResolveFunction (dwarf_cu, die, sc_list);
2747 }
2748 }
2749 die_offsets.clear();
2750 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002751 }
2752 }
Greg Clayton7f995132011-10-04 22:41:51 +00002753 }
2754 else
2755 {
2756
2757 // Index the DWARF if we haven't already
2758 if (!m_indexed)
2759 Index ();
2760
Greg Clayton7f995132011-10-04 22:41:51 +00002761 if (name_type_mask & eFunctionNameTypeFull)
2762 FindFunctions (name, m_function_fullname_index, sc_list);
2763
Jim Ingham4cda6e02011-10-07 22:23:45 +00002764 std::string base_name(base_name_start, base_name_end - base_name_start);
2765 ConstString base_name_const(base_name.c_str());
2766 DIEArray die_offsets;
2767 DWARFCompileUnit *dwarf_cu = NULL;
2768
2769 if (effective_name_type_mask & eFunctionNameTypeBase)
2770 {
2771 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002772 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002773 {
Greg Claytonaa044962011-10-13 00:59:38 +00002774 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2775 if (die)
2776 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002777 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2778 continue;
2779
Greg Claytonaa044962011-10-13 00:59:38 +00002780 if (!FunctionDieMatchesPartialName(die,
2781 dwarf_cu,
2782 effective_name_type_mask,
2783 name_cstr,
2784 base_name_start,
2785 base_name_end))
2786 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002787
Greg Claytonaa044962011-10-13 00:59:38 +00002788 // If we get to here, the die is good, and we should add it:
2789 ResolveFunction (dwarf_cu, die, sc_list);
2790 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002791 }
2792 die_offsets.clear();
2793 }
2794
Jim Inghamea8005a2011-10-11 01:18:11 +00002795 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002796 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002797 if (namespace_decl && *namespace_decl)
2798 return 0; // no methods in namespaces
2799
Jim Ingham4cda6e02011-10-07 22:23:45 +00002800 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
2801 {
Greg Claytonaa044962011-10-13 00:59:38 +00002802 for (uint32_t i = 0; i < num_base; i++)
2803 {
2804 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2805 if (die)
2806 {
2807 if (!FunctionDieMatchesPartialName(die,
2808 dwarf_cu,
2809 effective_name_type_mask,
2810 name_cstr,
2811 base_name_start,
2812 base_name_end))
2813 continue;
2814
2815 // If we get to here, the die is good, and we should add it:
2816 ResolveFunction (dwarf_cu, die, sc_list);
2817 }
2818 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002819 }
2820 die_offsets.clear();
2821 }
Greg Clayton7f995132011-10-04 22:41:51 +00002822
Sean Callanan213fdb82011-10-13 01:49:10 +00002823 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002824 {
Greg Clayton7f995132011-10-04 22:41:51 +00002825 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002826 }
2827
Greg Clayton4d01ace2011-09-29 16:58:15 +00002828 }
2829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830 // Return the number of variable that were appended to the list
2831 return sc_list.GetSize() - original_size;
2832}
2833
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002834uint32_t
2835SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2836{
2837 Timer scoped_timer (__PRETTY_FUNCTION__,
2838 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2839 regex.GetText());
2840
Greg Clayton21f2a492011-10-06 00:09:08 +00002841 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2842
2843 if (log)
2844 {
2845 log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", regex=\"%s\"append=%u, sc_list)",
2846 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2847 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2848 regex.GetText(), append);
2849 }
2850
2851
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002852 // If we aren't appending the results to this list, then clear the list
2853 if (!append)
2854 sc_list.Clear();
2855
2856 // Remember how many sc_list are in the list before we search in case
2857 // we are appending the results to a variable list.
2858 uint32_t original_size = sc_list.GetSize();
2859
Greg Clayton97fbc342011-10-20 22:30:33 +00002860 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002861 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002862 if (m_apple_names_ap.get())
2863 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002864 }
2865 else
2866 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002867 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002868 if (!m_indexed)
2869 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002870
Greg Clayton7f995132011-10-04 22:41:51 +00002871 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002872
Greg Clayton7f995132011-10-04 22:41:51 +00002873 FindFunctions (regex, m_function_fullname_index, sc_list);
2874 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002875
2876 // Return the number of variable that were appended to the list
2877 return sc_list.GetSize() - original_size;
2878}
Jim Ingham318c9f22011-08-26 19:44:13 +00002879
Greg Claytond16e1e52011-07-12 17:06:17 +00002880void
2881SymbolFileDWARF::ReportError (const char *format, ...)
2882{
2883 ::fprintf (stderr,
2884 "error: %s/%s ",
2885 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2886 m_obj_file->GetFileSpec().GetFilename().GetCString());
2887
Greg Claytoncfebbcf2011-10-01 01:37:20 +00002888 if (m_obj_file->GetModule()->GetObjectName())
2889 ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
2890
Greg Claytond16e1e52011-07-12 17:06:17 +00002891 va_list args;
2892 va_start (args, format);
2893 vfprintf (stderr, format, args);
2894 va_end (args);
2895}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002896
Jim Inghamc1663042011-09-29 22:12:35 +00002897void
2898SymbolFileDWARF::ReportWarning (const char *format, ...)
2899{
2900 ::fprintf (stderr,
2901 "warning: %s/%s ",
2902 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2903 m_obj_file->GetFileSpec().GetFilename().GetCString());
2904
Greg Claytoncfebbcf2011-10-01 01:37:20 +00002905 if (m_obj_file->GetModule()->GetObjectName())
2906 ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
2907
Jim Inghamc1663042011-09-29 22:12:35 +00002908 va_list args;
2909 va_start (args, format);
2910 vfprintf (stderr, format, args);
2911 va_end (args);
2912}
2913
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002915SymbolFileDWARF::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 +00002916{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002917 DWARFDebugInfo* info = DebugInfo();
2918 if (info == NULL)
2919 return 0;
2920
Greg Clayton21f2a492011-10-06 00:09:08 +00002921 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2922
2923 if (log)
2924 {
Sean Callananc41e68b2011-10-13 21:08:11 +00002925 log->Printf ("SymbolFileDWARF::FindTypes (file=\"%s/%s\", sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
Greg Clayton21f2a492011-10-06 00:09:08 +00002926 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2927 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2928 name.GetCString(), append, max_matches);
2929 }
2930
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002931 // If we aren't appending the results to this list, then clear the list
2932 if (!append)
2933 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002934
2935 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2936 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002937
Greg Claytond4a2b372011-09-12 23:21:58 +00002938 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002939
Greg Clayton97fbc342011-10-20 22:30:33 +00002940 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002941 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002942 if (m_apple_types_ap.get())
2943 {
2944 const char *name_cstr = name.GetCString();
2945 m_apple_types_ap->FindByName (name_cstr, die_offsets);
2946 }
Greg Clayton7f995132011-10-04 22:41:51 +00002947 }
2948 else
2949 {
2950 if (!m_indexed)
2951 Index ();
2952
2953 m_type_index.Find (name, die_offsets);
2954 }
2955
2956
2957 const size_t num_matches = die_offsets.size();
2958
Greg Claytond4a2b372011-09-12 23:21:58 +00002959 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002960 {
Greg Clayton7f995132011-10-04 22:41:51 +00002961 const uint32_t initial_types_size = types.GetSize();
2962 DWARFCompileUnit* dwarf_cu = NULL;
2963 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002964 DWARFDebugInfo* debug_info = DebugInfo();
2965 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002966 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002967 const dw_offset_t die_offset = die_offsets[i];
2968 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2969
Sean Callanan213fdb82011-10-13 01:49:10 +00002970 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2971 continue;
2972
Greg Claytond4a2b372011-09-12 23:21:58 +00002973 Type *matching_type = ResolveType (dwarf_cu, die);
2974 if (matching_type)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002975 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002976 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton85ae2e12011-10-18 23:36:41 +00002977 types.InsertUnique (TypeSP (matching_type));
2978 if (types.GetSize() >= max_matches)
2979 break;
Greg Clayton73bf5db2011-06-17 01:22:15 +00002980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981 }
Greg Clayton7f995132011-10-04 22:41:51 +00002982 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002983 }
Greg Clayton7f995132011-10-04 22:41:51 +00002984 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985}
2986
2987
Greg Clayton526e5af2010-11-13 03:52:47 +00002988ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002989SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00002990 const ConstString &name,
2991 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00002992{
Greg Clayton21f2a492011-10-06 00:09:08 +00002993 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2994
2995 if (log)
2996 {
2997 log->Printf ("SymbolFileDWARF::FindNamespace (file=\"%s/%s\", sc, name=\"%s\")",
2998 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2999 m_obj_file->GetFileSpec().GetFilename().GetCString(),
3000 name.GetCString());
3001 }
Sean Callanan213fdb82011-10-13 01:49:10 +00003002
3003 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3004 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00003005
Greg Clayton526e5af2010-11-13 03:52:47 +00003006 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003007 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003008 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003009 {
Greg Clayton7f995132011-10-04 22:41:51 +00003010 DIEArray die_offsets;
3011
Greg Clayton526e5af2010-11-13 03:52:47 +00003012 // Index if we already haven't to make sure the compile units
3013 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003014 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003015 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003016 if (m_apple_namespaces_ap.get())
3017 {
3018 const char *name_cstr = name.GetCString();
3019 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3020 }
Greg Clayton7f995132011-10-04 22:41:51 +00003021 }
3022 else
3023 {
3024 if (!m_indexed)
3025 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003026
Greg Clayton7f995132011-10-04 22:41:51 +00003027 m_namespace_index.Find (name, die_offsets);
3028 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003029
3030 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003031 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003032 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003033 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003034 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003035 DWARFDebugInfo* debug_info = DebugInfo();
3036 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003037 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003038 const dw_offset_t die_offset = die_offsets[i];
3039 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003040
3041 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3042 continue;
Greg Claytond4a2b372011-09-12 23:21:58 +00003043
3044 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3045 if (clang_namespace_decl)
3046 {
3047 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3048 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
3049 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003050 }
3051 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003052 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003053 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003054}
3055
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003056uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003057SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003058{
3059 // Remember how many sc_list are in the list before we search in case
3060 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003061 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003062
3063 const uint32_t num_die_offsets = die_offsets.size();
3064 // Parse all of the types we found from the pubtypes matches
3065 uint32_t i;
3066 uint32_t num_matches = 0;
3067 for (i = 0; i < num_die_offsets; ++i)
3068 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003069 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3070 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003071 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003072 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton85ae2e12011-10-18 23:36:41 +00003073 types.InsertUnique (TypeSP (matching_type));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003074 ++num_matches;
3075 if (num_matches >= max_matches)
3076 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003077 }
3078 }
3079
3080 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003081 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003082}
3083
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003084
3085size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003086SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3087 clang::DeclContext *containing_decl_ctx,
3088 TypeSP& type_sp,
3089 DWARFCompileUnit* dwarf_cu,
3090 const DWARFDebugInfoEntry *parent_die,
3091 bool skip_artificial,
3092 bool &is_static,
3093 TypeList* type_list,
3094 std::vector<clang_type_t>& function_param_types,
3095 std::vector<clang::ParmVarDecl*>& function_param_decls,
3096 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003097{
3098 if (parent_die == NULL)
3099 return 0;
3100
Greg Claytond88d7592010-09-15 08:33:30 +00003101 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3102
Greg Clayton7fedea22010-11-16 02:10:54 +00003103 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003104 const DWARFDebugInfoEntry *die;
3105 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3106 {
3107 dw_tag_t tag = die->Tag();
3108 switch (tag)
3109 {
3110 case DW_TAG_formal_parameter:
3111 {
3112 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003113 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003114 if (num_attributes > 0)
3115 {
3116 const char *name = NULL;
3117 Declaration decl;
3118 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003119 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003120 // one of None, Auto, Register, Extern, Static, PrivateExtern
3121
Sean Callanane2ef6e32010-09-23 03:01:22 +00003122 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003123 uint32_t i;
3124 for (i=0; i<num_attributes; ++i)
3125 {
3126 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3127 DWARFFormValue form_value;
3128 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3129 {
3130 switch (attr)
3131 {
3132 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3133 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3134 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3135 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3136 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003137 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003138 case DW_AT_location:
3139 // if (form_value.BlockData())
3140 // {
3141 // const DataExtractor& debug_info_data = debug_info();
3142 // uint32_t block_length = form_value.Unsigned();
3143 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3144 // }
3145 // else
3146 // {
3147 // }
3148 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003149 case DW_AT_const_value:
3150 case DW_AT_default_value:
3151 case DW_AT_description:
3152 case DW_AT_endianity:
3153 case DW_AT_is_optional:
3154 case DW_AT_segment:
3155 case DW_AT_variable_parameter:
3156 default:
3157 case DW_AT_abstract_origin:
3158 case DW_AT_sibling:
3159 break;
3160 }
3161 }
3162 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003163
Greg Clayton0fffff52010-09-24 05:15:53 +00003164 bool skip = false;
3165 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003166 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003167 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003168 {
3169 // In order to determine if a C++ member function is
3170 // "const" we have to look at the const-ness of "this"...
3171 // Ugly, but that
3172 if (arg_idx == 0)
3173 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003174 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003175 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003176 // Often times compilers omit the "this" name for the
3177 // specification DIEs, so we can't rely upon the name
3178 // being in the formal parameter DIE...
3179 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003180 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003181 Type *this_type = ResolveTypeUID (param_type_die_offset);
3182 if (this_type)
3183 {
3184 uint32_t encoding_mask = this_type->GetEncodingMask();
3185 if (encoding_mask & Type::eEncodingIsPointerUID)
3186 {
3187 is_static = false;
3188
3189 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3190 type_quals |= clang::Qualifiers::Const;
3191 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3192 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003193 }
3194 }
3195 }
3196 }
3197 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003198 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003199 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003200 else
3201 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003202
Greg Clayton0fffff52010-09-24 05:15:53 +00003203 // HACK: Objective C formal parameters "self" and "_cmd"
3204 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003205 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3206 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003207 {
3208 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3209 skip = true;
3210 }
3211 }
3212 }
3213
3214 if (!skip)
3215 {
3216 Type *type = ResolveTypeUID(param_type_die_offset);
3217 if (type)
3218 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003219 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003220
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003221 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003222 assert(param_var_decl);
3223 function_param_decls.push_back(param_var_decl);
3224 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003225 }
3226 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003227 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003228 }
3229 break;
3230
3231 default:
3232 break;
3233 }
3234 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003235 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003236}
3237
3238size_t
3239SymbolFileDWARF::ParseChildEnumerators
3240(
3241 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003242 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003243 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003244 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003245 const DWARFDebugInfoEntry *parent_die
3246)
3247{
3248 if (parent_die == NULL)
3249 return 0;
3250
3251 size_t enumerators_added = 0;
3252 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003253 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3254
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003255 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3256 {
3257 const dw_tag_t tag = die->Tag();
3258 if (tag == DW_TAG_enumerator)
3259 {
3260 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003261 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003262 if (num_child_attributes > 0)
3263 {
3264 const char *name = NULL;
3265 bool got_value = false;
3266 int64_t enum_value = 0;
3267 Declaration decl;
3268
3269 uint32_t i;
3270 for (i=0; i<num_child_attributes; ++i)
3271 {
3272 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3273 DWARFFormValue form_value;
3274 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3275 {
3276 switch (attr)
3277 {
3278 case DW_AT_const_value:
3279 got_value = true;
3280 enum_value = form_value.Unsigned();
3281 break;
3282
3283 case DW_AT_name:
3284 name = form_value.AsCString(&get_debug_str_data());
3285 break;
3286
3287 case DW_AT_description:
3288 default:
3289 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3290 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3291 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3292 case DW_AT_sibling:
3293 break;
3294 }
3295 }
3296 }
3297
3298 if (name && name[0] && got_value)
3299 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003300 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3301 enumerator_clang_type,
3302 decl,
3303 name,
3304 enum_value,
3305 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003306 ++enumerators_added;
3307 }
3308 }
3309 }
3310 }
3311 return enumerators_added;
3312}
3313
3314void
3315SymbolFileDWARF::ParseChildArrayInfo
3316(
3317 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003318 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003319 const DWARFDebugInfoEntry *parent_die,
3320 int64_t& first_index,
3321 std::vector<uint64_t>& element_orders,
3322 uint32_t& byte_stride,
3323 uint32_t& bit_stride
3324)
3325{
3326 if (parent_die == NULL)
3327 return;
3328
3329 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003330 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003331 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3332 {
3333 const dw_tag_t tag = die->Tag();
3334 switch (tag)
3335 {
3336 case DW_TAG_enumerator:
3337 {
3338 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003339 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003340 if (num_child_attributes > 0)
3341 {
3342 const char *name = NULL;
3343 bool got_value = false;
3344 int64_t enum_value = 0;
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:
3367 case DW_AT_decl_line:
3368 case DW_AT_decl_column:
3369 case DW_AT_sibling:
3370 break;
3371 }
3372 }
3373 }
3374 }
3375 }
3376 break;
3377
3378 case DW_TAG_subrange_type:
3379 {
3380 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003381 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003382 if (num_child_attributes > 0)
3383 {
3384 const char *name = NULL;
3385 bool got_value = false;
3386 uint64_t byte_size = 0;
3387 int64_t enum_value = 0;
3388 uint64_t num_elements = 0;
3389 uint64_t lower_bound = 0;
3390 uint64_t upper_bound = 0;
3391 uint32_t i;
3392 for (i=0; i<num_child_attributes; ++i)
3393 {
3394 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3395 DWARFFormValue form_value;
3396 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3397 {
3398 switch (attr)
3399 {
3400 case DW_AT_const_value:
3401 got_value = true;
3402 enum_value = form_value.Unsigned();
3403 break;
3404
3405 case DW_AT_name:
3406 name = form_value.AsCString(&get_debug_str_data());
3407 break;
3408
3409 case DW_AT_count:
3410 num_elements = form_value.Unsigned();
3411 break;
3412
3413 case DW_AT_bit_stride:
3414 bit_stride = form_value.Unsigned();
3415 break;
3416
3417 case DW_AT_byte_stride:
3418 byte_stride = form_value.Unsigned();
3419 break;
3420
3421 case DW_AT_byte_size:
3422 byte_size = form_value.Unsigned();
3423 break;
3424
3425 case DW_AT_lower_bound:
3426 lower_bound = form_value.Unsigned();
3427 break;
3428
3429 case DW_AT_upper_bound:
3430 upper_bound = form_value.Unsigned();
3431 break;
3432
3433 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003434 case DW_AT_abstract_origin:
3435 case DW_AT_accessibility:
3436 case DW_AT_allocated:
3437 case DW_AT_associated:
3438 case DW_AT_data_location:
3439 case DW_AT_declaration:
3440 case DW_AT_description:
3441 case DW_AT_sibling:
3442 case DW_AT_threads_scaled:
3443 case DW_AT_type:
3444 case DW_AT_visibility:
3445 break;
3446 }
3447 }
3448 }
3449
3450 if (upper_bound > lower_bound)
3451 num_elements = upper_bound - lower_bound + 1;
3452
3453 if (num_elements > 0)
3454 element_orders.push_back (num_elements);
3455 }
3456 }
3457 break;
3458 }
3459 }
3460}
3461
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003462TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003463SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003464{
3465 TypeSP type_sp;
3466 if (die != NULL)
3467 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003468 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003469 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003470 if (type_ptr == NULL)
3471 {
Greg Claytonca512b32011-01-14 04:54:56 +00003472 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3473 assert (lldb_cu);
3474 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003475 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003476 }
3477 else if (type_ptr != DIE_IS_BEING_PARSED)
3478 {
3479 // Grab the existing type from the master types lists
Greg Clayton85ae2e12011-10-18 23:36:41 +00003480 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003481 }
3482
3483 }
3484 return type_sp;
3485}
3486
3487clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003488SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003489{
3490 if (die_offset != DW_INVALID_OFFSET)
3491 {
3492 DWARFCompileUnitSP cu_sp;
3493 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003494 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003495 }
3496 return NULL;
3497}
3498
Sean Callanan72e49402011-08-05 23:43:37 +00003499clang::DeclContext *
3500SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3501{
3502 if (die_offset != DW_INVALID_OFFSET)
3503 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003504 DWARFDebugInfo* debug_info = DebugInfo();
3505 if (debug_info)
3506 {
3507 DWARFCompileUnitSP cu_sp;
3508 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3509 if (die)
3510 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3511 }
Sean Callanan72e49402011-08-05 23:43:37 +00003512 }
3513 return NULL;
3514}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003515
Greg Clayton96d7d742010-11-10 23:42:09 +00003516clang::NamespaceDecl *
3517SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3518{
Greg Clayton030a2042011-10-14 21:34:45 +00003519 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003520 {
Greg Clayton030a2042011-10-14 21:34:45 +00003521 // See if we already parsed this namespace DIE and associated it with a
3522 // uniqued namespace declaration
3523 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3524 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003525 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003526 else
3527 {
3528 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Greg Clayton9d3d6882011-10-31 23:51:19 +00003529 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3530 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3531 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3532 if (log)
Greg Clayton030a2042011-10-14 21:34:45 +00003533 {
Greg Clayton9d3d6882011-10-31 23:51:19 +00003534 const char *object_name = m_obj_file->GetModule()->GetObjectName().GetCString();
3535 if (namespace_name)
Greg Clayton030a2042011-10-14 21:34:45 +00003536 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003537 log->Printf ("ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)",
Greg Clayton030a2042011-10-14 21:34:45 +00003538 GetClangASTContext().getASTContext(),
Greg Clayton81c22f62011-10-19 18:09:39 +00003539 MakeUserID(die->GetOffset()),
Greg Clayton030a2042011-10-14 21:34:45 +00003540 namespace_name,
3541 namespace_decl,
3542 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
3543 m_obj_file->GetFileSpec().GetFilename().GetCString(),
3544 object_name ? "(" : "",
3545 object_name ? object_name : "",
3546 object_name ? "(" : "",
3547 namespace_decl->getOriginalNamespace());
3548 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003549 else
3550 {
3551 log->Printf ("ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)",
3552 GetClangASTContext().getASTContext(),
3553 MakeUserID(die->GetOffset()),
3554 namespace_decl,
3555 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
3556 m_obj_file->GetFileSpec().GetFilename().GetCString(),
3557 object_name ? "(" : "",
3558 object_name ? object_name : "",
3559 object_name ? "(" : "",
3560 namespace_decl->getOriginalNamespace());
3561 }
Greg Clayton030a2042011-10-14 21:34:45 +00003562 }
Greg Clayton9d3d6882011-10-31 23:51:19 +00003563
3564 if (namespace_decl)
3565 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3566 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003567 }
3568 }
3569 return NULL;
3570}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003571
3572clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003573SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3574{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003575 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3576 if (clang_decl_ctx)
3577 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003578 // If this DIE has a specification, or an abstract origin, then trace to those.
3579
3580 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
3581 if (die_offset != DW_INVALID_OFFSET)
3582 return GetClangDeclContextForDIEOffset (sc, die_offset);
3583
3584 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3585 if (die_offset != DW_INVALID_OFFSET)
3586 return GetClangDeclContextForDIEOffset (sc, die_offset);
3587
3588 // This is the DIE we want. Parse it, then query our map.
3589
3590 ParseType(sc, curr_cu, die, NULL);
3591
Greg Clayton5cf58b92011-10-05 22:22:08 +00003592 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3593
3594 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003595}
3596
3597clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003598SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003599{
Greg Claytonca512b32011-01-14 04:54:56 +00003600 if (m_clang_tu_decl == NULL)
3601 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003602
Greg Clayton2bc22f82011-09-30 03:20:47 +00003603 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003604
3605 if (decl_ctx_die_copy)
3606 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003607
3608 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003609 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003610
Greg Clayton2bc22f82011-09-30 03:20:47 +00003611 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3612 if (pos != m_die_to_decl_ctx.end())
3613 return pos->second;
3614
3615 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003616 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003617 case DW_TAG_compile_unit:
3618 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003619
Greg Clayton2bc22f82011-09-30 03:20:47 +00003620 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003621 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003622 break;
3623
3624 case DW_TAG_structure_type:
3625 case DW_TAG_union_type:
3626 case DW_TAG_class_type:
3627 {
3628 Type* type = ResolveType (cu, decl_ctx_die);
3629 if (type)
3630 {
3631 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3632 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003633 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003634 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3635 if (decl_ctx)
3636 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003637 }
3638 }
Greg Claytonca512b32011-01-14 04:54:56 +00003639 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003640 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003641
Greg Clayton2bc22f82011-09-30 03:20:47 +00003642 default:
3643 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003644 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003645 }
Greg Clayton7a345282010-11-09 23:46:37 +00003646 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003647}
3648
Greg Clayton2bc22f82011-09-30 03:20:47 +00003649
3650const DWARFDebugInfoEntry *
3651SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3652{
3653 if (cu && die)
3654 {
3655 const DWARFDebugInfoEntry * const decl_die = die;
3656
3657 while (die != NULL)
3658 {
3659 // If this is the original DIE that we are searching for a declaration
3660 // for, then don't look in the cache as we don't want our own decl
3661 // context to be our decl context...
3662 if (decl_die != die)
3663 {
3664 switch (die->Tag())
3665 {
3666 case DW_TAG_compile_unit:
3667 case DW_TAG_namespace:
3668 case DW_TAG_structure_type:
3669 case DW_TAG_union_type:
3670 case DW_TAG_class_type:
3671 return die;
3672
3673 default:
3674 break;
3675 }
3676 }
3677
3678 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3679 if (die_offset != DW_INVALID_OFFSET)
3680 {
3681 DWARFCompileUnit *spec_cu = cu;
3682 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3683 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3684 if (spec_die_decl_ctx_die)
3685 return spec_die_decl_ctx_die;
3686 }
3687
3688 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3689 if (die_offset != DW_INVALID_OFFSET)
3690 {
3691 DWARFCompileUnit *abs_cu = cu;
3692 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3693 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3694 if (abs_die_decl_ctx_die)
3695 return abs_die_decl_ctx_die;
3696 }
3697
3698 die = die->GetParent();
3699 }
3700 }
3701 return NULL;
3702}
3703
3704
3705
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003706// This function can be used when a DIE is found that is a forward declaration
3707// DIE and we want to try and find a type that has the complete definition.
3708TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00003709SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
3710 const DWARFDebugInfoEntry *die,
3711 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003712{
3713 TypeSP type_sp;
3714
Greg Clayton1a65ae12011-01-25 23:55:37 +00003715 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003716 return type_sp;
3717
Greg Clayton7f995132011-10-04 22:41:51 +00003718 DIEArray die_offsets;
3719
Greg Clayton97fbc342011-10-20 22:30:33 +00003720 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003721 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003722 if (m_apple_types_ap.get())
3723 {
3724 const char *name_cstr = type_name.GetCString();
3725 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3726 }
Greg Clayton7f995132011-10-04 22:41:51 +00003727 }
3728 else
3729 {
3730 if (!m_indexed)
3731 Index ();
3732
3733 m_type_index.Find (type_name, die_offsets);
3734 }
3735
3736
3737 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00003738
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003739 const dw_tag_t type_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00003740
3741 DWARFCompileUnit* type_cu = NULL;
3742 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003743 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003744 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003745 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003746 for (size_t i=0; i<num_matches; ++i)
3747 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003748 const dw_offset_t die_offset = die_offsets[i];
3749 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003750
3751 if (type_die != die && type_die->Tag() == type_tag)
3752 {
3753 // Hold off on comparing parent DIE tags until
3754 // we know what happens with stuff in namespaces
3755 // for gcc and clang...
3756 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3757 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3758 //if (parent_die->Tag() == parent_type_die->Tag())
3759 {
3760 Type *resolved_type = ResolveType (type_cu, type_die, false);
3761 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3762 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003763 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
3764 MakeUserID(die->GetOffset()),
3765 MakeUserID(curr_cu->GetOffset()),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003766 m_obj_file->GetFileSpec().GetFilename().AsCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00003767 MakeUserID(type_die->GetOffset()),
3768 MakeUserID(type_cu->GetOffset()));
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003769
3770 m_die_to_type[die] = resolved_type;
Greg Clayton85ae2e12011-10-18 23:36:41 +00003771 type_sp = resolved_type;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003772 break;
3773 }
3774 }
3775 }
3776 }
3777 }
3778 return type_sp;
3779}
3780
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003781TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003782SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003783{
3784 TypeSP type_sp;
3785
Greg Clayton1be10fc2010-09-29 01:12:09 +00003786 if (type_is_new_ptr)
3787 *type_is_new_ptr = false;
3788
Sean Callananc7fbf732010-08-06 00:32:49 +00003789 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003790 if (die != NULL)
3791 {
Greg Clayton21f2a492011-10-06 00:09:08 +00003792 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Jim Ingham16746d12011-08-25 23:21:43 +00003793 if (log && dwarf_cu)
3794 {
Jim Ingham318c9f22011-08-26 19:44:13 +00003795 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00003796 die->DumpLocation (this, dwarf_cu, s);
Jim Ingham318c9f22011-08-26 19:44:13 +00003797 log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
3798
Jim Ingham16746d12011-08-25 23:21:43 +00003799 }
3800
Greg Clayton594e5ed2010-09-27 21:07:38 +00003801 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003802 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003803 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003804 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003805 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003806 if (type_is_new_ptr)
3807 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003808
Greg Clayton594e5ed2010-09-27 21:07:38 +00003809 const dw_tag_t tag = die->Tag();
3810
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003811 bool is_forward_declaration = false;
3812 DWARFDebugInfoEntry::Attributes attributes;
3813 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003814 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003815 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3816 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003817 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003818 Declaration decl;
3819
Greg Clayton4957bf62010-09-30 21:49:03 +00003820 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003821 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003822
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003823 dw_attr_t attr;
3824
3825 switch (tag)
3826 {
3827 case DW_TAG_base_type:
3828 case DW_TAG_pointer_type:
3829 case DW_TAG_reference_type:
3830 case DW_TAG_typedef:
3831 case DW_TAG_const_type:
3832 case DW_TAG_restrict_type:
3833 case DW_TAG_volatile_type:
Greg Claytond4436412011-10-28 21:00:00 +00003834 case DW_TAG_unspecified_type:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003835 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003836 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003837 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003838
Greg Claytond88d7592010-09-15 08:33:30 +00003839 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003840 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003841 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3842
3843 if (num_attributes > 0)
3844 {
3845 uint32_t i;
3846 for (i=0; i<num_attributes; ++i)
3847 {
3848 attr = attributes.AttributeAtIndex(i);
3849 DWARFFormValue form_value;
3850 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3851 {
3852 switch (attr)
3853 {
3854 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3855 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3856 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3857 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003859 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003860 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3861 // include the "&"...
3862 if (tag == DW_TAG_reference_type)
3863 {
3864 if (strchr (type_name_cstr, '&') == NULL)
3865 type_name_cstr = NULL;
3866 }
3867 if (type_name_cstr)
3868 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003869 break;
Greg Clayton36909642011-03-15 04:38:20 +00003870 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003871 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3872 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3873 default:
3874 case DW_AT_sibling:
3875 break;
3876 }
3877 }
3878 }
3879 }
3880
Greg Clayton81c22f62011-10-19 18:09:39 +00003881 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 +00003882
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883 switch (tag)
3884 {
3885 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003886 break;
3887
Greg Claytond4436412011-10-28 21:00:00 +00003888 case DW_TAG_unspecified_type:
3889 if (strcmp(type_name_cstr, "nullptr_t") == 0)
3890 {
3891 resolve_state = Type::eResolveStateFull;
3892 clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
3893 break;
3894 }
3895 // Fall through to base type below in case we can handle the type there...
3896
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003897 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003898 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003899 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3900 encoding,
3901 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003902 break;
3903
Greg Clayton526e5af2010-11-13 03:52:47 +00003904 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3905 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3906 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3907 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3908 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3909 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003910 }
3911
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003912 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3913 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3914 {
3915 static ConstString g_objc_type_name_id("id");
3916 static ConstString g_objc_type_name_Class("Class");
3917 static ConstString g_objc_type_name_selector("SEL");
3918
Greg Clayton24739922010-10-13 03:15:28 +00003919 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003920 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003921 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003922 resolve_state = Type::eResolveStateFull;
3923
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003924 }
Greg Clayton24739922010-10-13 03:15:28 +00003925 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003926 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003927 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003928 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003929 }
Greg Clayton24739922010-10-13 03:15:28 +00003930 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003931 {
Sean Callananf6c73082010-12-06 23:53:20 +00003932 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003933 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003934 }
3935 }
3936
Greg Clayton81c22f62011-10-19 18:09:39 +00003937 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003938 this,
3939 type_name_const_str,
3940 byte_size,
3941 NULL,
3942 encoding_uid,
3943 encoding_data_type,
3944 &decl,
3945 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003946 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003947
Greg Clayton594e5ed2010-09-27 21:07:38 +00003948 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003949
3950// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3951// if (encoding_type != NULL)
3952// {
3953// if (encoding_type != DIE_IS_BEING_PARSED)
3954// type_sp->SetEncodingType(encoding_type);
3955// else
3956// m_indirect_fixups.push_back(type_sp.get());
3957// }
3958 }
3959 break;
3960
3961 case DW_TAG_structure_type:
3962 case DW_TAG_union_type:
3963 case DW_TAG_class_type:
3964 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003965 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003966 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003967
Greg Clayton9e409562010-07-28 02:04:09 +00003968 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003969 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003970 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003971 if (num_attributes > 0)
3972 {
3973 uint32_t i;
3974 for (i=0; i<num_attributes; ++i)
3975 {
3976 attr = attributes.AttributeAtIndex(i);
3977 DWARFFormValue form_value;
3978 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3979 {
3980 switch (attr)
3981 {
Greg Clayton9e409562010-07-28 02:04:09 +00003982 case DW_AT_decl_file:
3983 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3984 break;
3985
3986 case DW_AT_decl_line:
3987 decl.SetLine(form_value.Unsigned());
3988 break;
3989
3990 case DW_AT_decl_column:
3991 decl.SetColumn(form_value.Unsigned());
3992 break;
3993
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003994 case DW_AT_name:
3995 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003996 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003997 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003998
3999 case DW_AT_byte_size:
4000 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00004001 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00004002 break;
4003
4004 case DW_AT_accessibility:
4005 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4006 break;
4007
4008 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00004009 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00004010 break;
4011
4012 case DW_AT_APPLE_runtime_class:
4013 class_language = (LanguageType)form_value.Signed();
4014 break;
4015
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016 case DW_AT_allocated:
4017 case DW_AT_associated:
4018 case DW_AT_data_location:
4019 case DW_AT_description:
4020 case DW_AT_start_scope:
4021 case DW_AT_visibility:
4022 default:
4023 case DW_AT_sibling:
4024 break;
4025 }
4026 }
4027 }
4028 }
4029
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004030 UniqueDWARFASTType unique_ast_entry;
4031 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004032 {
Greg Claytone576ab22011-02-15 00:19:15 +00004033 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00004034 this,
4035 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00004036 die,
4037 decl,
Greg Clayton36909642011-03-15 04:38:20 +00004038 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00004039 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00004040 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004041 // We have already parsed this type or from another
4042 // compile unit. GCC loves to use the "one definition
4043 // rule" which can result in multiple definitions
4044 // of the same class over and over in each compile
4045 // unit.
4046 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004047 if (type_sp)
4048 {
Greg Clayton4272cc72011-02-02 02:24:04 +00004049 m_die_to_type[die] = type_sp.get();
4050 return type_sp;
4051 }
4052 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004053 }
4054
Greg Clayton81c22f62011-10-19 18:09:39 +00004055 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 +00004056
4057 int tag_decl_kind = -1;
4058 AccessType default_accessibility = eAccessNone;
4059 if (tag == DW_TAG_structure_type)
4060 {
4061 tag_decl_kind = clang::TTK_Struct;
4062 default_accessibility = eAccessPublic;
4063 }
4064 else if (tag == DW_TAG_union_type)
4065 {
4066 tag_decl_kind = clang::TTK_Union;
4067 default_accessibility = eAccessPublic;
4068 }
4069 else if (tag == DW_TAG_class_type)
4070 {
4071 tag_decl_kind = clang::TTK_Class;
4072 default_accessibility = eAccessPrivate;
4073 }
4074
4075
4076 if (is_forward_declaration)
4077 {
4078 // We have a forward declaration to a type and we need
4079 // to try and find a full declaration. We look in the
4080 // current type index just in case we have a forward
4081 // declaration followed by an actual declarations in the
4082 // DWARF. If this fails, we need to look elsewhere...
4083
4084 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4085
4086 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004087 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004088 // We weren't able to find a full declaration in
4089 // this DWARF, see if we have a declaration anywhere
4090 // else...
4091 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004092 }
4093
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004094 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004095 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004096 // We found a real definition for this type elsewhere
4097 // so lets use it and cache the fact that we found
4098 // a complete type for this die
4099 m_die_to_type[die] = type_sp.get();
4100 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004101 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004102 }
4103 assert (tag_decl_kind != -1);
4104 bool clang_type_was_created = false;
4105 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4106 if (clang_type == NULL)
4107 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004108 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton55561e92011-10-26 03:31:36 +00004109 if (accessibility == eAccessNone && decl_ctx)
4110 {
4111 // Check the decl context that contains this class/struct/union.
4112 // If it is a class we must give it an accessability.
4113 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4114 if (DeclKindIsCXXClass (containing_decl_kind))
4115 accessibility = default_accessibility;
4116 }
4117
Greg Claytonf0705c82011-10-22 03:33:13 +00004118 if (type_name_cstr && strchr (type_name_cstr, '<'))
4119 {
4120 ClangASTContext::TemplateParameterInfos template_param_infos;
4121 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4122 {
4123 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004124 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004125 type_name_cstr,
4126 tag_decl_kind,
4127 template_param_infos);
4128
4129 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4130 class_template_decl,
4131 tag_decl_kind,
4132 template_param_infos);
4133 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4134 clang_type_was_created = true;
4135 }
4136 }
4137
4138 if (!clang_type_was_created)
4139 {
4140 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004141 clang_type = ast.CreateRecordType (decl_ctx,
4142 accessibility,
4143 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004144 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004145 class_language);
4146 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004147 }
4148
4149 // Store a forward declaration to this class type in case any
4150 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004151 // types for function prototypes.
4152 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004153 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004154 this,
4155 type_name_const_str,
4156 byte_size,
4157 NULL,
4158 LLDB_INVALID_UID,
4159 Type::eEncodingIsUID,
4160 &decl,
4161 clang_type,
4162 Type::eResolveStateForward));
4163
4164
4165 // Add our type to the unique type map so we don't
4166 // end up creating many copies of the same type over
4167 // and over in the ASTContext for our module
4168 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004169 unique_ast_entry.m_symfile = this;
4170 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004171 unique_ast_entry.m_die = die;
4172 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00004173 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4174 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004175
4176 if (die->HasChildren() == false && is_forward_declaration == false)
4177 {
4178 // No children for this struct/union/class, lets finish it
4179 ast.StartTagDeclarationDefinition (clang_type);
4180 ast.CompleteTagDeclarationDefinition (clang_type);
4181 }
4182 else if (clang_type_was_created)
4183 {
4184 // Leave this as a forward declaration until we need
4185 // to know the details of the type. lldb_private::Type
4186 // will automatically call the SymbolFile virtual function
4187 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
4188 // When the definition needs to be defined.
4189 m_forward_decl_die_to_clang_type[die] = clang_type;
4190 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
4191 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00004192 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004193 }
4194 break;
4195
4196 case DW_TAG_enumeration_type:
4197 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004198 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004199 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004200
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004201 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004202
Greg Claytond88d7592010-09-15 08:33:30 +00004203 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204 if (num_attributes > 0)
4205 {
4206 uint32_t i;
4207
4208 for (i=0; i<num_attributes; ++i)
4209 {
4210 attr = attributes.AttributeAtIndex(i);
4211 DWARFFormValue form_value;
4212 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4213 {
4214 switch (attr)
4215 {
Greg Clayton7a345282010-11-09 23:46:37 +00004216 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4217 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4218 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004219 case DW_AT_name:
4220 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004221 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 break;
Greg Clayton7a345282010-11-09 23:46:37 +00004223 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004224 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00004225 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4226 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004227 case DW_AT_allocated:
4228 case DW_AT_associated:
4229 case DW_AT_bit_stride:
4230 case DW_AT_byte_stride:
4231 case DW_AT_data_location:
4232 case DW_AT_description:
4233 case DW_AT_start_scope:
4234 case DW_AT_visibility:
4235 case DW_AT_specification:
4236 case DW_AT_abstract_origin:
4237 case DW_AT_sibling:
4238 break;
4239 }
4240 }
4241 }
4242
Greg Clayton81c22f62011-10-19 18:09:39 +00004243 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 +00004244
Greg Clayton1be10fc2010-09-29 01:12:09 +00004245 clang_type_t enumerator_clang_type = NULL;
4246 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4247 if (clang_type == NULL)
4248 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004249 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
4250 DW_ATE_signed,
4251 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00004252 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00004253 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00004254 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004255 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004256 }
4257 else
4258 {
4259 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
4260 assert (enumerator_clang_type != NULL);
4261 }
4262
Greg Claytona2721472011-06-25 00:44:06 +00004263 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
4264
Greg Clayton81c22f62011-10-19 18:09:39 +00004265 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004266 this,
4267 type_name_const_str,
4268 byte_size,
4269 NULL,
4270 encoding_uid,
4271 Type::eEncodingIsUID,
4272 &decl,
4273 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004274 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275
Greg Clayton6beaaa62011-01-17 03:46:26 +00004276 ast.StartTagDeclarationDefinition (clang_type);
4277 if (die->HasChildren())
4278 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004279 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
4280 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00004281 }
4282 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004283 }
4284 }
4285 break;
4286
Jim Inghamb0be4422010-08-12 01:20:14 +00004287 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004288 case DW_TAG_subprogram:
4289 case DW_TAG_subroutine_type:
4290 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004291 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004292 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004293
4294 const char *mangled = NULL;
4295 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004296 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004297 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00004298 bool is_static = false;
4299 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00004300 bool is_explicit = false;
Greg Clayton72da3972011-08-16 18:40:23 +00004301 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
4302 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00004303
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004304 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00004305 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004306
4307
Greg Claytond88d7592010-09-15 08:33:30 +00004308 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004309 if (num_attributes > 0)
4310 {
4311 uint32_t i;
4312 for (i=0; i<num_attributes; ++i)
4313 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004314 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004315 DWARFFormValue form_value;
4316 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4317 {
4318 switch (attr)
4319 {
4320 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4321 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4322 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4323 case DW_AT_name:
4324 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004325 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004326 break;
4327
4328 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
4329 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004330 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00004331 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004332 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
4333 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00004334 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
4335
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004336 case DW_AT_external:
4337 if (form_value.Unsigned())
4338 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00004339 if (storage == clang::SC_None)
4340 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004341 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00004342 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004343 }
4344 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004345
Greg Clayton72da3972011-08-16 18:40:23 +00004346 case DW_AT_specification:
4347 specification_die_offset = form_value.Reference(dwarf_cu);
4348 break;
4349
4350 case DW_AT_abstract_origin:
4351 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
4352 break;
4353
4354
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004355 case DW_AT_allocated:
4356 case DW_AT_associated:
4357 case DW_AT_address_class:
4358 case DW_AT_artificial:
4359 case DW_AT_calling_convention:
4360 case DW_AT_data_location:
4361 case DW_AT_elemental:
4362 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004363 case DW_AT_frame_base:
4364 case DW_AT_high_pc:
4365 case DW_AT_low_pc:
4366 case DW_AT_object_pointer:
4367 case DW_AT_prototyped:
4368 case DW_AT_pure:
4369 case DW_AT_ranges:
4370 case DW_AT_recursive:
4371 case DW_AT_return_addr:
4372 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004373 case DW_AT_start_scope:
4374 case DW_AT_static_link:
4375 case DW_AT_trampoline:
4376 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004377 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004378 case DW_AT_description:
4379 case DW_AT_sibling:
4380 break;
4381 }
4382 }
4383 }
Greg Clayton24739922010-10-13 03:15:28 +00004384 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004385
Greg Clayton81c22f62011-10-19 18:09:39 +00004386 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 +00004387
Greg Clayton24739922010-10-13 03:15:28 +00004388 clang_type_t return_clang_type = NULL;
4389 Type *func_type = NULL;
4390
4391 if (type_die_offset != DW_INVALID_OFFSET)
4392 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00004393
Greg Clayton24739922010-10-13 03:15:28 +00004394 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00004395 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00004396 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004397 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004398
Greg Claytonf51de672010-10-01 02:31:07 +00004399
Greg Clayton24739922010-10-13 03:15:28 +00004400 std::vector<clang_type_t> function_param_types;
4401 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004402
Greg Clayton24739922010-10-13 03:15:28 +00004403 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00004404
Greg Claytoncb5860a2011-10-13 23:49:28 +00004405 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
4406 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00004407 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
4408
Greg Claytonf0705c82011-10-22 03:33:13 +00004409 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00004410 // Start off static. This will be set to false in ParseChildParameters(...)
4411 // if we find a "this" paramters as the first parameter
4412 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00004413 is_static = true;
4414
Greg Clayton24739922010-10-13 03:15:28 +00004415 if (die->HasChildren())
4416 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004417 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004418 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00004419 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004420 type_sp,
4421 dwarf_cu,
4422 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00004423 skip_artificial,
4424 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004425 type_list,
4426 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00004427 function_param_decls,
4428 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00004429 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004430
Greg Clayton24739922010-10-13 03:15:28 +00004431 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004432 clang_type = ast.CreateFunctionType (return_clang_type,
4433 &function_param_types[0],
4434 function_param_types.size(),
4435 is_variadic,
4436 type_quals);
4437
Greg Clayton24739922010-10-13 03:15:28 +00004438 if (type_name_cstr)
4439 {
4440 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00004441 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004442 {
Jim Inghamb7f6b2f2011-09-08 22:13:49 +00004443 if (ObjCLanguageRuntime::IsPossibleObjCMethodName (type_name_cstr))
Greg Clayton0fffff52010-09-24 05:15:53 +00004444 {
Greg Clayton24739922010-10-13 03:15:28 +00004445 // We need to find the DW_TAG_class_type or
4446 // DW_TAG_struct_type by name so we can add this
4447 // as a member function of the class.
4448 const char *class_name_start = type_name_cstr + 2;
4449 const char *class_name_end = ::strchr (class_name_start, ' ');
4450 SymbolContext empty_sc;
4451 clang_type_t class_opaque_type = NULL;
4452 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00004453 {
Greg Clayton24739922010-10-13 03:15:28 +00004454 ConstString class_name (class_name_start, class_name_end - class_name_start);
4455 TypeList types;
Sean Callanan213fdb82011-10-13 01:49:10 +00004456 const uint32_t match_count = FindTypes (empty_sc, class_name, NULL, true, UINT32_MAX, types);
Greg Clayton24739922010-10-13 03:15:28 +00004457 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00004458 {
Greg Clayton24739922010-10-13 03:15:28 +00004459 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00004460 {
Greg Clayton24739922010-10-13 03:15:28 +00004461 Type *type = types.GetTypeAtIndex (i).get();
4462 clang_type_t type_clang_forward_type = type->GetClangForwardType();
4463 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00004464 {
Greg Clayton24739922010-10-13 03:15:28 +00004465 class_opaque_type = type_clang_forward_type;
4466 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004467 }
4468 }
4469 }
Greg Clayton24739922010-10-13 03:15:28 +00004470 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004471
Greg Clayton24739922010-10-13 03:15:28 +00004472 if (class_opaque_type)
4473 {
4474 // If accessibility isn't set to anything valid, assume public for
4475 // now...
4476 if (accessibility == eAccessNone)
4477 accessibility = eAccessPublic;
4478
4479 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004480 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
4481 type_name_cstr,
4482 clang_type,
4483 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004484 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00004485 type_handled = objc_method_decl != NULL;
4486 }
4487 }
Greg Clayton5113dc82011-08-12 06:47:54 +00004488 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00004489 {
4490 // Look at the parent of this DIE and see if is is
4491 // a class or struct and see if this is actually a
4492 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00004493 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00004494 if (class_type)
4495 {
Greg Clayton72da3972011-08-16 18:40:23 +00004496 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00004497 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004498 // We have a specification which we are going to base our function
4499 // prototype off of, so we need this type to be completed so that the
4500 // m_die_to_decl_ctx for the method in the specification has a valid
4501 // clang decl context.
4502 class_type->GetClangFullType();
Greg Clayton72da3972011-08-16 18:40:23 +00004503 // If we have a specification, then the function type should have been
4504 // made with the specification and not with this die.
4505 DWARFCompileUnitSP spec_cu_sp;
4506 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004507 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
4508 if (spec_clang_decl_ctx)
4509 {
4510 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
4511 }
4512 else
Jim Inghamc1663042011-09-29 22:12:35 +00004513 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004514 ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
4515 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004516 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004517 }
Greg Clayton72da3972011-08-16 18:40:23 +00004518 type_handled = true;
4519 }
4520 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
4521 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004522 // We have a specification which we are going to base our function
4523 // prototype off of, so we need this type to be completed so that the
4524 // m_die_to_decl_ctx for the method in the abstract origin has a valid
4525 // clang decl context.
4526 class_type->GetClangFullType();
4527
Greg Clayton72da3972011-08-16 18:40:23 +00004528 DWARFCompileUnitSP abs_cu_sp;
4529 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004530 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
4531 if (abs_clang_decl_ctx)
4532 {
4533 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
4534 }
4535 else
Jim Inghamc1663042011-09-29 22:12:35 +00004536 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004537 ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
4538 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004539 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004540 }
Greg Clayton72da3972011-08-16 18:40:23 +00004541 type_handled = true;
4542 }
4543 else
4544 {
4545 clang_type_t class_opaque_type = class_type->GetClangForwardType();
4546 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00004547 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004548 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00004549 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004550 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
4551 // in the DWARF for C++ methods... Default to public for now...
4552 if (accessibility == eAccessNone)
4553 accessibility = eAccessPublic;
4554
4555 if (!is_static && !die->HasChildren())
4556 {
4557 // We have a C++ member function with no children (this pointer!)
4558 // and clang will get mad if we try and make a function that isn't
4559 // well formed in the DWARF, so we will just skip it...
4560 type_handled = true;
4561 }
4562 else
4563 {
4564 clang::CXXMethodDecl *cxx_method_decl;
4565 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00004566 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 +00004567 type_name_cstr,
4568 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00004569 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00004570 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
4571 m_obj_file->GetFileSpec().GetFilename().GetCString());
4572
Sean Callananc1b732d2011-11-01 18:07:13 +00004573 const bool is_attr_used = false;
4574
Greg Clayton20568dd2011-10-13 23:13:20 +00004575 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
4576 type_name_cstr,
4577 clang_type,
4578 accessibility,
4579 is_virtual,
4580 is_static,
4581 is_inline,
Sean Callananc1b732d2011-11-01 18:07:13 +00004582 is_explicit,
4583 is_attr_used);
Greg Clayton20568dd2011-10-13 23:13:20 +00004584 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
4585
4586 type_handled = cxx_method_decl != NULL;
4587 }
Greg Clayton72da3972011-08-16 18:40:23 +00004588 }
4589 else
4590 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004591 // We were asked to parse the type for a method in a class, yet the
4592 // class hasn't been asked to complete itself through the
4593 // clang::ExternalASTSource protocol, so we need to just have the
4594 // class complete itself and do things the right way, then our
4595 // DIE should then have an entry in the m_die_to_type map. First
4596 // we need to modify the m_die_to_type so it doesn't think we are
4597 // trying to parse this DIE anymore...
4598 m_die_to_type[die] = NULL;
4599
4600 // Now we get the full type to force our class type to complete itself
4601 // using the clang::ExternalASTSource protocol which will parse all
4602 // base classes and all methods (including the method for this DIE).
4603 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004604
Greg Clayton20568dd2011-10-13 23:13:20 +00004605 // The type for this DIE should have been filled in the function call above
4606 type_ptr = m_die_to_type[die];
4607 if (type_ptr)
4608 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00004609 type_sp = type_ptr;
Greg Clayton20568dd2011-10-13 23:13:20 +00004610 break;
4611 }
Greg Clayton72da3972011-08-16 18:40:23 +00004612 }
Greg Clayton931180e2011-01-27 06:44:37 +00004613 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004614 }
4615 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004616 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004617 }
Greg Clayton24739922010-10-13 03:15:28 +00004618
4619 if (!type_handled)
4620 {
4621 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00004622 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
4623 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004624 clang_type,
4625 storage,
4626 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00004627
4628 // Add the decl to our DIE to decl context map
4629 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00004630 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00004631 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004632 ast.SetFunctionParameters (function_decl,
4633 &function_param_decls.front(),
4634 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00004635 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004636 }
Greg Clayton81c22f62011-10-19 18:09:39 +00004637 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004638 this,
4639 type_name_const_str,
4640 0,
4641 NULL,
4642 LLDB_INVALID_UID,
4643 Type::eEncodingIsUID,
4644 &decl,
4645 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004646 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00004647 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004648 }
4649 break;
4650
4651 case DW_TAG_array_type:
4652 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004653 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004654 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004655
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004656 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004657 int64_t first_index = 0;
4658 uint32_t byte_stride = 0;
4659 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00004660 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004661
4662 if (num_attributes > 0)
4663 {
4664 uint32_t i;
4665 for (i=0; i<num_attributes; ++i)
4666 {
4667 attr = attributes.AttributeAtIndex(i);
4668 DWARFFormValue form_value;
4669 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4670 {
4671 switch (attr)
4672 {
4673 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4674 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4675 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4676 case DW_AT_name:
4677 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004678 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004679 break;
4680
4681 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004682 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004683 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
4684 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004685 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00004686 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004687 case DW_AT_allocated:
4688 case DW_AT_associated:
4689 case DW_AT_data_location:
4690 case DW_AT_description:
4691 case DW_AT_ordering:
4692 case DW_AT_start_scope:
4693 case DW_AT_visibility:
4694 case DW_AT_specification:
4695 case DW_AT_abstract_origin:
4696 case DW_AT_sibling:
4697 break;
4698 }
4699 }
4700 }
4701
Greg Clayton81c22f62011-10-19 18:09:39 +00004702 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 +00004703
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004704 Type *element_type = ResolveTypeUID(type_die_offset);
4705
4706 if (element_type)
4707 {
4708 std::vector<uint64_t> element_orders;
4709 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00004710 // We have an array that claims to have no members, lets give it at least one member...
4711 if (element_orders.empty())
4712 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004713 if (byte_stride == 0 && bit_stride == 0)
4714 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00004715 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004716 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
4717 uint64_t num_elements = 0;
4718 std::vector<uint64_t>::const_reverse_iterator pos;
4719 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
4720 for (pos = element_orders.rbegin(); pos != end; ++pos)
4721 {
4722 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004723 clang_type = ast.CreateArrayType (array_element_type,
4724 num_elements,
4725 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004726 array_element_type = clang_type;
4727 array_element_bit_stride = array_element_bit_stride * num_elements;
4728 }
4729 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00004730 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004731 this,
4732 empty_name,
4733 array_element_bit_stride / 8,
4734 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00004735 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004736 Type::eEncodingIsUID,
4737 &decl,
4738 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004739 Type::eResolveStateFull));
4740 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004741 }
4742 }
4743 }
4744 break;
4745
Greg Clayton9b81a312010-06-12 01:20:30 +00004746 case DW_TAG_ptr_to_member_type:
4747 {
4748 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
4749 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
4750
Greg Claytond88d7592010-09-15 08:33:30 +00004751 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00004752
4753 if (num_attributes > 0) {
4754 uint32_t i;
4755 for (i=0; i<num_attributes; ++i)
4756 {
4757 attr = attributes.AttributeAtIndex(i);
4758 DWARFFormValue form_value;
4759 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4760 {
4761 switch (attr)
4762 {
4763 case DW_AT_type:
4764 type_die_offset = form_value.Reference(dwarf_cu); break;
4765 case DW_AT_containing_type:
4766 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
4767 }
4768 }
4769 }
4770
4771 Type *pointee_type = ResolveTypeUID(type_die_offset);
4772 Type *class_type = ResolveTypeUID(containing_type_die_offset);
4773
Greg Clayton526e5af2010-11-13 03:52:47 +00004774 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
4775 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00004776
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004777 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
4778 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00004779
Greg Clayton526e5af2010-11-13 03:52:47 +00004780 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
4781 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00004782
Greg Clayton81c22f62011-10-19 18:09:39 +00004783 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004784 this,
4785 type_name_const_str,
4786 byte_size,
4787 NULL,
4788 LLDB_INVALID_UID,
4789 Type::eEncodingIsUID,
4790 NULL,
4791 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004792 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00004793 }
4794
4795 break;
4796 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004797 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00004798 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004799 break;
4800 }
4801
4802 if (type_sp.get())
4803 {
4804 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4805 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4806
4807 SymbolContextScope * symbol_context_scope = NULL;
4808 if (sc_parent_tag == DW_TAG_compile_unit)
4809 {
4810 symbol_context_scope = sc.comp_unit;
4811 }
4812 else if (sc.function != NULL)
4813 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004814 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004815 if (symbol_context_scope == NULL)
4816 symbol_context_scope = sc.function;
4817 }
4818
4819 if (symbol_context_scope != NULL)
4820 {
4821 type_sp->SetSymbolContextScope(symbol_context_scope);
4822 }
4823
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004824 // We are ready to put this type into the uniqued list up at the module level
4825 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00004826
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004827 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004828 }
4829 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00004830 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004831 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00004832 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004833 }
4834 }
4835 return type_sp;
4836}
4837
4838size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00004839SymbolFileDWARF::ParseTypes
4840(
4841 const SymbolContext& sc,
4842 DWARFCompileUnit* dwarf_cu,
4843 const DWARFDebugInfoEntry *die,
4844 bool parse_siblings,
4845 bool parse_children
4846)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004847{
4848 size_t types_added = 0;
4849 while (die != NULL)
4850 {
4851 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004852 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004853 {
4854 if (type_is_new)
4855 ++types_added;
4856 }
4857
4858 if (parse_children && die->HasChildren())
4859 {
4860 if (die->Tag() == DW_TAG_subprogram)
4861 {
4862 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00004863 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004864 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4865 }
4866 else
4867 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4868 }
4869
4870 if (parse_siblings)
4871 die = die->GetSibling();
4872 else
4873 die = NULL;
4874 }
4875 return types_added;
4876}
4877
4878
4879size_t
4880SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4881{
4882 assert(sc.comp_unit && sc.function);
4883 size_t functions_added = 0;
4884 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4885 if (dwarf_cu)
4886 {
4887 dw_offset_t function_die_offset = sc.function->GetID();
4888 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4889 if (function_die)
4890 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004891 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004892 }
4893 }
4894
4895 return functions_added;
4896}
4897
4898
4899size_t
4900SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4901{
4902 // At least a compile unit must be valid
4903 assert(sc.comp_unit);
4904 size_t types_added = 0;
4905 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4906 if (dwarf_cu)
4907 {
4908 if (sc.function)
4909 {
4910 dw_offset_t function_die_offset = sc.function->GetID();
4911 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4912 if (func_die && func_die->HasChildren())
4913 {
4914 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4915 }
4916 }
4917 else
4918 {
4919 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4920 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4921 {
4922 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4923 }
4924 }
4925 }
4926
4927 return types_added;
4928}
4929
4930size_t
4931SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4932{
4933 if (sc.comp_unit != NULL)
4934 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004935 DWARFDebugInfo* info = DebugInfo();
4936 if (info == NULL)
4937 return 0;
4938
4939 uint32_t cu_idx = UINT32_MAX;
4940 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004941
4942 if (dwarf_cu == NULL)
4943 return 0;
4944
4945 if (sc.function)
4946 {
4947 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004948
4949 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4950 assert (func_lo_pc != DW_INVALID_ADDRESS);
4951
Greg Claytonc662ec82011-06-17 22:10:16 +00004952 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4953
4954 // Let all blocks know they have parse all their variables
4955 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4956
4957 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004958 }
4959 else if (sc.comp_unit)
4960 {
4961 uint32_t vars_added = 0;
4962 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4963
4964 if (variables.get() == NULL)
4965 {
4966 variables.reset(new VariableList());
4967 sc.comp_unit->SetVariableList(variables);
4968
Greg Claytond4a2b372011-09-12 23:21:58 +00004969 DWARFCompileUnit* match_dwarf_cu = NULL;
4970 const DWARFDebugInfoEntry* die = NULL;
4971 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00004972 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004973 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004974 if (m_apple_names_ap.get())
4975 m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
4976 dwarf_cu->GetNextCompileUnitOffset(),
4977 die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00004978 }
4979 else
4980 {
4981 // Index if we already haven't to make sure the compile units
4982 // get indexed and make their global DIE index list
4983 if (!m_indexed)
4984 Index ();
4985
4986 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
4987 dwarf_cu->GetNextCompileUnitOffset(),
4988 die_offsets);
4989 }
4990
4991 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004992 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004993 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004994 DWARFDebugInfo* debug_info = DebugInfo();
4995 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004996 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004997 const dw_offset_t die_offset = die_offsets[i];
4998 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
4999 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5000 if (var_sp)
5001 {
5002 variables->AddVariableIfUnique (var_sp);
5003 ++vars_added;
5004 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005005 }
5006 }
5007 }
5008 return vars_added;
5009 }
5010 }
5011 return 0;
5012}
5013
5014
5015VariableSP
5016SymbolFileDWARF::ParseVariableDIE
5017(
5018 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005019 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005020 const DWARFDebugInfoEntry *die,
5021 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005022)
5023{
5024
Greg Clayton83c5cd92010-11-14 22:13:40 +00005025 VariableSP var_sp (m_die_to_variable_sp[die]);
5026 if (var_sp)
5027 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005028
5029 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00005030
5031 if ((tag == DW_TAG_variable) ||
5032 (tag == DW_TAG_constant) ||
5033 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005034 {
Greg Clayton7f995132011-10-04 22:41:51 +00005035 DWARFDebugInfoEntry::Attributes attributes;
5036 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5037 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005038 {
Greg Clayton7f995132011-10-04 22:41:51 +00005039 const char *name = NULL;
5040 const char *mangled = NULL;
5041 Declaration decl;
5042 uint32_t i;
5043 Type *var_type = NULL;
5044 DWARFExpression location;
5045 bool is_external = false;
5046 bool is_artificial = false;
5047 bool location_is_const_value_data = false;
5048 AccessType accessibility = eAccessNone;
5049
5050 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005051 {
Greg Clayton7f995132011-10-04 22:41:51 +00005052 dw_attr_t attr = attributes.AttributeAtIndex(i);
5053 DWARFFormValue form_value;
5054 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005055 {
Greg Clayton7f995132011-10-04 22:41:51 +00005056 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005057 {
Greg Clayton7f995132011-10-04 22:41:51 +00005058 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5059 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5060 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5061 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
5062 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
5063 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
5064 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5065 case DW_AT_const_value:
5066 location_is_const_value_data = true;
5067 // Fall through...
5068 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005069 {
Greg Clayton7f995132011-10-04 22:41:51 +00005070 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005071 {
Greg Clayton7f995132011-10-04 22:41:51 +00005072 const DataExtractor& debug_info_data = get_debug_info_data();
5073
5074 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5075 uint32_t block_length = form_value.Unsigned();
5076 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5077 }
5078 else
5079 {
5080 const DataExtractor& debug_loc_data = get_debug_loc_data();
5081 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5082
5083 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5084 if (loc_list_length > 0)
5085 {
5086 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5087 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5088 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5089 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005090 }
5091 }
Greg Clayton7f995132011-10-04 22:41:51 +00005092 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005093
Greg Clayton7f995132011-10-04 22:41:51 +00005094 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5095 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5096 case DW_AT_declaration:
5097 case DW_AT_description:
5098 case DW_AT_endianity:
5099 case DW_AT_segment:
5100 case DW_AT_start_scope:
5101 case DW_AT_visibility:
5102 default:
5103 case DW_AT_abstract_origin:
5104 case DW_AT_sibling:
5105 case DW_AT_specification:
5106 break;
5107 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005108 }
5109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005110
Greg Clayton7f995132011-10-04 22:41:51 +00005111 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005112 {
Greg Clayton7f995132011-10-04 22:41:51 +00005113 assert(var_type != DIE_IS_BEING_PARSED);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005114
Greg Clayton7f995132011-10-04 22:41:51 +00005115 ValueType scope = eValueTypeInvalid;
5116
5117 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5118 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5119
5120 if (tag == DW_TAG_formal_parameter)
5121 scope = eValueTypeVariableArgument;
5122 else if (is_external || parent_tag == DW_TAG_compile_unit)
5123 scope = eValueTypeVariableGlobal;
5124 else
5125 scope = eValueTypeVariableLocal;
5126
5127 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005128 switch (parent_tag)
Greg Clayton7f995132011-10-04 22:41:51 +00005129 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005130 case DW_TAG_subprogram:
5131 case DW_TAG_inlined_subroutine:
5132 case DW_TAG_lexical_block:
5133 if (sc.function)
5134 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005135 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Clayton5cf58b92011-10-05 22:22:08 +00005136 if (symbol_context_scope == NULL)
5137 symbol_context_scope = sc.function;
5138 }
5139 break;
5140
5141 default:
Greg Clayton7f995132011-10-04 22:41:51 +00005142 symbol_context_scope = sc.comp_unit;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005143 break;
Greg Clayton7f995132011-10-04 22:41:51 +00005144 }
5145
Greg Clayton5cf58b92011-10-05 22:22:08 +00005146 if (symbol_context_scope)
5147 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005148 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
5149 name,
5150 mangled,
5151 var_type,
5152 scope,
5153 symbol_context_scope,
5154 &decl,
5155 location,
5156 is_external,
5157 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00005158
5159 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
5160 }
5161 else
5162 {
5163 // Not ready to parse this variable yet. It might be a global
5164 // or static variable that is in a function scope and the function
5165 // in the symbol context wasn't filled in yet
5166 return var_sp;
5167 }
Greg Clayton7f995132011-10-04 22:41:51 +00005168 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005169 }
Greg Clayton7f995132011-10-04 22:41:51 +00005170 // Cache var_sp even if NULL (the variable was just a specification or
5171 // was missing vital information to be able to be displayed in the debugger
5172 // (missing location due to optimization, etc)) so we don't re-parse
5173 // this DIE over and over later...
5174 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005175 }
5176 return var_sp;
5177}
5178
Greg Claytonc662ec82011-06-17 22:10:16 +00005179
5180const DWARFDebugInfoEntry *
5181SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
5182 dw_offset_t spec_block_die_offset,
5183 DWARFCompileUnit **result_die_cu_handle)
5184{
5185 // Give the concrete function die specified by "func_die_offset", find the
5186 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5187 // to "spec_block_die_offset"
5188 DWARFDebugInfo* info = DebugInfo();
5189
5190 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
5191 if (die)
5192 {
5193 assert (*result_die_cu_handle);
5194 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
5195 }
5196 return NULL;
5197}
5198
5199
5200const DWARFDebugInfoEntry *
5201SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
5202 const DWARFDebugInfoEntry *die,
5203 dw_offset_t spec_block_die_offset,
5204 DWARFCompileUnit **result_die_cu_handle)
5205{
5206 if (die)
5207 {
5208 switch (die->Tag())
5209 {
5210 case DW_TAG_subprogram:
5211 case DW_TAG_inlined_subroutine:
5212 case DW_TAG_lexical_block:
5213 {
5214 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
5215 {
5216 *result_die_cu_handle = dwarf_cu;
5217 return die;
5218 }
5219
5220 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
5221 {
5222 *result_die_cu_handle = dwarf_cu;
5223 return die;
5224 }
5225 }
5226 break;
5227 }
5228
5229 // Give the concrete function die specified by "func_die_offset", find the
5230 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5231 // to "spec_block_die_offset"
5232 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
5233 {
5234 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
5235 child_die,
5236 spec_block_die_offset,
5237 result_die_cu_handle);
5238 if (result_die)
5239 return result_die;
5240 }
5241 }
5242
5243 *result_die_cu_handle = NULL;
5244 return NULL;
5245}
5246
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005247size_t
5248SymbolFileDWARF::ParseVariables
5249(
5250 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005251 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005252 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005253 const DWARFDebugInfoEntry *orig_die,
5254 bool parse_siblings,
5255 bool parse_children,
5256 VariableList* cc_variable_list
5257)
5258{
5259 if (orig_die == NULL)
5260 return 0;
5261
Greg Claytonc662ec82011-06-17 22:10:16 +00005262 VariableListSP variable_list_sp;
5263
5264 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005265 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00005266 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005267 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005268 dw_tag_t tag = die->Tag();
5269
5270 // Check to see if we have already parsed this variable or constant?
5271 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005272 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005273 if (cc_variable_list)
5274 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005275 }
5276 else
5277 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005278 // We haven't already parsed it, lets do that now.
5279 if ((tag == DW_TAG_variable) ||
5280 (tag == DW_TAG_constant) ||
5281 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005282 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005283 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00005284 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005285 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
5286 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5287 switch (parent_tag)
5288 {
5289 case DW_TAG_compile_unit:
5290 if (sc.comp_unit != NULL)
5291 {
5292 variable_list_sp = sc.comp_unit->GetVariableList(false);
5293 if (variable_list_sp.get() == NULL)
5294 {
5295 variable_list_sp.reset(new VariableList());
5296 sc.comp_unit->SetVariableList(variable_list_sp);
5297 }
5298 }
5299 else
5300 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005301 ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
5302 MakeUserID(sc_parent_die->GetOffset()),
5303 DW_TAG_value_to_name (parent_tag),
5304 MakeUserID(orig_die->GetOffset()),
5305 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005306 }
5307 break;
5308
5309 case DW_TAG_subprogram:
5310 case DW_TAG_inlined_subroutine:
5311 case DW_TAG_lexical_block:
5312 if (sc.function != NULL)
5313 {
5314 // Check to see if we already have parsed the variables for the given scope
5315
Greg Clayton81c22f62011-10-19 18:09:39 +00005316 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005317 if (block == NULL)
5318 {
5319 // This must be a specification or abstract origin with
5320 // a concrete block couterpart in the current function. We need
5321 // to find the concrete block so we can correctly add the
5322 // variable to it
5323 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
5324 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
5325 sc_parent_die->GetOffset(),
5326 &concrete_block_die_cu);
5327 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00005328 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005329 }
5330
5331 if (block != NULL)
5332 {
5333 const bool can_create = false;
5334 variable_list_sp = block->GetBlockVariableList (can_create);
5335 if (variable_list_sp.get() == NULL)
5336 {
5337 variable_list_sp.reset(new VariableList());
5338 block->SetVariableList(variable_list_sp);
5339 }
5340 }
5341 }
5342 break;
5343
5344 default:
Greg Clayton81c22f62011-10-19 18:09:39 +00005345 ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
5346 MakeUserID(orig_die->GetOffset()),
5347 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005348 break;
5349 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00005350 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005351
5352 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005353 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00005354 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
5355 if (var_sp)
5356 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005357 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00005358 if (cc_variable_list)
5359 cc_variable_list->AddVariableIfUnique (var_sp);
5360 ++vars_added;
5361 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005362 }
5363 }
5364 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005365
5366 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
5367
5368 if (!skip_children && parse_children && die->HasChildren())
5369 {
5370 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
5371 }
5372
5373 if (parse_siblings)
5374 die = die->GetSibling();
5375 else
5376 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005377 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005378 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005379}
5380
5381//------------------------------------------------------------------
5382// PluginInterface protocol
5383//------------------------------------------------------------------
5384const char *
5385SymbolFileDWARF::GetPluginName()
5386{
5387 return "SymbolFileDWARF";
5388}
5389
5390const char *
5391SymbolFileDWARF::GetShortPluginName()
5392{
5393 return GetPluginNameStatic();
5394}
5395
5396uint32_t
5397SymbolFileDWARF::GetPluginVersion()
5398{
5399 return 1;
5400}
5401
5402void
Greg Clayton6beaaa62011-01-17 03:46:26 +00005403SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
5404{
5405 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5406 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5407 if (clang_type)
5408 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5409}
5410
5411void
5412SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
5413{
5414 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5415 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5416 if (clang_type)
5417 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5418}
5419
Greg Claytona2721472011-06-25 00:44:06 +00005420void
Sean Callanancc427fa2011-07-30 02:42:06 +00005421SymbolFileDWARF::DumpIndexes ()
5422{
5423 StreamFile s(stdout, false);
5424
5425 s.Printf ("DWARF index for (%s) '%s/%s':",
5426 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
5427 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
5428 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
5429 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
5430 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
5431 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
5432 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
5433 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
5434 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
5435 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
5436 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
5437}
5438
5439void
5440SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
5441 const char *name,
5442 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00005443{
Sean Callanancc427fa2011-07-30 02:42:06 +00005444 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00005445
5446 if (iter == m_decl_ctx_to_die.end())
5447 return;
5448
Greg Claytoncb5860a2011-10-13 23:49:28 +00005449 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00005450 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005451 const DWARFDebugInfoEntry *context_die = *pos;
5452
5453 if (!results)
5454 return;
5455
5456 DWARFDebugInfo* info = DebugInfo();
5457
5458 DIEArray die_offsets;
5459
5460 DWARFCompileUnit* dwarf_cu = NULL;
5461 const DWARFDebugInfoEntry* die = NULL;
5462 size_t num_matches = m_type_index.Find (ConstString(name), die_offsets);
5463
5464 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00005465 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005466 for (size_t i = 0; i < num_matches; ++i)
5467 {
5468 const dw_offset_t die_offset = die_offsets[i];
5469 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00005470
Greg Claytoncb5860a2011-10-13 23:49:28 +00005471 if (die->GetParent() != context_die)
5472 continue;
5473
5474 Type *matching_type = ResolveType (dwarf_cu, die);
5475
5476 lldb::clang_type_t type = matching_type->GetClangFullType();
5477 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
5478
5479 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
5480 {
5481 clang::TagDecl *tag_decl = tag_type->getDecl();
5482 results->push_back(tag_decl);
5483 }
5484 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
5485 {
5486 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
5487 results->push_back(typedef_decl);
5488 }
Greg Claytona2721472011-06-25 00:44:06 +00005489 }
5490 }
5491 }
5492}
5493
5494void
5495SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00005496 const clang::DeclContext *decl_context,
5497 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00005498 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
5499{
Greg Clayton85ae2e12011-10-18 23:36:41 +00005500
5501 switch (decl_context->getDeclKind())
5502 {
5503 case clang::Decl::Namespace:
5504 case clang::Decl::TranslationUnit:
5505 {
5506 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5507 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
5508 }
5509 break;
5510 default:
5511 break;
5512 }
Greg Claytona2721472011-06-25 00:44:06 +00005513}