blob: dedd1115eeeff9a5cdc8bbe2d9277715f2473327 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
17#include "clang/Basic/Builtins.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/Basic/LangOptions.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000023#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Sean Callanancc427fa2011-07-30 02:42:06 +000025#include "llvm/Support/Casting.h"
26
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/PluginManager.h"
29#include "lldb/Core/RegularExpression.h"
30#include "lldb/Core/Scalar.h"
31#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000032#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000033#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/Timer.h"
35#include "lldb/Core/Value.h"
36
37#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000038#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/CompileUnit.h"
40#include "lldb/Symbol/LineTable.h"
41#include "lldb/Symbol/ObjectFile.h"
42#include "lldb/Symbol/SymbolVendor.h"
43#include "lldb/Symbol/VariableList.h"
44
45#include "DWARFCompileUnit.h"
46#include "DWARFDebugAbbrev.h"
47#include "DWARFDebugAranges.h"
48#include "DWARFDebugInfo.h"
49#include "DWARFDebugInfoEntry.h"
50#include "DWARFDebugLine.h"
51#include "DWARFDebugPubnames.h"
52#include "DWARFDebugRanges.h"
53#include "DWARFDIECollection.h"
54#include "DWARFFormValue.h"
55#include "DWARFLocationList.h"
56#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000057#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59#include <map>
60
Greg Clayton62742b12010-11-11 01:09:45 +000061//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000062
63#ifdef ENABLE_DEBUG_PRINTF
64#include <stdio.h>
65#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
66#else
67#define DEBUG_PRINTF(fmt, ...)
68#endif
69
Greg Clayton594e5ed2010-09-27 21:07:38 +000070#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
72using namespace lldb;
73using namespace lldb_private;
74
75
Sean Callananc7fbf732010-08-06 00:32:49 +000076static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000077DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078{
79 switch (dwarf_accessibility)
80 {
Sean Callananc7fbf732010-08-06 00:32:49 +000081 case DW_ACCESS_public: return eAccessPublic;
82 case DW_ACCESS_private: return eAccessPrivate;
83 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000084 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 }
Sean Callananc7fbf732010-08-06 00:32:49 +000086 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
89void
90SymbolFileDWARF::Initialize()
91{
92 LogChannelDWARF::Initialize();
93 PluginManager::RegisterPlugin (GetPluginNameStatic(),
94 GetPluginDescriptionStatic(),
95 CreateInstance);
96}
97
98void
99SymbolFileDWARF::Terminate()
100{
101 PluginManager::UnregisterPlugin (CreateInstance);
102 LogChannelDWARF::Initialize();
103}
104
105
106const char *
107SymbolFileDWARF::GetPluginNameStatic()
108{
109 return "symbol-file.dwarf2";
110}
111
112const char *
113SymbolFileDWARF::GetPluginDescriptionStatic()
114{
115 return "DWARF and DWARF3 debug symbol file reader.";
116}
117
118
119SymbolFile*
120SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
121{
122 return new SymbolFileDWARF(obj_file);
123}
124
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000125TypeList *
126SymbolFileDWARF::GetTypeList ()
127{
128 if (m_debug_map_symfile)
129 return m_debug_map_symfile->GetTypeList();
130 return m_obj_file->GetModule()->GetTypeList();
131
132}
133
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134//----------------------------------------------------------------------
135// Gets the first parent that is a lexical block, function or inlined
136// subroutine, or compile unit.
137//----------------------------------------------------------------------
138static const DWARFDebugInfoEntry *
139GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
140{
141 const DWARFDebugInfoEntry *die;
142 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
143 {
144 dw_tag_t tag = die->Tag();
145
146 switch (tag)
147 {
148 case DW_TAG_compile_unit:
149 case DW_TAG_subprogram:
150 case DW_TAG_inlined_subroutine:
151 case DW_TAG_lexical_block:
152 return die;
153 }
154 }
155 return NULL;
156}
157
158
Greg Clayton450e3f32010-10-12 02:24:53 +0000159SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
160 SymbolFile (objfile),
161 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000162 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 m_flags(),
164 m_data_debug_abbrev(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 m_data_debug_frame(),
166 m_data_debug_info(),
167 m_data_debug_line(),
168 m_data_debug_loc(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169 m_data_debug_ranges(),
170 m_data_debug_str(),
Greg Claytonf9eec202011-09-01 23:16:13 +0000171 m_data_debug_names (),
172 m_data_debug_types (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 m_abbr(),
174 m_aranges(),
175 m_info(),
176 m_line(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000177 m_function_basename_index(),
178 m_function_fullname_index(),
179 m_function_method_index(),
180 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000181 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000182 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000183 m_type_index(),
184 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000185 m_indexed (false),
186 m_is_external_ast_source (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000187 m_ranges(),
188 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189{
190}
191
192SymbolFileDWARF::~SymbolFileDWARF()
193{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000194 if (m_is_external_ast_source)
195 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
196}
197
198static const ConstString &
199GetDWARFMachOSegmentName ()
200{
201 static ConstString g_dwarf_section_name ("__DWARF");
202 return g_dwarf_section_name;
203}
204
Greg Claytone576ab22011-02-15 00:19:15 +0000205UniqueDWARFASTTypeMap &
206SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
207{
208 if (m_debug_map_symfile)
209 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
210 return m_unique_ast_type_map;
211}
212
Greg Clayton6beaaa62011-01-17 03:46:26 +0000213ClangASTContext &
214SymbolFileDWARF::GetClangASTContext ()
215{
216 if (m_debug_map_symfile)
217 return m_debug_map_symfile->GetClangASTContext ();
218
219 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
220 if (!m_is_external_ast_source)
221 {
222 m_is_external_ast_source = true;
223 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
224 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
225 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000226 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000227 this));
228
229 ast.SetExternalSource (ast_source_ap);
230 }
231 return ast;
232}
233
234void
235SymbolFileDWARF::InitializeObject()
236{
237 // Install our external AST source callbacks so we can complete Clang types.
238 Module *module = m_obj_file->GetModule();
239 if (module)
240 {
241 const SectionList *section_list = m_obj_file->GetSectionList();
242
243 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
244
245 // Memory map the DWARF mach-o segment so we have everything mmap'ed
246 // to keep our heap memory usage down.
247 if (section)
248 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250}
251
252bool
253SymbolFileDWARF::SupportedVersion(uint16_t version)
254{
255 return version == 2 || version == 3;
256}
257
258uint32_t
259SymbolFileDWARF::GetAbilities ()
260{
261 uint32_t abilities = 0;
262 if (m_obj_file != NULL)
263 {
264 const Section* section = NULL;
265 const SectionList *section_list = m_obj_file->GetSectionList();
266 if (section_list == NULL)
267 return 0;
268
269 uint64_t debug_abbrev_file_size = 0;
270 uint64_t debug_aranges_file_size = 0;
271 uint64_t debug_frame_file_size = 0;
272 uint64_t debug_info_file_size = 0;
273 uint64_t debug_line_file_size = 0;
274 uint64_t debug_loc_file_size = 0;
275 uint64_t debug_macinfo_file_size = 0;
276 uint64_t debug_pubnames_file_size = 0;
277 uint64_t debug_pubtypes_file_size = 0;
278 uint64_t debug_ranges_file_size = 0;
279 uint64_t debug_str_file_size = 0;
280
Greg Clayton6beaaa62011-01-17 03:46:26 +0000281 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282
283 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000284 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285
Greg Clayton4ceb9982010-07-21 22:54:26 +0000286 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287 if (section != NULL)
288 {
289 debug_info_file_size = section->GetByteSize();
290
Greg Clayton4ceb9982010-07-21 22:54:26 +0000291 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292 if (section)
293 debug_abbrev_file_size = section->GetByteSize();
294 else
295 m_flags.Set (flagsGotDebugAbbrevData);
296
Greg Clayton4ceb9982010-07-21 22:54:26 +0000297 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 if (section)
299 debug_aranges_file_size = section->GetByteSize();
300 else
301 m_flags.Set (flagsGotDebugArangesData);
302
Greg Clayton4ceb9982010-07-21 22:54:26 +0000303 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000304 if (section)
305 debug_frame_file_size = section->GetByteSize();
306 else
307 m_flags.Set (flagsGotDebugFrameData);
308
Greg Clayton4ceb9982010-07-21 22:54:26 +0000309 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 if (section)
311 debug_line_file_size = section->GetByteSize();
312 else
313 m_flags.Set (flagsGotDebugLineData);
314
Greg Clayton4ceb9982010-07-21 22:54:26 +0000315 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000316 if (section)
317 debug_loc_file_size = section->GetByteSize();
318 else
319 m_flags.Set (flagsGotDebugLocData);
320
Greg Clayton4ceb9982010-07-21 22:54:26 +0000321 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322 if (section)
323 debug_macinfo_file_size = section->GetByteSize();
324 else
325 m_flags.Set (flagsGotDebugMacInfoData);
326
Greg Clayton4ceb9982010-07-21 22:54:26 +0000327 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 if (section)
329 debug_pubnames_file_size = section->GetByteSize();
330 else
331 m_flags.Set (flagsGotDebugPubNamesData);
332
Greg Clayton4ceb9982010-07-21 22:54:26 +0000333 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000334 if (section)
335 debug_pubtypes_file_size = section->GetByteSize();
336 else
337 m_flags.Set (flagsGotDebugPubTypesData);
338
Greg Clayton4ceb9982010-07-21 22:54:26 +0000339 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340 if (section)
341 debug_ranges_file_size = section->GetByteSize();
342 else
343 m_flags.Set (flagsGotDebugRangesData);
344
Greg Clayton4ceb9982010-07-21 22:54:26 +0000345 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000346 if (section)
347 debug_str_file_size = section->GetByteSize();
348 else
349 m_flags.Set (flagsGotDebugStrData);
350 }
351
352 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
353 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
354
355 if (debug_line_file_size > 0)
356 abilities |= LineTables;
357
358 if (debug_aranges_file_size > 0)
359 abilities |= AddressAcceleratorTable;
360
361 if (debug_pubnames_file_size > 0)
362 abilities |= FunctionAcceleratorTable;
363
364 if (debug_pubtypes_file_size > 0)
365 abilities |= TypeAcceleratorTable;
366
367 if (debug_macinfo_file_size > 0)
368 abilities |= MacroInformation;
369
370 if (debug_frame_file_size > 0)
371 abilities |= CallFrameInformation;
372 }
373 return abilities;
374}
375
376const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000377SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378{
379 if (m_flags.IsClear (got_flag))
380 {
381 m_flags.Set (got_flag);
382 const SectionList *section_list = m_obj_file->GetSectionList();
383 if (section_list)
384 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000385 Section *section = section_list->FindSectionByType(sect_type, true).get();
386 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387 {
388 // See if we memory mapped the DWARF segment?
389 if (m_dwarf_data.GetByteSize())
390 {
391 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
392 }
393 else
394 {
395 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
396 data.Clear();
397 }
398 }
399 }
400 }
401 return data;
402}
403
404const DataExtractor&
405SymbolFileDWARF::get_debug_abbrev_data()
406{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000407 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408}
409
410const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411SymbolFileDWARF::get_debug_frame_data()
412{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000413 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414}
415
416const DataExtractor&
417SymbolFileDWARF::get_debug_info_data()
418{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000419 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420}
421
422const DataExtractor&
423SymbolFileDWARF::get_debug_line_data()
424{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000425 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426}
427
428const DataExtractor&
429SymbolFileDWARF::get_debug_loc_data()
430{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000431 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432}
433
434const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435SymbolFileDWARF::get_debug_ranges_data()
436{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000437 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438}
439
440const DataExtractor&
441SymbolFileDWARF::get_debug_str_data()
442{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000443 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444}
445
Greg Claytonf9eec202011-09-01 23:16:13 +0000446const DataExtractor&
447SymbolFileDWARF::get_debug_names_data()
448{
449 return GetCachedSectionData (flagsGotDebugNamesData, eSectionTypeDWARFDebugNames, m_data_debug_names);
450}
451
452const DataExtractor&
453SymbolFileDWARF::get_debug_types_data()
454{
455 return GetCachedSectionData (flagsGotDebugTypesData, eSectionTypeDWARFDebugTypes, m_data_debug_types);
456}
457
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458
459DWARFDebugAbbrev*
460SymbolFileDWARF::DebugAbbrev()
461{
462 if (m_abbr.get() == NULL)
463 {
464 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
465 if (debug_abbrev_data.GetByteSize() > 0)
466 {
467 m_abbr.reset(new DWARFDebugAbbrev());
468 if (m_abbr.get())
469 m_abbr->Parse(debug_abbrev_data);
470 }
471 }
472 return m_abbr.get();
473}
474
475const DWARFDebugAbbrev*
476SymbolFileDWARF::DebugAbbrev() const
477{
478 return m_abbr.get();
479}
480
481DWARFDebugAranges*
482SymbolFileDWARF::DebugAranges()
483{
Greg Clayton016a95e2010-09-14 02:20:48 +0000484 // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files
485 // and we are already parsing all of the DWARF because the .debug_pubnames
486 // is useless (it only mentions symbols that are externally visible), so
487 // don't use the .debug_aranges section, we should be using a debug aranges
488 // we got from SymbolFileDWARF::Index().
489
490 if (!m_indexed)
491 Index();
492
493
494// if (m_aranges.get() == NULL)
495// {
496// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
497// m_aranges.reset(new DWARFDebugAranges());
498// if (m_aranges.get())
499// {
500// const DataExtractor &debug_aranges_data = get_debug_aranges_data();
501// if (debug_aranges_data.GetByteSize() > 0)
502// m_aranges->Extract(debug_aranges_data);
503// else
504// m_aranges->Generate(this);
505// }
506// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 return m_aranges.get();
508}
509
510const DWARFDebugAranges*
511SymbolFileDWARF::DebugAranges() const
512{
513 return m_aranges.get();
514}
515
516
517DWARFDebugInfo*
518SymbolFileDWARF::DebugInfo()
519{
520 if (m_info.get() == NULL)
521 {
522 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
523 if (get_debug_info_data().GetByteSize() > 0)
524 {
525 m_info.reset(new DWARFDebugInfo());
526 if (m_info.get())
527 {
528 m_info->SetDwarfData(this);
529 }
530 }
531 }
532 return m_info.get();
533}
534
535const DWARFDebugInfo*
536SymbolFileDWARF::DebugInfo() const
537{
538 return m_info.get();
539}
540
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541DWARFCompileUnit*
542SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
543{
544 DWARFDebugInfo* info = DebugInfo();
545 if (info)
546 return info->GetCompileUnit(cu_uid).get();
547 return NULL;
548}
549
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550
551DWARFDebugRanges*
552SymbolFileDWARF::DebugRanges()
553{
554 if (m_ranges.get() == NULL)
555 {
556 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
557 if (get_debug_ranges_data().GetByteSize() > 0)
558 {
559 m_ranges.reset(new DWARFDebugRanges());
560 if (m_ranges.get())
561 m_ranges->Extract(this);
562 }
563 }
564 return m_ranges.get();
565}
566
567const DWARFDebugRanges*
568SymbolFileDWARF::DebugRanges() const
569{
570 return m_ranges.get();
571}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572
573bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000574SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575{
Greg Clayton96d7d742010-11-10 23:42:09 +0000576 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000578 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579 if (cu_die)
580 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000581 const char * cu_die_name = cu_die->GetName(this, curr_cu);
582 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000583 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584 if (cu_die_name)
585 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000586 FileSpec cu_file_spec;
587
Greg Clayton7bd65b92011-02-09 23:39:34 +0000588 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000590 // If we have a full path to the compile unit, we don't need to resolve
591 // the file. This can be expensive e.g. when the source files are NFS mounted.
592 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593 }
594 else
595 {
596 std::string fullpath(cu_comp_dir);
597 if (*fullpath.rbegin() != '/')
598 fullpath += '/';
599 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000600 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 }
602
Jim Ingham0f35ac22011-08-24 23:34:20 +0000603 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), curr_cu, cu_file_spec, curr_cu->GetOffset(), cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604 if (compile_unit_sp.get())
605 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000606 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 return true;
608 }
609 }
610 }
611 }
612 return false;
613}
614
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615uint32_t
616SymbolFileDWARF::GetNumCompileUnits()
617{
618 DWARFDebugInfo* info = DebugInfo();
619 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 return 0;
622}
623
624CompUnitSP
625SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
626{
627 CompUnitSP comp_unit;
628 DWARFDebugInfo* info = DebugInfo();
629 if (info)
630 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000631 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
632 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 {
634 // Our symbol vendor shouldn't be asking us to add a compile unit that
635 // has already been added to it, which this DWARF plug-in knows as it
636 // stores the lldb compile unit (CompileUnit) pointer in each
637 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000638 assert(curr_cu->GetUserData() == NULL);
639 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 }
641 }
642 return comp_unit;
643}
644
645static void
646AddRangesToBlock
647(
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000648 Block& block,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 DWARFDebugRanges::RangeList& ranges,
650 addr_t block_base_addr
651)
652{
653 ranges.SubtractOffset (block_base_addr);
654 size_t range_idx = 0;
655 const DWARFDebugRanges::Range *debug_range;
656 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
657 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000658 block.AddRange(debug_range->begin_offset, debug_range->end_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659 }
660}
661
662
663Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000664SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665{
666 DWARFDebugRanges::RangeList func_ranges;
667 const char *name = NULL;
668 const char *mangled = NULL;
669 int decl_file = 0;
670 int decl_line = 0;
671 int decl_column = 0;
672 int call_file = 0;
673 int call_line = 0;
674 int call_column = 0;
675 DWARFExpression frame_base;
676
Greg Claytonc93237c2010-10-01 20:48:32 +0000677 assert (die->Tag() == DW_TAG_subprogram);
678
679 if (die->Tag() != DW_TAG_subprogram)
680 return NULL;
681
Greg Clayton5113dc82011-08-12 06:47:54 +0000682 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
683 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
Greg Claytonc93237c2010-10-01 20:48:32 +0000684
Greg Clayton5113dc82011-08-12 06:47:54 +0000685 switch (containing_decl_kind)
686 {
687 case clang::Decl::Record:
688 case clang::Decl::CXXRecord:
689 case clang::Decl::ObjCClass:
690 case clang::Decl::ObjCImplementation:
691 case clang::Decl::ObjCInterface:
692 // We have methods of a class or struct
693 {
694 const DWARFDebugInfoEntry *containing_decl_die = m_decl_ctx_to_die[containing_decl_ctx];
695 assert (containing_decl_die);
696 Type *class_type = ResolveType (dwarf_cu, containing_decl_die);
697 if (class_type)
698 class_type->GetClangFullType();
699 // Make sure the class definition contains the funciton DIE
700 // we wanted to parse. If it does, we are done. Else, we need
701 // to fall through and parse the function DIE stil...
702 if (containing_decl_die->Contains (die))
703 break; // DIE has been parsed, we are done
704 }
705 // Fall through...
706
707 default:
708 // Parse the function prototype as a type that can then be added to concrete function instance
709 ParseTypes (sc, dwarf_cu, die, false, false);
710 break;
Greg Claytonc93237c2010-10-01 20:48:32 +0000711 }
712
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 //FixupTypes();
714
715 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
716 {
717 // Union of all ranges in the function DIE (if the function is discontiguous)
718 AddressRange func_range;
719 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
720 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
721 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
722 {
723 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
724 if (func_range.GetBaseAddress().IsValid())
725 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
726 }
727
728 if (func_range.GetBaseAddress().IsValid())
729 {
730 Mangled func_name;
731 if (mangled)
732 func_name.SetValue(mangled, true);
733 else if (name)
734 func_name.SetValue(name, false);
735
736 FunctionSP func_sp;
737 std::auto_ptr<Declaration> decl_ap;
738 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000739 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
740 decl_line,
741 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742
Greg Clayton594e5ed2010-09-27 21:07:38 +0000743 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744
745 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
746
747 func_range.GetBaseAddress().ResolveLinkedAddress();
748
749 func_sp.reset(new Function (sc.comp_unit,
750 die->GetOffset(), // UserID is the DIE offset
751 die->GetOffset(),
752 func_name,
753 func_type,
754 func_range)); // first address range
755
756 if (func_sp.get() != NULL)
757 {
758 func_sp->GetFrameBaseExpression() = frame_base;
759 sc.comp_unit->AddFunction(func_sp);
760 return func_sp.get();
761 }
762 }
763 }
764 return NULL;
765}
766
767size_t
768SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
769{
770 assert (sc.comp_unit);
771 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000772 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 if (dwarf_cu)
774 {
775 DWARFDIECollection function_dies;
776 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
777 size_t func_idx;
778 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
779 {
780 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
781 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
782 {
783 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
784 ++functions_added;
785 }
786 }
787 //FixupTypes();
788 }
789 return functions_added;
790}
791
792bool
793SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
794{
795 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000796 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
797 assert (curr_cu);
798 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799
800 if (cu_die)
801 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000802 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
803 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 +0000804
805 // All file indexes in DWARF are one based and a file of index zero is
806 // supposed to be the compile unit itself.
807 support_files.Append (*sc.comp_unit);
808
809 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
810 }
811 return false;
812}
813
814struct ParseDWARFLineTableCallbackInfo
815{
816 LineTable* line_table;
817 const SectionList *section_list;
818 lldb::addr_t prev_sect_file_base_addr;
819 lldb::addr_t curr_sect_file_base_addr;
820 bool is_oso_for_debug_map;
821 bool prev_in_final_executable;
822 DWARFDebugLine::Row prev_row;
823 SectionSP prev_section_sp;
824 SectionSP curr_section_sp;
825};
826
827//----------------------------------------------------------------------
828// ParseStatementTableCallback
829//----------------------------------------------------------------------
830static void
831ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
832{
833 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
834 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
835 {
836 // Just started parsing the line table
837 }
838 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
839 {
840 // Done parsing line table, nothing to do for the cleanup
841 }
842 else
843 {
844 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
845 // We have a new row, lets append it
846
847 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
848 {
849 info->prev_section_sp = info->curr_section_sp;
850 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
851 // If this is an end sequence entry, then we subtract one from the
852 // address to make sure we get an address that is not the end of
853 // a section.
854 if (state.end_sequence && state.address != 0)
855 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
856 else
857 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
858
859 if (info->curr_section_sp.get())
860 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
861 else
862 info->curr_sect_file_base_addr = 0;
863 }
864 if (info->curr_section_sp.get())
865 {
866 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
867 // Check for the fancy section magic to determine if we
868
869 if (info->is_oso_for_debug_map)
870 {
871 // When this is a debug map object file that contains DWARF
872 // (referenced from an N_OSO debug map nlist entry) we will have
873 // a file address in the file range for our section from the
874 // original .o file, and a load address in the executable that
875 // contains the debug map.
876 //
877 // If the sections for the file range and load range are
878 // different, we have a remapped section for the function and
879 // this address is resolved. If they are the same, then the
880 // function for this address didn't make it into the final
881 // executable.
882 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
883
884 // If we are doing DWARF with debug map, then we need to carefully
885 // add each line table entry as there may be gaps as functions
886 // get moved around or removed.
887 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
888 {
889 if (info->prev_in_final_executable)
890 {
891 bool terminate_previous_entry = false;
892 if (!curr_in_final_executable)
893 {
894 // Check for the case where the previous line entry
895 // in a function made it into the final executable,
896 // yet the current line entry falls in a function
897 // that didn't. The line table used to be contiguous
898 // through this address range but now it isn't. We
899 // need to terminate the previous line entry so
900 // that we can reconstruct the line range correctly
901 // for it and to keep the line table correct.
902 terminate_previous_entry = true;
903 }
904 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
905 {
906 // Check for cases where the line entries used to be
907 // contiguous address ranges, but now they aren't.
908 // This can happen when order files specify the
909 // ordering of the functions.
910 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
911 Section *curr_sect = info->curr_section_sp.get();
912 Section *prev_sect = info->prev_section_sp.get();
913 assert (curr_sect->GetLinkedSection());
914 assert (prev_sect->GetLinkedSection());
915 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
916 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
917 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
918 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
919 if (object_file_addr_delta != linked_file_addr_delta)
920 terminate_previous_entry = true;
921 }
922
923 if (terminate_previous_entry)
924 {
925 line_table->InsertLineEntry (info->prev_section_sp,
926 state.address - info->prev_sect_file_base_addr,
927 info->prev_row.line,
928 info->prev_row.column,
929 info->prev_row.file,
930 false, // is_stmt
931 false, // basic_block
932 false, // state.prologue_end
933 false, // state.epilogue_begin
934 true); // end_sequence);
935 }
936 }
937 }
938
939 if (curr_in_final_executable)
940 {
941 line_table->InsertLineEntry (info->curr_section_sp,
942 curr_line_section_offset,
943 state.line,
944 state.column,
945 state.file,
946 state.is_stmt,
947 state.basic_block,
948 state.prologue_end,
949 state.epilogue_begin,
950 state.end_sequence);
951 info->prev_section_sp = info->curr_section_sp;
952 }
953 else
954 {
955 // If the current address didn't make it into the final
956 // executable, the current section will be the __text
957 // segment in the .o file, so we need to clear this so
958 // we can catch the next function that did make it into
959 // the final executable.
960 info->prev_section_sp.reset();
961 info->curr_section_sp.reset();
962 }
963
964 info->prev_in_final_executable = curr_in_final_executable;
965 }
966 else
967 {
968 // We are not in an object file that contains DWARF for an
969 // N_OSO, this is just a normal DWARF file. The DWARF spec
970 // guarantees that the addresses will be in increasing order
971 // so, since we store line tables in file address order, we
972 // can always just append the line entry without needing to
973 // search for the correct insertion point (we don't need to
974 // use LineEntry::InsertLineEntry()).
975 line_table->AppendLineEntry (info->curr_section_sp,
976 curr_line_section_offset,
977 state.line,
978 state.column,
979 state.file,
980 state.is_stmt,
981 state.basic_block,
982 state.prologue_end,
983 state.epilogue_begin,
984 state.end_sequence);
985 }
986 }
987
988 info->prev_row = state;
989 }
990}
991
992bool
993SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
994{
995 assert (sc.comp_unit);
996 if (sc.comp_unit->GetLineTable() != NULL)
997 return true;
998
999 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1000 if (dwarf_cu)
1001 {
1002 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1003 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1004 if (cu_line_offset != DW_INVALID_OFFSET)
1005 {
1006 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1007 if (line_table_ap.get())
1008 {
Greg Clayton450e3f32010-10-12 02:24:53 +00001009 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 +00001010 uint32_t offset = cu_line_offset;
1011 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1012 sc.comp_unit->SetLineTable(line_table_ap.release());
1013 return true;
1014 }
1015 }
1016 }
1017 return false;
1018}
1019
1020size_t
1021SymbolFileDWARF::ParseFunctionBlocks
1022(
1023 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001024 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001025 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 const DWARFDebugInfoEntry *die,
1027 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001028 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001029)
1030{
1031 size_t blocks_added = 0;
1032 while (die != NULL)
1033 {
1034 dw_tag_t tag = die->Tag();
1035
1036 switch (tag)
1037 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001039 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040 case DW_TAG_lexical_block:
1041 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001042 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001043 if (tag == DW_TAG_subprogram)
1044 {
1045 // Skip any DW_TAG_subprogram DIEs that are inside
1046 // of a normal or inlined functions. These will be
1047 // parsed on their own as separate entities.
1048
1049 if (depth > 0)
1050 break;
1051
1052 block = parent_block;
1053 }
1054 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001055 {
1056 BlockSP block_sp(new Block (die->GetOffset()));
1057 parent_block->AddChild(block_sp);
1058 block = block_sp.get();
1059 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001060 DWARFDebugRanges::RangeList ranges;
1061 const char *name = NULL;
1062 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064 int decl_file = 0;
1065 int decl_line = 0;
1066 int decl_column = 0;
1067 int call_file = 0;
1068 int call_line = 0;
1069 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001070 if (die->GetDIENamesAndRanges (this,
1071 dwarf_cu,
1072 name,
1073 mangled_name,
1074 ranges,
1075 decl_file, decl_line, decl_column,
1076 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077 {
1078 if (tag == DW_TAG_subprogram)
1079 {
1080 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1081 subprogram_low_pc = ranges.LowestAddress(0);
1082 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001083 else if (tag == DW_TAG_inlined_subroutine)
1084 {
1085 // We get called here for inlined subroutines in two ways.
1086 // The first time is when we are making the Function object
1087 // for this inlined concrete instance. Since we're creating a top level block at
1088 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1089 // adjust the containing address.
1090 // The second time is when we are parsing the blocks inside the function that contains
1091 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1092 // function the offset will be for that function.
1093 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1094 {
1095 subprogram_low_pc = ranges.LowestAddress(0);
1096 }
1097 }
1098
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001099 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100
1101 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1102 {
1103 std::auto_ptr<Declaration> decl_ap;
1104 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001105 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1106 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107
1108 std::auto_ptr<Declaration> call_ap;
1109 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001110 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1111 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001113 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001114 }
1115
1116 ++blocks_added;
1117
Greg Claytondd7feaf2011-08-12 17:54:33 +00001118 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001120 blocks_added += ParseFunctionBlocks (sc,
1121 block,
1122 dwarf_cu,
1123 die->GetFirstChild(),
1124 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001125 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126 }
1127 }
1128 }
1129 break;
1130 default:
1131 break;
1132 }
1133
Greg Claytondd7feaf2011-08-12 17:54:33 +00001134 // Only parse siblings of the block if we are not at depth zero. A depth
1135 // of zero indicates we are currently parsing the top level
1136 // DW_TAG_subprogram DIE
1137
1138 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001140 else
1141 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 }
1143 return blocks_added;
1144}
1145
1146size_t
1147SymbolFileDWARF::ParseChildMembers
1148(
1149 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001150 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001152 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001153 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1155 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001156 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001157 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158 bool &is_a_class
1159)
1160{
1161 if (parent_die == NULL)
1162 return 0;
1163
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164 size_t count = 0;
1165 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001166 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001167 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001168
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1170 {
1171 dw_tag_t tag = die->Tag();
1172
1173 switch (tag)
1174 {
1175 case DW_TAG_member:
1176 {
1177 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001178 const size_t num_attributes = die->GetAttributes (this,
1179 dwarf_cu,
1180 fixed_form_sizes,
1181 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 if (num_attributes > 0)
1183 {
1184 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001185 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001187 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001189 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001190 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191 size_t byte_size = 0;
1192 size_t bit_offset = 0;
1193 size_t bit_size = 0;
1194 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001195 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 {
1197 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1198 DWARFFormValue form_value;
1199 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1200 {
1201 switch (attr)
1202 {
1203 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1204 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1205 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1206 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1207 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1208 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1209 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1210 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1211 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001212// if (form_value.BlockData())
1213// {
1214// Value initialValue(0);
1215// Value memberOffset(0);
1216// const DataExtractor& debug_info_data = get_debug_info_data();
1217// uint32_t block_length = form_value.Unsigned();
1218// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1219// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1220// {
1221// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1222// }
1223// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 break;
1225
Greg Clayton8cf05932010-07-22 18:30:50 +00001226 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001227 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 case DW_AT_declaration:
1229 case DW_AT_description:
1230 case DW_AT_mutable:
1231 case DW_AT_visibility:
1232 default:
1233 case DW_AT_sibling:
1234 break;
1235 }
1236 }
1237 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001238
1239 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1240
1241 if (class_language == eLanguageTypeObjC ||
1242 class_language == eLanguageTypeObjC_plus_plus)
1243 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001244
1245 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1246 {
1247 // Not all compilers will mark the vtable pointer
1248 // member as artificial (llvm-gcc). We can't have
1249 // the virtual members in our classes otherwise it
1250 // throws off all child offsets since we end up
1251 // having and extra pointer sized member in our
1252 // class layouts.
1253 is_artificial = true;
1254 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255
Greg Clayton24739922010-10-13 03:15:28 +00001256 if (is_artificial == false)
1257 {
1258 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001259 if (member_type)
1260 {
1261 if (accessibility == eAccessNone)
1262 accessibility = default_accessibility;
1263 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264
Greg Claytond16e1e52011-07-12 17:06:17 +00001265 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1266 name,
1267 member_type->GetClangLayoutType(),
1268 accessibility,
1269 bit_size);
1270 }
1271 else
1272 {
1273 if (name)
1274 ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed",
1275 die->GetOffset(),
1276 name,
1277 encoding_uid);
1278 else
1279 ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed",
1280 die->GetOffset(),
1281 encoding_uid);
1282 }
Greg Clayton24739922010-10-13 03:15:28 +00001283 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001285 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286 }
1287 break;
1288
1289 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001290 // Let the type parsing code handle this one for us.
1291 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001292 break;
1293
1294 case DW_TAG_inheritance:
1295 {
1296 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001297 if (default_accessibility == eAccessNone)
1298 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299 // TODO: implement DW_TAG_inheritance type parsing
1300 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001301 const size_t num_attributes = die->GetAttributes (this,
1302 dwarf_cu,
1303 fixed_form_sizes,
1304 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001305 if (num_attributes > 0)
1306 {
1307 Declaration decl;
1308 DWARFExpression location;
1309 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001310 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311 bool is_virtual = false;
1312 bool is_base_of_class = true;
1313 off_t member_offset = 0;
1314 uint32_t i;
1315 for (i=0; i<num_attributes; ++i)
1316 {
1317 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1318 DWARFFormValue form_value;
1319 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1320 {
1321 switch (attr)
1322 {
1323 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1324 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1325 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1326 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1327 case DW_AT_data_member_location:
1328 if (form_value.BlockData())
1329 {
1330 Value initialValue(0);
1331 Value memberOffset(0);
1332 const DataExtractor& debug_info_data = get_debug_info_data();
1333 uint32_t block_length = form_value.Unsigned();
1334 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001335 if (DWARFExpression::Evaluate (NULL,
1336 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001337 NULL,
1338 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001339 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001340 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001341 block_offset,
1342 block_length,
1343 eRegisterKindDWARF,
1344 &initialValue,
1345 memberOffset,
1346 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001347 {
1348 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1349 }
1350 }
1351 break;
1352
1353 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001354 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 break;
1356
1357 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1358 default:
1359 case DW_AT_sibling:
1360 break;
1361 }
1362 }
1363 }
1364
Greg Clayton526e5af2010-11-13 03:52:47 +00001365 Type *base_class_type = ResolveTypeUID(encoding_uid);
1366 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001367
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001368 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1369 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001370 if (class_language == eLanguageTypeObjC)
1371 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001372 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001373 }
1374 else
1375 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001376 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001377 accessibility,
1378 is_virtual,
1379 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001380 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001381 }
1382 }
1383 break;
1384
1385 default:
1386 break;
1387 }
1388 }
1389 return count;
1390}
1391
1392
1393clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001394SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001395{
1396 DWARFDebugInfo* debug_info = DebugInfo();
1397 if (debug_info)
1398 {
1399 DWARFCompileUnitSP cu_sp;
1400 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1401 if (die)
Sean Callanan72e49402011-08-05 23:43:37 +00001402 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
1403 }
1404 return NULL;
1405}
1406
1407clang::DeclContext*
1408SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1409{
1410 DWARFDebugInfo* debug_info = DebugInfo();
1411 if (debug_info)
1412 {
1413 DWARFCompileUnitSP cu_sp;
1414 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1415 if (die)
1416 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417 }
1418 return NULL;
1419}
1420
1421Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001422SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423{
1424 DWARFDebugInfo* debug_info = DebugInfo();
1425 if (debug_info)
1426 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001427 DWARFCompileUnitSP cu_sp;
1428 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001430 {
1431 // We might be coming in in the middle of a type tree (a class
1432 // withing a class, an enum within a class), so parse any needed
1433 // parent DIEs before we get to this one...
1434 const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
1435 switch (parent_die->Tag())
1436 {
1437 case DW_TAG_structure_type:
1438 case DW_TAG_union_type:
1439 case DW_TAG_class_type:
1440 ResolveType(cu_sp.get(), parent_die);
1441 break;
1442 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00001443 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001444 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 }
1446 return NULL;
1447}
1448
Greg Clayton6beaaa62011-01-17 03:46:26 +00001449// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1450// SymbolFileDWARF objects to detect if this DWARF file is the one that
1451// can resolve a clang_type.
1452bool
1453SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1454{
1455 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1456 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1457 return die != NULL;
1458}
1459
1460
Greg Clayton1be10fc2010-09-29 01:12:09 +00001461lldb::clang_type_t
1462SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1463{
1464 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001465 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1466 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001467 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001468 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001469// if (m_debug_map_symfile)
1470// {
1471// Type *type = m_die_to_type[die];
1472// if (type && type->GetSymbolFile() != this)
1473// return type->GetClangType();
1474// }
Greg Clayton73b472d2010-10-27 03:32:59 +00001475 // We have already resolved this type...
1476 return clang_type;
1477 }
1478 // Once we start resolving this type, remove it from the forward declaration
1479 // map in case anyone child members or other types require this type to get resolved.
1480 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1481 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001482 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001483
Greg Clayton1be10fc2010-09-29 01:12:09 +00001484
Greg Clayton450e3f32010-10-12 02:24:53 +00001485 DWARFDebugInfo* debug_info = DebugInfo();
1486
Greg Clayton96d7d742010-11-10 23:42:09 +00001487 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001488 Type *type = m_die_to_type.lookup (die);
1489
1490 const dw_tag_t tag = die->Tag();
1491
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001492 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1493 die->GetOffset(),
1494 DW_TAG_value_to_name(tag),
1495 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001496 assert (clang_type);
1497 DWARFDebugInfoEntry::Attributes attributes;
1498
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001499 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001500
1501 switch (tag)
1502 {
1503 case DW_TAG_structure_type:
1504 case DW_TAG_union_type:
1505 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001506 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001507 if (die->HasChildren())
1508 {
1509 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001510 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1511 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001512 class_language = eLanguageTypeObjC;
1513
1514 int tag_decl_kind = -1;
1515 AccessType default_accessibility = eAccessNone;
1516 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001517 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001518 tag_decl_kind = clang::TTK_Struct;
1519 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001520 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001521 else if (tag == DW_TAG_union_type)
1522 {
1523 tag_decl_kind = clang::TTK_Union;
1524 default_accessibility = eAccessPublic;
1525 }
1526 else if (tag == DW_TAG_class_type)
1527 {
1528 tag_decl_kind = clang::TTK_Class;
1529 default_accessibility = eAccessPrivate;
1530 }
1531
Greg Clayton96d7d742010-11-10 23:42:09 +00001532 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001533 std::vector<clang::CXXBaseSpecifier *> base_classes;
1534 std::vector<int> member_accessibilities;
1535 bool is_a_class = false;
1536 // Parse members and base classes first
1537 DWARFDIECollection member_function_dies;
1538
1539 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001540 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001541 die,
1542 clang_type,
1543 class_language,
1544 base_classes,
1545 member_accessibilities,
1546 member_function_dies,
1547 default_accessibility,
1548 is_a_class);
1549
1550 // Now parse any methods if there were any...
1551 size_t num_functions = member_function_dies.Size();
1552 if (num_functions > 0)
1553 {
1554 for (size_t i=0; i<num_functions; ++i)
1555 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001556 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001557 }
1558 }
1559
Greg Clayton450e3f32010-10-12 02:24:53 +00001560 if (class_language == eLanguageTypeObjC)
1561 {
Greg Claytone3055942011-06-30 02:28:26 +00001562 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001563 if (!class_str.empty())
1564 {
1565
1566 ConstString class_name (class_str.c_str());
1567 std::vector<NameToDIE::Info> method_die_infos;
1568 if (m_objc_class_selectors_index.Find (class_name, method_die_infos))
1569 {
1570 DWARFCompileUnit* method_cu = NULL;
1571 DWARFCompileUnit* prev_method_cu = NULL;
1572 const size_t num_objc_methods = method_die_infos.size();
1573 for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu)
1574 {
1575 method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx);
1576
1577 if (method_cu != prev_method_cu)
1578 method_cu->ExtractDIEsIfNeeded (false);
1579
1580 DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx);
1581
1582 ResolveType (method_cu, method_die);
1583 }
1584 }
1585 }
1586 }
1587
Greg Claytonc93237c2010-10-01 20:48:32 +00001588 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1589 // need to tell the clang type it is actually a class.
1590 if (class_language != eLanguageTypeObjC)
1591 {
1592 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001593 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001594 }
1595
1596 // Since DW_TAG_structure_type gets used for both classes
1597 // and structures, we may need to set any DW_TAG_member
1598 // fields to have a "private" access if none was specified.
1599 // When we parsed the child members we tracked that actual
1600 // accessibility value for each DW_TAG_member in the
1601 // "member_accessibilities" array. If the value for the
1602 // member is zero, then it was set to the "default_accessibility"
1603 // which for structs was "public". Below we correct this
1604 // by setting any fields to "private" that weren't correctly
1605 // set.
1606 if (is_a_class && !member_accessibilities.empty())
1607 {
1608 // This is a class and all members that didn't have
1609 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001610 ast.SetDefaultAccessForRecordFields (clang_type,
1611 eAccessPrivate,
1612 &member_accessibilities.front(),
1613 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001614 }
1615
1616 if (!base_classes.empty())
1617 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001618 ast.SetBaseClassesForClassType (clang_type,
1619 &base_classes.front(),
1620 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001621
1622 // Clang will copy each CXXBaseSpecifier in "base_classes"
1623 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001624 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1625 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001626 }
1627
1628 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001629 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001630 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001631
1632 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001633 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001634 if (die->HasChildren())
1635 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001636 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1637 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001638 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001639 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001640 return clang_type;
1641
1642 default:
1643 assert(false && "not a forward clang type decl!");
1644 break;
1645 }
1646 return NULL;
1647}
1648
Greg Claytonc685f8e2010-09-15 04:15:46 +00001649Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001650SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001651{
1652 if (type_die != NULL)
1653 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001654 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001655 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001656 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001657 if (assert_not_being_parsed)
1658 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001659 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001660 }
1661 return NULL;
1662}
1663
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001665SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666{
1667 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001668 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001669 {
1670 // The symbol vendor doesn't know about this compile unit, we
1671 // need to parse and add it to the symbol vendor object.
1672 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001673 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001674 if (dc_cu.get())
1675 {
1676 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001677 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001678 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679
1680 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001681
1682 if (m_debug_map_symfile)
1683 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001684 }
1685 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001686 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001687}
1688
1689bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001690SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001691{
1692 sc.Clear();
1693 // Check if the symbol vendor already knows about this compile unit?
1694 sc.module_sp = m_obj_file->GetModule()->GetSP();
Greg Clayton96d7d742010-11-10 23:42:09 +00001695 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001696
1697 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1698 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001699 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700
1701 return sc.function != NULL;
1702}
1703
1704uint32_t
1705SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1706{
1707 Timer scoped_timer(__PRETTY_FUNCTION__,
1708 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1709 so_addr.GetSection(),
1710 so_addr.GetOffset(),
1711 resolve_scope);
1712 uint32_t resolved = 0;
1713 if (resolve_scope & ( eSymbolContextCompUnit |
1714 eSymbolContextFunction |
1715 eSymbolContextBlock |
1716 eSymbolContextLineEntry))
1717 {
1718 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1719
1720 DWARFDebugAranges* debug_aranges = DebugAranges();
1721 DWARFDebugInfo* debug_info = DebugInfo();
1722 if (debug_aranges)
1723 {
1724 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1725 if (cu_offset != DW_INVALID_OFFSET)
1726 {
1727 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001728 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1729 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001731 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732 assert(sc.comp_unit != NULL);
1733 resolved |= eSymbolContextCompUnit;
1734
1735 if (resolve_scope & eSymbolContextLineEntry)
1736 {
1737 LineTable *line_table = sc.comp_unit->GetLineTable();
1738 if (line_table == NULL)
1739 {
1740 if (ParseCompileUnitLineTable(sc))
1741 line_table = sc.comp_unit->GetLineTable();
1742 }
1743 if (line_table != NULL)
1744 {
1745 if (so_addr.IsLinkedAddress())
1746 {
1747 Address linked_addr (so_addr);
1748 linked_addr.ResolveLinkedAddress();
1749 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1750 {
1751 resolved |= eSymbolContextLineEntry;
1752 }
1753 }
1754 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1755 {
1756 resolved |= eSymbolContextLineEntry;
1757 }
1758 }
1759 }
1760
1761 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1762 {
1763 DWARFDebugInfoEntry *function_die = NULL;
1764 DWARFDebugInfoEntry *block_die = NULL;
1765 if (resolve_scope & eSymbolContextBlock)
1766 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001767 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001768 }
1769 else
1770 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001771 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772 }
1773
1774 if (function_die != NULL)
1775 {
1776 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1777 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001778 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001779 }
1780
1781 if (sc.function != NULL)
1782 {
1783 resolved |= eSymbolContextFunction;
1784
1785 if (resolve_scope & eSymbolContextBlock)
1786 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001787 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001788
1789 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001790 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001792 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001793 if (sc.block)
1794 resolved |= eSymbolContextBlock;
1795 }
1796 }
1797 }
1798 }
1799 }
1800 }
1801 }
1802 return resolved;
1803}
1804
1805
1806
1807uint32_t
1808SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1809{
1810 const uint32_t prev_size = sc_list.GetSize();
1811 if (resolve_scope & eSymbolContextCompUnit)
1812 {
1813 DWARFDebugInfo* debug_info = DebugInfo();
1814 if (debug_info)
1815 {
1816 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001817 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818
Greg Clayton96d7d742010-11-10 23:42:09 +00001819 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001821 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001822 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1823 if (check_inlines || file_spec_matches_cu_file_spec)
1824 {
1825 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001826 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001827 assert(sc.comp_unit != NULL);
1828
1829 uint32_t file_idx = UINT32_MAX;
1830
1831 // If we are looking for inline functions only and we don't
1832 // find it in the support files, we are done.
1833 if (check_inlines)
1834 {
1835 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1836 if (file_idx == UINT32_MAX)
1837 continue;
1838 }
1839
1840 if (line != 0)
1841 {
1842 LineTable *line_table = sc.comp_unit->GetLineTable();
1843
1844 if (line_table != NULL && line != 0)
1845 {
1846 // We will have already looked up the file index if
1847 // we are searching for inline entries.
1848 if (!check_inlines)
1849 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1850
1851 if (file_idx != UINT32_MAX)
1852 {
1853 uint32_t found_line;
1854 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1855 found_line = sc.line_entry.line;
1856
Greg Clayton016a95e2010-09-14 02:20:48 +00001857 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858 {
1859 sc.function = NULL;
1860 sc.block = NULL;
1861 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1862 {
1863 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1864 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1865 {
1866 DWARFDebugInfoEntry *function_die = NULL;
1867 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001868 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869
1870 if (function_die != NULL)
1871 {
1872 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1873 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001874 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 }
1876
1877 if (sc.function != NULL)
1878 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001879 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880
1881 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001882 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001884 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885 }
1886 }
1887 }
1888
1889 sc_list.Append(sc);
1890 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1891 }
1892 }
1893 }
1894 else if (file_spec_matches_cu_file_spec && !check_inlines)
1895 {
1896 // only append the context if we aren't looking for inline call sites
1897 // by file and line and if the file spec matches that of the compile unit
1898 sc_list.Append(sc);
1899 }
1900 }
1901 else if (file_spec_matches_cu_file_spec && !check_inlines)
1902 {
1903 // only append the context if we aren't looking for inline call sites
1904 // by file and line and if the file spec matches that of the compile unit
1905 sc_list.Append(sc);
1906 }
1907
1908 if (!check_inlines)
1909 break;
1910 }
1911 }
1912 }
1913 }
1914 return sc_list.GetSize() - prev_size;
1915}
1916
1917void
1918SymbolFileDWARF::Index ()
1919{
1920 if (m_indexed)
1921 return;
1922 m_indexed = true;
1923 Timer scoped_timer (__PRETTY_FUNCTION__,
1924 "SymbolFileDWARF::Index (%s)",
1925 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1926
1927 DWARFDebugInfo* debug_info = DebugInfo();
1928 if (debug_info)
1929 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001930 m_aranges.reset(new DWARFDebugAranges());
1931
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932 uint32_t cu_idx = 0;
1933 const uint32_t num_compile_units = GetNumCompileUnits();
1934 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1935 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001936 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937
Greg Clayton96d7d742010-11-10 23:42:09 +00001938 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001939
Greg Clayton96d7d742010-11-10 23:42:09 +00001940 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001941 m_function_basename_index,
1942 m_function_fullname_index,
1943 m_function_method_index,
1944 m_function_selector_index,
1945 m_objc_class_selectors_index,
1946 m_global_index,
1947 m_type_index,
1948 m_namespace_index,
1949 DebugRanges(),
1950 m_aranges.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001951
1952 // Keep memory down by clearing DIEs if this generate function
1953 // caused them to be parsed
1954 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001955 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956 }
1957
Greg Clayton016a95e2010-09-14 02:20:48 +00001958 m_aranges->Sort();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001959
Greg Clayton24739922010-10-13 03:15:28 +00001960#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00001961 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00001962 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00001963 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1964 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001965 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1966 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1967 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1968 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1969 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1970 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001971 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001972 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001973#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001974 }
1975}
1976
1977uint32_t
1978SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1979{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001980 DWARFDebugInfo* info = DebugInfo();
1981 if (info == NULL)
1982 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001983
1984 // If we aren't appending the results to this list, then clear the list
1985 if (!append)
1986 variables.Clear();
1987
1988 // Remember how many variables are in the list before we search in case
1989 // we are appending the results to a variable list.
1990 const uint32_t original_size = variables.GetSize();
1991
1992 // Index the DWARF if we haven't already
1993 if (!m_indexed)
1994 Index ();
1995
Greg Claytonc685f8e2010-09-15 04:15:46 +00001996 SymbolContext sc;
1997 sc.module_sp = m_obj_file->GetModule()->GetSP();
1998 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999
Greg Clayton96d7d742010-11-10 23:42:09 +00002000 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002001 DWARFCompileUnit* prev_cu = NULL;
2002 const DWARFDebugInfoEntry* die = NULL;
2003 std::vector<NameToDIE::Info> die_info_array;
2004 const size_t num_matches = m_global_index.Find(name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002005 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002006 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002007 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002008
Greg Clayton96d7d742010-11-10 23:42:09 +00002009 if (curr_cu != prev_cu)
2010 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011
Greg Clayton96d7d742010-11-10 23:42:09 +00002012 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002013
Greg Clayton96d7d742010-11-10 23:42:09 +00002014 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002015 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016
Greg Clayton96d7d742010-11-10 23:42:09 +00002017 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002018
2019 if (variables.GetSize() - original_size >= max_matches)
2020 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021 }
2022
2023 // Return the number of variable that were appended to the list
2024 return variables.GetSize() - original_size;
2025}
2026
2027uint32_t
2028SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2029{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002030 DWARFDebugInfo* info = DebugInfo();
2031 if (info == NULL)
2032 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002033
2034 // If we aren't appending the results to this list, then clear the list
2035 if (!append)
2036 variables.Clear();
2037
2038 // Remember how many variables are in the list before we search in case
2039 // we are appending the results to a variable list.
2040 const uint32_t original_size = variables.GetSize();
2041
2042 // Index the DWARF if we haven't already
2043 if (!m_indexed)
2044 Index ();
2045
Greg Claytonc685f8e2010-09-15 04:15:46 +00002046 SymbolContext sc;
2047 sc.module_sp = m_obj_file->GetModule()->GetSP();
2048 assert (sc.module_sp);
2049
Greg Clayton96d7d742010-11-10 23:42:09 +00002050 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002051 DWARFCompileUnit* prev_cu = NULL;
2052 const DWARFDebugInfoEntry* die = NULL;
2053 std::vector<NameToDIE::Info> die_info_array;
2054 const size_t num_matches = m_global_index.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002055 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002056 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002057 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002058
Greg Clayton96d7d742010-11-10 23:42:09 +00002059 if (curr_cu != prev_cu)
2060 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002061
Greg Clayton96d7d742010-11-10 23:42:09 +00002062 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002063
Greg Clayton96d7d742010-11-10 23:42:09 +00002064 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002065 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066
Greg Clayton96d7d742010-11-10 23:42:09 +00002067 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068
Greg Claytonc685f8e2010-09-15 04:15:46 +00002069 if (variables.GetSize() - original_size >= max_matches)
2070 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071 }
2072
2073 // Return the number of variable that were appended to the list
2074 return variables.GetSize() - original_size;
2075}
2076
2077
Greg Clayton0c5cd902010-06-28 21:30:43 +00002078void
2079SymbolFileDWARF::FindFunctions
2080(
2081 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00002082 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00002083 SymbolContextList& sc_list
2084)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002085{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002086 DWARFDebugInfo* info = DebugInfo();
2087 if (info == NULL)
2088 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089
Greg Claytonc685f8e2010-09-15 04:15:46 +00002090 SymbolContext sc;
2091 sc.module_sp = m_obj_file->GetModule()->GetSP();
2092 assert (sc.module_sp);
2093
Greg Clayton96d7d742010-11-10 23:42:09 +00002094 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002095 DWARFCompileUnit* prev_cu = NULL;
2096 const DWARFDebugInfoEntry* die = NULL;
2097 std::vector<NameToDIE::Info> die_info_array;
Greg Claytond7e05462010-11-14 00:22:48 +00002098 const size_t num_matches = name_to_die.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002099 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002100 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002101 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002102
Greg Clayton96d7d742010-11-10 23:42:09 +00002103 if (curr_cu != prev_cu)
2104 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002105
Greg Clayton96d7d742010-11-10 23:42:09 +00002106 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytond7e05462010-11-14 00:22:48 +00002107
2108 const DWARFDebugInfoEntry* inlined_die = NULL;
2109 if (die->Tag() == DW_TAG_inlined_subroutine)
2110 {
2111 inlined_die = die;
2112
2113 while ((die = die->GetParent()) != NULL)
2114 {
2115 if (die->Tag() == DW_TAG_subprogram)
2116 break;
2117 }
2118 }
2119 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002120 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002121 {
Greg Claytond7e05462010-11-14 00:22:48 +00002122 Address addr;
2123 // Parse all blocks if needed
2124 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002125 {
Greg Claytond7e05462010-11-14 00:22:48 +00002126 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2127 assert (sc.block != NULL);
2128 if (sc.block->GetStartAddress (addr) == false)
2129 addr.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002130 }
Greg Claytond7e05462010-11-14 00:22:48 +00002131 else
2132 {
2133 sc.block = NULL;
2134 addr = sc.function->GetAddressRange().GetBaseAddress();
2135 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002136
Greg Claytond7e05462010-11-14 00:22:48 +00002137 if (addr.IsValid())
2138 {
2139
2140 // We found the function, so we should find the line table
2141 // and line table entry as well
2142 LineTable *line_table = sc.comp_unit->GetLineTable();
2143 if (line_table == NULL)
2144 {
2145 if (ParseCompileUnitLineTable(sc))
2146 line_table = sc.comp_unit->GetLineTable();
2147 }
2148 if (line_table != NULL)
2149 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2150
2151 sc_list.Append(sc);
2152 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002153 }
2154 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002155}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002156
Greg Claytonc685f8e2010-09-15 04:15:46 +00002157
2158void
2159SymbolFileDWARF::FindFunctions
2160(
2161 const RegularExpression &regex,
2162 const NameToDIE &name_to_die,
2163 SymbolContextList& sc_list
2164)
2165{
2166 DWARFDebugInfo* info = DebugInfo();
2167 if (info == NULL)
2168 return;
2169
2170 SymbolContext sc;
2171 sc.module_sp = m_obj_file->GetModule()->GetSP();
2172 assert (sc.module_sp);
2173
Greg Clayton96d7d742010-11-10 23:42:09 +00002174 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002175 DWARFCompileUnit* prev_cu = NULL;
2176 const DWARFDebugInfoEntry* die = NULL;
2177 std::vector<NameToDIE::Info> die_info_array;
2178 const size_t num_matches = name_to_die.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002179 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002180 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002181 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002182
Greg Clayton96d7d742010-11-10 23:42:09 +00002183 if (curr_cu != prev_cu)
2184 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002185
Greg Clayton96d7d742010-11-10 23:42:09 +00002186 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonab843392010-12-03 17:49:14 +00002187
2188 const DWARFDebugInfoEntry* inlined_die = NULL;
2189 if (die->Tag() == DW_TAG_inlined_subroutine)
2190 {
2191 inlined_die = die;
2192
2193 while ((die = die->GetParent()) != NULL)
2194 {
2195 if (die->Tag() == DW_TAG_subprogram)
2196 break;
2197 }
2198 }
2199 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00002200 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002201 {
Greg Claytonab843392010-12-03 17:49:14 +00002202 Address addr;
2203 // Parse all blocks if needed
2204 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002205 {
Greg Claytonab843392010-12-03 17:49:14 +00002206 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2207 assert (sc.block != NULL);
2208 if (sc.block->GetStartAddress (addr) == false)
2209 addr.Clear();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002210 }
Greg Claytonab843392010-12-03 17:49:14 +00002211 else
2212 {
2213 sc.block = NULL;
2214 addr = sc.function->GetAddressRange().GetBaseAddress();
2215 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002216
Greg Claytonab843392010-12-03 17:49:14 +00002217 if (addr.IsValid())
2218 {
2219
2220 // We found the function, so we should find the line table
2221 // and line table entry as well
2222 LineTable *line_table = sc.comp_unit->GetLineTable();
2223 if (line_table == NULL)
2224 {
2225 if (ParseCompileUnitLineTable(sc))
2226 line_table = sc.comp_unit->GetLineTable();
2227 }
2228 if (line_table != NULL)
2229 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2230
2231 sc_list.Append(sc);
2232 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002233 }
2234 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002235}
2236
2237uint32_t
2238SymbolFileDWARF::FindFunctions
2239(
2240 const ConstString &name,
2241 uint32_t name_type_mask,
2242 bool append,
2243 SymbolContextList& sc_list
2244)
2245{
2246 Timer scoped_timer (__PRETTY_FUNCTION__,
2247 "SymbolFileDWARF::FindFunctions (name = '%s')",
2248 name.AsCString());
2249
Greg Clayton0c5cd902010-06-28 21:30:43 +00002250 // If we aren't appending the results to this list, then clear the list
2251 if (!append)
2252 sc_list.Clear();
2253
2254 // Remember how many sc_list are in the list before we search in case
2255 // we are appending the results to a variable list.
2256 uint32_t original_size = sc_list.GetSize();
2257
2258 // Index the DWARF if we haven't already
2259 if (!m_indexed)
2260 Index ();
2261
2262 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002263 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002264
2265 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002266 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002267
2268 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002269 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002270
2271 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002272 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002273
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002274 // Return the number of variable that were appended to the list
2275 return sc_list.GetSize() - original_size;
2276}
2277
2278
2279uint32_t
2280SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2281{
2282 Timer scoped_timer (__PRETTY_FUNCTION__,
2283 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2284 regex.GetText());
2285
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002286 // If we aren't appending the results to this list, then clear the list
2287 if (!append)
2288 sc_list.Clear();
2289
2290 // Remember how many sc_list are in the list before we search in case
2291 // we are appending the results to a variable list.
2292 uint32_t original_size = sc_list.GetSize();
2293
2294 // Index the DWARF if we haven't already
2295 if (!m_indexed)
2296 Index ();
2297
Greg Claytonc685f8e2010-09-15 04:15:46 +00002298 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002299
Greg Claytonc685f8e2010-09-15 04:15:46 +00002300 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002301
2302 // Return the number of variable that were appended to the list
2303 return sc_list.GetSize() - original_size;
2304}
Jim Ingham318c9f22011-08-26 19:44:13 +00002305
Greg Claytond16e1e52011-07-12 17:06:17 +00002306void
2307SymbolFileDWARF::ReportError (const char *format, ...)
2308{
2309 ::fprintf (stderr,
2310 "error: %s/%s ",
2311 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2312 m_obj_file->GetFileSpec().GetFilename().GetCString());
2313
2314 va_list args;
2315 va_start (args, format);
2316 vfprintf (stderr, format, args);
2317 va_end (args);
2318}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002319
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002320uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002321SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002322{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002323 DWARFDebugInfo* info = DebugInfo();
2324 if (info == NULL)
2325 return 0;
2326
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002327 // If we aren't appending the results to this list, then clear the list
2328 if (!append)
2329 types.Clear();
2330
Greg Clayton6dbd3982010-09-15 05:51:24 +00002331 // Index if we already haven't to make sure the compile units
2332 // get indexed and make their global DIE index list
2333 if (!m_indexed)
2334 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002335
Greg Claytonc685f8e2010-09-15 04:15:46 +00002336 const uint32_t initial_types_size = types.GetSize();
Greg Clayton96d7d742010-11-10 23:42:09 +00002337 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002338 DWARFCompileUnit* prev_cu = NULL;
2339 const DWARFDebugInfoEntry* die = NULL;
2340 std::vector<NameToDIE::Info> die_info_array;
Greg Clayton69b04882010-10-15 02:03:22 +00002341 const size_t num_matches = m_type_index.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002342 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002343 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002344 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002345
Greg Clayton96d7d742010-11-10 23:42:09 +00002346 if (curr_cu != prev_cu)
2347 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002348
Greg Clayton96d7d742010-11-10 23:42:09 +00002349 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002350
Greg Clayton96d7d742010-11-10 23:42:09 +00002351 Type *matching_type = ResolveType (curr_cu, die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002352 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00002354 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002355 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Clayton73bf5db2011-06-17 01:22:15 +00002356 if (type_sp)
2357 {
2358 types.InsertUnique (type_sp);
2359 if (types.GetSize() >= max_matches)
2360 break;
2361 }
2362 else
2363 {
2364 fprintf (stderr, "error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID());
2365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002367 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002368 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002369}
2370
2371
Greg Clayton526e5af2010-11-13 03:52:47 +00002372ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002373SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2374 const ConstString &name)
2375{
Greg Clayton526e5af2010-11-13 03:52:47 +00002376 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002377 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002378 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002379 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002380 // Index if we already haven't to make sure the compile units
2381 // get indexed and make their global DIE index list
2382 if (!m_indexed)
2383 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002384
Greg Clayton526e5af2010-11-13 03:52:47 +00002385 DWARFCompileUnit* curr_cu = NULL;
2386 DWARFCompileUnit* prev_cu = NULL;
2387 const DWARFDebugInfoEntry* die = NULL;
2388 std::vector<NameToDIE::Info> die_info_array;
2389 const size_t num_matches = m_namespace_index.Find (name, die_info_array);
2390 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
2391 {
2392 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
2393
2394 if (curr_cu != prev_cu)
2395 curr_cu->ExtractDIEsIfNeeded (false);
Greg Clayton96d7d742010-11-10 23:42:09 +00002396
Greg Clayton526e5af2010-11-13 03:52:47 +00002397 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2398
2399 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die);
2400 if (clang_namespace_decl)
2401 {
2402 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2403 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2404 }
2405 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002406 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002407 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002408}
2409
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002410uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002411SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002412{
2413 // Remember how many sc_list are in the list before we search in case
2414 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002415 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002416
2417 const uint32_t num_die_offsets = die_offsets.size();
2418 // Parse all of the types we found from the pubtypes matches
2419 uint32_t i;
2420 uint32_t num_matches = 0;
2421 for (i = 0; i < num_die_offsets; ++i)
2422 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002423 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2424 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002425 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002426 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002427 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002428 assert (type_sp.get() != NULL);
2429 types.InsertUnique (type_sp);
2430 ++num_matches;
2431 if (num_matches >= max_matches)
2432 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002433 }
2434 }
2435
2436 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002437 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002438}
2439
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002440
2441size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00002442SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
2443 clang::DeclContext *containing_decl_ctx,
2444 TypeSP& type_sp,
2445 DWARFCompileUnit* dwarf_cu,
2446 const DWARFDebugInfoEntry *parent_die,
2447 bool skip_artificial,
2448 bool &is_static,
2449 TypeList* type_list,
2450 std::vector<clang_type_t>& function_param_types,
2451 std::vector<clang::ParmVarDecl*>& function_param_decls,
2452 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002453{
2454 if (parent_die == NULL)
2455 return 0;
2456
Greg Claytond88d7592010-09-15 08:33:30 +00002457 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2458
Greg Clayton7fedea22010-11-16 02:10:54 +00002459 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002460 const DWARFDebugInfoEntry *die;
2461 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2462 {
2463 dw_tag_t tag = die->Tag();
2464 switch (tag)
2465 {
2466 case DW_TAG_formal_parameter:
2467 {
2468 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002469 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002470 if (num_attributes > 0)
2471 {
2472 const char *name = NULL;
2473 Declaration decl;
2474 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002475 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002476 // one of None, Auto, Register, Extern, Static, PrivateExtern
2477
Sean Callanane2ef6e32010-09-23 03:01:22 +00002478 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002479 uint32_t i;
2480 for (i=0; i<num_attributes; ++i)
2481 {
2482 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2483 DWARFFormValue form_value;
2484 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2485 {
2486 switch (attr)
2487 {
2488 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2489 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2490 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2491 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2492 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002493 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002494 case DW_AT_location:
2495 // if (form_value.BlockData())
2496 // {
2497 // const DataExtractor& debug_info_data = debug_info();
2498 // uint32_t block_length = form_value.Unsigned();
2499 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2500 // }
2501 // else
2502 // {
2503 // }
2504 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002505 case DW_AT_const_value:
2506 case DW_AT_default_value:
2507 case DW_AT_description:
2508 case DW_AT_endianity:
2509 case DW_AT_is_optional:
2510 case DW_AT_segment:
2511 case DW_AT_variable_parameter:
2512 default:
2513 case DW_AT_abstract_origin:
2514 case DW_AT_sibling:
2515 break;
2516 }
2517 }
2518 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002519
Greg Clayton0fffff52010-09-24 05:15:53 +00002520 bool skip = false;
2521 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002522 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002523 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002524 {
2525 // In order to determine if a C++ member function is
2526 // "const" we have to look at the const-ness of "this"...
2527 // Ugly, but that
2528 if (arg_idx == 0)
2529 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002530 if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord)
Sean Callanan763d72a2011-08-02 22:21:50 +00002531 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002532 // Often times compilers omit the "this" name for the
2533 // specification DIEs, so we can't rely upon the name
2534 // being in the formal parameter DIE...
2535 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00002536 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002537 Type *this_type = ResolveTypeUID (param_type_die_offset);
2538 if (this_type)
2539 {
2540 uint32_t encoding_mask = this_type->GetEncodingMask();
2541 if (encoding_mask & Type::eEncodingIsPointerUID)
2542 {
2543 is_static = false;
2544
2545 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
2546 type_quals |= clang::Qualifiers::Const;
2547 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
2548 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002549 }
2550 }
2551 }
2552 }
2553 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002554 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002555 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002556 else
2557 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002558
Greg Clayton0fffff52010-09-24 05:15:53 +00002559 // HACK: Objective C formal parameters "self" and "_cmd"
2560 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002561 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2562 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002563 {
2564 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2565 skip = true;
2566 }
2567 }
2568 }
2569
2570 if (!skip)
2571 {
2572 Type *type = ResolveTypeUID(param_type_die_offset);
2573 if (type)
2574 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002575 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002576
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002577 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002578 assert(param_var_decl);
2579 function_param_decls.push_back(param_var_decl);
2580 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002581 }
2582 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002583 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002584 }
2585 break;
2586
2587 default:
2588 break;
2589 }
2590 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002591 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002592}
2593
2594size_t
2595SymbolFileDWARF::ParseChildEnumerators
2596(
2597 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002598 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002599 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002600 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002601 const DWARFDebugInfoEntry *parent_die
2602)
2603{
2604 if (parent_die == NULL)
2605 return 0;
2606
2607 size_t enumerators_added = 0;
2608 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002609 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002611 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2612 {
2613 const dw_tag_t tag = die->Tag();
2614 if (tag == DW_TAG_enumerator)
2615 {
2616 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002617 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002618 if (num_child_attributes > 0)
2619 {
2620 const char *name = NULL;
2621 bool got_value = false;
2622 int64_t enum_value = 0;
2623 Declaration decl;
2624
2625 uint32_t i;
2626 for (i=0; i<num_child_attributes; ++i)
2627 {
2628 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2629 DWARFFormValue form_value;
2630 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2631 {
2632 switch (attr)
2633 {
2634 case DW_AT_const_value:
2635 got_value = true;
2636 enum_value = form_value.Unsigned();
2637 break;
2638
2639 case DW_AT_name:
2640 name = form_value.AsCString(&get_debug_str_data());
2641 break;
2642
2643 case DW_AT_description:
2644 default:
2645 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2646 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2647 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2648 case DW_AT_sibling:
2649 break;
2650 }
2651 }
2652 }
2653
2654 if (name && name[0] && got_value)
2655 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002656 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2657 enumerator_clang_type,
2658 decl,
2659 name,
2660 enum_value,
2661 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002662 ++enumerators_added;
2663 }
2664 }
2665 }
2666 }
2667 return enumerators_added;
2668}
2669
2670void
2671SymbolFileDWARF::ParseChildArrayInfo
2672(
2673 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002674 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002675 const DWARFDebugInfoEntry *parent_die,
2676 int64_t& first_index,
2677 std::vector<uint64_t>& element_orders,
2678 uint32_t& byte_stride,
2679 uint32_t& bit_stride
2680)
2681{
2682 if (parent_die == NULL)
2683 return;
2684
2685 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002686 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002687 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2688 {
2689 const dw_tag_t tag = die->Tag();
2690 switch (tag)
2691 {
2692 case DW_TAG_enumerator:
2693 {
2694 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002695 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002696 if (num_child_attributes > 0)
2697 {
2698 const char *name = NULL;
2699 bool got_value = false;
2700 int64_t enum_value = 0;
2701
2702 uint32_t i;
2703 for (i=0; i<num_child_attributes; ++i)
2704 {
2705 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2706 DWARFFormValue form_value;
2707 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2708 {
2709 switch (attr)
2710 {
2711 case DW_AT_const_value:
2712 got_value = true;
2713 enum_value = form_value.Unsigned();
2714 break;
2715
2716 case DW_AT_name:
2717 name = form_value.AsCString(&get_debug_str_data());
2718 break;
2719
2720 case DW_AT_description:
2721 default:
2722 case DW_AT_decl_file:
2723 case DW_AT_decl_line:
2724 case DW_AT_decl_column:
2725 case DW_AT_sibling:
2726 break;
2727 }
2728 }
2729 }
2730 }
2731 }
2732 break;
2733
2734 case DW_TAG_subrange_type:
2735 {
2736 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002737 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002738 if (num_child_attributes > 0)
2739 {
2740 const char *name = NULL;
2741 bool got_value = false;
2742 uint64_t byte_size = 0;
2743 int64_t enum_value = 0;
2744 uint64_t num_elements = 0;
2745 uint64_t lower_bound = 0;
2746 uint64_t upper_bound = 0;
2747 uint32_t i;
2748 for (i=0; i<num_child_attributes; ++i)
2749 {
2750 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2751 DWARFFormValue form_value;
2752 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2753 {
2754 switch (attr)
2755 {
2756 case DW_AT_const_value:
2757 got_value = true;
2758 enum_value = form_value.Unsigned();
2759 break;
2760
2761 case DW_AT_name:
2762 name = form_value.AsCString(&get_debug_str_data());
2763 break;
2764
2765 case DW_AT_count:
2766 num_elements = form_value.Unsigned();
2767 break;
2768
2769 case DW_AT_bit_stride:
2770 bit_stride = form_value.Unsigned();
2771 break;
2772
2773 case DW_AT_byte_stride:
2774 byte_stride = form_value.Unsigned();
2775 break;
2776
2777 case DW_AT_byte_size:
2778 byte_size = form_value.Unsigned();
2779 break;
2780
2781 case DW_AT_lower_bound:
2782 lower_bound = form_value.Unsigned();
2783 break;
2784
2785 case DW_AT_upper_bound:
2786 upper_bound = form_value.Unsigned();
2787 break;
2788
2789 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002790 case DW_AT_abstract_origin:
2791 case DW_AT_accessibility:
2792 case DW_AT_allocated:
2793 case DW_AT_associated:
2794 case DW_AT_data_location:
2795 case DW_AT_declaration:
2796 case DW_AT_description:
2797 case DW_AT_sibling:
2798 case DW_AT_threads_scaled:
2799 case DW_AT_type:
2800 case DW_AT_visibility:
2801 break;
2802 }
2803 }
2804 }
2805
2806 if (upper_bound > lower_bound)
2807 num_elements = upper_bound - lower_bound + 1;
2808
2809 if (num_elements > 0)
2810 element_orders.push_back (num_elements);
2811 }
2812 }
2813 break;
2814 }
2815 }
2816}
2817
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002818TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002819SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002820{
2821 TypeSP type_sp;
2822 if (die != NULL)
2823 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002824 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002825 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002826 if (type_ptr == NULL)
2827 {
Greg Claytonca512b32011-01-14 04:54:56 +00002828 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
2829 assert (lldb_cu);
2830 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00002831 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002832 }
2833 else if (type_ptr != DIE_IS_BEING_PARSED)
2834 {
2835 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002836 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002837 }
2838
2839 }
2840 return type_sp;
2841}
2842
2843clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002844SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002845{
2846 if (die_offset != DW_INVALID_OFFSET)
2847 {
2848 DWARFCompileUnitSP cu_sp;
2849 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Sean Callanan72e49402011-08-05 23:43:37 +00002850 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851 }
2852 return NULL;
2853}
2854
Sean Callanan72e49402011-08-05 23:43:37 +00002855clang::DeclContext *
2856SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
2857{
2858 if (die_offset != DW_INVALID_OFFSET)
2859 {
2860 DWARFCompileUnitSP cu_sp;
2861 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2862 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
2863 }
2864 return NULL;
2865}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002866
Greg Clayton96d7d742010-11-10 23:42:09 +00002867clang::NamespaceDecl *
2868SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2869{
2870 if (die->Tag() == DW_TAG_namespace)
2871 {
2872 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2873 if (namespace_name)
2874 {
2875 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002876 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent()));
Greg Clayton96d7d742010-11-10 23:42:09 +00002877 if (namespace_decl)
Greg Claytona2721472011-06-25 00:44:06 +00002878 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Clayton96d7d742010-11-10 23:42:09 +00002879 return namespace_decl;
2880 }
2881 }
2882 return NULL;
2883}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002884
2885clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002886SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2887{
2888 // If this DIE has a specification, or an abstract origin, then trace to those.
2889
2890 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
2891 if (die_offset != DW_INVALID_OFFSET)
2892 return GetClangDeclContextForDIEOffset (sc, die_offset);
2893
2894 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
2895 if (die_offset != DW_INVALID_OFFSET)
2896 return GetClangDeclContextForDIEOffset (sc, die_offset);
2897
2898 // This is the DIE we want. Parse it, then query our map.
2899
2900 ParseType(sc, curr_cu, die, NULL);
2901
2902 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2903 if (pos != m_die_to_decl_ctx.end())
2904 return pos->second;
2905 else
2906 return NULL;
2907}
2908
2909clang::DeclContext *
2910SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002911{
Greg Claytonca512b32011-01-14 04:54:56 +00002912 if (m_clang_tu_decl == NULL)
2913 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914
Sean Callanan72e49402011-08-05 23:43:37 +00002915 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x )\n", die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002916 const DWARFDebugInfoEntry * const decl_die = die;
Greg Clayton4cd17802011-01-25 06:17:32 +00002917 clang::DeclContext *decl_ctx = NULL;
2918
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002919 while (die != NULL)
2920 {
Greg Claytonca512b32011-01-14 04:54:56 +00002921 // If this is the original DIE that we are searching for a declaration
2922 // for, then don't look in the cache as we don't want our own decl
2923 // context to be our decl context...
2924 if (decl_die != die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002925 {
Greg Claytonca512b32011-01-14 04:54:56 +00002926 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2927 if (pos != m_die_to_decl_ctx.end())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002928 {
Sean Callanan72e49402011-08-05 23:43:37 +00002929 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002930 return pos->second;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002931 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002932
Sean Callanan72e49402011-08-05 23:43:37 +00002933 //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 +00002934
2935 switch (die->Tag())
2936 {
2937 case DW_TAG_namespace:
2938 {
2939 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2940 if (namespace_name)
2941 {
2942 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002943 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die));
Greg Claytonca512b32011-01-14 04:54:56 +00002944 if (namespace_decl)
2945 {
Sean Callanan72e49402011-08-05 23:43:37 +00002946 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytona2721472011-06-25 00:44:06 +00002947 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Claytonca512b32011-01-14 04:54:56 +00002948 }
2949 return namespace_decl;
2950 }
2951 }
2952 break;
2953
2954 case DW_TAG_structure_type:
2955 case DW_TAG_union_type:
2956 case DW_TAG_class_type:
2957 {
Greg Clayton4cd17802011-01-25 06:17:32 +00002958 Type* type = ResolveType (curr_cu, die);
Greg Claytonca512b32011-01-14 04:54:56 +00002959 pos = m_die_to_decl_ctx.find(die);
Greg Claytonca512b32011-01-14 04:54:56 +00002960 if (pos != m_die_to_decl_ctx.end())
2961 {
Sean Callanan72e49402011-08-05 23:43:37 +00002962 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), die->GetOffset());
Greg Claytonca512b32011-01-14 04:54:56 +00002963 return pos->second;
2964 }
Greg Clayton4cd17802011-01-25 06:17:32 +00002965 else
2966 {
2967 if (type)
2968 {
2969 decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
Enrico Granata4a04dbc2011-08-12 18:43:16 +00002970 LinkDeclContextToDIE (decl_ctx, die);
Greg Clayton4cd17802011-01-25 06:17:32 +00002971 if (decl_ctx)
2972 return decl_ctx;
2973 }
2974 }
Greg Claytonca512b32011-01-14 04:54:56 +00002975 }
2976 break;
2977
2978 default:
2979 break;
2980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002981 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002982
Greg Clayton6beaaa62011-01-17 03:46:26 +00002983 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002984 if (die_offset != DW_INVALID_OFFSET)
2985 {
Sean Callanan72e49402011-08-05 23:43:37 +00002986 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_specification 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2987 decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset);
Greg Claytonca512b32011-01-14 04:54:56 +00002988 if (decl_ctx != m_clang_tu_decl)
2989 return decl_ctx;
2990 }
2991
Greg Clayton6beaaa62011-01-17 03:46:26 +00002992 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
Greg Claytonca512b32011-01-14 04:54:56 +00002993 if (die_offset != DW_INVALID_OFFSET)
2994 {
Sean Callanan72e49402011-08-05 23:43:37 +00002995 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) check DW_AT_abstract_origin 0x%8.8x\n", decl_die->GetOffset(), die_offset);
2996 decl_ctx = GetClangDeclContextContainingDIEOffset (die_offset);
Greg Claytonca512b32011-01-14 04:54:56 +00002997 if (decl_ctx != m_clang_tu_decl)
2998 return decl_ctx;
2999 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003000
3001 die = die->GetParent();
3002 }
Greg Clayton7a345282010-11-09 23:46:37 +00003003 // Right now we have only one translation unit per module...
Sean Callanan72e49402011-08-05 23:43:37 +00003004 //printf ("SymbolFileDWARF::GetClangDeclContextContainingDIE ( die = 0x%8.8x ) => 0x%8.8x\n", decl_die->GetOffset(), curr_cu->GetFirstDIEOffset());
Greg Clayton7a345282010-11-09 23:46:37 +00003005 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003006}
3007
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003008// This function can be used when a DIE is found that is a forward declaration
3009// DIE and we want to try and find a type that has the complete definition.
3010TypeSP
3011SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton1a65ae12011-01-25 23:55:37 +00003012 DWARFCompileUnit* cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003013 const DWARFDebugInfoEntry *die,
3014 const ConstString &type_name
3015)
3016{
3017 TypeSP type_sp;
3018
Greg Clayton1a65ae12011-01-25 23:55:37 +00003019 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003020 return type_sp;
3021
Greg Clayton69974892010-12-03 21:42:06 +00003022 if (!m_indexed)
3023 Index ();
3024
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003025 const dw_tag_t type_tag = die->Tag();
3026 std::vector<NameToDIE::Info> die_info_array;
3027 const size_t num_matches = m_type_index.Find (type_name, die_info_array);
3028 if (num_matches > 0)
3029 {
3030 DWARFCompileUnit* type_cu = NULL;
Greg Clayton1a65ae12011-01-25 23:55:37 +00003031 DWARFCompileUnit* curr_cu = cu;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003032 DWARFDebugInfo *info = DebugInfo();
3033 for (size_t i=0; i<num_matches; ++i)
3034 {
3035 type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx);
3036
3037 if (type_cu != curr_cu)
3038 {
3039 type_cu->ExtractDIEsIfNeeded (false);
3040 curr_cu = type_cu;
3041 }
3042
3043 DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx);
3044
3045 if (type_die != die && type_die->Tag() == type_tag)
3046 {
3047 // Hold off on comparing parent DIE tags until
3048 // we know what happens with stuff in namespaces
3049 // for gcc and clang...
3050 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3051 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3052 //if (parent_die->Tag() == parent_type_die->Tag())
3053 {
3054 Type *resolved_type = ResolveType (type_cu, type_die, false);
3055 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3056 {
3057 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
3058 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00003059 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003060 m_obj_file->GetFileSpec().GetFilename().AsCString(),
3061 type_die->GetOffset(),
3062 type_cu->GetOffset());
3063
3064 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003065 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00003066 if (!type_sp)
3067 {
3068 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
3069 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003070 break;
3071 }
3072 }
3073 }
3074 }
3075 }
3076 return type_sp;
3077}
3078
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003079TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003080SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003081{
3082 TypeSP type_sp;
3083
Greg Clayton1be10fc2010-09-29 01:12:09 +00003084 if (type_is_new_ptr)
3085 *type_is_new_ptr = false;
3086
Sean Callananc7fbf732010-08-06 00:32:49 +00003087 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003088 if (die != NULL)
3089 {
Jim Ingham16746d12011-08-25 23:21:43 +00003090 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3091 if (log && dwarf_cu)
3092 {
Jim Ingham318c9f22011-08-26 19:44:13 +00003093 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00003094 die->DumpLocation (this, dwarf_cu, s);
Jim Ingham318c9f22011-08-26 19:44:13 +00003095 log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
3096
Jim Ingham16746d12011-08-25 23:21:43 +00003097 }
3098
Greg Clayton594e5ed2010-09-27 21:07:38 +00003099 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003100 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003101 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003102 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003103 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003104 if (type_is_new_ptr)
3105 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003106
Greg Clayton594e5ed2010-09-27 21:07:38 +00003107 const dw_tag_t tag = die->Tag();
3108
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003109 bool is_forward_declaration = false;
3110 DWARFDebugInfoEntry::Attributes attributes;
3111 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003112 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003113 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3114 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003115 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003116 Declaration decl;
3117
Greg Clayton4957bf62010-09-30 21:49:03 +00003118 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003119 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003120
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003121 dw_attr_t attr;
3122
3123 switch (tag)
3124 {
3125 case DW_TAG_base_type:
3126 case DW_TAG_pointer_type:
3127 case DW_TAG_reference_type:
3128 case DW_TAG_typedef:
3129 case DW_TAG_const_type:
3130 case DW_TAG_restrict_type:
3131 case DW_TAG_volatile_type:
3132 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003133 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003134 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003135
Greg Claytond88d7592010-09-15 08:33:30 +00003136 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003137 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003138 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3139
3140 if (num_attributes > 0)
3141 {
3142 uint32_t i;
3143 for (i=0; i<num_attributes; ++i)
3144 {
3145 attr = attributes.AttributeAtIndex(i);
3146 DWARFFormValue form_value;
3147 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3148 {
3149 switch (attr)
3150 {
3151 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3152 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3153 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3154 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003155
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003156 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003157 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3158 // include the "&"...
3159 if (tag == DW_TAG_reference_type)
3160 {
3161 if (strchr (type_name_cstr, '&') == NULL)
3162 type_name_cstr = NULL;
3163 }
3164 if (type_name_cstr)
3165 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003166 break;
Greg Clayton36909642011-03-15 04:38:20 +00003167 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003168 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3169 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3170 default:
3171 case DW_AT_sibling:
3172 break;
3173 }
3174 }
3175 }
3176 }
3177
Greg Claytonc93237c2010-10-01 20:48:32 +00003178 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);
3179
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003180 switch (tag)
3181 {
3182 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003183 break;
3184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003185 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003186 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003187 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3188 encoding,
3189 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003190 break;
3191
Greg Clayton526e5af2010-11-13 03:52:47 +00003192 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3193 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3194 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3195 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3196 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3197 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003198 }
3199
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003200 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3201 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3202 {
3203 static ConstString g_objc_type_name_id("id");
3204 static ConstString g_objc_type_name_Class("Class");
3205 static ConstString g_objc_type_name_selector("SEL");
3206
Greg Clayton24739922010-10-13 03:15:28 +00003207 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003208 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003209 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003210 resolve_state = Type::eResolveStateFull;
3211
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003212 }
Greg Clayton24739922010-10-13 03:15:28 +00003213 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003214 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003215 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003216 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003217 }
Greg Clayton24739922010-10-13 03:15:28 +00003218 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003219 {
Sean Callananf6c73082010-12-06 23:53:20 +00003220 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003221 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003222 }
3223 }
3224
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003225 type_sp.reset( new Type (die->GetOffset(),
3226 this,
3227 type_name_const_str,
3228 byte_size,
3229 NULL,
3230 encoding_uid,
3231 encoding_data_type,
3232 &decl,
3233 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003234 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003235
Greg Clayton594e5ed2010-09-27 21:07:38 +00003236 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003237
3238// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3239// if (encoding_type != NULL)
3240// {
3241// if (encoding_type != DIE_IS_BEING_PARSED)
3242// type_sp->SetEncodingType(encoding_type);
3243// else
3244// m_indirect_fixups.push_back(type_sp.get());
3245// }
3246 }
3247 break;
3248
3249 case DW_TAG_structure_type:
3250 case DW_TAG_union_type:
3251 case DW_TAG_class_type:
3252 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003253 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003254 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003255
Greg Clayton9e409562010-07-28 02:04:09 +00003256 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003257 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003258 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003259 if (num_attributes > 0)
3260 {
3261 uint32_t i;
3262 for (i=0; i<num_attributes; ++i)
3263 {
3264 attr = attributes.AttributeAtIndex(i);
3265 DWARFFormValue form_value;
3266 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3267 {
3268 switch (attr)
3269 {
Greg Clayton9e409562010-07-28 02:04:09 +00003270 case DW_AT_decl_file:
3271 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3272 break;
3273
3274 case DW_AT_decl_line:
3275 decl.SetLine(form_value.Unsigned());
3276 break;
3277
3278 case DW_AT_decl_column:
3279 decl.SetColumn(form_value.Unsigned());
3280 break;
3281
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003282 case DW_AT_name:
3283 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003284 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003285 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003286
3287 case DW_AT_byte_size:
3288 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00003289 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00003290 break;
3291
3292 case DW_AT_accessibility:
3293 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3294 break;
3295
3296 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003297 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003298 break;
3299
3300 case DW_AT_APPLE_runtime_class:
3301 class_language = (LanguageType)form_value.Signed();
3302 break;
3303
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003304 case DW_AT_allocated:
3305 case DW_AT_associated:
3306 case DW_AT_data_location:
3307 case DW_AT_description:
3308 case DW_AT_start_scope:
3309 case DW_AT_visibility:
3310 default:
3311 case DW_AT_sibling:
3312 break;
3313 }
3314 }
3315 }
3316 }
3317
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003318 UniqueDWARFASTType unique_ast_entry;
3319 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003320 {
Greg Claytone576ab22011-02-15 00:19:15 +00003321 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00003322 this,
3323 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00003324 die,
3325 decl,
Greg Clayton36909642011-03-15 04:38:20 +00003326 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00003327 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003328 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003329 // We have already parsed this type or from another
3330 // compile unit. GCC loves to use the "one definition
3331 // rule" which can result in multiple definitions
3332 // of the same class over and over in each compile
3333 // unit.
3334 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003335 if (type_sp)
3336 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003337 m_die_to_type[die] = type_sp.get();
3338 return type_sp;
3339 }
3340 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003341 }
3342
3343 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3344
3345 int tag_decl_kind = -1;
3346 AccessType default_accessibility = eAccessNone;
3347 if (tag == DW_TAG_structure_type)
3348 {
3349 tag_decl_kind = clang::TTK_Struct;
3350 default_accessibility = eAccessPublic;
3351 }
3352 else if (tag == DW_TAG_union_type)
3353 {
3354 tag_decl_kind = clang::TTK_Union;
3355 default_accessibility = eAccessPublic;
3356 }
3357 else if (tag == DW_TAG_class_type)
3358 {
3359 tag_decl_kind = clang::TTK_Class;
3360 default_accessibility = eAccessPrivate;
3361 }
3362
3363
3364 if (is_forward_declaration)
3365 {
3366 // We have a forward declaration to a type and we need
3367 // to try and find a full declaration. We look in the
3368 // current type index just in case we have a forward
3369 // declaration followed by an actual declarations in the
3370 // DWARF. If this fails, we need to look elsewhere...
3371
3372 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3373
3374 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00003375 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003376 // We weren't able to find a full declaration in
3377 // this DWARF, see if we have a declaration anywhere
3378 // else...
3379 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00003380 }
3381
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003382 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00003383 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003384 // We found a real definition for this type elsewhere
3385 // so lets use it and cache the fact that we found
3386 // a complete type for this die
3387 m_die_to_type[die] = type_sp.get();
3388 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003389 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003390 }
3391 assert (tag_decl_kind != -1);
3392 bool clang_type_was_created = false;
3393 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3394 if (clang_type == NULL)
3395 {
3396 clang_type_was_created = true;
3397 clang_type = ast.CreateRecordType (type_name_cstr,
3398 tag_decl_kind,
Sean Callanan72e49402011-08-05 23:43:37 +00003399 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003400 class_language);
3401 }
3402
3403 // Store a forward declaration to this class type in case any
3404 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00003405 // types for function prototypes.
3406 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003407 type_sp.reset (new Type (die->GetOffset(),
3408 this,
3409 type_name_const_str,
3410 byte_size,
3411 NULL,
3412 LLDB_INVALID_UID,
3413 Type::eEncodingIsUID,
3414 &decl,
3415 clang_type,
3416 Type::eResolveStateForward));
3417
3418
3419 // Add our type to the unique type map so we don't
3420 // end up creating many copies of the same type over
3421 // and over in the ASTContext for our module
3422 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00003423 unique_ast_entry.m_symfile = this;
3424 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003425 unique_ast_entry.m_die = die;
3426 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00003427 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
3428 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003429
3430 if (die->HasChildren() == false && is_forward_declaration == false)
3431 {
3432 // No children for this struct/union/class, lets finish it
3433 ast.StartTagDeclarationDefinition (clang_type);
3434 ast.CompleteTagDeclarationDefinition (clang_type);
3435 }
3436 else if (clang_type_was_created)
3437 {
3438 // Leave this as a forward declaration until we need
3439 // to know the details of the type. lldb_private::Type
3440 // will automatically call the SymbolFile virtual function
3441 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3442 // When the definition needs to be defined.
3443 m_forward_decl_die_to_clang_type[die] = clang_type;
3444 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
3445 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00003446 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003447 }
3448 break;
3449
3450 case DW_TAG_enumeration_type:
3451 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003452 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003453 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003454
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003455 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003456
Greg Claytond88d7592010-09-15 08:33:30 +00003457 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003458 if (num_attributes > 0)
3459 {
3460 uint32_t i;
3461
3462 for (i=0; i<num_attributes; ++i)
3463 {
3464 attr = attributes.AttributeAtIndex(i);
3465 DWARFFormValue form_value;
3466 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3467 {
3468 switch (attr)
3469 {
Greg Clayton7a345282010-11-09 23:46:37 +00003470 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3471 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3472 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003473 case DW_AT_name:
3474 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003475 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003476 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003477 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003478 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00003479 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3480 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003481 case DW_AT_allocated:
3482 case DW_AT_associated:
3483 case DW_AT_bit_stride:
3484 case DW_AT_byte_stride:
3485 case DW_AT_data_location:
3486 case DW_AT_description:
3487 case DW_AT_start_scope:
3488 case DW_AT_visibility:
3489 case DW_AT_specification:
3490 case DW_AT_abstract_origin:
3491 case DW_AT_sibling:
3492 break;
3493 }
3494 }
3495 }
3496
Greg Claytonc93237c2010-10-01 20:48:32 +00003497 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3498
Greg Clayton1be10fc2010-09-29 01:12:09 +00003499 clang_type_t enumerator_clang_type = NULL;
3500 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3501 if (clang_type == NULL)
3502 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003503 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3504 DW_ATE_signed,
3505 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00003506 clang_type = ast.CreateEnumerationType (type_name_cstr,
Sean Callanan72e49402011-08-05 23:43:37 +00003507 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Claytonca512b32011-01-14 04:54:56 +00003508 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003509 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003510 }
3511 else
3512 {
3513 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3514 assert (enumerator_clang_type != NULL);
3515 }
3516
Greg Claytona2721472011-06-25 00:44:06 +00003517 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
3518
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003519 type_sp.reset( new Type (die->GetOffset(),
3520 this,
3521 type_name_const_str,
3522 byte_size,
3523 NULL,
3524 encoding_uid,
3525 Type::eEncodingIsUID,
3526 &decl,
3527 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003528 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003529
Greg Clayton6beaaa62011-01-17 03:46:26 +00003530#if LEAVE_ENUMS_FORWARD_DECLARED
Greg Clayton1be10fc2010-09-29 01:12:09 +00003531 // Leave this as a forward declaration until we need
3532 // to know the details of the type. lldb_private::Type
3533 // will automatically call the SymbolFile virtual function
3534 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3535 // When the definition needs to be defined.
3536 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003537 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003538 ClangASTContext::SetHasExternalStorage (clang_type, true);
3539#else
3540 ast.StartTagDeclarationDefinition (clang_type);
3541 if (die->HasChildren())
3542 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003543 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
3544 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00003545 }
3546 ast.CompleteTagDeclarationDefinition (clang_type);
3547#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003548 }
3549 }
3550 break;
3551
Jim Inghamb0be4422010-08-12 01:20:14 +00003552 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003553 case DW_TAG_subprogram:
3554 case DW_TAG_subroutine_type:
3555 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003556 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003557 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003558
3559 const char *mangled = NULL;
3560 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003561 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003562 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003563 bool is_static = false;
3564 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003565 bool is_explicit = false;
Greg Clayton72da3972011-08-16 18:40:23 +00003566 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
3567 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00003568
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003569 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003570 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003571
3572
Greg Claytond88d7592010-09-15 08:33:30 +00003573 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003574 if (num_attributes > 0)
3575 {
3576 uint32_t i;
3577 for (i=0; i<num_attributes; ++i)
3578 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003579 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003580 DWARFFormValue form_value;
3581 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3582 {
3583 switch (attr)
3584 {
3585 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3586 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3587 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3588 case DW_AT_name:
3589 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003590 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003591 break;
3592
3593 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3594 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003595 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003596 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003597 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3598 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003599 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3600
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601 case DW_AT_external:
3602 if (form_value.Unsigned())
3603 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003604 if (storage == clang::SC_None)
3605 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003606 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003607 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003608 }
3609 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003610
Greg Clayton72da3972011-08-16 18:40:23 +00003611 case DW_AT_specification:
3612 specification_die_offset = form_value.Reference(dwarf_cu);
3613 break;
3614
3615 case DW_AT_abstract_origin:
3616 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
3617 break;
3618
3619
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003620 case DW_AT_allocated:
3621 case DW_AT_associated:
3622 case DW_AT_address_class:
3623 case DW_AT_artificial:
3624 case DW_AT_calling_convention:
3625 case DW_AT_data_location:
3626 case DW_AT_elemental:
3627 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003628 case DW_AT_frame_base:
3629 case DW_AT_high_pc:
3630 case DW_AT_low_pc:
3631 case DW_AT_object_pointer:
3632 case DW_AT_prototyped:
3633 case DW_AT_pure:
3634 case DW_AT_ranges:
3635 case DW_AT_recursive:
3636 case DW_AT_return_addr:
3637 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003638 case DW_AT_start_scope:
3639 case DW_AT_static_link:
3640 case DW_AT_trampoline:
3641 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003642 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003643 case DW_AT_description:
3644 case DW_AT_sibling:
3645 break;
3646 }
3647 }
3648 }
Greg Clayton24739922010-10-13 03:15:28 +00003649 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003650
Greg Clayton24739922010-10-13 03:15:28 +00003651 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 +00003652
Greg Clayton24739922010-10-13 03:15:28 +00003653 clang_type_t return_clang_type = NULL;
3654 Type *func_type = NULL;
3655
3656 if (type_die_offset != DW_INVALID_OFFSET)
3657 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003658
Greg Clayton24739922010-10-13 03:15:28 +00003659 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003660 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003661 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003662 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003663
Greg Claytonf51de672010-10-01 02:31:07 +00003664
Greg Clayton24739922010-10-13 03:15:28 +00003665 std::vector<clang_type_t> function_param_types;
3666 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003667
Greg Clayton24739922010-10-13 03:15:28 +00003668 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00003669
Greg Clayton5113dc82011-08-12 06:47:54 +00003670 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
3671 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
3672
3673 const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord;
3674 // Start off static. This will be set to false in ParseChildParameters(...)
3675 // if we find a "this" paramters as the first parameter
3676 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00003677 is_static = true;
3678
Greg Clayton24739922010-10-13 03:15:28 +00003679 if (die->HasChildren())
3680 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003681 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003682 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00003683 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003684 type_sp,
3685 dwarf_cu,
3686 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00003687 skip_artificial,
3688 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003689 type_list,
3690 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003691 function_param_decls,
3692 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003693 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003694
Greg Clayton24739922010-10-13 03:15:28 +00003695 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003696 clang_type = ast.CreateFunctionType (return_clang_type,
3697 &function_param_types[0],
3698 function_param_types.size(),
3699 is_variadic,
3700 type_quals);
3701
Greg Clayton24739922010-10-13 03:15:28 +00003702 if (type_name_cstr)
3703 {
3704 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00003705 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003706 {
Greg Clayton24739922010-10-13 03:15:28 +00003707 if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
Greg Clayton0fffff52010-09-24 05:15:53 +00003708 {
Greg Clayton24739922010-10-13 03:15:28 +00003709 // We need to find the DW_TAG_class_type or
3710 // DW_TAG_struct_type by name so we can add this
3711 // as a member function of the class.
3712 const char *class_name_start = type_name_cstr + 2;
3713 const char *class_name_end = ::strchr (class_name_start, ' ');
3714 SymbolContext empty_sc;
3715 clang_type_t class_opaque_type = NULL;
3716 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003717 {
Greg Clayton24739922010-10-13 03:15:28 +00003718 ConstString class_name (class_name_start, class_name_end - class_name_start);
3719 TypeList types;
3720 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3721 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003722 {
Greg Clayton24739922010-10-13 03:15:28 +00003723 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003724 {
Greg Clayton24739922010-10-13 03:15:28 +00003725 Type *type = types.GetTypeAtIndex (i).get();
3726 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3727 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003728 {
Greg Clayton24739922010-10-13 03:15:28 +00003729 class_opaque_type = type_clang_forward_type;
3730 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003731 }
3732 }
3733 }
Greg Clayton24739922010-10-13 03:15:28 +00003734 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003735
Greg Clayton24739922010-10-13 03:15:28 +00003736 if (class_opaque_type)
3737 {
3738 // If accessibility isn't set to anything valid, assume public for
3739 // now...
3740 if (accessibility == eAccessNone)
3741 accessibility = eAccessPublic;
3742
3743 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003744 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3745 type_name_cstr,
3746 clang_type,
3747 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003748 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00003749 type_handled = objc_method_decl != NULL;
3750 }
3751 }
Greg Clayton5113dc82011-08-12 06:47:54 +00003752 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00003753 {
3754 // Look at the parent of this DIE and see if is is
3755 // a class or struct and see if this is actually a
3756 // C++ method
Greg Clayton5113dc82011-08-12 06:47:54 +00003757 Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]);
Greg Clayton24739922010-10-13 03:15:28 +00003758 if (class_type)
3759 {
Greg Clayton72da3972011-08-16 18:40:23 +00003760 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00003761 {
Greg Clayton72da3972011-08-16 18:40:23 +00003762 // If we have a specification, then the function type should have been
3763 // made with the specification and not with this die.
3764 DWARFCompileUnitSP spec_cu_sp;
3765 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
3766 if (m_die_to_decl_ctx[spec_die] == NULL)
3767 fprintf (stderr,"warning: 0x%8.8x: DW_AT_specification(0x%8.8x) has no decl\n", die->GetOffset(), specification_die_offset);
3768 type_handled = true;
3769 }
3770 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
3771 {
3772 DWARFCompileUnitSP abs_cu_sp;
3773 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
3774 if (m_die_to_decl_ctx[abs_die] == NULL)
3775 fprintf (stderr,"warning: 0x%8.8x: DW_AT_abstract_origin(0x%8.8x) has no decl\n", die->GetOffset(), abstract_origin_die_offset);
3776 type_handled = true;
3777 }
3778 else
3779 {
3780 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3781 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00003782 {
Greg Clayton72da3972011-08-16 18:40:23 +00003783 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3784 // in the DWARF for C++ methods... Default to public for now...
3785 if (accessibility == eAccessNone)
3786 accessibility = eAccessPublic;
3787
3788 if (!is_static && !die->HasChildren())
3789 {
3790 // We have a C++ member function with no children (this pointer!)
3791 // and clang will get mad if we try and make a function that isn't
3792 // well formed in the DWARF, so we will just skip it...
3793 type_handled = true;
3794 }
3795 else
3796 {
3797 clang::CXXMethodDecl *cxx_method_decl;
3798 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3799 type_name_cstr,
3800 clang_type,
3801 accessibility,
3802 is_virtual,
3803 is_static,
3804 is_inline,
3805 is_explicit);
3806 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003807
Greg Clayton72da3972011-08-16 18:40:23 +00003808 type_handled = cxx_method_decl != NULL;
3809 }
Greg Clayton931180e2011-01-27 06:44:37 +00003810 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003811 }
3812 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003813 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003814 }
Greg Clayton24739922010-10-13 03:15:28 +00003815
3816 if (!type_handled)
3817 {
3818 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003819 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3820 clang_type,
3821 storage,
3822 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003823
3824 // Add the decl to our DIE to decl context map
3825 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00003826 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00003827 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003828 ast.SetFunctionParameters (function_decl,
3829 &function_param_decls.front(),
3830 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003831 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003832 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003833 type_sp.reset( new Type (die->GetOffset(),
3834 this,
3835 type_name_const_str,
3836 0,
3837 NULL,
3838 LLDB_INVALID_UID,
3839 Type::eEncodingIsUID,
3840 &decl,
3841 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003842 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00003843 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003844 }
3845 break;
3846
3847 case DW_TAG_array_type:
3848 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003849 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003850 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003851
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003852 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003853 int64_t first_index = 0;
3854 uint32_t byte_stride = 0;
3855 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003856 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003857
3858 if (num_attributes > 0)
3859 {
3860 uint32_t i;
3861 for (i=0; i<num_attributes; ++i)
3862 {
3863 attr = attributes.AttributeAtIndex(i);
3864 DWARFFormValue form_value;
3865 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3866 {
3867 switch (attr)
3868 {
3869 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3870 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3871 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3872 case DW_AT_name:
3873 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003874 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003875 break;
3876
3877 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003878 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003879 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3880 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003881 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003882 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883 case DW_AT_allocated:
3884 case DW_AT_associated:
3885 case DW_AT_data_location:
3886 case DW_AT_description:
3887 case DW_AT_ordering:
3888 case DW_AT_start_scope:
3889 case DW_AT_visibility:
3890 case DW_AT_specification:
3891 case DW_AT_abstract_origin:
3892 case DW_AT_sibling:
3893 break;
3894 }
3895 }
3896 }
3897
Greg Claytonc93237c2010-10-01 20:48:32 +00003898 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3899
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003900 Type *element_type = ResolveTypeUID(type_die_offset);
3901
3902 if (element_type)
3903 {
3904 std::vector<uint64_t> element_orders;
3905 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00003906 // We have an array that claims to have no members, lets give it at least one member...
3907 if (element_orders.empty())
3908 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003909 if (byte_stride == 0 && bit_stride == 0)
3910 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00003911 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003912 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3913 uint64_t num_elements = 0;
3914 std::vector<uint64_t>::const_reverse_iterator pos;
3915 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3916 for (pos = element_orders.rbegin(); pos != end; ++pos)
3917 {
3918 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003919 clang_type = ast.CreateArrayType (array_element_type,
3920 num_elements,
3921 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003922 array_element_type = clang_type;
3923 array_element_bit_stride = array_element_bit_stride * num_elements;
3924 }
3925 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003926 type_sp.reset( new Type (die->GetOffset(),
3927 this,
3928 empty_name,
3929 array_element_bit_stride / 8,
3930 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00003931 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003932 Type::eEncodingIsUID,
3933 &decl,
3934 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003935 Type::eResolveStateFull));
3936 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003937 }
3938 }
3939 }
3940 break;
3941
Greg Clayton9b81a312010-06-12 01:20:30 +00003942 case DW_TAG_ptr_to_member_type:
3943 {
3944 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3945 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3946
Greg Claytond88d7592010-09-15 08:33:30 +00003947 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00003948
3949 if (num_attributes > 0) {
3950 uint32_t i;
3951 for (i=0; i<num_attributes; ++i)
3952 {
3953 attr = attributes.AttributeAtIndex(i);
3954 DWARFFormValue form_value;
3955 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3956 {
3957 switch (attr)
3958 {
3959 case DW_AT_type:
3960 type_die_offset = form_value.Reference(dwarf_cu); break;
3961 case DW_AT_containing_type:
3962 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3963 }
3964 }
3965 }
3966
3967 Type *pointee_type = ResolveTypeUID(type_die_offset);
3968 Type *class_type = ResolveTypeUID(containing_type_die_offset);
3969
Greg Clayton526e5af2010-11-13 03:52:47 +00003970 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
3971 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00003972
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003973 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
3974 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00003975
Greg Clayton526e5af2010-11-13 03:52:47 +00003976 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
3977 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00003978
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003979 type_sp.reset( new Type (die->GetOffset(),
3980 this,
3981 type_name_const_str,
3982 byte_size,
3983 NULL,
3984 LLDB_INVALID_UID,
3985 Type::eEncodingIsUID,
3986 NULL,
3987 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003988 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00003989 }
3990
3991 break;
3992 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003993 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00003994 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003995 break;
3996 }
3997
3998 if (type_sp.get())
3999 {
4000 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4001 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4002
4003 SymbolContextScope * symbol_context_scope = NULL;
4004 if (sc_parent_tag == DW_TAG_compile_unit)
4005 {
4006 symbol_context_scope = sc.comp_unit;
4007 }
4008 else if (sc.function != NULL)
4009 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004010 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004011 if (symbol_context_scope == NULL)
4012 symbol_context_scope = sc.function;
4013 }
4014
4015 if (symbol_context_scope != NULL)
4016 {
4017 type_sp->SetSymbolContextScope(symbol_context_scope);
4018 }
4019
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004020 // We are ready to put this type into the uniqued list up at the module level
4021 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00004022
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004023 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004024 }
4025 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00004026 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004027 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004028 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004029 }
4030 }
4031 return type_sp;
4032}
4033
4034size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00004035SymbolFileDWARF::ParseTypes
4036(
4037 const SymbolContext& sc,
4038 DWARFCompileUnit* dwarf_cu,
4039 const DWARFDebugInfoEntry *die,
4040 bool parse_siblings,
4041 bool parse_children
4042)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004043{
4044 size_t types_added = 0;
4045 while (die != NULL)
4046 {
4047 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004048 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004049 {
4050 if (type_is_new)
4051 ++types_added;
4052 }
4053
4054 if (parse_children && die->HasChildren())
4055 {
4056 if (die->Tag() == DW_TAG_subprogram)
4057 {
4058 SymbolContext child_sc(sc);
4059 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
4060 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4061 }
4062 else
4063 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4064 }
4065
4066 if (parse_siblings)
4067 die = die->GetSibling();
4068 else
4069 die = NULL;
4070 }
4071 return types_added;
4072}
4073
4074
4075size_t
4076SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4077{
4078 assert(sc.comp_unit && sc.function);
4079 size_t functions_added = 0;
4080 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4081 if (dwarf_cu)
4082 {
4083 dw_offset_t function_die_offset = sc.function->GetID();
4084 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4085 if (function_die)
4086 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004087 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004088 }
4089 }
4090
4091 return functions_added;
4092}
4093
4094
4095size_t
4096SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4097{
4098 // At least a compile unit must be valid
4099 assert(sc.comp_unit);
4100 size_t types_added = 0;
4101 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4102 if (dwarf_cu)
4103 {
4104 if (sc.function)
4105 {
4106 dw_offset_t function_die_offset = sc.function->GetID();
4107 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4108 if (func_die && func_die->HasChildren())
4109 {
4110 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4111 }
4112 }
4113 else
4114 {
4115 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4116 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4117 {
4118 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4119 }
4120 }
4121 }
4122
4123 return types_added;
4124}
4125
4126size_t
4127SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4128{
4129 if (sc.comp_unit != NULL)
4130 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004131 DWARFDebugInfo* info = DebugInfo();
4132 if (info == NULL)
4133 return 0;
4134
4135 uint32_t cu_idx = UINT32_MAX;
4136 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004137
4138 if (dwarf_cu == NULL)
4139 return 0;
4140
4141 if (sc.function)
4142 {
4143 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004144
4145 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4146 assert (func_lo_pc != DW_INVALID_ADDRESS);
4147
Greg Claytonc662ec82011-06-17 22:10:16 +00004148 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4149
4150 // Let all blocks know they have parse all their variables
4151 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4152
4153 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004154 }
4155 else if (sc.comp_unit)
4156 {
4157 uint32_t vars_added = 0;
4158 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4159
4160 if (variables.get() == NULL)
4161 {
4162 variables.reset(new VariableList());
4163 sc.comp_unit->SetVariableList(variables);
4164
4165 // Index if we already haven't to make sure the compile units
4166 // get indexed and make their global DIE index list
4167 if (!m_indexed)
4168 Index ();
4169
Greg Claytonc685f8e2010-09-15 04:15:46 +00004170 std::vector<NameToDIE::Info> global_die_info_array;
Greg Clayton4b3dc102010-11-01 20:32:12 +00004171 const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004172 for (size_t idx=0; idx<num_globals; ++idx)
4173 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00004174 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 +00004175 if (var_sp)
4176 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00004177 variables->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004178 ++vars_added;
4179 }
4180 }
4181 }
4182 return vars_added;
4183 }
4184 }
4185 return 0;
4186}
4187
4188
4189VariableSP
4190SymbolFileDWARF::ParseVariableDIE
4191(
4192 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004193 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004194 const DWARFDebugInfoEntry *die,
4195 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004196)
4197{
4198
Greg Clayton83c5cd92010-11-14 22:13:40 +00004199 VariableSP var_sp (m_die_to_variable_sp[die]);
4200 if (var_sp)
4201 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004202
4203 const dw_tag_t tag = die->Tag();
4204 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004205 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004206 if (num_attributes > 0)
4207 {
4208 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00004209 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004210 Declaration decl;
4211 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004212 Type *var_type = NULL;
4213 DWARFExpression location;
4214 bool is_external = false;
4215 bool is_artificial = false;
Greg Clayton007d5be2011-05-30 00:49:24 +00004216 bool location_is_const_value_data = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00004217 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004218
4219 for (i=0; i<num_attributes; ++i)
4220 {
4221 dw_attr_t attr = attributes.AttributeAtIndex(i);
4222 DWARFFormValue form_value;
4223 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4224 {
4225 switch (attr)
4226 {
4227 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4228 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4229 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4230 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00004231 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00004232 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004233 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Greg Clayton007d5be2011-05-30 00:49:24 +00004234 case DW_AT_const_value:
4235 location_is_const_value_data = true;
4236 // Fall through...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004237 case DW_AT_location:
4238 {
4239 if (form_value.BlockData())
4240 {
4241 const DataExtractor& debug_info_data = get_debug_info_data();
4242
4243 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4244 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00004245 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004246 }
4247 else
4248 {
4249 const DataExtractor& debug_loc_data = get_debug_loc_data();
4250 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4251
4252 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4253 if (loc_list_length > 0)
4254 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004255 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
4256 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4257 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004258 }
4259 }
4260 }
4261 break;
4262
4263 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004264 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004265 case DW_AT_declaration:
4266 case DW_AT_description:
4267 case DW_AT_endianity:
4268 case DW_AT_segment:
4269 case DW_AT_start_scope:
4270 case DW_AT_visibility:
4271 default:
4272 case DW_AT_abstract_origin:
4273 case DW_AT_sibling:
4274 case DW_AT_specification:
4275 break;
4276 }
4277 }
4278 }
4279
4280 if (location.IsValid())
4281 {
4282 assert(var_type != DIE_IS_BEING_PARSED);
4283
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004284 ValueType scope = eValueTypeInvalid;
4285
4286 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4287 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4288
4289 if (tag == DW_TAG_formal_parameter)
4290 scope = eValueTypeVariableArgument;
4291 else if (is_external || parent_tag == DW_TAG_compile_unit)
4292 scope = eValueTypeVariableGlobal;
4293 else
4294 scope = eValueTypeVariableLocal;
4295
4296 SymbolContextScope * symbol_context_scope = NULL;
4297 if (parent_tag == DW_TAG_compile_unit)
4298 {
4299 symbol_context_scope = sc.comp_unit;
4300 }
4301 else if (sc.function != NULL)
4302 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004303 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004304 if (symbol_context_scope == NULL)
4305 symbol_context_scope = sc.function;
4306 }
4307
4308 assert(symbol_context_scope != NULL);
4309 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00004310 name,
4311 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004312 var_type,
4313 scope,
4314 symbol_context_scope,
4315 &decl,
4316 location,
4317 is_external,
4318 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00004319
Greg Clayton007d5be2011-05-30 00:49:24 +00004320 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004321 }
4322 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00004323 // Cache var_sp even if NULL (the variable was just a specification or
4324 // was missing vital information to be able to be displayed in the debugger
4325 // (missing location due to optimization, etc)) so we don't re-parse
4326 // this DIE over and over later...
4327 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004328 return var_sp;
4329}
4330
Greg Claytonc662ec82011-06-17 22:10:16 +00004331
4332const DWARFDebugInfoEntry *
4333SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
4334 dw_offset_t spec_block_die_offset,
4335 DWARFCompileUnit **result_die_cu_handle)
4336{
4337 // Give the concrete function die specified by "func_die_offset", find the
4338 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4339 // to "spec_block_die_offset"
4340 DWARFDebugInfo* info = DebugInfo();
4341
4342 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
4343 if (die)
4344 {
4345 assert (*result_die_cu_handle);
4346 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
4347 }
4348 return NULL;
4349}
4350
4351
4352const DWARFDebugInfoEntry *
4353SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
4354 const DWARFDebugInfoEntry *die,
4355 dw_offset_t spec_block_die_offset,
4356 DWARFCompileUnit **result_die_cu_handle)
4357{
4358 if (die)
4359 {
4360 switch (die->Tag())
4361 {
4362 case DW_TAG_subprogram:
4363 case DW_TAG_inlined_subroutine:
4364 case DW_TAG_lexical_block:
4365 {
4366 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4367 {
4368 *result_die_cu_handle = dwarf_cu;
4369 return die;
4370 }
4371
4372 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4373 {
4374 *result_die_cu_handle = dwarf_cu;
4375 return die;
4376 }
4377 }
4378 break;
4379 }
4380
4381 // Give the concrete function die specified by "func_die_offset", find the
4382 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4383 // to "spec_block_die_offset"
4384 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
4385 {
4386 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
4387 child_die,
4388 spec_block_die_offset,
4389 result_die_cu_handle);
4390 if (result_die)
4391 return result_die;
4392 }
4393 }
4394
4395 *result_die_cu_handle = NULL;
4396 return NULL;
4397}
4398
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004399size_t
4400SymbolFileDWARF::ParseVariables
4401(
4402 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004403 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004404 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405 const DWARFDebugInfoEntry *orig_die,
4406 bool parse_siblings,
4407 bool parse_children,
4408 VariableList* cc_variable_list
4409)
4410{
4411 if (orig_die == NULL)
4412 return 0;
4413
Greg Claytonc662ec82011-06-17 22:10:16 +00004414 VariableListSP variable_list_sp;
4415
4416 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004417 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004418 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004419 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004420 dw_tag_t tag = die->Tag();
4421
4422 // Check to see if we have already parsed this variable or constant?
4423 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004424 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004425 if (cc_variable_list)
4426 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004427 }
4428 else
4429 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004430 // We haven't already parsed it, lets do that now.
4431 if ((tag == DW_TAG_variable) ||
4432 (tag == DW_TAG_constant) ||
4433 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004434 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004435 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004436 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004437 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4438 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4439 switch (parent_tag)
4440 {
4441 case DW_TAG_compile_unit:
4442 if (sc.comp_unit != NULL)
4443 {
4444 variable_list_sp = sc.comp_unit->GetVariableList(false);
4445 if (variable_list_sp.get() == NULL)
4446 {
4447 variable_list_sp.reset(new VariableList());
4448 sc.comp_unit->SetVariableList(variable_list_sp);
4449 }
4450 }
4451 else
4452 {
4453 fprintf (stderr,
4454 "error: parent 0x%8.8x %s with no valid compile unit in symbol context for 0x%8.8x %s.\n",
4455 sc_parent_die->GetOffset(),
4456 DW_TAG_value_to_name (parent_tag),
4457 orig_die->GetOffset(),
4458 DW_TAG_value_to_name (orig_die->Tag()));
4459 }
4460 break;
4461
4462 case DW_TAG_subprogram:
4463 case DW_TAG_inlined_subroutine:
4464 case DW_TAG_lexical_block:
4465 if (sc.function != NULL)
4466 {
4467 // Check to see if we already have parsed the variables for the given scope
4468
4469 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
4470 if (block == NULL)
4471 {
4472 // This must be a specification or abstract origin with
4473 // a concrete block couterpart in the current function. We need
4474 // to find the concrete block so we can correctly add the
4475 // variable to it
4476 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
4477 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4478 sc_parent_die->GetOffset(),
4479 &concrete_block_die_cu);
4480 if (concrete_block_die)
4481 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die->GetOffset());
4482 }
4483
4484 if (block != NULL)
4485 {
4486 const bool can_create = false;
4487 variable_list_sp = block->GetBlockVariableList (can_create);
4488 if (variable_list_sp.get() == NULL)
4489 {
4490 variable_list_sp.reset(new VariableList());
4491 block->SetVariableList(variable_list_sp);
4492 }
4493 }
4494 }
4495 break;
4496
4497 default:
4498 fprintf (stderr,
4499 "error: didn't find appropriate parent DIE for variable list for 0x%8.8x %s.\n",
4500 orig_die->GetOffset(),
4501 DW_TAG_value_to_name (orig_die->Tag()));
4502 break;
4503 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004504 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004505
4506 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004507 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00004508 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
4509 if (var_sp)
4510 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004511 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004512 if (cc_variable_list)
4513 cc_variable_list->AddVariableIfUnique (var_sp);
4514 ++vars_added;
4515 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004516 }
4517 }
4518 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004519
4520 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4521
4522 if (!skip_children && parse_children && die->HasChildren())
4523 {
4524 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
4525 }
4526
4527 if (parse_siblings)
4528 die = die->GetSibling();
4529 else
4530 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004531 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004532 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004533}
4534
4535//------------------------------------------------------------------
4536// PluginInterface protocol
4537//------------------------------------------------------------------
4538const char *
4539SymbolFileDWARF::GetPluginName()
4540{
4541 return "SymbolFileDWARF";
4542}
4543
4544const char *
4545SymbolFileDWARF::GetShortPluginName()
4546{
4547 return GetPluginNameStatic();
4548}
4549
4550uint32_t
4551SymbolFileDWARF::GetPluginVersion()
4552{
4553 return 1;
4554}
4555
4556void
Greg Clayton6beaaa62011-01-17 03:46:26 +00004557SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
4558{
4559 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4560 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4561 if (clang_type)
4562 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4563}
4564
4565void
4566SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
4567{
4568 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4569 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4570 if (clang_type)
4571 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4572}
4573
Greg Claytona2721472011-06-25 00:44:06 +00004574void
Sean Callanancc427fa2011-07-30 02:42:06 +00004575SymbolFileDWARF::DumpIndexes ()
4576{
4577 StreamFile s(stdout, false);
4578
4579 s.Printf ("DWARF index for (%s) '%s/%s':",
4580 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4581 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
4582 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
4583 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4584 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4585 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4586 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4587 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4588 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4589 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
4590 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
4591}
4592
4593void
4594SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
4595 const char *name,
4596 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00004597{
Sean Callanancc427fa2011-07-30 02:42:06 +00004598 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00004599
4600 if (iter == m_decl_ctx_to_die.end())
4601 return;
4602
Sean Callanancc427fa2011-07-30 02:42:06 +00004603 const DWARFDebugInfoEntry *context_die = iter->second;
Greg Claytona2721472011-06-25 00:44:06 +00004604
4605 if (!results)
4606 return;
4607
4608 DWARFDebugInfo* info = DebugInfo();
4609
4610 std::vector<NameToDIE::Info> die_info_array;
4611
Greg Clayton1d4313b2011-07-07 04:49:07 +00004612 size_t num_matches = m_type_index.Find (ConstString(name), die_info_array);
Greg Claytona2721472011-06-25 00:44:06 +00004613
4614 if (num_matches)
4615 {
4616 for (int i = 0;
4617 i < num_matches;
4618 ++i)
4619 {
4620 DWARFCompileUnit* compile_unit = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
4621 compile_unit->ExtractDIEsIfNeeded (false);
4622 const DWARFDebugInfoEntry *die = compile_unit->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
4623
Sean Callanancc427fa2011-07-30 02:42:06 +00004624 if (die->GetParent() != context_die)
Greg Claytona2721472011-06-25 00:44:06 +00004625 continue;
4626
4627 Type *matching_type = ResolveType (compile_unit, die);
4628
4629 lldb::clang_type_t type = matching_type->GetClangFullType();
4630 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
4631
Sean Callanancc427fa2011-07-30 02:42:06 +00004632 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004633 {
4634 clang::TagDecl *tag_decl = tag_type->getDecl();
4635 results->push_back(tag_decl);
4636 }
Sean Callanancc427fa2011-07-30 02:42:06 +00004637 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004638 {
4639 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
4640 results->push_back(typedef_decl);
4641 }
4642 }
4643 }
4644}
4645
4646void
4647SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
4648 const clang::DeclContext *DC,
4649 clang::DeclarationName Name,
4650 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
4651{
4652 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4653
Sean Callanancc427fa2011-07-30 02:42:06 +00004654 symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results);
Greg Claytona2721472011-06-25 00:44:06 +00004655}