blob: 84dcf25e27e3536a189e9efcea503e07918454b3 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
17#include "clang/Basic/Builtins.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/Basic/LangOptions.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000023#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Sean Callanancc427fa2011-07-30 02:42:06 +000025#include "llvm/Support/Casting.h"
26
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/PluginManager.h"
29#include "lldb/Core/RegularExpression.h"
30#include "lldb/Core/Scalar.h"
31#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000032#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/Timer.h"
34#include "lldb/Core/Value.h"
35
36#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000037#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Symbol/CompileUnit.h"
39#include "lldb/Symbol/LineTable.h"
40#include "lldb/Symbol/ObjectFile.h"
41#include "lldb/Symbol/SymbolVendor.h"
42#include "lldb/Symbol/VariableList.h"
43
44#include "DWARFCompileUnit.h"
45#include "DWARFDebugAbbrev.h"
46#include "DWARFDebugAranges.h"
47#include "DWARFDebugInfo.h"
48#include "DWARFDebugInfoEntry.h"
49#include "DWARFDebugLine.h"
50#include "DWARFDebugPubnames.h"
51#include "DWARFDebugRanges.h"
52#include "DWARFDIECollection.h"
53#include "DWARFFormValue.h"
54#include "DWARFLocationList.h"
55#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000056#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58#include <map>
59
Greg Clayton62742b12010-11-11 01:09:45 +000060//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000061
62#ifdef ENABLE_DEBUG_PRINTF
63#include <stdio.h>
64#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
65#else
66#define DEBUG_PRINTF(fmt, ...)
67#endif
68
Greg Clayton594e5ed2010-09-27 21:07:38 +000069#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070
71using namespace lldb;
72using namespace lldb_private;
73
74
Sean Callananc7fbf732010-08-06 00:32:49 +000075static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000076DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077{
78 switch (dwarf_accessibility)
79 {
Sean Callananc7fbf732010-08-06 00:32:49 +000080 case DW_ACCESS_public: return eAccessPublic;
81 case DW_ACCESS_private: return eAccessPrivate;
82 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000083 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 }
Sean Callananc7fbf732010-08-06 00:32:49 +000085 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086}
87
88void
89SymbolFileDWARF::Initialize()
90{
91 LogChannelDWARF::Initialize();
92 PluginManager::RegisterPlugin (GetPluginNameStatic(),
93 GetPluginDescriptionStatic(),
94 CreateInstance);
95}
96
97void
98SymbolFileDWARF::Terminate()
99{
100 PluginManager::UnregisterPlugin (CreateInstance);
101 LogChannelDWARF::Initialize();
102}
103
104
105const char *
106SymbolFileDWARF::GetPluginNameStatic()
107{
108 return "symbol-file.dwarf2";
109}
110
111const char *
112SymbolFileDWARF::GetPluginDescriptionStatic()
113{
114 return "DWARF and DWARF3 debug symbol file reader.";
115}
116
117
118SymbolFile*
119SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
120{
121 return new SymbolFileDWARF(obj_file);
122}
123
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000124TypeList *
125SymbolFileDWARF::GetTypeList ()
126{
127 if (m_debug_map_symfile)
128 return m_debug_map_symfile->GetTypeList();
129 return m_obj_file->GetModule()->GetTypeList();
130
131}
132
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000133//----------------------------------------------------------------------
134// Gets the first parent that is a lexical block, function or inlined
135// subroutine, or compile unit.
136//----------------------------------------------------------------------
137static const DWARFDebugInfoEntry *
138GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
139{
140 const DWARFDebugInfoEntry *die;
141 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
142 {
143 dw_tag_t tag = die->Tag();
144
145 switch (tag)
146 {
147 case DW_TAG_compile_unit:
148 case DW_TAG_subprogram:
149 case DW_TAG_inlined_subroutine:
150 case DW_TAG_lexical_block:
151 return die;
152 }
153 }
154 return NULL;
155}
156
157
Greg Clayton450e3f32010-10-12 02:24:53 +0000158SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
159 SymbolFile (objfile),
160 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000161 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162 m_flags(),
163 m_data_debug_abbrev(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164 m_data_debug_frame(),
165 m_data_debug_info(),
166 m_data_debug_line(),
167 m_data_debug_loc(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168 m_data_debug_ranges(),
169 m_data_debug_str(),
170 m_abbr(),
171 m_aranges(),
172 m_info(),
173 m_line(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000174 m_function_basename_index(),
175 m_function_fullname_index(),
176 m_function_method_index(),
177 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000178 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000179 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000180 m_type_index(),
181 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000182 m_indexed (false),
183 m_is_external_ast_source (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000184 m_ranges(),
185 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186{
187}
188
189SymbolFileDWARF::~SymbolFileDWARF()
190{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000191 if (m_is_external_ast_source)
192 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
193}
194
195static const ConstString &
196GetDWARFMachOSegmentName ()
197{
198 static ConstString g_dwarf_section_name ("__DWARF");
199 return g_dwarf_section_name;
200}
201
Greg Claytone576ab22011-02-15 00:19:15 +0000202UniqueDWARFASTTypeMap &
203SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
204{
205 if (m_debug_map_symfile)
206 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
207 return m_unique_ast_type_map;
208}
209
Greg Clayton6beaaa62011-01-17 03:46:26 +0000210ClangASTContext &
211SymbolFileDWARF::GetClangASTContext ()
212{
213 if (m_debug_map_symfile)
214 return m_debug_map_symfile->GetClangASTContext ();
215
216 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
217 if (!m_is_external_ast_source)
218 {
219 m_is_external_ast_source = true;
220 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
221 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
222 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000223 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000224 this));
225
226 ast.SetExternalSource (ast_source_ap);
227 }
228 return ast;
229}
230
231void
232SymbolFileDWARF::InitializeObject()
233{
234 // Install our external AST source callbacks so we can complete Clang types.
235 Module *module = m_obj_file->GetModule();
236 if (module)
237 {
238 const SectionList *section_list = m_obj_file->GetSectionList();
239
240 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
241
242 // Memory map the DWARF mach-o segment so we have everything mmap'ed
243 // to keep our heap memory usage down.
244 if (section)
245 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
246 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247}
248
249bool
250SymbolFileDWARF::SupportedVersion(uint16_t version)
251{
252 return version == 2 || version == 3;
253}
254
255uint32_t
256SymbolFileDWARF::GetAbilities ()
257{
258 uint32_t abilities = 0;
259 if (m_obj_file != NULL)
260 {
261 const Section* section = NULL;
262 const SectionList *section_list = m_obj_file->GetSectionList();
263 if (section_list == NULL)
264 return 0;
265
266 uint64_t debug_abbrev_file_size = 0;
267 uint64_t debug_aranges_file_size = 0;
268 uint64_t debug_frame_file_size = 0;
269 uint64_t debug_info_file_size = 0;
270 uint64_t debug_line_file_size = 0;
271 uint64_t debug_loc_file_size = 0;
272 uint64_t debug_macinfo_file_size = 0;
273 uint64_t debug_pubnames_file_size = 0;
274 uint64_t debug_pubtypes_file_size = 0;
275 uint64_t debug_ranges_file_size = 0;
276 uint64_t debug_str_file_size = 0;
277
Greg Clayton6beaaa62011-01-17 03:46:26 +0000278 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000279
280 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000281 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282
Greg Clayton4ceb9982010-07-21 22:54:26 +0000283 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284 if (section != NULL)
285 {
286 debug_info_file_size = section->GetByteSize();
287
Greg Clayton4ceb9982010-07-21 22:54:26 +0000288 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 if (section)
290 debug_abbrev_file_size = section->GetByteSize();
291 else
292 m_flags.Set (flagsGotDebugAbbrevData);
293
Greg Clayton4ceb9982010-07-21 22:54:26 +0000294 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295 if (section)
296 debug_aranges_file_size = section->GetByteSize();
297 else
298 m_flags.Set (flagsGotDebugArangesData);
299
Greg Clayton4ceb9982010-07-21 22:54:26 +0000300 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301 if (section)
302 debug_frame_file_size = section->GetByteSize();
303 else
304 m_flags.Set (flagsGotDebugFrameData);
305
Greg Clayton4ceb9982010-07-21 22:54:26 +0000306 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307 if (section)
308 debug_line_file_size = section->GetByteSize();
309 else
310 m_flags.Set (flagsGotDebugLineData);
311
Greg Clayton4ceb9982010-07-21 22:54:26 +0000312 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 if (section)
314 debug_loc_file_size = section->GetByteSize();
315 else
316 m_flags.Set (flagsGotDebugLocData);
317
Greg Clayton4ceb9982010-07-21 22:54:26 +0000318 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319 if (section)
320 debug_macinfo_file_size = section->GetByteSize();
321 else
322 m_flags.Set (flagsGotDebugMacInfoData);
323
Greg Clayton4ceb9982010-07-21 22:54:26 +0000324 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325 if (section)
326 debug_pubnames_file_size = section->GetByteSize();
327 else
328 m_flags.Set (flagsGotDebugPubNamesData);
329
Greg Clayton4ceb9982010-07-21 22:54:26 +0000330 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331 if (section)
332 debug_pubtypes_file_size = section->GetByteSize();
333 else
334 m_flags.Set (flagsGotDebugPubTypesData);
335
Greg Clayton4ceb9982010-07-21 22:54:26 +0000336 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337 if (section)
338 debug_ranges_file_size = section->GetByteSize();
339 else
340 m_flags.Set (flagsGotDebugRangesData);
341
Greg Clayton4ceb9982010-07-21 22:54:26 +0000342 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 if (section)
344 debug_str_file_size = section->GetByteSize();
345 else
346 m_flags.Set (flagsGotDebugStrData);
347 }
348
349 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
350 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
351
352 if (debug_line_file_size > 0)
353 abilities |= LineTables;
354
355 if (debug_aranges_file_size > 0)
356 abilities |= AddressAcceleratorTable;
357
358 if (debug_pubnames_file_size > 0)
359 abilities |= FunctionAcceleratorTable;
360
361 if (debug_pubtypes_file_size > 0)
362 abilities |= TypeAcceleratorTable;
363
364 if (debug_macinfo_file_size > 0)
365 abilities |= MacroInformation;
366
367 if (debug_frame_file_size > 0)
368 abilities |= CallFrameInformation;
369 }
370 return abilities;
371}
372
373const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000374SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375{
376 if (m_flags.IsClear (got_flag))
377 {
378 m_flags.Set (got_flag);
379 const SectionList *section_list = m_obj_file->GetSectionList();
380 if (section_list)
381 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000382 Section *section = section_list->FindSectionByType(sect_type, true).get();
383 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 {
385 // See if we memory mapped the DWARF segment?
386 if (m_dwarf_data.GetByteSize())
387 {
388 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
389 }
390 else
391 {
392 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
393 data.Clear();
394 }
395 }
396 }
397 }
398 return data;
399}
400
401const DataExtractor&
402SymbolFileDWARF::get_debug_abbrev_data()
403{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000404 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
407const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408SymbolFileDWARF::get_debug_frame_data()
409{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000410 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411}
412
413const DataExtractor&
414SymbolFileDWARF::get_debug_info_data()
415{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000416 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417}
418
419const DataExtractor&
420SymbolFileDWARF::get_debug_line_data()
421{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000422 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423}
424
425const DataExtractor&
426SymbolFileDWARF::get_debug_loc_data()
427{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000428 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429}
430
431const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432SymbolFileDWARF::get_debug_ranges_data()
433{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000434 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435}
436
437const DataExtractor&
438SymbolFileDWARF::get_debug_str_data()
439{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000440 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441}
442
443
444DWARFDebugAbbrev*
445SymbolFileDWARF::DebugAbbrev()
446{
447 if (m_abbr.get() == NULL)
448 {
449 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
450 if (debug_abbrev_data.GetByteSize() > 0)
451 {
452 m_abbr.reset(new DWARFDebugAbbrev());
453 if (m_abbr.get())
454 m_abbr->Parse(debug_abbrev_data);
455 }
456 }
457 return m_abbr.get();
458}
459
460const DWARFDebugAbbrev*
461SymbolFileDWARF::DebugAbbrev() const
462{
463 return m_abbr.get();
464}
465
466DWARFDebugAranges*
467SymbolFileDWARF::DebugAranges()
468{
Greg Clayton016a95e2010-09-14 02:20:48 +0000469 // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files
470 // and we are already parsing all of the DWARF because the .debug_pubnames
471 // is useless (it only mentions symbols that are externally visible), so
472 // don't use the .debug_aranges section, we should be using a debug aranges
473 // we got from SymbolFileDWARF::Index().
474
475 if (!m_indexed)
476 Index();
477
478
479// if (m_aranges.get() == NULL)
480// {
481// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
482// m_aranges.reset(new DWARFDebugAranges());
483// if (m_aranges.get())
484// {
485// const DataExtractor &debug_aranges_data = get_debug_aranges_data();
486// if (debug_aranges_data.GetByteSize() > 0)
487// m_aranges->Extract(debug_aranges_data);
488// else
489// m_aranges->Generate(this);
490// }
491// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492 return m_aranges.get();
493}
494
495const DWARFDebugAranges*
496SymbolFileDWARF::DebugAranges() const
497{
498 return m_aranges.get();
499}
500
501
502DWARFDebugInfo*
503SymbolFileDWARF::DebugInfo()
504{
505 if (m_info.get() == NULL)
506 {
507 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
508 if (get_debug_info_data().GetByteSize() > 0)
509 {
510 m_info.reset(new DWARFDebugInfo());
511 if (m_info.get())
512 {
513 m_info->SetDwarfData(this);
514 }
515 }
516 }
517 return m_info.get();
518}
519
520const DWARFDebugInfo*
521SymbolFileDWARF::DebugInfo() const
522{
523 return m_info.get();
524}
525
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526DWARFCompileUnit*
527SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
528{
529 DWARFDebugInfo* info = DebugInfo();
530 if (info)
531 return info->GetCompileUnit(cu_uid).get();
532 return NULL;
533}
534
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535
536DWARFDebugRanges*
537SymbolFileDWARF::DebugRanges()
538{
539 if (m_ranges.get() == NULL)
540 {
541 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
542 if (get_debug_ranges_data().GetByteSize() > 0)
543 {
544 m_ranges.reset(new DWARFDebugRanges());
545 if (m_ranges.get())
546 m_ranges->Extract(this);
547 }
548 }
549 return m_ranges.get();
550}
551
552const DWARFDebugRanges*
553SymbolFileDWARF::DebugRanges() const
554{
555 return m_ranges.get();
556}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557
558bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000559SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560{
Greg Clayton96d7d742010-11-10 23:42:09 +0000561 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000563 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 if (cu_die)
565 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000566 const char * cu_die_name = cu_die->GetName(this, curr_cu);
567 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
568 LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 if (cu_die_name)
570 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000571 FileSpec cu_file_spec;
572
Greg Clayton7bd65b92011-02-09 23:39:34 +0000573 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000575 // If we have a full path to the compile unit, we don't need to resolve
576 // the file. This can be expensive e.g. when the source files are NFS mounted.
577 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578 }
579 else
580 {
581 std::string fullpath(cu_comp_dir);
582 if (*fullpath.rbegin() != '/')
583 fullpath += '/';
584 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000585 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 }
587
Greg Clayton96d7d742010-11-10 23:42:09 +0000588 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), curr_cu, cu_file_spec, curr_cu->GetOffset(), class_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589 if (compile_unit_sp.get())
590 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000591 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592 return true;
593 }
594 }
595 }
596 }
597 return false;
598}
599
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600uint32_t
601SymbolFileDWARF::GetNumCompileUnits()
602{
603 DWARFDebugInfo* info = DebugInfo();
604 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606 return 0;
607}
608
609CompUnitSP
610SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
611{
612 CompUnitSP comp_unit;
613 DWARFDebugInfo* info = DebugInfo();
614 if (info)
615 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000616 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
617 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618 {
619 // Our symbol vendor shouldn't be asking us to add a compile unit that
620 // has already been added to it, which this DWARF plug-in knows as it
621 // stores the lldb compile unit (CompileUnit) pointer in each
622 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000623 assert(curr_cu->GetUserData() == NULL);
624 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 }
626 }
627 return comp_unit;
628}
629
630static void
631AddRangesToBlock
632(
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000633 Block& block,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 DWARFDebugRanges::RangeList& ranges,
635 addr_t block_base_addr
636)
637{
638 ranges.SubtractOffset (block_base_addr);
639 size_t range_idx = 0;
640 const DWARFDebugRanges::Range *debug_range;
641 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
642 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000643 block.AddRange(debug_range->begin_offset, debug_range->end_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 }
645}
646
647
648Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000649SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650{
651 DWARFDebugRanges::RangeList func_ranges;
652 const char *name = NULL;
653 const char *mangled = NULL;
654 int decl_file = 0;
655 int decl_line = 0;
656 int decl_column = 0;
657 int call_file = 0;
658 int call_line = 0;
659 int call_column = 0;
660 DWARFExpression frame_base;
661
Greg Claytonc93237c2010-10-01 20:48:32 +0000662 assert (die->Tag() == DW_TAG_subprogram);
663
664 if (die->Tag() != DW_TAG_subprogram)
665 return NULL;
666
Greg Clayton5113dc82011-08-12 06:47:54 +0000667 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
668 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
Greg Claytonc93237c2010-10-01 20:48:32 +0000669
Greg Clayton5113dc82011-08-12 06:47:54 +0000670 switch (containing_decl_kind)
671 {
672 case clang::Decl::Record:
673 case clang::Decl::CXXRecord:
674 case clang::Decl::ObjCClass:
675 case clang::Decl::ObjCImplementation:
676 case clang::Decl::ObjCInterface:
677 // We have methods of a class or struct
678 {
679 const DWARFDebugInfoEntry *containing_decl_die = m_decl_ctx_to_die[containing_decl_ctx];
680 assert (containing_decl_die);
681 Type *class_type = ResolveType (dwarf_cu, containing_decl_die);
682 if (class_type)
683 class_type->GetClangFullType();
684 // Make sure the class definition contains the funciton DIE
685 // we wanted to parse. If it does, we are done. Else, we need
686 // to fall through and parse the function DIE stil...
687 if (containing_decl_die->Contains (die))
688 break; // DIE has been parsed, we are done
689 }
690 // Fall through...
691
692 default:
693 // Parse the function prototype as a type that can then be added to concrete function instance
694 ParseTypes (sc, dwarf_cu, die, false, false);
695 break;
Greg Claytonc93237c2010-10-01 20:48:32 +0000696 }
697
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698 //FixupTypes();
699
700 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
701 {
702 // Union of all ranges in the function DIE (if the function is discontiguous)
703 AddressRange func_range;
704 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
705 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
706 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
707 {
708 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
709 if (func_range.GetBaseAddress().IsValid())
710 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
711 }
712
713 if (func_range.GetBaseAddress().IsValid())
714 {
715 Mangled func_name;
716 if (mangled)
717 func_name.SetValue(mangled, true);
718 else if (name)
719 func_name.SetValue(name, false);
720
721 FunctionSP func_sp;
722 std::auto_ptr<Declaration> decl_ap;
723 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000724 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
725 decl_line,
726 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727
Greg Clayton594e5ed2010-09-27 21:07:38 +0000728 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729
730 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
731
732 func_range.GetBaseAddress().ResolveLinkedAddress();
733
734 func_sp.reset(new Function (sc.comp_unit,
735 die->GetOffset(), // UserID is the DIE offset
736 die->GetOffset(),
737 func_name,
738 func_type,
739 func_range)); // first address range
740
741 if (func_sp.get() != NULL)
742 {
743 func_sp->GetFrameBaseExpression() = frame_base;
744 sc.comp_unit->AddFunction(func_sp);
745 return func_sp.get();
746 }
747 }
748 }
749 return NULL;
750}
751
752size_t
753SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
754{
755 assert (sc.comp_unit);
756 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000757 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000758 if (dwarf_cu)
759 {
760 DWARFDIECollection function_dies;
761 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
762 size_t func_idx;
763 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
764 {
765 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
766 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
767 {
768 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
769 ++functions_added;
770 }
771 }
772 //FixupTypes();
773 }
774 return functions_added;
775}
776
777bool
778SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
779{
780 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000781 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
782 assert (curr_cu);
783 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784
785 if (cu_die)
786 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000787 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
788 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789
790 // All file indexes in DWARF are one based and a file of index zero is
791 // supposed to be the compile unit itself.
792 support_files.Append (*sc.comp_unit);
793
794 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
795 }
796 return false;
797}
798
799struct ParseDWARFLineTableCallbackInfo
800{
801 LineTable* line_table;
802 const SectionList *section_list;
803 lldb::addr_t prev_sect_file_base_addr;
804 lldb::addr_t curr_sect_file_base_addr;
805 bool is_oso_for_debug_map;
806 bool prev_in_final_executable;
807 DWARFDebugLine::Row prev_row;
808 SectionSP prev_section_sp;
809 SectionSP curr_section_sp;
810};
811
812//----------------------------------------------------------------------
813// ParseStatementTableCallback
814//----------------------------------------------------------------------
815static void
816ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
817{
818 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
819 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
820 {
821 // Just started parsing the line table
822 }
823 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
824 {
825 // Done parsing line table, nothing to do for the cleanup
826 }
827 else
828 {
829 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
830 // We have a new row, lets append it
831
832 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
833 {
834 info->prev_section_sp = info->curr_section_sp;
835 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
836 // If this is an end sequence entry, then we subtract one from the
837 // address to make sure we get an address that is not the end of
838 // a section.
839 if (state.end_sequence && state.address != 0)
840 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
841 else
842 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
843
844 if (info->curr_section_sp.get())
845 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
846 else
847 info->curr_sect_file_base_addr = 0;
848 }
849 if (info->curr_section_sp.get())
850 {
851 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
852 // Check for the fancy section magic to determine if we
853
854 if (info->is_oso_for_debug_map)
855 {
856 // When this is a debug map object file that contains DWARF
857 // (referenced from an N_OSO debug map nlist entry) we will have
858 // a file address in the file range for our section from the
859 // original .o file, and a load address in the executable that
860 // contains the debug map.
861 //
862 // If the sections for the file range and load range are
863 // different, we have a remapped section for the function and
864 // this address is resolved. If they are the same, then the
865 // function for this address didn't make it into the final
866 // executable.
867 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
868
869 // If we are doing DWARF with debug map, then we need to carefully
870 // add each line table entry as there may be gaps as functions
871 // get moved around or removed.
872 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
873 {
874 if (info->prev_in_final_executable)
875 {
876 bool terminate_previous_entry = false;
877 if (!curr_in_final_executable)
878 {
879 // Check for the case where the previous line entry
880 // in a function made it into the final executable,
881 // yet the current line entry falls in a function
882 // that didn't. The line table used to be contiguous
883 // through this address range but now it isn't. We
884 // need to terminate the previous line entry so
885 // that we can reconstruct the line range correctly
886 // for it and to keep the line table correct.
887 terminate_previous_entry = true;
888 }
889 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
890 {
891 // Check for cases where the line entries used to be
892 // contiguous address ranges, but now they aren't.
893 // This can happen when order files specify the
894 // ordering of the functions.
895 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
896 Section *curr_sect = info->curr_section_sp.get();
897 Section *prev_sect = info->prev_section_sp.get();
898 assert (curr_sect->GetLinkedSection());
899 assert (prev_sect->GetLinkedSection());
900 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
901 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
902 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
903 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
904 if (object_file_addr_delta != linked_file_addr_delta)
905 terminate_previous_entry = true;
906 }
907
908 if (terminate_previous_entry)
909 {
910 line_table->InsertLineEntry (info->prev_section_sp,
911 state.address - info->prev_sect_file_base_addr,
912 info->prev_row.line,
913 info->prev_row.column,
914 info->prev_row.file,
915 false, // is_stmt
916 false, // basic_block
917 false, // state.prologue_end
918 false, // state.epilogue_begin
919 true); // end_sequence);
920 }
921 }
922 }
923
924 if (curr_in_final_executable)
925 {
926 line_table->InsertLineEntry (info->curr_section_sp,
927 curr_line_section_offset,
928 state.line,
929 state.column,
930 state.file,
931 state.is_stmt,
932 state.basic_block,
933 state.prologue_end,
934 state.epilogue_begin,
935 state.end_sequence);
936 info->prev_section_sp = info->curr_section_sp;
937 }
938 else
939 {
940 // If the current address didn't make it into the final
941 // executable, the current section will be the __text
942 // segment in the .o file, so we need to clear this so
943 // we can catch the next function that did make it into
944 // the final executable.
945 info->prev_section_sp.reset();
946 info->curr_section_sp.reset();
947 }
948
949 info->prev_in_final_executable = curr_in_final_executable;
950 }
951 else
952 {
953 // We are not in an object file that contains DWARF for an
954 // N_OSO, this is just a normal DWARF file. The DWARF spec
955 // guarantees that the addresses will be in increasing order
956 // so, since we store line tables in file address order, we
957 // can always just append the line entry without needing to
958 // search for the correct insertion point (we don't need to
959 // use LineEntry::InsertLineEntry()).
960 line_table->AppendLineEntry (info->curr_section_sp,
961 curr_line_section_offset,
962 state.line,
963 state.column,
964 state.file,
965 state.is_stmt,
966 state.basic_block,
967 state.prologue_end,
968 state.epilogue_begin,
969 state.end_sequence);
970 }
971 }
972
973 info->prev_row = state;
974 }
975}
976
977bool
978SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
979{
980 assert (sc.comp_unit);
981 if (sc.comp_unit->GetLineTable() != NULL)
982 return true;
983
984 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
985 if (dwarf_cu)
986 {
987 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
988 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
989 if (cu_line_offset != DW_INVALID_OFFSET)
990 {
991 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
992 if (line_table_ap.get())
993 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000994 ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_debug_map_symfile != NULL, false};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 uint32_t offset = cu_line_offset;
996 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
997 sc.comp_unit->SetLineTable(line_table_ap.release());
998 return true;
999 }
1000 }
1001 }
1002 return false;
1003}
1004
1005size_t
1006SymbolFileDWARF::ParseFunctionBlocks
1007(
1008 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001009 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001010 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001011 const DWARFDebugInfoEntry *die,
1012 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001013 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014)
1015{
1016 size_t blocks_added = 0;
1017 while (die != NULL)
1018 {
1019 dw_tag_t tag = die->Tag();
1020
1021 switch (tag)
1022 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001024 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 case DW_TAG_lexical_block:
1026 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001027 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001028 if (tag == DW_TAG_subprogram)
1029 {
1030 // Skip any DW_TAG_subprogram DIEs that are inside
1031 // of a normal or inlined functions. These will be
1032 // parsed on their own as separate entities.
1033
1034 if (depth > 0)
1035 break;
1036
1037 block = parent_block;
1038 }
1039 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001040 {
1041 BlockSP block_sp(new Block (die->GetOffset()));
1042 parent_block->AddChild(block_sp);
1043 block = block_sp.get();
1044 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001045 DWARFDebugRanges::RangeList ranges;
1046 const char *name = NULL;
1047 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049 int decl_file = 0;
1050 int decl_line = 0;
1051 int decl_column = 0;
1052 int call_file = 0;
1053 int call_line = 0;
1054 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001055 if (die->GetDIENamesAndRanges (this,
1056 dwarf_cu,
1057 name,
1058 mangled_name,
1059 ranges,
1060 decl_file, decl_line, decl_column,
1061 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062 {
1063 if (tag == DW_TAG_subprogram)
1064 {
1065 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1066 subprogram_low_pc = ranges.LowestAddress(0);
1067 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001068 else if (tag == DW_TAG_inlined_subroutine)
1069 {
1070 // We get called here for inlined subroutines in two ways.
1071 // The first time is when we are making the Function object
1072 // for this inlined concrete instance. Since we're creating a top level block at
1073 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1074 // adjust the containing address.
1075 // The second time is when we are parsing the blocks inside the function that contains
1076 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1077 // function the offset will be for that function.
1078 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1079 {
1080 subprogram_low_pc = ranges.LowestAddress(0);
1081 }
1082 }
1083
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001084 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085
1086 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1087 {
1088 std::auto_ptr<Declaration> decl_ap;
1089 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001090 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1091 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092
1093 std::auto_ptr<Declaration> call_ap;
1094 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001095 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1096 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001098 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099 }
1100
1101 ++blocks_added;
1102
Greg Claytondd7feaf2011-08-12 17:54:33 +00001103 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001105 blocks_added += ParseFunctionBlocks (sc,
1106 block,
1107 dwarf_cu,
1108 die->GetFirstChild(),
1109 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001110 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001111 }
1112 }
1113 }
1114 break;
1115 default:
1116 break;
1117 }
1118
Greg Claytondd7feaf2011-08-12 17:54:33 +00001119 // Only parse siblings of the block if we are not at depth zero. A depth
1120 // of zero indicates we are currently parsing the top level
1121 // DW_TAG_subprogram DIE
1122
1123 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001124 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001125 else
1126 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001127 }
1128 return blocks_added;
1129}
1130
1131size_t
1132SymbolFileDWARF::ParseChildMembers
1133(
1134 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001135 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001137 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001138 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1140 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001141 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001142 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143 bool &is_a_class
1144)
1145{
1146 if (parent_die == NULL)
1147 return 0;
1148
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149 size_t count = 0;
1150 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001151 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001152 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001153
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1155 {
1156 dw_tag_t tag = die->Tag();
1157
1158 switch (tag)
1159 {
1160 case DW_TAG_member:
1161 {
1162 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001163 const size_t num_attributes = die->GetAttributes (this,
1164 dwarf_cu,
1165 fixed_form_sizes,
1166 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 if (num_attributes > 0)
1168 {
1169 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001170 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001172 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001174 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001175 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 size_t byte_size = 0;
1177 size_t bit_offset = 0;
1178 size_t bit_size = 0;
1179 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001180 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 {
1182 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1183 DWARFFormValue form_value;
1184 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1185 {
1186 switch (attr)
1187 {
1188 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1189 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1190 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1191 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1192 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1193 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1194 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1195 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1196 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001197// if (form_value.BlockData())
1198// {
1199// Value initialValue(0);
1200// Value memberOffset(0);
1201// const DataExtractor& debug_info_data = get_debug_info_data();
1202// uint32_t block_length = form_value.Unsigned();
1203// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1204// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1205// {
1206// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1207// }
1208// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 break;
1210
Greg Clayton8cf05932010-07-22 18:30:50 +00001211 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001212 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213 case DW_AT_declaration:
1214 case DW_AT_description:
1215 case DW_AT_mutable:
1216 case DW_AT_visibility:
1217 default:
1218 case DW_AT_sibling:
1219 break;
1220 }
1221 }
1222 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001223
1224 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1225
1226 if (class_language == eLanguageTypeObjC ||
1227 class_language == eLanguageTypeObjC_plus_plus)
1228 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001229
1230 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1231 {
1232 // Not all compilers will mark the vtable pointer
1233 // member as artificial (llvm-gcc). We can't have
1234 // the virtual members in our classes otherwise it
1235 // throws off all child offsets since we end up
1236 // having and extra pointer sized member in our
1237 // class layouts.
1238 is_artificial = true;
1239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240
Greg Clayton24739922010-10-13 03:15:28 +00001241 if (is_artificial == false)
1242 {
1243 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001244 if (member_type)
1245 {
1246 if (accessibility == eAccessNone)
1247 accessibility = default_accessibility;
1248 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249
Greg Claytond16e1e52011-07-12 17:06:17 +00001250 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1251 name,
1252 member_type->GetClangLayoutType(),
1253 accessibility,
1254 bit_size);
1255 }
1256 else
1257 {
1258 if (name)
1259 ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed",
1260 die->GetOffset(),
1261 name,
1262 encoding_uid);
1263 else
1264 ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed",
1265 die->GetOffset(),
1266 encoding_uid);
1267 }
Greg Clayton24739922010-10-13 03:15:28 +00001268 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001270 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001271 }
1272 break;
1273
1274 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001275 // Let the type parsing code handle this one for us.
1276 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 break;
1278
1279 case DW_TAG_inheritance:
1280 {
1281 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001282 if (default_accessibility == eAccessNone)
1283 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 // TODO: implement DW_TAG_inheritance type parsing
1285 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001286 const size_t num_attributes = die->GetAttributes (this,
1287 dwarf_cu,
1288 fixed_form_sizes,
1289 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290 if (num_attributes > 0)
1291 {
1292 Declaration decl;
1293 DWARFExpression location;
1294 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001295 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 bool is_virtual = false;
1297 bool is_base_of_class = true;
1298 off_t member_offset = 0;
1299 uint32_t i;
1300 for (i=0; i<num_attributes; ++i)
1301 {
1302 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1303 DWARFFormValue form_value;
1304 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1305 {
1306 switch (attr)
1307 {
1308 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1309 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1310 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1311 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1312 case DW_AT_data_member_location:
1313 if (form_value.BlockData())
1314 {
1315 Value initialValue(0);
1316 Value memberOffset(0);
1317 const DataExtractor& debug_info_data = get_debug_info_data();
1318 uint32_t block_length = form_value.Unsigned();
1319 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001320 if (DWARFExpression::Evaluate (NULL,
1321 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001322 NULL,
1323 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001324 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001325 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001326 block_offset,
1327 block_length,
1328 eRegisterKindDWARF,
1329 &initialValue,
1330 memberOffset,
1331 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001332 {
1333 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1334 }
1335 }
1336 break;
1337
1338 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001339 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 break;
1341
1342 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1343 default:
1344 case DW_AT_sibling:
1345 break;
1346 }
1347 }
1348 }
1349
Greg Clayton526e5af2010-11-13 03:52:47 +00001350 Type *base_class_type = ResolveTypeUID(encoding_uid);
1351 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001352
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001353 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1354 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001355 if (class_language == eLanguageTypeObjC)
1356 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001357 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001358 }
1359 else
1360 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001361 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001362 accessibility,
1363 is_virtual,
1364 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 }
1367 }
1368 break;
1369
1370 default:
1371 break;
1372 }
1373 }
1374 return count;
1375}
1376
1377
1378clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001379SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380{
1381 DWARFDebugInfo* debug_info = DebugInfo();
1382 if (debug_info)
1383 {
1384 DWARFCompileUnitSP cu_sp;
1385 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1386 if (die)
Sean Callanan72e49402011-08-05 23:43:37 +00001387 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
1388 }
1389 return NULL;
1390}
1391
1392clang::DeclContext*
1393SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1394{
1395 DWARFDebugInfo* debug_info = DebugInfo();
1396 if (debug_info)
1397 {
1398 DWARFCompileUnitSP cu_sp;
1399 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1400 if (die)
1401 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001402 }
1403 return NULL;
1404}
1405
1406Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001407SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408{
1409 DWARFDebugInfo* debug_info = DebugInfo();
1410 if (debug_info)
1411 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001412 DWARFCompileUnitSP cu_sp;
1413 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001415 {
1416 // We might be coming in in the middle of a type tree (a class
1417 // withing a class, an enum within a class), so parse any needed
1418 // parent DIEs before we get to this one...
1419 const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
1420 switch (parent_die->Tag())
1421 {
1422 case DW_TAG_structure_type:
1423 case DW_TAG_union_type:
1424 case DW_TAG_class_type:
1425 ResolveType(cu_sp.get(), parent_die);
1426 break;
1427 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00001428 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001429 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430 }
1431 return NULL;
1432}
1433
Greg Clayton6beaaa62011-01-17 03:46:26 +00001434// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1435// SymbolFileDWARF objects to detect if this DWARF file is the one that
1436// can resolve a clang_type.
1437bool
1438SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1439{
1440 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1441 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1442 return die != NULL;
1443}
1444
1445
Greg Clayton1be10fc2010-09-29 01:12:09 +00001446lldb::clang_type_t
1447SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1448{
1449 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001450 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1451 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001452 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001453 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001454// if (m_debug_map_symfile)
1455// {
1456// Type *type = m_die_to_type[die];
1457// if (type && type->GetSymbolFile() != this)
1458// return type->GetClangType();
1459// }
Greg Clayton73b472d2010-10-27 03:32:59 +00001460 // We have already resolved this type...
1461 return clang_type;
1462 }
1463 // Once we start resolving this type, remove it from the forward declaration
1464 // map in case anyone child members or other types require this type to get resolved.
1465 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1466 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001467 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001468
Greg Clayton1be10fc2010-09-29 01:12:09 +00001469
Greg Clayton450e3f32010-10-12 02:24:53 +00001470 DWARFDebugInfo* debug_info = DebugInfo();
1471
Greg Clayton96d7d742010-11-10 23:42:09 +00001472 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001473 Type *type = m_die_to_type.lookup (die);
1474
1475 const dw_tag_t tag = die->Tag();
1476
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001477 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1478 die->GetOffset(),
1479 DW_TAG_value_to_name(tag),
1480 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001481 assert (clang_type);
1482 DWARFDebugInfoEntry::Attributes attributes;
1483
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001484 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001485
1486 switch (tag)
1487 {
1488 case DW_TAG_structure_type:
1489 case DW_TAG_union_type:
1490 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001491 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001492 if (die->HasChildren())
1493 {
1494 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001495 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1496 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001497 class_language = eLanguageTypeObjC;
1498
1499 int tag_decl_kind = -1;
1500 AccessType default_accessibility = eAccessNone;
1501 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001502 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001503 tag_decl_kind = clang::TTK_Struct;
1504 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001505 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001506 else if (tag == DW_TAG_union_type)
1507 {
1508 tag_decl_kind = clang::TTK_Union;
1509 default_accessibility = eAccessPublic;
1510 }
1511 else if (tag == DW_TAG_class_type)
1512 {
1513 tag_decl_kind = clang::TTK_Class;
1514 default_accessibility = eAccessPrivate;
1515 }
1516
Greg Clayton96d7d742010-11-10 23:42:09 +00001517 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001518 std::vector<clang::CXXBaseSpecifier *> base_classes;
1519 std::vector<int> member_accessibilities;
1520 bool is_a_class = false;
1521 // Parse members and base classes first
1522 DWARFDIECollection member_function_dies;
1523
1524 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001525 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001526 die,
1527 clang_type,
1528 class_language,
1529 base_classes,
1530 member_accessibilities,
1531 member_function_dies,
1532 default_accessibility,
1533 is_a_class);
1534
1535 // Now parse any methods if there were any...
1536 size_t num_functions = member_function_dies.Size();
1537 if (num_functions > 0)
1538 {
1539 for (size_t i=0; i<num_functions; ++i)
1540 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001541 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001542 }
1543 }
1544
Greg Clayton450e3f32010-10-12 02:24:53 +00001545 if (class_language == eLanguageTypeObjC)
1546 {
Greg Claytone3055942011-06-30 02:28:26 +00001547 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001548 if (!class_str.empty())
1549 {
1550
1551 ConstString class_name (class_str.c_str());
1552 std::vector<NameToDIE::Info> method_die_infos;
1553 if (m_objc_class_selectors_index.Find (class_name, method_die_infos))
1554 {
1555 DWARFCompileUnit* method_cu = NULL;
1556 DWARFCompileUnit* prev_method_cu = NULL;
1557 const size_t num_objc_methods = method_die_infos.size();
1558 for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu)
1559 {
1560 method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx);
1561
1562 if (method_cu != prev_method_cu)
1563 method_cu->ExtractDIEsIfNeeded (false);
1564
1565 DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx);
1566
1567 ResolveType (method_cu, method_die);
1568 }
1569 }
1570 }
1571 }
1572
Greg Claytonc93237c2010-10-01 20:48:32 +00001573 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1574 // need to tell the clang type it is actually a class.
1575 if (class_language != eLanguageTypeObjC)
1576 {
1577 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001578 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001579 }
1580
1581 // Since DW_TAG_structure_type gets used for both classes
1582 // and structures, we may need to set any DW_TAG_member
1583 // fields to have a "private" access if none was specified.
1584 // When we parsed the child members we tracked that actual
1585 // accessibility value for each DW_TAG_member in the
1586 // "member_accessibilities" array. If the value for the
1587 // member is zero, then it was set to the "default_accessibility"
1588 // which for structs was "public". Below we correct this
1589 // by setting any fields to "private" that weren't correctly
1590 // set.
1591 if (is_a_class && !member_accessibilities.empty())
1592 {
1593 // This is a class and all members that didn't have
1594 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001595 ast.SetDefaultAccessForRecordFields (clang_type,
1596 eAccessPrivate,
1597 &member_accessibilities.front(),
1598 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001599 }
1600
1601 if (!base_classes.empty())
1602 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001603 ast.SetBaseClassesForClassType (clang_type,
1604 &base_classes.front(),
1605 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001606
1607 // Clang will copy each CXXBaseSpecifier in "base_classes"
1608 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001609 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1610 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001611 }
1612
1613 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001614 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001615 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001616
1617 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001618 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001619 if (die->HasChildren())
1620 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001621 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1622 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001623 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001624 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001625 return clang_type;
1626
1627 default:
1628 assert(false && "not a forward clang type decl!");
1629 break;
1630 }
1631 return NULL;
1632}
1633
Greg Claytonc685f8e2010-09-15 04:15:46 +00001634Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001635SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001636{
1637 if (type_die != NULL)
1638 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001639 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001640 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001641 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001642 if (assert_not_being_parsed)
1643 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001644 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001645 }
1646 return NULL;
1647}
1648
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001649CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001650SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001651{
1652 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001653 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001654 {
1655 // The symbol vendor doesn't know about this compile unit, we
1656 // need to parse and add it to the symbol vendor object.
1657 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001658 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 if (dc_cu.get())
1660 {
1661 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001662 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001663 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664
1665 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001666
1667 if (m_debug_map_symfile)
1668 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001669 }
1670 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001671 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001672}
1673
1674bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001675SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001676{
1677 sc.Clear();
1678 // Check if the symbol vendor already knows about this compile unit?
1679 sc.module_sp = m_obj_file->GetModule()->GetSP();
Greg Clayton96d7d742010-11-10 23:42:09 +00001680 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001681
1682 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1683 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001684 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685
1686 return sc.function != NULL;
1687}
1688
1689uint32_t
1690SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1691{
1692 Timer scoped_timer(__PRETTY_FUNCTION__,
1693 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1694 so_addr.GetSection(),
1695 so_addr.GetOffset(),
1696 resolve_scope);
1697 uint32_t resolved = 0;
1698 if (resolve_scope & ( eSymbolContextCompUnit |
1699 eSymbolContextFunction |
1700 eSymbolContextBlock |
1701 eSymbolContextLineEntry))
1702 {
1703 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1704
1705 DWARFDebugAranges* debug_aranges = DebugAranges();
1706 DWARFDebugInfo* debug_info = DebugInfo();
1707 if (debug_aranges)
1708 {
1709 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1710 if (cu_offset != DW_INVALID_OFFSET)
1711 {
1712 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001713 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1714 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001716 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001717 assert(sc.comp_unit != NULL);
1718 resolved |= eSymbolContextCompUnit;
1719
1720 if (resolve_scope & eSymbolContextLineEntry)
1721 {
1722 LineTable *line_table = sc.comp_unit->GetLineTable();
1723 if (line_table == NULL)
1724 {
1725 if (ParseCompileUnitLineTable(sc))
1726 line_table = sc.comp_unit->GetLineTable();
1727 }
1728 if (line_table != NULL)
1729 {
1730 if (so_addr.IsLinkedAddress())
1731 {
1732 Address linked_addr (so_addr);
1733 linked_addr.ResolveLinkedAddress();
1734 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1735 {
1736 resolved |= eSymbolContextLineEntry;
1737 }
1738 }
1739 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1740 {
1741 resolved |= eSymbolContextLineEntry;
1742 }
1743 }
1744 }
1745
1746 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1747 {
1748 DWARFDebugInfoEntry *function_die = NULL;
1749 DWARFDebugInfoEntry *block_die = NULL;
1750 if (resolve_scope & eSymbolContextBlock)
1751 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001752 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753 }
1754 else
1755 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001756 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001757 }
1758
1759 if (function_die != NULL)
1760 {
1761 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1762 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001763 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001764 }
1765
1766 if (sc.function != NULL)
1767 {
1768 resolved |= eSymbolContextFunction;
1769
1770 if (resolve_scope & eSymbolContextBlock)
1771 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001772 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001773
1774 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001775 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001777 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001778 if (sc.block)
1779 resolved |= eSymbolContextBlock;
1780 }
1781 }
1782 }
1783 }
1784 }
1785 }
1786 }
1787 return resolved;
1788}
1789
1790
1791
1792uint32_t
1793SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1794{
1795 const uint32_t prev_size = sc_list.GetSize();
1796 if (resolve_scope & eSymbolContextCompUnit)
1797 {
1798 DWARFDebugInfo* debug_info = DebugInfo();
1799 if (debug_info)
1800 {
1801 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001802 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803
Greg Clayton96d7d742010-11-10 23:42:09 +00001804 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001805 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001806 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1808 if (check_inlines || file_spec_matches_cu_file_spec)
1809 {
1810 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001811 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812 assert(sc.comp_unit != NULL);
1813
1814 uint32_t file_idx = UINT32_MAX;
1815
1816 // If we are looking for inline functions only and we don't
1817 // find it in the support files, we are done.
1818 if (check_inlines)
1819 {
1820 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1821 if (file_idx == UINT32_MAX)
1822 continue;
1823 }
1824
1825 if (line != 0)
1826 {
1827 LineTable *line_table = sc.comp_unit->GetLineTable();
1828
1829 if (line_table != NULL && line != 0)
1830 {
1831 // We will have already looked up the file index if
1832 // we are searching for inline entries.
1833 if (!check_inlines)
1834 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1835
1836 if (file_idx != UINT32_MAX)
1837 {
1838 uint32_t found_line;
1839 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1840 found_line = sc.line_entry.line;
1841
Greg Clayton016a95e2010-09-14 02:20:48 +00001842 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843 {
1844 sc.function = NULL;
1845 sc.block = NULL;
1846 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1847 {
1848 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1849 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1850 {
1851 DWARFDebugInfoEntry *function_die = NULL;
1852 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001853 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854
1855 if (function_die != NULL)
1856 {
1857 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1858 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001859 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860 }
1861
1862 if (sc.function != NULL)
1863 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001864 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001865
1866 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001867 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001869 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870 }
1871 }
1872 }
1873
1874 sc_list.Append(sc);
1875 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1876 }
1877 }
1878 }
1879 else if (file_spec_matches_cu_file_spec && !check_inlines)
1880 {
1881 // only append the context if we aren't looking for inline call sites
1882 // by file and line and if the file spec matches that of the compile unit
1883 sc_list.Append(sc);
1884 }
1885 }
1886 else if (file_spec_matches_cu_file_spec && !check_inlines)
1887 {
1888 // only append the context if we aren't looking for inline call sites
1889 // by file and line and if the file spec matches that of the compile unit
1890 sc_list.Append(sc);
1891 }
1892
1893 if (!check_inlines)
1894 break;
1895 }
1896 }
1897 }
1898 }
1899 return sc_list.GetSize() - prev_size;
1900}
1901
1902void
1903SymbolFileDWARF::Index ()
1904{
1905 if (m_indexed)
1906 return;
1907 m_indexed = true;
1908 Timer scoped_timer (__PRETTY_FUNCTION__,
1909 "SymbolFileDWARF::Index (%s)",
1910 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1911
1912 DWARFDebugInfo* debug_info = DebugInfo();
1913 if (debug_info)
1914 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001915 m_aranges.reset(new DWARFDebugAranges());
1916
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917 uint32_t cu_idx = 0;
1918 const uint32_t num_compile_units = GetNumCompileUnits();
1919 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1920 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001921 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922
Greg Clayton96d7d742010-11-10 23:42:09 +00001923 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924
Greg Clayton96d7d742010-11-10 23:42:09 +00001925 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001926 m_function_basename_index,
1927 m_function_fullname_index,
1928 m_function_method_index,
1929 m_function_selector_index,
1930 m_objc_class_selectors_index,
1931 m_global_index,
1932 m_type_index,
1933 m_namespace_index,
1934 DebugRanges(),
1935 m_aranges.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936
1937 // Keep memory down by clearing DIEs if this generate function
1938 // caused them to be parsed
1939 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001940 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941 }
1942
Greg Clayton016a95e2010-09-14 02:20:48 +00001943 m_aranges->Sort();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001944
Greg Clayton24739922010-10-13 03:15:28 +00001945#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00001946 StreamFile s(stdout, false);
Greg Clayton24739922010-10-13 03:15:28 +00001947 s.Printf ("DWARF index for (%s) '%s/%s':",
1948 GetObjectFile()->GetModule()->GetArchitecture().AsCString(),
1949 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1950 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001951 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1952 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1953 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1954 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1955 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1956 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001957 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001958 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001959#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001960 }
1961}
1962
1963uint32_t
1964SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1965{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001966 DWARFDebugInfo* info = DebugInfo();
1967 if (info == NULL)
1968 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001969
1970 // If we aren't appending the results to this list, then clear the list
1971 if (!append)
1972 variables.Clear();
1973
1974 // Remember how many variables are in the list before we search in case
1975 // we are appending the results to a variable list.
1976 const uint32_t original_size = variables.GetSize();
1977
1978 // Index the DWARF if we haven't already
1979 if (!m_indexed)
1980 Index ();
1981
Greg Claytonc685f8e2010-09-15 04:15:46 +00001982 SymbolContext sc;
1983 sc.module_sp = m_obj_file->GetModule()->GetSP();
1984 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001985
Greg Clayton96d7d742010-11-10 23:42:09 +00001986 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001987 DWARFCompileUnit* prev_cu = NULL;
1988 const DWARFDebugInfoEntry* die = NULL;
1989 std::vector<NameToDIE::Info> die_info_array;
1990 const size_t num_matches = m_global_index.Find(name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001991 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001992 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001993 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001994
Greg Clayton96d7d742010-11-10 23:42:09 +00001995 if (curr_cu != prev_cu)
1996 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001997
Greg Clayton96d7d742010-11-10 23:42:09 +00001998 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999
Greg Clayton96d7d742010-11-10 23:42:09 +00002000 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002001 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002
Greg Clayton96d7d742010-11-10 23:42:09 +00002003 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002004
2005 if (variables.GetSize() - original_size >= max_matches)
2006 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007 }
2008
2009 // Return the number of variable that were appended to the list
2010 return variables.GetSize() - original_size;
2011}
2012
2013uint32_t
2014SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2015{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002016 DWARFDebugInfo* info = DebugInfo();
2017 if (info == NULL)
2018 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019
2020 // If we aren't appending the results to this list, then clear the list
2021 if (!append)
2022 variables.Clear();
2023
2024 // Remember how many variables are in the list before we search in case
2025 // we are appending the results to a variable list.
2026 const uint32_t original_size = variables.GetSize();
2027
2028 // Index the DWARF if we haven't already
2029 if (!m_indexed)
2030 Index ();
2031
Greg Claytonc685f8e2010-09-15 04:15:46 +00002032 SymbolContext sc;
2033 sc.module_sp = m_obj_file->GetModule()->GetSP();
2034 assert (sc.module_sp);
2035
Greg Clayton96d7d742010-11-10 23:42:09 +00002036 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002037 DWARFCompileUnit* prev_cu = NULL;
2038 const DWARFDebugInfoEntry* die = NULL;
2039 std::vector<NameToDIE::Info> die_info_array;
2040 const size_t num_matches = m_global_index.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002041 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002042 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002043 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002044
Greg Clayton96d7d742010-11-10 23:42:09 +00002045 if (curr_cu != prev_cu)
2046 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002047
Greg Clayton96d7d742010-11-10 23:42:09 +00002048 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049
Greg Clayton96d7d742010-11-10 23:42:09 +00002050 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002051 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002052
Greg Clayton96d7d742010-11-10 23:42:09 +00002053 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002054
Greg Claytonc685f8e2010-09-15 04:15:46 +00002055 if (variables.GetSize() - original_size >= max_matches)
2056 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002057 }
2058
2059 // Return the number of variable that were appended to the list
2060 return variables.GetSize() - original_size;
2061}
2062
2063
Greg Clayton0c5cd902010-06-28 21:30:43 +00002064void
2065SymbolFileDWARF::FindFunctions
2066(
2067 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00002068 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00002069 SymbolContextList& sc_list
2070)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002072 DWARFDebugInfo* info = DebugInfo();
2073 if (info == NULL)
2074 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002075
Greg Claytonc685f8e2010-09-15 04:15:46 +00002076 SymbolContext sc;
2077 sc.module_sp = m_obj_file->GetModule()->GetSP();
2078 assert (sc.module_sp);
2079
Greg Clayton96d7d742010-11-10 23:42:09 +00002080 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002081 DWARFCompileUnit* prev_cu = NULL;
2082 const DWARFDebugInfoEntry* die = NULL;
2083 std::vector<NameToDIE::Info> die_info_array;
Greg Claytond7e05462010-11-14 00:22:48 +00002084 const size_t num_matches = name_to_die.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002085 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002086 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002087 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002088
Greg Clayton96d7d742010-11-10 23:42:09 +00002089 if (curr_cu != prev_cu)
2090 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002091
Greg Clayton96d7d742010-11-10 23:42:09 +00002092 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytond7e05462010-11-14 00:22:48 +00002093
2094 const DWARFDebugInfoEntry* inlined_die = NULL;
2095 if (die->Tag() == DW_TAG_inlined_subroutine)
2096 {
2097 inlined_die = die;
2098
2099 while ((die = die->GetParent()) != NULL)
2100 {
2101 if (die->Tag() == DW_TAG_subprogram)
2102 break;
2103 }
2104 }
2105 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002106 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002107 {
Greg Claytond7e05462010-11-14 00:22:48 +00002108 Address addr;
2109 // Parse all blocks if needed
2110 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002111 {
Greg Claytond7e05462010-11-14 00:22:48 +00002112 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2113 assert (sc.block != NULL);
2114 if (sc.block->GetStartAddress (addr) == false)
2115 addr.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116 }
Greg Claytond7e05462010-11-14 00:22:48 +00002117 else
2118 {
2119 sc.block = NULL;
2120 addr = sc.function->GetAddressRange().GetBaseAddress();
2121 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002122
Greg Claytond7e05462010-11-14 00:22:48 +00002123 if (addr.IsValid())
2124 {
2125
2126 // We found the function, so we should find the line table
2127 // and line table entry as well
2128 LineTable *line_table = sc.comp_unit->GetLineTable();
2129 if (line_table == NULL)
2130 {
2131 if (ParseCompileUnitLineTable(sc))
2132 line_table = sc.comp_unit->GetLineTable();
2133 }
2134 if (line_table != NULL)
2135 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2136
2137 sc_list.Append(sc);
2138 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002139 }
2140 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002141}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002142
Greg Claytonc685f8e2010-09-15 04:15:46 +00002143
2144void
2145SymbolFileDWARF::FindFunctions
2146(
2147 const RegularExpression &regex,
2148 const NameToDIE &name_to_die,
2149 SymbolContextList& sc_list
2150)
2151{
2152 DWARFDebugInfo* info = DebugInfo();
2153 if (info == NULL)
2154 return;
2155
2156 SymbolContext sc;
2157 sc.module_sp = m_obj_file->GetModule()->GetSP();
2158 assert (sc.module_sp);
2159
Greg Clayton96d7d742010-11-10 23:42:09 +00002160 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002161 DWARFCompileUnit* prev_cu = NULL;
2162 const DWARFDebugInfoEntry* die = NULL;
2163 std::vector<NameToDIE::Info> die_info_array;
2164 const size_t num_matches = name_to_die.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002165 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002166 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002167 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002168
Greg Clayton96d7d742010-11-10 23:42:09 +00002169 if (curr_cu != prev_cu)
2170 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002171
Greg Clayton96d7d742010-11-10 23:42:09 +00002172 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonab843392010-12-03 17:49:14 +00002173
2174 const DWARFDebugInfoEntry* inlined_die = NULL;
2175 if (die->Tag() == DW_TAG_inlined_subroutine)
2176 {
2177 inlined_die = die;
2178
2179 while ((die = die->GetParent()) != NULL)
2180 {
2181 if (die->Tag() == DW_TAG_subprogram)
2182 break;
2183 }
2184 }
2185 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002186 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002187 {
Greg Claytonab843392010-12-03 17:49:14 +00002188 Address addr;
2189 // Parse all blocks if needed
2190 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002191 {
Greg Claytonab843392010-12-03 17:49:14 +00002192 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2193 assert (sc.block != NULL);
2194 if (sc.block->GetStartAddress (addr) == false)
2195 addr.Clear();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002196 }
Greg Claytonab843392010-12-03 17:49:14 +00002197 else
2198 {
2199 sc.block = NULL;
2200 addr = sc.function->GetAddressRange().GetBaseAddress();
2201 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002202
Greg Claytonab843392010-12-03 17:49:14 +00002203 if (addr.IsValid())
2204 {
2205
2206 // We found the function, so we should find the line table
2207 // and line table entry as well
2208 LineTable *line_table = sc.comp_unit->GetLineTable();
2209 if (line_table == NULL)
2210 {
2211 if (ParseCompileUnitLineTable(sc))
2212 line_table = sc.comp_unit->GetLineTable();
2213 }
2214 if (line_table != NULL)
2215 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2216
2217 sc_list.Append(sc);
2218 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002219 }
2220 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002221}
2222
2223uint32_t
2224SymbolFileDWARF::FindFunctions
2225(
2226 const ConstString &name,
2227 uint32_t name_type_mask,
2228 bool append,
2229 SymbolContextList& sc_list
2230)
2231{
2232 Timer scoped_timer (__PRETTY_FUNCTION__,
2233 "SymbolFileDWARF::FindFunctions (name = '%s')",
2234 name.AsCString());
2235
Greg Clayton0c5cd902010-06-28 21:30:43 +00002236 // If we aren't appending the results to this list, then clear the list
2237 if (!append)
2238 sc_list.Clear();
2239
2240 // Remember how many sc_list are in the list before we search in case
2241 // we are appending the results to a variable list.
2242 uint32_t original_size = sc_list.GetSize();
2243
2244 // Index the DWARF if we haven't already
2245 if (!m_indexed)
2246 Index ();
2247
2248 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002249 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002250
2251 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002252 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002253
2254 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002255 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002256
2257 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002258 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002259
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002260 // Return the number of variable that were appended to the list
2261 return sc_list.GetSize() - original_size;
2262}
2263
2264
2265uint32_t
2266SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2267{
2268 Timer scoped_timer (__PRETTY_FUNCTION__,
2269 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2270 regex.GetText());
2271
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 // If we aren't appending the results to this list, then clear the list
2273 if (!append)
2274 sc_list.Clear();
2275
2276 // Remember how many sc_list are in the list before we search in case
2277 // we are appending the results to a variable list.
2278 uint32_t original_size = sc_list.GetSize();
2279
2280 // Index the DWARF if we haven't already
2281 if (!m_indexed)
2282 Index ();
2283
Greg Claytonc685f8e2010-09-15 04:15:46 +00002284 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002285
Greg Claytonc685f8e2010-09-15 04:15:46 +00002286 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002287
2288 // Return the number of variable that were appended to the list
2289 return sc_list.GetSize() - original_size;
2290}
Greg Claytond16e1e52011-07-12 17:06:17 +00002291void
2292SymbolFileDWARF::ReportError (const char *format, ...)
2293{
2294 ::fprintf (stderr,
2295 "error: %s/%s ",
2296 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2297 m_obj_file->GetFileSpec().GetFilename().GetCString());
2298
2299 va_list args;
2300 va_start (args, format);
2301 vfprintf (stderr, format, args);
2302 va_end (args);
2303}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002304
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002305uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002306SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002307{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002308 DWARFDebugInfo* info = DebugInfo();
2309 if (info == NULL)
2310 return 0;
2311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002312 // If we aren't appending the results to this list, then clear the list
2313 if (!append)
2314 types.Clear();
2315
Greg Clayton6dbd3982010-09-15 05:51:24 +00002316 // Index if we already haven't to make sure the compile units
2317 // get indexed and make their global DIE index list
2318 if (!m_indexed)
2319 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002320
Greg Claytonc685f8e2010-09-15 04:15:46 +00002321 const uint32_t initial_types_size = types.GetSize();
Greg Clayton96d7d742010-11-10 23:42:09 +00002322 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002323 DWARFCompileUnit* prev_cu = NULL;
2324 const DWARFDebugInfoEntry* die = NULL;
2325 std::vector<NameToDIE::Info> die_info_array;
Greg Clayton69b04882010-10-15 02:03:22 +00002326 const size_t num_matches = m_type_index.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002327 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002328 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002329 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002330
Greg Clayton96d7d742010-11-10 23:42:09 +00002331 if (curr_cu != prev_cu)
2332 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002333
Greg Clayton96d7d742010-11-10 23:42:09 +00002334 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002335
Greg Clayton96d7d742010-11-10 23:42:09 +00002336 Type *matching_type = ResolveType (curr_cu, die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002337 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002338 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00002339 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002340 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Clayton73bf5db2011-06-17 01:22:15 +00002341 if (type_sp)
2342 {
2343 types.InsertUnique (type_sp);
2344 if (types.GetSize() >= max_matches)
2345 break;
2346 }
2347 else
2348 {
2349 fprintf (stderr, "error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID());
2350 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002352 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002353 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002354}
2355
2356
Greg Clayton526e5af2010-11-13 03:52:47 +00002357ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002358SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2359 const ConstString &name)
2360{
Greg Clayton526e5af2010-11-13 03:52:47 +00002361 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002362 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002363 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002364 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002365 // Index if we already haven't to make sure the compile units
2366 // get indexed and make their global DIE index list
2367 if (!m_indexed)
2368 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002369
Greg Clayton526e5af2010-11-13 03:52:47 +00002370 DWARFCompileUnit* curr_cu = NULL;
2371 DWARFCompileUnit* prev_cu = NULL;
2372 const DWARFDebugInfoEntry* die = NULL;
2373 std::vector<NameToDIE::Info> die_info_array;
2374 const size_t num_matches = m_namespace_index.Find (name, die_info_array);
2375 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
2376 {
2377 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
2378
2379 if (curr_cu != prev_cu)
2380 curr_cu->ExtractDIEsIfNeeded (false);
Greg Clayton96d7d742010-11-10 23:42:09 +00002381
Greg Clayton526e5af2010-11-13 03:52:47 +00002382 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2383
2384 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die);
2385 if (clang_namespace_decl)
2386 {
2387 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2388 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2389 }
2390 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002391 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002392 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002393}
2394
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002395uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002396SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002397{
2398 // Remember how many sc_list are in the list before we search in case
2399 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002400 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002401
2402 const uint32_t num_die_offsets = die_offsets.size();
2403 // Parse all of the types we found from the pubtypes matches
2404 uint32_t i;
2405 uint32_t num_matches = 0;
2406 for (i = 0; i < num_die_offsets; ++i)
2407 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002408 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2409 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002410 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002411 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002412 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002413 assert (type_sp.get() != NULL);
2414 types.InsertUnique (type_sp);
2415 ++num_matches;
2416 if (num_matches >= max_matches)
2417 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002418 }
2419 }
2420
2421 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002422 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423}
2424
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002425
2426size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00002427SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
2428 clang::DeclContext *containing_decl_ctx,
2429 TypeSP& type_sp,
2430 DWARFCompileUnit* dwarf_cu,
2431 const DWARFDebugInfoEntry *parent_die,
2432 bool skip_artificial,
2433 bool &is_static,
2434 TypeList* type_list,
2435 std::vector<clang_type_t>& function_param_types,
2436 std::vector<clang::ParmVarDecl*>& function_param_decls,
2437 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002438{
2439 if (parent_die == NULL)
2440 return 0;
2441
Greg Claytond88d7592010-09-15 08:33:30 +00002442 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2443
Greg Clayton7fedea22010-11-16 02:10:54 +00002444 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002445 const DWARFDebugInfoEntry *die;
2446 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2447 {
2448 dw_tag_t tag = die->Tag();
2449 switch (tag)
2450 {
2451 case DW_TAG_formal_parameter:
2452 {
2453 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002454 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002455 if (num_attributes > 0)
2456 {
2457 const char *name = NULL;
2458 Declaration decl;
2459 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002460 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461 // one of None, Auto, Register, Extern, Static, PrivateExtern
2462
Sean Callanane2ef6e32010-09-23 03:01:22 +00002463 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002464 uint32_t i;
2465 for (i=0; i<num_attributes; ++i)
2466 {
2467 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2468 DWARFFormValue form_value;
2469 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2470 {
2471 switch (attr)
2472 {
2473 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2474 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2475 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2476 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2477 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002478 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002479 case DW_AT_location:
2480 // if (form_value.BlockData())
2481 // {
2482 // const DataExtractor& debug_info_data = debug_info();
2483 // uint32_t block_length = form_value.Unsigned();
2484 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2485 // }
2486 // else
2487 // {
2488 // }
2489 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490 case DW_AT_const_value:
2491 case DW_AT_default_value:
2492 case DW_AT_description:
2493 case DW_AT_endianity:
2494 case DW_AT_is_optional:
2495 case DW_AT_segment:
2496 case DW_AT_variable_parameter:
2497 default:
2498 case DW_AT_abstract_origin:
2499 case DW_AT_sibling:
2500 break;
2501 }
2502 }
2503 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002504
Greg Clayton0fffff52010-09-24 05:15:53 +00002505 bool skip = false;
2506 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002507 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002508 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002509 {
2510 // In order to determine if a C++ member function is
2511 // "const" we have to look at the const-ness of "this"...
2512 // Ugly, but that
2513 if (arg_idx == 0)
2514 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002515 if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord)
Sean Callanan763d72a2011-08-02 22:21:50 +00002516 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002517 // Often times compilers omit the "this" name for the
2518 // specification DIEs, so we can't rely upon the name
2519 // being in the formal parameter DIE...
2520 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00002521 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002522 Type *this_type = ResolveTypeUID (param_type_die_offset);
2523 if (this_type)
2524 {
2525 uint32_t encoding_mask = this_type->GetEncodingMask();
2526 if (encoding_mask & Type::eEncodingIsPointerUID)
2527 {
2528 is_static = false;
2529
2530 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
2531 type_quals |= clang::Qualifiers::Const;
2532 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
2533 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002534 }
2535 }
2536 }
2537 }
2538 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002539 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002540 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002541 else
2542 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543
Greg Clayton0fffff52010-09-24 05:15:53 +00002544 // HACK: Objective C formal parameters "self" and "_cmd"
2545 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002546 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2547 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002548 {
2549 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2550 skip = true;
2551 }
2552 }
2553 }
2554
2555 if (!skip)
2556 {
2557 Type *type = ResolveTypeUID(param_type_die_offset);
2558 if (type)
2559 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002560 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002561
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002562 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002563 assert(param_var_decl);
2564 function_param_decls.push_back(param_var_decl);
2565 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002566 }
2567 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002568 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002569 }
2570 break;
2571
2572 default:
2573 break;
2574 }
2575 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002576 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002577}
2578
2579size_t
2580SymbolFileDWARF::ParseChildEnumerators
2581(
2582 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002583 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002584 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002585 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002586 const DWARFDebugInfoEntry *parent_die
2587)
2588{
2589 if (parent_die == NULL)
2590 return 0;
2591
2592 size_t enumerators_added = 0;
2593 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002594 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2595
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002596 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2597 {
2598 const dw_tag_t tag = die->Tag();
2599 if (tag == DW_TAG_enumerator)
2600 {
2601 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002602 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002603 if (num_child_attributes > 0)
2604 {
2605 const char *name = NULL;
2606 bool got_value = false;
2607 int64_t enum_value = 0;
2608 Declaration decl;
2609
2610 uint32_t i;
2611 for (i=0; i<num_child_attributes; ++i)
2612 {
2613 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2614 DWARFFormValue form_value;
2615 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2616 {
2617 switch (attr)
2618 {
2619 case DW_AT_const_value:
2620 got_value = true;
2621 enum_value = form_value.Unsigned();
2622 break;
2623
2624 case DW_AT_name:
2625 name = form_value.AsCString(&get_debug_str_data());
2626 break;
2627
2628 case DW_AT_description:
2629 default:
2630 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2631 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2632 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2633 case DW_AT_sibling:
2634 break;
2635 }
2636 }
2637 }
2638
2639 if (name && name[0] && got_value)
2640 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002641 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2642 enumerator_clang_type,
2643 decl,
2644 name,
2645 enum_value,
2646 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002647 ++enumerators_added;
2648 }
2649 }
2650 }
2651 }
2652 return enumerators_added;
2653}
2654
2655void
2656SymbolFileDWARF::ParseChildArrayInfo
2657(
2658 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002659 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002660 const DWARFDebugInfoEntry *parent_die,
2661 int64_t& first_index,
2662 std::vector<uint64_t>& element_orders,
2663 uint32_t& byte_stride,
2664 uint32_t& bit_stride
2665)
2666{
2667 if (parent_die == NULL)
2668 return;
2669
2670 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002671 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002672 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2673 {
2674 const dw_tag_t tag = die->Tag();
2675 switch (tag)
2676 {
2677 case DW_TAG_enumerator:
2678 {
2679 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002680 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002681 if (num_child_attributes > 0)
2682 {
2683 const char *name = NULL;
2684 bool got_value = false;
2685 int64_t enum_value = 0;
2686
2687 uint32_t i;
2688 for (i=0; i<num_child_attributes; ++i)
2689 {
2690 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2691 DWARFFormValue form_value;
2692 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2693 {
2694 switch (attr)
2695 {
2696 case DW_AT_const_value:
2697 got_value = true;
2698 enum_value = form_value.Unsigned();
2699 break;
2700
2701 case DW_AT_name:
2702 name = form_value.AsCString(&get_debug_str_data());
2703 break;
2704
2705 case DW_AT_description:
2706 default:
2707 case DW_AT_decl_file:
2708 case DW_AT_decl_line:
2709 case DW_AT_decl_column:
2710 case DW_AT_sibling:
2711 break;
2712 }
2713 }
2714 }
2715 }
2716 }
2717 break;
2718
2719 case DW_TAG_subrange_type:
2720 {
2721 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002722 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002723 if (num_child_attributes > 0)
2724 {
2725 const char *name = NULL;
2726 bool got_value = false;
2727 uint64_t byte_size = 0;
2728 int64_t enum_value = 0;
2729 uint64_t num_elements = 0;
2730 uint64_t lower_bound = 0;
2731 uint64_t upper_bound = 0;
2732 uint32_t i;
2733 for (i=0; i<num_child_attributes; ++i)
2734 {
2735 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2736 DWARFFormValue form_value;
2737 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2738 {
2739 switch (attr)
2740 {
2741 case DW_AT_const_value:
2742 got_value = true;
2743 enum_value = form_value.Unsigned();
2744 break;
2745
2746 case DW_AT_name:
2747 name = form_value.AsCString(&get_debug_str_data());
2748 break;
2749
2750 case DW_AT_count:
2751 num_elements = form_value.Unsigned();
2752 break;
2753
2754 case DW_AT_bit_stride:
2755 bit_stride = form_value.Unsigned();
2756 break;
2757
2758 case DW_AT_byte_stride:
2759 byte_stride = form_value.Unsigned();
2760 break;
2761
2762 case DW_AT_byte_size:
2763 byte_size = form_value.Unsigned();
2764 break;
2765
2766 case DW_AT_lower_bound:
2767 lower_bound = form_value.Unsigned();
2768 break;
2769
2770 case DW_AT_upper_bound:
2771 upper_bound = form_value.Unsigned();
2772 break;
2773
2774 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002775 case DW_AT_abstract_origin:
2776 case DW_AT_accessibility:
2777 case DW_AT_allocated:
2778 case DW_AT_associated:
2779 case DW_AT_data_location:
2780 case DW_AT_declaration:
2781 case DW_AT_description:
2782 case DW_AT_sibling:
2783 case DW_AT_threads_scaled:
2784 case DW_AT_type:
2785 case DW_AT_visibility:
2786 break;
2787 }
2788 }
2789 }
2790
2791 if (upper_bound > lower_bound)
2792 num_elements = upper_bound - lower_bound + 1;
2793
2794 if (num_elements > 0)
2795 element_orders.push_back (num_elements);
2796 }
2797 }
2798 break;
2799 }
2800 }
2801}
2802
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002803TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002804SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002805{
2806 TypeSP type_sp;
2807 if (die != NULL)
2808 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002809 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002810 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002811 if (type_ptr == NULL)
2812 {
Greg Claytonca512b32011-01-14 04:54:56 +00002813 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
2814 assert (lldb_cu);
2815 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00002816 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002817 }
2818 else if (type_ptr != DIE_IS_BEING_PARSED)
2819 {
2820 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002821 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002822 }
2823
2824 }
2825 return type_sp;
2826}
2827
2828clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002829SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830{
2831 if (die_offset != DW_INVALID_OFFSET)
2832 {
2833 DWARFCompileUnitSP cu_sp;
2834 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Sean Callanan72e49402011-08-05 23:43:37 +00002835 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836 }
2837 return NULL;
2838}
2839
Sean Callanan72e49402011-08-05 23:43:37 +00002840clang::DeclContext *
2841SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
2842{
2843 if (die_offset != DW_INVALID_OFFSET)
2844 {
2845 DWARFCompileUnitSP cu_sp;
2846 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2847 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
2848 }
2849 return NULL;
2850}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851
Greg Clayton96d7d742010-11-10 23:42:09 +00002852clang::NamespaceDecl *
2853SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2854{
2855 if (die->Tag() == DW_TAG_namespace)
2856 {
2857 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2858 if (namespace_name)
2859 {
2860 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002861 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent()));
Greg Clayton96d7d742010-11-10 23:42:09 +00002862 if (namespace_decl)
Greg Claytona2721472011-06-25 00:44:06 +00002863 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Clayton96d7d742010-11-10 23:42:09 +00002864 return namespace_decl;
2865 }
2866 }
2867 return NULL;
2868}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002869
2870clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002871SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2872{
2873 // If this DIE has a specification, or an abstract origin, then trace to those.
2874
2875 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
2876 if (die_offset != DW_INVALID_OFFSET)
2877 return GetClangDeclContextForDIEOffset (sc, die_offset);
2878
2879 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
2880 if (die_offset != DW_INVALID_OFFSET)
2881 return GetClangDeclContextForDIEOffset (sc, die_offset);
2882
2883 // This is the DIE we want. Parse it, then query our map.
2884
2885 ParseType(sc, curr_cu, die, NULL);
2886
2887 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2888 if (pos != m_die_to_decl_ctx.end())
2889 return pos->second;
2890 else
2891 return NULL;
2892}
2893
2894clang::DeclContext *
2895SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002896{
Greg Claytonca512b32011-01-14 04:54:56 +00002897 if (m_clang_tu_decl == NULL)
2898 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002899
Sean Callanan72e49402011-08-05 23:43:37 +00002900 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x )\n", die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002901 const DWARFDebugInfoEntry * const decl_die = die;
Greg Clayton4cd17802011-01-25 06:17:32 +00002902 clang::DeclContext *decl_ctx = NULL;
2903
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002904 while (die != NULL)
2905 {
Greg Claytonca512b32011-01-14 04:54:56 +00002906 // If this is the original DIE that we are searching for a declaration
2907 // for, then don't look in the cache as we don't want our own decl
2908 // context to be our decl context...
2909 if (decl_die != die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002910 {
Greg Claytonca512b32011-01-14 04:54:56 +00002911 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2912 if (pos != m_die_to_decl_ctx.end())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002913 {
Sean Callanan72e49402011-08-05 23:43:37 +00002914 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002915 return pos->second;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002916 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917
Sean Callanan72e49402011-08-05 23:43:37 +00002918 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) checking parent 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002919
2920 switch (die->Tag())
2921 {
2922 case DW_TAG_namespace:
2923 {
2924 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2925 if (namespace_name)
2926 {
2927 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002928 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die));
Greg Claytonca512b32011-01-14 04:54:56 +00002929 if (namespace_decl)
2930 {
Sean Callanan72e49402011-08-05 23:43:37 +00002931 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytona2721472011-06-25 00:44:06 +00002932 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Claytonca512b32011-01-14 04:54:56 +00002933 }
2934 return namespace_decl;
2935 }
2936 }
2937 break;
2938
2939 case DW_TAG_structure_type:
2940 case DW_TAG_union_type:
2941 case DW_TAG_class_type:
2942 {
Greg Clayton4cd17802011-01-25 06:17:32 +00002943 Type* type = ResolveType (curr_cu, die);
Greg Claytonca512b32011-01-14 04:54:56 +00002944 pos = m_die_to_decl_ctx.find(die);
Greg Claytonca512b32011-01-14 04:54:56 +00002945 if (pos != m_die_to_decl_ctx.end())
2946 {
Sean Callanan72e49402011-08-05 23:43:37 +00002947 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002948 return pos->second;
2949 }
Greg Clayton4cd17802011-01-25 06:17:32 +00002950 else
2951 {
2952 if (type)
2953 {
2954 decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
Enrico Granata4a04dbc2011-08-12 18:43:16 +00002955 LinkDeclContextToDIE (decl_ctx, die);
Greg Clayton4cd17802011-01-25 06:17:32 +00002956 if (decl_ctx)
2957 return decl_ctx;
2958 }
2959 }
Greg Claytonca512b32011-01-14 04:54:56 +00002960 }
2961 break;
2962
2963 default:
2964 break;
2965 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002966 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002967
Greg Clayton6beaaa62011-01-17 03:46:26 +00002968 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002969 if (die_offset != DW_INVALID_OFFSET)
2970 {
Sean Callanan72e49402011-08-05 23:43:37 +00002971 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2972 decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset);
Greg Claytonca512b32011-01-14 04:54:56 +00002973 if (decl_ctx != m_clang_tu_decl)
2974 return decl_ctx;
2975 }
2976
Greg Clayton6beaaa62011-01-17 03:46:26 +00002977 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002978 if (die_offset != DW_INVALID_OFFSET)
2979 {
Sean Callanan72e49402011-08-05 23:43:37 +00002980 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2981 decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset);
Greg Claytonca512b32011-01-14 04:54:56 +00002982 if (decl_ctx != m_clang_tu_decl)
2983 return decl_ctx;
2984 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002985
2986 die = die->GetParent();
2987 }
Greg Clayton7a345282010-11-09 23:46:37 +00002988 // Right now we have only one translation unit per module...
Sean Callanan72e49402011-08-05 23:43:37 +00002989 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset());
Greg Clayton7a345282010-11-09 23:46:37 +00002990 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991}
2992
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002993// This function can be used when a DIE is found that is a forward declaration
2994// DIE and we want to try and find a type that has the complete definition.
2995TypeSP
2996SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton1a65ae12011-01-25 23:55:37 +00002997 DWARFCompileUnit* cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002998 const DWARFDebugInfoEntry *die,
2999 const ConstString &type_name
3000)
3001{
3002 TypeSP type_sp;
3003
Greg Clayton1a65ae12011-01-25 23:55:37 +00003004 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003005 return type_sp;
3006
Greg Clayton69974892010-12-03 21:42:06 +00003007 if (!m_indexed)
3008 Index ();
3009
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003010 const dw_tag_t type_tag = die->Tag();
3011 std::vector<NameToDIE::Info> die_info_array;
3012 const size_t num_matches = m_type_index.Find (type_name, die_info_array);
3013 if (num_matches > 0)
3014 {
3015 DWARFCompileUnit* type_cu = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +00003016 DWARFCompileUnit* curr_cu = cu;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003017 DWARFDebugInfo *info = DebugInfo();
3018 for (size_t i=0; i<num_matches; ++i)
3019 {
3020 type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx);
3021
3022 if (type_cu != curr_cu)
3023 {
3024 type_cu->ExtractDIEsIfNeeded (false);
3025 curr_cu = type_cu;
3026 }
3027
3028 DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx);
3029
3030 if (type_die != die && type_die->Tag() == type_tag)
3031 {
3032 // Hold off on comparing parent DIE tags until
3033 // we know what happens with stuff in namespaces
3034 // for gcc and clang...
3035 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3036 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3037 //if (parent_die->Tag() == parent_type_die->Tag())
3038 {
3039 Type *resolved_type = ResolveType (type_cu, type_die, false);
3040 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3041 {
3042 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
3043 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00003044 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003045 m_obj_file->GetFileSpec().GetFilename().AsCString(),
3046 type_die->GetOffset(),
3047 type_cu->GetOffset());
3048
3049 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003050 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00003051 if (!type_sp)
3052 {
3053 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
3054 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003055 break;
3056 }
3057 }
3058 }
3059 }
3060 }
3061 return type_sp;
3062}
3063
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003064TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003065SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003066{
3067 TypeSP type_sp;
3068
Greg Clayton1be10fc2010-09-29 01:12:09 +00003069 if (type_is_new_ptr)
3070 *type_is_new_ptr = false;
3071
Sean Callananc7fbf732010-08-06 00:32:49 +00003072 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003073 if (die != NULL)
3074 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00003075 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003076 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003077 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003078 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003079 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003080 if (type_is_new_ptr)
3081 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003082
Greg Clayton594e5ed2010-09-27 21:07:38 +00003083 const dw_tag_t tag = die->Tag();
3084
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003085 bool is_forward_declaration = false;
3086 DWARFDebugInfoEntry::Attributes attributes;
3087 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003088 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003089 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3090 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003091 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003092 Declaration decl;
3093
Greg Clayton4957bf62010-09-30 21:49:03 +00003094 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003095 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003096
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003097 dw_attr_t attr;
3098
3099 switch (tag)
3100 {
3101 case DW_TAG_base_type:
3102 case DW_TAG_pointer_type:
3103 case DW_TAG_reference_type:
3104 case DW_TAG_typedef:
3105 case DW_TAG_const_type:
3106 case DW_TAG_restrict_type:
3107 case DW_TAG_volatile_type:
3108 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003110 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003111
Greg Claytond88d7592010-09-15 08:33:30 +00003112 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003113 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003114 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3115
3116 if (num_attributes > 0)
3117 {
3118 uint32_t i;
3119 for (i=0; i<num_attributes; ++i)
3120 {
3121 attr = attributes.AttributeAtIndex(i);
3122 DWARFFormValue form_value;
3123 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3124 {
3125 switch (attr)
3126 {
3127 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3128 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3129 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3130 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003131
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003132 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003133 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3134 // include the "&"...
3135 if (tag == DW_TAG_reference_type)
3136 {
3137 if (strchr (type_name_cstr, '&') == NULL)
3138 type_name_cstr = NULL;
3139 }
3140 if (type_name_cstr)
3141 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003142 break;
Greg Clayton36909642011-03-15 04:38:20 +00003143 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003144 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3145 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3146 default:
3147 case DW_AT_sibling:
3148 break;
3149 }
3150 }
3151 }
3152 }
3153
Greg Claytonc93237c2010-10-01 20:48:32 +00003154 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") type => 0x%8.8x\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
3155
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003156 switch (tag)
3157 {
3158 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003159 break;
3160
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003161 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003162 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003163 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3164 encoding,
3165 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003166 break;
3167
Greg Clayton526e5af2010-11-13 03:52:47 +00003168 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3169 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3170 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3171 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3172 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3173 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003174 }
3175
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003176 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3177 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3178 {
3179 static ConstString g_objc_type_name_id("id");
3180 static ConstString g_objc_type_name_Class("Class");
3181 static ConstString g_objc_type_name_selector("SEL");
3182
Greg Clayton24739922010-10-13 03:15:28 +00003183 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003184 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003185 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003186 resolve_state = Type::eResolveStateFull;
3187
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003188 }
Greg Clayton24739922010-10-13 03:15:28 +00003189 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003190 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003191 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003192 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003193 }
Greg Clayton24739922010-10-13 03:15:28 +00003194 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003195 {
Sean Callananf6c73082010-12-06 23:53:20 +00003196 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003197 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003198 }
3199 }
3200
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003201 type_sp.reset( new Type (die->GetOffset(),
3202 this,
3203 type_name_const_str,
3204 byte_size,
3205 NULL,
3206 encoding_uid,
3207 encoding_data_type,
3208 &decl,
3209 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003210 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003211
Greg Clayton594e5ed2010-09-27 21:07:38 +00003212 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003213
3214// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3215// if (encoding_type != NULL)
3216// {
3217// if (encoding_type != DIE_IS_BEING_PARSED)
3218// type_sp->SetEncodingType(encoding_type);
3219// else
3220// m_indirect_fixups.push_back(type_sp.get());
3221// }
3222 }
3223 break;
3224
3225 case DW_TAG_structure_type:
3226 case DW_TAG_union_type:
3227 case DW_TAG_class_type:
3228 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003229 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003230 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003231
Greg Clayton9e409562010-07-28 02:04:09 +00003232 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003233 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003234 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003235 if (num_attributes > 0)
3236 {
3237 uint32_t i;
3238 for (i=0; i<num_attributes; ++i)
3239 {
3240 attr = attributes.AttributeAtIndex(i);
3241 DWARFFormValue form_value;
3242 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3243 {
3244 switch (attr)
3245 {
Greg Clayton9e409562010-07-28 02:04:09 +00003246 case DW_AT_decl_file:
3247 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3248 break;
3249
3250 case DW_AT_decl_line:
3251 decl.SetLine(form_value.Unsigned());
3252 break;
3253
3254 case DW_AT_decl_column:
3255 decl.SetColumn(form_value.Unsigned());
3256 break;
3257
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003258 case DW_AT_name:
3259 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003260 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003261 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003262
3263 case DW_AT_byte_size:
3264 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00003265 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00003266 break;
3267
3268 case DW_AT_accessibility:
3269 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3270 break;
3271
3272 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003273 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003274 break;
3275
3276 case DW_AT_APPLE_runtime_class:
3277 class_language = (LanguageType)form_value.Signed();
3278 break;
3279
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003280 case DW_AT_allocated:
3281 case DW_AT_associated:
3282 case DW_AT_data_location:
3283 case DW_AT_description:
3284 case DW_AT_start_scope:
3285 case DW_AT_visibility:
3286 default:
3287 case DW_AT_sibling:
3288 break;
3289 }
3290 }
3291 }
3292 }
3293
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003294 UniqueDWARFASTType unique_ast_entry;
3295 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003296 {
Greg Claytone576ab22011-02-15 00:19:15 +00003297 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00003298 this,
3299 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00003300 die,
3301 decl,
Greg Clayton36909642011-03-15 04:38:20 +00003302 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00003303 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003304 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003305 // We have already parsed this type or from another
3306 // compile unit. GCC loves to use the "one definition
3307 // rule" which can result in multiple definitions
3308 // of the same class over and over in each compile
3309 // unit.
3310 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003311 if (type_sp)
3312 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003313 m_die_to_type[die] = type_sp.get();
3314 return type_sp;
3315 }
3316 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003317 }
3318
3319 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3320
3321 int tag_decl_kind = -1;
3322 AccessType default_accessibility = eAccessNone;
3323 if (tag == DW_TAG_structure_type)
3324 {
3325 tag_decl_kind = clang::TTK_Struct;
3326 default_accessibility = eAccessPublic;
3327 }
3328 else if (tag == DW_TAG_union_type)
3329 {
3330 tag_decl_kind = clang::TTK_Union;
3331 default_accessibility = eAccessPublic;
3332 }
3333 else if (tag == DW_TAG_class_type)
3334 {
3335 tag_decl_kind = clang::TTK_Class;
3336 default_accessibility = eAccessPrivate;
3337 }
3338
3339
3340 if (is_forward_declaration)
3341 {
3342 // We have a forward declaration to a type and we need
3343 // to try and find a full declaration. We look in the
3344 // current type index just in case we have a forward
3345 // declaration followed by an actual declarations in the
3346 // DWARF. If this fails, we need to look elsewhere...
3347
3348 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3349
3350 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00003351 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003352 // We weren't able to find a full declaration in
3353 // this DWARF, see if we have a declaration anywhere
3354 // else...
3355 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00003356 }
3357
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003358 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00003359 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003360 // We found a real definition for this type elsewhere
3361 // so lets use it and cache the fact that we found
3362 // a complete type for this die
3363 m_die_to_type[die] = type_sp.get();
3364 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003365 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003366 }
3367 assert (tag_decl_kind != -1);
3368 bool clang_type_was_created = false;
3369 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3370 if (clang_type == NULL)
3371 {
3372 clang_type_was_created = true;
3373 clang_type = ast.CreateRecordType (type_name_cstr,
3374 tag_decl_kind,
Sean Callanan72e49402011-08-05 23:43:37 +00003375 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003376 class_language);
3377 }
3378
3379 // Store a forward declaration to this class type in case any
3380 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00003381 // types for function prototypes.
3382 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003383 type_sp.reset (new Type (die->GetOffset(),
3384 this,
3385 type_name_const_str,
3386 byte_size,
3387 NULL,
3388 LLDB_INVALID_UID,
3389 Type::eEncodingIsUID,
3390 &decl,
3391 clang_type,
3392 Type::eResolveStateForward));
3393
3394
3395 // Add our type to the unique type map so we don't
3396 // end up creating many copies of the same type over
3397 // and over in the ASTContext for our module
3398 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00003399 unique_ast_entry.m_symfile = this;
3400 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003401 unique_ast_entry.m_die = die;
3402 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00003403 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
3404 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003405
3406 if (die->HasChildren() == false && is_forward_declaration == false)
3407 {
3408 // No children for this struct/union/class, lets finish it
3409 ast.StartTagDeclarationDefinition (clang_type);
3410 ast.CompleteTagDeclarationDefinition (clang_type);
3411 }
3412 else if (clang_type_was_created)
3413 {
3414 // Leave this as a forward declaration until we need
3415 // to know the details of the type. lldb_private::Type
3416 // will automatically call the SymbolFile virtual function
3417 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3418 // When the definition needs to be defined.
3419 m_forward_decl_die_to_clang_type[die] = clang_type;
3420 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
3421 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00003422 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003423 }
3424 break;
3425
3426 case DW_TAG_enumeration_type:
3427 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003428 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003429 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003431 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003432
Greg Claytond88d7592010-09-15 08:33:30 +00003433 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003434 if (num_attributes > 0)
3435 {
3436 uint32_t i;
3437
3438 for (i=0; i<num_attributes; ++i)
3439 {
3440 attr = attributes.AttributeAtIndex(i);
3441 DWARFFormValue form_value;
3442 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3443 {
3444 switch (attr)
3445 {
Greg Clayton7a345282010-11-09 23:46:37 +00003446 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3447 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3448 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003449 case DW_AT_name:
3450 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003451 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003452 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003453 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003454 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00003455 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3456 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003457 case DW_AT_allocated:
3458 case DW_AT_associated:
3459 case DW_AT_bit_stride:
3460 case DW_AT_byte_stride:
3461 case DW_AT_data_location:
3462 case DW_AT_description:
3463 case DW_AT_start_scope:
3464 case DW_AT_visibility:
3465 case DW_AT_specification:
3466 case DW_AT_abstract_origin:
3467 case DW_AT_sibling:
3468 break;
3469 }
3470 }
3471 }
3472
Greg Claytonc93237c2010-10-01 20:48:32 +00003473 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3474
Greg Clayton1be10fc2010-09-29 01:12:09 +00003475 clang_type_t enumerator_clang_type = NULL;
3476 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3477 if (clang_type == NULL)
3478 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003479 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3480 DW_ATE_signed,
3481 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00003482 clang_type = ast.CreateEnumerationType (type_name_cstr,
Sean Callanan72e49402011-08-05 23:43:37 +00003483 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Claytonca512b32011-01-14 04:54:56 +00003484 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003485 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003486 }
3487 else
3488 {
3489 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3490 assert (enumerator_clang_type != NULL);
3491 }
3492
Greg Claytona2721472011-06-25 00:44:06 +00003493 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
3494
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003495 type_sp.reset( new Type (die->GetOffset(),
3496 this,
3497 type_name_const_str,
3498 byte_size,
3499 NULL,
3500 encoding_uid,
3501 Type::eEncodingIsUID,
3502 &decl,
3503 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003504 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003505
Greg Clayton6beaaa62011-01-17 03:46:26 +00003506#if LEAVE_ENUMS_FORWARD_DECLARED
Greg Clayton1be10fc2010-09-29 01:12:09 +00003507 // Leave this as a forward declaration until we need
3508 // to know the details of the type. lldb_private::Type
3509 // will automatically call the SymbolFile virtual function
3510 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3511 // When the definition needs to be defined.
3512 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003513 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003514 ClangASTContext::SetHasExternalStorage (clang_type, true);
3515#else
3516 ast.StartTagDeclarationDefinition (clang_type);
3517 if (die->HasChildren())
3518 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003519 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
3520 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00003521 }
3522 ast.CompleteTagDeclarationDefinition (clang_type);
3523#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003524 }
3525 }
3526 break;
3527
Jim Inghamb0be4422010-08-12 01:20:14 +00003528 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003529 case DW_TAG_subprogram:
3530 case DW_TAG_subroutine_type:
3531 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003532 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003533 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003534
3535 const char *mangled = NULL;
3536 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003537 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003538 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003539 bool is_static = false;
3540 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003541 bool is_explicit = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003542
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003543 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003544 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003545
3546
Greg Claytond88d7592010-09-15 08:33:30 +00003547 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003548 if (num_attributes > 0)
3549 {
3550 uint32_t i;
3551 for (i=0; i<num_attributes; ++i)
3552 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003553 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003554 DWARFFormValue form_value;
3555 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3556 {
3557 switch (attr)
3558 {
3559 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3560 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3561 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3562 case DW_AT_name:
3563 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003564 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003565 break;
3566
3567 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3568 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003569 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003570 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003571 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3572 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003573 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3574
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003575 case DW_AT_external:
3576 if (form_value.Unsigned())
3577 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003578 if (storage == clang::SC_None)
3579 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003580 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003581 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003582 }
3583 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003584
3585 case DW_AT_allocated:
3586 case DW_AT_associated:
3587 case DW_AT_address_class:
3588 case DW_AT_artificial:
3589 case DW_AT_calling_convention:
3590 case DW_AT_data_location:
3591 case DW_AT_elemental:
3592 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003593 case DW_AT_frame_base:
3594 case DW_AT_high_pc:
3595 case DW_AT_low_pc:
3596 case DW_AT_object_pointer:
3597 case DW_AT_prototyped:
3598 case DW_AT_pure:
3599 case DW_AT_ranges:
3600 case DW_AT_recursive:
3601 case DW_AT_return_addr:
3602 case DW_AT_segment:
3603 case DW_AT_specification:
3604 case DW_AT_start_scope:
3605 case DW_AT_static_link:
3606 case DW_AT_trampoline:
3607 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003608 case DW_AT_vtable_elem_location:
3609 case DW_AT_abstract_origin:
3610 case DW_AT_description:
3611 case DW_AT_sibling:
3612 break;
3613 }
3614 }
3615 }
Greg Clayton24739922010-10-13 03:15:28 +00003616 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003617
Greg Clayton24739922010-10-13 03:15:28 +00003618 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00003619
Greg Clayton24739922010-10-13 03:15:28 +00003620 clang_type_t return_clang_type = NULL;
3621 Type *func_type = NULL;
3622
3623 if (type_die_offset != DW_INVALID_OFFSET)
3624 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003625
Greg Clayton24739922010-10-13 03:15:28 +00003626 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003627 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003628 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003629 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003630
Greg Claytonf51de672010-10-01 02:31:07 +00003631
Greg Clayton24739922010-10-13 03:15:28 +00003632 std::vector<clang_type_t> function_param_types;
3633 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003634
Greg Clayton24739922010-10-13 03:15:28 +00003635 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00003636
Greg Clayton5113dc82011-08-12 06:47:54 +00003637 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
3638 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
3639
3640 const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord;
3641 // Start off static. This will be set to false in ParseChildParameters(...)
3642 // if we find a "this" paramters as the first parameter
3643 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00003644 is_static = true;
3645
Greg Clayton24739922010-10-13 03:15:28 +00003646 if (die->HasChildren())
3647 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003648 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003649 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00003650 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003651 type_sp,
3652 dwarf_cu,
3653 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00003654 skip_artificial,
3655 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003656 type_list,
3657 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003658 function_param_decls,
3659 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003660 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661
Greg Clayton24739922010-10-13 03:15:28 +00003662 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003663 clang_type = ast.CreateFunctionType (return_clang_type,
3664 &function_param_types[0],
3665 function_param_types.size(),
3666 is_variadic,
3667 type_quals);
3668
Greg Clayton24739922010-10-13 03:15:28 +00003669 if (type_name_cstr)
3670 {
3671 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00003672 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003673 {
Greg Clayton24739922010-10-13 03:15:28 +00003674 if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
Greg Clayton0fffff52010-09-24 05:15:53 +00003675 {
Greg Clayton24739922010-10-13 03:15:28 +00003676 // We need to find the DW_TAG_class_type or
3677 // DW_TAG_struct_type by name so we can add this
3678 // as a member function of the class.
3679 const char *class_name_start = type_name_cstr + 2;
3680 const char *class_name_end = ::strchr (class_name_start, ' ');
3681 SymbolContext empty_sc;
3682 clang_type_t class_opaque_type = NULL;
3683 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003684 {
Greg Clayton24739922010-10-13 03:15:28 +00003685 ConstString class_name (class_name_start, class_name_end - class_name_start);
3686 TypeList types;
3687 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3688 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003689 {
Greg Clayton24739922010-10-13 03:15:28 +00003690 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003691 {
Greg Clayton24739922010-10-13 03:15:28 +00003692 Type *type = types.GetTypeAtIndex (i).get();
3693 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3694 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003695 {
Greg Clayton24739922010-10-13 03:15:28 +00003696 class_opaque_type = type_clang_forward_type;
3697 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003698 }
3699 }
3700 }
Greg Clayton24739922010-10-13 03:15:28 +00003701 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003702
Greg Clayton24739922010-10-13 03:15:28 +00003703 if (class_opaque_type)
3704 {
3705 // If accessibility isn't set to anything valid, assume public for
3706 // now...
3707 if (accessibility == eAccessNone)
3708 accessibility = eAccessPublic;
3709
3710 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003711 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3712 type_name_cstr,
3713 clang_type,
3714 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003715 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00003716 type_handled = objc_method_decl != NULL;
3717 }
3718 }
Greg Clayton5113dc82011-08-12 06:47:54 +00003719 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00003720 {
3721 // Look at the parent of this DIE and see if is is
3722 // a class or struct and see if this is actually a
3723 // C++ method
Greg Clayton5113dc82011-08-12 06:47:54 +00003724 Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]);
Greg Clayton24739922010-10-13 03:15:28 +00003725 if (class_type)
3726 {
3727 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3728 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003729 {
Greg Clayton24739922010-10-13 03:15:28 +00003730 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3731 // in the DWARF for C++ methods... Default to public for now...
Greg Clayton6d01ad92010-09-29 01:57:37 +00003732 if (accessibility == eAccessNone)
3733 accessibility = eAccessPublic;
Greg Clayton931180e2011-01-27 06:44:37 +00003734
3735 if (!is_static && !die->HasChildren())
3736 {
3737 // We have a C++ member function with no children (this pointer!)
3738 // and clang will get mad if we try and make a function that isn't
3739 // well formed in the DWARF, so we will just skip it...
3740 type_handled = true;
3741 }
3742 else
3743 {
3744 clang::CXXMethodDecl *cxx_method_decl;
3745 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3746 type_name_cstr,
3747 clang_type,
3748 accessibility,
3749 is_virtual,
3750 is_static,
3751 is_inline,
3752 is_explicit);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003753 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
3754
Greg Clayton931180e2011-01-27 06:44:37 +00003755 type_handled = cxx_method_decl != NULL;
3756 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003757 }
3758 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003759 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003760 }
Greg Clayton24739922010-10-13 03:15:28 +00003761
3762 if (!type_handled)
3763 {
3764 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003765 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3766 clang_type,
3767 storage,
3768 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003769
3770 // Add the decl to our DIE to decl context map
3771 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00003772 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00003773 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003774 ast.SetFunctionParameters (function_decl,
3775 &function_param_decls.front(),
3776 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003777 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003778 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003779 type_sp.reset( new Type (die->GetOffset(),
3780 this,
3781 type_name_const_str,
3782 0,
3783 NULL,
3784 LLDB_INVALID_UID,
3785 Type::eEncodingIsUID,
3786 &decl,
3787 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003788 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00003789 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003790 }
3791 break;
3792
3793 case DW_TAG_array_type:
3794 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003795 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003796 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003797
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003798 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003799 int64_t first_index = 0;
3800 uint32_t byte_stride = 0;
3801 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003802 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003803
3804 if (num_attributes > 0)
3805 {
3806 uint32_t i;
3807 for (i=0; i<num_attributes; ++i)
3808 {
3809 attr = attributes.AttributeAtIndex(i);
3810 DWARFFormValue form_value;
3811 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3812 {
3813 switch (attr)
3814 {
3815 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3816 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3817 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3818 case DW_AT_name:
3819 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003820 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003821 break;
3822
3823 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003824 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003825 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3826 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003827 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003828 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003829 case DW_AT_allocated:
3830 case DW_AT_associated:
3831 case DW_AT_data_location:
3832 case DW_AT_description:
3833 case DW_AT_ordering:
3834 case DW_AT_start_scope:
3835 case DW_AT_visibility:
3836 case DW_AT_specification:
3837 case DW_AT_abstract_origin:
3838 case DW_AT_sibling:
3839 break;
3840 }
3841 }
3842 }
3843
Greg Claytonc93237c2010-10-01 20:48:32 +00003844 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3845
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003846 Type *element_type = ResolveTypeUID(type_die_offset);
3847
3848 if (element_type)
3849 {
3850 std::vector<uint64_t> element_orders;
3851 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00003852 // We have an array that claims to have no members, lets give it at least one member...
3853 if (element_orders.empty())
3854 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003855 if (byte_stride == 0 && bit_stride == 0)
3856 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00003857 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003858 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3859 uint64_t num_elements = 0;
3860 std::vector<uint64_t>::const_reverse_iterator pos;
3861 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3862 for (pos = element_orders.rbegin(); pos != end; ++pos)
3863 {
3864 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003865 clang_type = ast.CreateArrayType (array_element_type,
3866 num_elements,
3867 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003868 array_element_type = clang_type;
3869 array_element_bit_stride = array_element_bit_stride * num_elements;
3870 }
3871 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003872 type_sp.reset( new Type (die->GetOffset(),
3873 this,
3874 empty_name,
3875 array_element_bit_stride / 8,
3876 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00003877 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003878 Type::eEncodingIsUID,
3879 &decl,
3880 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003881 Type::eResolveStateFull));
3882 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883 }
3884 }
3885 }
3886 break;
3887
Greg Clayton9b81a312010-06-12 01:20:30 +00003888 case DW_TAG_ptr_to_member_type:
3889 {
3890 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3891 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3892
Greg Claytond88d7592010-09-15 08:33:30 +00003893 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00003894
3895 if (num_attributes > 0) {
3896 uint32_t i;
3897 for (i=0; i<num_attributes; ++i)
3898 {
3899 attr = attributes.AttributeAtIndex(i);
3900 DWARFFormValue form_value;
3901 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3902 {
3903 switch (attr)
3904 {
3905 case DW_AT_type:
3906 type_die_offset = form_value.Reference(dwarf_cu); break;
3907 case DW_AT_containing_type:
3908 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3909 }
3910 }
3911 }
3912
3913 Type *pointee_type = ResolveTypeUID(type_die_offset);
3914 Type *class_type = ResolveTypeUID(containing_type_die_offset);
3915
Greg Clayton526e5af2010-11-13 03:52:47 +00003916 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
3917 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00003918
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003919 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
3920 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00003921
Greg Clayton526e5af2010-11-13 03:52:47 +00003922 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
3923 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00003924
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003925 type_sp.reset( new Type (die->GetOffset(),
3926 this,
3927 type_name_const_str,
3928 byte_size,
3929 NULL,
3930 LLDB_INVALID_UID,
3931 Type::eEncodingIsUID,
3932 NULL,
3933 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003934 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00003935 }
3936
3937 break;
3938 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003939 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00003940 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003941 break;
3942 }
3943
3944 if (type_sp.get())
3945 {
3946 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3947 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3948
3949 SymbolContextScope * symbol_context_scope = NULL;
3950 if (sc_parent_tag == DW_TAG_compile_unit)
3951 {
3952 symbol_context_scope = sc.comp_unit;
3953 }
3954 else if (sc.function != NULL)
3955 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003956 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003957 if (symbol_context_scope == NULL)
3958 symbol_context_scope = sc.function;
3959 }
3960
3961 if (symbol_context_scope != NULL)
3962 {
3963 type_sp->SetSymbolContextScope(symbol_context_scope);
3964 }
3965
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003966 // We are ready to put this type into the uniqued list up at the module level
3967 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00003968
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003969 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003970 }
3971 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00003972 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003973 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003974 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003975 }
3976 }
3977 return type_sp;
3978}
3979
3980size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003981SymbolFileDWARF::ParseTypes
3982(
3983 const SymbolContext& sc,
3984 DWARFCompileUnit* dwarf_cu,
3985 const DWARFDebugInfoEntry *die,
3986 bool parse_siblings,
3987 bool parse_children
3988)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003989{
3990 size_t types_added = 0;
3991 while (die != NULL)
3992 {
3993 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003994 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003995 {
3996 if (type_is_new)
3997 ++types_added;
3998 }
3999
4000 if (parse_children && die->HasChildren())
4001 {
4002 if (die->Tag() == DW_TAG_subprogram)
4003 {
4004 SymbolContext child_sc(sc);
4005 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
4006 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4007 }
4008 else
4009 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4010 }
4011
4012 if (parse_siblings)
4013 die = die->GetSibling();
4014 else
4015 die = NULL;
4016 }
4017 return types_added;
4018}
4019
4020
4021size_t
4022SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4023{
4024 assert(sc.comp_unit && sc.function);
4025 size_t functions_added = 0;
4026 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4027 if (dwarf_cu)
4028 {
4029 dw_offset_t function_die_offset = sc.function->GetID();
4030 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4031 if (function_die)
4032 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004033 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004034 }
4035 }
4036
4037 return functions_added;
4038}
4039
4040
4041size_t
4042SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4043{
4044 // At least a compile unit must be valid
4045 assert(sc.comp_unit);
4046 size_t types_added = 0;
4047 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4048 if (dwarf_cu)
4049 {
4050 if (sc.function)
4051 {
4052 dw_offset_t function_die_offset = sc.function->GetID();
4053 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4054 if (func_die && func_die->HasChildren())
4055 {
4056 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4057 }
4058 }
4059 else
4060 {
4061 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4062 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4063 {
4064 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4065 }
4066 }
4067 }
4068
4069 return types_added;
4070}
4071
4072size_t
4073SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4074{
4075 if (sc.comp_unit != NULL)
4076 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004077 DWARFDebugInfo* info = DebugInfo();
4078 if (info == NULL)
4079 return 0;
4080
4081 uint32_t cu_idx = UINT32_MAX;
4082 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004083
4084 if (dwarf_cu == NULL)
4085 return 0;
4086
4087 if (sc.function)
4088 {
4089 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004090
4091 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4092 assert (func_lo_pc != DW_INVALID_ADDRESS);
4093
Greg Claytonc662ec82011-06-17 22:10:16 +00004094 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4095
4096 // Let all blocks know they have parse all their variables
4097 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4098
4099 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004100 }
4101 else if (sc.comp_unit)
4102 {
4103 uint32_t vars_added = 0;
4104 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4105
4106 if (variables.get() == NULL)
4107 {
4108 variables.reset(new VariableList());
4109 sc.comp_unit->SetVariableList(variables);
4110
4111 // Index if we already haven't to make sure the compile units
4112 // get indexed and make their global DIE index list
4113 if (!m_indexed)
4114 Index ();
4115
Greg Claytonc685f8e2010-09-15 04:15:46 +00004116 std::vector<NameToDIE::Info> global_die_info_array;
Greg Clayton4b3dc102010-11-01 20:32:12 +00004117 const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004118 for (size_t idx=0; idx<num_globals; ++idx)
4119 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00004120 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004121 if (var_sp)
4122 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00004123 variables->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004124 ++vars_added;
4125 }
4126 }
4127 }
4128 return vars_added;
4129 }
4130 }
4131 return 0;
4132}
4133
4134
4135VariableSP
4136SymbolFileDWARF::ParseVariableDIE
4137(
4138 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004139 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004140 const DWARFDebugInfoEntry *die,
4141 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004142)
4143{
4144
Greg Clayton83c5cd92010-11-14 22:13:40 +00004145 VariableSP var_sp (m_die_to_variable_sp[die]);
4146 if (var_sp)
4147 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004148
4149 const dw_tag_t tag = die->Tag();
4150 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004151 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004152 if (num_attributes > 0)
4153 {
4154 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00004155 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004156 Declaration decl;
4157 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004158 Type *var_type = NULL;
4159 DWARFExpression location;
4160 bool is_external = false;
4161 bool is_artificial = false;
Greg Clayton007d5be2011-05-30 00:49:24 +00004162 bool location_is_const_value_data = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00004163 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004164
4165 for (i=0; i<num_attributes; ++i)
4166 {
4167 dw_attr_t attr = attributes.AttributeAtIndex(i);
4168 DWARFFormValue form_value;
4169 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4170 {
4171 switch (attr)
4172 {
4173 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4174 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4175 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4176 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00004177 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00004178 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004179 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Greg Clayton007d5be2011-05-30 00:49:24 +00004180 case DW_AT_const_value:
4181 location_is_const_value_data = true;
4182 // Fall through...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004183 case DW_AT_location:
4184 {
4185 if (form_value.BlockData())
4186 {
4187 const DataExtractor& debug_info_data = get_debug_info_data();
4188
4189 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4190 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00004191 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004192 }
4193 else
4194 {
4195 const DataExtractor& debug_loc_data = get_debug_loc_data();
4196 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4197
4198 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4199 if (loc_list_length > 0)
4200 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004201 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
4202 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4203 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204 }
4205 }
4206 }
4207 break;
4208
4209 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004210 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004211 case DW_AT_declaration:
4212 case DW_AT_description:
4213 case DW_AT_endianity:
4214 case DW_AT_segment:
4215 case DW_AT_start_scope:
4216 case DW_AT_visibility:
4217 default:
4218 case DW_AT_abstract_origin:
4219 case DW_AT_sibling:
4220 case DW_AT_specification:
4221 break;
4222 }
4223 }
4224 }
4225
4226 if (location.IsValid())
4227 {
4228 assert(var_type != DIE_IS_BEING_PARSED);
4229
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004230 ValueType scope = eValueTypeInvalid;
4231
4232 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4233 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4234
4235 if (tag == DW_TAG_formal_parameter)
4236 scope = eValueTypeVariableArgument;
4237 else if (is_external || parent_tag == DW_TAG_compile_unit)
4238 scope = eValueTypeVariableGlobal;
4239 else
4240 scope = eValueTypeVariableLocal;
4241
4242 SymbolContextScope * symbol_context_scope = NULL;
4243 if (parent_tag == DW_TAG_compile_unit)
4244 {
4245 symbol_context_scope = sc.comp_unit;
4246 }
4247 else if (sc.function != NULL)
4248 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004249 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004250 if (symbol_context_scope == NULL)
4251 symbol_context_scope = sc.function;
4252 }
4253
4254 assert(symbol_context_scope != NULL);
4255 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00004256 name,
4257 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004258 var_type,
4259 scope,
4260 symbol_context_scope,
4261 &decl,
4262 location,
4263 is_external,
4264 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00004265
Greg Clayton007d5be2011-05-30 00:49:24 +00004266 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004267 }
4268 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00004269 // Cache var_sp even if NULL (the variable was just a specification or
4270 // was missing vital information to be able to be displayed in the debugger
4271 // (missing location due to optimization, etc)) so we don't re-parse
4272 // this DIE over and over later...
4273 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004274 return var_sp;
4275}
4276
Greg Claytonc662ec82011-06-17 22:10:16 +00004277
4278const DWARFDebugInfoEntry *
4279SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
4280 dw_offset_t spec_block_die_offset,
4281 DWARFCompileUnit **result_die_cu_handle)
4282{
4283 // Give the concrete function die specified by "func_die_offset", find the
4284 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4285 // to "spec_block_die_offset"
4286 DWARFDebugInfo* info = DebugInfo();
4287
4288 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
4289 if (die)
4290 {
4291 assert (*result_die_cu_handle);
4292 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
4293 }
4294 return NULL;
4295}
4296
4297
4298const DWARFDebugInfoEntry *
4299SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
4300 const DWARFDebugInfoEntry *die,
4301 dw_offset_t spec_block_die_offset,
4302 DWARFCompileUnit **result_die_cu_handle)
4303{
4304 if (die)
4305 {
4306 switch (die->Tag())
4307 {
4308 case DW_TAG_subprogram:
4309 case DW_TAG_inlined_subroutine:
4310 case DW_TAG_lexical_block:
4311 {
4312 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4313 {
4314 *result_die_cu_handle = dwarf_cu;
4315 return die;
4316 }
4317
4318 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4319 {
4320 *result_die_cu_handle = dwarf_cu;
4321 return die;
4322 }
4323 }
4324 break;
4325 }
4326
4327 // Give the concrete function die specified by "func_die_offset", find the
4328 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4329 // to "spec_block_die_offset"
4330 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
4331 {
4332 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
4333 child_die,
4334 spec_block_die_offset,
4335 result_die_cu_handle);
4336 if (result_die)
4337 return result_die;
4338 }
4339 }
4340
4341 *result_die_cu_handle = NULL;
4342 return NULL;
4343}
4344
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004345size_t
4346SymbolFileDWARF::ParseVariables
4347(
4348 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004349 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004350 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004351 const DWARFDebugInfoEntry *orig_die,
4352 bool parse_siblings,
4353 bool parse_children,
4354 VariableList* cc_variable_list
4355)
4356{
4357 if (orig_die == NULL)
4358 return 0;
4359
Greg Claytonc662ec82011-06-17 22:10:16 +00004360 VariableListSP variable_list_sp;
4361
4362 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004363 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004364 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004365 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004366 dw_tag_t tag = die->Tag();
4367
4368 // Check to see if we have already parsed this variable or constant?
4369 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004370 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004371 if (cc_variable_list)
4372 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004373 }
4374 else
4375 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004376 // We haven't already parsed it, lets do that now.
4377 if ((tag == DW_TAG_variable) ||
4378 (tag == DW_TAG_constant) ||
4379 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004380 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004381 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004382 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004383 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4384 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4385 switch (parent_tag)
4386 {
4387 case DW_TAG_compile_unit:
4388 if (sc.comp_unit != NULL)
4389 {
4390 variable_list_sp = sc.comp_unit->GetVariableList(false);
4391 if (variable_list_sp.get() == NULL)
4392 {
4393 variable_list_sp.reset(new VariableList());
4394 sc.comp_unit->SetVariableList(variable_list_sp);
4395 }
4396 }
4397 else
4398 {
4399 fprintf (stderr,
4400 "error: parent 0x%8.8x %s with no valid compile unit in symbol context for 0x%8.8x %s.\n",
4401 sc_parent_die->GetOffset(),
4402 DW_TAG_value_to_name (parent_tag),
4403 orig_die->GetOffset(),
4404 DW_TAG_value_to_name (orig_die->Tag()));
4405 }
4406 break;
4407
4408 case DW_TAG_subprogram:
4409 case DW_TAG_inlined_subroutine:
4410 case DW_TAG_lexical_block:
4411 if (sc.function != NULL)
4412 {
4413 // Check to see if we already have parsed the variables for the given scope
4414
4415 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
4416 if (block == NULL)
4417 {
4418 // This must be a specification or abstract origin with
4419 // a concrete block couterpart in the current function. We need
4420 // to find the concrete block so we can correctly add the
4421 // variable to it
4422 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
4423 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4424 sc_parent_die->GetOffset(),
4425 &concrete_block_die_cu);
4426 if (concrete_block_die)
4427 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die->GetOffset());
4428 }
4429
4430 if (block != NULL)
4431 {
4432 const bool can_create = false;
4433 variable_list_sp = block->GetBlockVariableList (can_create);
4434 if (variable_list_sp.get() == NULL)
4435 {
4436 variable_list_sp.reset(new VariableList());
4437 block->SetVariableList(variable_list_sp);
4438 }
4439 }
4440 }
4441 break;
4442
4443 default:
4444 fprintf (stderr,
4445 "error: didn't find appropriate parent DIE for variable list for 0x%8.8x %s.\n",
4446 orig_die->GetOffset(),
4447 DW_TAG_value_to_name (orig_die->Tag()));
4448 break;
4449 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004450 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004451
4452 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004453 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00004454 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
4455 if (var_sp)
4456 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004457 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004458 if (cc_variable_list)
4459 cc_variable_list->AddVariableIfUnique (var_sp);
4460 ++vars_added;
4461 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004462 }
4463 }
4464 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004465
4466 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4467
4468 if (!skip_children && parse_children && die->HasChildren())
4469 {
4470 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
4471 }
4472
4473 if (parse_siblings)
4474 die = die->GetSibling();
4475 else
4476 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004477 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004478 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004479}
4480
4481//------------------------------------------------------------------
4482// PluginInterface protocol
4483//------------------------------------------------------------------
4484const char *
4485SymbolFileDWARF::GetPluginName()
4486{
4487 return "SymbolFileDWARF";
4488}
4489
4490const char *
4491SymbolFileDWARF::GetShortPluginName()
4492{
4493 return GetPluginNameStatic();
4494}
4495
4496uint32_t
4497SymbolFileDWARF::GetPluginVersion()
4498{
4499 return 1;
4500}
4501
4502void
Greg Clayton6beaaa62011-01-17 03:46:26 +00004503SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
4504{
4505 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4506 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4507 if (clang_type)
4508 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4509}
4510
4511void
4512SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
4513{
4514 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4515 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4516 if (clang_type)
4517 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4518}
4519
Greg Claytona2721472011-06-25 00:44:06 +00004520void
Sean Callanancc427fa2011-07-30 02:42:06 +00004521SymbolFileDWARF::DumpIndexes ()
4522{
4523 StreamFile s(stdout, false);
4524
4525 s.Printf ("DWARF index for (%s) '%s/%s':",
4526 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4527 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
4528 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
4529 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4530 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4531 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4532 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4533 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4534 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4535 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
4536 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
4537}
4538
4539void
4540SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
4541 const char *name,
4542 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00004543{
Sean Callanancc427fa2011-07-30 02:42:06 +00004544 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00004545
4546 if (iter == m_decl_ctx_to_die.end())
4547 return;
4548
Sean Callanancc427fa2011-07-30 02:42:06 +00004549 const DWARFDebugInfoEntry *context_die = iter->second;
Greg Claytona2721472011-06-25 00:44:06 +00004550
4551 if (!results)
4552 return;
4553
4554 DWARFDebugInfo* info = DebugInfo();
4555
4556 std::vector<NameToDIE::Info> die_info_array;
4557
Greg Clayton1d4313b2011-07-07 04:49:07 +00004558 size_t num_matches = m_type_index.Find (ConstString(name), die_info_array);
Greg Claytona2721472011-06-25 00:44:06 +00004559
4560 if (num_matches)
4561 {
4562 for (int i = 0;
4563 i < num_matches;
4564 ++i)
4565 {
4566 DWARFCompileUnit* compile_unit = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
4567 compile_unit->ExtractDIEsIfNeeded (false);
4568 const DWARFDebugInfoEntry *die = compile_unit->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
4569
Sean Callanancc427fa2011-07-30 02:42:06 +00004570 if (die->GetParent() != context_die)
Greg Claytona2721472011-06-25 00:44:06 +00004571 continue;
4572
4573 Type *matching_type = ResolveType (compile_unit, die);
4574
4575 lldb::clang_type_t type = matching_type->GetClangFullType();
4576 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
4577
Sean Callanancc427fa2011-07-30 02:42:06 +00004578 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004579 {
4580 clang::TagDecl *tag_decl = tag_type->getDecl();
4581 results->push_back(tag_decl);
4582 }
Sean Callanancc427fa2011-07-30 02:42:06 +00004583 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004584 {
4585 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
4586 results->push_back(typedef_decl);
4587 }
4588 }
4589 }
4590}
4591
4592void
4593SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
4594 const clang::DeclContext *DC,
4595 clang::DeclarationName Name,
4596 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
4597{
4598 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4599
Sean Callanancc427fa2011-07-30 02:42:06 +00004600 symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results);
Greg Claytona2721472011-06-25 00:44:06 +00004601}