blob: d3082fe9b74dc8be9055dc212ddfbdddfba9ba0a [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"
23
24#include "lldb/Core/Module.h"
25#include "lldb/Core/PluginManager.h"
26#include "lldb/Core/RegularExpression.h"
27#include "lldb/Core/Scalar.h"
28#include "lldb/Core/Section.h"
29#include "lldb/Core/Timer.h"
30#include "lldb/Core/Value.h"
31
32#include "lldb/Symbol/Block.h"
33#include "lldb/Symbol/CompileUnit.h"
34#include "lldb/Symbol/LineTable.h"
35#include "lldb/Symbol/ObjectFile.h"
36#include "lldb/Symbol/SymbolVendor.h"
37#include "lldb/Symbol/VariableList.h"
38
39#include "DWARFCompileUnit.h"
40#include "DWARFDebugAbbrev.h"
41#include "DWARFDebugAranges.h"
42#include "DWARFDebugInfo.h"
43#include "DWARFDebugInfoEntry.h"
44#include "DWARFDebugLine.h"
45#include "DWARFDebugPubnames.h"
46#include "DWARFDebugRanges.h"
47#include "DWARFDIECollection.h"
48#include "DWARFFormValue.h"
49#include "DWARFLocationList.h"
50#include "LogChannelDWARF.h"
51
52#include <map>
53
54#define DIE_IS_BEING_PARSED ((void*)1)
55
56using namespace lldb;
57using namespace lldb_private;
58
59
Greg Clayton8cf05932010-07-22 18:30:50 +000060static ClangASTContext::AccessType
61DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062{
63 switch (dwarf_accessibility)
64 {
Greg Clayton8cf05932010-07-22 18:30:50 +000065 case DW_ACCESS_public: return ClangASTContext::eAccessPublic;
66 case DW_ACCESS_private: return ClangASTContext::eAccessPrivate;
67 case DW_ACCESS_protected: return ClangASTContext::eAccessProtected;
68 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 }
Greg Clayton8cf05932010-07-22 18:30:50 +000070 return ClangASTContext::eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071}
72
73void
74SymbolFileDWARF::Initialize()
75{
76 LogChannelDWARF::Initialize();
77 PluginManager::RegisterPlugin (GetPluginNameStatic(),
78 GetPluginDescriptionStatic(),
79 CreateInstance);
80}
81
82void
83SymbolFileDWARF::Terminate()
84{
85 PluginManager::UnregisterPlugin (CreateInstance);
86 LogChannelDWARF::Initialize();
87}
88
89
90const char *
91SymbolFileDWARF::GetPluginNameStatic()
92{
93 return "symbol-file.dwarf2";
94}
95
96const char *
97SymbolFileDWARF::GetPluginDescriptionStatic()
98{
99 return "DWARF and DWARF3 debug symbol file reader.";
100}
101
102
103SymbolFile*
104SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
105{
106 return new SymbolFileDWARF(obj_file);
107}
108
109//----------------------------------------------------------------------
110// Gets the first parent that is a lexical block, function or inlined
111// subroutine, or compile unit.
112//----------------------------------------------------------------------
113static const DWARFDebugInfoEntry *
114GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
115{
116 const DWARFDebugInfoEntry *die;
117 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
118 {
119 dw_tag_t tag = die->Tag();
120
121 switch (tag)
122 {
123 case DW_TAG_compile_unit:
124 case DW_TAG_subprogram:
125 case DW_TAG_inlined_subroutine:
126 case DW_TAG_lexical_block:
127 return die;
128 }
129 }
130 return NULL;
131}
132
133
134SymbolFileDWARF::SymbolFileDWARF(ObjectFile* ofile) :
135 SymbolFile(ofile),
136 m_flags(),
137 m_data_debug_abbrev(),
138 m_data_debug_aranges(),
139 m_data_debug_frame(),
140 m_data_debug_info(),
141 m_data_debug_line(),
142 m_data_debug_loc(),
143 m_data_debug_macinfo(),
144 m_data_debug_pubnames(),
145 m_data_debug_pubtypes(),
146 m_data_debug_ranges(),
147 m_data_debug_str(),
148 m_abbr(),
149 m_aranges(),
150 m_info(),
151 m_line(),
Greg Clayton0c5cd902010-06-28 21:30:43 +0000152 m_base_name_to_function_die(),
153 m_full_name_to_function_die(),
154 m_method_name_to_function_die(),
155 m_selector_name_to_function_die(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 m_name_to_global_die(),
157 m_name_to_type_die(),
158 m_indexed(false),
159// m_pubnames(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160// m_pubbasetypes(),
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000161 m_pubtypes(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 m_ranges()//,
163// m_type_fixups(),
164// m_indirect_fixups()
165{
166}
167
168SymbolFileDWARF::~SymbolFileDWARF()
169{
170}
171
172bool
173SymbolFileDWARF::SupportedVersion(uint16_t version)
174{
175 return version == 2 || version == 3;
176}
177
178uint32_t
179SymbolFileDWARF::GetAbilities ()
180{
181 uint32_t abilities = 0;
182 if (m_obj_file != NULL)
183 {
184 const Section* section = NULL;
185 const SectionList *section_list = m_obj_file->GetSectionList();
186 if (section_list == NULL)
187 return 0;
188
189 uint64_t debug_abbrev_file_size = 0;
190 uint64_t debug_aranges_file_size = 0;
191 uint64_t debug_frame_file_size = 0;
192 uint64_t debug_info_file_size = 0;
193 uint64_t debug_line_file_size = 0;
194 uint64_t debug_loc_file_size = 0;
195 uint64_t debug_macinfo_file_size = 0;
196 uint64_t debug_pubnames_file_size = 0;
197 uint64_t debug_pubtypes_file_size = 0;
198 uint64_t debug_ranges_file_size = 0;
199 uint64_t debug_str_file_size = 0;
200
201 static ConstString g_dwarf_section_name ("__DWARF");
202
203 section = section_list->FindSectionByName(g_dwarf_section_name).get();
204
205 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000206 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
Greg Clayton4ceb9982010-07-21 22:54:26 +0000208 section_list = &section->GetChildren ();
209 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210
Greg Clayton4ceb9982010-07-21 22:54:26 +0000211 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 if (section != NULL)
213 {
214 debug_info_file_size = section->GetByteSize();
215
Greg Clayton4ceb9982010-07-21 22:54:26 +0000216 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217 if (section)
218 debug_abbrev_file_size = section->GetByteSize();
219 else
220 m_flags.Set (flagsGotDebugAbbrevData);
221
Greg Clayton4ceb9982010-07-21 22:54:26 +0000222 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223 if (section)
224 debug_aranges_file_size = section->GetByteSize();
225 else
226 m_flags.Set (flagsGotDebugArangesData);
227
Greg Clayton4ceb9982010-07-21 22:54:26 +0000228 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229 if (section)
230 debug_frame_file_size = section->GetByteSize();
231 else
232 m_flags.Set (flagsGotDebugFrameData);
233
Greg Clayton4ceb9982010-07-21 22:54:26 +0000234 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 if (section)
236 debug_line_file_size = section->GetByteSize();
237 else
238 m_flags.Set (flagsGotDebugLineData);
239
Greg Clayton4ceb9982010-07-21 22:54:26 +0000240 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241 if (section)
242 debug_loc_file_size = section->GetByteSize();
243 else
244 m_flags.Set (flagsGotDebugLocData);
245
Greg Clayton4ceb9982010-07-21 22:54:26 +0000246 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247 if (section)
248 debug_macinfo_file_size = section->GetByteSize();
249 else
250 m_flags.Set (flagsGotDebugMacInfoData);
251
Greg Clayton4ceb9982010-07-21 22:54:26 +0000252 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253 if (section)
254 debug_pubnames_file_size = section->GetByteSize();
255 else
256 m_flags.Set (flagsGotDebugPubNamesData);
257
Greg Clayton4ceb9982010-07-21 22:54:26 +0000258 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 if (section)
260 debug_pubtypes_file_size = section->GetByteSize();
261 else
262 m_flags.Set (flagsGotDebugPubTypesData);
263
Greg Clayton4ceb9982010-07-21 22:54:26 +0000264 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 if (section)
266 debug_ranges_file_size = section->GetByteSize();
267 else
268 m_flags.Set (flagsGotDebugRangesData);
269
Greg Clayton4ceb9982010-07-21 22:54:26 +0000270 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 if (section)
272 debug_str_file_size = section->GetByteSize();
273 else
274 m_flags.Set (flagsGotDebugStrData);
275 }
276
277 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
278 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
279
280 if (debug_line_file_size > 0)
281 abilities |= LineTables;
282
283 if (debug_aranges_file_size > 0)
284 abilities |= AddressAcceleratorTable;
285
286 if (debug_pubnames_file_size > 0)
287 abilities |= FunctionAcceleratorTable;
288
289 if (debug_pubtypes_file_size > 0)
290 abilities |= TypeAcceleratorTable;
291
292 if (debug_macinfo_file_size > 0)
293 abilities |= MacroInformation;
294
295 if (debug_frame_file_size > 0)
296 abilities |= CallFrameInformation;
297 }
298 return abilities;
299}
300
301const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000302SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303{
304 if (m_flags.IsClear (got_flag))
305 {
306 m_flags.Set (got_flag);
307 const SectionList *section_list = m_obj_file->GetSectionList();
308 if (section_list)
309 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000310 Section *section = section_list->FindSectionByType(sect_type, true).get();
311 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312 {
313 // See if we memory mapped the DWARF segment?
314 if (m_dwarf_data.GetByteSize())
315 {
316 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
317 }
318 else
319 {
320 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
321 data.Clear();
322 }
323 }
324 }
325 }
326 return data;
327}
328
329const DataExtractor&
330SymbolFileDWARF::get_debug_abbrev_data()
331{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000332 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333}
334
335const DataExtractor&
336SymbolFileDWARF::get_debug_aranges_data()
337{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000338 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000339}
340
341const DataExtractor&
342SymbolFileDWARF::get_debug_frame_data()
343{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000344 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000345}
346
347const DataExtractor&
348SymbolFileDWARF::get_debug_info_data()
349{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000350 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
353const DataExtractor&
354SymbolFileDWARF::get_debug_line_data()
355{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000356 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000357}
358
359const DataExtractor&
360SymbolFileDWARF::get_debug_loc_data()
361{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000362 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365const DataExtractor&
366SymbolFileDWARF::get_debug_macinfo_data()
367{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000368 return GetCachedSectionData (flagsGotDebugMacInfoData, eSectionTypeDWARFDebugMacInfo, m_data_debug_macinfo);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369}
370
371const DataExtractor&
372SymbolFileDWARF::get_debug_pubnames_data()
373{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000374 return GetCachedSectionData (flagsGotDebugPubNamesData, eSectionTypeDWARFDebugPubNames, m_data_debug_pubnames);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375}
376
377const DataExtractor&
378SymbolFileDWARF::get_debug_pubtypes_data()
379{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000380 return GetCachedSectionData (flagsGotDebugPubTypesData, eSectionTypeDWARFDebugPubTypes, m_data_debug_pubtypes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381}
382
383const DataExtractor&
384SymbolFileDWARF::get_debug_ranges_data()
385{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000386 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387}
388
389const DataExtractor&
390SymbolFileDWARF::get_debug_str_data()
391{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000392 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393}
394
395
396DWARFDebugAbbrev*
397SymbolFileDWARF::DebugAbbrev()
398{
399 if (m_abbr.get() == NULL)
400 {
401 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
402 if (debug_abbrev_data.GetByteSize() > 0)
403 {
404 m_abbr.reset(new DWARFDebugAbbrev());
405 if (m_abbr.get())
406 m_abbr->Parse(debug_abbrev_data);
407 }
408 }
409 return m_abbr.get();
410}
411
412const DWARFDebugAbbrev*
413SymbolFileDWARF::DebugAbbrev() const
414{
415 return m_abbr.get();
416}
417
418DWARFDebugAranges*
419SymbolFileDWARF::DebugAranges()
420{
421 if (m_aranges.get() == NULL)
422 {
423 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
424 m_aranges.reset(new DWARFDebugAranges());
425 if (m_aranges.get())
426 {
427 const DataExtractor &debug_aranges_data = get_debug_aranges_data();
428 if (debug_aranges_data.GetByteSize() > 0)
429 m_aranges->Extract(debug_aranges_data);
430 else
431 m_aranges->Generate(this);
432 }
433 }
434 return m_aranges.get();
435}
436
437const DWARFDebugAranges*
438SymbolFileDWARF::DebugAranges() const
439{
440 return m_aranges.get();
441}
442
443
444DWARFDebugInfo*
445SymbolFileDWARF::DebugInfo()
446{
447 if (m_info.get() == NULL)
448 {
449 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
450 if (get_debug_info_data().GetByteSize() > 0)
451 {
452 m_info.reset(new DWARFDebugInfo());
453 if (m_info.get())
454 {
455 m_info->SetDwarfData(this);
456 }
457 }
458 }
459 return m_info.get();
460}
461
462const DWARFDebugInfo*
463SymbolFileDWARF::DebugInfo() const
464{
465 return m_info.get();
466}
467
468//DWARFDebugLine*
469//SymbolFileDWARF::DebugLine()
470//{
471// if (m_line.get() == NULL)
472// {
473// Timer scoped_timer(__PRETTY_FUNCTION__);
474// const DataExtractor &debug_line_data = debug_line();
475// if (debug_line_data.GetByteSize() > 0)
476// {
477// m_line.reset(new DWARFDebugLine());
478// if (m_line.get())
479// m_line->Parse(debug_line_data);
480// }
481// }
482// return m_line.get();
483//}
484//
485//const DWARFDebugLine*
486//SymbolFileDWARF::DebugLine() const
487//{
488// return m_line.get();
489//}
490
491
492DWARFCompileUnit*
493SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
494{
495 DWARFDebugInfo* info = DebugInfo();
496 if (info)
497 return info->GetCompileUnit(cu_uid).get();
498 return NULL;
499}
500
501//DWARFCompileUnit*
502//SymbolFileDWARF::GetNextUnparsedDWARFCompileUnit(DWARFCompileUnit* prev_cu)
503//{
504// DWARFCompileUnit* cu = NULL;
505// DWARFDebugInfo* info = DebugInfo();
506// if (info)
507// {
508// uint32_t cu_idx = 0;
509// if (prev_cu != NULL)
510// {
511// // Find the index of the previus DWARF compile unit if one was provided
512// while ((cu = info->GetCompileUnitAtIndex(cu_idx)) != NULL)
513// {
514// ++cu_idx;
515// if (cu == prev_cu)
516// break;
517// }
518// }
519//
520// // Now find the next unparsed DWARF compile unit. We do this by checking the
521// // user data in the DWARFCompileUnit class that starts as NULL, and eventually
522// // holds a pointer to the CompileUnit that was created for it after it has
523// // been parsed.
524// while ((cu = info->GetCompileUnitAtIndex(cu_idx)) != NULL)
525// {
526// if (cu->GetUserData() == NULL)
527// break;
528// }
529// }
530// return cu;
531//}
532
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}
554//
555//DWARFDebugPubnames*
556//SymbolFileDWARF::DebugPubnames()
557//{
558// if (m_pubnames.get() == NULL)
559// {
560// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
561// const DataExtractor &debug_pubnames_data = get_debug_pubnames_data();
562// if (debug_pubnames_data.GetByteSize() > 0)
563// {
564// // Pass false to indicate this is a pubnames section
565// m_pubnames.reset(new DWARFDebugPubnames());
566// if (m_pubnames.get())
567// {
568// // "m_pubnames->GeneratePubnames" is costly, but needed for global variables
569// m_pubnames->GeneratePubnames(this);
570//
571//#if 0
572// StreamFile s(stdout);
573// s.Printf (".debug_pubnames for %s/%s:\n",
574// m_obj_file->GetModule()->GetFileSpec().GetDirectory().AsCString(),
575// m_obj_file->GetModule()->GetFileSpec().GetFilename().AsCString());
576// m_pubnames->Dump (&s);
577//#endif
578// // "m_pubnames->Extract" is quicker, but the pubnames don't always contain what we need.
579// //m_pubnames->Extract(debug_pubnames_data);
580// }
581// }
582// }
583// return m_pubnames.get();
584//}
585//
586//const DWARFDebugPubnames*
587//SymbolFileDWARF::DebugPubnames() const
588//{
589// return m_pubnames.get();
590//}
591
592//DWARFDebugPubnames*
593//SymbolFileDWARF::DebugPubBaseTypes()
594//{
595// if (m_pubbasetypes.get() == NULL)
596// {
597// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
598// // Pass false to indicate this is a pubnames section
599// m_pubbasetypes.reset(new DWARFDebugPubnames());
600// if (m_pubbasetypes.get())
601// m_pubbasetypes->GeneratePubBaseTypes(this);
602// }
603// return m_pubbasetypes.get();
604//}
605//
606//const DWARFDebugPubnames*
607//SymbolFileDWARF::DebugPubBaseTypes() const
608//{
609// return m_pubbasetypes.get();
610//}
611//
612//const DWARFDebugPubnames*
613//SymbolFileDWARF::DebugPubtypes() const
614//{
615// return m_pubtypes.get();
616//}
617//
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000618DWARFDebugPubnames*
619SymbolFileDWARF::DebugPubtypes()
620{
621 if (m_pubtypes.get() == NULL)
622 {
623 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
624 const DataExtractor &debug_pubtypes_data = get_debug_pubtypes_data();
625 if (debug_pubtypes_data.GetByteSize() > 0)
626 {
627 // Pass false to indicate this is a pubnames section
628 m_pubtypes.reset(new DWARFDebugPubnames());
629 if (m_pubtypes.get())
630 m_pubtypes->Extract(debug_pubtypes_data);
631 }
632 }
633 return m_pubtypes.get();
634}
635
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636
637bool
638SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit* cu, CompUnitSP& compile_unit_sp)
639{
640 if (cu != NULL)
641 {
642 const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly ();
643 if (cu_die)
644 {
645 const char * cu_die_name = cu_die->GetName(this, cu);
646 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL);
Greg Clayton9e409562010-07-28 02:04:09 +0000647 LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 if (cu_die_name)
649 {
650 if (cu_die_name[0] == '/' || cu_comp_dir == NULL && cu_comp_dir[0])
651 {
Greg Clayton9e409562010-07-28 02:04:09 +0000652 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), cu, cu_die_name, cu->GetOffset(), class_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 }
654 else
655 {
656 std::string fullpath(cu_comp_dir);
657 if (*fullpath.rbegin() != '/')
658 fullpath += '/';
659 fullpath += cu_die_name;
660
Greg Clayton9e409562010-07-28 02:04:09 +0000661 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), cu, fullpath.c_str(), cu->GetOffset(), class_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662 }
663
664 if (compile_unit_sp.get())
665 {
666 cu->SetUserData(compile_unit_sp.get());
667 return true;
668 }
669 }
670 }
671 }
672 return false;
673}
674
675#if defined LLDB_SYMBOL_FILE_DWARF_SHRINK_TEST
676
677void
678SymbolFileDWARF::ShrinkDSYM(CompileUnit *dc_cu, DWARFCompileUnit *dw_cu, const FileSpec& cu_fspec, const FileSpec& base_types_fspec, FSToDIES& fs_to_dies, const DWARFDebugInfoEntry *die)
679{
680 while (die != NULL)
681 {
682 dw_tag_t tag = die->Tag();
683
684 switch (tag)
685 {
686 case DW_TAG_base_type:
687 // Put all base types into the base type compile unit
688 fs_to_dies[base_types_fspec].Insert(die);
689 break;
690
691 default:
692 {
693 uint32_t decl_file = die->GetAttributeValueAsUnsigned(this, dw_cu, DW_AT_decl_file, 0);
694 if (decl_file)
695 {
696 fs_to_dies[dc_cu->GetSupportFiles().GetFileSpecAtIndex(decl_file)].Insert(die);
697 }
698 else
699 {
700 // add this to the current compile unit
701 fs_to_dies[cu_fspec].Insert(die);
702 }
703 }
704 break;
705 }
706
707 die = die->GetSibling();
708 }
709}
710
711
712
713#endif
714
715uint32_t
716SymbolFileDWARF::GetNumCompileUnits()
717{
718 DWARFDebugInfo* info = DebugInfo();
719 if (info)
720 {
721#if defined LLDB_SYMBOL_FILE_DWARF_SHRINK_TEST
722 uint32_t cu_idx;
723 FSToDIES fs_to_dies;
724
725 FileSpec base_type_fspec("DW_TAG_base_type");
726 const uint32_t num_comp_units = info->GetNumCompileUnits();
727
728 for (cu_idx=0; cu_idx < num_comp_units; ++cu_idx)
729 {
730 DWARFCompileUnit* cu = info->GetCompileUnitAtIndex(cu_idx);
731 if (cu != NULL)
732 {
733 const DWARFDebugInfoEntry *cu_die = cu->DIE();
734 if (cu_die)
735 {
736 CompUnitSP dc_cu_sp;
737 ParseCompileUnit(cu, dc_cu_sp);
738 if (dc_cu_sp.get())
739 {
740 FileSpec cu_fspec(*dc_cu_sp.get());
741
742 ShrinkDSYM(dc_cu_sp.get(), cu, cu_fspec, base_type_fspec, fs_to_dies, cu->DIE()->GetFirstChild());
743 }
744 }
745 }
746 }
747
748 Stream strm(stdout);
749 FSToDIES::const_iterator pos, end = fs_to_dies.end();
750 for (pos = fs_to_dies.begin(); pos != end; ++pos)
751 {
752 strm << "\n\nMinimal Compile Unit: " << pos->first << ":\n";
753 const DWARFDIECollection& dies = pos->second;
754 dies.Dump(strm, NULL);
755 }
756 return num_comp_units;
757#else
758 return info->GetNumCompileUnits();
759#endif
760 }
761 return 0;
762}
763
764CompUnitSP
765SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
766{
767 CompUnitSP comp_unit;
768 DWARFDebugInfo* info = DebugInfo();
769 if (info)
770 {
771 DWARFCompileUnit* cu = info->GetCompileUnitAtIndex(cu_idx);
772 if (cu != NULL)
773 {
774 // Our symbol vendor shouldn't be asking us to add a compile unit that
775 // has already been added to it, which this DWARF plug-in knows as it
776 // stores the lldb compile unit (CompileUnit) pointer in each
777 // DWARFCompileUnit object when it gets added.
778 assert(cu->GetUserData() == NULL);
779 ParseCompileUnit(cu, comp_unit);
780 }
781 }
782 return comp_unit;
783}
784
785static void
786AddRangesToBlock
787(
788 BlockList& blocks,
789 lldb::user_id_t blockID,
790 DWARFDebugRanges::RangeList& ranges,
791 addr_t block_base_addr
792)
793{
794 ranges.SubtractOffset (block_base_addr);
795 size_t range_idx = 0;
796 const DWARFDebugRanges::Range *debug_range;
797 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
798 {
799 blocks.AddRange(blockID, debug_range->begin_offset, debug_range->end_offset);
800 }
801}
802
803
804Function *
805SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
806{
807 DWARFDebugRanges::RangeList func_ranges;
808 const char *name = NULL;
809 const char *mangled = NULL;
810 int decl_file = 0;
811 int decl_line = 0;
812 int decl_column = 0;
813 int call_file = 0;
814 int call_line = 0;
815 int call_column = 0;
816 DWARFExpression frame_base;
817
818 // Parse the function prototype as a type that can then be added to concrete function instance
819 ParseTypes (sc, dwarf_cu, die, false, false);
820 //FixupTypes();
821
822 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
823 {
824 // Union of all ranges in the function DIE (if the function is discontiguous)
825 AddressRange func_range;
826 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
827 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
828 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
829 {
830 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
831 if (func_range.GetBaseAddress().IsValid())
832 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
833 }
834
835 if (func_range.GetBaseAddress().IsValid())
836 {
837 Mangled func_name;
838 if (mangled)
839 func_name.SetValue(mangled, true);
840 else if (name)
841 func_name.SetValue(name, false);
842
843 FunctionSP func_sp;
844 std::auto_ptr<Declaration> decl_ap;
845 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
846 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), decl_line, decl_column));
847
848 Type *func_type = NULL;
849
850 if (die->GetUserData() != DIE_IS_BEING_PARSED)
851 func_type = (Type*)die->GetUserData();
852
853 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
854
855 func_range.GetBaseAddress().ResolveLinkedAddress();
856
857 func_sp.reset(new Function (sc.comp_unit,
858 die->GetOffset(), // UserID is the DIE offset
859 die->GetOffset(),
860 func_name,
861 func_type,
862 func_range)); // first address range
863
864 if (func_sp.get() != NULL)
865 {
866 func_sp->GetFrameBaseExpression() = frame_base;
867 sc.comp_unit->AddFunction(func_sp);
868 return func_sp.get();
869 }
870 }
871 }
872 return NULL;
873}
874
875size_t
876SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
877{
878 assert (sc.comp_unit);
879 size_t functions_added = 0;
880 const DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
881 if (dwarf_cu)
882 {
883 DWARFDIECollection function_dies;
884 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
885 size_t func_idx;
886 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
887 {
888 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
889 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
890 {
891 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
892 ++functions_added;
893 }
894 }
895 //FixupTypes();
896 }
897 return functions_added;
898}
899
900bool
901SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
902{
903 assert (sc.comp_unit);
904 DWARFCompileUnit* cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
905 assert (cu);
906 const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly();
907
908 if (cu_die)
909 {
910 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL);
911 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
912
913 // All file indexes in DWARF are one based and a file of index zero is
914 // supposed to be the compile unit itself.
915 support_files.Append (*sc.comp_unit);
916
917 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
918 }
919 return false;
920}
921
922struct ParseDWARFLineTableCallbackInfo
923{
924 LineTable* line_table;
925 const SectionList *section_list;
926 lldb::addr_t prev_sect_file_base_addr;
927 lldb::addr_t curr_sect_file_base_addr;
928 bool is_oso_for_debug_map;
929 bool prev_in_final_executable;
930 DWARFDebugLine::Row prev_row;
931 SectionSP prev_section_sp;
932 SectionSP curr_section_sp;
933};
934
935//----------------------------------------------------------------------
936// ParseStatementTableCallback
937//----------------------------------------------------------------------
938static void
939ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
940{
941 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
942 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
943 {
944 // Just started parsing the line table
945 }
946 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
947 {
948 // Done parsing line table, nothing to do for the cleanup
949 }
950 else
951 {
952 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
953 // We have a new row, lets append it
954
955 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
956 {
957 info->prev_section_sp = info->curr_section_sp;
958 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
959 // If this is an end sequence entry, then we subtract one from the
960 // address to make sure we get an address that is not the end of
961 // a section.
962 if (state.end_sequence && state.address != 0)
963 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
964 else
965 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
966
967 if (info->curr_section_sp.get())
968 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
969 else
970 info->curr_sect_file_base_addr = 0;
971 }
972 if (info->curr_section_sp.get())
973 {
974 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
975 // Check for the fancy section magic to determine if we
976
977 if (info->is_oso_for_debug_map)
978 {
979 // When this is a debug map object file that contains DWARF
980 // (referenced from an N_OSO debug map nlist entry) we will have
981 // a file address in the file range for our section from the
982 // original .o file, and a load address in the executable that
983 // contains the debug map.
984 //
985 // If the sections for the file range and load range are
986 // different, we have a remapped section for the function and
987 // this address is resolved. If they are the same, then the
988 // function for this address didn't make it into the final
989 // executable.
990 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
991
992 // If we are doing DWARF with debug map, then we need to carefully
993 // add each line table entry as there may be gaps as functions
994 // get moved around or removed.
995 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
996 {
997 if (info->prev_in_final_executable)
998 {
999 bool terminate_previous_entry = false;
1000 if (!curr_in_final_executable)
1001 {
1002 // Check for the case where the previous line entry
1003 // in a function made it into the final executable,
1004 // yet the current line entry falls in a function
1005 // that didn't. The line table used to be contiguous
1006 // through this address range but now it isn't. We
1007 // need to terminate the previous line entry so
1008 // that we can reconstruct the line range correctly
1009 // for it and to keep the line table correct.
1010 terminate_previous_entry = true;
1011 }
1012 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1013 {
1014 // Check for cases where the line entries used to be
1015 // contiguous address ranges, but now they aren't.
1016 // This can happen when order files specify the
1017 // ordering of the functions.
1018 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1019 Section *curr_sect = info->curr_section_sp.get();
1020 Section *prev_sect = info->prev_section_sp.get();
1021 assert (curr_sect->GetLinkedSection());
1022 assert (prev_sect->GetLinkedSection());
1023 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1024 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1025 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1026 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1027 if (object_file_addr_delta != linked_file_addr_delta)
1028 terminate_previous_entry = true;
1029 }
1030
1031 if (terminate_previous_entry)
1032 {
1033 line_table->InsertLineEntry (info->prev_section_sp,
1034 state.address - info->prev_sect_file_base_addr,
1035 info->prev_row.line,
1036 info->prev_row.column,
1037 info->prev_row.file,
1038 false, // is_stmt
1039 false, // basic_block
1040 false, // state.prologue_end
1041 false, // state.epilogue_begin
1042 true); // end_sequence);
1043 }
1044 }
1045 }
1046
1047 if (curr_in_final_executable)
1048 {
1049 line_table->InsertLineEntry (info->curr_section_sp,
1050 curr_line_section_offset,
1051 state.line,
1052 state.column,
1053 state.file,
1054 state.is_stmt,
1055 state.basic_block,
1056 state.prologue_end,
1057 state.epilogue_begin,
1058 state.end_sequence);
1059 info->prev_section_sp = info->curr_section_sp;
1060 }
1061 else
1062 {
1063 // If the current address didn't make it into the final
1064 // executable, the current section will be the __text
1065 // segment in the .o file, so we need to clear this so
1066 // we can catch the next function that did make it into
1067 // the final executable.
1068 info->prev_section_sp.reset();
1069 info->curr_section_sp.reset();
1070 }
1071
1072 info->prev_in_final_executable = curr_in_final_executable;
1073 }
1074 else
1075 {
1076 // We are not in an object file that contains DWARF for an
1077 // N_OSO, this is just a normal DWARF file. The DWARF spec
1078 // guarantees that the addresses will be in increasing order
1079 // so, since we store line tables in file address order, we
1080 // can always just append the line entry without needing to
1081 // search for the correct insertion point (we don't need to
1082 // use LineEntry::InsertLineEntry()).
1083 line_table->AppendLineEntry (info->curr_section_sp,
1084 curr_line_section_offset,
1085 state.line,
1086 state.column,
1087 state.file,
1088 state.is_stmt,
1089 state.basic_block,
1090 state.prologue_end,
1091 state.epilogue_begin,
1092 state.end_sequence);
1093 }
1094 }
1095
1096 info->prev_row = state;
1097 }
1098}
1099
1100bool
1101SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1102{
1103 assert (sc.comp_unit);
1104 if (sc.comp_unit->GetLineTable() != NULL)
1105 return true;
1106
1107 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1108 if (dwarf_cu)
1109 {
1110 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1111 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1112 if (cu_line_offset != DW_INVALID_OFFSET)
1113 {
1114 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1115 if (line_table_ap.get())
1116 {
1117 ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_flags.IsSet (flagsDWARFIsOSOForDebugMap), false};
1118 uint32_t offset = cu_line_offset;
1119 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1120 sc.comp_unit->SetLineTable(line_table_ap.release());
1121 return true;
1122 }
1123 }
1124 }
1125 return false;
1126}
1127
1128size_t
1129SymbolFileDWARF::ParseFunctionBlocks
1130(
1131 const SymbolContext& sc,
1132 lldb::user_id_t parentBlockID,
1133 const DWARFCompileUnit* dwarf_cu,
1134 const DWARFDebugInfoEntry *die,
1135 addr_t subprogram_low_pc,
1136 bool parse_siblings,
1137 bool parse_children
1138)
1139{
1140 size_t blocks_added = 0;
1141 while (die != NULL)
1142 {
1143 dw_tag_t tag = die->Tag();
1144
1145 switch (tag)
1146 {
1147 case DW_TAG_subprogram:
1148 case DW_TAG_inlined_subroutine:
1149 case DW_TAG_lexical_block:
1150 {
1151 DWARFDebugRanges::RangeList ranges;
1152 const char *name = NULL;
1153 const char *mangled_name = NULL;
1154 BlockList& blocks = sc.function->GetBlocks(false);
1155
1156 lldb::user_id_t blockID = blocks.AddChild(parentBlockID, die->GetOffset());
1157 int decl_file = 0;
1158 int decl_line = 0;
1159 int decl_column = 0;
1160 int call_file = 0;
1161 int call_line = 0;
1162 int call_column = 0;
1163 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled_name, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column))
1164 {
1165 if (tag == DW_TAG_subprogram)
1166 {
1167 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1168 subprogram_low_pc = ranges.LowestAddress(0);
1169 }
1170
1171 AddRangesToBlock (blocks, blockID, ranges, subprogram_low_pc);
1172
1173 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1174 {
1175 std::auto_ptr<Declaration> decl_ap;
1176 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1177 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), decl_line, decl_column));
1178
1179 std::auto_ptr<Declaration> call_ap;
1180 if (call_file != 0 || call_line != 0 || call_column != 0)
1181 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), call_line, call_column));
1182
1183 blocks.SetInlinedFunctionInfo(blockID, name, mangled_name, decl_ap.get(), call_ap.get());
1184 }
1185
1186 ++blocks_added;
1187
1188 if (parse_children && die->HasChildren())
1189 {
1190 blocks_added += ParseFunctionBlocks(sc, blockID, dwarf_cu, die->GetFirstChild(), subprogram_low_pc, true, true);
1191 }
1192 }
1193 }
1194 break;
1195 default:
1196 break;
1197 }
1198
1199 if (parse_siblings)
1200 die = die->GetSibling();
1201 else
1202 die = NULL;
1203 }
1204 return blocks_added;
1205}
1206
1207size_t
1208SymbolFileDWARF::ParseChildMembers
1209(
1210 const SymbolContext& sc,
1211 TypeSP& type_sp,
1212 const DWARFCompileUnit* dwarf_cu,
1213 const DWARFDebugInfoEntry *parent_die,
Greg Clayton9e409562010-07-28 02:04:09 +00001214 void *class_clang_type,
1215 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1217 std::vector<int>& member_accessibilities,
Greg Clayton8cf05932010-07-22 18:30:50 +00001218 ClangASTContext::AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 bool &is_a_class
1220)
1221{
1222 if (parent_die == NULL)
1223 return 0;
1224
1225 TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
1226
1227 size_t count = 0;
1228 const DWARFDebugInfoEntry *die;
1229 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1230 {
1231 dw_tag_t tag = die->Tag();
1232
1233 switch (tag)
1234 {
1235 case DW_TAG_member:
1236 {
1237 DWARFDebugInfoEntry::Attributes attributes;
1238 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
1239 if (num_attributes > 0)
1240 {
1241 Declaration decl;
1242 DWARFExpression location;
1243 const char *name = NULL;
1244 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Greg Clayton8cf05932010-07-22 18:30:50 +00001245 ClangASTContext::AccessType accessibility = ClangASTContext::eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 off_t member_offset = 0;
1247 size_t byte_size = 0;
1248 size_t bit_offset = 0;
1249 size_t bit_size = 0;
1250 uint32_t i;
1251 for (i=0; i<num_attributes; ++i)
1252 {
1253 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1254 DWARFFormValue form_value;
1255 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1256 {
1257 switch (attr)
1258 {
1259 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1260 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1261 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1262 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1263 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1264 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1265 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1266 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1267 case DW_AT_data_member_location:
1268 if (form_value.BlockData())
1269 {
1270 Value initialValue(0);
1271 Value memberOffset(0);
1272 const DataExtractor& debug_info_data = get_debug_info_data();
1273 uint32_t block_length = form_value.Unsigned();
1274 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1275 if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1276 {
1277 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1278 }
1279 }
1280 break;
1281
Greg Clayton8cf05932010-07-22 18:30:50 +00001282 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283 case DW_AT_declaration:
1284 case DW_AT_description:
1285 case DW_AT_mutable:
1286 case DW_AT_visibility:
1287 default:
1288 case DW_AT_sibling:
1289 break;
1290 }
1291 }
1292 }
1293
1294 Type *member_type = ResolveTypeUID(encoding_uid);
1295 assert(member_type);
Greg Clayton8cf05932010-07-22 18:30:50 +00001296 if (accessibility == ClangASTContext::eAccessNone)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297 accessibility = default_accessibility;
1298 member_accessibilities.push_back(accessibility);
1299
1300 type_list->GetClangASTContext().AddFieldToRecordType (type_sp->GetOpaqueClangQualType(), name, member_type->GetOpaqueClangQualType(), accessibility, bit_size);
1301 }
1302 }
1303 break;
1304
1305 case DW_TAG_subprogram:
1306 {
1307 is_a_class = true;
Greg Clayton8cf05932010-07-22 18:30:50 +00001308 if (default_accessibility == ClangASTContext::eAccessNone)
1309 default_accessibility = ClangASTContext::eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 // TODO: implement DW_TAG_subprogram type parsing
1311// UserDefTypeChildInfo method_info(die->GetOffset());
1312//
1313// FunctionSP func_sp (sc.comp_unit->FindFunctionByUID (die->GetOffset()));
1314// if (func_sp.get() == NULL)
1315// ParseCompileUnitFunction(sc, dwarf_cu, die);
1316//
1317// method_info.SetEncodingTypeUID(die->GetOffset());
1318// struct_udt->AddMethod(method_info);
1319 }
1320 break;
1321
1322 case DW_TAG_inheritance:
1323 {
1324 is_a_class = true;
Greg Clayton8cf05932010-07-22 18:30:50 +00001325 if (default_accessibility == ClangASTContext::eAccessNone)
1326 default_accessibility = ClangASTContext::eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 // TODO: implement DW_TAG_inheritance type parsing
1328 DWARFDebugInfoEntry::Attributes attributes;
1329 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
1330 if (num_attributes > 0)
1331 {
1332 Declaration decl;
1333 DWARFExpression location;
1334 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Greg Clayton8cf05932010-07-22 18:30:50 +00001335 ClangASTContext::AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336 bool is_virtual = false;
1337 bool is_base_of_class = true;
1338 off_t member_offset = 0;
1339 uint32_t i;
1340 for (i=0; i<num_attributes; ++i)
1341 {
1342 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1343 DWARFFormValue form_value;
1344 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1345 {
1346 switch (attr)
1347 {
1348 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1349 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1350 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1351 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1352 case DW_AT_data_member_location:
1353 if (form_value.BlockData())
1354 {
1355 Value initialValue(0);
1356 Value memberOffset(0);
1357 const DataExtractor& debug_info_data = get_debug_info_data();
1358 uint32_t block_length = form_value.Unsigned();
1359 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1360 if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1361 {
1362 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1363 }
1364 }
1365 break;
1366
1367 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001368 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 break;
1370
1371 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1372 default:
1373 case DW_AT_sibling:
1374 break;
1375 }
1376 }
1377 }
1378
1379 Type *base_class_dctype = ResolveTypeUID(encoding_uid);
1380 assert(base_class_dctype);
Greg Clayton9e409562010-07-28 02:04:09 +00001381
1382 if (class_language == eLanguageTypeObjC)
1383 {
1384 type_list->GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_dctype->GetOpaqueClangQualType());
1385 }
1386 else
1387 {
1388 base_classes.push_back (type_list->GetClangASTContext().CreateBaseClassSpecifier (base_class_dctype->GetOpaqueClangQualType(), accessibility, is_virtual, is_base_of_class));
1389 assert(base_classes.back());
1390 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 }
1392 }
1393 break;
1394
1395 default:
1396 break;
1397 }
1398 }
1399 return count;
1400}
1401
1402
1403clang::DeclContext*
1404SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid)
1405{
1406 DWARFDebugInfo* debug_info = DebugInfo();
1407 if (debug_info)
1408 {
1409 DWARFCompileUnitSP cu_sp;
1410 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1411 if (die)
1412 return GetClangDeclContextForDIE (cu_sp.get(), die);
1413 }
1414 return NULL;
1415}
1416
1417Type*
1418SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid)
1419{
1420 DWARFDebugInfo* debug_info = DebugInfo();
1421 if (debug_info)
1422 {
1423 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, NULL);
1424 if (type_die != NULL)
1425 {
1426 void *type = type_die->GetUserData();
1427 if (type == NULL)
1428 {
1429 DWARFCompileUnitSP cu_sp;
1430 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1431 if (die != NULL)
1432 {
1433 TypeSP owning_type_sp;
1434 TypeSP type_sp(GetTypeForDIE(cu_sp.get(), die, owning_type_sp, 0, 0));
1435 }
1436 type = type_die->GetUserData();
1437 }
1438 if (type != DIE_IS_BEING_PARSED)
1439 return (Type *)type;
1440 }
1441 }
1442 return NULL;
1443}
1444
1445CompileUnit*
1446SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit* cu, uint32_t cu_idx)
1447{
1448 // Check if the symbol vendor already knows about this compile unit?
1449 if (cu->GetUserData() == NULL)
1450 {
1451 // The symbol vendor doesn't know about this compile unit, we
1452 // need to parse and add it to the symbol vendor object.
1453 CompUnitSP dc_cu;
1454 ParseCompileUnit(cu, dc_cu);
1455 if (dc_cu.get())
1456 {
1457 // Figure out the compile unit index if we weren't given one
1458 if (cu_idx == UINT_MAX)
1459 DebugInfo()->GetCompileUnit(cu->GetOffset(), &cu_idx);
1460
1461 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
1462 }
1463 }
1464 return (CompileUnit*)cu->GetUserData();
1465}
1466
1467bool
1468SymbolFileDWARF::GetFunction (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
1469{
1470 sc.Clear();
1471 // Check if the symbol vendor already knows about this compile unit?
1472 sc.module_sp = m_obj_file->GetModule()->GetSP();
1473 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT_MAX);
1474
1475 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1476 if (sc.function == NULL)
1477 sc.function = ParseCompileUnitFunction(sc, cu, func_die);
1478
1479 return sc.function != NULL;
1480}
1481
1482uint32_t
1483SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1484{
1485 Timer scoped_timer(__PRETTY_FUNCTION__,
1486 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1487 so_addr.GetSection(),
1488 so_addr.GetOffset(),
1489 resolve_scope);
1490 uint32_t resolved = 0;
1491 if (resolve_scope & ( eSymbolContextCompUnit |
1492 eSymbolContextFunction |
1493 eSymbolContextBlock |
1494 eSymbolContextLineEntry))
1495 {
1496 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1497
1498 DWARFDebugAranges* debug_aranges = DebugAranges();
1499 DWARFDebugInfo* debug_info = DebugInfo();
1500 if (debug_aranges)
1501 {
1502 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1503 if (cu_offset != DW_INVALID_OFFSET)
1504 {
1505 uint32_t cu_idx;
1506 DWARFCompileUnit* cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1507 if (cu)
1508 {
1509 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1510 assert(sc.comp_unit != NULL);
1511 resolved |= eSymbolContextCompUnit;
1512
1513 if (resolve_scope & eSymbolContextLineEntry)
1514 {
1515 LineTable *line_table = sc.comp_unit->GetLineTable();
1516 if (line_table == NULL)
1517 {
1518 if (ParseCompileUnitLineTable(sc))
1519 line_table = sc.comp_unit->GetLineTable();
1520 }
1521 if (line_table != NULL)
1522 {
1523 if (so_addr.IsLinkedAddress())
1524 {
1525 Address linked_addr (so_addr);
1526 linked_addr.ResolveLinkedAddress();
1527 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1528 {
1529 resolved |= eSymbolContextLineEntry;
1530 }
1531 }
1532 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1533 {
1534 resolved |= eSymbolContextLineEntry;
1535 }
1536 }
1537 }
1538
1539 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1540 {
1541 DWARFDebugInfoEntry *function_die = NULL;
1542 DWARFDebugInfoEntry *block_die = NULL;
1543 if (resolve_scope & eSymbolContextBlock)
1544 {
1545 cu->LookupAddress(file_vm_addr, &function_die, &block_die);
1546 }
1547 else
1548 {
1549 cu->LookupAddress(file_vm_addr, &function_die, NULL);
1550 }
1551
1552 if (function_die != NULL)
1553 {
1554 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1555 if (sc.function == NULL)
1556 sc.function = ParseCompileUnitFunction(sc, cu, function_die);
1557 }
1558
1559 if (sc.function != NULL)
1560 {
1561 resolved |= eSymbolContextFunction;
1562
1563 if (resolve_scope & eSymbolContextBlock)
1564 {
1565 BlockList& blocks = sc.function->GetBlocks(true);
1566
1567 if (block_die != NULL)
1568 sc.block = blocks.GetBlockByID(block_die->GetOffset());
1569 else
1570 sc.block = blocks.GetBlockByID(function_die->GetOffset());
1571 if (sc.block)
1572 resolved |= eSymbolContextBlock;
1573 }
1574 }
1575 }
1576 }
1577 }
1578 }
1579 }
1580 return resolved;
1581}
1582
1583
1584
1585uint32_t
1586SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1587{
1588 const uint32_t prev_size = sc_list.GetSize();
1589 if (resolve_scope & eSymbolContextCompUnit)
1590 {
1591 DWARFDebugInfo* debug_info = DebugInfo();
1592 if (debug_info)
1593 {
1594 uint32_t cu_idx;
1595 DWARFCompileUnit* cu = NULL;
1596
1597 for (cu_idx = 0; (cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
1598 {
1599 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1600 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1601 if (check_inlines || file_spec_matches_cu_file_spec)
1602 {
1603 SymbolContext sc (m_obj_file->GetModule());
1604 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1605 assert(sc.comp_unit != NULL);
1606
1607 uint32_t file_idx = UINT32_MAX;
1608
1609 // If we are looking for inline functions only and we don't
1610 // find it in the support files, we are done.
1611 if (check_inlines)
1612 {
1613 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1614 if (file_idx == UINT32_MAX)
1615 continue;
1616 }
1617
1618 if (line != 0)
1619 {
1620 LineTable *line_table = sc.comp_unit->GetLineTable();
1621
1622 if (line_table != NULL && line != 0)
1623 {
1624 // We will have already looked up the file index if
1625 // we are searching for inline entries.
1626 if (!check_inlines)
1627 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1628
1629 if (file_idx != UINT32_MAX)
1630 {
1631 uint32_t found_line;
1632 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1633 found_line = sc.line_entry.line;
1634
1635 while (line_idx != UINT_MAX)
1636 {
1637 sc.function = NULL;
1638 sc.block = NULL;
1639 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1640 {
1641 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1642 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1643 {
1644 DWARFDebugInfoEntry *function_die = NULL;
1645 DWARFDebugInfoEntry *block_die = NULL;
1646 cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
1647
1648 if (function_die != NULL)
1649 {
1650 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1651 if (sc.function == NULL)
1652 sc.function = ParseCompileUnitFunction(sc, cu, function_die);
1653 }
1654
1655 if (sc.function != NULL)
1656 {
1657 BlockList& blocks = sc.function->GetBlocks(true);
1658
1659 if (block_die != NULL)
1660 sc.block = blocks.GetBlockByID(block_die->GetOffset());
1661 else
1662 sc.block = blocks.GetBlockByID(function_die->GetOffset());
1663 }
1664 }
1665 }
1666
1667 sc_list.Append(sc);
1668 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1669 }
1670 }
1671 }
1672 else if (file_spec_matches_cu_file_spec && !check_inlines)
1673 {
1674 // only append the context if we aren't looking for inline call sites
1675 // by file and line and if the file spec matches that of the compile unit
1676 sc_list.Append(sc);
1677 }
1678 }
1679 else if (file_spec_matches_cu_file_spec && !check_inlines)
1680 {
1681 // only append the context if we aren't looking for inline call sites
1682 // by file and line and if the file spec matches that of the compile unit
1683 sc_list.Append(sc);
1684 }
1685
1686 if (!check_inlines)
1687 break;
1688 }
1689 }
1690 }
1691 }
1692 return sc_list.GetSize() - prev_size;
1693}
1694
1695void
1696SymbolFileDWARF::Index ()
1697{
1698 if (m_indexed)
1699 return;
1700 m_indexed = true;
1701 Timer scoped_timer (__PRETTY_FUNCTION__,
1702 "SymbolFileDWARF::Index (%s)",
1703 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1704
1705 DWARFDebugInfo* debug_info = DebugInfo();
1706 if (debug_info)
1707 {
1708 uint32_t cu_idx = 0;
1709 const uint32_t num_compile_units = GetNumCompileUnits();
1710 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1711 {
1712 DWARFCompileUnit* cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1713
1714 bool clear_dies = cu->ExtractDIEsIfNeeded (false) > 1;
1715
Greg Clayton0c5cd902010-06-28 21:30:43 +00001716 cu->Index (m_base_name_to_function_die,
1717 m_full_name_to_function_die,
1718 m_method_name_to_function_die,
1719 m_selector_name_to_function_die,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001720 m_name_to_global_die,
1721 m_name_to_type_die);
1722
1723 // Keep memory down by clearing DIEs if this generate function
1724 // caused them to be parsed
1725 if (clear_dies)
1726 cu->ClearDIEs (true);
1727 }
1728
Greg Clayton0c5cd902010-06-28 21:30:43 +00001729 m_base_name_to_function_die.Sort();
1730 m_full_name_to_function_die.Sort();
1731 m_method_name_to_function_die.Sort();
1732 m_selector_name_to_function_die.Sort();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 m_name_to_global_die.Sort();
1734 m_name_to_type_die.Sort();
1735 }
1736}
1737
1738uint32_t
1739SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1740{
1741 std::vector<dw_offset_t> die_offsets;
1742
1743 // If we aren't appending the results to this list, then clear the list
1744 if (!append)
1745 variables.Clear();
1746
1747 // Remember how many variables are in the list before we search in case
1748 // we are appending the results to a variable list.
1749 const uint32_t original_size = variables.GetSize();
1750
1751 // Index the DWARF if we haven't already
1752 if (!m_indexed)
1753 Index ();
1754
1755 const UniqueCStringMap<dw_offset_t>::Entry *entry;
1756
1757 for (entry = m_name_to_global_die.FindFirstValueForName (name.AsCString());
1758 entry != NULL;
1759 entry = m_name_to_global_die.FindNextValueForName (name.AsCString(), entry))
1760 {
1761 DWARFCompileUnitSP cu_sp;
1762 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr (entry->value, &cu_sp);
1763 DWARFCompileUnit* cu = cu_sp.get();
1764 if (die)
1765 {
1766 SymbolContext sc;
1767 sc.module_sp = m_obj_file->GetModule()->GetSP();
1768 assert (sc.module_sp);
1769
1770 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT_MAX);
1771 assert(sc.comp_unit != NULL);
1772
1773 ParseVariables(sc, cu_sp.get(), die, false, false, &variables);
1774
1775 if (variables.GetSize() - original_size >= max_matches)
1776 break;
1777 }
1778 }
1779
1780 // Return the number of variable that were appended to the list
1781 return variables.GetSize() - original_size;
1782}
1783
1784uint32_t
1785SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
1786{
1787 std::vector<dw_offset_t> die_offsets;
1788
1789 // If we aren't appending the results to this list, then clear the list
1790 if (!append)
1791 variables.Clear();
1792
1793 // Remember how many variables are in the list before we search in case
1794 // we are appending the results to a variable list.
1795 const uint32_t original_size = variables.GetSize();
1796
1797 // Index the DWARF if we haven't already
1798 if (!m_indexed)
1799 Index ();
1800
1801 // Create the pubnames information so we can quickly lookup external symbols by name
1802 const size_t num_entries = m_name_to_global_die.GetSize();
1803 for (size_t i=0; i<num_entries; i++)
1804 {
1805 if (!regex.Execute(m_name_to_global_die.GetCStringAtIndex (i)))
1806 continue;
1807
1808 const dw_offset_t die_offset = *m_name_to_global_die.GetValueAtIndex (i);
1809
1810 DWARFCompileUnitSP cu_sp;
1811 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr (die_offset, &cu_sp);
1812 DWARFCompileUnit* cu = cu_sp.get();
1813 if (die)
1814 {
1815 SymbolContext sc;
1816 sc.module_sp = m_obj_file->GetModule()->GetSP();
1817 assert (sc.module_sp);
1818
1819
1820 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT_MAX);
1821 assert(sc.comp_unit != NULL);
1822
1823 ParseVariables(sc, cu_sp.get(), die, false, false, &variables);
1824
1825 if (variables.GetSize() - original_size >= max_matches)
1826 break;
1827 }
1828 }
1829
1830 // Return the number of variable that were appended to the list
1831 return variables.GetSize() - original_size;
1832}
1833
1834
Greg Clayton0c5cd902010-06-28 21:30:43 +00001835void
1836SymbolFileDWARF::FindFunctions
1837(
1838 const ConstString &name,
1839 UniqueCStringMap<dw_offset_t> &name_to_die,
1840 SymbolContextList& sc_list
1841)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001842{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843 const UniqueCStringMap<dw_offset_t>::Entry *entry;
1844
1845 SymbolContext sc;
Greg Clayton0c5cd902010-06-28 21:30:43 +00001846 for (entry = name_to_die.FindFirstValueForName (name.AsCString());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001847 entry != NULL;
Greg Clayton0c5cd902010-06-28 21:30:43 +00001848 entry = name_to_die.FindNextValueForName (name.AsCString(), entry))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849 {
1850 DWARFCompileUnitSP cu_sp;
1851 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr (entry->value, &cu_sp);
1852 if (die)
1853 {
1854 if (GetFunction (cu_sp.get(), die, sc))
1855 {
1856 // We found the function, so we should find the line table
1857 // and line table entry as well
1858 LineTable *line_table = sc.comp_unit->GetLineTable();
1859 if (line_table == NULL)
1860 {
1861 if (ParseCompileUnitLineTable(sc))
1862 line_table = sc.comp_unit->GetLineTable();
1863 }
1864 if (line_table != NULL)
1865 line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry);
1866
1867 sc_list.Append(sc);
1868 }
1869 }
1870 }
1871
Greg Clayton0c5cd902010-06-28 21:30:43 +00001872}
1873
1874uint32_t
1875SymbolFileDWARF::FindFunctions
1876(
1877 const ConstString &name,
1878 uint32_t name_type_mask,
1879 bool append,
1880 SymbolContextList& sc_list
1881)
1882{
1883 Timer scoped_timer (__PRETTY_FUNCTION__,
1884 "SymbolFileDWARF::FindFunctions (name = '%s')",
1885 name.AsCString());
1886
1887 std::vector<dw_offset_t> die_offsets;
1888
1889 // If we aren't appending the results to this list, then clear the list
1890 if (!append)
1891 sc_list.Clear();
1892
1893 // Remember how many sc_list are in the list before we search in case
1894 // we are appending the results to a variable list.
1895 uint32_t original_size = sc_list.GetSize();
1896
1897 // Index the DWARF if we haven't already
1898 if (!m_indexed)
1899 Index ();
1900
1901 if (name_type_mask & eFunctionNameTypeBase)
1902 FindFunctions (name, m_base_name_to_function_die, sc_list);
1903
1904 if (name_type_mask & eFunctionNameTypeFull)
1905 FindFunctions (name, m_full_name_to_function_die, sc_list);
1906
1907 if (name_type_mask & eFunctionNameTypeMethod)
1908 FindFunctions (name, m_method_name_to_function_die, sc_list);
1909
1910 if (name_type_mask & eFunctionNameTypeSelector)
1911 FindFunctions (name, m_selector_name_to_function_die, sc_list);
1912
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001913 // Return the number of variable that were appended to the list
1914 return sc_list.GetSize() - original_size;
1915}
1916
1917
1918uint32_t
1919SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
1920{
1921 Timer scoped_timer (__PRETTY_FUNCTION__,
1922 "SymbolFileDWARF::FindFunctions (regex = '%s')",
1923 regex.GetText());
1924
1925 std::vector<dw_offset_t> die_offsets;
1926
1927 // If we aren't appending the results to this list, then clear the list
1928 if (!append)
1929 sc_list.Clear();
1930
1931 // Remember how many sc_list are in the list before we search in case
1932 // we are appending the results to a variable list.
1933 uint32_t original_size = sc_list.GetSize();
1934
1935 // Index the DWARF if we haven't already
1936 if (!m_indexed)
1937 Index ();
1938
1939 // Create the pubnames information so we can quickly lookup external symbols by name
1940 // Create the pubnames information so we can quickly lookup external symbols by name
Greg Clayton0c5cd902010-06-28 21:30:43 +00001941 const size_t num_entries = m_full_name_to_function_die.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942 SymbolContext sc;
1943 for (size_t i=0; i<num_entries; i++)
1944 {
Greg Clayton0c5cd902010-06-28 21:30:43 +00001945 if (!regex.Execute(m_full_name_to_function_die.GetCStringAtIndex (i)))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946 continue;
1947
Greg Clayton0c5cd902010-06-28 21:30:43 +00001948 const dw_offset_t die_offset = *m_full_name_to_function_die.GetValueAtIndex (i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949
1950 DWARFCompileUnitSP cu_sp;
1951 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr (die_offset, &cu_sp);
1952 if (die)
1953 {
1954 if (GetFunction (cu_sp.get(), die, sc))
1955 {
1956 // We found the function, so we should find the line table
1957 // and line table entry as well
1958 LineTable *line_table = sc.comp_unit->GetLineTable();
1959 if (line_table == NULL)
1960 {
1961 if (ParseCompileUnitLineTable(sc))
1962 line_table = sc.comp_unit->GetLineTable();
1963 }
1964 if (line_table != NULL)
1965 line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry);
1966
1967
1968 sc_list.Append(sc);
1969 }
1970 }
1971 }
1972
1973 // Return the number of variable that were appended to the list
1974 return sc_list.GetSize() - original_size;
1975}
1976
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001978SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001979{
1980 // If we aren't appending the results to this list, then clear the list
1981 if (!append)
1982 types.Clear();
1983
1984 // Create the pubnames information so we can quickly lookup external symbols by name
1985 DWARFDebugPubnames* pubtypes = DebugPubtypes();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001986
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987 if (pubtypes)
1988 {
1989 std::vector<dw_offset_t> die_offsets;
1990 if (!pubtypes->Find(name.AsCString(), false, die_offsets))
1991 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001992// DWARFDebugPubnames* pub_base_types = DebugPubBaseTypes();
1993// if (pub_base_types && !pub_base_types->Find(name.AsCString(), false, die_offsets))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001994 return 0;
1995 }
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001996 return FindTypes(die_offsets, max_matches, types);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001997 }
1998 return 0;
1999}
2000
2001
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002002//uint32_t
2003//SymbolFileDWARF::FindTypes(const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types)
2004//{
2005// // If we aren't appending the results to this list, then clear the list
2006// if (!append)
2007// types.Clear();
2008//
2009// // Create the pubnames information so we can quickly lookup external symbols by name
2010// DWARFDebugPubnames* pubtypes = DebugPubtypes();
2011// if (pubtypes)
2012// {
2013// std::vector<dw_offset_t> die_offsets;
2014// if (!pubtypes->Find(regex, die_offsets))
2015// {
2016// DWARFDebugPubnames* pub_base_types = DebugPubBaseTypes();
2017// if (pub_base_types && !pub_base_types->Find(regex, die_offsets))
2018// return 0;
2019// }
2020//
2021// return FindTypes(die_offsets, max_matches, encoding, udt_uid, types);
2022// }
2023//
2024// return 0;
2025//}
2026//
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027
2028
2029uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002030SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031{
2032 // Remember how many sc_list are in the list before we search in case
2033 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002034 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035
2036 const uint32_t num_die_offsets = die_offsets.size();
2037 // Parse all of the types we found from the pubtypes matches
2038 uint32_t i;
2039 uint32_t num_matches = 0;
2040 for (i = 0; i < num_die_offsets; ++i)
2041 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002042 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2043 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002044 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002045 // We found a type pointer, now find the shared pointer form our type list
2046 TypeSP type_sp (m_obj_file->GetModule()->GetTypeList()->FindType(matching_type->GetID()));
2047 assert (type_sp.get() != NULL);
2048 types.InsertUnique (type_sp);
2049 ++num_matches;
2050 if (num_matches >= max_matches)
2051 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002052 }
2053 }
2054
2055 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002056 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002057}
2058
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002059
2060size_t
2061SymbolFileDWARF::ParseChildParameters
2062(
2063 const SymbolContext& sc,
2064 TypeSP& type_sp,
2065 const DWARFCompileUnit* dwarf_cu,
2066 const DWARFDebugInfoEntry *parent_die,
2067 TypeList* type_list,
2068 std::vector<void *>& function_param_types,
2069 std::vector<clang::ParmVarDecl*>& function_param_decls
2070)
2071{
2072 if (parent_die == NULL)
2073 return 0;
2074
2075 size_t count = 0;
2076 const DWARFDebugInfoEntry *die;
2077 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2078 {
2079 dw_tag_t tag = die->Tag();
2080 switch (tag)
2081 {
2082 case DW_TAG_formal_parameter:
2083 {
2084 DWARFDebugInfoEntry::Attributes attributes;
2085 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2086 if (num_attributes > 0)
2087 {
2088 const char *name = NULL;
2089 Declaration decl;
2090 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
2091 // one of None, Auto, Register, Extern, Static, PrivateExtern
2092
2093 clang::VarDecl::StorageClass storage = clang::VarDecl::None;
2094 uint32_t i;
2095 for (i=0; i<num_attributes; ++i)
2096 {
2097 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2098 DWARFFormValue form_value;
2099 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2100 {
2101 switch (attr)
2102 {
2103 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2104 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2105 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2106 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2107 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
2108 case DW_AT_location:
2109 // if (form_value.BlockData())
2110 // {
2111 // const DataExtractor& debug_info_data = debug_info();
2112 // uint32_t block_length = form_value.Unsigned();
2113 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2114 // }
2115 // else
2116 // {
2117 // }
2118 // break;
2119 case DW_AT_artificial:
2120 case DW_AT_const_value:
2121 case DW_AT_default_value:
2122 case DW_AT_description:
2123 case DW_AT_endianity:
2124 case DW_AT_is_optional:
2125 case DW_AT_segment:
2126 case DW_AT_variable_parameter:
2127 default:
2128 case DW_AT_abstract_origin:
2129 case DW_AT_sibling:
2130 break;
2131 }
2132 }
2133 }
2134 Type *dc_type = ResolveTypeUID(param_type_die_offset);
2135 if (dc_type)
2136 {
2137 function_param_types.push_back (dc_type->GetOpaqueClangQualType());
2138
2139 clang::ParmVarDecl *param_var_decl = type_list->GetClangASTContext().CreateParmeterDeclaration (name, dc_type->GetOpaqueClangQualType(), storage);
2140 assert(param_var_decl);
2141 function_param_decls.push_back(param_var_decl);
2142 }
2143 }
2144 }
2145 break;
2146
2147 default:
2148 break;
2149 }
2150 }
2151 return count;
2152}
2153
2154size_t
2155SymbolFileDWARF::ParseChildEnumerators
2156(
2157 const SymbolContext& sc,
2158 TypeSP& type_sp,
2159 void * enumerator_qual_type,
2160 uint32_t enumerator_byte_size,
2161 const DWARFCompileUnit* dwarf_cu,
2162 const DWARFDebugInfoEntry *parent_die
2163)
2164{
2165 if (parent_die == NULL)
2166 return 0;
2167
2168 size_t enumerators_added = 0;
2169 const DWARFDebugInfoEntry *die;
2170 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2171 {
2172 const dw_tag_t tag = die->Tag();
2173 if (tag == DW_TAG_enumerator)
2174 {
2175 DWARFDebugInfoEntry::Attributes attributes;
2176 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2177 if (num_child_attributes > 0)
2178 {
2179 const char *name = NULL;
2180 bool got_value = false;
2181 int64_t enum_value = 0;
2182 Declaration decl;
2183
2184 uint32_t i;
2185 for (i=0; i<num_child_attributes; ++i)
2186 {
2187 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2188 DWARFFormValue form_value;
2189 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2190 {
2191 switch (attr)
2192 {
2193 case DW_AT_const_value:
2194 got_value = true;
2195 enum_value = form_value.Unsigned();
2196 break;
2197
2198 case DW_AT_name:
2199 name = form_value.AsCString(&get_debug_str_data());
2200 break;
2201
2202 case DW_AT_description:
2203 default:
2204 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2205 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2206 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2207 case DW_AT_sibling:
2208 break;
2209 }
2210 }
2211 }
2212
2213 if (name && name[0] && got_value)
2214 {
2215 TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2216 type_list->GetClangASTContext().AddEnumerationValueToEnumerationType (type_sp->GetOpaqueClangQualType(), enumerator_qual_type, decl, name, enum_value, enumerator_byte_size * 8);
2217 ++enumerators_added;
2218 }
2219 }
2220 }
2221 }
2222 return enumerators_added;
2223}
2224
2225void
2226SymbolFileDWARF::ParseChildArrayInfo
2227(
2228 const SymbolContext& sc,
2229 const DWARFCompileUnit* dwarf_cu,
2230 const DWARFDebugInfoEntry *parent_die,
2231 int64_t& first_index,
2232 std::vector<uint64_t>& element_orders,
2233 uint32_t& byte_stride,
2234 uint32_t& bit_stride
2235)
2236{
2237 if (parent_die == NULL)
2238 return;
2239
2240 const DWARFDebugInfoEntry *die;
2241 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2242 {
2243 const dw_tag_t tag = die->Tag();
2244 switch (tag)
2245 {
2246 case DW_TAG_enumerator:
2247 {
2248 DWARFDebugInfoEntry::Attributes attributes;
2249 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2250 if (num_child_attributes > 0)
2251 {
2252 const char *name = NULL;
2253 bool got_value = false;
2254 int64_t enum_value = 0;
2255
2256 uint32_t i;
2257 for (i=0; i<num_child_attributes; ++i)
2258 {
2259 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2260 DWARFFormValue form_value;
2261 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2262 {
2263 switch (attr)
2264 {
2265 case DW_AT_const_value:
2266 got_value = true;
2267 enum_value = form_value.Unsigned();
2268 break;
2269
2270 case DW_AT_name:
2271 name = form_value.AsCString(&get_debug_str_data());
2272 break;
2273
2274 case DW_AT_description:
2275 default:
2276 case DW_AT_decl_file:
2277 case DW_AT_decl_line:
2278 case DW_AT_decl_column:
2279 case DW_AT_sibling:
2280 break;
2281 }
2282 }
2283 }
2284 }
2285 }
2286 break;
2287
2288 case DW_TAG_subrange_type:
2289 {
2290 DWARFDebugInfoEntry::Attributes attributes;
2291 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2292 if (num_child_attributes > 0)
2293 {
2294 const char *name = NULL;
2295 bool got_value = false;
2296 uint64_t byte_size = 0;
2297 int64_t enum_value = 0;
2298 uint64_t num_elements = 0;
2299 uint64_t lower_bound = 0;
2300 uint64_t upper_bound = 0;
2301 uint32_t i;
2302 for (i=0; i<num_child_attributes; ++i)
2303 {
2304 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2305 DWARFFormValue form_value;
2306 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2307 {
2308 switch (attr)
2309 {
2310 case DW_AT_const_value:
2311 got_value = true;
2312 enum_value = form_value.Unsigned();
2313 break;
2314
2315 case DW_AT_name:
2316 name = form_value.AsCString(&get_debug_str_data());
2317 break;
2318
2319 case DW_AT_count:
2320 num_elements = form_value.Unsigned();
2321 break;
2322
2323 case DW_AT_bit_stride:
2324 bit_stride = form_value.Unsigned();
2325 break;
2326
2327 case DW_AT_byte_stride:
2328 byte_stride = form_value.Unsigned();
2329 break;
2330
2331 case DW_AT_byte_size:
2332 byte_size = form_value.Unsigned();
2333 break;
2334
2335 case DW_AT_lower_bound:
2336 lower_bound = form_value.Unsigned();
2337 break;
2338
2339 case DW_AT_upper_bound:
2340 upper_bound = form_value.Unsigned();
2341 break;
2342
2343 default:
2344 //printf("0x%8.8x: %-30s skipping attribute at 0x%8.8x: %s\n", die->GetOffset(), DW_TAG_value_to_name(tag), attributes.die_offsets[i], DW_AT_value_to_name(attr)); // remove this, debug only
2345
2346 case DW_AT_abstract_origin:
2347 case DW_AT_accessibility:
2348 case DW_AT_allocated:
2349 case DW_AT_associated:
2350 case DW_AT_data_location:
2351 case DW_AT_declaration:
2352 case DW_AT_description:
2353 case DW_AT_sibling:
2354 case DW_AT_threads_scaled:
2355 case DW_AT_type:
2356 case DW_AT_visibility:
2357 break;
2358 }
2359 }
2360 }
2361
2362 if (upper_bound > lower_bound)
2363 num_elements = upper_bound - lower_bound + 1;
2364
2365 if (num_elements > 0)
2366 element_orders.push_back (num_elements);
2367 }
2368 }
2369 break;
2370 }
2371 }
2372}
2373
2374Type*
2375SymbolFileDWARF::GetUniquedTypeForDIEOffset(dw_offset_t type_die_offset, TypeSP& owning_type_sp, int32_t child_type, uint32_t idx, bool safe)
2376{
2377 if (type_die_offset != DW_INVALID_OFFSET)
2378 {
2379 DWARFCompileUnitSP cu_sp;
2380 const DWARFDebugInfoEntry* type_die = DebugInfo()->GetDIEPtr(type_die_offset, &cu_sp);
2381 assert(type_die != NULL);
2382 GetTypeForDIE(cu_sp.get(), type_die, owning_type_sp, child_type, idx);
2383 // Return the uniqued type if there is one
2384 Type* type = (Type*)type_die->GetUserData();
2385 if (type == DIE_IS_BEING_PARSED && safe)
2386 return NULL;
2387 return type;
2388 }
2389 return NULL;
2390}
2391
2392TypeSP
2393SymbolFileDWARF::GetTypeForDIE(DWARFCompileUnit *cu, const DWARFDebugInfoEntry* die, TypeSP& owning_type_sp, int32_t child_type, uint32_t idx)
2394{
2395 TypeSP type_sp;
2396 if (die != NULL)
2397 {
2398 assert(cu != NULL);
2399 Type *type_ptr = (Type *)die->GetUserData();
2400 if (type_ptr == NULL)
2401 {
2402 SymbolContext sc(GetCompUnitForDWARFCompUnit(cu));
2403 bool type_is_new = false;
2404 type_sp = ParseType(sc, cu, die, type_is_new);
2405 type_ptr = (Type *)die->GetUserData();
2406 if (owning_type_sp.get() == NULL)
2407 owning_type_sp = type_sp;
2408 }
2409 else if (type_ptr != DIE_IS_BEING_PARSED)
2410 {
2411 // Grab the existing type from the master types lists
2412 type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(type_ptr->GetID());
2413 }
2414
2415 }
2416 return type_sp;
2417}
2418
2419clang::DeclContext *
2420SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset)
2421{
2422 if (die_offset != DW_INVALID_OFFSET)
2423 {
2424 DWARFCompileUnitSP cu_sp;
2425 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2426 return GetClangDeclContextForDIE (cu_sp.get(), die);
2427 }
2428 return NULL;
2429}
2430
2431
2432
2433clang::DeclContext *
2434SymbolFileDWARF::GetClangDeclContextForDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
2435{
2436 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2437 if (pos != m_die_to_decl_ctx.end())
2438 return pos->second;
2439
2440 while (die != NULL)
2441 {
2442 switch (die->Tag())
2443 {
2444 case DW_TAG_namespace:
2445 {
2446 const char *namespace_name = die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL);
2447 if (namespace_name)
2448 {
2449 TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2450 assert(type_list);
2451 Declaration decl; // TODO: fill in the decl object
2452 clang::NamespaceDecl *namespace_decl = type_list->GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (cu, die->GetParent()));
2453 if (namespace_decl)
2454 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2455 return namespace_decl;
2456 }
2457 }
2458 break;
2459
2460 default:
2461 break;
2462 }
2463 clang::DeclContext *decl_ctx;
2464 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_specification, DW_INVALID_OFFSET));
2465 if (decl_ctx)
2466 return decl_ctx;
2467
2468 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET));
2469 if (decl_ctx)
2470 return decl_ctx;
2471
2472 die = die->GetParent();
2473 }
2474 return NULL;
2475}
2476
2477TypeSP
2478SymbolFileDWARF::ParseType(const SymbolContext& sc, const DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool &type_is_new)
2479{
2480 TypeSP type_sp;
2481
Greg Clayton8cf05932010-07-22 18:30:50 +00002482 ClangASTContext::AccessType accessibility = ClangASTContext::eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002483 if (die != NULL)
2484 {
2485 dw_tag_t tag = die->Tag();
2486 if (die->GetUserData() == NULL)
2487 {
2488 type_is_new = true;
2489
2490 bool is_forward_declaration = false;
2491 DWARFDebugInfoEntry::Attributes attributes;
2492 const char *type_name_cstr = NULL;
2493 ConstString type_name_dbstr;
2494 Type::EncodingUIDType encoding_uid_type = Type::eIsTypeWithUID;
2495 void *clang_type = NULL;
2496
2497 TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2498 dw_attr_t attr;
2499
2500 switch (tag)
2501 {
2502 case DW_TAG_base_type:
2503 case DW_TAG_pointer_type:
2504 case DW_TAG_reference_type:
2505 case DW_TAG_typedef:
2506 case DW_TAG_const_type:
2507 case DW_TAG_restrict_type:
2508 case DW_TAG_volatile_type:
2509 {
2510 //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag));
2511 // Set a bit that lets us know that we are currently parsing this
2512 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(DIE_IS_BEING_PARSED);
2513
2514 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2515 Declaration decl;
2516 uint32_t encoding = 0;
2517 size_t byte_size = 0;
2518 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
2519
2520 if (num_attributes > 0)
2521 {
2522 uint32_t i;
2523 for (i=0; i<num_attributes; ++i)
2524 {
2525 attr = attributes.AttributeAtIndex(i);
2526 DWARFFormValue form_value;
2527 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2528 {
2529 switch (attr)
2530 {
2531 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2532 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2533 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2534 case DW_AT_name:
2535 type_name_cstr = form_value.AsCString(&get_debug_str_data());
2536 type_name_dbstr.SetCString(type_name_cstr);
2537 break;
2538 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
2539 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
2540 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
2541 default:
2542 case DW_AT_sibling:
2543 break;
2544 }
2545 }
2546 }
2547 }
2548
2549 switch (tag)
2550 {
2551 default:
2552 case DW_TAG_base_type:
2553 clang_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, encoding, byte_size * 8);
2554 break;
2555
2556 case DW_TAG_pointer_type:
2557 // The encoding_uid will be embedded into the
2558 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2559 encoding_uid_type = Type::ePointerToTypeWithUID;
2560 break;
2561
2562 case DW_TAG_reference_type:
2563 // The encoding_uid will be embedded into the
2564 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2565 encoding_uid_type = Type::eLValueReferenceToTypeWithUID;
2566 break;
2567
2568 case DW_TAG_typedef:
2569 // The encoding_uid will be embedded into the
2570 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2571 encoding_uid_type = Type::eTypedefToTypeWithUID;
2572 break;
2573
2574 case DW_TAG_const_type:
2575 // The encoding_uid will be embedded into the
2576 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2577 encoding_uid_type = Type::eIsConstTypeWithUID; //ClangASTContext::AddConstModifier (clang_type);
2578 break;
2579
2580 case DW_TAG_restrict_type:
2581 // The encoding_uid will be embedded into the
2582 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2583 encoding_uid_type = Type::eIsRestrictTypeWithUID; //ClangASTContext::AddRestrictModifier (clang_type);
2584 break;
2585
2586 case DW_TAG_volatile_type:
2587 // The encoding_uid will be embedded into the
2588 // Type object and will be looked up when the Type::GetOpaqueClangQualType()
2589 encoding_uid_type = Type::eIsVolatileTypeWithUID; //ClangASTContext::AddVolatileModifier (clang_type);
2590 break;
2591 }
2592
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002593 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
2594 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
2595 {
2596 static ConstString g_objc_type_name_id("id");
2597 static ConstString g_objc_type_name_Class("Class");
2598 static ConstString g_objc_type_name_selector("SEL");
2599
2600 if (type_name_dbstr == g_objc_type_name_id)
2601 {
2602 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_id();
2603 ResolveTypeUID (encoding_uid);
2604 }
2605 else if (type_name_dbstr == g_objc_type_name_Class)
2606 {
2607 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_Class();
2608 ResolveTypeUID (encoding_uid);
2609 }
2610 else if (type_name_dbstr == g_objc_type_name_selector)
2611 {
2612 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_selector();
2613 ResolveTypeUID (encoding_uid);
2614 }
2615 }
2616
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002617 type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, encoding_uid_type, &decl, clang_type));
2618
2619 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
2620
2621
2622// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
2623// if (encoding_type != NULL)
2624// {
2625// if (encoding_type != DIE_IS_BEING_PARSED)
2626// type_sp->SetEncodingType(encoding_type);
2627// else
2628// m_indirect_fixups.push_back(type_sp.get());
2629// }
2630 }
2631 break;
2632
2633 case DW_TAG_structure_type:
2634 case DW_TAG_union_type:
2635 case DW_TAG_class_type:
2636 {
2637 //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag));
2638 // Set a bit that lets us know that we are currently parsing this
2639 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(DIE_IS_BEING_PARSED);
2640
2641 size_t byte_size = 0;
Greg Clayton9e409562010-07-28 02:04:09 +00002642 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002643 //bool struct_is_class = false;
2644 Declaration decl;
2645 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2646 if (num_attributes > 0)
2647 {
2648 uint32_t i;
2649 for (i=0; i<num_attributes; ++i)
2650 {
2651 attr = attributes.AttributeAtIndex(i);
2652 DWARFFormValue form_value;
2653 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2654 {
2655 switch (attr)
2656 {
Greg Clayton9e409562010-07-28 02:04:09 +00002657 case DW_AT_decl_file:
2658 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
2659 break;
2660
2661 case DW_AT_decl_line:
2662 decl.SetLine(form_value.Unsigned());
2663 break;
2664
2665 case DW_AT_decl_column:
2666 decl.SetColumn(form_value.Unsigned());
2667 break;
2668
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002669 case DW_AT_name:
2670 type_name_cstr = form_value.AsCString(&get_debug_str_data());
2671 type_name_dbstr.SetCString(type_name_cstr);
2672 break;
Greg Clayton9e409562010-07-28 02:04:09 +00002673
2674 case DW_AT_byte_size:
2675 byte_size = form_value.Unsigned();
2676 break;
2677
2678 case DW_AT_accessibility:
2679 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
2680 break;
2681
2682 case DW_AT_declaration:
2683 is_forward_declaration = form_value.Unsigned() != 0;
2684 break;
2685
2686 case DW_AT_APPLE_runtime_class:
2687 class_language = (LanguageType)form_value.Signed();
2688 break;
2689
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002690 case DW_AT_allocated:
2691 case DW_AT_associated:
2692 case DW_AT_data_location:
2693 case DW_AT_description:
2694 case DW_AT_start_scope:
2695 case DW_AT_visibility:
2696 default:
2697 case DW_AT_sibling:
2698 break;
2699 }
2700 }
2701 }
2702 }
2703
2704 int tag_decl_kind = -1;
Greg Clayton8cf05932010-07-22 18:30:50 +00002705 ClangASTContext::AccessType default_accessibility = ClangASTContext::eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002706 if (tag == DW_TAG_structure_type)
2707 {
2708 tag_decl_kind = clang::TTK_Struct;
Greg Clayton8cf05932010-07-22 18:30:50 +00002709 default_accessibility = ClangASTContext::eAccessPublic;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002710 }
2711 else if (tag == DW_TAG_union_type)
2712 {
2713 tag_decl_kind = clang::TTK_Union;
Greg Clayton8cf05932010-07-22 18:30:50 +00002714 default_accessibility = ClangASTContext::eAccessPublic;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002715 }
2716 else if (tag == DW_TAG_class_type)
2717 {
2718 tag_decl_kind = clang::TTK_Class;
Greg Clayton8cf05932010-07-22 18:30:50 +00002719 default_accessibility = ClangASTContext::eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002720 }
2721
2722 assert (tag_decl_kind != -1);
Greg Clayton9e409562010-07-28 02:04:09 +00002723 clang_type = type_list->GetClangASTContext().CreateRecordType (type_name_cstr, tag_decl_kind, GetClangDeclContextForDIE (dwarf_cu, die), class_language);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002724
2725 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
2726 type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
2727
2728 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
2729
2730// assert(type_sp.get());
2731// if (accessibility)
2732// type_sp->SetAccess(accessibility);
2733//
2734 type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
2735 if (die->HasChildren())
2736 {
2737 std::vector<clang::CXXBaseSpecifier *> base_classes;
2738 std::vector<int> member_accessibilities;
2739 bool is_a_class = false;
Greg Clayton9e409562010-07-28 02:04:09 +00002740 ParseChildMembers (sc,
2741 type_sp,
2742 dwarf_cu,
2743 die,
2744 clang_type,
2745 class_language,
2746 base_classes,
2747 member_accessibilities,
2748 default_accessibility,
2749 is_a_class);
2750
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002751 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2752 // need to tell the clang type it is actually a class.
Greg Clayton9e409562010-07-28 02:04:09 +00002753 if (class_language != eLanguageTypeObjC)
2754 {
2755 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2756 type_list->GetClangASTContext().SetTagTypeKind (clang_type, clang::TTK_Class);
2757 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002758
2759 // Since DW_TAG_structure_type gets used for both classes
2760 // and structures, we may need to set any DW_TAG_member
2761 // fields to have a "private" access if none was specified.
2762 // When we parsed the child members we tracked that actual
2763 // accessibility value for each DW_TAG_member in the
2764 // "member_accessibilities" array. If the value for the
2765 // member is zero, then it was set to the "default_accessibility"
2766 // which for structs was "public". Below we correct this
2767 // by setting any fields to "private" that weren't correctly
2768 // set.
2769 if (is_a_class && !member_accessibilities.empty())
2770 {
2771 // This is a class and all members that didn't have
2772 // their access specified are private.
Greg Clayton8cf05932010-07-22 18:30:50 +00002773 type_list->GetClangASTContext().SetDefaultAccessForRecordFields (clang_type, ClangASTContext::eAccessPrivate, &member_accessibilities.front(), member_accessibilities.size());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002774 }
2775
2776 if (!base_classes.empty())
2777 {
Greg Clayton471b31c2010-07-20 22:52:08 +00002778 type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, &base_classes.front(), base_classes.size());
2779
2780 // Clang will copy each CXXBaseSpecifier in "base_classes"
2781 // so we have to free them all.
2782 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), base_classes.size());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002783 }
Greg Clayton0b42ac32010-07-02 01:29:13 +00002784
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002785 }
2786 type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
2787 }
2788 break;
2789
2790 case DW_TAG_enumeration_type:
2791 {
2792 //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag));
2793 // Set a bit that lets us know that we are currently parsing this
2794 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(DIE_IS_BEING_PARSED);
2795
2796 size_t byte_size = 0;
2797 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
2798 Declaration decl;
2799
2800 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2801 if (num_attributes > 0)
2802 {
2803 uint32_t i;
2804
2805 for (i=0; i<num_attributes; ++i)
2806 {
2807 attr = attributes.AttributeAtIndex(i);
2808 DWARFFormValue form_value;
2809 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2810 {
2811 switch (attr)
2812 {
2813 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2814 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2815 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2816 case DW_AT_name:
2817 type_name_cstr = form_value.AsCString(&get_debug_str_data());
2818 type_name_dbstr.SetCString(type_name_cstr);
2819 break;
2820 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
2821 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00002822 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002823 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
2824 case DW_AT_allocated:
2825 case DW_AT_associated:
2826 case DW_AT_bit_stride:
2827 case DW_AT_byte_stride:
2828 case DW_AT_data_location:
2829 case DW_AT_description:
2830 case DW_AT_start_scope:
2831 case DW_AT_visibility:
2832 case DW_AT_specification:
2833 case DW_AT_abstract_origin:
2834 case DW_AT_sibling:
2835 break;
2836 }
2837 }
2838 }
2839
2840 clang_type = type_list->GetClangASTContext().CreateEnumerationType(decl, type_name_cstr);
2841 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
2842 type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, Type::eIsTypeWithUID, &decl, clang_type));
2843
2844 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
2845
2846 if (die->HasChildren())
2847 {
2848 type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
2849 void *enumerator_qual_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, DW_ATE_signed, byte_size * 8);
2850 ParseChildEnumerators(sc, type_sp, enumerator_qual_type, byte_size, dwarf_cu, die);
2851 type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
2852 }
2853 }
2854 }
2855 break;
2856
2857 case DW_TAG_subprogram:
2858 case DW_TAG_subroutine_type:
2859 {
2860 //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag));
2861 // Set a bit that lets us know that we are currently parsing this
2862 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(DIE_IS_BEING_PARSED);
2863
2864 const char *mangled = NULL;
2865 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
2866 Declaration decl;
2867 bool isVariadic = false;
2868 bool is_inline = false;
2869 unsigned type_quals = 0;
2870 clang::FunctionDecl::StorageClass storage = clang::FunctionDecl::None;//, Extern, Static, PrivateExtern
2871
2872
2873 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2874 if (num_attributes > 0)
2875 {
2876 uint32_t i;
2877 for (i=0; i<num_attributes; ++i)
2878 {
2879 attr = attributes.AttributeAtIndex(i);
2880 DWARFFormValue form_value;
2881 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2882 {
2883 switch (attr)
2884 {
2885 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2886 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2887 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2888 case DW_AT_name:
2889 type_name_cstr = form_value.AsCString(&get_debug_str_data());
2890 type_name_dbstr.SetCString(type_name_cstr);
2891 break;
2892
2893 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
2894 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00002895 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002896 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
2897 case DW_AT_external:
2898 if (form_value.Unsigned())
2899 {
2900 if (storage == clang::FunctionDecl::None)
2901 storage = clang::FunctionDecl::Extern;
2902 else
2903 storage = clang::FunctionDecl::PrivateExtern;
2904 }
2905 break;
2906 case DW_AT_inline:
2907 is_inline = form_value.Unsigned() != 0;
2908 break;
2909
2910 case DW_AT_allocated:
2911 case DW_AT_associated:
2912 case DW_AT_address_class:
2913 case DW_AT_artificial:
2914 case DW_AT_calling_convention:
2915 case DW_AT_data_location:
2916 case DW_AT_elemental:
2917 case DW_AT_entry_pc:
2918 case DW_AT_explicit:
2919 case DW_AT_frame_base:
2920 case DW_AT_high_pc:
2921 case DW_AT_low_pc:
2922 case DW_AT_object_pointer:
2923 case DW_AT_prototyped:
2924 case DW_AT_pure:
2925 case DW_AT_ranges:
2926 case DW_AT_recursive:
2927 case DW_AT_return_addr:
2928 case DW_AT_segment:
2929 case DW_AT_specification:
2930 case DW_AT_start_scope:
2931 case DW_AT_static_link:
2932 case DW_AT_trampoline:
2933 case DW_AT_visibility:
2934 case DW_AT_virtuality:
2935 case DW_AT_vtable_elem_location:
2936 case DW_AT_abstract_origin:
2937 case DW_AT_description:
2938 case DW_AT_sibling:
2939 break;
2940 }
2941 }
2942 }
2943
2944 void *return_clang_type = NULL;
2945 Type *func_type = ResolveTypeUID(type_die_offset);
2946 if (func_type)
2947 return_clang_type = func_type->GetOpaqueClangQualType();
2948 else
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002949 return_clang_type = type_list->GetClangASTContext().GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002950
2951 std::vector<void *> function_param_types;
2952 std::vector<clang::ParmVarDecl*> function_param_decls;
2953
2954 // Parse the function children for the parameters
2955 ParseChildParameters(sc, type_sp, dwarf_cu, die, type_list, function_param_types, function_param_decls);
2956
2957 clang_type = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), isVariadic, type_quals);
2958 if (type_name_cstr)
2959 {
2960 clang::FunctionDecl *function_decl = type_list->GetClangASTContext().CreateFunctionDeclaration (type_name_cstr, clang_type, storage, is_inline);
2961 // Add the decl to our DIE to decl context map
2962 assert (function_decl);
2963 m_die_to_decl_ctx[die] = function_decl;
2964 if (!function_param_decls.empty())
Greg Clayton471b31c2010-07-20 22:52:08 +00002965 type_list->GetClangASTContext().SetFunctionParameters (function_decl, &function_param_decls.front(), function_param_decls.size());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002966 }
2967 type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, 0, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
2968
2969 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
2970 assert(type_sp.get());
2971 }
2972 }
2973 break;
2974
2975 case DW_TAG_array_type:
2976 {
2977 //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag));
2978 // Set a bit that lets us know that we are currently parsing this
2979 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(DIE_IS_BEING_PARSED);
2980
2981 size_t byte_size = 0;
2982 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
2983 Declaration decl;
2984 int64_t first_index = 0;
2985 uint32_t byte_stride = 0;
2986 uint32_t bit_stride = 0;
2987 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
2988
2989 if (num_attributes > 0)
2990 {
2991 uint32_t i;
2992 for (i=0; i<num_attributes; ++i)
2993 {
2994 attr = attributes.AttributeAtIndex(i);
2995 DWARFFormValue form_value;
2996 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2997 {
2998 switch (attr)
2999 {
3000 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3001 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3002 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3003 case DW_AT_name:
3004 type_name_cstr = form_value.AsCString(&get_debug_str_data());
3005 type_name_dbstr.SetCString(type_name_cstr);
3006 break;
3007
3008 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
3009 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3010 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3011 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003012 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003013 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
3014 case DW_AT_allocated:
3015 case DW_AT_associated:
3016 case DW_AT_data_location:
3017 case DW_AT_description:
3018 case DW_AT_ordering:
3019 case DW_AT_start_scope:
3020 case DW_AT_visibility:
3021 case DW_AT_specification:
3022 case DW_AT_abstract_origin:
3023 case DW_AT_sibling:
3024 break;
3025 }
3026 }
3027 }
3028
3029 Type *element_type = ResolveTypeUID(type_die_offset);
3030
3031 if (element_type)
3032 {
3033 std::vector<uint64_t> element_orders;
3034 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
3035 if (byte_stride == 0 && bit_stride == 0)
3036 byte_stride = element_type->GetByteSize();
3037 void *array_element_type = element_type->GetOpaqueClangQualType();
3038 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3039 uint64_t num_elements = 0;
3040 std::vector<uint64_t>::const_reverse_iterator pos;
3041 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3042 for (pos = element_orders.rbegin(); pos != end; ++pos)
3043 {
3044 num_elements = *pos;
3045 clang_type = type_list->GetClangASTContext().CreateArrayType (array_element_type, num_elements, num_elements * array_element_bit_stride);
3046 array_element_type = clang_type;
3047 array_element_bit_stride = array_element_bit_stride * num_elements;
3048 }
3049 ConstString empty_name;
3050 type_sp.reset( new Type(die->GetOffset(), this, empty_name, array_element_bit_stride / 8, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
3051 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
3052 }
3053 }
3054 }
3055 break;
3056
Greg Clayton9b81a312010-06-12 01:20:30 +00003057 case DW_TAG_ptr_to_member_type:
3058 {
3059 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3060 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3061
3062 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
3063
3064 if (num_attributes > 0) {
3065 uint32_t i;
3066 for (i=0; i<num_attributes; ++i)
3067 {
3068 attr = attributes.AttributeAtIndex(i);
3069 DWARFFormValue form_value;
3070 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3071 {
3072 switch (attr)
3073 {
3074 case DW_AT_type:
3075 type_die_offset = form_value.Reference(dwarf_cu); break;
3076 case DW_AT_containing_type:
3077 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3078 }
3079 }
3080 }
3081
3082 Type *pointee_type = ResolveTypeUID(type_die_offset);
3083 Type *class_type = ResolveTypeUID(containing_type_die_offset);
3084
3085 void *pointee_clang_type = pointee_type->GetOpaqueClangQualType();
Greg Clayton1ba811d2010-06-12 15:33:14 +00003086 void *class_clang_type = class_type->GetOpaqueClangQualType();
Greg Clayton9b81a312010-06-12 01:20:30 +00003087
Greg Claytonb1320972010-07-14 00:18:15 +00003088 clang_type = type_list->GetClangASTContext().CreateMemberPointerType(pointee_clang_type, class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00003089
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003090 size_t byte_size = ClangASTType::GetClangTypeBitWidth (type_list->GetClangASTContext().getASTContext(), clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00003091
3092 type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, NULL, clang_type));
3093 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(type_sp.get());
3094 }
3095
3096 break;
3097 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003098 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00003099 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003100 break;
3101 }
3102
3103 if (type_sp.get())
3104 {
3105 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3106 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3107
3108 SymbolContextScope * symbol_context_scope = NULL;
3109 if (sc_parent_tag == DW_TAG_compile_unit)
3110 {
3111 symbol_context_scope = sc.comp_unit;
3112 }
3113 else if (sc.function != NULL)
3114 {
3115 symbol_context_scope = sc.function->GetBlocks(true).GetBlockByID(sc_parent_die->GetOffset());
3116 if (symbol_context_scope == NULL)
3117 symbol_context_scope = sc.function;
3118 }
3119
3120 if (symbol_context_scope != NULL)
3121 {
3122 type_sp->SetSymbolContextScope(symbol_context_scope);
3123 }
3124
3125// if (udt_sp.get())
3126// {
3127// if (is_forward_declaration)
3128// udt_sp->GetFlags().Set(UserDefType::flagIsForwardDefinition);
3129// type_sp->SetUserDefinedType(udt_sp);
3130// }
3131
3132 if (type_sp.unique())
3133 {
3134 // We are ready to put this type into the uniqued list up at the module level
3135 TypeSP uniqued_type_sp(m_obj_file->GetModule()->GetTypeList()->InsertUnique(type_sp));
3136
3137 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(uniqued_type_sp.get());
3138
3139 type_sp = uniqued_type_sp;
3140 }
3141 }
3142 }
3143 else
3144 {
3145 switch (tag)
3146 {
3147 case DW_TAG_base_type:
3148 case DW_TAG_pointer_type:
3149 case DW_TAG_reference_type:
3150 case DW_TAG_typedef:
3151 case DW_TAG_const_type:
3152 case DW_TAG_restrict_type:
3153 case DW_TAG_volatile_type:
3154 case DW_TAG_structure_type:
3155 case DW_TAG_union_type:
3156 case DW_TAG_class_type:
3157 case DW_TAG_enumeration_type:
3158 case DW_TAG_subprogram:
3159 case DW_TAG_subroutine_type:
3160 case DW_TAG_array_type:
3161 {
3162 Type *existing_type = (Type*)die->GetUserData();
3163 if (existing_type != DIE_IS_BEING_PARSED)
3164 {
3165 type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(existing_type->GetID());
3166 }
3167 }
3168 break;
3169 default:
3170 //assert(!"invalid type tag...");
3171 break;
3172 }
3173 }
3174 }
3175 return type_sp;
3176}
3177
3178size_t
3179SymbolFileDWARF::ParseTypes (const SymbolContext& sc, const DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool parse_siblings, bool parse_children)
3180{
3181 size_t types_added = 0;
3182 while (die != NULL)
3183 {
3184 bool type_is_new = false;
3185 if (ParseType(sc, dwarf_cu, die, type_is_new).get())
3186 {
3187 if (type_is_new)
3188 ++types_added;
3189 }
3190
3191 if (parse_children && die->HasChildren())
3192 {
3193 if (die->Tag() == DW_TAG_subprogram)
3194 {
3195 SymbolContext child_sc(sc);
3196 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
3197 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
3198 }
3199 else
3200 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
3201 }
3202
3203 if (parse_siblings)
3204 die = die->GetSibling();
3205 else
3206 die = NULL;
3207 }
3208 return types_added;
3209}
3210
3211
3212size_t
3213SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3214{
3215 assert(sc.comp_unit && sc.function);
3216 size_t functions_added = 0;
3217 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3218 if (dwarf_cu)
3219 {
3220 dw_offset_t function_die_offset = sc.function->GetID();
3221 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
3222 if (function_die)
3223 {
3224 ParseFunctionBlocks(sc, Block::RootID, dwarf_cu, function_die, LLDB_INVALID_ADDRESS, false, true);
3225 }
3226 }
3227
3228 return functions_added;
3229}
3230
3231
3232size_t
3233SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3234{
3235 // At least a compile unit must be valid
3236 assert(sc.comp_unit);
3237 size_t types_added = 0;
3238 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3239 if (dwarf_cu)
3240 {
3241 if (sc.function)
3242 {
3243 dw_offset_t function_die_offset = sc.function->GetID();
3244 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
3245 if (func_die && func_die->HasChildren())
3246 {
3247 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
3248 }
3249 }
3250 else
3251 {
3252 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
3253 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
3254 {
3255 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
3256 }
3257 }
3258 }
3259
3260 return types_added;
3261}
3262
3263size_t
3264SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3265{
3266 if (sc.comp_unit != NULL)
3267 {
3268 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3269
3270 if (dwarf_cu == NULL)
3271 return 0;
3272
3273 if (sc.function)
3274 {
3275 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
3276 return ParseVariables(sc, dwarf_cu, function_die->GetFirstChild(), true, true);
3277 }
3278 else if (sc.comp_unit)
3279 {
3280 uint32_t vars_added = 0;
3281 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3282
3283 if (variables.get() == NULL)
3284 {
3285 variables.reset(new VariableList());
3286 sc.comp_unit->SetVariableList(variables);
3287
3288 // Index if we already haven't to make sure the compile units
3289 // get indexed and make their global DIE index list
3290 if (!m_indexed)
3291 Index ();
3292
3293 const size_t num_globals = dwarf_cu->GetNumGlobals();
3294 for (size_t idx=0; idx<num_globals; ++idx)
3295 {
3296 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetGlobalDIEAtIndex (idx)));
3297 if (var_sp)
3298 {
3299 variables->AddVariable(var_sp);
3300 ++vars_added;
3301 }
3302 }
3303 }
3304 return vars_added;
3305 }
3306 }
3307 return 0;
3308}
3309
3310
3311VariableSP
3312SymbolFileDWARF::ParseVariableDIE
3313(
3314 const SymbolContext& sc,
3315 const DWARFCompileUnit* dwarf_cu,
3316 const DWARFDebugInfoEntry *die
3317)
3318{
3319
3320 VariableSP var_sp;
3321
3322 const dw_tag_t tag = die->Tag();
3323 DWARFDebugInfoEntry::Attributes attributes;
3324 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, attributes);
3325 if (num_attributes > 0)
3326 {
3327 const char *name = NULL;
3328 Declaration decl;
3329 uint32_t i;
3330 TypeSP type_sp;
3331 Type *var_type = NULL;
3332 DWARFExpression location;
3333 bool is_external = false;
3334 bool is_artificial = false;
Greg Clayton8cf05932010-07-22 18:30:50 +00003335 ClangASTContext::AccessType accessibility = ClangASTContext::eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003336
3337 for (i=0; i<num_attributes; ++i)
3338 {
3339 dw_attr_t attr = attributes.AttributeAtIndex(i);
3340 DWARFFormValue form_value;
3341 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3342 {
3343 switch (attr)
3344 {
3345 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3346 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3347 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3348 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3349 case DW_AT_type: var_type = GetUniquedTypeForDIEOffset(form_value.Reference(dwarf_cu), type_sp, 0, 0, false); break;
3350 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
3351 case DW_AT_location:
3352 {
3353 if (form_value.BlockData())
3354 {
3355 const DataExtractor& debug_info_data = get_debug_info_data();
3356
3357 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3358 uint32_t block_length = form_value.Unsigned();
3359 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length, NULL);
3360 }
3361 else
3362 {
3363 const DataExtractor& debug_loc_data = get_debug_loc_data();
3364 const dw_offset_t debug_loc_offset = form_value.Unsigned();
3365
3366 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
3367 if (loc_list_length > 0)
3368 {
3369 Address base_address(dwarf_cu->GetBaseAddress(), m_obj_file->GetSectionList());
3370 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length, &base_address);
3371 }
3372 }
3373 }
3374 break;
3375
3376 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003377 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003378 case DW_AT_const_value:
3379 case DW_AT_declaration:
3380 case DW_AT_description:
3381 case DW_AT_endianity:
3382 case DW_AT_segment:
3383 case DW_AT_start_scope:
3384 case DW_AT_visibility:
3385 default:
3386 case DW_AT_abstract_origin:
3387 case DW_AT_sibling:
3388 case DW_AT_specification:
3389 break;
3390 }
3391 }
3392 }
3393
3394 if (location.IsValid())
3395 {
3396 assert(var_type != DIE_IS_BEING_PARSED);
3397
3398 ConstString var_name(name);
3399
3400 ValueType scope = eValueTypeInvalid;
3401
3402 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3403 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3404
3405 if (tag == DW_TAG_formal_parameter)
3406 scope = eValueTypeVariableArgument;
3407 else if (is_external || parent_tag == DW_TAG_compile_unit)
3408 scope = eValueTypeVariableGlobal;
3409 else
3410 scope = eValueTypeVariableLocal;
3411
3412 SymbolContextScope * symbol_context_scope = NULL;
3413 if (parent_tag == DW_TAG_compile_unit)
3414 {
3415 symbol_context_scope = sc.comp_unit;
3416 }
3417 else if (sc.function != NULL)
3418 {
3419 symbol_context_scope = sc.function->GetBlocks(true).GetBlockByID(sc_parent_die->GetOffset());
3420 if (symbol_context_scope == NULL)
3421 symbol_context_scope = sc.function;
3422 }
3423
3424 assert(symbol_context_scope != NULL);
3425 var_sp.reset (new Variable(die->GetOffset(),
3426 var_name,
3427 var_type,
3428 scope,
3429 symbol_context_scope,
3430 &decl,
3431 location,
3432 is_external,
3433 is_artificial));
3434 const_cast<DWARFDebugInfoEntry*>(die)->SetUserData(var_sp.get());
3435 }
3436 }
3437 return var_sp;
3438}
3439
3440size_t
3441SymbolFileDWARF::ParseVariables
3442(
3443 const SymbolContext& sc,
3444 const DWARFCompileUnit* dwarf_cu,
3445 const DWARFDebugInfoEntry *orig_die,
3446 bool parse_siblings,
3447 bool parse_children,
3448 VariableList* cc_variable_list
3449)
3450{
3451 if (orig_die == NULL)
3452 return 0;
3453
3454 size_t vars_added = 0;
3455 const DWARFDebugInfoEntry *die = orig_die;
3456 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
3457 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3458 VariableListSP variables;
3459 switch (parent_tag)
3460 {
3461 case DW_TAG_compile_unit:
3462 if (sc.comp_unit != NULL)
3463 {
3464 variables = sc.comp_unit->GetVariableList(false);
3465 if (variables.get() == NULL)
3466 {
3467 variables.reset(new VariableList());
3468 sc.comp_unit->SetVariableList(variables);
3469 }
3470 }
3471 else
3472 {
3473 assert(!"Parent DIE was a compile unit, yet we don't have a valid compile unit in the symbol context...");
3474 vars_added = 0;
3475 }
3476 break;
3477
3478 case DW_TAG_subprogram:
3479 case DW_TAG_inlined_subroutine:
3480 case DW_TAG_lexical_block:
3481 if (sc.function != NULL)
3482 {
3483 // Check to see if we already have parsed the variables for the given scope
3484 variables = sc.function->GetBlocks(true).GetVariableList(sc_parent_die->GetOffset(), false, false);
3485 if (variables.get() == NULL)
3486 {
3487 variables.reset(new VariableList());
3488 sc.function->GetBlocks(true).SetVariableList(sc_parent_die->GetOffset(), variables);
3489 }
3490 }
3491 else
3492 {
3493 assert(!"Parent DIE was a function or block, yet we don't have a function in the symbol context...");
3494 vars_added = 0;
3495 }
3496 break;
3497
3498 default:
3499 assert(!"Didn't find appropriate parent DIE for variable list...");
3500 break;
3501 }
3502
3503 // We need to have a variable list at this point that we can add variables to
3504 assert(variables.get());
3505
3506 while (die != NULL)
3507 {
3508 dw_tag_t tag = die->Tag();
3509
3510 // Check to see if we have already parsed this variable or constant?
3511 if (die->GetUserData() == NULL)
3512 {
3513 // We haven't already parsed it, lets do that now.
3514 if ((tag == DW_TAG_variable) ||
3515 (tag == DW_TAG_constant) ||
3516 (tag == DW_TAG_formal_parameter && sc.function))
3517 {
3518 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die));
3519 if (var_sp)
3520 {
3521 variables->AddVariable(var_sp);
3522 ++vars_added;
3523 }
3524 }
3525 }
3526
3527 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
3528
3529 if (!skip_children && parse_children && die->HasChildren())
3530 {
3531 vars_added += ParseVariables(sc, dwarf_cu, die->GetFirstChild(), true, true);
3532 //vars_added += ParseVariables(sc, dwarf_cu, die->GetFirstChild(), parse_siblings, parse_children);
3533 }
3534
3535 if (parse_siblings)
3536 die = die->GetSibling();
3537 else
3538 die = NULL;
3539 }
3540
3541 if (cc_variable_list)
3542 {
3543 cc_variable_list->AddVariables(variables.get());
3544 }
3545
3546 return vars_added;
3547}
3548
3549//------------------------------------------------------------------
3550// PluginInterface protocol
3551//------------------------------------------------------------------
3552const char *
3553SymbolFileDWARF::GetPluginName()
3554{
3555 return "SymbolFileDWARF";
3556}
3557
3558const char *
3559SymbolFileDWARF::GetShortPluginName()
3560{
3561 return GetPluginNameStatic();
3562}
3563
3564uint32_t
3565SymbolFileDWARF::GetPluginVersion()
3566{
3567 return 1;
3568}
3569
3570void
3571SymbolFileDWARF::GetPluginCommandHelp (const char *command, Stream *strm)
3572{
3573}
3574
3575Error
3576SymbolFileDWARF::ExecutePluginCommand (Args &command, Stream *strm)
3577{
3578 Error error;
3579 error.SetErrorString("No plug-in command are currently supported.");
3580 return error;
3581}
3582
3583Log *
3584SymbolFileDWARF::EnablePluginLogging (Stream *strm, Args &command)
3585{
3586 return NULL;
3587}
3588