blob: c4705960facbbc5e2958d497daadd48d6e0a5d7e [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
25#include "lldb/Core/Module.h"
26#include "lldb/Core/PluginManager.h"
27#include "lldb/Core/RegularExpression.h"
28#include "lldb/Core/Scalar.h"
29#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000030#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/Timer.h"
32#include "lldb/Core/Value.h"
33
34#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000035#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Symbol/CompileUnit.h"
37#include "lldb/Symbol/LineTable.h"
38#include "lldb/Symbol/ObjectFile.h"
39#include "lldb/Symbol/SymbolVendor.h"
40#include "lldb/Symbol/VariableList.h"
41
42#include "DWARFCompileUnit.h"
43#include "DWARFDebugAbbrev.h"
44#include "DWARFDebugAranges.h"
45#include "DWARFDebugInfo.h"
46#include "DWARFDebugInfoEntry.h"
47#include "DWARFDebugLine.h"
48#include "DWARFDebugPubnames.h"
49#include "DWARFDebugRanges.h"
50#include "DWARFDIECollection.h"
51#include "DWARFFormValue.h"
52#include "DWARFLocationList.h"
53#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000054#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
56#include <map>
57
Greg Clayton62742b12010-11-11 01:09:45 +000058//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000059
60#ifdef ENABLE_DEBUG_PRINTF
61#include <stdio.h>
62#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
63#else
64#define DEBUG_PRINTF(fmt, ...)
65#endif
66
Greg Clayton594e5ed2010-09-27 21:07:38 +000067#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
69using namespace lldb;
70using namespace lldb_private;
71
72
Sean Callananc7fbf732010-08-06 00:32:49 +000073static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000074DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075{
76 switch (dwarf_accessibility)
77 {
Sean Callananc7fbf732010-08-06 00:32:49 +000078 case DW_ACCESS_public: return eAccessPublic;
79 case DW_ACCESS_private: return eAccessPrivate;
80 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000081 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 }
Sean Callananc7fbf732010-08-06 00:32:49 +000083 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084}
85
86void
87SymbolFileDWARF::Initialize()
88{
89 LogChannelDWARF::Initialize();
90 PluginManager::RegisterPlugin (GetPluginNameStatic(),
91 GetPluginDescriptionStatic(),
92 CreateInstance);
93}
94
95void
96SymbolFileDWARF::Terminate()
97{
98 PluginManager::UnregisterPlugin (CreateInstance);
99 LogChannelDWARF::Initialize();
100}
101
102
103const char *
104SymbolFileDWARF::GetPluginNameStatic()
105{
106 return "symbol-file.dwarf2";
107}
108
109const char *
110SymbolFileDWARF::GetPluginDescriptionStatic()
111{
112 return "DWARF and DWARF3 debug symbol file reader.";
113}
114
115
116SymbolFile*
117SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
118{
119 return new SymbolFileDWARF(obj_file);
120}
121
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000122TypeList *
123SymbolFileDWARF::GetTypeList ()
124{
125 if (m_debug_map_symfile)
126 return m_debug_map_symfile->GetTypeList();
127 return m_obj_file->GetModule()->GetTypeList();
128
129}
130
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131//----------------------------------------------------------------------
132// Gets the first parent that is a lexical block, function or inlined
133// subroutine, or compile unit.
134//----------------------------------------------------------------------
135static const DWARFDebugInfoEntry *
136GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
137{
138 const DWARFDebugInfoEntry *die;
139 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
140 {
141 dw_tag_t tag = die->Tag();
142
143 switch (tag)
144 {
145 case DW_TAG_compile_unit:
146 case DW_TAG_subprogram:
147 case DW_TAG_inlined_subroutine:
148 case DW_TAG_lexical_block:
149 return die;
150 }
151 }
152 return NULL;
153}
154
155
Greg Clayton450e3f32010-10-12 02:24:53 +0000156SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
157 SymbolFile (objfile),
158 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000159 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160 m_flags(),
161 m_data_debug_abbrev(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 m_data_debug_frame(),
163 m_data_debug_info(),
164 m_data_debug_line(),
165 m_data_debug_loc(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166 m_data_debug_ranges(),
167 m_data_debug_str(),
168 m_abbr(),
169 m_aranges(),
170 m_info(),
171 m_line(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000172 m_function_basename_index(),
173 m_function_fullname_index(),
174 m_function_method_index(),
175 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000176 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000177 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000178 m_type_index(),
179 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000180 m_indexed (false),
181 m_is_external_ast_source (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000182 m_ranges(),
183 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184{
185}
186
187SymbolFileDWARF::~SymbolFileDWARF()
188{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000189 if (m_is_external_ast_source)
190 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
191}
192
193static const ConstString &
194GetDWARFMachOSegmentName ()
195{
196 static ConstString g_dwarf_section_name ("__DWARF");
197 return g_dwarf_section_name;
198}
199
Greg Claytone576ab22011-02-15 00:19:15 +0000200UniqueDWARFASTTypeMap &
201SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
202{
203 if (m_debug_map_symfile)
204 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
205 return m_unique_ast_type_map;
206}
207
Greg Clayton6beaaa62011-01-17 03:46:26 +0000208ClangASTContext &
209SymbolFileDWARF::GetClangASTContext ()
210{
211 if (m_debug_map_symfile)
212 return m_debug_map_symfile->GetClangASTContext ();
213
214 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
215 if (!m_is_external_ast_source)
216 {
217 m_is_external_ast_source = true;
218 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
219 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
220 SymbolFileDWARF::CompleteObjCInterfaceDecl,
221 this));
222
223 ast.SetExternalSource (ast_source_ap);
224 }
225 return ast;
226}
227
228void
229SymbolFileDWARF::InitializeObject()
230{
231 // Install our external AST source callbacks so we can complete Clang types.
232 Module *module = m_obj_file->GetModule();
233 if (module)
234 {
235 const SectionList *section_list = m_obj_file->GetSectionList();
236
237 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
238
239 // Memory map the DWARF mach-o segment so we have everything mmap'ed
240 // to keep our heap memory usage down.
241 if (section)
242 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
243 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244}
245
246bool
247SymbolFileDWARF::SupportedVersion(uint16_t version)
248{
249 return version == 2 || version == 3;
250}
251
252uint32_t
253SymbolFileDWARF::GetAbilities ()
254{
255 uint32_t abilities = 0;
256 if (m_obj_file != NULL)
257 {
258 const Section* section = NULL;
259 const SectionList *section_list = m_obj_file->GetSectionList();
260 if (section_list == NULL)
261 return 0;
262
263 uint64_t debug_abbrev_file_size = 0;
264 uint64_t debug_aranges_file_size = 0;
265 uint64_t debug_frame_file_size = 0;
266 uint64_t debug_info_file_size = 0;
267 uint64_t debug_line_file_size = 0;
268 uint64_t debug_loc_file_size = 0;
269 uint64_t debug_macinfo_file_size = 0;
270 uint64_t debug_pubnames_file_size = 0;
271 uint64_t debug_pubtypes_file_size = 0;
272 uint64_t debug_ranges_file_size = 0;
273 uint64_t debug_str_file_size = 0;
274
Greg Clayton6beaaa62011-01-17 03:46:26 +0000275 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276
277 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000278 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279
Greg Clayton4ceb9982010-07-21 22:54:26 +0000280 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281 if (section != NULL)
282 {
283 debug_info_file_size = section->GetByteSize();
284
Greg Clayton4ceb9982010-07-21 22:54:26 +0000285 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286 if (section)
287 debug_abbrev_file_size = section->GetByteSize();
288 else
289 m_flags.Set (flagsGotDebugAbbrevData);
290
Greg Clayton4ceb9982010-07-21 22:54:26 +0000291 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292 if (section)
293 debug_aranges_file_size = section->GetByteSize();
294 else
295 m_flags.Set (flagsGotDebugArangesData);
296
Greg Clayton4ceb9982010-07-21 22:54:26 +0000297 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 if (section)
299 debug_frame_file_size = section->GetByteSize();
300 else
301 m_flags.Set (flagsGotDebugFrameData);
302
Greg Clayton4ceb9982010-07-21 22:54:26 +0000303 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304 if (section)
305 debug_line_file_size = section->GetByteSize();
306 else
307 m_flags.Set (flagsGotDebugLineData);
308
Greg Clayton4ceb9982010-07-21 22:54:26 +0000309 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 if (section)
311 debug_loc_file_size = section->GetByteSize();
312 else
313 m_flags.Set (flagsGotDebugLocData);
314
Greg Clayton4ceb9982010-07-21 22:54:26 +0000315 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 if (section)
317 debug_macinfo_file_size = section->GetByteSize();
318 else
319 m_flags.Set (flagsGotDebugMacInfoData);
320
Greg Clayton4ceb9982010-07-21 22:54:26 +0000321 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322 if (section)
323 debug_pubnames_file_size = section->GetByteSize();
324 else
325 m_flags.Set (flagsGotDebugPubNamesData);
326
Greg Clayton4ceb9982010-07-21 22:54:26 +0000327 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 if (section)
329 debug_pubtypes_file_size = section->GetByteSize();
330 else
331 m_flags.Set (flagsGotDebugPubTypesData);
332
Greg Clayton4ceb9982010-07-21 22:54:26 +0000333 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334 if (section)
335 debug_ranges_file_size = section->GetByteSize();
336 else
337 m_flags.Set (flagsGotDebugRangesData);
338
Greg Clayton4ceb9982010-07-21 22:54:26 +0000339 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340 if (section)
341 debug_str_file_size = section->GetByteSize();
342 else
343 m_flags.Set (flagsGotDebugStrData);
344 }
345
346 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
347 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
348
349 if (debug_line_file_size > 0)
350 abilities |= LineTables;
351
352 if (debug_aranges_file_size > 0)
353 abilities |= AddressAcceleratorTable;
354
355 if (debug_pubnames_file_size > 0)
356 abilities |= FunctionAcceleratorTable;
357
358 if (debug_pubtypes_file_size > 0)
359 abilities |= TypeAcceleratorTable;
360
361 if (debug_macinfo_file_size > 0)
362 abilities |= MacroInformation;
363
364 if (debug_frame_file_size > 0)
365 abilities |= CallFrameInformation;
366 }
367 return abilities;
368}
369
370const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000371SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372{
373 if (m_flags.IsClear (got_flag))
374 {
375 m_flags.Set (got_flag);
376 const SectionList *section_list = m_obj_file->GetSectionList();
377 if (section_list)
378 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000379 Section *section = section_list->FindSectionByType(sect_type, true).get();
380 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 {
382 // See if we memory mapped the DWARF segment?
383 if (m_dwarf_data.GetByteSize())
384 {
385 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
386 }
387 else
388 {
389 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
390 data.Clear();
391 }
392 }
393 }
394 }
395 return data;
396}
397
398const DataExtractor&
399SymbolFileDWARF::get_debug_abbrev_data()
400{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000401 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402}
403
404const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405SymbolFileDWARF::get_debug_frame_data()
406{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000407 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408}
409
410const DataExtractor&
411SymbolFileDWARF::get_debug_info_data()
412{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000413 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
416const DataExtractor&
417SymbolFileDWARF::get_debug_line_data()
418{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000419 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420}
421
422const DataExtractor&
423SymbolFileDWARF::get_debug_loc_data()
424{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000425 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426}
427
428const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429SymbolFileDWARF::get_debug_ranges_data()
430{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432}
433
434const DataExtractor&
435SymbolFileDWARF::get_debug_str_data()
436{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000437 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438}
439
440
441DWARFDebugAbbrev*
442SymbolFileDWARF::DebugAbbrev()
443{
444 if (m_abbr.get() == NULL)
445 {
446 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
447 if (debug_abbrev_data.GetByteSize() > 0)
448 {
449 m_abbr.reset(new DWARFDebugAbbrev());
450 if (m_abbr.get())
451 m_abbr->Parse(debug_abbrev_data);
452 }
453 }
454 return m_abbr.get();
455}
456
457const DWARFDebugAbbrev*
458SymbolFileDWARF::DebugAbbrev() const
459{
460 return m_abbr.get();
461}
462
463DWARFDebugAranges*
464SymbolFileDWARF::DebugAranges()
465{
Greg Clayton016a95e2010-09-14 02:20:48 +0000466 // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files
467 // and we are already parsing all of the DWARF because the .debug_pubnames
468 // is useless (it only mentions symbols that are externally visible), so
469 // don't use the .debug_aranges section, we should be using a debug aranges
470 // we got from SymbolFileDWARF::Index().
471
472 if (!m_indexed)
473 Index();
474
475
476// if (m_aranges.get() == NULL)
477// {
478// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
479// m_aranges.reset(new DWARFDebugAranges());
480// if (m_aranges.get())
481// {
482// const DataExtractor &debug_aranges_data = get_debug_aranges_data();
483// if (debug_aranges_data.GetByteSize() > 0)
484// m_aranges->Extract(debug_aranges_data);
485// else
486// m_aranges->Generate(this);
487// }
488// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489 return m_aranges.get();
490}
491
492const DWARFDebugAranges*
493SymbolFileDWARF::DebugAranges() const
494{
495 return m_aranges.get();
496}
497
498
499DWARFDebugInfo*
500SymbolFileDWARF::DebugInfo()
501{
502 if (m_info.get() == NULL)
503 {
504 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
505 if (get_debug_info_data().GetByteSize() > 0)
506 {
507 m_info.reset(new DWARFDebugInfo());
508 if (m_info.get())
509 {
510 m_info->SetDwarfData(this);
511 }
512 }
513 }
514 return m_info.get();
515}
516
517const DWARFDebugInfo*
518SymbolFileDWARF::DebugInfo() const
519{
520 return m_info.get();
521}
522
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523DWARFCompileUnit*
524SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
525{
526 DWARFDebugInfo* info = DebugInfo();
527 if (info)
528 return info->GetCompileUnit(cu_uid).get();
529 return NULL;
530}
531
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532
533DWARFDebugRanges*
534SymbolFileDWARF::DebugRanges()
535{
536 if (m_ranges.get() == NULL)
537 {
538 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
539 if (get_debug_ranges_data().GetByteSize() > 0)
540 {
541 m_ranges.reset(new DWARFDebugRanges());
542 if (m_ranges.get())
543 m_ranges->Extract(this);
544 }
545 }
546 return m_ranges.get();
547}
548
549const DWARFDebugRanges*
550SymbolFileDWARF::DebugRanges() const
551{
552 return m_ranges.get();
553}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554
555bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000556SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557{
Greg Clayton96d7d742010-11-10 23:42:09 +0000558 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000560 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 if (cu_die)
562 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000563 const char * cu_die_name = cu_die->GetName(this, curr_cu);
564 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
565 LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566 if (cu_die_name)
567 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000568 FileSpec cu_file_spec;
569
Greg Clayton7bd65b92011-02-09 23:39:34 +0000570 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000572 // If we have a full path to the compile unit, we don't need to resolve
573 // the file. This can be expensive e.g. when the source files are NFS mounted.
574 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 }
576 else
577 {
578 std::string fullpath(cu_comp_dir);
579 if (*fullpath.rbegin() != '/')
580 fullpath += '/';
581 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000582 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 }
584
Greg Clayton96d7d742010-11-10 23:42:09 +0000585 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), curr_cu, cu_file_spec, curr_cu->GetOffset(), class_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 if (compile_unit_sp.get())
587 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000588 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589 return true;
590 }
591 }
592 }
593 }
594 return false;
595}
596
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000597uint32_t
598SymbolFileDWARF::GetNumCompileUnits()
599{
600 DWARFDebugInfo* info = DebugInfo();
601 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 return 0;
604}
605
606CompUnitSP
607SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
608{
609 CompUnitSP comp_unit;
610 DWARFDebugInfo* info = DebugInfo();
611 if (info)
612 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000613 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
614 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615 {
616 // Our symbol vendor shouldn't be asking us to add a compile unit that
617 // has already been added to it, which this DWARF plug-in knows as it
618 // stores the lldb compile unit (CompileUnit) pointer in each
619 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000620 assert(curr_cu->GetUserData() == NULL);
621 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000622 }
623 }
624 return comp_unit;
625}
626
627static void
628AddRangesToBlock
629(
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000630 Block& block,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631 DWARFDebugRanges::RangeList& ranges,
632 addr_t block_base_addr
633)
634{
635 ranges.SubtractOffset (block_base_addr);
636 size_t range_idx = 0;
637 const DWARFDebugRanges::Range *debug_range;
638 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
639 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000640 block.AddRange(debug_range->begin_offset, debug_range->end_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 }
642}
643
644
645Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000646SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000647{
648 DWARFDebugRanges::RangeList func_ranges;
649 const char *name = NULL;
650 const char *mangled = NULL;
651 int decl_file = 0;
652 int decl_line = 0;
653 int decl_column = 0;
654 int call_file = 0;
655 int call_line = 0;
656 int call_column = 0;
657 DWARFExpression frame_base;
658
Greg Claytonc93237c2010-10-01 20:48:32 +0000659 assert (die->Tag() == DW_TAG_subprogram);
660
661 if (die->Tag() != DW_TAG_subprogram)
662 return NULL;
663
664 const DWARFDebugInfoEntry *parent_die = die->GetParent();
665 switch (parent_die->Tag())
666 {
667 case DW_TAG_structure_type:
668 case DW_TAG_class_type:
669 // We have methods of a class or struct
670 {
671 Type *class_type = ResolveType (dwarf_cu, parent_die);
672 if (class_type)
673 class_type->GetClangType();
674 }
675 break;
676
677 default:
678 // Parse the function prototype as a type that can then be added to concrete function instance
679 ParseTypes (sc, dwarf_cu, die, false, false);
680 break;
681 }
682
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 //FixupTypes();
684
685 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
686 {
687 // Union of all ranges in the function DIE (if the function is discontiguous)
688 AddressRange func_range;
689 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
690 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
691 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
692 {
693 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
694 if (func_range.GetBaseAddress().IsValid())
695 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
696 }
697
698 if (func_range.GetBaseAddress().IsValid())
699 {
700 Mangled func_name;
701 if (mangled)
702 func_name.SetValue(mangled, true);
703 else if (name)
704 func_name.SetValue(name, false);
705
706 FunctionSP func_sp;
707 std::auto_ptr<Declaration> decl_ap;
708 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000709 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
710 decl_line,
711 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712
Greg Clayton594e5ed2010-09-27 21:07:38 +0000713 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714
715 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
716
717 func_range.GetBaseAddress().ResolveLinkedAddress();
718
719 func_sp.reset(new Function (sc.comp_unit,
720 die->GetOffset(), // UserID is the DIE offset
721 die->GetOffset(),
722 func_name,
723 func_type,
724 func_range)); // first address range
725
726 if (func_sp.get() != NULL)
727 {
728 func_sp->GetFrameBaseExpression() = frame_base;
729 sc.comp_unit->AddFunction(func_sp);
730 return func_sp.get();
731 }
732 }
733 }
734 return NULL;
735}
736
737size_t
738SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
739{
740 assert (sc.comp_unit);
741 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000742 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743 if (dwarf_cu)
744 {
745 DWARFDIECollection function_dies;
746 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
747 size_t func_idx;
748 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
749 {
750 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
751 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
752 {
753 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
754 ++functions_added;
755 }
756 }
757 //FixupTypes();
758 }
759 return functions_added;
760}
761
762bool
763SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
764{
765 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000766 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
767 assert (curr_cu);
768 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769
770 if (cu_die)
771 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000772 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
773 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 +0000774
775 // All file indexes in DWARF are one based and a file of index zero is
776 // supposed to be the compile unit itself.
777 support_files.Append (*sc.comp_unit);
778
779 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
780 }
781 return false;
782}
783
784struct ParseDWARFLineTableCallbackInfo
785{
786 LineTable* line_table;
787 const SectionList *section_list;
788 lldb::addr_t prev_sect_file_base_addr;
789 lldb::addr_t curr_sect_file_base_addr;
790 bool is_oso_for_debug_map;
791 bool prev_in_final_executable;
792 DWARFDebugLine::Row prev_row;
793 SectionSP prev_section_sp;
794 SectionSP curr_section_sp;
795};
796
797//----------------------------------------------------------------------
798// ParseStatementTableCallback
799//----------------------------------------------------------------------
800static void
801ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
802{
803 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
804 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
805 {
806 // Just started parsing the line table
807 }
808 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
809 {
810 // Done parsing line table, nothing to do for the cleanup
811 }
812 else
813 {
814 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
815 // We have a new row, lets append it
816
817 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
818 {
819 info->prev_section_sp = info->curr_section_sp;
820 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
821 // If this is an end sequence entry, then we subtract one from the
822 // address to make sure we get an address that is not the end of
823 // a section.
824 if (state.end_sequence && state.address != 0)
825 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
826 else
827 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
828
829 if (info->curr_section_sp.get())
830 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
831 else
832 info->curr_sect_file_base_addr = 0;
833 }
834 if (info->curr_section_sp.get())
835 {
836 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
837 // Check for the fancy section magic to determine if we
838
839 if (info->is_oso_for_debug_map)
840 {
841 // When this is a debug map object file that contains DWARF
842 // (referenced from an N_OSO debug map nlist entry) we will have
843 // a file address in the file range for our section from the
844 // original .o file, and a load address in the executable that
845 // contains the debug map.
846 //
847 // If the sections for the file range and load range are
848 // different, we have a remapped section for the function and
849 // this address is resolved. If they are the same, then the
850 // function for this address didn't make it into the final
851 // executable.
852 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
853
854 // If we are doing DWARF with debug map, then we need to carefully
855 // add each line table entry as there may be gaps as functions
856 // get moved around or removed.
857 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
858 {
859 if (info->prev_in_final_executable)
860 {
861 bool terminate_previous_entry = false;
862 if (!curr_in_final_executable)
863 {
864 // Check for the case where the previous line entry
865 // in a function made it into the final executable,
866 // yet the current line entry falls in a function
867 // that didn't. The line table used to be contiguous
868 // through this address range but now it isn't. We
869 // need to terminate the previous line entry so
870 // that we can reconstruct the line range correctly
871 // for it and to keep the line table correct.
872 terminate_previous_entry = true;
873 }
874 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
875 {
876 // Check for cases where the line entries used to be
877 // contiguous address ranges, but now they aren't.
878 // This can happen when order files specify the
879 // ordering of the functions.
880 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
881 Section *curr_sect = info->curr_section_sp.get();
882 Section *prev_sect = info->prev_section_sp.get();
883 assert (curr_sect->GetLinkedSection());
884 assert (prev_sect->GetLinkedSection());
885 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
886 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
887 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
888 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
889 if (object_file_addr_delta != linked_file_addr_delta)
890 terminate_previous_entry = true;
891 }
892
893 if (terminate_previous_entry)
894 {
895 line_table->InsertLineEntry (info->prev_section_sp,
896 state.address - info->prev_sect_file_base_addr,
897 info->prev_row.line,
898 info->prev_row.column,
899 info->prev_row.file,
900 false, // is_stmt
901 false, // basic_block
902 false, // state.prologue_end
903 false, // state.epilogue_begin
904 true); // end_sequence);
905 }
906 }
907 }
908
909 if (curr_in_final_executable)
910 {
911 line_table->InsertLineEntry (info->curr_section_sp,
912 curr_line_section_offset,
913 state.line,
914 state.column,
915 state.file,
916 state.is_stmt,
917 state.basic_block,
918 state.prologue_end,
919 state.epilogue_begin,
920 state.end_sequence);
921 info->prev_section_sp = info->curr_section_sp;
922 }
923 else
924 {
925 // If the current address didn't make it into the final
926 // executable, the current section will be the __text
927 // segment in the .o file, so we need to clear this so
928 // we can catch the next function that did make it into
929 // the final executable.
930 info->prev_section_sp.reset();
931 info->curr_section_sp.reset();
932 }
933
934 info->prev_in_final_executable = curr_in_final_executable;
935 }
936 else
937 {
938 // We are not in an object file that contains DWARF for an
939 // N_OSO, this is just a normal DWARF file. The DWARF spec
940 // guarantees that the addresses will be in increasing order
941 // so, since we store line tables in file address order, we
942 // can always just append the line entry without needing to
943 // search for the correct insertion point (we don't need to
944 // use LineEntry::InsertLineEntry()).
945 line_table->AppendLineEntry (info->curr_section_sp,
946 curr_line_section_offset,
947 state.line,
948 state.column,
949 state.file,
950 state.is_stmt,
951 state.basic_block,
952 state.prologue_end,
953 state.epilogue_begin,
954 state.end_sequence);
955 }
956 }
957
958 info->prev_row = state;
959 }
960}
961
962bool
963SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
964{
965 assert (sc.comp_unit);
966 if (sc.comp_unit->GetLineTable() != NULL)
967 return true;
968
969 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
970 if (dwarf_cu)
971 {
972 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
973 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
974 if (cu_line_offset != DW_INVALID_OFFSET)
975 {
976 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
977 if (line_table_ap.get())
978 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000979 ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_debug_map_symfile != NULL, false};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980 uint32_t offset = cu_line_offset;
981 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
982 sc.comp_unit->SetLineTable(line_table_ap.release());
983 return true;
984 }
985 }
986 }
987 return false;
988}
989
990size_t
991SymbolFileDWARF::ParseFunctionBlocks
992(
993 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000994 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +0000995 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000996 const DWARFDebugInfoEntry *die,
997 addr_t subprogram_low_pc,
998 bool parse_siblings,
999 bool parse_children
1000)
1001{
1002 size_t blocks_added = 0;
1003 while (die != NULL)
1004 {
1005 dw_tag_t tag = die->Tag();
1006
1007 switch (tag)
1008 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001009 case DW_TAG_inlined_subroutine:
Jim Inghamb0be4422010-08-12 01:20:14 +00001010 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001011 case DW_TAG_lexical_block:
1012 {
1013 DWARFDebugRanges::RangeList ranges;
1014 const char *name = NULL;
1015 const char *mangled_name = NULL;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001016 Block *block = NULL;
1017 if (tag != DW_TAG_subprogram)
1018 {
1019 BlockSP block_sp(new Block (die->GetOffset()));
1020 parent_block->AddChild(block_sp);
1021 block = block_sp.get();
1022 }
1023 else
1024 {
1025 block = parent_block;
1026 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001028 int decl_file = 0;
1029 int decl_line = 0;
1030 int decl_column = 0;
1031 int call_file = 0;
1032 int call_line = 0;
1033 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001034 if (die->GetDIENamesAndRanges (this,
1035 dwarf_cu,
1036 name,
1037 mangled_name,
1038 ranges,
1039 decl_file, decl_line, decl_column,
1040 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041 {
1042 if (tag == DW_TAG_subprogram)
1043 {
1044 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1045 subprogram_low_pc = ranges.LowestAddress(0);
1046 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001047 else if (tag == DW_TAG_inlined_subroutine)
1048 {
1049 // We get called here for inlined subroutines in two ways.
1050 // The first time is when we are making the Function object
1051 // for this inlined concrete instance. Since we're creating a top level block at
1052 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1053 // adjust the containing address.
1054 // The second time is when we are parsing the blocks inside the function that contains
1055 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1056 // function the offset will be for that function.
1057 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1058 {
1059 subprogram_low_pc = ranges.LowestAddress(0);
1060 }
1061 }
1062
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001063 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064
1065 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1066 {
1067 std::auto_ptr<Declaration> decl_ap;
1068 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001069 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1070 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071
1072 std::auto_ptr<Declaration> call_ap;
1073 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001074 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1075 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001076
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001077 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078 }
1079
1080 ++blocks_added;
1081
1082 if (parse_children && die->HasChildren())
1083 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001084 blocks_added += ParseFunctionBlocks (sc,
1085 block,
1086 dwarf_cu,
1087 die->GetFirstChild(),
1088 subprogram_low_pc,
1089 true,
1090 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001091 }
1092 }
1093 }
1094 break;
1095 default:
1096 break;
1097 }
1098
1099 if (parse_siblings)
1100 die = die->GetSibling();
1101 else
1102 die = NULL;
1103 }
1104 return blocks_added;
1105}
1106
1107size_t
1108SymbolFileDWARF::ParseChildMembers
1109(
1110 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001111 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001113 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001114 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001115 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1116 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001117 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001118 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119 bool &is_a_class
1120)
1121{
1122 if (parent_die == NULL)
1123 return 0;
1124
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001125 size_t count = 0;
1126 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001127 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001128 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001129
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1131 {
1132 dw_tag_t tag = die->Tag();
1133
1134 switch (tag)
1135 {
1136 case DW_TAG_member:
1137 {
1138 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001139 const size_t num_attributes = die->GetAttributes (this,
1140 dwarf_cu,
1141 fixed_form_sizes,
1142 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143 if (num_attributes > 0)
1144 {
1145 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001146 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001148 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001150 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001151 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152 size_t byte_size = 0;
1153 size_t bit_offset = 0;
1154 size_t bit_size = 0;
1155 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001156 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 {
1158 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1159 DWARFFormValue form_value;
1160 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1161 {
1162 switch (attr)
1163 {
1164 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1165 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1166 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1167 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1168 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1169 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1170 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1171 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1172 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001173// if (form_value.BlockData())
1174// {
1175// Value initialValue(0);
1176// Value memberOffset(0);
1177// const DataExtractor& debug_info_data = get_debug_info_data();
1178// uint32_t block_length = form_value.Unsigned();
1179// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1180// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1181// {
1182// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1183// }
1184// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185 break;
1186
Greg Clayton8cf05932010-07-22 18:30:50 +00001187 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001188 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 case DW_AT_declaration:
1190 case DW_AT_description:
1191 case DW_AT_mutable:
1192 case DW_AT_visibility:
1193 default:
1194 case DW_AT_sibling:
1195 break;
1196 }
1197 }
1198 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001199
1200 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1201
1202 if (class_language == eLanguageTypeObjC ||
1203 class_language == eLanguageTypeObjC_plus_plus)
1204 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001205
1206 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1207 {
1208 // Not all compilers will mark the vtable pointer
1209 // member as artificial (llvm-gcc). We can't have
1210 // the virtual members in our classes otherwise it
1211 // throws off all child offsets since we end up
1212 // having and extra pointer sized member in our
1213 // class layouts.
1214 is_artificial = true;
1215 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216
Greg Clayton24739922010-10-13 03:15:28 +00001217 if (is_artificial == false)
1218 {
1219 Type *member_type = ResolveTypeUID(encoding_uid);
1220 assert(member_type);
1221 if (accessibility == eAccessNone)
1222 accessibility = default_accessibility;
1223 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224
Greg Claytonba2d22d2010-11-13 22:57:37 +00001225 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1226 name,
1227 member_type->GetClangLayoutType(),
1228 accessibility,
1229 bit_size);
Greg Clayton24739922010-10-13 03:15:28 +00001230 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001231 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001232 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 }
1234 break;
1235
1236 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001237 // Let the type parsing code handle this one for us.
1238 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239 break;
1240
1241 case DW_TAG_inheritance:
1242 {
1243 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001244 if (default_accessibility == eAccessNone)
1245 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 // TODO: implement DW_TAG_inheritance type parsing
1247 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001248 const size_t num_attributes = die->GetAttributes (this,
1249 dwarf_cu,
1250 fixed_form_sizes,
1251 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 if (num_attributes > 0)
1253 {
1254 Declaration decl;
1255 DWARFExpression location;
1256 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001257 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 bool is_virtual = false;
1259 bool is_base_of_class = true;
1260 off_t member_offset = 0;
1261 uint32_t i;
1262 for (i=0; i<num_attributes; ++i)
1263 {
1264 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1265 DWARFFormValue form_value;
1266 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1267 {
1268 switch (attr)
1269 {
1270 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1271 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1272 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1273 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1274 case DW_AT_data_member_location:
1275 if (form_value.BlockData())
1276 {
1277 Value initialValue(0);
1278 Value memberOffset(0);
1279 const DataExtractor& debug_info_data = get_debug_info_data();
1280 uint32_t block_length = form_value.Unsigned();
1281 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001282 if (DWARFExpression::Evaluate (NULL,
1283 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001284 NULL,
1285 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001286 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001287 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001288 block_offset,
1289 block_length,
1290 eRegisterKindDWARF,
1291 &initialValue,
1292 memberOffset,
1293 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294 {
1295 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1296 }
1297 }
1298 break;
1299
1300 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001301 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 break;
1303
1304 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1305 default:
1306 case DW_AT_sibling:
1307 break;
1308 }
1309 }
1310 }
1311
Greg Clayton526e5af2010-11-13 03:52:47 +00001312 Type *base_class_type = ResolveTypeUID(encoding_uid);
1313 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001314
1315 if (class_language == eLanguageTypeObjC)
1316 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001317 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_type->GetClangType());
Greg Clayton9e409562010-07-28 02:04:09 +00001318 }
1319 else
1320 {
Greg Claytonba2d22d2010-11-13 22:57:37 +00001321 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_type->GetClangType(),
1322 accessibility,
1323 is_virtual,
1324 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001325 assert(base_classes.back());
1326 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 }
1328 }
1329 break;
1330
1331 default:
1332 break;
1333 }
1334 }
1335 return count;
1336}
1337
1338
1339clang::DeclContext*
1340SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid)
1341{
1342 DWARFDebugInfo* debug_info = DebugInfo();
1343 if (debug_info)
1344 {
1345 DWARFCompileUnitSP cu_sp;
1346 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1347 if (die)
1348 return GetClangDeclContextForDIE (cu_sp.get(), die);
1349 }
1350 return NULL;
1351}
1352
1353Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001354SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355{
1356 DWARFDebugInfo* debug_info = DebugInfo();
1357 if (debug_info)
1358 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001359 DWARFCompileUnitSP cu_sp;
1360 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001362 {
1363 // We might be coming in in the middle of a type tree (a class
1364 // withing a class, an enum within a class), so parse any needed
1365 // parent DIEs before we get to this one...
1366 const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
1367 switch (parent_die->Tag())
1368 {
1369 case DW_TAG_structure_type:
1370 case DW_TAG_union_type:
1371 case DW_TAG_class_type:
1372 ResolveType(cu_sp.get(), parent_die);
1373 break;
1374 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00001375 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001376 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001377 }
1378 return NULL;
1379}
1380
Greg Clayton6beaaa62011-01-17 03:46:26 +00001381// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1382// SymbolFileDWARF objects to detect if this DWARF file is the one that
1383// can resolve a clang_type.
1384bool
1385SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1386{
1387 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1388 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1389 return die != NULL;
1390}
1391
1392
Greg Clayton1be10fc2010-09-29 01:12:09 +00001393lldb::clang_type_t
1394SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1395{
1396 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001397 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1398 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001399 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001400 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001401// if (m_debug_map_symfile)
1402// {
1403// Type *type = m_die_to_type[die];
1404// if (type && type->GetSymbolFile() != this)
1405// return type->GetClangType();
1406// }
Greg Clayton73b472d2010-10-27 03:32:59 +00001407 // We have already resolved this type...
1408 return clang_type;
1409 }
1410 // Once we start resolving this type, remove it from the forward declaration
1411 // map in case anyone child members or other types require this type to get resolved.
1412 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1413 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001414 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001415
Greg Clayton1be10fc2010-09-29 01:12:09 +00001416
Greg Clayton450e3f32010-10-12 02:24:53 +00001417 DWARFDebugInfo* debug_info = DebugInfo();
1418
Greg Clayton96d7d742010-11-10 23:42:09 +00001419 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001420 Type *type = m_die_to_type.lookup (die);
1421
1422 const dw_tag_t tag = die->Tag();
1423
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001424 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1425 die->GetOffset(),
1426 DW_TAG_value_to_name(tag),
1427 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001428 assert (clang_type);
1429 DWARFDebugInfoEntry::Attributes attributes;
1430
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001431 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001432
1433 switch (tag)
1434 {
1435 case DW_TAG_structure_type:
1436 case DW_TAG_union_type:
1437 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001438 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001439 if (die->HasChildren())
1440 {
1441 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001442 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1443 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001444 class_language = eLanguageTypeObjC;
1445
1446 int tag_decl_kind = -1;
1447 AccessType default_accessibility = eAccessNone;
1448 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001449 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001450 tag_decl_kind = clang::TTK_Struct;
1451 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001452 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001453 else if (tag == DW_TAG_union_type)
1454 {
1455 tag_decl_kind = clang::TTK_Union;
1456 default_accessibility = eAccessPublic;
1457 }
1458 else if (tag == DW_TAG_class_type)
1459 {
1460 tag_decl_kind = clang::TTK_Class;
1461 default_accessibility = eAccessPrivate;
1462 }
1463
Greg Clayton96d7d742010-11-10 23:42:09 +00001464 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001465 std::vector<clang::CXXBaseSpecifier *> base_classes;
1466 std::vector<int> member_accessibilities;
1467 bool is_a_class = false;
1468 // Parse members and base classes first
1469 DWARFDIECollection member_function_dies;
1470
1471 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001472 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001473 die,
1474 clang_type,
1475 class_language,
1476 base_classes,
1477 member_accessibilities,
1478 member_function_dies,
1479 default_accessibility,
1480 is_a_class);
1481
1482 // Now parse any methods if there were any...
1483 size_t num_functions = member_function_dies.Size();
1484 if (num_functions > 0)
1485 {
1486 for (size_t i=0; i<num_functions; ++i)
1487 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001488 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001489 }
1490 }
1491
Greg Clayton450e3f32010-10-12 02:24:53 +00001492 if (class_language == eLanguageTypeObjC)
1493 {
1494 std::string class_str (ClangASTContext::GetTypeName (clang_type));
1495 if (!class_str.empty())
1496 {
1497
1498 ConstString class_name (class_str.c_str());
1499 std::vector<NameToDIE::Info> method_die_infos;
1500 if (m_objc_class_selectors_index.Find (class_name, method_die_infos))
1501 {
1502 DWARFCompileUnit* method_cu = NULL;
1503 DWARFCompileUnit* prev_method_cu = NULL;
1504 const size_t num_objc_methods = method_die_infos.size();
1505 for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu)
1506 {
1507 method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx);
1508
1509 if (method_cu != prev_method_cu)
1510 method_cu->ExtractDIEsIfNeeded (false);
1511
1512 DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx);
1513
1514 ResolveType (method_cu, method_die);
1515 }
1516 }
1517 }
1518 }
1519
Greg Claytonc93237c2010-10-01 20:48:32 +00001520 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1521 // need to tell the clang type it is actually a class.
1522 if (class_language != eLanguageTypeObjC)
1523 {
1524 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001525 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001526 }
1527
1528 // Since DW_TAG_structure_type gets used for both classes
1529 // and structures, we may need to set any DW_TAG_member
1530 // fields to have a "private" access if none was specified.
1531 // When we parsed the child members we tracked that actual
1532 // accessibility value for each DW_TAG_member in the
1533 // "member_accessibilities" array. If the value for the
1534 // member is zero, then it was set to the "default_accessibility"
1535 // which for structs was "public". Below we correct this
1536 // by setting any fields to "private" that weren't correctly
1537 // set.
1538 if (is_a_class && !member_accessibilities.empty())
1539 {
1540 // This is a class and all members that didn't have
1541 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001542 ast.SetDefaultAccessForRecordFields (clang_type,
1543 eAccessPrivate,
1544 &member_accessibilities.front(),
1545 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001546 }
1547
1548 if (!base_classes.empty())
1549 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001550 ast.SetBaseClassesForClassType (clang_type,
1551 &base_classes.front(),
1552 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001553
1554 // Clang will copy each CXXBaseSpecifier in "base_classes"
1555 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001556 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1557 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001558 }
1559
1560 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001561 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001562 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001563
1564 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001565 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001566 if (die->HasChildren())
1567 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001568 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1569 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001570 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001571 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001572 return clang_type;
1573
1574 default:
1575 assert(false && "not a forward clang type decl!");
1576 break;
1577 }
1578 return NULL;
1579}
1580
Greg Claytonc685f8e2010-09-15 04:15:46 +00001581Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001582SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001583{
1584 if (type_die != NULL)
1585 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001586 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001587 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001588 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001589 if (assert_not_being_parsed)
1590 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001591 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001592 }
1593 return NULL;
1594}
1595
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001596CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001597SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001598{
1599 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001600 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001601 {
1602 // The symbol vendor doesn't know about this compile unit, we
1603 // need to parse and add it to the symbol vendor object.
1604 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001605 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001606 if (dc_cu.get())
1607 {
1608 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001609 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001610 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611
1612 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001613
1614 if (m_debug_map_symfile)
1615 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001616 }
1617 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001618 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001619}
1620
1621bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001622SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623{
1624 sc.Clear();
1625 // Check if the symbol vendor already knows about this compile unit?
1626 sc.module_sp = m_obj_file->GetModule()->GetSP();
Greg Clayton96d7d742010-11-10 23:42:09 +00001627 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001628
1629 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1630 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001631 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001632
1633 return sc.function != NULL;
1634}
1635
1636uint32_t
1637SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1638{
1639 Timer scoped_timer(__PRETTY_FUNCTION__,
1640 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1641 so_addr.GetSection(),
1642 so_addr.GetOffset(),
1643 resolve_scope);
1644 uint32_t resolved = 0;
1645 if (resolve_scope & ( eSymbolContextCompUnit |
1646 eSymbolContextFunction |
1647 eSymbolContextBlock |
1648 eSymbolContextLineEntry))
1649 {
1650 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1651
1652 DWARFDebugAranges* debug_aranges = DebugAranges();
1653 DWARFDebugInfo* debug_info = DebugInfo();
1654 if (debug_aranges)
1655 {
1656 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1657 if (cu_offset != DW_INVALID_OFFSET)
1658 {
1659 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001660 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1661 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001662 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001663 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664 assert(sc.comp_unit != NULL);
1665 resolved |= eSymbolContextCompUnit;
1666
1667 if (resolve_scope & eSymbolContextLineEntry)
1668 {
1669 LineTable *line_table = sc.comp_unit->GetLineTable();
1670 if (line_table == NULL)
1671 {
1672 if (ParseCompileUnitLineTable(sc))
1673 line_table = sc.comp_unit->GetLineTable();
1674 }
1675 if (line_table != NULL)
1676 {
1677 if (so_addr.IsLinkedAddress())
1678 {
1679 Address linked_addr (so_addr);
1680 linked_addr.ResolveLinkedAddress();
1681 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1682 {
1683 resolved |= eSymbolContextLineEntry;
1684 }
1685 }
1686 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1687 {
1688 resolved |= eSymbolContextLineEntry;
1689 }
1690 }
1691 }
1692
1693 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1694 {
1695 DWARFDebugInfoEntry *function_die = NULL;
1696 DWARFDebugInfoEntry *block_die = NULL;
1697 if (resolve_scope & eSymbolContextBlock)
1698 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001699 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700 }
1701 else
1702 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001703 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704 }
1705
1706 if (function_die != NULL)
1707 {
1708 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1709 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001710 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001711 }
1712
1713 if (sc.function != NULL)
1714 {
1715 resolved |= eSymbolContextFunction;
1716
1717 if (resolve_scope & eSymbolContextBlock)
1718 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001719 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001720
1721 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001722 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001723 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001724 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725 if (sc.block)
1726 resolved |= eSymbolContextBlock;
1727 }
1728 }
1729 }
1730 }
1731 }
1732 }
1733 }
1734 return resolved;
1735}
1736
1737
1738
1739uint32_t
1740SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1741{
1742 const uint32_t prev_size = sc_list.GetSize();
1743 if (resolve_scope & eSymbolContextCompUnit)
1744 {
1745 DWARFDebugInfo* debug_info = DebugInfo();
1746 if (debug_info)
1747 {
1748 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001749 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001750
Greg Clayton96d7d742010-11-10 23:42:09 +00001751 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001752 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001753 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1755 if (check_inlines || file_spec_matches_cu_file_spec)
1756 {
1757 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001758 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001759 assert(sc.comp_unit != NULL);
1760
1761 uint32_t file_idx = UINT32_MAX;
1762
1763 // If we are looking for inline functions only and we don't
1764 // find it in the support files, we are done.
1765 if (check_inlines)
1766 {
1767 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1768 if (file_idx == UINT32_MAX)
1769 continue;
1770 }
1771
1772 if (line != 0)
1773 {
1774 LineTable *line_table = sc.comp_unit->GetLineTable();
1775
1776 if (line_table != NULL && line != 0)
1777 {
1778 // We will have already looked up the file index if
1779 // we are searching for inline entries.
1780 if (!check_inlines)
1781 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1782
1783 if (file_idx != UINT32_MAX)
1784 {
1785 uint32_t found_line;
1786 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1787 found_line = sc.line_entry.line;
1788
Greg Clayton016a95e2010-09-14 02:20:48 +00001789 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790 {
1791 sc.function = NULL;
1792 sc.block = NULL;
1793 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1794 {
1795 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1796 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1797 {
1798 DWARFDebugInfoEntry *function_die = NULL;
1799 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001800 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801
1802 if (function_die != NULL)
1803 {
1804 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1805 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001806 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807 }
1808
1809 if (sc.function != NULL)
1810 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001811 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812
1813 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001814 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001815 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001816 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001817 }
1818 }
1819 }
1820
1821 sc_list.Append(sc);
1822 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1823 }
1824 }
1825 }
1826 else if (file_spec_matches_cu_file_spec && !check_inlines)
1827 {
1828 // only append the context if we aren't looking for inline call sites
1829 // by file and line and if the file spec matches that of the compile unit
1830 sc_list.Append(sc);
1831 }
1832 }
1833 else if (file_spec_matches_cu_file_spec && !check_inlines)
1834 {
1835 // only append the context if we aren't looking for inline call sites
1836 // by file and line and if the file spec matches that of the compile unit
1837 sc_list.Append(sc);
1838 }
1839
1840 if (!check_inlines)
1841 break;
1842 }
1843 }
1844 }
1845 }
1846 return sc_list.GetSize() - prev_size;
1847}
1848
1849void
1850SymbolFileDWARF::Index ()
1851{
1852 if (m_indexed)
1853 return;
1854 m_indexed = true;
1855 Timer scoped_timer (__PRETTY_FUNCTION__,
1856 "SymbolFileDWARF::Index (%s)",
1857 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1858
1859 DWARFDebugInfo* debug_info = DebugInfo();
1860 if (debug_info)
1861 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001862 m_aranges.reset(new DWARFDebugAranges());
1863
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864 uint32_t cu_idx = 0;
1865 const uint32_t num_compile_units = GetNumCompileUnits();
1866 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1867 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001868 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869
Greg Clayton96d7d742010-11-10 23:42:09 +00001870 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001871
Greg Clayton96d7d742010-11-10 23:42:09 +00001872 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001873 m_function_basename_index,
1874 m_function_fullname_index,
1875 m_function_method_index,
1876 m_function_selector_index,
1877 m_objc_class_selectors_index,
1878 m_global_index,
1879 m_type_index,
1880 m_namespace_index,
1881 DebugRanges(),
1882 m_aranges.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883
1884 // Keep memory down by clearing DIEs if this generate function
1885 // caused them to be parsed
1886 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001887 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001888 }
1889
Greg Clayton016a95e2010-09-14 02:20:48 +00001890 m_aranges->Sort();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001891
Greg Clayton24739922010-10-13 03:15:28 +00001892#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00001893 StreamFile s(stdout, false);
Greg Clayton24739922010-10-13 03:15:28 +00001894 s.Printf ("DWARF index for (%s) '%s/%s':",
1895 GetObjectFile()->GetModule()->GetArchitecture().AsCString(),
1896 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1897 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001898 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1899 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1900 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1901 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1902 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1903 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001904 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001905 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001906#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 }
1908}
1909
1910uint32_t
1911SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1912{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001913 DWARFDebugInfo* info = DebugInfo();
1914 if (info == NULL)
1915 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001916
1917 // If we aren't appending the results to this list, then clear the list
1918 if (!append)
1919 variables.Clear();
1920
1921 // Remember how many variables are in the list before we search in case
1922 // we are appending the results to a variable list.
1923 const uint32_t original_size = variables.GetSize();
1924
1925 // Index the DWARF if we haven't already
1926 if (!m_indexed)
1927 Index ();
1928
Greg Claytonc685f8e2010-09-15 04:15:46 +00001929 SymbolContext sc;
1930 sc.module_sp = m_obj_file->GetModule()->GetSP();
1931 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932
Greg Clayton96d7d742010-11-10 23:42:09 +00001933 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001934 DWARFCompileUnit* prev_cu = NULL;
1935 const DWARFDebugInfoEntry* die = NULL;
1936 std::vector<NameToDIE::Info> die_info_array;
1937 const size_t num_matches = m_global_index.Find(name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001938 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001939 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001940 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001941
Greg Clayton96d7d742010-11-10 23:42:09 +00001942 if (curr_cu != prev_cu)
1943 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001944
Greg Clayton96d7d742010-11-10 23:42:09 +00001945 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946
Greg Clayton96d7d742010-11-10 23:42:09 +00001947 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001948 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949
Greg Clayton96d7d742010-11-10 23:42:09 +00001950 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001951
1952 if (variables.GetSize() - original_size >= max_matches)
1953 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001954 }
1955
1956 // Return the number of variable that were appended to the list
1957 return variables.GetSize() - original_size;
1958}
1959
1960uint32_t
1961SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
1962{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001963 DWARFDebugInfo* info = DebugInfo();
1964 if (info == NULL)
1965 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966
1967 // If we aren't appending the results to this list, then clear the list
1968 if (!append)
1969 variables.Clear();
1970
1971 // Remember how many variables are in the list before we search in case
1972 // we are appending the results to a variable list.
1973 const uint32_t original_size = variables.GetSize();
1974
1975 // Index the DWARF if we haven't already
1976 if (!m_indexed)
1977 Index ();
1978
Greg Claytonc685f8e2010-09-15 04:15:46 +00001979 SymbolContext sc;
1980 sc.module_sp = m_obj_file->GetModule()->GetSP();
1981 assert (sc.module_sp);
1982
Greg Clayton96d7d742010-11-10 23:42:09 +00001983 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001984 DWARFCompileUnit* prev_cu = NULL;
1985 const DWARFDebugInfoEntry* die = NULL;
1986 std::vector<NameToDIE::Info> die_info_array;
1987 const size_t num_matches = m_global_index.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001988 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001989 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001990 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001991
Greg Clayton96d7d742010-11-10 23:42:09 +00001992 if (curr_cu != prev_cu)
1993 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001994
Greg Clayton96d7d742010-11-10 23:42:09 +00001995 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996
Greg Clayton96d7d742010-11-10 23:42:09 +00001997 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001998 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999
Greg Clayton96d7d742010-11-10 23:42:09 +00002000 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001
Greg Claytonc685f8e2010-09-15 04:15:46 +00002002 if (variables.GetSize() - original_size >= max_matches)
2003 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 }
2005
2006 // Return the number of variable that were appended to the list
2007 return variables.GetSize() - original_size;
2008}
2009
2010
Greg Clayton0c5cd902010-06-28 21:30:43 +00002011void
2012SymbolFileDWARF::FindFunctions
2013(
2014 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00002015 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00002016 SymbolContextList& sc_list
2017)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002019 DWARFDebugInfo* info = DebugInfo();
2020 if (info == NULL)
2021 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022
Greg Claytonc685f8e2010-09-15 04:15:46 +00002023 SymbolContext sc;
2024 sc.module_sp = m_obj_file->GetModule()->GetSP();
2025 assert (sc.module_sp);
2026
Greg Clayton96d7d742010-11-10 23:42:09 +00002027 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002028 DWARFCompileUnit* prev_cu = NULL;
2029 const DWARFDebugInfoEntry* die = NULL;
2030 std::vector<NameToDIE::Info> die_info_array;
Greg Claytond7e05462010-11-14 00:22:48 +00002031 const size_t num_matches = name_to_die.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002032 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002033 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002034 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002035
Greg Clayton96d7d742010-11-10 23:42:09 +00002036 if (curr_cu != prev_cu)
2037 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002038
Greg Clayton96d7d742010-11-10 23:42:09 +00002039 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytond7e05462010-11-14 00:22:48 +00002040
2041 const DWARFDebugInfoEntry* inlined_die = NULL;
2042 if (die->Tag() == DW_TAG_inlined_subroutine)
2043 {
2044 inlined_die = die;
2045
2046 while ((die = die->GetParent()) != NULL)
2047 {
2048 if (die->Tag() == DW_TAG_subprogram)
2049 break;
2050 }
2051 }
2052 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002053 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002054 {
Greg Claytond7e05462010-11-14 00:22:48 +00002055 Address addr;
2056 // Parse all blocks if needed
2057 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002058 {
Greg Claytond7e05462010-11-14 00:22:48 +00002059 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2060 assert (sc.block != NULL);
2061 if (sc.block->GetStartAddress (addr) == false)
2062 addr.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002063 }
Greg Claytond7e05462010-11-14 00:22:48 +00002064 else
2065 {
2066 sc.block = NULL;
2067 addr = sc.function->GetAddressRange().GetBaseAddress();
2068 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002069
Greg Claytond7e05462010-11-14 00:22:48 +00002070 if (addr.IsValid())
2071 {
2072
2073 // We found the function, so we should find the line table
2074 // and line table entry as well
2075 LineTable *line_table = sc.comp_unit->GetLineTable();
2076 if (line_table == NULL)
2077 {
2078 if (ParseCompileUnitLineTable(sc))
2079 line_table = sc.comp_unit->GetLineTable();
2080 }
2081 if (line_table != NULL)
2082 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2083
2084 sc_list.Append(sc);
2085 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002086 }
2087 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002088}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089
Greg Claytonc685f8e2010-09-15 04:15:46 +00002090
2091void
2092SymbolFileDWARF::FindFunctions
2093(
2094 const RegularExpression &regex,
2095 const NameToDIE &name_to_die,
2096 SymbolContextList& sc_list
2097)
2098{
2099 DWARFDebugInfo* info = DebugInfo();
2100 if (info == NULL)
2101 return;
2102
2103 SymbolContext sc;
2104 sc.module_sp = m_obj_file->GetModule()->GetSP();
2105 assert (sc.module_sp);
2106
Greg Clayton96d7d742010-11-10 23:42:09 +00002107 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002108 DWARFCompileUnit* prev_cu = NULL;
2109 const DWARFDebugInfoEntry* die = NULL;
2110 std::vector<NameToDIE::Info> die_info_array;
2111 const size_t num_matches = name_to_die.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002112 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002113 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002114 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002115
Greg Clayton96d7d742010-11-10 23:42:09 +00002116 if (curr_cu != prev_cu)
2117 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002118
Greg Clayton96d7d742010-11-10 23:42:09 +00002119 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonab843392010-12-03 17:49:14 +00002120
2121 const DWARFDebugInfoEntry* inlined_die = NULL;
2122 if (die->Tag() == DW_TAG_inlined_subroutine)
2123 {
2124 inlined_die = die;
2125
2126 while ((die = die->GetParent()) != NULL)
2127 {
2128 if (die->Tag() == DW_TAG_subprogram)
2129 break;
2130 }
2131 }
2132 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002133 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002134 {
Greg Claytonab843392010-12-03 17:49:14 +00002135 Address addr;
2136 // Parse all blocks if needed
2137 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002138 {
Greg Claytonab843392010-12-03 17:49:14 +00002139 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2140 assert (sc.block != NULL);
2141 if (sc.block->GetStartAddress (addr) == false)
2142 addr.Clear();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002143 }
Greg Claytonab843392010-12-03 17:49:14 +00002144 else
2145 {
2146 sc.block = NULL;
2147 addr = sc.function->GetAddressRange().GetBaseAddress();
2148 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002149
Greg Claytonab843392010-12-03 17:49:14 +00002150 if (addr.IsValid())
2151 {
2152
2153 // We found the function, so we should find the line table
2154 // and line table entry as well
2155 LineTable *line_table = sc.comp_unit->GetLineTable();
2156 if (line_table == NULL)
2157 {
2158 if (ParseCompileUnitLineTable(sc))
2159 line_table = sc.comp_unit->GetLineTable();
2160 }
2161 if (line_table != NULL)
2162 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2163
2164 sc_list.Append(sc);
2165 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002166 }
2167 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002168}
2169
2170uint32_t
2171SymbolFileDWARF::FindFunctions
2172(
2173 const ConstString &name,
2174 uint32_t name_type_mask,
2175 bool append,
2176 SymbolContextList& sc_list
2177)
2178{
2179 Timer scoped_timer (__PRETTY_FUNCTION__,
2180 "SymbolFileDWARF::FindFunctions (name = '%s')",
2181 name.AsCString());
2182
Greg Clayton0c5cd902010-06-28 21:30:43 +00002183 // If we aren't appending the results to this list, then clear the list
2184 if (!append)
2185 sc_list.Clear();
2186
2187 // Remember how many sc_list are in the list before we search in case
2188 // we are appending the results to a variable list.
2189 uint32_t original_size = sc_list.GetSize();
2190
2191 // Index the DWARF if we haven't already
2192 if (!m_indexed)
2193 Index ();
2194
2195 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002196 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002197
2198 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002199 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002200
2201 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002202 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002203
2204 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002205 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002206
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002207 // Return the number of variable that were appended to the list
2208 return sc_list.GetSize() - original_size;
2209}
2210
2211
2212uint32_t
2213SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2214{
2215 Timer scoped_timer (__PRETTY_FUNCTION__,
2216 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2217 regex.GetText());
2218
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002219 // If we aren't appending the results to this list, then clear the list
2220 if (!append)
2221 sc_list.Clear();
2222
2223 // Remember how many sc_list are in the list before we search in case
2224 // we are appending the results to a variable list.
2225 uint32_t original_size = sc_list.GetSize();
2226
2227 // Index the DWARF if we haven't already
2228 if (!m_indexed)
2229 Index ();
2230
Greg Claytonc685f8e2010-09-15 04:15:46 +00002231 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002232
Greg Claytonc685f8e2010-09-15 04:15:46 +00002233 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002234
2235 // Return the number of variable that were appended to the list
2236 return sc_list.GetSize() - original_size;
2237}
2238
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002239uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002240SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002242 DWARFDebugInfo* info = DebugInfo();
2243 if (info == NULL)
2244 return 0;
2245
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002246 // If we aren't appending the results to this list, then clear the list
2247 if (!append)
2248 types.Clear();
2249
Greg Clayton6dbd3982010-09-15 05:51:24 +00002250 // Index if we already haven't to make sure the compile units
2251 // get indexed and make their global DIE index list
2252 if (!m_indexed)
2253 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002254
Greg Claytonc685f8e2010-09-15 04:15:46 +00002255 const uint32_t initial_types_size = types.GetSize();
Greg Clayton96d7d742010-11-10 23:42:09 +00002256 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002257 DWARFCompileUnit* prev_cu = NULL;
2258 const DWARFDebugInfoEntry* die = NULL;
2259 std::vector<NameToDIE::Info> die_info_array;
Greg Clayton69b04882010-10-15 02:03:22 +00002260 const size_t num_matches = m_type_index.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002261 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002262 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002263 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002264
Greg Clayton96d7d742010-11-10 23:42:09 +00002265 if (curr_cu != prev_cu)
2266 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002267
Greg Clayton96d7d742010-11-10 23:42:09 +00002268 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002269
Greg Clayton96d7d742010-11-10 23:42:09 +00002270 Type *matching_type = ResolveType (curr_cu, die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002271 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00002273 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002274 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonc685f8e2010-09-15 04:15:46 +00002275 assert (type_sp.get() != NULL);
2276 types.InsertUnique (type_sp);
2277 if (types.GetSize() >= max_matches)
2278 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002279 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002280 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002281 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002282}
2283
2284
Greg Clayton526e5af2010-11-13 03:52:47 +00002285ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002286SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2287 const ConstString &name)
2288{
Greg Clayton526e5af2010-11-13 03:52:47 +00002289 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002290 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002291 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002292 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002293 // Index if we already haven't to make sure the compile units
2294 // get indexed and make their global DIE index list
2295 if (!m_indexed)
2296 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002297
Greg Clayton526e5af2010-11-13 03:52:47 +00002298 DWARFCompileUnit* curr_cu = NULL;
2299 DWARFCompileUnit* prev_cu = NULL;
2300 const DWARFDebugInfoEntry* die = NULL;
2301 std::vector<NameToDIE::Info> die_info_array;
2302 const size_t num_matches = m_namespace_index.Find (name, die_info_array);
2303 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
2304 {
2305 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
2306
2307 if (curr_cu != prev_cu)
2308 curr_cu->ExtractDIEsIfNeeded (false);
Greg Clayton96d7d742010-11-10 23:42:09 +00002309
Greg Clayton526e5af2010-11-13 03:52:47 +00002310 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2311
2312 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die);
2313 if (clang_namespace_decl)
2314 {
2315 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2316 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2317 }
2318 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002319 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002320 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002321}
2322
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002323uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002324SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002325{
2326 // Remember how many sc_list are in the list before we search in case
2327 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002328 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002329
2330 const uint32_t num_die_offsets = die_offsets.size();
2331 // Parse all of the types we found from the pubtypes matches
2332 uint32_t i;
2333 uint32_t num_matches = 0;
2334 for (i = 0; i < num_die_offsets; ++i)
2335 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002336 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2337 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002338 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002339 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002340 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002341 assert (type_sp.get() != NULL);
2342 types.InsertUnique (type_sp);
2343 ++num_matches;
2344 if (num_matches >= max_matches)
2345 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002346 }
2347 }
2348
2349 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002350 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351}
2352
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353
2354size_t
2355SymbolFileDWARF::ParseChildParameters
2356(
2357 const SymbolContext& sc,
2358 TypeSP& type_sp,
Greg Clayton0fffff52010-09-24 05:15:53 +00002359 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002360 const DWARFDebugInfoEntry *parent_die,
Greg Claytona51ed9b2010-09-23 01:09:21 +00002361 bool skip_artificial,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002362 TypeList* type_list,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002363 std::vector<clang_type_t>& function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00002364 std::vector<clang::ParmVarDecl*>& function_param_decls,
2365 unsigned &type_quals
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366)
2367{
2368 if (parent_die == NULL)
2369 return 0;
2370
Greg Claytond88d7592010-09-15 08:33:30 +00002371 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2372
Greg Clayton7fedea22010-11-16 02:10:54 +00002373 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002374 const DWARFDebugInfoEntry *die;
2375 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2376 {
2377 dw_tag_t tag = die->Tag();
2378 switch (tag)
2379 {
2380 case DW_TAG_formal_parameter:
2381 {
2382 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002383 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002384 if (num_attributes > 0)
2385 {
2386 const char *name = NULL;
2387 Declaration decl;
2388 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002389 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002390 // one of None, Auto, Register, Extern, Static, PrivateExtern
2391
Sean Callanane2ef6e32010-09-23 03:01:22 +00002392 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002393 uint32_t i;
2394 for (i=0; i<num_attributes; ++i)
2395 {
2396 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2397 DWARFFormValue form_value;
2398 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2399 {
2400 switch (attr)
2401 {
2402 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2403 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2404 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2405 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2406 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002407 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002408 case DW_AT_location:
2409 // if (form_value.BlockData())
2410 // {
2411 // const DataExtractor& debug_info_data = debug_info();
2412 // uint32_t block_length = form_value.Unsigned();
2413 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2414 // }
2415 // else
2416 // {
2417 // }
2418 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002419 case DW_AT_const_value:
2420 case DW_AT_default_value:
2421 case DW_AT_description:
2422 case DW_AT_endianity:
2423 case DW_AT_is_optional:
2424 case DW_AT_segment:
2425 case DW_AT_variable_parameter:
2426 default:
2427 case DW_AT_abstract_origin:
2428 case DW_AT_sibling:
2429 break;
2430 }
2431 }
2432 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002433
Greg Clayton0fffff52010-09-24 05:15:53 +00002434 bool skip = false;
2435 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002436 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002437 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002438 {
2439 // In order to determine if a C++ member function is
2440 // "const" we have to look at the const-ness of "this"...
2441 // Ugly, but that
2442 if (arg_idx == 0)
2443 {
2444 const DWARFDebugInfoEntry *grandparent_die = parent_die->GetParent();
2445 if (grandparent_die && (grandparent_die->Tag() == DW_TAG_structure_type ||
2446 grandparent_die->Tag() == DW_TAG_class_type))
2447 {
2448 LanguageType language = sc.comp_unit->GetLanguage();
2449 if (language == eLanguageTypeObjC_plus_plus || language == eLanguageTypeC_plus_plus)
2450 {
2451 // Often times compilers omit the "this" name for the
2452 // specification DIEs, so we can't rely upon the name
2453 // being in the formal parameter DIE...
2454 if (name == NULL || ::strcmp(name, "this")==0)
2455 {
2456 Type *this_type = ResolveTypeUID (param_type_die_offset);
2457 if (this_type)
2458 {
2459 uint32_t encoding_mask = this_type->GetEncodingMask();
2460 if (encoding_mask & Type::eEncodingIsPointerUID)
2461 {
2462 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
Greg Clayton47fbf1a2010-11-16 22:09:25 +00002463 type_quals |= clang::Qualifiers::Const;
Greg Clayton7fedea22010-11-16 02:10:54 +00002464 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
Greg Clayton47fbf1a2010-11-16 22:09:25 +00002465 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002466 }
2467 }
2468 }
2469 }
2470 }
2471 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002472 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002473 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002474 else
2475 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002476
Greg Clayton0fffff52010-09-24 05:15:53 +00002477 // HACK: Objective C formal parameters "self" and "_cmd"
2478 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002479 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2480 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002481 {
2482 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2483 skip = true;
2484 }
2485 }
2486 }
2487
2488 if (!skip)
2489 {
2490 Type *type = ResolveTypeUID(param_type_die_offset);
2491 if (type)
2492 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002493 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002494
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002495 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002496 assert(param_var_decl);
2497 function_param_decls.push_back(param_var_decl);
2498 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002499 }
2500 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002501 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502 }
2503 break;
2504
2505 default:
2506 break;
2507 }
2508 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002509 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002510}
2511
2512size_t
2513SymbolFileDWARF::ParseChildEnumerators
2514(
2515 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002516 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002517 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002518 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002519 const DWARFDebugInfoEntry *parent_die
2520)
2521{
2522 if (parent_die == NULL)
2523 return 0;
2524
2525 size_t enumerators_added = 0;
2526 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002527 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2528
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002529 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2530 {
2531 const dw_tag_t tag = die->Tag();
2532 if (tag == DW_TAG_enumerator)
2533 {
2534 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002535 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002536 if (num_child_attributes > 0)
2537 {
2538 const char *name = NULL;
2539 bool got_value = false;
2540 int64_t enum_value = 0;
2541 Declaration decl;
2542
2543 uint32_t i;
2544 for (i=0; i<num_child_attributes; ++i)
2545 {
2546 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2547 DWARFFormValue form_value;
2548 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2549 {
2550 switch (attr)
2551 {
2552 case DW_AT_const_value:
2553 got_value = true;
2554 enum_value = form_value.Unsigned();
2555 break;
2556
2557 case DW_AT_name:
2558 name = form_value.AsCString(&get_debug_str_data());
2559 break;
2560
2561 case DW_AT_description:
2562 default:
2563 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2564 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2565 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2566 case DW_AT_sibling:
2567 break;
2568 }
2569 }
2570 }
2571
2572 if (name && name[0] && got_value)
2573 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002574 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2575 enumerator_clang_type,
2576 decl,
2577 name,
2578 enum_value,
2579 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002580 ++enumerators_added;
2581 }
2582 }
2583 }
2584 }
2585 return enumerators_added;
2586}
2587
2588void
2589SymbolFileDWARF::ParseChildArrayInfo
2590(
2591 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002592 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002593 const DWARFDebugInfoEntry *parent_die,
2594 int64_t& first_index,
2595 std::vector<uint64_t>& element_orders,
2596 uint32_t& byte_stride,
2597 uint32_t& bit_stride
2598)
2599{
2600 if (parent_die == NULL)
2601 return;
2602
2603 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002604 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002605 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2606 {
2607 const dw_tag_t tag = die->Tag();
2608 switch (tag)
2609 {
2610 case DW_TAG_enumerator:
2611 {
2612 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002613 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002614 if (num_child_attributes > 0)
2615 {
2616 const char *name = NULL;
2617 bool got_value = false;
2618 int64_t enum_value = 0;
2619
2620 uint32_t i;
2621 for (i=0; i<num_child_attributes; ++i)
2622 {
2623 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2624 DWARFFormValue form_value;
2625 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2626 {
2627 switch (attr)
2628 {
2629 case DW_AT_const_value:
2630 got_value = true;
2631 enum_value = form_value.Unsigned();
2632 break;
2633
2634 case DW_AT_name:
2635 name = form_value.AsCString(&get_debug_str_data());
2636 break;
2637
2638 case DW_AT_description:
2639 default:
2640 case DW_AT_decl_file:
2641 case DW_AT_decl_line:
2642 case DW_AT_decl_column:
2643 case DW_AT_sibling:
2644 break;
2645 }
2646 }
2647 }
2648 }
2649 }
2650 break;
2651
2652 case DW_TAG_subrange_type:
2653 {
2654 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002655 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002656 if (num_child_attributes > 0)
2657 {
2658 const char *name = NULL;
2659 bool got_value = false;
2660 uint64_t byte_size = 0;
2661 int64_t enum_value = 0;
2662 uint64_t num_elements = 0;
2663 uint64_t lower_bound = 0;
2664 uint64_t upper_bound = 0;
2665 uint32_t i;
2666 for (i=0; i<num_child_attributes; ++i)
2667 {
2668 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2669 DWARFFormValue form_value;
2670 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2671 {
2672 switch (attr)
2673 {
2674 case DW_AT_const_value:
2675 got_value = true;
2676 enum_value = form_value.Unsigned();
2677 break;
2678
2679 case DW_AT_name:
2680 name = form_value.AsCString(&get_debug_str_data());
2681 break;
2682
2683 case DW_AT_count:
2684 num_elements = form_value.Unsigned();
2685 break;
2686
2687 case DW_AT_bit_stride:
2688 bit_stride = form_value.Unsigned();
2689 break;
2690
2691 case DW_AT_byte_stride:
2692 byte_stride = form_value.Unsigned();
2693 break;
2694
2695 case DW_AT_byte_size:
2696 byte_size = form_value.Unsigned();
2697 break;
2698
2699 case DW_AT_lower_bound:
2700 lower_bound = form_value.Unsigned();
2701 break;
2702
2703 case DW_AT_upper_bound:
2704 upper_bound = form_value.Unsigned();
2705 break;
2706
2707 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002708 case DW_AT_abstract_origin:
2709 case DW_AT_accessibility:
2710 case DW_AT_allocated:
2711 case DW_AT_associated:
2712 case DW_AT_data_location:
2713 case DW_AT_declaration:
2714 case DW_AT_description:
2715 case DW_AT_sibling:
2716 case DW_AT_threads_scaled:
2717 case DW_AT_type:
2718 case DW_AT_visibility:
2719 break;
2720 }
2721 }
2722 }
2723
2724 if (upper_bound > lower_bound)
2725 num_elements = upper_bound - lower_bound + 1;
2726
2727 if (num_elements > 0)
2728 element_orders.push_back (num_elements);
2729 }
2730 }
2731 break;
2732 }
2733 }
2734}
2735
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002736TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002737SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002738{
2739 TypeSP type_sp;
2740 if (die != NULL)
2741 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002742 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002743 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002744 if (type_ptr == NULL)
2745 {
Greg Claytonca512b32011-01-14 04:54:56 +00002746 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
2747 assert (lldb_cu);
2748 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00002749 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002750 }
2751 else if (type_ptr != DIE_IS_BEING_PARSED)
2752 {
2753 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002754 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002755 }
2756
2757 }
2758 return type_sp;
2759}
2760
2761clang::DeclContext *
2762SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset)
2763{
2764 if (die_offset != DW_INVALID_OFFSET)
2765 {
2766 DWARFCompileUnitSP cu_sp;
2767 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2768 return GetClangDeclContextForDIE (cu_sp.get(), die);
2769 }
2770 return NULL;
2771}
2772
2773
Greg Clayton96d7d742010-11-10 23:42:09 +00002774clang::NamespaceDecl *
2775SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2776{
2777 if (die->Tag() == DW_TAG_namespace)
2778 {
2779 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2780 if (namespace_name)
2781 {
2782 Declaration decl; // TODO: fill in the decl object
2783 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent()));
2784 if (namespace_decl)
2785 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2786 return namespace_decl;
2787 }
2788 }
2789 return NULL;
2790}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002791
2792clang::DeclContext *
Greg Clayton96d7d742010-11-10 23:42:09 +00002793SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002794{
Greg Claytonca512b32011-01-14 04:54:56 +00002795 if (m_clang_tu_decl == NULL)
2796 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002797
Greg Claytonca512b32011-01-14 04:54:56 +00002798 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x )\n", die->GetOffset());
2799 const DWARFDebugInfoEntry * const decl_die = die;
Greg Clayton4cd17802011-01-25 06:17:32 +00002800 clang::DeclContext *decl_ctx = NULL;
2801
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002802 while (die != NULL)
2803 {
Greg Claytonca512b32011-01-14 04:54:56 +00002804 // If this is the original DIE that we are searching for a declaration
2805 // for, then don't look in the cache as we don't want our own decl
2806 // context to be our decl context...
2807 if (decl_die != die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002808 {
Greg Claytonca512b32011-01-14 04:54:56 +00002809 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2810 if (pos != m_die_to_decl_ctx.end())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002811 {
Greg Claytonca512b32011-01-14 04:54:56 +00002812 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
2813 return pos->second;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002814 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002815
Greg Claytonca512b32011-01-14 04:54:56 +00002816 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
2817
2818 switch (die->Tag())
2819 {
2820 case DW_TAG_namespace:
2821 {
2822 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2823 if (namespace_name)
2824 {
2825 Declaration decl; // TODO: fill in the decl object
Greg Clayton6beaaa62011-01-17 03:46:26 +00002826 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die));
Greg Claytonca512b32011-01-14 04:54:56 +00002827 if (namespace_decl)
2828 {
2829 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
2830 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2831 }
2832 return namespace_decl;
2833 }
2834 }
2835 break;
2836
2837 case DW_TAG_structure_type:
2838 case DW_TAG_union_type:
2839 case DW_TAG_class_type:
2840 {
Greg Clayton4cd17802011-01-25 06:17:32 +00002841 Type* type = ResolveType (curr_cu, die);
Greg Claytonca512b32011-01-14 04:54:56 +00002842 pos = m_die_to_decl_ctx.find(die);
Greg Claytonca512b32011-01-14 04:54:56 +00002843 if (pos != m_die_to_decl_ctx.end())
2844 {
2845 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
2846 return pos->second;
2847 }
Greg Clayton4cd17802011-01-25 06:17:32 +00002848 else
2849 {
2850 if (type)
2851 {
2852 decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
2853 if (decl_ctx)
2854 return decl_ctx;
2855 }
2856 }
Greg Claytonca512b32011-01-14 04:54:56 +00002857 }
2858 break;
2859
2860 default:
2861 break;
2862 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002863 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002864
Greg Clayton6beaaa62011-01-17 03:46:26 +00002865 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002866 if (die_offset != DW_INVALID_OFFSET)
2867 {
2868 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2869 decl_ctx = GetClangDeclContextForDIEOffset (die_offset);
2870 if (decl_ctx != m_clang_tu_decl)
2871 return decl_ctx;
2872 }
2873
Greg Clayton6beaaa62011-01-17 03:46:26 +00002874 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002875 if (die_offset != DW_INVALID_OFFSET)
2876 {
2877 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2878 decl_ctx = GetClangDeclContextForDIEOffset (die_offset);
2879 if (decl_ctx != m_clang_tu_decl)
2880 return decl_ctx;
2881 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002882
2883 die = die->GetParent();
2884 }
Greg Clayton7a345282010-11-09 23:46:37 +00002885 // Right now we have only one translation unit per module...
Greg Claytonca512b32011-01-14 04:54:56 +00002886 //printf ("SymbolFileDWARF::GetClangDeclContextForDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset());
Greg Clayton7a345282010-11-09 23:46:37 +00002887 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002888}
2889
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002890// This function can be used when a DIE is found that is a forward declaration
2891// DIE and we want to try and find a type that has the complete definition.
2892TypeSP
2893SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton1a65ae12011-01-25 23:55:37 +00002894 DWARFCompileUnit* cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002895 const DWARFDebugInfoEntry *die,
2896 const ConstString &type_name
2897)
2898{
2899 TypeSP type_sp;
2900
Greg Clayton1a65ae12011-01-25 23:55:37 +00002901 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002902 return type_sp;
2903
Greg Clayton69974892010-12-03 21:42:06 +00002904 if (!m_indexed)
2905 Index ();
2906
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002907 const dw_tag_t type_tag = die->Tag();
2908 std::vector<NameToDIE::Info> die_info_array;
2909 const size_t num_matches = m_type_index.Find (type_name, die_info_array);
2910 if (num_matches > 0)
2911 {
2912 DWARFCompileUnit* type_cu = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +00002913 DWARFCompileUnit* curr_cu = cu;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002914 DWARFDebugInfo *info = DebugInfo();
2915 for (size_t i=0; i<num_matches; ++i)
2916 {
2917 type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx);
2918
2919 if (type_cu != curr_cu)
2920 {
2921 type_cu->ExtractDIEsIfNeeded (false);
2922 curr_cu = type_cu;
2923 }
2924
2925 DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx);
2926
2927 if (type_die != die && type_die->Tag() == type_tag)
2928 {
2929 // Hold off on comparing parent DIE tags until
2930 // we know what happens with stuff in namespaces
2931 // for gcc and clang...
2932 //DWARFDebugInfoEntry *parent_die = die->GetParent();
2933 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
2934 //if (parent_die->Tag() == parent_type_die->Tag())
2935 {
2936 Type *resolved_type = ResolveType (type_cu, type_die, false);
2937 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
2938 {
2939 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
2940 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00002941 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002942 m_obj_file->GetFileSpec().GetFilename().AsCString(),
2943 type_die->GetOffset(),
2944 type_cu->GetOffset());
2945
2946 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002947 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00002948 if (!type_sp)
2949 {
2950 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
2951 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002952 break;
2953 }
2954 }
2955 }
2956 }
2957 }
2958 return type_sp;
2959}
2960
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002961TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00002962SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002963{
2964 TypeSP type_sp;
2965
Greg Clayton1be10fc2010-09-29 01:12:09 +00002966 if (type_is_new_ptr)
2967 *type_is_new_ptr = false;
2968
Sean Callananc7fbf732010-08-06 00:32:49 +00002969 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002970 if (die != NULL)
2971 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002972 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002973 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00002974 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002975 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002976 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002977 if (type_is_new_ptr)
2978 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002979
Greg Clayton594e5ed2010-09-27 21:07:38 +00002980 const dw_tag_t tag = die->Tag();
2981
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002982 bool is_forward_declaration = false;
2983 DWARFDebugInfoEntry::Attributes attributes;
2984 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00002985 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00002986 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
2987 size_t byte_size = 0;
2988 Declaration decl;
2989
Greg Clayton4957bf62010-09-30 21:49:03 +00002990 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002991 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002992
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002993 dw_attr_t attr;
2994
2995 switch (tag)
2996 {
2997 case DW_TAG_base_type:
2998 case DW_TAG_pointer_type:
2999 case DW_TAG_reference_type:
3000 case DW_TAG_typedef:
3001 case DW_TAG_const_type:
3002 case DW_TAG_restrict_type:
3003 case DW_TAG_volatile_type:
3004 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003005 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003006 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003007
Greg Claytond88d7592010-09-15 08:33:30 +00003008 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003009 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003010 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3011
3012 if (num_attributes > 0)
3013 {
3014 uint32_t i;
3015 for (i=0; i<num_attributes; ++i)
3016 {
3017 attr = attributes.AttributeAtIndex(i);
3018 DWARFFormValue form_value;
3019 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3020 {
3021 switch (attr)
3022 {
3023 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3024 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3025 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3026 case DW_AT_name:
3027 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003028 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003029 break;
3030 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3031 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3032 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3033 default:
3034 case DW_AT_sibling:
3035 break;
3036 }
3037 }
3038 }
3039 }
3040
Greg Claytonc93237c2010-10-01 20:48:32 +00003041 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") type => 0x%8.8x\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
3042
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003043 switch (tag)
3044 {
3045 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003046 break;
3047
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003048 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003049 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003050 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3051 encoding,
3052 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003053 break;
3054
Greg Clayton526e5af2010-11-13 03:52:47 +00003055 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3056 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3057 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3058 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3059 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3060 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003061 }
3062
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003063 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3064 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3065 {
3066 static ConstString g_objc_type_name_id("id");
3067 static ConstString g_objc_type_name_Class("Class");
3068 static ConstString g_objc_type_name_selector("SEL");
3069
Greg Clayton24739922010-10-13 03:15:28 +00003070 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003071 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003072 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003073 resolve_state = Type::eResolveStateFull;
3074
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003075 }
Greg Clayton24739922010-10-13 03:15:28 +00003076 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003077 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003078 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003079 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003080 }
Greg Clayton24739922010-10-13 03:15:28 +00003081 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003082 {
Sean Callananf6c73082010-12-06 23:53:20 +00003083 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003084 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003085 }
3086 }
3087
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003088 type_sp.reset( new Type (die->GetOffset(),
3089 this,
3090 type_name_const_str,
3091 byte_size,
3092 NULL,
3093 encoding_uid,
3094 encoding_data_type,
3095 &decl,
3096 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003097 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003098
Greg Clayton594e5ed2010-09-27 21:07:38 +00003099 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003100
3101// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3102// if (encoding_type != NULL)
3103// {
3104// if (encoding_type != DIE_IS_BEING_PARSED)
3105// type_sp->SetEncodingType(encoding_type);
3106// else
3107// m_indirect_fixups.push_back(type_sp.get());
3108// }
3109 }
3110 break;
3111
3112 case DW_TAG_structure_type:
3113 case DW_TAG_union_type:
3114 case DW_TAG_class_type:
3115 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003116 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003117 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003118
Greg Clayton9e409562010-07-28 02:04:09 +00003119 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003120 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003121 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003122 if (num_attributes > 0)
3123 {
3124 uint32_t i;
3125 for (i=0; i<num_attributes; ++i)
3126 {
3127 attr = attributes.AttributeAtIndex(i);
3128 DWARFFormValue form_value;
3129 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3130 {
3131 switch (attr)
3132 {
Greg Clayton9e409562010-07-28 02:04:09 +00003133 case DW_AT_decl_file:
3134 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3135 break;
3136
3137 case DW_AT_decl_line:
3138 decl.SetLine(form_value.Unsigned());
3139 break;
3140
3141 case DW_AT_decl_column:
3142 decl.SetColumn(form_value.Unsigned());
3143 break;
3144
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003145 case DW_AT_name:
3146 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003147 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003148 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003149
3150 case DW_AT_byte_size:
3151 byte_size = form_value.Unsigned();
3152 break;
3153
3154 case DW_AT_accessibility:
3155 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3156 break;
3157
3158 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003159 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003160 break;
3161
3162 case DW_AT_APPLE_runtime_class:
3163 class_language = (LanguageType)form_value.Signed();
3164 break;
3165
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003166 case DW_AT_allocated:
3167 case DW_AT_associated:
3168 case DW_AT_data_location:
3169 case DW_AT_description:
3170 case DW_AT_start_scope:
3171 case DW_AT_visibility:
3172 default:
3173 case DW_AT_sibling:
3174 break;
3175 }
3176 }
3177 }
3178 }
3179
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003180 UniqueDWARFASTType unique_ast_entry;
3181 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003182 {
Greg Claytone576ab22011-02-15 00:19:15 +00003183 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
3184 die,
3185 decl,
3186 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003187 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003188 // We have already parsed this type or from another
3189 // compile unit. GCC loves to use the "one definition
3190 // rule" which can result in multiple definitions
3191 // of the same class over and over in each compile
3192 // unit.
3193 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003194 if (type_sp)
3195 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003196 m_die_to_type[die] = type_sp.get();
3197 return type_sp;
3198 }
3199 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003200 }
3201
3202 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3203
3204 int tag_decl_kind = -1;
3205 AccessType default_accessibility = eAccessNone;
3206 if (tag == DW_TAG_structure_type)
3207 {
3208 tag_decl_kind = clang::TTK_Struct;
3209 default_accessibility = eAccessPublic;
3210 }
3211 else if (tag == DW_TAG_union_type)
3212 {
3213 tag_decl_kind = clang::TTK_Union;
3214 default_accessibility = eAccessPublic;
3215 }
3216 else if (tag == DW_TAG_class_type)
3217 {
3218 tag_decl_kind = clang::TTK_Class;
3219 default_accessibility = eAccessPrivate;
3220 }
3221
3222
3223 if (is_forward_declaration)
3224 {
3225 // We have a forward declaration to a type and we need
3226 // to try and find a full declaration. We look in the
3227 // current type index just in case we have a forward
3228 // declaration followed by an actual declarations in the
3229 // DWARF. If this fails, we need to look elsewhere...
3230
3231 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3232
3233 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00003234 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003235 // We weren't able to find a full declaration in
3236 // this DWARF, see if we have a declaration anywhere
3237 // else...
3238 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00003239 }
3240
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003241 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00003242 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003243 // We found a real definition for this type elsewhere
3244 // so lets use it and cache the fact that we found
3245 // a complete type for this die
3246 m_die_to_type[die] = type_sp.get();
3247 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003248 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003249 }
3250 assert (tag_decl_kind != -1);
3251 bool clang_type_was_created = false;
3252 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3253 if (clang_type == NULL)
3254 {
3255 clang_type_was_created = true;
3256 clang_type = ast.CreateRecordType (type_name_cstr,
3257 tag_decl_kind,
3258 GetClangDeclContextForDIE (dwarf_cu, die),
3259 class_language);
3260 }
3261
3262 // Store a forward declaration to this class type in case any
3263 // parameters in any class methods need it for the clang
3264 // types for function prototypes.
3265 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
3266 type_sp.reset (new Type (die->GetOffset(),
3267 this,
3268 type_name_const_str,
3269 byte_size,
3270 NULL,
3271 LLDB_INVALID_UID,
3272 Type::eEncodingIsUID,
3273 &decl,
3274 clang_type,
3275 Type::eResolveStateForward));
3276
3277
3278 // Add our type to the unique type map so we don't
3279 // end up creating many copies of the same type over
3280 // and over in the ASTContext for our module
3281 unique_ast_entry.m_type_sp = type_sp;
3282 unique_ast_entry.m_die = die;
3283 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00003284 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
3285 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003286
3287 if (die->HasChildren() == false && is_forward_declaration == false)
3288 {
3289 // No children for this struct/union/class, lets finish it
3290 ast.StartTagDeclarationDefinition (clang_type);
3291 ast.CompleteTagDeclarationDefinition (clang_type);
3292 }
3293 else if (clang_type_was_created)
3294 {
3295 // Leave this as a forward declaration until we need
3296 // to know the details of the type. lldb_private::Type
3297 // will automatically call the SymbolFile virtual function
3298 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3299 // When the definition needs to be defined.
3300 m_forward_decl_die_to_clang_type[die] = clang_type;
3301 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
3302 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00003303 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003304 }
3305 break;
3306
3307 case DW_TAG_enumeration_type:
3308 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003309 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003310 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003312 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003313
Greg Claytond88d7592010-09-15 08:33:30 +00003314 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003315 if (num_attributes > 0)
3316 {
3317 uint32_t i;
3318
3319 for (i=0; i<num_attributes; ++i)
3320 {
3321 attr = attributes.AttributeAtIndex(i);
3322 DWARFFormValue form_value;
3323 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3324 {
3325 switch (attr)
3326 {
Greg Clayton7a345282010-11-09 23:46:37 +00003327 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3328 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3329 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003330 case DW_AT_name:
3331 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003332 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003333 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003334 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3335 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3336 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3337 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003338 case DW_AT_allocated:
3339 case DW_AT_associated:
3340 case DW_AT_bit_stride:
3341 case DW_AT_byte_stride:
3342 case DW_AT_data_location:
3343 case DW_AT_description:
3344 case DW_AT_start_scope:
3345 case DW_AT_visibility:
3346 case DW_AT_specification:
3347 case DW_AT_abstract_origin:
3348 case DW_AT_sibling:
3349 break;
3350 }
3351 }
3352 }
3353
Greg Claytonc93237c2010-10-01 20:48:32 +00003354 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3355
Greg Clayton1be10fc2010-09-29 01:12:09 +00003356 clang_type_t enumerator_clang_type = NULL;
3357 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3358 if (clang_type == NULL)
3359 {
Greg Clayton4cd17802011-01-25 06:17:32 +00003360 if (die->GetOffset() == 0x1c436)
3361 printf("REMOVE THIS!!!\n");
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003362 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3363 DW_ATE_signed,
3364 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00003365 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Clayton6beaaa62011-01-17 03:46:26 +00003366 GetClangDeclContextForDIE (dwarf_cu, die),
Greg Claytonca512b32011-01-14 04:54:56 +00003367 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003368 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003369 }
3370 else
3371 {
3372 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3373 assert (enumerator_clang_type != NULL);
3374 }
3375
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003376 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003377 type_sp.reset( new Type (die->GetOffset(),
3378 this,
3379 type_name_const_str,
3380 byte_size,
3381 NULL,
3382 encoding_uid,
3383 Type::eEncodingIsUID,
3384 &decl,
3385 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003386 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003387
Greg Clayton6beaaa62011-01-17 03:46:26 +00003388#if LEAVE_ENUMS_FORWARD_DECLARED
Greg Clayton1be10fc2010-09-29 01:12:09 +00003389 // Leave this as a forward declaration until we need
3390 // to know the details of the type. lldb_private::Type
3391 // will automatically call the SymbolFile virtual function
3392 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3393 // When the definition needs to be defined.
3394 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003395 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003396 ClangASTContext::SetHasExternalStorage (clang_type, true);
3397#else
3398 ast.StartTagDeclarationDefinition (clang_type);
3399 if (die->HasChildren())
3400 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003401 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
3402 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00003403 }
3404 ast.CompleteTagDeclarationDefinition (clang_type);
3405#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003406 }
3407 }
3408 break;
3409
Jim Inghamb0be4422010-08-12 01:20:14 +00003410 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003411 case DW_TAG_subprogram:
3412 case DW_TAG_subroutine_type:
3413 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003414 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003415 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003416
3417 const char *mangled = NULL;
3418 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003419 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003420 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003421 bool is_static = false;
3422 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003423 bool is_explicit = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003424
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003425 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003426 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003427
3428
Greg Claytond88d7592010-09-15 08:33:30 +00003429 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430 if (num_attributes > 0)
3431 {
3432 uint32_t i;
3433 for (i=0; i<num_attributes; ++i)
3434 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003435 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003436 DWARFFormValue form_value;
3437 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3438 {
3439 switch (attr)
3440 {
3441 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3442 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3443 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3444 case DW_AT_name:
3445 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003446 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003447 break;
3448
3449 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3450 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003451 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003452 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003453 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3454 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003455 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3456
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003457 case DW_AT_external:
3458 if (form_value.Unsigned())
3459 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003460 if (storage == clang::SC_None)
3461 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003462 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003463 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003464 }
3465 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003466
3467 case DW_AT_allocated:
3468 case DW_AT_associated:
3469 case DW_AT_address_class:
3470 case DW_AT_artificial:
3471 case DW_AT_calling_convention:
3472 case DW_AT_data_location:
3473 case DW_AT_elemental:
3474 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003475 case DW_AT_frame_base:
3476 case DW_AT_high_pc:
3477 case DW_AT_low_pc:
3478 case DW_AT_object_pointer:
3479 case DW_AT_prototyped:
3480 case DW_AT_pure:
3481 case DW_AT_ranges:
3482 case DW_AT_recursive:
3483 case DW_AT_return_addr:
3484 case DW_AT_segment:
3485 case DW_AT_specification:
3486 case DW_AT_start_scope:
3487 case DW_AT_static_link:
3488 case DW_AT_trampoline:
3489 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003490 case DW_AT_vtable_elem_location:
3491 case DW_AT_abstract_origin:
3492 case DW_AT_description:
3493 case DW_AT_sibling:
3494 break;
3495 }
3496 }
3497 }
Greg Clayton24739922010-10-13 03:15:28 +00003498 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003499
Greg Clayton24739922010-10-13 03:15:28 +00003500 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00003501
Greg Clayton24739922010-10-13 03:15:28 +00003502 clang_type_t return_clang_type = NULL;
3503 Type *func_type = NULL;
3504
3505 if (type_die_offset != DW_INVALID_OFFSET)
3506 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003507
Greg Clayton24739922010-10-13 03:15:28 +00003508 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003509 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003510 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003511 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003512
Greg Claytonf51de672010-10-01 02:31:07 +00003513
Greg Clayton24739922010-10-13 03:15:28 +00003514 std::vector<clang_type_t> function_param_types;
3515 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003516
Greg Clayton24739922010-10-13 03:15:28 +00003517 // Parse the function children for the parameters
3518 if (die->HasChildren())
3519 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003520 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003521 ParseChildParameters (sc,
3522 type_sp,
3523 dwarf_cu,
3524 die,
3525 skip_artificial,
3526 type_list,
3527 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003528 function_param_decls,
3529 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003530 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003531
Greg Clayton24739922010-10-13 03:15:28 +00003532 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003533 clang_type = ast.CreateFunctionType (return_clang_type,
3534 &function_param_types[0],
3535 function_param_types.size(),
3536 is_variadic,
3537 type_quals);
3538
Greg Clayton24739922010-10-13 03:15:28 +00003539 if (type_name_cstr)
3540 {
3541 bool type_handled = false;
3542 const DWARFDebugInfoEntry *parent_die = die->GetParent();
3543 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003544 {
Greg Clayton24739922010-10-13 03:15:28 +00003545 if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
Greg Clayton0fffff52010-09-24 05:15:53 +00003546 {
Greg Clayton24739922010-10-13 03:15:28 +00003547 // We need to find the DW_TAG_class_type or
3548 // DW_TAG_struct_type by name so we can add this
3549 // as a member function of the class.
3550 const char *class_name_start = type_name_cstr + 2;
3551 const char *class_name_end = ::strchr (class_name_start, ' ');
3552 SymbolContext empty_sc;
3553 clang_type_t class_opaque_type = NULL;
3554 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003555 {
Greg Clayton24739922010-10-13 03:15:28 +00003556 ConstString class_name (class_name_start, class_name_end - class_name_start);
3557 TypeList types;
3558 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3559 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003560 {
Greg Clayton24739922010-10-13 03:15:28 +00003561 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003562 {
Greg Clayton24739922010-10-13 03:15:28 +00003563 Type *type = types.GetTypeAtIndex (i).get();
3564 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3565 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003566 {
Greg Clayton24739922010-10-13 03:15:28 +00003567 class_opaque_type = type_clang_forward_type;
3568 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003569 }
3570 }
3571 }
Greg Clayton24739922010-10-13 03:15:28 +00003572 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003573
Greg Clayton24739922010-10-13 03:15:28 +00003574 if (class_opaque_type)
3575 {
3576 // If accessibility isn't set to anything valid, assume public for
3577 // now...
3578 if (accessibility == eAccessNone)
3579 accessibility = eAccessPublic;
3580
3581 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003582 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3583 type_name_cstr,
3584 clang_type,
3585 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00003586 type_handled = objc_method_decl != NULL;
3587 }
3588 }
3589 else if (parent_die->Tag() == DW_TAG_class_type ||
3590 parent_die->Tag() == DW_TAG_structure_type)
3591 {
3592 // Look at the parent of this DIE and see if is is
3593 // a class or struct and see if this is actually a
3594 // C++ method
3595 Type *class_type = ResolveType (dwarf_cu, parent_die);
3596 if (class_type)
3597 {
3598 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3599 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003600 {
Greg Clayton24739922010-10-13 03:15:28 +00003601 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3602 // in the DWARF for C++ methods... Default to public for now...
Greg Clayton6d01ad92010-09-29 01:57:37 +00003603 if (accessibility == eAccessNone)
3604 accessibility = eAccessPublic;
Greg Clayton931180e2011-01-27 06:44:37 +00003605
3606 if (!is_static && !die->HasChildren())
3607 {
3608 // We have a C++ member function with no children (this pointer!)
3609 // and clang will get mad if we try and make a function that isn't
3610 // well formed in the DWARF, so we will just skip it...
3611 type_handled = true;
3612 }
3613 else
3614 {
3615 clang::CXXMethodDecl *cxx_method_decl;
3616 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3617 type_name_cstr,
3618 clang_type,
3619 accessibility,
3620 is_virtual,
3621 is_static,
3622 is_inline,
3623 is_explicit);
3624 type_handled = cxx_method_decl != NULL;
3625 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003626 }
3627 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003628 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003629 }
Greg Clayton24739922010-10-13 03:15:28 +00003630
3631 if (!type_handled)
3632 {
3633 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003634 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3635 clang_type,
3636 storage,
3637 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003638
3639 // Add the decl to our DIE to decl context map
3640 assert (function_decl);
3641 m_die_to_decl_ctx[die] = function_decl;
3642 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003643 ast.SetFunctionParameters (function_decl,
3644 &function_param_decls.front(),
3645 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003646 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003647 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003648 type_sp.reset( new Type (die->GetOffset(),
3649 this,
3650 type_name_const_str,
3651 0,
3652 NULL,
3653 LLDB_INVALID_UID,
3654 Type::eEncodingIsUID,
3655 &decl,
3656 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003657 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00003658 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003659 }
3660 break;
3661
3662 case DW_TAG_array_type:
3663 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003664 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003665 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003666
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003667 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003668 int64_t first_index = 0;
3669 uint32_t byte_stride = 0;
3670 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003671 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003672
3673 if (num_attributes > 0)
3674 {
3675 uint32_t i;
3676 for (i=0; i<num_attributes; ++i)
3677 {
3678 attr = attributes.AttributeAtIndex(i);
3679 DWARFFormValue form_value;
3680 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3681 {
3682 switch (attr)
3683 {
3684 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3685 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3686 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3687 case DW_AT_name:
3688 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003689 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003690 break;
3691
3692 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
3693 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3694 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3695 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003696 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003697 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003698 case DW_AT_allocated:
3699 case DW_AT_associated:
3700 case DW_AT_data_location:
3701 case DW_AT_description:
3702 case DW_AT_ordering:
3703 case DW_AT_start_scope:
3704 case DW_AT_visibility:
3705 case DW_AT_specification:
3706 case DW_AT_abstract_origin:
3707 case DW_AT_sibling:
3708 break;
3709 }
3710 }
3711 }
3712
Greg Claytonc93237c2010-10-01 20:48:32 +00003713 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003715 Type *element_type = ResolveTypeUID(type_die_offset);
3716
3717 if (element_type)
3718 {
3719 std::vector<uint64_t> element_orders;
3720 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00003721 // We have an array that claims to have no members, lets give it at least one member...
3722 if (element_orders.empty())
3723 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003724 if (byte_stride == 0 && bit_stride == 0)
3725 byte_stride = element_type->GetByteSize();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003726 clang_type_t array_element_type = element_type->GetClangType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003727 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3728 uint64_t num_elements = 0;
3729 std::vector<uint64_t>::const_reverse_iterator pos;
3730 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3731 for (pos = element_orders.rbegin(); pos != end; ++pos)
3732 {
3733 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003734 clang_type = ast.CreateArrayType (array_element_type,
3735 num_elements,
3736 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003737 array_element_type = clang_type;
3738 array_element_bit_stride = array_element_bit_stride * num_elements;
3739 }
3740 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003741 type_sp.reset( new Type (die->GetOffset(),
3742 this,
3743 empty_name,
3744 array_element_bit_stride / 8,
3745 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00003746 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003747 Type::eEncodingIsUID,
3748 &decl,
3749 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003750 Type::eResolveStateFull));
3751 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003752 }
3753 }
3754 }
3755 break;
3756
Greg Clayton9b81a312010-06-12 01:20:30 +00003757 case DW_TAG_ptr_to_member_type:
3758 {
3759 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3760 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3761
Greg Claytond88d7592010-09-15 08:33:30 +00003762 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00003763
3764 if (num_attributes > 0) {
3765 uint32_t i;
3766 for (i=0; i<num_attributes; ++i)
3767 {
3768 attr = attributes.AttributeAtIndex(i);
3769 DWARFFormValue form_value;
3770 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3771 {
3772 switch (attr)
3773 {
3774 case DW_AT_type:
3775 type_die_offset = form_value.Reference(dwarf_cu); break;
3776 case DW_AT_containing_type:
3777 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3778 }
3779 }
3780 }
3781
3782 Type *pointee_type = ResolveTypeUID(type_die_offset);
3783 Type *class_type = ResolveTypeUID(containing_type_die_offset);
3784
Greg Clayton526e5af2010-11-13 03:52:47 +00003785 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
3786 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00003787
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003788 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
3789 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00003790
Greg Clayton526e5af2010-11-13 03:52:47 +00003791 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
3792 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00003793
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003794 type_sp.reset( new Type (die->GetOffset(),
3795 this,
3796 type_name_const_str,
3797 byte_size,
3798 NULL,
3799 LLDB_INVALID_UID,
3800 Type::eEncodingIsUID,
3801 NULL,
3802 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003803 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00003804 }
3805
3806 break;
3807 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003808 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00003809 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003810 break;
3811 }
3812
3813 if (type_sp.get())
3814 {
3815 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3816 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3817
3818 SymbolContextScope * symbol_context_scope = NULL;
3819 if (sc_parent_tag == DW_TAG_compile_unit)
3820 {
3821 symbol_context_scope = sc.comp_unit;
3822 }
3823 else if (sc.function != NULL)
3824 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003825 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003826 if (symbol_context_scope == NULL)
3827 symbol_context_scope = sc.function;
3828 }
3829
3830 if (symbol_context_scope != NULL)
3831 {
3832 type_sp->SetSymbolContextScope(symbol_context_scope);
3833 }
3834
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003835 // We are ready to put this type into the uniqued list up at the module level
3836 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00003837
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003838 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003839 }
3840 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00003841 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003842 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003843 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003844 }
3845 }
3846 return type_sp;
3847}
3848
3849size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003850SymbolFileDWARF::ParseTypes
3851(
3852 const SymbolContext& sc,
3853 DWARFCompileUnit* dwarf_cu,
3854 const DWARFDebugInfoEntry *die,
3855 bool parse_siblings,
3856 bool parse_children
3857)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003858{
3859 size_t types_added = 0;
3860 while (die != NULL)
3861 {
3862 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003863 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003864 {
3865 if (type_is_new)
3866 ++types_added;
3867 }
3868
3869 if (parse_children && die->HasChildren())
3870 {
3871 if (die->Tag() == DW_TAG_subprogram)
3872 {
3873 SymbolContext child_sc(sc);
3874 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
3875 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
3876 }
3877 else
3878 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
3879 }
3880
3881 if (parse_siblings)
3882 die = die->GetSibling();
3883 else
3884 die = NULL;
3885 }
3886 return types_added;
3887}
3888
3889
3890size_t
3891SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3892{
3893 assert(sc.comp_unit && sc.function);
3894 size_t functions_added = 0;
3895 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3896 if (dwarf_cu)
3897 {
3898 dw_offset_t function_die_offset = sc.function->GetID();
3899 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
3900 if (function_die)
3901 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003902 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, false, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003903 }
3904 }
3905
3906 return functions_added;
3907}
3908
3909
3910size_t
3911SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3912{
3913 // At least a compile unit must be valid
3914 assert(sc.comp_unit);
3915 size_t types_added = 0;
3916 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3917 if (dwarf_cu)
3918 {
3919 if (sc.function)
3920 {
3921 dw_offset_t function_die_offset = sc.function->GetID();
3922 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
3923 if (func_die && func_die->HasChildren())
3924 {
3925 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
3926 }
3927 }
3928 else
3929 {
3930 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
3931 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
3932 {
3933 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
3934 }
3935 }
3936 }
3937
3938 return types_added;
3939}
3940
3941size_t
3942SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3943{
3944 if (sc.comp_unit != NULL)
3945 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00003946 DWARFDebugInfo* info = DebugInfo();
3947 if (info == NULL)
3948 return 0;
3949
3950 uint32_t cu_idx = UINT32_MAX;
3951 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003952
3953 if (dwarf_cu == NULL)
3954 return 0;
3955
3956 if (sc.function)
3957 {
3958 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00003959
3960 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
3961 assert (func_lo_pc != DW_INVALID_ADDRESS);
3962
3963 return ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003964 }
3965 else if (sc.comp_unit)
3966 {
3967 uint32_t vars_added = 0;
3968 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3969
3970 if (variables.get() == NULL)
3971 {
3972 variables.reset(new VariableList());
3973 sc.comp_unit->SetVariableList(variables);
3974
3975 // Index if we already haven't to make sure the compile units
3976 // get indexed and make their global DIE index list
3977 if (!m_indexed)
3978 Index ();
3979
Greg Claytonc685f8e2010-09-15 04:15:46 +00003980 std::vector<NameToDIE::Info> global_die_info_array;
Greg Clayton4b3dc102010-11-01 20:32:12 +00003981 const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003982 for (size_t idx=0; idx<num_globals; ++idx)
3983 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00003984 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003985 if (var_sp)
3986 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00003987 variables->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003988 ++vars_added;
3989 }
3990 }
3991 }
3992 return vars_added;
3993 }
3994 }
3995 return 0;
3996}
3997
3998
3999VariableSP
4000SymbolFileDWARF::ParseVariableDIE
4001(
4002 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004003 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004004 const DWARFDebugInfoEntry *die,
4005 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004006)
4007{
4008
Greg Clayton83c5cd92010-11-14 22:13:40 +00004009 VariableSP var_sp (m_die_to_variable_sp[die]);
4010 if (var_sp)
4011 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004012
4013 const dw_tag_t tag = die->Tag();
4014 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004015 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004016 if (num_attributes > 0)
4017 {
4018 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00004019 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004020 Declaration decl;
4021 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004022 Type *var_type = NULL;
4023 DWARFExpression location;
4024 bool is_external = false;
4025 bool is_artificial = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00004026 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004027
4028 for (i=0; i<num_attributes; ++i)
4029 {
4030 dw_attr_t attr = attributes.AttributeAtIndex(i);
4031 DWARFFormValue form_value;
4032 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4033 {
4034 switch (attr)
4035 {
4036 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4037 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4038 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4039 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00004040 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00004041 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004042 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
4043 case DW_AT_location:
4044 {
4045 if (form_value.BlockData())
4046 {
4047 const DataExtractor& debug_info_data = get_debug_info_data();
4048
4049 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4050 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00004051 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004052 }
4053 else
4054 {
4055 const DataExtractor& debug_loc_data = get_debug_loc_data();
4056 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4057
4058 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4059 if (loc_list_length > 0)
4060 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004061 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
4062 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4063 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004064 }
4065 }
4066 }
4067 break;
4068
4069 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004070 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004071 case DW_AT_const_value:
4072 case DW_AT_declaration:
4073 case DW_AT_description:
4074 case DW_AT_endianity:
4075 case DW_AT_segment:
4076 case DW_AT_start_scope:
4077 case DW_AT_visibility:
4078 default:
4079 case DW_AT_abstract_origin:
4080 case DW_AT_sibling:
4081 case DW_AT_specification:
4082 break;
4083 }
4084 }
4085 }
4086
4087 if (location.IsValid())
4088 {
4089 assert(var_type != DIE_IS_BEING_PARSED);
4090
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004091 ValueType scope = eValueTypeInvalid;
4092
4093 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4094 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4095
4096 if (tag == DW_TAG_formal_parameter)
4097 scope = eValueTypeVariableArgument;
4098 else if (is_external || parent_tag == DW_TAG_compile_unit)
4099 scope = eValueTypeVariableGlobal;
4100 else
4101 scope = eValueTypeVariableLocal;
4102
4103 SymbolContextScope * symbol_context_scope = NULL;
4104 if (parent_tag == DW_TAG_compile_unit)
4105 {
4106 symbol_context_scope = sc.comp_unit;
4107 }
4108 else if (sc.function != NULL)
4109 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004110 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004111 if (symbol_context_scope == NULL)
4112 symbol_context_scope = sc.function;
4113 }
4114
4115 assert(symbol_context_scope != NULL);
4116 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00004117 name,
4118 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004119 var_type,
4120 scope,
4121 symbol_context_scope,
4122 &decl,
4123 location,
4124 is_external,
4125 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00004126
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004127 }
4128 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00004129 // Cache var_sp even if NULL (the variable was just a specification or
4130 // was missing vital information to be able to be displayed in the debugger
4131 // (missing location due to optimization, etc)) so we don't re-parse
4132 // this DIE over and over later...
4133 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004134 return var_sp;
4135}
4136
4137size_t
4138SymbolFileDWARF::ParseVariables
4139(
4140 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004141 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004142 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004143 const DWARFDebugInfoEntry *orig_die,
4144 bool parse_siblings,
4145 bool parse_children,
4146 VariableList* cc_variable_list
4147)
4148{
4149 if (orig_die == NULL)
4150 return 0;
4151
4152 size_t vars_added = 0;
4153 const DWARFDebugInfoEntry *die = orig_die;
4154 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4155 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4156 VariableListSP variables;
4157 switch (parent_tag)
4158 {
4159 case DW_TAG_compile_unit:
4160 if (sc.comp_unit != NULL)
4161 {
4162 variables = sc.comp_unit->GetVariableList(false);
4163 if (variables.get() == NULL)
4164 {
4165 variables.reset(new VariableList());
4166 sc.comp_unit->SetVariableList(variables);
4167 }
4168 }
4169 else
4170 {
4171 assert(!"Parent DIE was a compile unit, yet we don't have a valid compile unit in the symbol context...");
4172 vars_added = 0;
4173 }
4174 break;
4175
4176 case DW_TAG_subprogram:
4177 case DW_TAG_inlined_subroutine:
4178 case DW_TAG_lexical_block:
4179 if (sc.function != NULL)
4180 {
4181 // Check to see if we already have parsed the variables for the given scope
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004182
4183 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
4184 assert (block != NULL);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004185 variables = block->GetVariableList(false, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004186 if (variables.get() == NULL)
4187 {
4188 variables.reset(new VariableList());
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004189 block->SetVariableList(variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004190 }
4191 }
4192 else
4193 {
4194 assert(!"Parent DIE was a function or block, yet we don't have a function in the symbol context...");
4195 vars_added = 0;
4196 }
4197 break;
4198
4199 default:
4200 assert(!"Didn't find appropriate parent DIE for variable list...");
4201 break;
4202 }
4203
4204 // We need to have a variable list at this point that we can add variables to
4205 assert(variables.get());
4206
4207 while (die != NULL)
4208 {
4209 dw_tag_t tag = die->Tag();
4210
4211 // Check to see if we have already parsed this variable or constant?
Greg Claytonbcf12172010-10-28 00:56:11 +00004212 if (m_die_to_variable_sp[die])
4213 {
4214 if (cc_variable_list)
Greg Clayton83c5cd92010-11-14 22:13:40 +00004215 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Greg Claytonbcf12172010-10-28 00:56:11 +00004216 }
4217 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218 {
4219 // We haven't already parsed it, lets do that now.
4220 if ((tag == DW_TAG_variable) ||
4221 (tag == DW_TAG_constant) ||
4222 (tag == DW_TAG_formal_parameter && sc.function))
4223 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004224 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004225 if (var_sp)
4226 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00004227 variables->AddVariableIfUnique (var_sp);
Greg Claytonbcf12172010-10-28 00:56:11 +00004228 if (cc_variable_list)
Greg Clayton83c5cd92010-11-14 22:13:40 +00004229 cc_variable_list->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004230 ++vars_added;
4231 }
4232 }
4233 }
4234
4235 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4236
4237 if (!skip_children && parse_children && die->HasChildren())
4238 {
Greg Claytonbcf12172010-10-28 00:56:11 +00004239 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004240 }
4241
4242 if (parse_siblings)
4243 die = die->GetSibling();
4244 else
4245 die = NULL;
4246 }
4247
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004248 return vars_added;
4249}
4250
4251//------------------------------------------------------------------
4252// PluginInterface protocol
4253//------------------------------------------------------------------
4254const char *
4255SymbolFileDWARF::GetPluginName()
4256{
4257 return "SymbolFileDWARF";
4258}
4259
4260const char *
4261SymbolFileDWARF::GetShortPluginName()
4262{
4263 return GetPluginNameStatic();
4264}
4265
4266uint32_t
4267SymbolFileDWARF::GetPluginVersion()
4268{
4269 return 1;
4270}
4271
4272void
4273SymbolFileDWARF::GetPluginCommandHelp (const char *command, Stream *strm)
4274{
4275}
4276
4277Error
4278SymbolFileDWARF::ExecutePluginCommand (Args &command, Stream *strm)
4279{
4280 Error error;
4281 error.SetErrorString("No plug-in command are currently supported.");
4282 return error;
4283}
4284
4285Log *
4286SymbolFileDWARF::EnablePluginLogging (Stream *strm, Args &command)
4287{
4288 return NULL;
4289}
4290
Greg Clayton6beaaa62011-01-17 03:46:26 +00004291void
4292SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
4293{
4294 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4295 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4296 if (clang_type)
4297 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4298}
4299
4300void
4301SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
4302{
4303 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4304 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4305 if (clang_type)
4306 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4307}
4308