blob: f9453afd0f339b1a598e82d0314b33968a015a40 [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
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000045#include "lldb/Target/ObjCLanguageRuntime.h"
46
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "DWARFCompileUnit.h"
48#include "DWARFDebugAbbrev.h"
49#include "DWARFDebugAranges.h"
50#include "DWARFDebugInfo.h"
51#include "DWARFDebugInfoEntry.h"
52#include "DWARFDebugLine.h"
53#include "DWARFDebugPubnames.h"
54#include "DWARFDebugRanges.h"
55#include "DWARFDIECollection.h"
56#include "DWARFFormValue.h"
57#include "DWARFLocationList.h"
58#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000059#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61#include <map>
62
Greg Clayton62742b12010-11-11 01:09:45 +000063//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000064
65#ifdef ENABLE_DEBUG_PRINTF
66#include <stdio.h>
67#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
68#else
69#define DEBUG_PRINTF(fmt, ...)
70#endif
71
Greg Clayton594e5ed2010-09-27 21:07:38 +000072#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073
74using namespace lldb;
75using namespace lldb_private;
76
77
Sean Callananc7fbf732010-08-06 00:32:49 +000078static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000079DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080{
81 switch (dwarf_accessibility)
82 {
Sean Callananc7fbf732010-08-06 00:32:49 +000083 case DW_ACCESS_public: return eAccessPublic;
84 case DW_ACCESS_private: return eAccessPrivate;
85 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000086 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087 }
Sean Callananc7fbf732010-08-06 00:32:49 +000088 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089}
90
91void
92SymbolFileDWARF::Initialize()
93{
94 LogChannelDWARF::Initialize();
95 PluginManager::RegisterPlugin (GetPluginNameStatic(),
96 GetPluginDescriptionStatic(),
97 CreateInstance);
98}
99
100void
101SymbolFileDWARF::Terminate()
102{
103 PluginManager::UnregisterPlugin (CreateInstance);
104 LogChannelDWARF::Initialize();
105}
106
107
108const char *
109SymbolFileDWARF::GetPluginNameStatic()
110{
Greg Claytond4a2b372011-09-12 23:21:58 +0000111 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112}
113
114const char *
115SymbolFileDWARF::GetPluginDescriptionStatic()
116{
117 return "DWARF and DWARF3 debug symbol file reader.";
118}
119
120
121SymbolFile*
122SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
123{
124 return new SymbolFileDWARF(obj_file);
125}
126
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000127TypeList *
128SymbolFileDWARF::GetTypeList ()
129{
130 if (m_debug_map_symfile)
131 return m_debug_map_symfile->GetTypeList();
132 return m_obj_file->GetModule()->GetTypeList();
133
134}
135
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136//----------------------------------------------------------------------
137// Gets the first parent that is a lexical block, function or inlined
138// subroutine, or compile unit.
139//----------------------------------------------------------------------
140static const DWARFDebugInfoEntry *
141GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
142{
143 const DWARFDebugInfoEntry *die;
144 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
145 {
146 dw_tag_t tag = die->Tag();
147
148 switch (tag)
149 {
150 case DW_TAG_compile_unit:
151 case DW_TAG_subprogram:
152 case DW_TAG_inlined_subroutine:
153 case DW_TAG_lexical_block:
154 return die;
155 }
156 }
157 return NULL;
158}
159
160
Greg Clayton450e3f32010-10-12 02:24:53 +0000161SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
162 SymbolFile (objfile),
163 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000164 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000166 m_data_debug_abbrev (),
167 m_data_debug_aranges (),
168 m_data_debug_frame (),
169 m_data_debug_info (),
170 m_data_debug_line (),
171 m_data_debug_loc (),
172 m_data_debug_ranges (),
173 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000174 m_data_apple_names (),
175 m_data_apple_types (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 m_info(),
178 m_line(),
Greg Clayton17674402011-09-28 17:06:40 +0000179 m_apple_names (this, m_data_apple_names, true),
Greg Clayton4d01ace2011-09-29 16:58:15 +0000180 m_apple_types (this, m_data_apple_types, true),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000181 m_function_basename_index(),
182 m_function_fullname_index(),
183 m_function_method_index(),
184 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000185 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000186 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000187 m_type_index(),
188 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000189 m_indexed (false),
190 m_is_external_ast_source (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000191 m_ranges(),
192 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193{
194}
195
196SymbolFileDWARF::~SymbolFileDWARF()
197{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000198 if (m_is_external_ast_source)
199 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
200}
201
202static const ConstString &
203GetDWARFMachOSegmentName ()
204{
205 static ConstString g_dwarf_section_name ("__DWARF");
206 return g_dwarf_section_name;
207}
208
Greg Claytone576ab22011-02-15 00:19:15 +0000209UniqueDWARFASTTypeMap &
210SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
211{
212 if (m_debug_map_symfile)
213 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
214 return m_unique_ast_type_map;
215}
216
Greg Clayton6beaaa62011-01-17 03:46:26 +0000217ClangASTContext &
218SymbolFileDWARF::GetClangASTContext ()
219{
220 if (m_debug_map_symfile)
221 return m_debug_map_symfile->GetClangASTContext ();
222
223 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
224 if (!m_is_external_ast_source)
225 {
226 m_is_external_ast_source = true;
227 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
228 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
229 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000230 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000231 this));
232
233 ast.SetExternalSource (ast_source_ap);
234 }
235 return ast;
236}
237
238void
239SymbolFileDWARF::InitializeObject()
240{
241 // Install our external AST source callbacks so we can complete Clang types.
242 Module *module = m_obj_file->GetModule();
243 if (module)
244 {
245 const SectionList *section_list = m_obj_file->GetSectionList();
246
247 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
248
249 // Memory map the DWARF mach-o segment so we have everything mmap'ed
250 // to keep our heap memory usage down.
251 if (section)
252 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
253 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000254 get_apple_names_data();
255 get_apple_types_data();
256 m_apple_names.Initialize();
257 m_apple_types.Initialize();
258
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259}
260
261bool
262SymbolFileDWARF::SupportedVersion(uint16_t version)
263{
264 return version == 2 || version == 3;
265}
266
267uint32_t
268SymbolFileDWARF::GetAbilities ()
269{
270 uint32_t abilities = 0;
271 if (m_obj_file != NULL)
272 {
273 const Section* section = NULL;
274 const SectionList *section_list = m_obj_file->GetSectionList();
275 if (section_list == NULL)
276 return 0;
277
278 uint64_t debug_abbrev_file_size = 0;
279 uint64_t debug_aranges_file_size = 0;
280 uint64_t debug_frame_file_size = 0;
281 uint64_t debug_info_file_size = 0;
282 uint64_t debug_line_file_size = 0;
283 uint64_t debug_loc_file_size = 0;
284 uint64_t debug_macinfo_file_size = 0;
285 uint64_t debug_pubnames_file_size = 0;
286 uint64_t debug_pubtypes_file_size = 0;
287 uint64_t debug_ranges_file_size = 0;
288 uint64_t debug_str_file_size = 0;
289
Greg Clayton6beaaa62011-01-17 03:46:26 +0000290 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000291
292 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000293 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294
Greg Clayton4ceb9982010-07-21 22:54:26 +0000295 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296 if (section != NULL)
297 {
298 debug_info_file_size = section->GetByteSize();
299
Greg Clayton4ceb9982010-07-21 22:54:26 +0000300 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301 if (section)
302 debug_abbrev_file_size = section->GetByteSize();
303 else
304 m_flags.Set (flagsGotDebugAbbrevData);
305
Greg Clayton4ceb9982010-07-21 22:54:26 +0000306 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307 if (section)
308 debug_aranges_file_size = section->GetByteSize();
309 else
310 m_flags.Set (flagsGotDebugArangesData);
311
Greg Clayton4ceb9982010-07-21 22:54:26 +0000312 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 if (section)
314 debug_frame_file_size = section->GetByteSize();
315 else
316 m_flags.Set (flagsGotDebugFrameData);
317
Greg Clayton4ceb9982010-07-21 22:54:26 +0000318 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319 if (section)
320 debug_line_file_size = section->GetByteSize();
321 else
322 m_flags.Set (flagsGotDebugLineData);
323
Greg Clayton4ceb9982010-07-21 22:54:26 +0000324 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325 if (section)
326 debug_loc_file_size = section->GetByteSize();
327 else
328 m_flags.Set (flagsGotDebugLocData);
329
Greg Clayton4ceb9982010-07-21 22:54:26 +0000330 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331 if (section)
332 debug_macinfo_file_size = section->GetByteSize();
333 else
334 m_flags.Set (flagsGotDebugMacInfoData);
335
Greg Clayton4ceb9982010-07-21 22:54:26 +0000336 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337 if (section)
338 debug_pubnames_file_size = section->GetByteSize();
339 else
340 m_flags.Set (flagsGotDebugPubNamesData);
341
Greg Clayton4ceb9982010-07-21 22:54:26 +0000342 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343 if (section)
344 debug_pubtypes_file_size = section->GetByteSize();
345 else
346 m_flags.Set (flagsGotDebugPubTypesData);
347
Greg Clayton4ceb9982010-07-21 22:54:26 +0000348 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349 if (section)
350 debug_ranges_file_size = section->GetByteSize();
351 else
352 m_flags.Set (flagsGotDebugRangesData);
353
Greg Clayton4ceb9982010-07-21 22:54:26 +0000354 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355 if (section)
356 debug_str_file_size = section->GetByteSize();
357 else
358 m_flags.Set (flagsGotDebugStrData);
359 }
360
361 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
362 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
363
364 if (debug_line_file_size > 0)
365 abilities |= LineTables;
366
367 if (debug_aranges_file_size > 0)
368 abilities |= AddressAcceleratorTable;
369
370 if (debug_pubnames_file_size > 0)
371 abilities |= FunctionAcceleratorTable;
372
373 if (debug_pubtypes_file_size > 0)
374 abilities |= TypeAcceleratorTable;
375
376 if (debug_macinfo_file_size > 0)
377 abilities |= MacroInformation;
378
379 if (debug_frame_file_size > 0)
380 abilities |= CallFrameInformation;
381 }
382 return abilities;
383}
384
385const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000386SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387{
388 if (m_flags.IsClear (got_flag))
389 {
390 m_flags.Set (got_flag);
391 const SectionList *section_list = m_obj_file->GetSectionList();
392 if (section_list)
393 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000394 Section *section = section_list->FindSectionByType(sect_type, true).get();
395 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 {
397 // See if we memory mapped the DWARF segment?
398 if (m_dwarf_data.GetByteSize())
399 {
400 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
401 }
402 else
403 {
404 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
405 data.Clear();
406 }
407 }
408 }
409 }
410 return data;
411}
412
413const DataExtractor&
414SymbolFileDWARF::get_debug_abbrev_data()
415{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000416 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417}
418
419const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000420SymbolFileDWARF::get_debug_aranges_data()
421{
422 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
423}
424
425const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426SymbolFileDWARF::get_debug_frame_data()
427{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000428 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429}
430
431const DataExtractor&
432SymbolFileDWARF::get_debug_info_data()
433{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000434 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435}
436
437const DataExtractor&
438SymbolFileDWARF::get_debug_line_data()
439{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000440 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441}
442
443const DataExtractor&
444SymbolFileDWARF::get_debug_loc_data()
445{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000446 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447}
448
449const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450SymbolFileDWARF::get_debug_ranges_data()
451{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000452 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453}
454
455const DataExtractor&
456SymbolFileDWARF::get_debug_str_data()
457{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000458 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459}
460
Greg Claytonf9eec202011-09-01 23:16:13 +0000461const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000462SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000463{
Greg Clayton17674402011-09-28 17:06:40 +0000464 return GetCachedSectionData (flagsGotDebugNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000465}
466
467const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000468SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000469{
Greg Clayton17674402011-09-28 17:06:40 +0000470 return GetCachedSectionData (flagsGotDebugTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000471}
472
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473
474DWARFDebugAbbrev*
475SymbolFileDWARF::DebugAbbrev()
476{
477 if (m_abbr.get() == NULL)
478 {
479 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
480 if (debug_abbrev_data.GetByteSize() > 0)
481 {
482 m_abbr.reset(new DWARFDebugAbbrev());
483 if (m_abbr.get())
484 m_abbr->Parse(debug_abbrev_data);
485 }
486 }
487 return m_abbr.get();
488}
489
490const DWARFDebugAbbrev*
491SymbolFileDWARF::DebugAbbrev() const
492{
493 return m_abbr.get();
494}
495
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496
497DWARFDebugInfo*
498SymbolFileDWARF::DebugInfo()
499{
500 if (m_info.get() == NULL)
501 {
502 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
503 if (get_debug_info_data().GetByteSize() > 0)
504 {
505 m_info.reset(new DWARFDebugInfo());
506 if (m_info.get())
507 {
508 m_info->SetDwarfData(this);
509 }
510 }
511 }
512 return m_info.get();
513}
514
515const DWARFDebugInfo*
516SymbolFileDWARF::DebugInfo() const
517{
518 return m_info.get();
519}
520
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521DWARFCompileUnit*
522SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
523{
524 DWARFDebugInfo* info = DebugInfo();
525 if (info)
526 return info->GetCompileUnit(cu_uid).get();
527 return NULL;
528}
529
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530
531DWARFDebugRanges*
532SymbolFileDWARF::DebugRanges()
533{
534 if (m_ranges.get() == NULL)
535 {
536 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
537 if (get_debug_ranges_data().GetByteSize() > 0)
538 {
539 m_ranges.reset(new DWARFDebugRanges());
540 if (m_ranges.get())
541 m_ranges->Extract(this);
542 }
543 }
544 return m_ranges.get();
545}
546
547const DWARFDebugRanges*
548SymbolFileDWARF::DebugRanges() const
549{
550 return m_ranges.get();
551}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552
553bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000554SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555{
Greg Clayton96d7d742010-11-10 23:42:09 +0000556 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000558 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 if (cu_die)
560 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000561 const char * cu_die_name = cu_die->GetName(this, curr_cu);
562 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000563 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 if (cu_die_name)
565 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000566 FileSpec cu_file_spec;
567
Greg Clayton7bd65b92011-02-09 23:39:34 +0000568 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000570 // If we have a full path to the compile unit, we don't need to resolve
571 // the file. This can be expensive e.g. when the source files are NFS mounted.
572 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 }
574 else
575 {
576 std::string fullpath(cu_comp_dir);
577 if (*fullpath.rbegin() != '/')
578 fullpath += '/';
579 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000580 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581 }
582
Jim Ingham0f35ac22011-08-24 23:34:20 +0000583 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 +0000584 if (compile_unit_sp.get())
585 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000586 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 return true;
588 }
589 }
590 }
591 }
592 return false;
593}
594
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595uint32_t
596SymbolFileDWARF::GetNumCompileUnits()
597{
598 DWARFDebugInfo* info = DebugInfo();
599 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 return 0;
602}
603
604CompUnitSP
605SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
606{
607 CompUnitSP comp_unit;
608 DWARFDebugInfo* info = DebugInfo();
609 if (info)
610 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000611 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
612 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613 {
614 // Our symbol vendor shouldn't be asking us to add a compile unit that
615 // has already been added to it, which this DWARF plug-in knows as it
616 // stores the lldb compile unit (CompileUnit) pointer in each
617 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000618 assert(curr_cu->GetUserData() == NULL);
619 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620 }
621 }
622 return comp_unit;
623}
624
625static void
626AddRangesToBlock
627(
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000628 Block& block,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 DWARFDebugRanges::RangeList& ranges,
630 addr_t block_base_addr
631)
632{
633 ranges.SubtractOffset (block_base_addr);
634 size_t range_idx = 0;
635 const DWARFDebugRanges::Range *debug_range;
636 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
637 {
Greg Clayton6c7f5612011-09-29 23:41:34 +0000638 block.AddRange(VMRange (debug_range->begin_offset, debug_range->end_offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639 }
640}
641
642
643Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000644SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645{
646 DWARFDebugRanges::RangeList func_ranges;
647 const char *name = NULL;
648 const char *mangled = NULL;
649 int decl_file = 0;
650 int decl_line = 0;
651 int decl_column = 0;
652 int call_file = 0;
653 int call_line = 0;
654 int call_column = 0;
655 DWARFExpression frame_base;
656
Greg Claytonc93237c2010-10-01 20:48:32 +0000657 assert (die->Tag() == DW_TAG_subprogram);
658
659 if (die->Tag() != DW_TAG_subprogram)
660 return NULL;
661
Greg Clayton2bc22f82011-09-30 03:20:47 +0000662// clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
663// const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
664//
665// switch (containing_decl_kind)
666// {
667// case clang::Decl::Record:
668// case clang::Decl::CXXRecord:
669// case clang::Decl::ObjCClass:
670// case clang::Decl::ObjCImplementation:
671// case clang::Decl::ObjCInterface:
672// // We have methods of a class or struct
673// {
674// const DWARFDebugInfoEntry *containing_decl_die = m_decl_ctx_to_die[containing_decl_ctx];
675// assert (containing_decl_die);
676// Type *class_type = ResolveType (dwarf_cu, containing_decl_die);
677// if (class_type)
678// class_type->GetClangFullType();
679// // Make sure the class definition contains the funciton DIE
680// // we wanted to parse. If it does, we are done. Else, we need
681// // to fall through and parse the function DIE stil...
682// if (containing_decl_die->Contains (die))
683// break; // DIE has been parsed, we are done
684// }
685// // Fall through...
686//
687// default:
688// // Parse the function prototype as a type that can then be added to concrete function instance
689// //ParseTypes (sc, dwarf_cu, die, false, false);
690// break;
691// }
Greg Claytonc93237c2010-10-01 20:48:32 +0000692
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693 //FixupTypes();
694
695 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
696 {
697 // Union of all ranges in the function DIE (if the function is discontiguous)
698 AddressRange func_range;
699 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
700 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
701 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
702 {
703 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
704 if (func_range.GetBaseAddress().IsValid())
705 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
706 }
707
708 if (func_range.GetBaseAddress().IsValid())
709 {
710 Mangled func_name;
711 if (mangled)
712 func_name.SetValue(mangled, true);
713 else if (name)
714 func_name.SetValue(name, false);
715
716 FunctionSP func_sp;
717 std::auto_ptr<Declaration> decl_ap;
718 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000719 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
720 decl_line,
721 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722
Greg Clayton594e5ed2010-09-27 21:07:38 +0000723 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724
725 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
726
727 func_range.GetBaseAddress().ResolveLinkedAddress();
728
729 func_sp.reset(new Function (sc.comp_unit,
730 die->GetOffset(), // UserID is the DIE offset
731 die->GetOffset(),
732 func_name,
733 func_type,
734 func_range)); // first address range
735
736 if (func_sp.get() != NULL)
737 {
738 func_sp->GetFrameBaseExpression() = frame_base;
739 sc.comp_unit->AddFunction(func_sp);
740 return func_sp.get();
741 }
742 }
743 }
744 return NULL;
745}
746
747size_t
748SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
749{
750 assert (sc.comp_unit);
751 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000752 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 if (dwarf_cu)
754 {
755 DWARFDIECollection function_dies;
756 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
757 size_t func_idx;
758 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
759 {
760 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
761 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
762 {
763 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
764 ++functions_added;
765 }
766 }
767 //FixupTypes();
768 }
769 return functions_added;
770}
771
772bool
773SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
774{
775 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000776 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
777 assert (curr_cu);
778 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779
780 if (cu_die)
781 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000782 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
783 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 +0000784
785 // All file indexes in DWARF are one based and a file of index zero is
786 // supposed to be the compile unit itself.
787 support_files.Append (*sc.comp_unit);
788
789 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
790 }
791 return false;
792}
793
794struct ParseDWARFLineTableCallbackInfo
795{
796 LineTable* line_table;
797 const SectionList *section_list;
798 lldb::addr_t prev_sect_file_base_addr;
799 lldb::addr_t curr_sect_file_base_addr;
800 bool is_oso_for_debug_map;
801 bool prev_in_final_executable;
802 DWARFDebugLine::Row prev_row;
803 SectionSP prev_section_sp;
804 SectionSP curr_section_sp;
805};
806
807//----------------------------------------------------------------------
808// ParseStatementTableCallback
809//----------------------------------------------------------------------
810static void
811ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
812{
813 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
814 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
815 {
816 // Just started parsing the line table
817 }
818 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
819 {
820 // Done parsing line table, nothing to do for the cleanup
821 }
822 else
823 {
824 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
825 // We have a new row, lets append it
826
827 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
828 {
829 info->prev_section_sp = info->curr_section_sp;
830 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
831 // If this is an end sequence entry, then we subtract one from the
832 // address to make sure we get an address that is not the end of
833 // a section.
834 if (state.end_sequence && state.address != 0)
835 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
836 else
837 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
838
839 if (info->curr_section_sp.get())
840 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
841 else
842 info->curr_sect_file_base_addr = 0;
843 }
844 if (info->curr_section_sp.get())
845 {
846 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
847 // Check for the fancy section magic to determine if we
848
849 if (info->is_oso_for_debug_map)
850 {
851 // When this is a debug map object file that contains DWARF
852 // (referenced from an N_OSO debug map nlist entry) we will have
853 // a file address in the file range for our section from the
854 // original .o file, and a load address in the executable that
855 // contains the debug map.
856 //
857 // If the sections for the file range and load range are
858 // different, we have a remapped section for the function and
859 // this address is resolved. If they are the same, then the
860 // function for this address didn't make it into the final
861 // executable.
862 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
863
864 // If we are doing DWARF with debug map, then we need to carefully
865 // add each line table entry as there may be gaps as functions
866 // get moved around or removed.
867 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
868 {
869 if (info->prev_in_final_executable)
870 {
871 bool terminate_previous_entry = false;
872 if (!curr_in_final_executable)
873 {
874 // Check for the case where the previous line entry
875 // in a function made it into the final executable,
876 // yet the current line entry falls in a function
877 // that didn't. The line table used to be contiguous
878 // through this address range but now it isn't. We
879 // need to terminate the previous line entry so
880 // that we can reconstruct the line range correctly
881 // for it and to keep the line table correct.
882 terminate_previous_entry = true;
883 }
884 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
885 {
886 // Check for cases where the line entries used to be
887 // contiguous address ranges, but now they aren't.
888 // This can happen when order files specify the
889 // ordering of the functions.
890 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
891 Section *curr_sect = info->curr_section_sp.get();
892 Section *prev_sect = info->prev_section_sp.get();
893 assert (curr_sect->GetLinkedSection());
894 assert (prev_sect->GetLinkedSection());
895 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
896 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
897 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
898 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
899 if (object_file_addr_delta != linked_file_addr_delta)
900 terminate_previous_entry = true;
901 }
902
903 if (terminate_previous_entry)
904 {
905 line_table->InsertLineEntry (info->prev_section_sp,
906 state.address - info->prev_sect_file_base_addr,
907 info->prev_row.line,
908 info->prev_row.column,
909 info->prev_row.file,
910 false, // is_stmt
911 false, // basic_block
912 false, // state.prologue_end
913 false, // state.epilogue_begin
914 true); // end_sequence);
915 }
916 }
917 }
918
919 if (curr_in_final_executable)
920 {
921 line_table->InsertLineEntry (info->curr_section_sp,
922 curr_line_section_offset,
923 state.line,
924 state.column,
925 state.file,
926 state.is_stmt,
927 state.basic_block,
928 state.prologue_end,
929 state.epilogue_begin,
930 state.end_sequence);
931 info->prev_section_sp = info->curr_section_sp;
932 }
933 else
934 {
935 // If the current address didn't make it into the final
936 // executable, the current section will be the __text
937 // segment in the .o file, so we need to clear this so
938 // we can catch the next function that did make it into
939 // the final executable.
940 info->prev_section_sp.reset();
941 info->curr_section_sp.reset();
942 }
943
944 info->prev_in_final_executable = curr_in_final_executable;
945 }
946 else
947 {
948 // We are not in an object file that contains DWARF for an
949 // N_OSO, this is just a normal DWARF file. The DWARF spec
950 // guarantees that the addresses will be in increasing order
951 // so, since we store line tables in file address order, we
952 // can always just append the line entry without needing to
953 // search for the correct insertion point (we don't need to
954 // use LineEntry::InsertLineEntry()).
955 line_table->AppendLineEntry (info->curr_section_sp,
956 curr_line_section_offset,
957 state.line,
958 state.column,
959 state.file,
960 state.is_stmt,
961 state.basic_block,
962 state.prologue_end,
963 state.epilogue_begin,
964 state.end_sequence);
965 }
966 }
967
968 info->prev_row = state;
969 }
970}
971
972bool
973SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
974{
975 assert (sc.comp_unit);
976 if (sc.comp_unit->GetLineTable() != NULL)
977 return true;
978
979 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
980 if (dwarf_cu)
981 {
982 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
983 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
984 if (cu_line_offset != DW_INVALID_OFFSET)
985 {
986 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
987 if (line_table_ap.get())
988 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000989 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 +0000990 uint32_t offset = cu_line_offset;
991 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
992 sc.comp_unit->SetLineTable(line_table_ap.release());
993 return true;
994 }
995 }
996 }
997 return false;
998}
999
1000size_t
1001SymbolFileDWARF::ParseFunctionBlocks
1002(
1003 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001004 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001005 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001006 const DWARFDebugInfoEntry *die,
1007 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001008 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001009)
1010{
1011 size_t blocks_added = 0;
1012 while (die != NULL)
1013 {
1014 dw_tag_t tag = die->Tag();
1015
1016 switch (tag)
1017 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001019 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020 case DW_TAG_lexical_block:
1021 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001022 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001023 if (tag == DW_TAG_subprogram)
1024 {
1025 // Skip any DW_TAG_subprogram DIEs that are inside
1026 // of a normal or inlined functions. These will be
1027 // parsed on their own as separate entities.
1028
1029 if (depth > 0)
1030 break;
1031
1032 block = parent_block;
1033 }
1034 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001035 {
1036 BlockSP block_sp(new Block (die->GetOffset()));
1037 parent_block->AddChild(block_sp);
1038 block = block_sp.get();
1039 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001040 DWARFDebugRanges::RangeList ranges;
1041 const char *name = NULL;
1042 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001044 int decl_file = 0;
1045 int decl_line = 0;
1046 int decl_column = 0;
1047 int call_file = 0;
1048 int call_line = 0;
1049 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001050 if (die->GetDIENamesAndRanges (this,
1051 dwarf_cu,
1052 name,
1053 mangled_name,
1054 ranges,
1055 decl_file, decl_line, decl_column,
1056 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001057 {
1058 if (tag == DW_TAG_subprogram)
1059 {
1060 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1061 subprogram_low_pc = ranges.LowestAddress(0);
1062 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001063 else if (tag == DW_TAG_inlined_subroutine)
1064 {
1065 // We get called here for inlined subroutines in two ways.
1066 // The first time is when we are making the Function object
1067 // for this inlined concrete instance. Since we're creating a top level block at
1068 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1069 // adjust the containing address.
1070 // The second time is when we are parsing the blocks inside the function that contains
1071 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1072 // function the offset will be for that function.
1073 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1074 {
1075 subprogram_low_pc = ranges.LowestAddress(0);
1076 }
1077 }
1078
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001079 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080
1081 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1082 {
1083 std::auto_ptr<Declaration> decl_ap;
1084 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001085 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1086 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087
1088 std::auto_ptr<Declaration> call_ap;
1089 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001090 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1091 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001093 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 }
1095
1096 ++blocks_added;
1097
Greg Claytondd7feaf2011-08-12 17:54:33 +00001098 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001100 blocks_added += ParseFunctionBlocks (sc,
1101 block,
1102 dwarf_cu,
1103 die->GetFirstChild(),
1104 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001105 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001106 }
1107 }
1108 }
1109 break;
1110 default:
1111 break;
1112 }
1113
Greg Claytondd7feaf2011-08-12 17:54:33 +00001114 // Only parse siblings of the block if we are not at depth zero. A depth
1115 // of zero indicates we are currently parsing the top level
1116 // DW_TAG_subprogram DIE
1117
1118 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001120 else
1121 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122 }
1123 return blocks_added;
1124}
1125
1126size_t
1127SymbolFileDWARF::ParseChildMembers
1128(
1129 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001130 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001131 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001132 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001133 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1135 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001136 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001137 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 bool &is_a_class
1139)
1140{
1141 if (parent_die == NULL)
1142 return 0;
1143
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001144 size_t count = 0;
1145 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001146 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001147 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001148
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1150 {
1151 dw_tag_t tag = die->Tag();
1152
1153 switch (tag)
1154 {
1155 case DW_TAG_member:
1156 {
1157 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001158 const size_t num_attributes = die->GetAttributes (this,
1159 dwarf_cu,
1160 fixed_form_sizes,
1161 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 if (num_attributes > 0)
1163 {
1164 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001165 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001167 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001169 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001170 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 size_t byte_size = 0;
1172 size_t bit_offset = 0;
1173 size_t bit_size = 0;
1174 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001175 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 {
1177 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1178 DWARFFormValue form_value;
1179 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1180 {
1181 switch (attr)
1182 {
1183 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1184 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1185 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1186 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1187 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1188 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1189 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1190 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1191 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001192// if (form_value.BlockData())
1193// {
1194// Value initialValue(0);
1195// Value memberOffset(0);
1196// const DataExtractor& debug_info_data = get_debug_info_data();
1197// uint32_t block_length = form_value.Unsigned();
1198// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1199// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1200// {
1201// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1202// }
1203// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204 break;
1205
Greg Clayton8cf05932010-07-22 18:30:50 +00001206 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001207 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 case DW_AT_declaration:
1209 case DW_AT_description:
1210 case DW_AT_mutable:
1211 case DW_AT_visibility:
1212 default:
1213 case DW_AT_sibling:
1214 break;
1215 }
1216 }
1217 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001218
1219 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1220
1221 if (class_language == eLanguageTypeObjC ||
1222 class_language == eLanguageTypeObjC_plus_plus)
1223 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001224
1225 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1226 {
1227 // Not all compilers will mark the vtable pointer
1228 // member as artificial (llvm-gcc). We can't have
1229 // the virtual members in our classes otherwise it
1230 // throws off all child offsets since we end up
1231 // having and extra pointer sized member in our
1232 // class layouts.
1233 is_artificial = true;
1234 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001235
Greg Clayton24739922010-10-13 03:15:28 +00001236 if (is_artificial == false)
1237 {
1238 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001239 if (member_type)
1240 {
1241 if (accessibility == eAccessNone)
1242 accessibility = default_accessibility;
1243 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244
Greg Claytond16e1e52011-07-12 17:06:17 +00001245 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1246 name,
1247 member_type->GetClangLayoutType(),
1248 accessibility,
1249 bit_size);
1250 }
1251 else
1252 {
1253 if (name)
1254 ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed",
1255 die->GetOffset(),
1256 name,
1257 encoding_uid);
1258 else
1259 ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed",
1260 die->GetOffset(),
1261 encoding_uid);
1262 }
Greg Clayton24739922010-10-13 03:15:28 +00001263 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001265 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 }
1267 break;
1268
1269 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001270 // Let the type parsing code handle this one for us.
1271 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272 break;
1273
1274 case DW_TAG_inheritance:
1275 {
1276 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001277 if (default_accessibility == eAccessNone)
1278 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279 // TODO: implement DW_TAG_inheritance type parsing
1280 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001281 const size_t num_attributes = die->GetAttributes (this,
1282 dwarf_cu,
1283 fixed_form_sizes,
1284 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 if (num_attributes > 0)
1286 {
1287 Declaration decl;
1288 DWARFExpression location;
1289 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001290 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291 bool is_virtual = false;
1292 bool is_base_of_class = true;
1293 off_t member_offset = 0;
1294 uint32_t i;
1295 for (i=0; i<num_attributes; ++i)
1296 {
1297 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1298 DWARFFormValue form_value;
1299 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1300 {
1301 switch (attr)
1302 {
1303 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1304 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1305 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1306 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1307 case DW_AT_data_member_location:
1308 if (form_value.BlockData())
1309 {
1310 Value initialValue(0);
1311 Value memberOffset(0);
1312 const DataExtractor& debug_info_data = get_debug_info_data();
1313 uint32_t block_length = form_value.Unsigned();
1314 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001315 if (DWARFExpression::Evaluate (NULL,
1316 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001317 NULL,
1318 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001319 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001320 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001321 block_offset,
1322 block_length,
1323 eRegisterKindDWARF,
1324 &initialValue,
1325 memberOffset,
1326 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 {
1328 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1329 }
1330 }
1331 break;
1332
1333 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001334 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001335 break;
1336
1337 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1338 default:
1339 case DW_AT_sibling:
1340 break;
1341 }
1342 }
1343 }
1344
Greg Clayton526e5af2010-11-13 03:52:47 +00001345 Type *base_class_type = ResolveTypeUID(encoding_uid);
1346 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001347
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001348 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1349 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001350 if (class_language == eLanguageTypeObjC)
1351 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001352 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001353 }
1354 else
1355 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001356 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001357 accessibility,
1358 is_virtual,
1359 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001360 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361 }
1362 }
1363 break;
1364
1365 default:
1366 break;
1367 }
1368 }
1369 return count;
1370}
1371
1372
1373clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001374SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375{
1376 DWARFDebugInfo* debug_info = DebugInfo();
1377 if (debug_info)
1378 {
1379 DWARFCompileUnitSP cu_sp;
1380 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1381 if (die)
Sean Callanan72e49402011-08-05 23:43:37 +00001382 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
1383 }
1384 return NULL;
1385}
1386
1387clang::DeclContext*
1388SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1389{
1390 DWARFDebugInfo* debug_info = DebugInfo();
1391 if (debug_info)
1392 {
1393 DWARFCompileUnitSP cu_sp;
1394 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1395 if (die)
1396 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397 }
1398 return NULL;
1399}
1400
1401Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001402SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001403{
1404 DWARFDebugInfo* debug_info = DebugInfo();
1405 if (debug_info)
1406 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001407 DWARFCompileUnitSP cu_sp;
1408 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001410 {
1411 // We might be coming in in the middle of a type tree (a class
1412 // withing a class, an enum within a class), so parse any needed
1413 // parent DIEs before we get to this one...
1414 const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
1415 switch (parent_die->Tag())
1416 {
1417 case DW_TAG_structure_type:
1418 case DW_TAG_union_type:
1419 case DW_TAG_class_type:
1420 ResolveType(cu_sp.get(), parent_die);
1421 break;
1422 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00001423 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001424 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 }
1426 return NULL;
1427}
1428
Greg Clayton6beaaa62011-01-17 03:46:26 +00001429// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1430// SymbolFileDWARF objects to detect if this DWARF file is the one that
1431// can resolve a clang_type.
1432bool
1433SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1434{
1435 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1436 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1437 return die != NULL;
1438}
1439
1440
Greg Clayton1be10fc2010-09-29 01:12:09 +00001441lldb::clang_type_t
1442SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1443{
1444 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001445 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1446 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001447 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001448 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001449// if (m_debug_map_symfile)
1450// {
1451// Type *type = m_die_to_type[die];
1452// if (type && type->GetSymbolFile() != this)
1453// return type->GetClangType();
1454// }
Greg Clayton73b472d2010-10-27 03:32:59 +00001455 // We have already resolved this type...
1456 return clang_type;
1457 }
1458 // Once we start resolving this type, remove it from the forward declaration
1459 // map in case anyone child members or other types require this type to get resolved.
1460 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1461 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001462 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001463
Greg Clayton1be10fc2010-09-29 01:12:09 +00001464
Greg Clayton450e3f32010-10-12 02:24:53 +00001465 DWARFDebugInfo* debug_info = DebugInfo();
1466
Greg Clayton96d7d742010-11-10 23:42:09 +00001467 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001468 Type *type = m_die_to_type.lookup (die);
1469
1470 const dw_tag_t tag = die->Tag();
1471
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001472 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1473 die->GetOffset(),
1474 DW_TAG_value_to_name(tag),
1475 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001476 assert (clang_type);
1477 DWARFDebugInfoEntry::Attributes attributes;
1478
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001479 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001480
1481 switch (tag)
1482 {
1483 case DW_TAG_structure_type:
1484 case DW_TAG_union_type:
1485 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001486 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001487 if (die->HasChildren())
1488 {
1489 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001490 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1491 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001492 class_language = eLanguageTypeObjC;
1493
1494 int tag_decl_kind = -1;
1495 AccessType default_accessibility = eAccessNone;
1496 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001497 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001498 tag_decl_kind = clang::TTK_Struct;
1499 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001500 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001501 else if (tag == DW_TAG_union_type)
1502 {
1503 tag_decl_kind = clang::TTK_Union;
1504 default_accessibility = eAccessPublic;
1505 }
1506 else if (tag == DW_TAG_class_type)
1507 {
1508 tag_decl_kind = clang::TTK_Class;
1509 default_accessibility = eAccessPrivate;
1510 }
1511
Greg Clayton96d7d742010-11-10 23:42:09 +00001512 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001513 std::vector<clang::CXXBaseSpecifier *> base_classes;
1514 std::vector<int> member_accessibilities;
1515 bool is_a_class = false;
1516 // Parse members and base classes first
1517 DWARFDIECollection member_function_dies;
1518
1519 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001520 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001521 die,
1522 clang_type,
1523 class_language,
1524 base_classes,
1525 member_accessibilities,
1526 member_function_dies,
1527 default_accessibility,
1528 is_a_class);
1529
1530 // Now parse any methods if there were any...
1531 size_t num_functions = member_function_dies.Size();
1532 if (num_functions > 0)
1533 {
1534 for (size_t i=0; i<num_functions; ++i)
1535 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001536 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001537 }
1538 }
1539
Greg Clayton450e3f32010-10-12 02:24:53 +00001540 if (class_language == eLanguageTypeObjC)
1541 {
Greg Claytone3055942011-06-30 02:28:26 +00001542 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001543 if (!class_str.empty())
1544 {
1545
1546 ConstString class_name (class_str.c_str());
Greg Claytond4a2b372011-09-12 23:21:58 +00001547 DIEArray method_die_offsets;
1548 if (m_objc_class_selectors_index.Find (class_name, method_die_offsets))
Greg Clayton450e3f32010-10-12 02:24:53 +00001549 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001550 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton450e3f32010-10-12 02:24:53 +00001551
Greg Claytond4a2b372011-09-12 23:21:58 +00001552 DWARFCompileUnit* method_cu = NULL;
1553 const size_t num_matches = method_die_offsets.size();
1554 for (size_t i=0; i<num_matches; ++i)
1555 {
1556 const dw_offset_t die_offset = method_die_offsets[i];
1557 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Greg Clayton450e3f32010-10-12 02:24:53 +00001558
1559 ResolveType (method_cu, method_die);
1560 }
1561 }
1562 }
1563 }
1564
Greg Claytonc93237c2010-10-01 20:48:32 +00001565 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1566 // need to tell the clang type it is actually a class.
1567 if (class_language != eLanguageTypeObjC)
1568 {
1569 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001570 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001571 }
1572
1573 // Since DW_TAG_structure_type gets used for both classes
1574 // and structures, we may need to set any DW_TAG_member
1575 // fields to have a "private" access if none was specified.
1576 // When we parsed the child members we tracked that actual
1577 // accessibility value for each DW_TAG_member in the
1578 // "member_accessibilities" array. If the value for the
1579 // member is zero, then it was set to the "default_accessibility"
1580 // which for structs was "public". Below we correct this
1581 // by setting any fields to "private" that weren't correctly
1582 // set.
1583 if (is_a_class && !member_accessibilities.empty())
1584 {
1585 // This is a class and all members that didn't have
1586 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001587 ast.SetDefaultAccessForRecordFields (clang_type,
1588 eAccessPrivate,
1589 &member_accessibilities.front(),
1590 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001591 }
1592
1593 if (!base_classes.empty())
1594 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001595 ast.SetBaseClassesForClassType (clang_type,
1596 &base_classes.front(),
1597 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001598
1599 // Clang will copy each CXXBaseSpecifier in "base_classes"
1600 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001601 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1602 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001603 }
1604
1605 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001606 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001607 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001608
1609 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001610 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001611 if (die->HasChildren())
1612 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001613 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1614 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001615 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001616 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001617 return clang_type;
1618
1619 default:
1620 assert(false && "not a forward clang type decl!");
1621 break;
1622 }
1623 return NULL;
1624}
1625
Greg Claytonc685f8e2010-09-15 04:15:46 +00001626Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001627SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001628{
1629 if (type_die != NULL)
1630 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001631 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001632 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001633 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001634 if (assert_not_being_parsed)
1635 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001636 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001637 }
1638 return NULL;
1639}
1640
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001641CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001642SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643{
1644 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001645 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646 {
1647 // The symbol vendor doesn't know about this compile unit, we
1648 // need to parse and add it to the symbol vendor object.
1649 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001650 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001651 if (dc_cu.get())
1652 {
1653 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001654 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001655 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001656
1657 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001658
1659 if (m_debug_map_symfile)
1660 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001661 }
1662 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001663 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664}
1665
1666bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001667SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001668{
1669 sc.Clear();
1670 // Check if the symbol vendor already knows about this compile unit?
Greg Claytona2eee182011-09-17 07:23:18 +00001671 sc.module_sp = m_obj_file->GetModule();
Greg Clayton96d7d742010-11-10 23:42:09 +00001672 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001673
1674 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1675 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001676 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677
1678 return sc.function != NULL;
1679}
1680
1681uint32_t
1682SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1683{
1684 Timer scoped_timer(__PRETTY_FUNCTION__,
1685 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1686 so_addr.GetSection(),
1687 so_addr.GetOffset(),
1688 resolve_scope);
1689 uint32_t resolved = 0;
1690 if (resolve_scope & ( eSymbolContextCompUnit |
1691 eSymbolContextFunction |
1692 eSymbolContextBlock |
1693 eSymbolContextLineEntry))
1694 {
1695 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1696
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001697 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001698 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001700 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701 if (cu_offset != DW_INVALID_OFFSET)
1702 {
1703 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001704 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1705 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001707 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708 assert(sc.comp_unit != NULL);
1709 resolved |= eSymbolContextCompUnit;
1710
1711 if (resolve_scope & eSymbolContextLineEntry)
1712 {
1713 LineTable *line_table = sc.comp_unit->GetLineTable();
1714 if (line_table == NULL)
1715 {
1716 if (ParseCompileUnitLineTable(sc))
1717 line_table = sc.comp_unit->GetLineTable();
1718 }
1719 if (line_table != NULL)
1720 {
1721 if (so_addr.IsLinkedAddress())
1722 {
1723 Address linked_addr (so_addr);
1724 linked_addr.ResolveLinkedAddress();
1725 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1726 {
1727 resolved |= eSymbolContextLineEntry;
1728 }
1729 }
1730 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1731 {
1732 resolved |= eSymbolContextLineEntry;
1733 }
1734 }
1735 }
1736
1737 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1738 {
1739 DWARFDebugInfoEntry *function_die = NULL;
1740 DWARFDebugInfoEntry *block_die = NULL;
1741 if (resolve_scope & eSymbolContextBlock)
1742 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001743 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 }
1745 else
1746 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001747 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748 }
1749
1750 if (function_die != NULL)
1751 {
1752 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1753 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001754 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001755 }
1756
1757 if (sc.function != NULL)
1758 {
1759 resolved |= eSymbolContextFunction;
1760
1761 if (resolve_scope & eSymbolContextBlock)
1762 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001763 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001764
1765 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001766 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001767 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001768 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001769 if (sc.block)
1770 resolved |= eSymbolContextBlock;
1771 }
1772 }
1773 }
1774 }
1775 }
1776 }
1777 }
1778 return resolved;
1779}
1780
1781
1782
1783uint32_t
1784SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1785{
1786 const uint32_t prev_size = sc_list.GetSize();
1787 if (resolve_scope & eSymbolContextCompUnit)
1788 {
1789 DWARFDebugInfo* debug_info = DebugInfo();
1790 if (debug_info)
1791 {
1792 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001793 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794
Greg Clayton96d7d742010-11-10 23:42:09 +00001795 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001797 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001798 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1799 if (check_inlines || file_spec_matches_cu_file_spec)
1800 {
1801 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001802 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803 assert(sc.comp_unit != NULL);
1804
1805 uint32_t file_idx = UINT32_MAX;
1806
1807 // If we are looking for inline functions only and we don't
1808 // find it in the support files, we are done.
1809 if (check_inlines)
1810 {
Jim Ingham87df91b2011-09-23 00:54:11 +00001811 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812 if (file_idx == UINT32_MAX)
1813 continue;
1814 }
1815
1816 if (line != 0)
1817 {
1818 LineTable *line_table = sc.comp_unit->GetLineTable();
1819
1820 if (line_table != NULL && line != 0)
1821 {
1822 // We will have already looked up the file index if
1823 // we are searching for inline entries.
1824 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00001825 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826
1827 if (file_idx != UINT32_MAX)
1828 {
1829 uint32_t found_line;
1830 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1831 found_line = sc.line_entry.line;
1832
Greg Clayton016a95e2010-09-14 02:20:48 +00001833 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001834 {
1835 sc.function = NULL;
1836 sc.block = NULL;
1837 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1838 {
1839 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1840 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1841 {
1842 DWARFDebugInfoEntry *function_die = NULL;
1843 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001844 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001845
1846 if (function_die != NULL)
1847 {
1848 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1849 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001850 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851 }
1852
1853 if (sc.function != NULL)
1854 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001855 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001856
1857 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001858 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001860 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 }
1862 }
1863 }
1864
1865 sc_list.Append(sc);
1866 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1867 }
1868 }
1869 }
1870 else if (file_spec_matches_cu_file_spec && !check_inlines)
1871 {
1872 // only append the context if we aren't looking for inline call sites
1873 // by file and line and if the file spec matches that of the compile unit
1874 sc_list.Append(sc);
1875 }
1876 }
1877 else if (file_spec_matches_cu_file_spec && !check_inlines)
1878 {
1879 // only append the context if we aren't looking for inline call sites
1880 // by file and line and if the file spec matches that of the compile unit
1881 sc_list.Append(sc);
1882 }
1883
1884 if (!check_inlines)
1885 break;
1886 }
1887 }
1888 }
1889 }
1890 return sc_list.GetSize() - prev_size;
1891}
1892
1893void
1894SymbolFileDWARF::Index ()
1895{
1896 if (m_indexed)
1897 return;
1898 m_indexed = true;
1899 Timer scoped_timer (__PRETTY_FUNCTION__,
1900 "SymbolFileDWARF::Index (%s)",
1901 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1902
1903 DWARFDebugInfo* debug_info = DebugInfo();
1904 if (debug_info)
1905 {
1906 uint32_t cu_idx = 0;
1907 const uint32_t num_compile_units = GetNumCompileUnits();
1908 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1909 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001910 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001911
Greg Clayton96d7d742010-11-10 23:42:09 +00001912 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001913
Greg Clayton96d7d742010-11-10 23:42:09 +00001914 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001915 m_function_basename_index,
1916 m_function_fullname_index,
1917 m_function_method_index,
1918 m_function_selector_index,
1919 m_objc_class_selectors_index,
1920 m_global_index,
1921 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00001922 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923
1924 // Keep memory down by clearing DIEs if this generate function
1925 // caused them to be parsed
1926 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001927 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001928 }
1929
Greg Claytond4a2b372011-09-12 23:21:58 +00001930 m_function_basename_index.Finalize();
1931 m_function_fullname_index.Finalize();
1932 m_function_method_index.Finalize();
1933 m_function_selector_index.Finalize();
1934 m_objc_class_selectors_index.Finalize();
1935 m_global_index.Finalize();
1936 m_type_index.Finalize();
1937 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001938
Greg Clayton24739922010-10-13 03:15:28 +00001939#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00001940 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00001941 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00001942 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1943 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001944 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1945 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1946 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1947 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1948 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1949 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001950 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001951 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001952#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 }
1954}
1955
1956uint32_t
1957SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1958{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001959 DWARFDebugInfo* info = DebugInfo();
1960 if (info == NULL)
1961 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962
1963 // If we aren't appending the results to this list, then clear the list
1964 if (!append)
1965 variables.Clear();
1966
1967 // Remember how many variables are in the list before we search in case
1968 // we are appending the results to a variable list.
1969 const uint32_t original_size = variables.GetSize();
1970
1971 // Index the DWARF if we haven't already
1972 if (!m_indexed)
1973 Index ();
1974
Greg Claytonc685f8e2010-09-15 04:15:46 +00001975 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00001976 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001977 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978
Greg Claytond4a2b372011-09-12 23:21:58 +00001979 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001980 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00001981 DIEArray die_offsets;
1982 const size_t num_matches = m_global_index.Find (name, die_offsets);
1983 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001984 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001985 DWARFDebugInfo* debug_info = DebugInfo();
1986 for (size_t i=0; i<num_matches; ++i)
1987 {
1988 const dw_offset_t die_offset = die_offsets[i];
1989 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001990
Greg Claytond4a2b372011-09-12 23:21:58 +00001991 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
1992 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993
Greg Claytond4a2b372011-09-12 23:21:58 +00001994 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995
Greg Claytond4a2b372011-09-12 23:21:58 +00001996 if (variables.GetSize() - original_size >= max_matches)
1997 break;
1998 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999 }
2000
2001 // Return the number of variable that were appended to the list
2002 return variables.GetSize() - original_size;
2003}
2004
2005uint32_t
2006SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2007{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002008 DWARFDebugInfo* info = DebugInfo();
2009 if (info == NULL)
2010 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011
2012 // If we aren't appending the results to this list, then clear the list
2013 if (!append)
2014 variables.Clear();
2015
2016 // Remember how many variables are in the list before we search in case
2017 // we are appending the results to a variable list.
2018 const uint32_t original_size = variables.GetSize();
2019
2020 // Index the DWARF if we haven't already
2021 if (!m_indexed)
2022 Index ();
2023
Greg Claytonc685f8e2010-09-15 04:15:46 +00002024 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002025 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002026 assert (sc.module_sp);
2027
Greg Claytond4a2b372011-09-12 23:21:58 +00002028 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002029 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002030 DIEArray die_offsets;
2031 const size_t num_matches = m_global_index.Find (regex, die_offsets);
2032 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002033 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002034 DWARFDebugInfo* debug_info = DebugInfo();
2035 for (size_t i=0; i<num_matches; ++i)
2036 {
2037 const dw_offset_t die_offset = die_offsets[i];
2038 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2039 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2040 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002041
Greg Claytond4a2b372011-09-12 23:21:58 +00002042 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002043
Greg Claytond4a2b372011-09-12 23:21:58 +00002044 if (variables.GetSize() - original_size >= max_matches)
2045 break;
2046 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002047 }
2048
2049 // Return the number of variable that were appended to the list
2050 return variables.GetSize() - original_size;
2051}
2052
2053
Greg Clayton9e315582011-09-02 04:03:59 +00002054uint32_t
2055SymbolFileDWARF::ResolveFunctions (const DIEArray &die_offsets,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002056 SymbolContextList& sc_list,
2057 const ConstString &name,
2058 uint32_t name_type_mask)
Greg Clayton9e315582011-09-02 04:03:59 +00002059{
2060 DWARFDebugInfo* info = DebugInfo();
2061 if (info == NULL)
2062 return 0;
2063
2064 const uint32_t sc_list_initial_size = sc_list.GetSize();
2065 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002066 sc.module_sp = m_obj_file->GetModule();
Greg Clayton9e315582011-09-02 04:03:59 +00002067 assert (sc.module_sp);
2068
2069 DWARFCompileUnit* dwarf_cu = NULL;
2070 const size_t num_matches = die_offsets.size();
2071 for (size_t i=0; i<num_matches; ++i)
2072 {
2073 const dw_offset_t die_offset = die_offsets[i];
2074 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2075
Greg Clayton2bc22f82011-09-30 03:20:47 +00002076 // If we aren't doing full names,
2077 if ((name_type_mask & eFunctionNameTypeFull) == 0)
2078 {
2079 const char *name_cstr = name.GetCString();
2080 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(name_cstr))
2081 continue;
2082 }
2083
2084
Greg Clayton9e315582011-09-02 04:03:59 +00002085 const DWARFDebugInfoEntry* inlined_die = NULL;
2086 if (die->Tag() == DW_TAG_inlined_subroutine)
2087 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002088 // We only are looking for selectors, which disallows anything inlined
2089 if (name_type_mask == eFunctionNameTypeSelector)
2090 continue;
2091
Greg Clayton9e315582011-09-02 04:03:59 +00002092 inlined_die = die;
2093
2094 while ((die = die->GetParent()) != NULL)
2095 {
2096 if (die->Tag() == DW_TAG_subprogram)
2097 break;
2098 }
2099 }
2100 assert (die->Tag() == DW_TAG_subprogram);
2101 if (GetFunction (dwarf_cu, die, sc))
2102 {
2103 Address addr;
2104 // Parse all blocks if needed
2105 if (inlined_die)
2106 {
2107 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2108 assert (sc.block != NULL);
2109 if (sc.block->GetStartAddress (addr) == false)
2110 addr.Clear();
2111 }
2112 else
2113 {
2114 sc.block = NULL;
2115 addr = sc.function->GetAddressRange().GetBaseAddress();
2116 }
2117
2118 if (addr.IsValid())
2119 {
2120
2121 // We found the function, so we should find the line table
2122 // and line table entry as well
2123 LineTable *line_table = sc.comp_unit->GetLineTable();
2124 if (line_table == NULL)
2125 {
2126 if (ParseCompileUnitLineTable(sc))
2127 line_table = sc.comp_unit->GetLineTable();
2128 }
2129 if (line_table != NULL)
2130 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2131
2132 sc_list.Append(sc);
2133 }
2134 }
2135 }
2136 return sc_list.GetSize() - sc_list_initial_size;
2137}
2138
Greg Clayton0c5cd902010-06-28 21:30:43 +00002139void
2140SymbolFileDWARF::FindFunctions
2141(
2142 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00002143 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00002144 SymbolContextList& sc_list
2145)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002146{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002147 DWARFDebugInfo* info = DebugInfo();
2148 if (info == NULL)
2149 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002150
Greg Claytonc685f8e2010-09-15 04:15:46 +00002151 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002152 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002153 assert (sc.module_sp);
2154
Greg Claytond4a2b372011-09-12 23:21:58 +00002155 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002156 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002157 DIEArray die_offsets;
2158 const size_t num_matches = name_to_die.Find (name, die_offsets);
2159 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002160 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002161 DWARFDebugInfo* debug_info = DebugInfo();
2162 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002163 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002164 const dw_offset_t die_offset = die_offsets[i];
2165 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2166 const DWARFDebugInfoEntry* inlined_die = NULL;
2167 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Claytond7e05462010-11-14 00:22:48 +00002168 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002169 inlined_die = die;
2170
2171 while ((die = die->GetParent()) != NULL)
Greg Claytond7e05462010-11-14 00:22:48 +00002172 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002173 if (die->Tag() == DW_TAG_subprogram)
2174 break;
Greg Claytond7e05462010-11-14 00:22:48 +00002175 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002176 }
2177 assert (die->Tag() == DW_TAG_subprogram);
2178 if (GetFunction (dwarf_cu, die, sc))
2179 {
2180 Address addr;
2181 // Parse all blocks if needed
2182 if (inlined_die)
2183 {
2184 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2185 assert (sc.block != NULL);
2186 if (sc.block->GetStartAddress (addr) == false)
2187 addr.Clear();
2188 }
2189 else
2190 {
2191 sc.block = NULL;
2192 addr = sc.function->GetAddressRange().GetBaseAddress();
2193 }
Greg Claytond7e05462010-11-14 00:22:48 +00002194
Greg Claytond4a2b372011-09-12 23:21:58 +00002195 if (addr.IsValid())
2196 {
2197
2198 // We found the function, so we should find the line table
2199 // and line table entry as well
2200 LineTable *line_table = sc.comp_unit->GetLineTable();
2201 if (line_table == NULL)
2202 {
2203 if (ParseCompileUnitLineTable(sc))
2204 line_table = sc.comp_unit->GetLineTable();
2205 }
2206 if (line_table != NULL)
2207 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2208
2209 sc_list.Append(sc);
2210 }
Greg Claytond7e05462010-11-14 00:22:48 +00002211 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002212 }
2213 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002214}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002215
Greg Claytonc685f8e2010-09-15 04:15:46 +00002216
2217void
2218SymbolFileDWARF::FindFunctions
2219(
2220 const RegularExpression &regex,
2221 const NameToDIE &name_to_die,
2222 SymbolContextList& sc_list
2223)
2224{
2225 DWARFDebugInfo* info = DebugInfo();
2226 if (info == NULL)
2227 return;
2228
2229 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002230 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002231 assert (sc.module_sp);
2232
Greg Claytond4a2b372011-09-12 23:21:58 +00002233 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002234 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002235 DIEArray die_offsets;
2236 const size_t num_matches = name_to_die.Find (regex, die_offsets);
2237 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002238 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002239 DWARFDebugInfo* debug_info = DebugInfo();
2240 for (size_t i=0; i<num_matches; ++i)
Greg Claytonab843392010-12-03 17:49:14 +00002241 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002242 const dw_offset_t die_offset = die_offsets[i];
2243 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2244
2245 const DWARFDebugInfoEntry* inlined_die = NULL;
2246 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Claytonab843392010-12-03 17:49:14 +00002247 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002248 inlined_die = die;
2249
2250 while ((die = die->GetParent()) != NULL)
Greg Claytonab843392010-12-03 17:49:14 +00002251 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002252 if (die->Tag() == DW_TAG_subprogram)
2253 break;
Greg Claytonab843392010-12-03 17:49:14 +00002254 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002255 }
2256 assert (die->Tag() == DW_TAG_subprogram);
2257 if (GetFunction (dwarf_cu, die, sc))
2258 {
2259 Address addr;
2260 // Parse all blocks if needed
2261 if (inlined_die)
2262 {
2263 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2264 assert (sc.block != NULL);
2265 if (sc.block->GetStartAddress (addr) == false)
2266 addr.Clear();
2267 }
2268 else
2269 {
2270 sc.block = NULL;
2271 addr = sc.function->GetAddressRange().GetBaseAddress();
2272 }
Greg Claytonab843392010-12-03 17:49:14 +00002273
Greg Claytond4a2b372011-09-12 23:21:58 +00002274 if (addr.IsValid())
2275 {
2276
2277 // We found the function, so we should find the line table
2278 // and line table entry as well
2279 LineTable *line_table = sc.comp_unit->GetLineTable();
2280 if (line_table == NULL)
2281 {
2282 if (ParseCompileUnitLineTable(sc))
2283 line_table = sc.comp_unit->GetLineTable();
2284 }
2285 if (line_table != NULL)
2286 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2287
2288 sc_list.Append(sc);
2289 }
Greg Claytonab843392010-12-03 17:49:14 +00002290 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002291 }
2292 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002293}
2294
2295uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002296SymbolFileDWARF::FindFunctions (const ConstString &name,
2297 uint32_t name_type_mask,
2298 bool append,
2299 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002300{
2301 Timer scoped_timer (__PRETTY_FUNCTION__,
2302 "SymbolFileDWARF::FindFunctions (name = '%s')",
2303 name.AsCString());
2304
Greg Clayton0c5cd902010-06-28 21:30:43 +00002305 // If we aren't appending the results to this list, then clear the list
2306 if (!append)
2307 sc_list.Clear();
2308
2309 // Remember how many sc_list are in the list before we search in case
2310 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002311
Greg Clayton9e315582011-09-02 04:03:59 +00002312 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002313
2314 // Index the DWARF if we haven't already
2315 if (!m_indexed)
2316 Index ();
2317
2318 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002319 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002320
2321 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002322 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002323
2324 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002325 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002326
2327 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002328 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002329
Greg Clayton4d01ace2011-09-29 16:58:15 +00002330 if (m_apple_names.IsValid())
2331 {
2332 SymbolContextList sc_list_apple;
2333 DIEArray die_offsets;
2334 const uint32_t num_matches = m_apple_names.Find(name.GetCString(), die_offsets);
2335 if (num_matches > 0)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002336 ResolveFunctions (die_offsets, sc_list_apple, name, name_type_mask);
Greg Clayton4d01ace2011-09-29 16:58:15 +00002337 if (sc_list != sc_list_apple)
2338 assert (!"__apple_names results differ from DWARF index results");
2339 }
2340
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002341 // Return the number of variable that were appended to the list
2342 return sc_list.GetSize() - original_size;
2343}
2344
2345
2346uint32_t
2347SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2348{
2349 Timer scoped_timer (__PRETTY_FUNCTION__,
2350 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2351 regex.GetText());
2352
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353 // If we aren't appending the results to this list, then clear the list
2354 if (!append)
2355 sc_list.Clear();
2356
2357 // Remember how many sc_list are in the list before we search in case
2358 // we are appending the results to a variable list.
2359 uint32_t original_size = sc_list.GetSize();
2360
2361 // Index the DWARF if we haven't already
2362 if (!m_indexed)
2363 Index ();
2364
Greg Claytonc685f8e2010-09-15 04:15:46 +00002365 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366
Greg Claytonc685f8e2010-09-15 04:15:46 +00002367 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002368
2369 // Return the number of variable that were appended to the list
2370 return sc_list.GetSize() - original_size;
2371}
Jim Ingham318c9f22011-08-26 19:44:13 +00002372
Greg Claytond16e1e52011-07-12 17:06:17 +00002373void
2374SymbolFileDWARF::ReportError (const char *format, ...)
2375{
2376 ::fprintf (stderr,
2377 "error: %s/%s ",
2378 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2379 m_obj_file->GetFileSpec().GetFilename().GetCString());
2380
2381 va_list args;
2382 va_start (args, format);
2383 vfprintf (stderr, format, args);
2384 va_end (args);
2385}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002386
Jim Inghamc1663042011-09-29 22:12:35 +00002387void
2388SymbolFileDWARF::ReportWarning (const char *format, ...)
2389{
2390 ::fprintf (stderr,
2391 "warning: %s/%s ",
2392 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2393 m_obj_file->GetFileSpec().GetFilename().GetCString());
2394
2395 va_list args;
2396 va_start (args, format);
2397 vfprintf (stderr, format, args);
2398 va_end (args);
2399}
2400
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002401uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002402SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002403{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002404 DWARFDebugInfo* info = DebugInfo();
2405 if (info == NULL)
2406 return 0;
2407
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002408 // If we aren't appending the results to this list, then clear the list
2409 if (!append)
2410 types.Clear();
2411
Greg Clayton6dbd3982010-09-15 05:51:24 +00002412 // Index if we already haven't to make sure the compile units
2413 // get indexed and make their global DIE index list
2414 if (!m_indexed)
2415 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002416
Greg Claytonc685f8e2010-09-15 04:15:46 +00002417 const uint32_t initial_types_size = types.GetSize();
Greg Claytond4a2b372011-09-12 23:21:58 +00002418 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002419 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002420 DIEArray die_offsets;
2421 const size_t num_matches = m_type_index.Find (name, die_offsets);
2422 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002424 DWARFDebugInfo* debug_info = DebugInfo();
2425 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002426 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002427 const dw_offset_t die_offset = die_offsets[i];
2428 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2429
2430 Type *matching_type = ResolveType (dwarf_cu, die);
2431 if (matching_type)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002432 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002433 // We found a type pointer, now find the shared pointer form our type list
2434 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
2435 if (type_sp)
2436 {
2437 types.InsertUnique (type_sp);
2438 if (types.GetSize() >= max_matches)
2439 break;
2440 }
2441 else
2442 {
Jim Inghamc1663042011-09-29 22:12:35 +00002443 ReportError ("error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID());
Greg Claytond4a2b372011-09-12 23:21:58 +00002444 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00002445 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002446 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002447 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002448 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002449}
2450
2451
Greg Clayton526e5af2010-11-13 03:52:47 +00002452ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002453SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2454 const ConstString &name)
2455{
Greg Clayton526e5af2010-11-13 03:52:47 +00002456 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002457 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002458 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002459 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002460 // Index if we already haven't to make sure the compile units
2461 // get indexed and make their global DIE index list
2462 if (!m_indexed)
2463 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002464
Greg Claytond4a2b372011-09-12 23:21:58 +00002465
2466 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00002467 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002468 DIEArray die_offsets;
2469 const size_t num_matches = m_namespace_index.Find (name, die_offsets);
2470 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00002471 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002472 DWARFDebugInfo* debug_info = DebugInfo();
2473 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00002474 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002475 const dw_offset_t die_offset = die_offsets[i];
2476 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2477
2478 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
2479 if (clang_namespace_decl)
2480 {
2481 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2482 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2483 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002484 }
2485 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002486 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002487 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002488}
2489
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002490uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002491SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002492{
2493 // Remember how many sc_list are in the list before we search in case
2494 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002495 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002496
2497 const uint32_t num_die_offsets = die_offsets.size();
2498 // Parse all of the types we found from the pubtypes matches
2499 uint32_t i;
2500 uint32_t num_matches = 0;
2501 for (i = 0; i < num_die_offsets; ++i)
2502 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002503 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2504 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002505 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002506 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002507 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002508 assert (type_sp.get() != NULL);
2509 types.InsertUnique (type_sp);
2510 ++num_matches;
2511 if (num_matches >= max_matches)
2512 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002513 }
2514 }
2515
2516 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002517 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002518}
2519
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002520
2521size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00002522SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
2523 clang::DeclContext *containing_decl_ctx,
2524 TypeSP& type_sp,
2525 DWARFCompileUnit* dwarf_cu,
2526 const DWARFDebugInfoEntry *parent_die,
2527 bool skip_artificial,
2528 bool &is_static,
2529 TypeList* type_list,
2530 std::vector<clang_type_t>& function_param_types,
2531 std::vector<clang::ParmVarDecl*>& function_param_decls,
2532 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002533{
2534 if (parent_die == NULL)
2535 return 0;
2536
Greg Claytond88d7592010-09-15 08:33:30 +00002537 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2538
Greg Clayton7fedea22010-11-16 02:10:54 +00002539 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002540 const DWARFDebugInfoEntry *die;
2541 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2542 {
2543 dw_tag_t tag = die->Tag();
2544 switch (tag)
2545 {
2546 case DW_TAG_formal_parameter:
2547 {
2548 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002549 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002550 if (num_attributes > 0)
2551 {
2552 const char *name = NULL;
2553 Declaration decl;
2554 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002555 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002556 // one of None, Auto, Register, Extern, Static, PrivateExtern
2557
Sean Callanane2ef6e32010-09-23 03:01:22 +00002558 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002559 uint32_t i;
2560 for (i=0; i<num_attributes; ++i)
2561 {
2562 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2563 DWARFFormValue form_value;
2564 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2565 {
2566 switch (attr)
2567 {
2568 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2569 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2570 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2571 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2572 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002573 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002574 case DW_AT_location:
2575 // if (form_value.BlockData())
2576 // {
2577 // const DataExtractor& debug_info_data = debug_info();
2578 // uint32_t block_length = form_value.Unsigned();
2579 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2580 // }
2581 // else
2582 // {
2583 // }
2584 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002585 case DW_AT_const_value:
2586 case DW_AT_default_value:
2587 case DW_AT_description:
2588 case DW_AT_endianity:
2589 case DW_AT_is_optional:
2590 case DW_AT_segment:
2591 case DW_AT_variable_parameter:
2592 default:
2593 case DW_AT_abstract_origin:
2594 case DW_AT_sibling:
2595 break;
2596 }
2597 }
2598 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002599
Greg Clayton0fffff52010-09-24 05:15:53 +00002600 bool skip = false;
2601 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002602 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002603 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002604 {
2605 // In order to determine if a C++ member function is
2606 // "const" we have to look at the const-ness of "this"...
2607 // Ugly, but that
2608 if (arg_idx == 0)
2609 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002610 if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord)
Sean Callanan763d72a2011-08-02 22:21:50 +00002611 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002612 // Often times compilers omit the "this" name for the
2613 // specification DIEs, so we can't rely upon the name
2614 // being in the formal parameter DIE...
2615 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00002616 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002617 Type *this_type = ResolveTypeUID (param_type_die_offset);
2618 if (this_type)
2619 {
2620 uint32_t encoding_mask = this_type->GetEncodingMask();
2621 if (encoding_mask & Type::eEncodingIsPointerUID)
2622 {
2623 is_static = false;
2624
2625 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
2626 type_quals |= clang::Qualifiers::Const;
2627 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
2628 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002629 }
2630 }
2631 }
2632 }
2633 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002634 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002635 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002636 else
2637 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002638
Greg Clayton0fffff52010-09-24 05:15:53 +00002639 // HACK: Objective C formal parameters "self" and "_cmd"
2640 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002641 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2642 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002643 {
2644 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2645 skip = true;
2646 }
2647 }
2648 }
2649
2650 if (!skip)
2651 {
2652 Type *type = ResolveTypeUID(param_type_die_offset);
2653 if (type)
2654 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002655 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002656
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002657 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002658 assert(param_var_decl);
2659 function_param_decls.push_back(param_var_decl);
2660 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002661 }
2662 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002663 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664 }
2665 break;
2666
2667 default:
2668 break;
2669 }
2670 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002671 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002672}
2673
2674size_t
2675SymbolFileDWARF::ParseChildEnumerators
2676(
2677 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002678 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002679 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002680 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002681 const DWARFDebugInfoEntry *parent_die
2682)
2683{
2684 if (parent_die == NULL)
2685 return 0;
2686
2687 size_t enumerators_added = 0;
2688 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002689 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002691 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2692 {
2693 const dw_tag_t tag = die->Tag();
2694 if (tag == DW_TAG_enumerator)
2695 {
2696 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002697 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002698 if (num_child_attributes > 0)
2699 {
2700 const char *name = NULL;
2701 bool got_value = false;
2702 int64_t enum_value = 0;
2703 Declaration decl;
2704
2705 uint32_t i;
2706 for (i=0; i<num_child_attributes; ++i)
2707 {
2708 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2709 DWARFFormValue form_value;
2710 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2711 {
2712 switch (attr)
2713 {
2714 case DW_AT_const_value:
2715 got_value = true;
2716 enum_value = form_value.Unsigned();
2717 break;
2718
2719 case DW_AT_name:
2720 name = form_value.AsCString(&get_debug_str_data());
2721 break;
2722
2723 case DW_AT_description:
2724 default:
2725 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2726 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2727 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2728 case DW_AT_sibling:
2729 break;
2730 }
2731 }
2732 }
2733
2734 if (name && name[0] && got_value)
2735 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002736 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2737 enumerator_clang_type,
2738 decl,
2739 name,
2740 enum_value,
2741 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002742 ++enumerators_added;
2743 }
2744 }
2745 }
2746 }
2747 return enumerators_added;
2748}
2749
2750void
2751SymbolFileDWARF::ParseChildArrayInfo
2752(
2753 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002754 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002755 const DWARFDebugInfoEntry *parent_die,
2756 int64_t& first_index,
2757 std::vector<uint64_t>& element_orders,
2758 uint32_t& byte_stride,
2759 uint32_t& bit_stride
2760)
2761{
2762 if (parent_die == NULL)
2763 return;
2764
2765 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002766 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002767 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2768 {
2769 const dw_tag_t tag = die->Tag();
2770 switch (tag)
2771 {
2772 case DW_TAG_enumerator:
2773 {
2774 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002775 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002776 if (num_child_attributes > 0)
2777 {
2778 const char *name = NULL;
2779 bool got_value = false;
2780 int64_t enum_value = 0;
2781
2782 uint32_t i;
2783 for (i=0; i<num_child_attributes; ++i)
2784 {
2785 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2786 DWARFFormValue form_value;
2787 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2788 {
2789 switch (attr)
2790 {
2791 case DW_AT_const_value:
2792 got_value = true;
2793 enum_value = form_value.Unsigned();
2794 break;
2795
2796 case DW_AT_name:
2797 name = form_value.AsCString(&get_debug_str_data());
2798 break;
2799
2800 case DW_AT_description:
2801 default:
2802 case DW_AT_decl_file:
2803 case DW_AT_decl_line:
2804 case DW_AT_decl_column:
2805 case DW_AT_sibling:
2806 break;
2807 }
2808 }
2809 }
2810 }
2811 }
2812 break;
2813
2814 case DW_TAG_subrange_type:
2815 {
2816 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002817 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002818 if (num_child_attributes > 0)
2819 {
2820 const char *name = NULL;
2821 bool got_value = false;
2822 uint64_t byte_size = 0;
2823 int64_t enum_value = 0;
2824 uint64_t num_elements = 0;
2825 uint64_t lower_bound = 0;
2826 uint64_t upper_bound = 0;
2827 uint32_t i;
2828 for (i=0; i<num_child_attributes; ++i)
2829 {
2830 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2831 DWARFFormValue form_value;
2832 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2833 {
2834 switch (attr)
2835 {
2836 case DW_AT_const_value:
2837 got_value = true;
2838 enum_value = form_value.Unsigned();
2839 break;
2840
2841 case DW_AT_name:
2842 name = form_value.AsCString(&get_debug_str_data());
2843 break;
2844
2845 case DW_AT_count:
2846 num_elements = form_value.Unsigned();
2847 break;
2848
2849 case DW_AT_bit_stride:
2850 bit_stride = form_value.Unsigned();
2851 break;
2852
2853 case DW_AT_byte_stride:
2854 byte_stride = form_value.Unsigned();
2855 break;
2856
2857 case DW_AT_byte_size:
2858 byte_size = form_value.Unsigned();
2859 break;
2860
2861 case DW_AT_lower_bound:
2862 lower_bound = form_value.Unsigned();
2863 break;
2864
2865 case DW_AT_upper_bound:
2866 upper_bound = form_value.Unsigned();
2867 break;
2868
2869 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002870 case DW_AT_abstract_origin:
2871 case DW_AT_accessibility:
2872 case DW_AT_allocated:
2873 case DW_AT_associated:
2874 case DW_AT_data_location:
2875 case DW_AT_declaration:
2876 case DW_AT_description:
2877 case DW_AT_sibling:
2878 case DW_AT_threads_scaled:
2879 case DW_AT_type:
2880 case DW_AT_visibility:
2881 break;
2882 }
2883 }
2884 }
2885
2886 if (upper_bound > lower_bound)
2887 num_elements = upper_bound - lower_bound + 1;
2888
2889 if (num_elements > 0)
2890 element_orders.push_back (num_elements);
2891 }
2892 }
2893 break;
2894 }
2895 }
2896}
2897
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002898TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002899SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002900{
2901 TypeSP type_sp;
2902 if (die != NULL)
2903 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002904 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002905 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002906 if (type_ptr == NULL)
2907 {
Greg Claytonca512b32011-01-14 04:54:56 +00002908 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
2909 assert (lldb_cu);
2910 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00002911 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002912 }
2913 else if (type_ptr != DIE_IS_BEING_PARSED)
2914 {
2915 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002916 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917 }
2918
2919 }
2920 return type_sp;
2921}
2922
2923clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002924SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002925{
2926 if (die_offset != DW_INVALID_OFFSET)
2927 {
2928 DWARFCompileUnitSP cu_sp;
2929 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Sean Callanan72e49402011-08-05 23:43:37 +00002930 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002931 }
2932 return NULL;
2933}
2934
Sean Callanan72e49402011-08-05 23:43:37 +00002935clang::DeclContext *
2936SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
2937{
2938 if (die_offset != DW_INVALID_OFFSET)
2939 {
2940 DWARFCompileUnitSP cu_sp;
2941 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2942 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
2943 }
2944 return NULL;
2945}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002946
Greg Clayton96d7d742010-11-10 23:42:09 +00002947clang::NamespaceDecl *
2948SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2949{
2950 if (die->Tag() == DW_TAG_namespace)
2951 {
2952 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2953 if (namespace_name)
2954 {
2955 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002956 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent()));
Greg Clayton96d7d742010-11-10 23:42:09 +00002957 if (namespace_decl)
Greg Claytona2721472011-06-25 00:44:06 +00002958 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Clayton96d7d742010-11-10 23:42:09 +00002959 return namespace_decl;
2960 }
2961 }
2962 return NULL;
2963}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002964
2965clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002966SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2967{
2968 // If this DIE has a specification, or an abstract origin, then trace to those.
2969
2970 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
2971 if (die_offset != DW_INVALID_OFFSET)
2972 return GetClangDeclContextForDIEOffset (sc, die_offset);
2973
2974 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
2975 if (die_offset != DW_INVALID_OFFSET)
2976 return GetClangDeclContextForDIEOffset (sc, die_offset);
2977
2978 // This is the DIE we want. Parse it, then query our map.
2979
2980 ParseType(sc, curr_cu, die, NULL);
2981
2982 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2983 if (pos != m_die_to_decl_ctx.end())
2984 return pos->second;
2985 else
2986 return NULL;
2987}
2988
2989clang::DeclContext *
Greg Clayton2bc22f82011-09-30 03:20:47 +00002990SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002991{
Greg Claytonca512b32011-01-14 04:54:56 +00002992 if (m_clang_tu_decl == NULL)
2993 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002994
Greg Clayton2bc22f82011-09-30 03:20:47 +00002995 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2996
2997 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002998 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002999 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3000 if (pos != m_die_to_decl_ctx.end())
3001 return pos->second;
3002
3003 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003004 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003005 case DW_TAG_compile_unit:
3006 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003007
Greg Clayton2bc22f82011-09-30 03:20:47 +00003008 case DW_TAG_namespace:
Greg Claytonca512b32011-01-14 04:54:56 +00003009 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003010 const char *namespace_name = decl_ctx_die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL);
3011 if (namespace_name)
Greg Claytonca512b32011-01-14 04:54:56 +00003012 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003013 Declaration decl; // TODO: fill in the decl object
3014 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (cu, decl_ctx_die));
3015 if (namespace_decl)
3016 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, decl_ctx_die);
3017 return namespace_decl;
3018 }
3019 }
3020 break;
3021
3022 case DW_TAG_structure_type:
3023 case DW_TAG_union_type:
3024 case DW_TAG_class_type:
3025 {
3026 Type* type = ResolveType (cu, decl_ctx_die);
3027 if (type)
3028 {
3029 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3030 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003031 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003032 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3033 if (decl_ctx)
3034 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003035 }
3036 }
Greg Claytonca512b32011-01-14 04:54:56 +00003037 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003038 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039
Greg Clayton2bc22f82011-09-30 03:20:47 +00003040 default:
3041 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003042 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003043 }
Greg Clayton7a345282010-11-09 23:46:37 +00003044 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003045}
3046
Greg Clayton2bc22f82011-09-30 03:20:47 +00003047
3048const DWARFDebugInfoEntry *
3049SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3050{
3051 if (cu && die)
3052 {
3053 const DWARFDebugInfoEntry * const decl_die = die;
3054
3055 while (die != NULL)
3056 {
3057 // If this is the original DIE that we are searching for a declaration
3058 // for, then don't look in the cache as we don't want our own decl
3059 // context to be our decl context...
3060 if (decl_die != die)
3061 {
3062 switch (die->Tag())
3063 {
3064 case DW_TAG_compile_unit:
3065 case DW_TAG_namespace:
3066 case DW_TAG_structure_type:
3067 case DW_TAG_union_type:
3068 case DW_TAG_class_type:
3069 return die;
3070
3071 default:
3072 break;
3073 }
3074 }
3075
3076 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3077 if (die_offset != DW_INVALID_OFFSET)
3078 {
3079 DWARFCompileUnit *spec_cu = cu;
3080 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3081 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3082 if (spec_die_decl_ctx_die)
3083 return spec_die_decl_ctx_die;
3084 }
3085
3086 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3087 if (die_offset != DW_INVALID_OFFSET)
3088 {
3089 DWARFCompileUnit *abs_cu = cu;
3090 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3091 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3092 if (abs_die_decl_ctx_die)
3093 return abs_die_decl_ctx_die;
3094 }
3095
3096 die = die->GetParent();
3097 }
3098 }
3099 return NULL;
3100}
3101
3102
3103
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003104// This function can be used when a DIE is found that is a forward declaration
3105// DIE and we want to try and find a type that has the complete definition.
3106TypeSP
3107SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton1a65ae12011-01-25 23:55:37 +00003108 DWARFCompileUnit* cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003109 const DWARFDebugInfoEntry *die,
3110 const ConstString &type_name
3111)
3112{
3113 TypeSP type_sp;
3114
Greg Clayton1a65ae12011-01-25 23:55:37 +00003115 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003116 return type_sp;
3117
Greg Clayton69974892010-12-03 21:42:06 +00003118 if (!m_indexed)
3119 Index ();
3120
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003121 const dw_tag_t type_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00003122
3123 DWARFCompileUnit* type_cu = NULL;
3124 const DWARFDebugInfoEntry* type_die = NULL;
3125 DIEArray die_offsets;
3126 const size_t num_matches = m_type_index.Find (type_name, die_offsets);
3127 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003128 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003129 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003130 for (size_t i=0; i<num_matches; ++i)
3131 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003132 const dw_offset_t die_offset = die_offsets[i];
3133 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003134
3135 if (type_die != die && type_die->Tag() == type_tag)
3136 {
3137 // Hold off on comparing parent DIE tags until
3138 // we know what happens with stuff in namespaces
3139 // for gcc and clang...
3140 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3141 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3142 //if (parent_die->Tag() == parent_type_die->Tag())
3143 {
3144 Type *resolved_type = ResolveType (type_cu, type_die, false);
3145 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3146 {
3147 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
3148 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00003149 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003150 m_obj_file->GetFileSpec().GetFilename().AsCString(),
3151 type_die->GetOffset(),
3152 type_cu->GetOffset());
3153
3154 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003155 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00003156 if (!type_sp)
3157 {
3158 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
3159 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003160 break;
3161 }
3162 }
3163 }
3164 }
3165 }
3166 return type_sp;
3167}
3168
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003169TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003170SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003171{
3172 TypeSP type_sp;
3173
Greg Clayton1be10fc2010-09-29 01:12:09 +00003174 if (type_is_new_ptr)
3175 *type_is_new_ptr = false;
3176
Sean Callananc7fbf732010-08-06 00:32:49 +00003177 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003178 if (die != NULL)
3179 {
Jim Ingham16746d12011-08-25 23:21:43 +00003180 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3181 if (log && dwarf_cu)
3182 {
Jim Ingham318c9f22011-08-26 19:44:13 +00003183 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00003184 die->DumpLocation (this, dwarf_cu, s);
Jim Ingham318c9f22011-08-26 19:44:13 +00003185 log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
3186
Jim Ingham16746d12011-08-25 23:21:43 +00003187 }
3188
Greg Clayton594e5ed2010-09-27 21:07:38 +00003189 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003190 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003191 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003192 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003193 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003194 if (type_is_new_ptr)
3195 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003196
Greg Clayton594e5ed2010-09-27 21:07:38 +00003197 const dw_tag_t tag = die->Tag();
3198
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003199 bool is_forward_declaration = false;
3200 DWARFDebugInfoEntry::Attributes attributes;
3201 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003202 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003203 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3204 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003205 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003206 Declaration decl;
3207
Greg Clayton4957bf62010-09-30 21:49:03 +00003208 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003209 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003211 dw_attr_t attr;
3212
3213 switch (tag)
3214 {
3215 case DW_TAG_base_type:
3216 case DW_TAG_pointer_type:
3217 case DW_TAG_reference_type:
3218 case DW_TAG_typedef:
3219 case DW_TAG_const_type:
3220 case DW_TAG_restrict_type:
3221 case DW_TAG_volatile_type:
3222 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003223 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003224 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003225
Greg Claytond88d7592010-09-15 08:33:30 +00003226 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003227 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003228 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3229
3230 if (num_attributes > 0)
3231 {
3232 uint32_t i;
3233 for (i=0; i<num_attributes; ++i)
3234 {
3235 attr = attributes.AttributeAtIndex(i);
3236 DWARFFormValue form_value;
3237 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3238 {
3239 switch (attr)
3240 {
3241 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3242 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3243 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3244 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003245
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003246 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003247 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3248 // include the "&"...
3249 if (tag == DW_TAG_reference_type)
3250 {
3251 if (strchr (type_name_cstr, '&') == NULL)
3252 type_name_cstr = NULL;
3253 }
3254 if (type_name_cstr)
3255 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003256 break;
Greg Clayton36909642011-03-15 04:38:20 +00003257 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003258 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3259 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3260 default:
3261 case DW_AT_sibling:
3262 break;
3263 }
3264 }
3265 }
3266 }
3267
Greg Claytonc93237c2010-10-01 20:48:32 +00003268 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);
3269
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003270 switch (tag)
3271 {
3272 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003273 break;
3274
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003275 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003276 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003277 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3278 encoding,
3279 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003280 break;
3281
Greg Clayton526e5af2010-11-13 03:52:47 +00003282 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3283 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3284 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3285 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3286 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3287 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003288 }
3289
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003290 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3291 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3292 {
3293 static ConstString g_objc_type_name_id("id");
3294 static ConstString g_objc_type_name_Class("Class");
3295 static ConstString g_objc_type_name_selector("SEL");
3296
Greg Clayton24739922010-10-13 03:15:28 +00003297 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003298 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003299 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003300 resolve_state = Type::eResolveStateFull;
3301
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003302 }
Greg Clayton24739922010-10-13 03:15:28 +00003303 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003304 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003305 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003306 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003307 }
Greg Clayton24739922010-10-13 03:15:28 +00003308 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003309 {
Sean Callananf6c73082010-12-06 23:53:20 +00003310 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003311 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003312 }
3313 }
3314
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003315 type_sp.reset( new Type (die->GetOffset(),
3316 this,
3317 type_name_const_str,
3318 byte_size,
3319 NULL,
3320 encoding_uid,
3321 encoding_data_type,
3322 &decl,
3323 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003324 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003325
Greg Clayton594e5ed2010-09-27 21:07:38 +00003326 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003327
3328// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3329// if (encoding_type != NULL)
3330// {
3331// if (encoding_type != DIE_IS_BEING_PARSED)
3332// type_sp->SetEncodingType(encoding_type);
3333// else
3334// m_indirect_fixups.push_back(type_sp.get());
3335// }
3336 }
3337 break;
3338
3339 case DW_TAG_structure_type:
3340 case DW_TAG_union_type:
3341 case DW_TAG_class_type:
3342 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003343 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003344 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003345
Greg Clayton9e409562010-07-28 02:04:09 +00003346 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003347 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003348 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003349 if (num_attributes > 0)
3350 {
3351 uint32_t i;
3352 for (i=0; i<num_attributes; ++i)
3353 {
3354 attr = attributes.AttributeAtIndex(i);
3355 DWARFFormValue form_value;
3356 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3357 {
3358 switch (attr)
3359 {
Greg Clayton9e409562010-07-28 02:04:09 +00003360 case DW_AT_decl_file:
3361 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3362 break;
3363
3364 case DW_AT_decl_line:
3365 decl.SetLine(form_value.Unsigned());
3366 break;
3367
3368 case DW_AT_decl_column:
3369 decl.SetColumn(form_value.Unsigned());
3370 break;
3371
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003372 case DW_AT_name:
3373 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003374 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003375 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003376
3377 case DW_AT_byte_size:
3378 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00003379 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00003380 break;
3381
3382 case DW_AT_accessibility:
3383 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3384 break;
3385
3386 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003387 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003388 break;
3389
3390 case DW_AT_APPLE_runtime_class:
3391 class_language = (LanguageType)form_value.Signed();
3392 break;
3393
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003394 case DW_AT_allocated:
3395 case DW_AT_associated:
3396 case DW_AT_data_location:
3397 case DW_AT_description:
3398 case DW_AT_start_scope:
3399 case DW_AT_visibility:
3400 default:
3401 case DW_AT_sibling:
3402 break;
3403 }
3404 }
3405 }
3406 }
3407
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003408 UniqueDWARFASTType unique_ast_entry;
3409 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003410 {
Greg Claytone576ab22011-02-15 00:19:15 +00003411 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00003412 this,
3413 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00003414 die,
3415 decl,
Greg Clayton36909642011-03-15 04:38:20 +00003416 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00003417 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003418 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003419 // We have already parsed this type or from another
3420 // compile unit. GCC loves to use the "one definition
3421 // rule" which can result in multiple definitions
3422 // of the same class over and over in each compile
3423 // unit.
3424 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003425 if (type_sp)
3426 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003427 m_die_to_type[die] = type_sp.get();
3428 return type_sp;
3429 }
3430 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003431 }
3432
3433 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3434
3435 int tag_decl_kind = -1;
3436 AccessType default_accessibility = eAccessNone;
3437 if (tag == DW_TAG_structure_type)
3438 {
3439 tag_decl_kind = clang::TTK_Struct;
3440 default_accessibility = eAccessPublic;
3441 }
3442 else if (tag == DW_TAG_union_type)
3443 {
3444 tag_decl_kind = clang::TTK_Union;
3445 default_accessibility = eAccessPublic;
3446 }
3447 else if (tag == DW_TAG_class_type)
3448 {
3449 tag_decl_kind = clang::TTK_Class;
3450 default_accessibility = eAccessPrivate;
3451 }
3452
3453
3454 if (is_forward_declaration)
3455 {
3456 // We have a forward declaration to a type and we need
3457 // to try and find a full declaration. We look in the
3458 // current type index just in case we have a forward
3459 // declaration followed by an actual declarations in the
3460 // DWARF. If this fails, we need to look elsewhere...
3461
3462 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3463
3464 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00003465 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003466 // We weren't able to find a full declaration in
3467 // this DWARF, see if we have a declaration anywhere
3468 // else...
3469 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00003470 }
3471
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003472 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00003473 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003474 // We found a real definition for this type elsewhere
3475 // so lets use it and cache the fact that we found
3476 // a complete type for this die
3477 m_die_to_type[die] = type_sp.get();
3478 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003479 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003480 }
3481 assert (tag_decl_kind != -1);
3482 bool clang_type_was_created = false;
3483 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3484 if (clang_type == NULL)
3485 {
3486 clang_type_was_created = true;
3487 clang_type = ast.CreateRecordType (type_name_cstr,
3488 tag_decl_kind,
Sean Callanan72e49402011-08-05 23:43:37 +00003489 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003490 class_language);
3491 }
3492
3493 // Store a forward declaration to this class type in case any
3494 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00003495 // types for function prototypes.
3496 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003497 type_sp.reset (new Type (die->GetOffset(),
3498 this,
3499 type_name_const_str,
3500 byte_size,
3501 NULL,
3502 LLDB_INVALID_UID,
3503 Type::eEncodingIsUID,
3504 &decl,
3505 clang_type,
3506 Type::eResolveStateForward));
3507
3508
3509 // Add our type to the unique type map so we don't
3510 // end up creating many copies of the same type over
3511 // and over in the ASTContext for our module
3512 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00003513 unique_ast_entry.m_symfile = this;
3514 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003515 unique_ast_entry.m_die = die;
3516 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00003517 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
3518 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003519
3520 if (die->HasChildren() == false && is_forward_declaration == false)
3521 {
3522 // No children for this struct/union/class, lets finish it
3523 ast.StartTagDeclarationDefinition (clang_type);
3524 ast.CompleteTagDeclarationDefinition (clang_type);
3525 }
3526 else if (clang_type_was_created)
3527 {
3528 // Leave this as a forward declaration until we need
3529 // to know the details of the type. lldb_private::Type
3530 // will automatically call the SymbolFile virtual function
3531 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3532 // When the definition needs to be defined.
3533 m_forward_decl_die_to_clang_type[die] = clang_type;
3534 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
3535 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00003536 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003537 }
3538 break;
3539
3540 case DW_TAG_enumeration_type:
3541 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003542 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003543 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003544
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003545 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003546
Greg Claytond88d7592010-09-15 08:33:30 +00003547 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003548 if (num_attributes > 0)
3549 {
3550 uint32_t i;
3551
3552 for (i=0; i<num_attributes; ++i)
3553 {
3554 attr = attributes.AttributeAtIndex(i);
3555 DWARFFormValue form_value;
3556 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3557 {
3558 switch (attr)
3559 {
Greg Clayton7a345282010-11-09 23:46:37 +00003560 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3561 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3562 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003563 case DW_AT_name:
3564 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003565 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003566 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003567 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003568 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00003569 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3570 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003571 case DW_AT_allocated:
3572 case DW_AT_associated:
3573 case DW_AT_bit_stride:
3574 case DW_AT_byte_stride:
3575 case DW_AT_data_location:
3576 case DW_AT_description:
3577 case DW_AT_start_scope:
3578 case DW_AT_visibility:
3579 case DW_AT_specification:
3580 case DW_AT_abstract_origin:
3581 case DW_AT_sibling:
3582 break;
3583 }
3584 }
3585 }
3586
Greg Claytonc93237c2010-10-01 20:48:32 +00003587 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3588
Greg Clayton1be10fc2010-09-29 01:12:09 +00003589 clang_type_t enumerator_clang_type = NULL;
3590 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3591 if (clang_type == NULL)
3592 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003593 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3594 DW_ATE_signed,
3595 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00003596 clang_type = ast.CreateEnumerationType (type_name_cstr,
Sean Callanan72e49402011-08-05 23:43:37 +00003597 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Claytonca512b32011-01-14 04:54:56 +00003598 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003599 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003600 }
3601 else
3602 {
3603 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3604 assert (enumerator_clang_type != NULL);
3605 }
3606
Greg Claytona2721472011-06-25 00:44:06 +00003607 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
3608
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003609 type_sp.reset( new Type (die->GetOffset(),
3610 this,
3611 type_name_const_str,
3612 byte_size,
3613 NULL,
3614 encoding_uid,
3615 Type::eEncodingIsUID,
3616 &decl,
3617 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003618 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003619
Greg Clayton6beaaa62011-01-17 03:46:26 +00003620#if LEAVE_ENUMS_FORWARD_DECLARED
Greg Clayton1be10fc2010-09-29 01:12:09 +00003621 // Leave this as a forward declaration until we need
3622 // to know the details of the type. lldb_private::Type
3623 // will automatically call the SymbolFile virtual function
3624 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3625 // When the definition needs to be defined.
3626 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003627 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003628 ClangASTContext::SetHasExternalStorage (clang_type, true);
3629#else
3630 ast.StartTagDeclarationDefinition (clang_type);
3631 if (die->HasChildren())
3632 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003633 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
3634 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00003635 }
3636 ast.CompleteTagDeclarationDefinition (clang_type);
3637#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003638 }
3639 }
3640 break;
3641
Jim Inghamb0be4422010-08-12 01:20:14 +00003642 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003643 case DW_TAG_subprogram:
3644 case DW_TAG_subroutine_type:
3645 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003646 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003647 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003648
3649 const char *mangled = NULL;
3650 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003651 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003652 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003653 bool is_static = false;
3654 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003655 bool is_explicit = false;
Greg Clayton72da3972011-08-16 18:40:23 +00003656 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
3657 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00003658
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003659 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003660 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661
3662
Greg Claytond88d7592010-09-15 08:33:30 +00003663 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003664 if (num_attributes > 0)
3665 {
3666 uint32_t i;
3667 for (i=0; i<num_attributes; ++i)
3668 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003669 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003670 DWARFFormValue form_value;
3671 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3672 {
3673 switch (attr)
3674 {
3675 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3676 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3677 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3678 case DW_AT_name:
3679 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003680 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003681 break;
3682
3683 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3684 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003685 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003686 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003687 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3688 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003689 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3690
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003691 case DW_AT_external:
3692 if (form_value.Unsigned())
3693 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003694 if (storage == clang::SC_None)
3695 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003696 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003697 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003698 }
3699 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003700
Greg Clayton72da3972011-08-16 18:40:23 +00003701 case DW_AT_specification:
3702 specification_die_offset = form_value.Reference(dwarf_cu);
3703 break;
3704
3705 case DW_AT_abstract_origin:
3706 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
3707 break;
3708
3709
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003710 case DW_AT_allocated:
3711 case DW_AT_associated:
3712 case DW_AT_address_class:
3713 case DW_AT_artificial:
3714 case DW_AT_calling_convention:
3715 case DW_AT_data_location:
3716 case DW_AT_elemental:
3717 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003718 case DW_AT_frame_base:
3719 case DW_AT_high_pc:
3720 case DW_AT_low_pc:
3721 case DW_AT_object_pointer:
3722 case DW_AT_prototyped:
3723 case DW_AT_pure:
3724 case DW_AT_ranges:
3725 case DW_AT_recursive:
3726 case DW_AT_return_addr:
3727 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003728 case DW_AT_start_scope:
3729 case DW_AT_static_link:
3730 case DW_AT_trampoline:
3731 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003732 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003733 case DW_AT_description:
3734 case DW_AT_sibling:
3735 break;
3736 }
3737 }
3738 }
Greg Clayton24739922010-10-13 03:15:28 +00003739 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740
Greg Clayton24739922010-10-13 03:15:28 +00003741 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 +00003742
Greg Clayton24739922010-10-13 03:15:28 +00003743 clang_type_t return_clang_type = NULL;
3744 Type *func_type = NULL;
3745
3746 if (type_die_offset != DW_INVALID_OFFSET)
3747 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003748
Greg Clayton24739922010-10-13 03:15:28 +00003749 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003750 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003751 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003752 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003753
Greg Claytonf51de672010-10-01 02:31:07 +00003754
Greg Clayton24739922010-10-13 03:15:28 +00003755 std::vector<clang_type_t> function_param_types;
3756 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003757
Greg Clayton24739922010-10-13 03:15:28 +00003758 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00003759
Greg Clayton5113dc82011-08-12 06:47:54 +00003760 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
3761 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
3762
3763 const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord;
3764 // Start off static. This will be set to false in ParseChildParameters(...)
3765 // if we find a "this" paramters as the first parameter
3766 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00003767 is_static = true;
3768
Greg Clayton24739922010-10-13 03:15:28 +00003769 if (die->HasChildren())
3770 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003771 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003772 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00003773 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003774 type_sp,
3775 dwarf_cu,
3776 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00003777 skip_artificial,
3778 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003779 type_list,
3780 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003781 function_param_decls,
3782 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003784
Greg Clayton24739922010-10-13 03:15:28 +00003785 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003786 clang_type = ast.CreateFunctionType (return_clang_type,
3787 &function_param_types[0],
3788 function_param_types.size(),
3789 is_variadic,
3790 type_quals);
3791
Greg Clayton24739922010-10-13 03:15:28 +00003792 if (type_name_cstr)
3793 {
3794 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00003795 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003796 {
Jim Inghamb7f6b2f2011-09-08 22:13:49 +00003797 if (ObjCLanguageRuntime::IsPossibleObjCMethodName (type_name_cstr))
Greg Clayton0fffff52010-09-24 05:15:53 +00003798 {
Greg Clayton24739922010-10-13 03:15:28 +00003799 // We need to find the DW_TAG_class_type or
3800 // DW_TAG_struct_type by name so we can add this
3801 // as a member function of the class.
3802 const char *class_name_start = type_name_cstr + 2;
3803 const char *class_name_end = ::strchr (class_name_start, ' ');
3804 SymbolContext empty_sc;
3805 clang_type_t class_opaque_type = NULL;
3806 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003807 {
Greg Clayton24739922010-10-13 03:15:28 +00003808 ConstString class_name (class_name_start, class_name_end - class_name_start);
3809 TypeList types;
3810 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3811 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003812 {
Greg Clayton24739922010-10-13 03:15:28 +00003813 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003814 {
Greg Clayton24739922010-10-13 03:15:28 +00003815 Type *type = types.GetTypeAtIndex (i).get();
3816 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3817 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003818 {
Greg Clayton24739922010-10-13 03:15:28 +00003819 class_opaque_type = type_clang_forward_type;
3820 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003821 }
3822 }
3823 }
Greg Clayton24739922010-10-13 03:15:28 +00003824 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003825
Greg Clayton24739922010-10-13 03:15:28 +00003826 if (class_opaque_type)
3827 {
3828 // If accessibility isn't set to anything valid, assume public for
3829 // now...
3830 if (accessibility == eAccessNone)
3831 accessibility = eAccessPublic;
3832
3833 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003834 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3835 type_name_cstr,
3836 clang_type,
3837 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003838 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00003839 type_handled = objc_method_decl != NULL;
3840 }
3841 }
Greg Clayton5113dc82011-08-12 06:47:54 +00003842 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00003843 {
3844 // Look at the parent of this DIE and see if is is
3845 // a class or struct and see if this is actually a
3846 // C++ method
Greg Clayton5113dc82011-08-12 06:47:54 +00003847 Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]);
Greg Clayton24739922010-10-13 03:15:28 +00003848 if (class_type)
3849 {
Greg Clayton72da3972011-08-16 18:40:23 +00003850 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00003851 {
Greg Clayton72da3972011-08-16 18:40:23 +00003852 // If we have a specification, then the function type should have been
3853 // made with the specification and not with this die.
3854 DWARFCompileUnitSP spec_cu_sp;
3855 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
3856 if (m_die_to_decl_ctx[spec_die] == NULL)
Jim Inghamc1663042011-09-29 22:12:35 +00003857 {
3858 ReportWarning ("0x%8.8x: DW_AT_specification(0x%8.8x) has no decl\n",
3859 die->GetOffset(),
3860 specification_die_offset);
3861 }
Greg Clayton72da3972011-08-16 18:40:23 +00003862 type_handled = true;
3863 }
3864 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
3865 {
3866 DWARFCompileUnitSP abs_cu_sp;
3867 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
3868 if (m_die_to_decl_ctx[abs_die] == NULL)
Jim Inghamc1663042011-09-29 22:12:35 +00003869 {
3870 ReportWarning ("0x%8.8x: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
3871 die->GetOffset(),
3872 abstract_origin_die_offset);
3873 }
Greg Clayton72da3972011-08-16 18:40:23 +00003874 type_handled = true;
3875 }
3876 else
3877 {
3878 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3879 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00003880 {
Greg Clayton72da3972011-08-16 18:40:23 +00003881 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3882 // in the DWARF for C++ methods... Default to public for now...
3883 if (accessibility == eAccessNone)
3884 accessibility = eAccessPublic;
3885
3886 if (!is_static && !die->HasChildren())
3887 {
3888 // We have a C++ member function with no children (this pointer!)
3889 // and clang will get mad if we try and make a function that isn't
3890 // well formed in the DWARF, so we will just skip it...
3891 type_handled = true;
3892 }
3893 else
3894 {
3895 clang::CXXMethodDecl *cxx_method_decl;
3896 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3897 type_name_cstr,
3898 clang_type,
3899 accessibility,
3900 is_virtual,
3901 is_static,
3902 is_inline,
3903 is_explicit);
3904 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003905
Greg Clayton72da3972011-08-16 18:40:23 +00003906 type_handled = cxx_method_decl != NULL;
3907 }
Greg Clayton931180e2011-01-27 06:44:37 +00003908 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003909 }
3910 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003911 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003912 }
Greg Clayton24739922010-10-13 03:15:28 +00003913
3914 if (!type_handled)
3915 {
3916 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003917 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3918 clang_type,
3919 storage,
3920 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003921
3922 // Add the decl to our DIE to decl context map
3923 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00003924 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00003925 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003926 ast.SetFunctionParameters (function_decl,
3927 &function_param_decls.front(),
3928 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003929 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003930 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003931 type_sp.reset( new Type (die->GetOffset(),
3932 this,
3933 type_name_const_str,
3934 0,
3935 NULL,
3936 LLDB_INVALID_UID,
3937 Type::eEncodingIsUID,
3938 &decl,
3939 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003940 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00003941 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003942 }
3943 break;
3944
3945 case DW_TAG_array_type:
3946 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003947 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003948 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003949
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003950 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003951 int64_t first_index = 0;
3952 uint32_t byte_stride = 0;
3953 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003954 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003955
3956 if (num_attributes > 0)
3957 {
3958 uint32_t i;
3959 for (i=0; i<num_attributes; ++i)
3960 {
3961 attr = attributes.AttributeAtIndex(i);
3962 DWARFFormValue form_value;
3963 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3964 {
3965 switch (attr)
3966 {
3967 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3968 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3969 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3970 case DW_AT_name:
3971 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003972 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003973 break;
3974
3975 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003976 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003977 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3978 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003979 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003980 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003981 case DW_AT_allocated:
3982 case DW_AT_associated:
3983 case DW_AT_data_location:
3984 case DW_AT_description:
3985 case DW_AT_ordering:
3986 case DW_AT_start_scope:
3987 case DW_AT_visibility:
3988 case DW_AT_specification:
3989 case DW_AT_abstract_origin:
3990 case DW_AT_sibling:
3991 break;
3992 }
3993 }
3994 }
3995
Greg Claytonc93237c2010-10-01 20:48:32 +00003996 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3997
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003998 Type *element_type = ResolveTypeUID(type_die_offset);
3999
4000 if (element_type)
4001 {
4002 std::vector<uint64_t> element_orders;
4003 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00004004 // We have an array that claims to have no members, lets give it at least one member...
4005 if (element_orders.empty())
4006 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004007 if (byte_stride == 0 && bit_stride == 0)
4008 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00004009 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004010 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
4011 uint64_t num_elements = 0;
4012 std::vector<uint64_t>::const_reverse_iterator pos;
4013 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
4014 for (pos = element_orders.rbegin(); pos != end; ++pos)
4015 {
4016 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004017 clang_type = ast.CreateArrayType (array_element_type,
4018 num_elements,
4019 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004020 array_element_type = clang_type;
4021 array_element_bit_stride = array_element_bit_stride * num_elements;
4022 }
4023 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004024 type_sp.reset( new Type (die->GetOffset(),
4025 this,
4026 empty_name,
4027 array_element_bit_stride / 8,
4028 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00004029 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004030 Type::eEncodingIsUID,
4031 &decl,
4032 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004033 Type::eResolveStateFull));
4034 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004035 }
4036 }
4037 }
4038 break;
4039
Greg Clayton9b81a312010-06-12 01:20:30 +00004040 case DW_TAG_ptr_to_member_type:
4041 {
4042 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
4043 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
4044
Greg Claytond88d7592010-09-15 08:33:30 +00004045 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00004046
4047 if (num_attributes > 0) {
4048 uint32_t i;
4049 for (i=0; i<num_attributes; ++i)
4050 {
4051 attr = attributes.AttributeAtIndex(i);
4052 DWARFFormValue form_value;
4053 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4054 {
4055 switch (attr)
4056 {
4057 case DW_AT_type:
4058 type_die_offset = form_value.Reference(dwarf_cu); break;
4059 case DW_AT_containing_type:
4060 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
4061 }
4062 }
4063 }
4064
4065 Type *pointee_type = ResolveTypeUID(type_die_offset);
4066 Type *class_type = ResolveTypeUID(containing_type_die_offset);
4067
Greg Clayton526e5af2010-11-13 03:52:47 +00004068 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
4069 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00004070
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004071 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
4072 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00004073
Greg Clayton526e5af2010-11-13 03:52:47 +00004074 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
4075 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00004076
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004077 type_sp.reset( new Type (die->GetOffset(),
4078 this,
4079 type_name_const_str,
4080 byte_size,
4081 NULL,
4082 LLDB_INVALID_UID,
4083 Type::eEncodingIsUID,
4084 NULL,
4085 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004086 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00004087 }
4088
4089 break;
4090 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004091 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00004092 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004093 break;
4094 }
4095
4096 if (type_sp.get())
4097 {
4098 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4099 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4100
4101 SymbolContextScope * symbol_context_scope = NULL;
4102 if (sc_parent_tag == DW_TAG_compile_unit)
4103 {
4104 symbol_context_scope = sc.comp_unit;
4105 }
4106 else if (sc.function != NULL)
4107 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004108 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004109 if (symbol_context_scope == NULL)
4110 symbol_context_scope = sc.function;
4111 }
4112
4113 if (symbol_context_scope != NULL)
4114 {
4115 type_sp->SetSymbolContextScope(symbol_context_scope);
4116 }
4117
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004118 // We are ready to put this type into the uniqued list up at the module level
4119 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00004120
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004121 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004122 }
4123 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00004124 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004125 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004126 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004127 }
4128 }
4129 return type_sp;
4130}
4131
4132size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00004133SymbolFileDWARF::ParseTypes
4134(
4135 const SymbolContext& sc,
4136 DWARFCompileUnit* dwarf_cu,
4137 const DWARFDebugInfoEntry *die,
4138 bool parse_siblings,
4139 bool parse_children
4140)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004141{
4142 size_t types_added = 0;
4143 while (die != NULL)
4144 {
4145 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004146 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004147 {
4148 if (type_is_new)
4149 ++types_added;
4150 }
4151
4152 if (parse_children && die->HasChildren())
4153 {
4154 if (die->Tag() == DW_TAG_subprogram)
4155 {
4156 SymbolContext child_sc(sc);
4157 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
4158 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4159 }
4160 else
4161 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4162 }
4163
4164 if (parse_siblings)
4165 die = die->GetSibling();
4166 else
4167 die = NULL;
4168 }
4169 return types_added;
4170}
4171
4172
4173size_t
4174SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4175{
4176 assert(sc.comp_unit && sc.function);
4177 size_t functions_added = 0;
4178 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4179 if (dwarf_cu)
4180 {
4181 dw_offset_t function_die_offset = sc.function->GetID();
4182 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4183 if (function_die)
4184 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004185 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004186 }
4187 }
4188
4189 return functions_added;
4190}
4191
4192
4193size_t
4194SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4195{
4196 // At least a compile unit must be valid
4197 assert(sc.comp_unit);
4198 size_t types_added = 0;
4199 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4200 if (dwarf_cu)
4201 {
4202 if (sc.function)
4203 {
4204 dw_offset_t function_die_offset = sc.function->GetID();
4205 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4206 if (func_die && func_die->HasChildren())
4207 {
4208 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4209 }
4210 }
4211 else
4212 {
4213 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4214 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4215 {
4216 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4217 }
4218 }
4219 }
4220
4221 return types_added;
4222}
4223
4224size_t
4225SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4226{
4227 if (sc.comp_unit != NULL)
4228 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004229 DWARFDebugInfo* info = DebugInfo();
4230 if (info == NULL)
4231 return 0;
4232
4233 uint32_t cu_idx = UINT32_MAX;
4234 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235
4236 if (dwarf_cu == NULL)
4237 return 0;
4238
4239 if (sc.function)
4240 {
4241 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004242
4243 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4244 assert (func_lo_pc != DW_INVALID_ADDRESS);
4245
Greg Claytonc662ec82011-06-17 22:10:16 +00004246 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4247
4248 // Let all blocks know they have parse all their variables
4249 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4250
4251 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004252 }
4253 else if (sc.comp_unit)
4254 {
4255 uint32_t vars_added = 0;
4256 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4257
4258 if (variables.get() == NULL)
4259 {
4260 variables.reset(new VariableList());
4261 sc.comp_unit->SetVariableList(variables);
4262
4263 // Index if we already haven't to make sure the compile units
4264 // get indexed and make their global DIE index list
4265 if (!m_indexed)
4266 Index ();
4267
Greg Claytond4a2b372011-09-12 23:21:58 +00004268 DWARFCompileUnit* match_dwarf_cu = NULL;
4269 const DWARFDebugInfoEntry* die = NULL;
4270 DIEArray die_offsets;
4271 const size_t num_matches = m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
4272 dwarf_cu->GetNextCompileUnitOffset(),
4273 die_offsets);
4274 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004275 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004276 DWARFDebugInfo* debug_info = DebugInfo();
4277 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004278 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004279 const dw_offset_t die_offset = die_offsets[i];
4280 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
4281 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
4282 if (var_sp)
4283 {
4284 variables->AddVariableIfUnique (var_sp);
4285 ++vars_added;
4286 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004287 }
4288 }
4289 }
4290 return vars_added;
4291 }
4292 }
4293 return 0;
4294}
4295
4296
4297VariableSP
4298SymbolFileDWARF::ParseVariableDIE
4299(
4300 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004301 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004302 const DWARFDebugInfoEntry *die,
4303 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004304)
4305{
4306
Greg Clayton83c5cd92010-11-14 22:13:40 +00004307 VariableSP var_sp (m_die_to_variable_sp[die]);
4308 if (var_sp)
4309 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004310
4311 const dw_tag_t tag = die->Tag();
4312 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004313 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004314 if (num_attributes > 0)
4315 {
4316 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00004317 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004318 Declaration decl;
4319 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004320 Type *var_type = NULL;
4321 DWARFExpression location;
4322 bool is_external = false;
4323 bool is_artificial = false;
Greg Clayton007d5be2011-05-30 00:49:24 +00004324 bool location_is_const_value_data = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00004325 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004326
4327 for (i=0; i<num_attributes; ++i)
4328 {
4329 dw_attr_t attr = attributes.AttributeAtIndex(i);
4330 DWARFFormValue form_value;
4331 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4332 {
4333 switch (attr)
4334 {
4335 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4336 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4337 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4338 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00004339 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00004340 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004341 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Greg Clayton007d5be2011-05-30 00:49:24 +00004342 case DW_AT_const_value:
4343 location_is_const_value_data = true;
4344 // Fall through...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004345 case DW_AT_location:
4346 {
4347 if (form_value.BlockData())
4348 {
4349 const DataExtractor& debug_info_data = get_debug_info_data();
4350
4351 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4352 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00004353 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004354 }
4355 else
4356 {
4357 const DataExtractor& debug_loc_data = get_debug_loc_data();
4358 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4359
4360 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4361 if (loc_list_length > 0)
4362 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004363 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
4364 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4365 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004366 }
4367 }
4368 }
4369 break;
4370
4371 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004372 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004373 case DW_AT_declaration:
4374 case DW_AT_description:
4375 case DW_AT_endianity:
4376 case DW_AT_segment:
4377 case DW_AT_start_scope:
4378 case DW_AT_visibility:
4379 default:
4380 case DW_AT_abstract_origin:
4381 case DW_AT_sibling:
4382 case DW_AT_specification:
4383 break;
4384 }
4385 }
4386 }
4387
4388 if (location.IsValid())
4389 {
4390 assert(var_type != DIE_IS_BEING_PARSED);
4391
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004392 ValueType scope = eValueTypeInvalid;
4393
4394 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4395 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4396
4397 if (tag == DW_TAG_formal_parameter)
4398 scope = eValueTypeVariableArgument;
4399 else if (is_external || parent_tag == DW_TAG_compile_unit)
4400 scope = eValueTypeVariableGlobal;
4401 else
4402 scope = eValueTypeVariableLocal;
4403
4404 SymbolContextScope * symbol_context_scope = NULL;
4405 if (parent_tag == DW_TAG_compile_unit)
4406 {
4407 symbol_context_scope = sc.comp_unit;
4408 }
4409 else if (sc.function != NULL)
4410 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004411 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004412 if (symbol_context_scope == NULL)
4413 symbol_context_scope = sc.function;
4414 }
4415
4416 assert(symbol_context_scope != NULL);
4417 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00004418 name,
4419 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004420 var_type,
4421 scope,
4422 symbol_context_scope,
4423 &decl,
4424 location,
4425 is_external,
4426 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00004427
Greg Clayton007d5be2011-05-30 00:49:24 +00004428 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004429 }
4430 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00004431 // Cache var_sp even if NULL (the variable was just a specification or
4432 // was missing vital information to be able to be displayed in the debugger
4433 // (missing location due to optimization, etc)) so we don't re-parse
4434 // this DIE over and over later...
4435 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004436 return var_sp;
4437}
4438
Greg Claytonc662ec82011-06-17 22:10:16 +00004439
4440const DWARFDebugInfoEntry *
4441SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
4442 dw_offset_t spec_block_die_offset,
4443 DWARFCompileUnit **result_die_cu_handle)
4444{
4445 // Give the concrete function die specified by "func_die_offset", find the
4446 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4447 // to "spec_block_die_offset"
4448 DWARFDebugInfo* info = DebugInfo();
4449
4450 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
4451 if (die)
4452 {
4453 assert (*result_die_cu_handle);
4454 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
4455 }
4456 return NULL;
4457}
4458
4459
4460const DWARFDebugInfoEntry *
4461SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
4462 const DWARFDebugInfoEntry *die,
4463 dw_offset_t spec_block_die_offset,
4464 DWARFCompileUnit **result_die_cu_handle)
4465{
4466 if (die)
4467 {
4468 switch (die->Tag())
4469 {
4470 case DW_TAG_subprogram:
4471 case DW_TAG_inlined_subroutine:
4472 case DW_TAG_lexical_block:
4473 {
4474 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4475 {
4476 *result_die_cu_handle = dwarf_cu;
4477 return die;
4478 }
4479
4480 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4481 {
4482 *result_die_cu_handle = dwarf_cu;
4483 return die;
4484 }
4485 }
4486 break;
4487 }
4488
4489 // Give the concrete function die specified by "func_die_offset", find the
4490 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4491 // to "spec_block_die_offset"
4492 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
4493 {
4494 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
4495 child_die,
4496 spec_block_die_offset,
4497 result_die_cu_handle);
4498 if (result_die)
4499 return result_die;
4500 }
4501 }
4502
4503 *result_die_cu_handle = NULL;
4504 return NULL;
4505}
4506
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004507size_t
4508SymbolFileDWARF::ParseVariables
4509(
4510 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004511 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004512 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004513 const DWARFDebugInfoEntry *orig_die,
4514 bool parse_siblings,
4515 bool parse_children,
4516 VariableList* cc_variable_list
4517)
4518{
4519 if (orig_die == NULL)
4520 return 0;
4521
Greg Claytonc662ec82011-06-17 22:10:16 +00004522 VariableListSP variable_list_sp;
4523
4524 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004525 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004526 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004527 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004528 dw_tag_t tag = die->Tag();
4529
4530 // Check to see if we have already parsed this variable or constant?
4531 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004532 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004533 if (cc_variable_list)
4534 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004535 }
4536 else
4537 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004538 // We haven't already parsed it, lets do that now.
4539 if ((tag == DW_TAG_variable) ||
4540 (tag == DW_TAG_constant) ||
4541 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004542 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004543 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004544 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004545 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4546 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4547 switch (parent_tag)
4548 {
4549 case DW_TAG_compile_unit:
4550 if (sc.comp_unit != NULL)
4551 {
4552 variable_list_sp = sc.comp_unit->GetVariableList(false);
4553 if (variable_list_sp.get() == NULL)
4554 {
4555 variable_list_sp.reset(new VariableList());
4556 sc.comp_unit->SetVariableList(variable_list_sp);
4557 }
4558 }
4559 else
4560 {
Jim Inghamc1663042011-09-29 22:12:35 +00004561 ReportError ("parent 0x%8.8x %s with no valid compile unit in symbol context for 0x%8.8x %s.\n",
Greg Claytonc662ec82011-06-17 22:10:16 +00004562 sc_parent_die->GetOffset(),
4563 DW_TAG_value_to_name (parent_tag),
4564 orig_die->GetOffset(),
4565 DW_TAG_value_to_name (orig_die->Tag()));
4566 }
4567 break;
4568
4569 case DW_TAG_subprogram:
4570 case DW_TAG_inlined_subroutine:
4571 case DW_TAG_lexical_block:
4572 if (sc.function != NULL)
4573 {
4574 // Check to see if we already have parsed the variables for the given scope
4575
4576 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
4577 if (block == NULL)
4578 {
4579 // This must be a specification or abstract origin with
4580 // a concrete block couterpart in the current function. We need
4581 // to find the concrete block so we can correctly add the
4582 // variable to it
4583 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
4584 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4585 sc_parent_die->GetOffset(),
4586 &concrete_block_die_cu);
4587 if (concrete_block_die)
4588 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die->GetOffset());
4589 }
4590
4591 if (block != NULL)
4592 {
4593 const bool can_create = false;
4594 variable_list_sp = block->GetBlockVariableList (can_create);
4595 if (variable_list_sp.get() == NULL)
4596 {
4597 variable_list_sp.reset(new VariableList());
4598 block->SetVariableList(variable_list_sp);
4599 }
4600 }
4601 }
4602 break;
4603
4604 default:
Jim Inghamc1663042011-09-29 22:12:35 +00004605 ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8x %s.\n",
Greg Claytonc662ec82011-06-17 22:10:16 +00004606 orig_die->GetOffset(),
4607 DW_TAG_value_to_name (orig_die->Tag()));
4608 break;
4609 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004610 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004611
4612 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004613 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00004614 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
4615 if (var_sp)
4616 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004617 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004618 if (cc_variable_list)
4619 cc_variable_list->AddVariableIfUnique (var_sp);
4620 ++vars_added;
4621 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004622 }
4623 }
4624 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004625
4626 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4627
4628 if (!skip_children && parse_children && die->HasChildren())
4629 {
4630 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
4631 }
4632
4633 if (parse_siblings)
4634 die = die->GetSibling();
4635 else
4636 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004637 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004638 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004639}
4640
4641//------------------------------------------------------------------
4642// PluginInterface protocol
4643//------------------------------------------------------------------
4644const char *
4645SymbolFileDWARF::GetPluginName()
4646{
4647 return "SymbolFileDWARF";
4648}
4649
4650const char *
4651SymbolFileDWARF::GetShortPluginName()
4652{
4653 return GetPluginNameStatic();
4654}
4655
4656uint32_t
4657SymbolFileDWARF::GetPluginVersion()
4658{
4659 return 1;
4660}
4661
4662void
Greg Clayton6beaaa62011-01-17 03:46:26 +00004663SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
4664{
4665 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4666 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4667 if (clang_type)
4668 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4669}
4670
4671void
4672SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
4673{
4674 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4675 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4676 if (clang_type)
4677 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4678}
4679
Greg Claytona2721472011-06-25 00:44:06 +00004680void
Sean Callanancc427fa2011-07-30 02:42:06 +00004681SymbolFileDWARF::DumpIndexes ()
4682{
4683 StreamFile s(stdout, false);
4684
4685 s.Printf ("DWARF index for (%s) '%s/%s':",
4686 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4687 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
4688 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
4689 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4690 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4691 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4692 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4693 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4694 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4695 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
4696 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
4697}
4698
4699void
4700SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
4701 const char *name,
4702 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00004703{
Sean Callanancc427fa2011-07-30 02:42:06 +00004704 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00004705
4706 if (iter == m_decl_ctx_to_die.end())
4707 return;
4708
Sean Callanancc427fa2011-07-30 02:42:06 +00004709 const DWARFDebugInfoEntry *context_die = iter->second;
Greg Claytona2721472011-06-25 00:44:06 +00004710
4711 if (!results)
4712 return;
4713
4714 DWARFDebugInfo* info = DebugInfo();
4715
Greg Claytond4a2b372011-09-12 23:21:58 +00004716 DIEArray die_offsets;
Greg Claytona2721472011-06-25 00:44:06 +00004717
Greg Claytond4a2b372011-09-12 23:21:58 +00004718 DWARFCompileUnit* dwarf_cu = NULL;
4719 const DWARFDebugInfoEntry* die = NULL;
4720 size_t num_matches = m_type_index.Find (ConstString(name), die_offsets);
Greg Claytona2721472011-06-25 00:44:06 +00004721
4722 if (num_matches)
4723 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004724 for (size_t i = 0; i < num_matches; ++i)
Greg Claytona2721472011-06-25 00:44:06 +00004725 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004726 const dw_offset_t die_offset = die_offsets[i];
4727 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4728
Sean Callanancc427fa2011-07-30 02:42:06 +00004729 if (die->GetParent() != context_die)
Greg Claytona2721472011-06-25 00:44:06 +00004730 continue;
4731
Greg Claytond4a2b372011-09-12 23:21:58 +00004732 Type *matching_type = ResolveType (dwarf_cu, die);
Greg Claytona2721472011-06-25 00:44:06 +00004733
4734 lldb::clang_type_t type = matching_type->GetClangFullType();
4735 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
4736
Sean Callanancc427fa2011-07-30 02:42:06 +00004737 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004738 {
4739 clang::TagDecl *tag_decl = tag_type->getDecl();
4740 results->push_back(tag_decl);
4741 }
Sean Callanancc427fa2011-07-30 02:42:06 +00004742 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004743 {
4744 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
4745 results->push_back(typedef_decl);
4746 }
4747 }
4748 }
4749}
4750
4751void
4752SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
4753 const clang::DeclContext *DC,
4754 clang::DeclarationName Name,
4755 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
4756{
4757 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4758
Sean Callanancc427fa2011-07-30 02:42:06 +00004759 symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results);
Greg Claytona2721472011-06-25 00:44:06 +00004760}