blob: 7beadf88c34661da6e9f786a10dbb36e709193a4 [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
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
663 {
664 // Union of all ranges in the function DIE (if the function is discontiguous)
665 AddressRange func_range;
666 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
667 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
668 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
669 {
670 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
671 if (func_range.GetBaseAddress().IsValid())
672 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
673 }
674
675 if (func_range.GetBaseAddress().IsValid())
676 {
677 Mangled func_name;
678 if (mangled)
679 func_name.SetValue(mangled, true);
680 else if (name)
681 func_name.SetValue(name, false);
682
683 FunctionSP func_sp;
684 std::auto_ptr<Declaration> decl_ap;
685 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000686 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
687 decl_line,
688 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000690 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000691 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692
693 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
694
695 func_range.GetBaseAddress().ResolveLinkedAddress();
696
697 func_sp.reset(new Function (sc.comp_unit,
698 die->GetOffset(), // UserID is the DIE offset
699 die->GetOffset(),
700 func_name,
701 func_type,
702 func_range)); // first address range
703
704 if (func_sp.get() != NULL)
705 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000706 if (frame_base.IsValid())
707 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 sc.comp_unit->AddFunction(func_sp);
709 return func_sp.get();
710 }
711 }
712 }
713 return NULL;
714}
715
716size_t
717SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
718{
719 assert (sc.comp_unit);
720 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000721 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 if (dwarf_cu)
723 {
724 DWARFDIECollection function_dies;
725 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
726 size_t func_idx;
727 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
728 {
729 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
730 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
731 {
732 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
733 ++functions_added;
734 }
735 }
736 //FixupTypes();
737 }
738 return functions_added;
739}
740
741bool
742SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
743{
744 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000745 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
746 assert (curr_cu);
747 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748
749 if (cu_die)
750 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000751 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
752 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 +0000753
754 // All file indexes in DWARF are one based and a file of index zero is
755 // supposed to be the compile unit itself.
756 support_files.Append (*sc.comp_unit);
757
758 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
759 }
760 return false;
761}
762
763struct ParseDWARFLineTableCallbackInfo
764{
765 LineTable* line_table;
766 const SectionList *section_list;
767 lldb::addr_t prev_sect_file_base_addr;
768 lldb::addr_t curr_sect_file_base_addr;
769 bool is_oso_for_debug_map;
770 bool prev_in_final_executable;
771 DWARFDebugLine::Row prev_row;
772 SectionSP prev_section_sp;
773 SectionSP curr_section_sp;
774};
775
776//----------------------------------------------------------------------
777// ParseStatementTableCallback
778//----------------------------------------------------------------------
779static void
780ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
781{
782 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
783 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
784 {
785 // Just started parsing the line table
786 }
787 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
788 {
789 // Done parsing line table, nothing to do for the cleanup
790 }
791 else
792 {
793 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
794 // We have a new row, lets append it
795
796 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
797 {
798 info->prev_section_sp = info->curr_section_sp;
799 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
800 // If this is an end sequence entry, then we subtract one from the
801 // address to make sure we get an address that is not the end of
802 // a section.
803 if (state.end_sequence && state.address != 0)
804 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
805 else
806 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
807
808 if (info->curr_section_sp.get())
809 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
810 else
811 info->curr_sect_file_base_addr = 0;
812 }
813 if (info->curr_section_sp.get())
814 {
815 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
816 // Check for the fancy section magic to determine if we
817
818 if (info->is_oso_for_debug_map)
819 {
820 // When this is a debug map object file that contains DWARF
821 // (referenced from an N_OSO debug map nlist entry) we will have
822 // a file address in the file range for our section from the
823 // original .o file, and a load address in the executable that
824 // contains the debug map.
825 //
826 // If the sections for the file range and load range are
827 // different, we have a remapped section for the function and
828 // this address is resolved. If they are the same, then the
829 // function for this address didn't make it into the final
830 // executable.
831 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
832
833 // If we are doing DWARF with debug map, then we need to carefully
834 // add each line table entry as there may be gaps as functions
835 // get moved around or removed.
836 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
837 {
838 if (info->prev_in_final_executable)
839 {
840 bool terminate_previous_entry = false;
841 if (!curr_in_final_executable)
842 {
843 // Check for the case where the previous line entry
844 // in a function made it into the final executable,
845 // yet the current line entry falls in a function
846 // that didn't. The line table used to be contiguous
847 // through this address range but now it isn't. We
848 // need to terminate the previous line entry so
849 // that we can reconstruct the line range correctly
850 // for it and to keep the line table correct.
851 terminate_previous_entry = true;
852 }
853 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
854 {
855 // Check for cases where the line entries used to be
856 // contiguous address ranges, but now they aren't.
857 // This can happen when order files specify the
858 // ordering of the functions.
859 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
860 Section *curr_sect = info->curr_section_sp.get();
861 Section *prev_sect = info->prev_section_sp.get();
862 assert (curr_sect->GetLinkedSection());
863 assert (prev_sect->GetLinkedSection());
864 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
865 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
866 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
867 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
868 if (object_file_addr_delta != linked_file_addr_delta)
869 terminate_previous_entry = true;
870 }
871
872 if (terminate_previous_entry)
873 {
874 line_table->InsertLineEntry (info->prev_section_sp,
875 state.address - info->prev_sect_file_base_addr,
876 info->prev_row.line,
877 info->prev_row.column,
878 info->prev_row.file,
879 false, // is_stmt
880 false, // basic_block
881 false, // state.prologue_end
882 false, // state.epilogue_begin
883 true); // end_sequence);
884 }
885 }
886 }
887
888 if (curr_in_final_executable)
889 {
890 line_table->InsertLineEntry (info->curr_section_sp,
891 curr_line_section_offset,
892 state.line,
893 state.column,
894 state.file,
895 state.is_stmt,
896 state.basic_block,
897 state.prologue_end,
898 state.epilogue_begin,
899 state.end_sequence);
900 info->prev_section_sp = info->curr_section_sp;
901 }
902 else
903 {
904 // If the current address didn't make it into the final
905 // executable, the current section will be the __text
906 // segment in the .o file, so we need to clear this so
907 // we can catch the next function that did make it into
908 // the final executable.
909 info->prev_section_sp.reset();
910 info->curr_section_sp.reset();
911 }
912
913 info->prev_in_final_executable = curr_in_final_executable;
914 }
915 else
916 {
917 // We are not in an object file that contains DWARF for an
918 // N_OSO, this is just a normal DWARF file. The DWARF spec
919 // guarantees that the addresses will be in increasing order
920 // so, since we store line tables in file address order, we
921 // can always just append the line entry without needing to
922 // search for the correct insertion point (we don't need to
923 // use LineEntry::InsertLineEntry()).
924 line_table->AppendLineEntry (info->curr_section_sp,
925 curr_line_section_offset,
926 state.line,
927 state.column,
928 state.file,
929 state.is_stmt,
930 state.basic_block,
931 state.prologue_end,
932 state.epilogue_begin,
933 state.end_sequence);
934 }
935 }
936
937 info->prev_row = state;
938 }
939}
940
941bool
942SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
943{
944 assert (sc.comp_unit);
945 if (sc.comp_unit->GetLineTable() != NULL)
946 return true;
947
948 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
949 if (dwarf_cu)
950 {
951 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
952 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
953 if (cu_line_offset != DW_INVALID_OFFSET)
954 {
955 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
956 if (line_table_ap.get())
957 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000958 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 +0000959 uint32_t offset = cu_line_offset;
960 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
961 sc.comp_unit->SetLineTable(line_table_ap.release());
962 return true;
963 }
964 }
965 }
966 return false;
967}
968
969size_t
970SymbolFileDWARF::ParseFunctionBlocks
971(
972 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000973 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +0000974 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000975 const DWARFDebugInfoEntry *die,
976 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +0000977 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000978)
979{
980 size_t blocks_added = 0;
981 while (die != NULL)
982 {
983 dw_tag_t tag = die->Tag();
984
985 switch (tag)
986 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000987 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +0000988 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989 case DW_TAG_lexical_block:
990 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000991 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +0000992 if (tag == DW_TAG_subprogram)
993 {
994 // Skip any DW_TAG_subprogram DIEs that are inside
995 // of a normal or inlined functions. These will be
996 // parsed on their own as separate entities.
997
998 if (depth > 0)
999 break;
1000
1001 block = parent_block;
1002 }
1003 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001004 {
1005 BlockSP block_sp(new Block (die->GetOffset()));
1006 parent_block->AddChild(block_sp);
1007 block = block_sp.get();
1008 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001009 DWARFDebugRanges::RangeList ranges;
1010 const char *name = NULL;
1011 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001013 int decl_file = 0;
1014 int decl_line = 0;
1015 int decl_column = 0;
1016 int call_file = 0;
1017 int call_line = 0;
1018 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001019 if (die->GetDIENamesAndRanges (this,
1020 dwarf_cu,
1021 name,
1022 mangled_name,
1023 ranges,
1024 decl_file, decl_line, decl_column,
1025 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 {
1027 if (tag == DW_TAG_subprogram)
1028 {
1029 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1030 subprogram_low_pc = ranges.LowestAddress(0);
1031 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001032 else if (tag == DW_TAG_inlined_subroutine)
1033 {
1034 // We get called here for inlined subroutines in two ways.
1035 // The first time is when we are making the Function object
1036 // for this inlined concrete instance. Since we're creating a top level block at
1037 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1038 // adjust the containing address.
1039 // The second time is when we are parsing the blocks inside the function that contains
1040 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1041 // function the offset will be for that function.
1042 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1043 {
1044 subprogram_low_pc = ranges.LowestAddress(0);
1045 }
1046 }
1047
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001048 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001049
1050 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1051 {
1052 std::auto_ptr<Declaration> decl_ap;
1053 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001054 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1055 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056
1057 std::auto_ptr<Declaration> call_ap;
1058 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001059 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1060 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001062 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 }
1064
1065 ++blocks_added;
1066
Greg Claytondd7feaf2011-08-12 17:54:33 +00001067 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001069 blocks_added += ParseFunctionBlocks (sc,
1070 block,
1071 dwarf_cu,
1072 die->GetFirstChild(),
1073 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001074 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075 }
1076 }
1077 }
1078 break;
1079 default:
1080 break;
1081 }
1082
Greg Claytondd7feaf2011-08-12 17:54:33 +00001083 // Only parse siblings of the block if we are not at depth zero. A depth
1084 // of zero indicates we are currently parsing the top level
1085 // DW_TAG_subprogram DIE
1086
1087 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001089 else
1090 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001091 }
1092 return blocks_added;
1093}
1094
1095size_t
1096SymbolFileDWARF::ParseChildMembers
1097(
1098 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001099 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001101 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001102 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1104 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001105 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001106 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107 bool &is_a_class
1108)
1109{
1110 if (parent_die == NULL)
1111 return 0;
1112
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001113 size_t count = 0;
1114 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001115 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001116 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001117
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001118 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1119 {
1120 dw_tag_t tag = die->Tag();
1121
1122 switch (tag)
1123 {
1124 case DW_TAG_member:
1125 {
1126 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001127 const size_t num_attributes = die->GetAttributes (this,
1128 dwarf_cu,
1129 fixed_form_sizes,
1130 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001131 if (num_attributes > 0)
1132 {
1133 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001134 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001136 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001137 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001138 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001139 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140 size_t byte_size = 0;
1141 size_t bit_offset = 0;
1142 size_t bit_size = 0;
1143 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001144 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145 {
1146 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1147 DWARFFormValue form_value;
1148 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1149 {
1150 switch (attr)
1151 {
1152 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1153 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1154 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1155 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1156 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1157 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1158 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1159 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1160 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001161// if (form_value.BlockData())
1162// {
1163// Value initialValue(0);
1164// Value memberOffset(0);
1165// const DataExtractor& debug_info_data = get_debug_info_data();
1166// uint32_t block_length = form_value.Unsigned();
1167// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1168// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1169// {
1170// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1171// }
1172// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 break;
1174
Greg Clayton8cf05932010-07-22 18:30:50 +00001175 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001176 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177 case DW_AT_declaration:
1178 case DW_AT_description:
1179 case DW_AT_mutable:
1180 case DW_AT_visibility:
1181 default:
1182 case DW_AT_sibling:
1183 break;
1184 }
1185 }
1186 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001187
1188 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1189
1190 if (class_language == eLanguageTypeObjC ||
1191 class_language == eLanguageTypeObjC_plus_plus)
1192 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001193
1194 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1195 {
1196 // Not all compilers will mark the vtable pointer
1197 // member as artificial (llvm-gcc). We can't have
1198 // the virtual members in our classes otherwise it
1199 // throws off all child offsets since we end up
1200 // having and extra pointer sized member in our
1201 // class layouts.
1202 is_artificial = true;
1203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204
Greg Clayton24739922010-10-13 03:15:28 +00001205 if (is_artificial == false)
1206 {
1207 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001208 if (member_type)
1209 {
1210 if (accessibility == eAccessNone)
1211 accessibility = default_accessibility;
1212 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213
Greg Claytond16e1e52011-07-12 17:06:17 +00001214 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1215 name,
1216 member_type->GetClangLayoutType(),
1217 accessibility,
1218 bit_size);
1219 }
1220 else
1221 {
1222 if (name)
1223 ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed",
1224 die->GetOffset(),
1225 name,
1226 encoding_uid);
1227 else
1228 ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed",
1229 die->GetOffset(),
1230 encoding_uid);
1231 }
Greg Clayton24739922010-10-13 03:15:28 +00001232 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001234 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001235 }
1236 break;
1237
1238 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001239 // Let the type parsing code handle this one for us.
1240 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241 break;
1242
1243 case DW_TAG_inheritance:
1244 {
1245 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001246 if (default_accessibility == eAccessNone)
1247 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 // TODO: implement DW_TAG_inheritance type parsing
1249 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001250 const size_t num_attributes = die->GetAttributes (this,
1251 dwarf_cu,
1252 fixed_form_sizes,
1253 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 if (num_attributes > 0)
1255 {
1256 Declaration decl;
1257 DWARFExpression location;
1258 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001259 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 bool is_virtual = false;
1261 bool is_base_of_class = true;
1262 off_t member_offset = 0;
1263 uint32_t i;
1264 for (i=0; i<num_attributes; ++i)
1265 {
1266 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1267 DWARFFormValue form_value;
1268 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1269 {
1270 switch (attr)
1271 {
1272 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1273 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1274 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1275 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1276 case DW_AT_data_member_location:
1277 if (form_value.BlockData())
1278 {
1279 Value initialValue(0);
1280 Value memberOffset(0);
1281 const DataExtractor& debug_info_data = get_debug_info_data();
1282 uint32_t block_length = form_value.Unsigned();
1283 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001284 if (DWARFExpression::Evaluate (NULL,
1285 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001286 NULL,
1287 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001288 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001289 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001290 block_offset,
1291 block_length,
1292 eRegisterKindDWARF,
1293 &initialValue,
1294 memberOffset,
1295 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 {
1297 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1298 }
1299 }
1300 break;
1301
1302 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001303 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 break;
1305
1306 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1307 default:
1308 case DW_AT_sibling:
1309 break;
1310 }
1311 }
1312 }
1313
Greg Clayton526e5af2010-11-13 03:52:47 +00001314 Type *base_class_type = ResolveTypeUID(encoding_uid);
1315 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001316
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001317 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1318 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001319 if (class_language == eLanguageTypeObjC)
1320 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001321 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001322 }
1323 else
1324 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001325 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001326 accessibility,
1327 is_virtual,
1328 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001329 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 }
1331 }
1332 break;
1333
1334 default:
1335 break;
1336 }
1337 }
1338 return count;
1339}
1340
1341
1342clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001343SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001344{
1345 DWARFDebugInfo* debug_info = DebugInfo();
1346 if (debug_info)
1347 {
1348 DWARFCompileUnitSP cu_sp;
1349 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1350 if (die)
Sean Callanan72e49402011-08-05 23:43:37 +00001351 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
1352 }
1353 return NULL;
1354}
1355
1356clang::DeclContext*
1357SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1358{
1359 DWARFDebugInfo* debug_info = DebugInfo();
1360 if (debug_info)
1361 {
1362 DWARFCompileUnitSP cu_sp;
1363 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1364 if (die)
1365 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 }
1367 return NULL;
1368}
1369
1370Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001371SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372{
1373 DWARFDebugInfo* debug_info = DebugInfo();
1374 if (debug_info)
1375 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001376 DWARFCompileUnitSP cu_sp;
1377 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001379 {
1380 // We might be coming in in the middle of a type tree (a class
1381 // withing a class, an enum within a class), so parse any needed
1382 // parent DIEs before we get to this one...
1383 const DWARFDebugInfoEntry* parent_die = type_die->GetParent();
1384 switch (parent_die->Tag())
1385 {
1386 case DW_TAG_structure_type:
1387 case DW_TAG_union_type:
1388 case DW_TAG_class_type:
1389 ResolveType(cu_sp.get(), parent_die);
1390 break;
1391 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00001392 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001393 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394 }
1395 return NULL;
1396}
1397
Greg Clayton6beaaa62011-01-17 03:46:26 +00001398// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1399// SymbolFileDWARF objects to detect if this DWARF file is the one that
1400// can resolve a clang_type.
1401bool
1402SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1403{
1404 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1405 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1406 return die != NULL;
1407}
1408
1409
Greg Clayton1be10fc2010-09-29 01:12:09 +00001410lldb::clang_type_t
1411SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1412{
1413 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001414 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1415 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001416 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001417 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001418// if (m_debug_map_symfile)
1419// {
1420// Type *type = m_die_to_type[die];
1421// if (type && type->GetSymbolFile() != this)
1422// return type->GetClangType();
1423// }
Greg Clayton73b472d2010-10-27 03:32:59 +00001424 // We have already resolved this type...
1425 return clang_type;
1426 }
1427 // Once we start resolving this type, remove it from the forward declaration
1428 // map in case anyone child members or other types require this type to get resolved.
1429 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1430 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001431 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001432
Greg Clayton1be10fc2010-09-29 01:12:09 +00001433
Greg Clayton450e3f32010-10-12 02:24:53 +00001434 DWARFDebugInfo* debug_info = DebugInfo();
1435
Greg Clayton96d7d742010-11-10 23:42:09 +00001436 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001437 Type *type = m_die_to_type.lookup (die);
1438
1439 const dw_tag_t tag = die->Tag();
1440
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001441 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1442 die->GetOffset(),
1443 DW_TAG_value_to_name(tag),
1444 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001445 assert (clang_type);
1446 DWARFDebugInfoEntry::Attributes attributes;
1447
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001448 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001449
1450 switch (tag)
1451 {
1452 case DW_TAG_structure_type:
1453 case DW_TAG_union_type:
1454 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001455 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001456 if (die->HasChildren())
1457 {
1458 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001459 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1460 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001461 class_language = eLanguageTypeObjC;
1462
1463 int tag_decl_kind = -1;
1464 AccessType default_accessibility = eAccessNone;
1465 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001466 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001467 tag_decl_kind = clang::TTK_Struct;
1468 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001469 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001470 else if (tag == DW_TAG_union_type)
1471 {
1472 tag_decl_kind = clang::TTK_Union;
1473 default_accessibility = eAccessPublic;
1474 }
1475 else if (tag == DW_TAG_class_type)
1476 {
1477 tag_decl_kind = clang::TTK_Class;
1478 default_accessibility = eAccessPrivate;
1479 }
1480
Greg Clayton96d7d742010-11-10 23:42:09 +00001481 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001482 std::vector<clang::CXXBaseSpecifier *> base_classes;
1483 std::vector<int> member_accessibilities;
1484 bool is_a_class = false;
1485 // Parse members and base classes first
1486 DWARFDIECollection member_function_dies;
1487
1488 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001489 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001490 die,
1491 clang_type,
1492 class_language,
1493 base_classes,
1494 member_accessibilities,
1495 member_function_dies,
1496 default_accessibility,
1497 is_a_class);
1498
1499 // Now parse any methods if there were any...
1500 size_t num_functions = member_function_dies.Size();
1501 if (num_functions > 0)
1502 {
1503 for (size_t i=0; i<num_functions; ++i)
1504 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001505 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001506 }
1507 }
1508
Greg Clayton450e3f32010-10-12 02:24:53 +00001509 if (class_language == eLanguageTypeObjC)
1510 {
Greg Claytone3055942011-06-30 02:28:26 +00001511 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001512 if (!class_str.empty())
1513 {
1514
1515 ConstString class_name (class_str.c_str());
Greg Claytond4a2b372011-09-12 23:21:58 +00001516 DIEArray method_die_offsets;
1517 if (m_objc_class_selectors_index.Find (class_name, method_die_offsets))
Greg Clayton450e3f32010-10-12 02:24:53 +00001518 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001519 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton450e3f32010-10-12 02:24:53 +00001520
Greg Claytond4a2b372011-09-12 23:21:58 +00001521 DWARFCompileUnit* method_cu = NULL;
1522 const size_t num_matches = method_die_offsets.size();
1523 for (size_t i=0; i<num_matches; ++i)
1524 {
1525 const dw_offset_t die_offset = method_die_offsets[i];
1526 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Greg Clayton450e3f32010-10-12 02:24:53 +00001527
1528 ResolveType (method_cu, method_die);
1529 }
1530 }
1531 }
1532 }
1533
Greg Claytonc93237c2010-10-01 20:48:32 +00001534 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1535 // need to tell the clang type it is actually a class.
1536 if (class_language != eLanguageTypeObjC)
1537 {
1538 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001539 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001540 }
1541
1542 // Since DW_TAG_structure_type gets used for both classes
1543 // and structures, we may need to set any DW_TAG_member
1544 // fields to have a "private" access if none was specified.
1545 // When we parsed the child members we tracked that actual
1546 // accessibility value for each DW_TAG_member in the
1547 // "member_accessibilities" array. If the value for the
1548 // member is zero, then it was set to the "default_accessibility"
1549 // which for structs was "public". Below we correct this
1550 // by setting any fields to "private" that weren't correctly
1551 // set.
1552 if (is_a_class && !member_accessibilities.empty())
1553 {
1554 // This is a class and all members that didn't have
1555 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001556 ast.SetDefaultAccessForRecordFields (clang_type,
1557 eAccessPrivate,
1558 &member_accessibilities.front(),
1559 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001560 }
1561
1562 if (!base_classes.empty())
1563 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001564 ast.SetBaseClassesForClassType (clang_type,
1565 &base_classes.front(),
1566 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001567
1568 // Clang will copy each CXXBaseSpecifier in "base_classes"
1569 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001570 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1571 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001572 }
1573
1574 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001575 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001576 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001577
1578 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001579 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001580 if (die->HasChildren())
1581 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001582 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1583 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001584 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001585 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001586 return clang_type;
1587
1588 default:
1589 assert(false && "not a forward clang type decl!");
1590 break;
1591 }
1592 return NULL;
1593}
1594
Greg Claytonc685f8e2010-09-15 04:15:46 +00001595Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001596SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001597{
1598 if (type_die != NULL)
1599 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001600 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001601 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001602 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001603 if (assert_not_being_parsed)
1604 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001605 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001606 }
1607 return NULL;
1608}
1609
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001611SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001612{
1613 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001614 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615 {
1616 // The symbol vendor doesn't know about this compile unit, we
1617 // need to parse and add it to the symbol vendor object.
1618 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001619 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001620 if (dc_cu.get())
1621 {
1622 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001623 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001624 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001625
1626 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001627
1628 if (m_debug_map_symfile)
1629 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001630 }
1631 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001632 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001633}
1634
1635bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001636SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001637{
1638 sc.Clear();
1639 // Check if the symbol vendor already knows about this compile unit?
Greg Claytona2eee182011-09-17 07:23:18 +00001640 sc.module_sp = m_obj_file->GetModule();
Greg Clayton96d7d742010-11-10 23:42:09 +00001641 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642
1643 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1644 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001645 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646
1647 return sc.function != NULL;
1648}
1649
1650uint32_t
1651SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1652{
1653 Timer scoped_timer(__PRETTY_FUNCTION__,
1654 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1655 so_addr.GetSection(),
1656 so_addr.GetOffset(),
1657 resolve_scope);
1658 uint32_t resolved = 0;
1659 if (resolve_scope & ( eSymbolContextCompUnit |
1660 eSymbolContextFunction |
1661 eSymbolContextBlock |
1662 eSymbolContextLineEntry))
1663 {
1664 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1665
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001667 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001668 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001669 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001670 if (cu_offset != DW_INVALID_OFFSET)
1671 {
1672 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001673 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1674 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001676 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677 assert(sc.comp_unit != NULL);
1678 resolved |= eSymbolContextCompUnit;
1679
1680 if (resolve_scope & eSymbolContextLineEntry)
1681 {
1682 LineTable *line_table = sc.comp_unit->GetLineTable();
1683 if (line_table == NULL)
1684 {
1685 if (ParseCompileUnitLineTable(sc))
1686 line_table = sc.comp_unit->GetLineTable();
1687 }
1688 if (line_table != NULL)
1689 {
1690 if (so_addr.IsLinkedAddress())
1691 {
1692 Address linked_addr (so_addr);
1693 linked_addr.ResolveLinkedAddress();
1694 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1695 {
1696 resolved |= eSymbolContextLineEntry;
1697 }
1698 }
1699 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1700 {
1701 resolved |= eSymbolContextLineEntry;
1702 }
1703 }
1704 }
1705
1706 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1707 {
1708 DWARFDebugInfoEntry *function_die = NULL;
1709 DWARFDebugInfoEntry *block_die = NULL;
1710 if (resolve_scope & eSymbolContextBlock)
1711 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001712 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713 }
1714 else
1715 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001716 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001717 }
1718
1719 if (function_die != NULL)
1720 {
1721 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1722 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001723 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 }
1725
1726 if (sc.function != NULL)
1727 {
1728 resolved |= eSymbolContextFunction;
1729
1730 if (resolve_scope & eSymbolContextBlock)
1731 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001732 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733
1734 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001735 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001736 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001737 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001738 if (sc.block)
1739 resolved |= eSymbolContextBlock;
1740 }
1741 }
1742 }
1743 }
1744 }
1745 }
1746 }
1747 return resolved;
1748}
1749
1750
1751
1752uint32_t
1753SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1754{
1755 const uint32_t prev_size = sc_list.GetSize();
1756 if (resolve_scope & eSymbolContextCompUnit)
1757 {
1758 DWARFDebugInfo* debug_info = DebugInfo();
1759 if (debug_info)
1760 {
1761 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001762 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001763
Greg Clayton96d7d742010-11-10 23:42:09 +00001764 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001765 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001766 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001767 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1768 if (check_inlines || file_spec_matches_cu_file_spec)
1769 {
1770 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001771 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772 assert(sc.comp_unit != NULL);
1773
1774 uint32_t file_idx = UINT32_MAX;
1775
1776 // If we are looking for inline functions only and we don't
1777 // find it in the support files, we are done.
1778 if (check_inlines)
1779 {
Jim Ingham87df91b2011-09-23 00:54:11 +00001780 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001781 if (file_idx == UINT32_MAX)
1782 continue;
1783 }
1784
1785 if (line != 0)
1786 {
1787 LineTable *line_table = sc.comp_unit->GetLineTable();
1788
1789 if (line_table != NULL && line != 0)
1790 {
1791 // We will have already looked up the file index if
1792 // we are searching for inline entries.
1793 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00001794 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795
1796 if (file_idx != UINT32_MAX)
1797 {
1798 uint32_t found_line;
1799 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1800 found_line = sc.line_entry.line;
1801
Greg Clayton016a95e2010-09-14 02:20:48 +00001802 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803 {
1804 sc.function = NULL;
1805 sc.block = NULL;
1806 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1807 {
1808 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1809 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1810 {
1811 DWARFDebugInfoEntry *function_die = NULL;
1812 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001813 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814
1815 if (function_die != NULL)
1816 {
1817 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1818 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001819 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820 }
1821
1822 if (sc.function != NULL)
1823 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001824 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001825
1826 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001827 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001828 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001829 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 }
1831 }
1832 }
1833
1834 sc_list.Append(sc);
1835 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1836 }
1837 }
1838 }
1839 else if (file_spec_matches_cu_file_spec && !check_inlines)
1840 {
1841 // only append the context if we aren't looking for inline call sites
1842 // by file and line and if the file spec matches that of the compile unit
1843 sc_list.Append(sc);
1844 }
1845 }
1846 else if (file_spec_matches_cu_file_spec && !check_inlines)
1847 {
1848 // only append the context if we aren't looking for inline call sites
1849 // by file and line and if the file spec matches that of the compile unit
1850 sc_list.Append(sc);
1851 }
1852
1853 if (!check_inlines)
1854 break;
1855 }
1856 }
1857 }
1858 }
1859 return sc_list.GetSize() - prev_size;
1860}
1861
1862void
1863SymbolFileDWARF::Index ()
1864{
1865 if (m_indexed)
1866 return;
1867 m_indexed = true;
1868 Timer scoped_timer (__PRETTY_FUNCTION__,
1869 "SymbolFileDWARF::Index (%s)",
1870 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1871
1872 DWARFDebugInfo* debug_info = DebugInfo();
1873 if (debug_info)
1874 {
1875 uint32_t cu_idx = 0;
1876 const uint32_t num_compile_units = GetNumCompileUnits();
1877 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1878 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001879 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880
Greg Clayton96d7d742010-11-10 23:42:09 +00001881 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001882
Greg Clayton96d7d742010-11-10 23:42:09 +00001883 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001884 m_function_basename_index,
1885 m_function_fullname_index,
1886 m_function_method_index,
1887 m_function_selector_index,
1888 m_objc_class_selectors_index,
1889 m_global_index,
1890 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00001891 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892
1893 // Keep memory down by clearing DIEs if this generate function
1894 // caused them to be parsed
1895 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001896 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897 }
1898
Greg Claytond4a2b372011-09-12 23:21:58 +00001899 m_function_basename_index.Finalize();
1900 m_function_fullname_index.Finalize();
1901 m_function_method_index.Finalize();
1902 m_function_selector_index.Finalize();
1903 m_objc_class_selectors_index.Finalize();
1904 m_global_index.Finalize();
1905 m_type_index.Finalize();
1906 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001907
Greg Clayton24739922010-10-13 03:15:28 +00001908#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00001909 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00001910 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00001911 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1912 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001913 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1914 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1915 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1916 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1917 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1918 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001919 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001920 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001921#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 }
1923}
1924
1925uint32_t
1926SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1927{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001928 DWARFDebugInfo* info = DebugInfo();
1929 if (info == NULL)
1930 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931
1932 // If we aren't appending the results to this list, then clear the list
1933 if (!append)
1934 variables.Clear();
1935
1936 // Remember how many variables are in the list before we search in case
1937 // we are appending the results to a variable list.
1938 const uint32_t original_size = variables.GetSize();
1939
1940 // Index the DWARF if we haven't already
1941 if (!m_indexed)
1942 Index ();
1943
Greg Claytonc685f8e2010-09-15 04:15:46 +00001944 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00001945 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001946 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947
Greg Claytond4a2b372011-09-12 23:21:58 +00001948 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001949 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00001950 DIEArray die_offsets;
1951 const size_t num_matches = m_global_index.Find (name, die_offsets);
1952 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001954 DWARFDebugInfo* debug_info = DebugInfo();
1955 for (size_t i=0; i<num_matches; ++i)
1956 {
1957 const dw_offset_t die_offset = die_offsets[i];
1958 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959
Greg Claytond4a2b372011-09-12 23:21:58 +00001960 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
1961 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962
Greg Claytond4a2b372011-09-12 23:21:58 +00001963 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001964
Greg Claytond4a2b372011-09-12 23:21:58 +00001965 if (variables.GetSize() - original_size >= max_matches)
1966 break;
1967 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001968 }
1969
1970 // Return the number of variable that were appended to the list
1971 return variables.GetSize() - original_size;
1972}
1973
1974uint32_t
1975SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
1976{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001977 DWARFDebugInfo* info = DebugInfo();
1978 if (info == NULL)
1979 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001980
1981 // If we aren't appending the results to this list, then clear the list
1982 if (!append)
1983 variables.Clear();
1984
1985 // Remember how many variables are in the list before we search in case
1986 // we are appending the results to a variable list.
1987 const uint32_t original_size = variables.GetSize();
1988
1989 // Index the DWARF if we haven't already
1990 if (!m_indexed)
1991 Index ();
1992
Greg Claytonc685f8e2010-09-15 04:15:46 +00001993 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00001994 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001995 assert (sc.module_sp);
1996
Greg Claytond4a2b372011-09-12 23:21:58 +00001997 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001998 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00001999 DIEArray die_offsets;
2000 const size_t num_matches = m_global_index.Find (regex, die_offsets);
2001 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002003 DWARFDebugInfo* debug_info = DebugInfo();
2004 for (size_t i=0; i<num_matches; ++i)
2005 {
2006 const dw_offset_t die_offset = die_offsets[i];
2007 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2008 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2009 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010
Greg Claytond4a2b372011-09-12 23:21:58 +00002011 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012
Greg Claytond4a2b372011-09-12 23:21:58 +00002013 if (variables.GetSize() - original_size >= max_matches)
2014 break;
2015 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 }
2017
2018 // Return the number of variable that were appended to the list
2019 return variables.GetSize() - original_size;
2020}
2021
2022
Greg Clayton9e315582011-09-02 04:03:59 +00002023uint32_t
2024SymbolFileDWARF::ResolveFunctions (const DIEArray &die_offsets,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002025 SymbolContextList& sc_list,
2026 const ConstString &name,
2027 uint32_t name_type_mask)
Greg Clayton9e315582011-09-02 04:03:59 +00002028{
2029 DWARFDebugInfo* info = DebugInfo();
2030 if (info == NULL)
2031 return 0;
2032
2033 const uint32_t sc_list_initial_size = sc_list.GetSize();
2034 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002035 sc.module_sp = m_obj_file->GetModule();
Greg Clayton9e315582011-09-02 04:03:59 +00002036 assert (sc.module_sp);
2037
2038 DWARFCompileUnit* dwarf_cu = NULL;
2039 const size_t num_matches = die_offsets.size();
2040 for (size_t i=0; i<num_matches; ++i)
2041 {
2042 const dw_offset_t die_offset = die_offsets[i];
2043 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2044
Greg Clayton2bc22f82011-09-30 03:20:47 +00002045 // If we aren't doing full names,
2046 if ((name_type_mask & eFunctionNameTypeFull) == 0)
2047 {
2048 const char *name_cstr = name.GetCString();
2049 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(name_cstr))
2050 continue;
2051 }
2052
2053
Greg Clayton9e315582011-09-02 04:03:59 +00002054 const DWARFDebugInfoEntry* inlined_die = NULL;
2055 if (die->Tag() == DW_TAG_inlined_subroutine)
2056 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002057 // We only are looking for selectors, which disallows anything inlined
2058 if (name_type_mask == eFunctionNameTypeSelector)
2059 continue;
2060
Greg Clayton9e315582011-09-02 04:03:59 +00002061 inlined_die = die;
2062
2063 while ((die = die->GetParent()) != NULL)
2064 {
2065 if (die->Tag() == DW_TAG_subprogram)
2066 break;
2067 }
2068 }
2069 assert (die->Tag() == DW_TAG_subprogram);
2070 if (GetFunction (dwarf_cu, die, sc))
2071 {
2072 Address addr;
2073 // Parse all blocks if needed
2074 if (inlined_die)
2075 {
2076 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2077 assert (sc.block != NULL);
2078 if (sc.block->GetStartAddress (addr) == false)
2079 addr.Clear();
2080 }
2081 else
2082 {
2083 sc.block = NULL;
2084 addr = sc.function->GetAddressRange().GetBaseAddress();
2085 }
2086
2087 if (addr.IsValid())
2088 {
2089
2090 // We found the function, so we should find the line table
2091 // and line table entry as well
2092 LineTable *line_table = sc.comp_unit->GetLineTable();
2093 if (line_table == NULL)
2094 {
2095 if (ParseCompileUnitLineTable(sc))
2096 line_table = sc.comp_unit->GetLineTable();
2097 }
2098 if (line_table != NULL)
2099 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2100
2101 sc_list.Append(sc);
2102 }
2103 }
2104 }
2105 return sc_list.GetSize() - sc_list_initial_size;
2106}
2107
Greg Clayton0c5cd902010-06-28 21:30:43 +00002108void
2109SymbolFileDWARF::FindFunctions
2110(
2111 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00002112 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00002113 SymbolContextList& sc_list
2114)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002116 DWARFDebugInfo* info = DebugInfo();
2117 if (info == NULL)
2118 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002119
Greg Claytonc685f8e2010-09-15 04:15:46 +00002120 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002121 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002122 assert (sc.module_sp);
2123
Greg Claytond4a2b372011-09-12 23:21:58 +00002124 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002125 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002126 DIEArray die_offsets;
2127 const size_t num_matches = name_to_die.Find (name, die_offsets);
2128 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002129 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002130 DWARFDebugInfo* debug_info = DebugInfo();
2131 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002132 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002133 const dw_offset_t die_offset = die_offsets[i];
2134 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2135 const DWARFDebugInfoEntry* inlined_die = NULL;
2136 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Claytond7e05462010-11-14 00:22:48 +00002137 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002138 inlined_die = die;
2139
2140 while ((die = die->GetParent()) != NULL)
Greg Claytond7e05462010-11-14 00:22:48 +00002141 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002142 if (die->Tag() == DW_TAG_subprogram)
2143 break;
Greg Claytond7e05462010-11-14 00:22:48 +00002144 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002145 }
2146 assert (die->Tag() == DW_TAG_subprogram);
2147 if (GetFunction (dwarf_cu, die, sc))
2148 {
2149 Address addr;
2150 // Parse all blocks if needed
2151 if (inlined_die)
2152 {
2153 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2154 assert (sc.block != NULL);
2155 if (sc.block->GetStartAddress (addr) == false)
2156 addr.Clear();
2157 }
2158 else
2159 {
2160 sc.block = NULL;
2161 addr = sc.function->GetAddressRange().GetBaseAddress();
2162 }
Greg Claytond7e05462010-11-14 00:22:48 +00002163
Greg Claytond4a2b372011-09-12 23:21:58 +00002164 if (addr.IsValid())
2165 {
2166
2167 // We found the function, so we should find the line table
2168 // and line table entry as well
2169 LineTable *line_table = sc.comp_unit->GetLineTable();
2170 if (line_table == NULL)
2171 {
2172 if (ParseCompileUnitLineTable(sc))
2173 line_table = sc.comp_unit->GetLineTable();
2174 }
2175 if (line_table != NULL)
2176 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2177
2178 sc_list.Append(sc);
2179 }
Greg Claytond7e05462010-11-14 00:22:48 +00002180 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002181 }
2182 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002183}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002184
Greg Claytonc685f8e2010-09-15 04:15:46 +00002185
2186void
2187SymbolFileDWARF::FindFunctions
2188(
2189 const RegularExpression &regex,
2190 const NameToDIE &name_to_die,
2191 SymbolContextList& sc_list
2192)
2193{
2194 DWARFDebugInfo* info = DebugInfo();
2195 if (info == NULL)
2196 return;
2197
2198 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002199 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002200 assert (sc.module_sp);
2201
Greg Claytond4a2b372011-09-12 23:21:58 +00002202 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002203 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002204 DIEArray die_offsets;
2205 const size_t num_matches = name_to_die.Find (regex, die_offsets);
2206 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002207 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002208 DWARFDebugInfo* debug_info = DebugInfo();
2209 for (size_t i=0; i<num_matches; ++i)
Greg Claytonab843392010-12-03 17:49:14 +00002210 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002211 const dw_offset_t die_offset = die_offsets[i];
2212 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2213
2214 const DWARFDebugInfoEntry* inlined_die = NULL;
2215 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Claytonab843392010-12-03 17:49:14 +00002216 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002217 inlined_die = die;
2218
2219 while ((die = die->GetParent()) != NULL)
Greg Claytonab843392010-12-03 17:49:14 +00002220 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002221 if (die->Tag() == DW_TAG_subprogram)
2222 break;
Greg Claytonab843392010-12-03 17:49:14 +00002223 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002224 }
2225 assert (die->Tag() == DW_TAG_subprogram);
2226 if (GetFunction (dwarf_cu, die, sc))
2227 {
2228 Address addr;
2229 // Parse all blocks if needed
2230 if (inlined_die)
2231 {
2232 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
2233 assert (sc.block != NULL);
2234 if (sc.block->GetStartAddress (addr) == false)
2235 addr.Clear();
2236 }
2237 else
2238 {
2239 sc.block = NULL;
2240 addr = sc.function->GetAddressRange().GetBaseAddress();
2241 }
Greg Claytonab843392010-12-03 17:49:14 +00002242
Greg Claytond4a2b372011-09-12 23:21:58 +00002243 if (addr.IsValid())
2244 {
2245
2246 // We found the function, so we should find the line table
2247 // and line table entry as well
2248 LineTable *line_table = sc.comp_unit->GetLineTable();
2249 if (line_table == NULL)
2250 {
2251 if (ParseCompileUnitLineTable(sc))
2252 line_table = sc.comp_unit->GetLineTable();
2253 }
2254 if (line_table != NULL)
2255 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2256
2257 sc_list.Append(sc);
2258 }
Greg Claytonab843392010-12-03 17:49:14 +00002259 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002260 }
2261 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002262}
2263
2264uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002265SymbolFileDWARF::FindFunctions (const ConstString &name,
2266 uint32_t name_type_mask,
2267 bool append,
2268 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002269{
2270 Timer scoped_timer (__PRETTY_FUNCTION__,
2271 "SymbolFileDWARF::FindFunctions (name = '%s')",
2272 name.AsCString());
2273
Greg Clayton0c5cd902010-06-28 21:30:43 +00002274 // If we aren't appending the results to this list, then clear the list
2275 if (!append)
2276 sc_list.Clear();
2277
2278 // Remember how many sc_list are in the list before we search in case
2279 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002280
Greg Clayton9e315582011-09-02 04:03:59 +00002281 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002282
2283 // Index the DWARF if we haven't already
2284 if (!m_indexed)
2285 Index ();
2286
2287 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002288 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002289
2290 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002291 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002292
2293 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002294 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002295
2296 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002297 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002298
Greg Clayton4d01ace2011-09-29 16:58:15 +00002299 if (m_apple_names.IsValid())
2300 {
2301 SymbolContextList sc_list_apple;
2302 DIEArray die_offsets;
2303 const uint32_t num_matches = m_apple_names.Find(name.GetCString(), die_offsets);
2304 if (num_matches > 0)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002305 ResolveFunctions (die_offsets, sc_list_apple, name, name_type_mask);
Greg Clayton4d01ace2011-09-29 16:58:15 +00002306 if (sc_list != sc_list_apple)
2307 assert (!"__apple_names results differ from DWARF index results");
2308 }
2309
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002310 // Return the number of variable that were appended to the list
2311 return sc_list.GetSize() - original_size;
2312}
2313
2314
2315uint32_t
2316SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2317{
2318 Timer scoped_timer (__PRETTY_FUNCTION__,
2319 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2320 regex.GetText());
2321
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002322 // If we aren't appending the results to this list, then clear the list
2323 if (!append)
2324 sc_list.Clear();
2325
2326 // Remember how many sc_list are in the list before we search in case
2327 // we are appending the results to a variable list.
2328 uint32_t original_size = sc_list.GetSize();
2329
2330 // Index the DWARF if we haven't already
2331 if (!m_indexed)
2332 Index ();
2333
Greg Claytonc685f8e2010-09-15 04:15:46 +00002334 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002335
Greg Claytonc685f8e2010-09-15 04:15:46 +00002336 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002337
2338 // Return the number of variable that were appended to the list
2339 return sc_list.GetSize() - original_size;
2340}
Jim Ingham318c9f22011-08-26 19:44:13 +00002341
Greg Claytond16e1e52011-07-12 17:06:17 +00002342void
2343SymbolFileDWARF::ReportError (const char *format, ...)
2344{
2345 ::fprintf (stderr,
2346 "error: %s/%s ",
2347 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2348 m_obj_file->GetFileSpec().GetFilename().GetCString());
2349
2350 va_list args;
2351 va_start (args, format);
2352 vfprintf (stderr, format, args);
2353 va_end (args);
2354}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002355
Jim Inghamc1663042011-09-29 22:12:35 +00002356void
2357SymbolFileDWARF::ReportWarning (const char *format, ...)
2358{
2359 ::fprintf (stderr,
2360 "warning: %s/%s ",
2361 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2362 m_obj_file->GetFileSpec().GetFilename().GetCString());
2363
2364 va_list args;
2365 va_start (args, format);
2366 vfprintf (stderr, format, args);
2367 va_end (args);
2368}
2369
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002370uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002371SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002372{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002373 DWARFDebugInfo* info = DebugInfo();
2374 if (info == NULL)
2375 return 0;
2376
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002377 // If we aren't appending the results to this list, then clear the list
2378 if (!append)
2379 types.Clear();
2380
Greg Clayton6dbd3982010-09-15 05:51:24 +00002381 // Index if we already haven't to make sure the compile units
2382 // get indexed and make their global DIE index list
2383 if (!m_indexed)
2384 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002385
Greg Claytonc685f8e2010-09-15 04:15:46 +00002386 const uint32_t initial_types_size = types.GetSize();
Greg Claytond4a2b372011-09-12 23:21:58 +00002387 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002388 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002389 DIEArray die_offsets;
2390 const size_t num_matches = m_type_index.Find (name, die_offsets);
2391 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002392 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002393 DWARFDebugInfo* debug_info = DebugInfo();
2394 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002395 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002396 const dw_offset_t die_offset = die_offsets[i];
2397 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2398
2399 Type *matching_type = ResolveType (dwarf_cu, die);
2400 if (matching_type)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002401 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002402 // We found a type pointer, now find the shared pointer form our type list
2403 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
2404 if (type_sp)
2405 {
2406 types.InsertUnique (type_sp);
2407 if (types.GetSize() >= max_matches)
2408 break;
2409 }
2410 else
2411 {
Jim Inghamc1663042011-09-29 22:12:35 +00002412 ReportError ("error: can't find shared pointer for type 0x%8.8x.\n", matching_type->GetID());
Greg Claytond4a2b372011-09-12 23:21:58 +00002413 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00002414 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002415 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002416 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002417 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002418}
2419
2420
Greg Clayton526e5af2010-11-13 03:52:47 +00002421ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002422SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2423 const ConstString &name)
2424{
Greg Clayton526e5af2010-11-13 03:52:47 +00002425 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002426 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002427 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002428 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002429 // Index if we already haven't to make sure the compile units
2430 // get indexed and make their global DIE index list
2431 if (!m_indexed)
2432 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002433
Greg Claytond4a2b372011-09-12 23:21:58 +00002434
2435 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00002436 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002437 DIEArray die_offsets;
2438 const size_t num_matches = m_namespace_index.Find (name, die_offsets);
2439 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00002440 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002441 DWARFDebugInfo* debug_info = DebugInfo();
2442 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00002443 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002444 const dw_offset_t die_offset = die_offsets[i];
2445 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2446
2447 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
2448 if (clang_namespace_decl)
2449 {
2450 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2451 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2452 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002453 }
2454 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002455 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002456 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002457}
2458
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002459uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002460SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002461{
2462 // Remember how many sc_list are in the list before we search in case
2463 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002464 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002465
2466 const uint32_t num_die_offsets = die_offsets.size();
2467 // Parse all of the types we found from the pubtypes matches
2468 uint32_t i;
2469 uint32_t num_matches = 0;
2470 for (i = 0; i < num_die_offsets; ++i)
2471 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002472 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2473 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002474 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002475 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002476 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002477 assert (type_sp.get() != NULL);
2478 types.InsertUnique (type_sp);
2479 ++num_matches;
2480 if (num_matches >= max_matches)
2481 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002482 }
2483 }
2484
2485 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002486 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002487}
2488
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002489
2490size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00002491SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
2492 clang::DeclContext *containing_decl_ctx,
2493 TypeSP& type_sp,
2494 DWARFCompileUnit* dwarf_cu,
2495 const DWARFDebugInfoEntry *parent_die,
2496 bool skip_artificial,
2497 bool &is_static,
2498 TypeList* type_list,
2499 std::vector<clang_type_t>& function_param_types,
2500 std::vector<clang::ParmVarDecl*>& function_param_decls,
2501 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002502{
2503 if (parent_die == NULL)
2504 return 0;
2505
Greg Claytond88d7592010-09-15 08:33:30 +00002506 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2507
Greg Clayton7fedea22010-11-16 02:10:54 +00002508 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002509 const DWARFDebugInfoEntry *die;
2510 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2511 {
2512 dw_tag_t tag = die->Tag();
2513 switch (tag)
2514 {
2515 case DW_TAG_formal_parameter:
2516 {
2517 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002518 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002519 if (num_attributes > 0)
2520 {
2521 const char *name = NULL;
2522 Declaration decl;
2523 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002524 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002525 // one of None, Auto, Register, Extern, Static, PrivateExtern
2526
Sean Callanane2ef6e32010-09-23 03:01:22 +00002527 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002528 uint32_t i;
2529 for (i=0; i<num_attributes; ++i)
2530 {
2531 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2532 DWARFFormValue form_value;
2533 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2534 {
2535 switch (attr)
2536 {
2537 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2538 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2539 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2540 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2541 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002542 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543 case DW_AT_location:
2544 // if (form_value.BlockData())
2545 // {
2546 // const DataExtractor& debug_info_data = debug_info();
2547 // uint32_t block_length = form_value.Unsigned();
2548 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2549 // }
2550 // else
2551 // {
2552 // }
2553 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002554 case DW_AT_const_value:
2555 case DW_AT_default_value:
2556 case DW_AT_description:
2557 case DW_AT_endianity:
2558 case DW_AT_is_optional:
2559 case DW_AT_segment:
2560 case DW_AT_variable_parameter:
2561 default:
2562 case DW_AT_abstract_origin:
2563 case DW_AT_sibling:
2564 break;
2565 }
2566 }
2567 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002568
Greg Clayton0fffff52010-09-24 05:15:53 +00002569 bool skip = false;
2570 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002571 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002572 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002573 {
2574 // In order to determine if a C++ member function is
2575 // "const" we have to look at the const-ness of "this"...
2576 // Ugly, but that
2577 if (arg_idx == 0)
2578 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002579 if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord)
Sean Callanan763d72a2011-08-02 22:21:50 +00002580 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002581 // Often times compilers omit the "this" name for the
2582 // specification DIEs, so we can't rely upon the name
2583 // being in the formal parameter DIE...
2584 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00002585 {
Greg Clayton5113dc82011-08-12 06:47:54 +00002586 Type *this_type = ResolveTypeUID (param_type_die_offset);
2587 if (this_type)
2588 {
2589 uint32_t encoding_mask = this_type->GetEncodingMask();
2590 if (encoding_mask & Type::eEncodingIsPointerUID)
2591 {
2592 is_static = false;
2593
2594 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
2595 type_quals |= clang::Qualifiers::Const;
2596 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
2597 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002598 }
2599 }
2600 }
2601 }
2602 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002603 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002604 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002605 else
2606 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002607
Greg Clayton0fffff52010-09-24 05:15:53 +00002608 // HACK: Objective C formal parameters "self" and "_cmd"
2609 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002610 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2611 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002612 {
2613 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2614 skip = true;
2615 }
2616 }
2617 }
2618
2619 if (!skip)
2620 {
2621 Type *type = ResolveTypeUID(param_type_die_offset);
2622 if (type)
2623 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002624 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002625
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002626 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002627 assert(param_var_decl);
2628 function_param_decls.push_back(param_var_decl);
2629 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002630 }
2631 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002632 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002633 }
2634 break;
2635
2636 default:
2637 break;
2638 }
2639 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002640 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002641}
2642
2643size_t
2644SymbolFileDWARF::ParseChildEnumerators
2645(
2646 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002647 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002648 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002649 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002650 const DWARFDebugInfoEntry *parent_die
2651)
2652{
2653 if (parent_die == NULL)
2654 return 0;
2655
2656 size_t enumerators_added = 0;
2657 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002658 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2659
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002660 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2661 {
2662 const dw_tag_t tag = die->Tag();
2663 if (tag == DW_TAG_enumerator)
2664 {
2665 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002666 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002667 if (num_child_attributes > 0)
2668 {
2669 const char *name = NULL;
2670 bool got_value = false;
2671 int64_t enum_value = 0;
2672 Declaration decl;
2673
2674 uint32_t i;
2675 for (i=0; i<num_child_attributes; ++i)
2676 {
2677 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2678 DWARFFormValue form_value;
2679 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2680 {
2681 switch (attr)
2682 {
2683 case DW_AT_const_value:
2684 got_value = true;
2685 enum_value = form_value.Unsigned();
2686 break;
2687
2688 case DW_AT_name:
2689 name = form_value.AsCString(&get_debug_str_data());
2690 break;
2691
2692 case DW_AT_description:
2693 default:
2694 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2695 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2696 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2697 case DW_AT_sibling:
2698 break;
2699 }
2700 }
2701 }
2702
2703 if (name && name[0] && got_value)
2704 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002705 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2706 enumerator_clang_type,
2707 decl,
2708 name,
2709 enum_value,
2710 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002711 ++enumerators_added;
2712 }
2713 }
2714 }
2715 }
2716 return enumerators_added;
2717}
2718
2719void
2720SymbolFileDWARF::ParseChildArrayInfo
2721(
2722 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002723 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002724 const DWARFDebugInfoEntry *parent_die,
2725 int64_t& first_index,
2726 std::vector<uint64_t>& element_orders,
2727 uint32_t& byte_stride,
2728 uint32_t& bit_stride
2729)
2730{
2731 if (parent_die == NULL)
2732 return;
2733
2734 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002735 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002736 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2737 {
2738 const dw_tag_t tag = die->Tag();
2739 switch (tag)
2740 {
2741 case DW_TAG_enumerator:
2742 {
2743 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002744 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002745 if (num_child_attributes > 0)
2746 {
2747 const char *name = NULL;
2748 bool got_value = false;
2749 int64_t enum_value = 0;
2750
2751 uint32_t i;
2752 for (i=0; i<num_child_attributes; ++i)
2753 {
2754 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2755 DWARFFormValue form_value;
2756 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2757 {
2758 switch (attr)
2759 {
2760 case DW_AT_const_value:
2761 got_value = true;
2762 enum_value = form_value.Unsigned();
2763 break;
2764
2765 case DW_AT_name:
2766 name = form_value.AsCString(&get_debug_str_data());
2767 break;
2768
2769 case DW_AT_description:
2770 default:
2771 case DW_AT_decl_file:
2772 case DW_AT_decl_line:
2773 case DW_AT_decl_column:
2774 case DW_AT_sibling:
2775 break;
2776 }
2777 }
2778 }
2779 }
2780 }
2781 break;
2782
2783 case DW_TAG_subrange_type:
2784 {
2785 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002786 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002787 if (num_child_attributes > 0)
2788 {
2789 const char *name = NULL;
2790 bool got_value = false;
2791 uint64_t byte_size = 0;
2792 int64_t enum_value = 0;
2793 uint64_t num_elements = 0;
2794 uint64_t lower_bound = 0;
2795 uint64_t upper_bound = 0;
2796 uint32_t i;
2797 for (i=0; i<num_child_attributes; ++i)
2798 {
2799 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2800 DWARFFormValue form_value;
2801 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2802 {
2803 switch (attr)
2804 {
2805 case DW_AT_const_value:
2806 got_value = true;
2807 enum_value = form_value.Unsigned();
2808 break;
2809
2810 case DW_AT_name:
2811 name = form_value.AsCString(&get_debug_str_data());
2812 break;
2813
2814 case DW_AT_count:
2815 num_elements = form_value.Unsigned();
2816 break;
2817
2818 case DW_AT_bit_stride:
2819 bit_stride = form_value.Unsigned();
2820 break;
2821
2822 case DW_AT_byte_stride:
2823 byte_stride = form_value.Unsigned();
2824 break;
2825
2826 case DW_AT_byte_size:
2827 byte_size = form_value.Unsigned();
2828 break;
2829
2830 case DW_AT_lower_bound:
2831 lower_bound = form_value.Unsigned();
2832 break;
2833
2834 case DW_AT_upper_bound:
2835 upper_bound = form_value.Unsigned();
2836 break;
2837
2838 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002839 case DW_AT_abstract_origin:
2840 case DW_AT_accessibility:
2841 case DW_AT_allocated:
2842 case DW_AT_associated:
2843 case DW_AT_data_location:
2844 case DW_AT_declaration:
2845 case DW_AT_description:
2846 case DW_AT_sibling:
2847 case DW_AT_threads_scaled:
2848 case DW_AT_type:
2849 case DW_AT_visibility:
2850 break;
2851 }
2852 }
2853 }
2854
2855 if (upper_bound > lower_bound)
2856 num_elements = upper_bound - lower_bound + 1;
2857
2858 if (num_elements > 0)
2859 element_orders.push_back (num_elements);
2860 }
2861 }
2862 break;
2863 }
2864 }
2865}
2866
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002867TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002868SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002869{
2870 TypeSP type_sp;
2871 if (die != NULL)
2872 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002873 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002874 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002875 if (type_ptr == NULL)
2876 {
Greg Claytonca512b32011-01-14 04:54:56 +00002877 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
2878 assert (lldb_cu);
2879 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00002880 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002881 }
2882 else if (type_ptr != DIE_IS_BEING_PARSED)
2883 {
2884 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002885 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002886 }
2887
2888 }
2889 return type_sp;
2890}
2891
2892clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002893SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002894{
2895 if (die_offset != DW_INVALID_OFFSET)
2896 {
2897 DWARFCompileUnitSP cu_sp;
2898 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Sean Callanan72e49402011-08-05 23:43:37 +00002899 return GetClangDeclContextContainingDIE (cu_sp.get(), die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002900 }
2901 return NULL;
2902}
2903
Sean Callanan72e49402011-08-05 23:43:37 +00002904clang::DeclContext *
2905SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
2906{
2907 if (die_offset != DW_INVALID_OFFSET)
2908 {
2909 DWARFCompileUnitSP cu_sp;
2910 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2911 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
2912 }
2913 return NULL;
2914}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002915
Greg Clayton96d7d742010-11-10 23:42:09 +00002916clang::NamespaceDecl *
2917SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2918{
2919 if (die->Tag() == DW_TAG_namespace)
2920 {
2921 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2922 if (namespace_name)
2923 {
2924 Declaration decl; // TODO: fill in the decl object
Sean Callanan72e49402011-08-05 23:43:37 +00002925 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (curr_cu, die->GetParent()));
Greg Clayton96d7d742010-11-10 23:42:09 +00002926 if (namespace_decl)
Greg Claytona2721472011-06-25 00:44:06 +00002927 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
Greg Clayton96d7d742010-11-10 23:42:09 +00002928 return namespace_decl;
2929 }
2930 }
2931 return NULL;
2932}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002933
2934clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00002935SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2936{
2937 // If this DIE has a specification, or an abstract origin, then trace to those.
2938
2939 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
2940 if (die_offset != DW_INVALID_OFFSET)
2941 return GetClangDeclContextForDIEOffset (sc, die_offset);
2942
2943 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
2944 if (die_offset != DW_INVALID_OFFSET)
2945 return GetClangDeclContextForDIEOffset (sc, die_offset);
2946
2947 // This is the DIE we want. Parse it, then query our map.
2948
2949 ParseType(sc, curr_cu, die, NULL);
2950
2951 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2952 if (pos != m_die_to_decl_ctx.end())
2953 return pos->second;
2954 else
2955 return NULL;
2956}
2957
2958clang::DeclContext *
Greg Clayton2bc22f82011-09-30 03:20:47 +00002959SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002960{
Greg Claytonca512b32011-01-14 04:54:56 +00002961 if (m_clang_tu_decl == NULL)
2962 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002963
Greg Clayton2bc22f82011-09-30 03:20:47 +00002964 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2965
2966 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002967 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002968 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
2969 if (pos != m_die_to_decl_ctx.end())
2970 return pos->second;
2971
2972 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002973 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002974 case DW_TAG_compile_unit:
2975 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002976
Greg Clayton2bc22f82011-09-30 03:20:47 +00002977 case DW_TAG_namespace:
Greg Claytonca512b32011-01-14 04:54:56 +00002978 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002979 const char *namespace_name = decl_ctx_die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL);
2980 if (namespace_name)
Greg Claytonca512b32011-01-14 04:54:56 +00002981 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00002982 Declaration decl; // TODO: fill in the decl object
2983 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextContainingDIE (cu, decl_ctx_die));
2984 if (namespace_decl)
2985 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, decl_ctx_die);
2986 return namespace_decl;
2987 }
2988 }
2989 break;
2990
2991 case DW_TAG_structure_type:
2992 case DW_TAG_union_type:
2993 case DW_TAG_class_type:
2994 {
2995 Type* type = ResolveType (cu, decl_ctx_die);
2996 if (type)
2997 {
2998 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
2999 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003000 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003001 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3002 if (decl_ctx)
3003 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003004 }
3005 }
Greg Claytonca512b32011-01-14 04:54:56 +00003006 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003007 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003008
Greg Clayton2bc22f82011-09-30 03:20:47 +00003009 default:
3010 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003011 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003012 }
Greg Clayton7a345282010-11-09 23:46:37 +00003013 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003014}
3015
Greg Clayton2bc22f82011-09-30 03:20:47 +00003016
3017const DWARFDebugInfoEntry *
3018SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3019{
3020 if (cu && die)
3021 {
3022 const DWARFDebugInfoEntry * const decl_die = die;
3023
3024 while (die != NULL)
3025 {
3026 // If this is the original DIE that we are searching for a declaration
3027 // for, then don't look in the cache as we don't want our own decl
3028 // context to be our decl context...
3029 if (decl_die != die)
3030 {
3031 switch (die->Tag())
3032 {
3033 case DW_TAG_compile_unit:
3034 case DW_TAG_namespace:
3035 case DW_TAG_structure_type:
3036 case DW_TAG_union_type:
3037 case DW_TAG_class_type:
3038 return die;
3039
3040 default:
3041 break;
3042 }
3043 }
3044
3045 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3046 if (die_offset != DW_INVALID_OFFSET)
3047 {
3048 DWARFCompileUnit *spec_cu = cu;
3049 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3050 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3051 if (spec_die_decl_ctx_die)
3052 return spec_die_decl_ctx_die;
3053 }
3054
3055 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3056 if (die_offset != DW_INVALID_OFFSET)
3057 {
3058 DWARFCompileUnit *abs_cu = cu;
3059 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3060 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3061 if (abs_die_decl_ctx_die)
3062 return abs_die_decl_ctx_die;
3063 }
3064
3065 die = die->GetParent();
3066 }
3067 }
3068 return NULL;
3069}
3070
3071
3072
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003073// This function can be used when a DIE is found that is a forward declaration
3074// DIE and we want to try and find a type that has the complete definition.
3075TypeSP
3076SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton1a65ae12011-01-25 23:55:37 +00003077 DWARFCompileUnit* cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003078 const DWARFDebugInfoEntry *die,
3079 const ConstString &type_name
3080)
3081{
3082 TypeSP type_sp;
3083
Greg Clayton1a65ae12011-01-25 23:55:37 +00003084 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003085 return type_sp;
3086
Greg Clayton69974892010-12-03 21:42:06 +00003087 if (!m_indexed)
3088 Index ();
3089
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003090 const dw_tag_t type_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00003091
3092 DWARFCompileUnit* type_cu = NULL;
3093 const DWARFDebugInfoEntry* type_die = NULL;
3094 DIEArray die_offsets;
3095 const size_t num_matches = m_type_index.Find (type_name, die_offsets);
3096 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003097 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003098 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003099 for (size_t i=0; i<num_matches; ++i)
3100 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003101 const dw_offset_t die_offset = die_offsets[i];
3102 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003103
3104 if (type_die != die && type_die->Tag() == type_tag)
3105 {
3106 // Hold off on comparing parent DIE tags until
3107 // we know what happens with stuff in namespaces
3108 // for gcc and clang...
3109 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3110 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3111 //if (parent_die->Tag() == parent_type_die->Tag())
3112 {
3113 Type *resolved_type = ResolveType (type_cu, type_die, false);
3114 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3115 {
3116 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
3117 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00003118 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003119 m_obj_file->GetFileSpec().GetFilename().AsCString(),
3120 type_die->GetOffset(),
3121 type_cu->GetOffset());
3122
3123 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003124 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00003125 if (!type_sp)
3126 {
3127 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
3128 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003129 break;
3130 }
3131 }
3132 }
3133 }
3134 }
3135 return type_sp;
3136}
3137
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003138TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003139SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003140{
3141 TypeSP type_sp;
3142
Greg Clayton1be10fc2010-09-29 01:12:09 +00003143 if (type_is_new_ptr)
3144 *type_is_new_ptr = false;
3145
Sean Callananc7fbf732010-08-06 00:32:49 +00003146 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003147 if (die != NULL)
3148 {
Jim Ingham16746d12011-08-25 23:21:43 +00003149 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3150 if (log && dwarf_cu)
3151 {
Jim Ingham318c9f22011-08-26 19:44:13 +00003152 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00003153 die->DumpLocation (this, dwarf_cu, s);
Jim Ingham318c9f22011-08-26 19:44:13 +00003154 log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
3155
Jim Ingham16746d12011-08-25 23:21:43 +00003156 }
3157
Greg Clayton594e5ed2010-09-27 21:07:38 +00003158 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003159 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003160 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003161 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003162 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003163 if (type_is_new_ptr)
3164 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003165
Greg Clayton594e5ed2010-09-27 21:07:38 +00003166 const dw_tag_t tag = die->Tag();
3167
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003168 bool is_forward_declaration = false;
3169 DWARFDebugInfoEntry::Attributes attributes;
3170 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003171 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003172 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3173 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003174 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003175 Declaration decl;
3176
Greg Clayton4957bf62010-09-30 21:49:03 +00003177 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003178 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003179
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003180 dw_attr_t attr;
3181
3182 switch (tag)
3183 {
3184 case DW_TAG_base_type:
3185 case DW_TAG_pointer_type:
3186 case DW_TAG_reference_type:
3187 case DW_TAG_typedef:
3188 case DW_TAG_const_type:
3189 case DW_TAG_restrict_type:
3190 case DW_TAG_volatile_type:
3191 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003192 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003193 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003194
Greg Claytond88d7592010-09-15 08:33:30 +00003195 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003196 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3198
3199 if (num_attributes > 0)
3200 {
3201 uint32_t i;
3202 for (i=0; i<num_attributes; ++i)
3203 {
3204 attr = attributes.AttributeAtIndex(i);
3205 DWARFFormValue form_value;
3206 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3207 {
3208 switch (attr)
3209 {
3210 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3211 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3212 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3213 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003214
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003215 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003216 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3217 // include the "&"...
3218 if (tag == DW_TAG_reference_type)
3219 {
3220 if (strchr (type_name_cstr, '&') == NULL)
3221 type_name_cstr = NULL;
3222 }
3223 if (type_name_cstr)
3224 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003225 break;
Greg Clayton36909642011-03-15 04:38:20 +00003226 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003227 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3228 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3229 default:
3230 case DW_AT_sibling:
3231 break;
3232 }
3233 }
3234 }
3235 }
3236
Greg Claytonc93237c2010-10-01 20:48:32 +00003237 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);
3238
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003239 switch (tag)
3240 {
3241 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003242 break;
3243
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003244 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003245 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003246 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3247 encoding,
3248 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003249 break;
3250
Greg Clayton526e5af2010-11-13 03:52:47 +00003251 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3252 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3253 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3254 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3255 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3256 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003257 }
3258
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003259 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3260 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3261 {
3262 static ConstString g_objc_type_name_id("id");
3263 static ConstString g_objc_type_name_Class("Class");
3264 static ConstString g_objc_type_name_selector("SEL");
3265
Greg Clayton24739922010-10-13 03:15:28 +00003266 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003267 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003268 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003269 resolve_state = Type::eResolveStateFull;
3270
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003271 }
Greg Clayton24739922010-10-13 03:15:28 +00003272 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003273 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003274 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003275 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003276 }
Greg Clayton24739922010-10-13 03:15:28 +00003277 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003278 {
Sean Callananf6c73082010-12-06 23:53:20 +00003279 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003280 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003281 }
3282 }
3283
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003284 type_sp.reset( new Type (die->GetOffset(),
3285 this,
3286 type_name_const_str,
3287 byte_size,
3288 NULL,
3289 encoding_uid,
3290 encoding_data_type,
3291 &decl,
3292 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003293 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003294
Greg Clayton594e5ed2010-09-27 21:07:38 +00003295 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003296
3297// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3298// if (encoding_type != NULL)
3299// {
3300// if (encoding_type != DIE_IS_BEING_PARSED)
3301// type_sp->SetEncodingType(encoding_type);
3302// else
3303// m_indirect_fixups.push_back(type_sp.get());
3304// }
3305 }
3306 break;
3307
3308 case DW_TAG_structure_type:
3309 case DW_TAG_union_type:
3310 case DW_TAG_class_type:
3311 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003312 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003313 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003314
Greg Clayton9e409562010-07-28 02:04:09 +00003315 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003316 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003317 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003318 if (num_attributes > 0)
3319 {
3320 uint32_t i;
3321 for (i=0; i<num_attributes; ++i)
3322 {
3323 attr = attributes.AttributeAtIndex(i);
3324 DWARFFormValue form_value;
3325 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3326 {
3327 switch (attr)
3328 {
Greg Clayton9e409562010-07-28 02:04:09 +00003329 case DW_AT_decl_file:
3330 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3331 break;
3332
3333 case DW_AT_decl_line:
3334 decl.SetLine(form_value.Unsigned());
3335 break;
3336
3337 case DW_AT_decl_column:
3338 decl.SetColumn(form_value.Unsigned());
3339 break;
3340
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003341 case DW_AT_name:
3342 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003343 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003344 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003345
3346 case DW_AT_byte_size:
3347 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00003348 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00003349 break;
3350
3351 case DW_AT_accessibility:
3352 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3353 break;
3354
3355 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003356 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003357 break;
3358
3359 case DW_AT_APPLE_runtime_class:
3360 class_language = (LanguageType)form_value.Signed();
3361 break;
3362
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003363 case DW_AT_allocated:
3364 case DW_AT_associated:
3365 case DW_AT_data_location:
3366 case DW_AT_description:
3367 case DW_AT_start_scope:
3368 case DW_AT_visibility:
3369 default:
3370 case DW_AT_sibling:
3371 break;
3372 }
3373 }
3374 }
3375 }
3376
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003377 UniqueDWARFASTType unique_ast_entry;
3378 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003379 {
Greg Claytone576ab22011-02-15 00:19:15 +00003380 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00003381 this,
3382 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00003383 die,
3384 decl,
Greg Clayton36909642011-03-15 04:38:20 +00003385 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00003386 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003387 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003388 // We have already parsed this type or from another
3389 // compile unit. GCC loves to use the "one definition
3390 // rule" which can result in multiple definitions
3391 // of the same class over and over in each compile
3392 // unit.
3393 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003394 if (type_sp)
3395 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003396 m_die_to_type[die] = type_sp.get();
3397 return type_sp;
3398 }
3399 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003400 }
3401
3402 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3403
3404 int tag_decl_kind = -1;
3405 AccessType default_accessibility = eAccessNone;
3406 if (tag == DW_TAG_structure_type)
3407 {
3408 tag_decl_kind = clang::TTK_Struct;
3409 default_accessibility = eAccessPublic;
3410 }
3411 else if (tag == DW_TAG_union_type)
3412 {
3413 tag_decl_kind = clang::TTK_Union;
3414 default_accessibility = eAccessPublic;
3415 }
3416 else if (tag == DW_TAG_class_type)
3417 {
3418 tag_decl_kind = clang::TTK_Class;
3419 default_accessibility = eAccessPrivate;
3420 }
3421
3422
3423 if (is_forward_declaration)
3424 {
3425 // We have a forward declaration to a type and we need
3426 // to try and find a full declaration. We look in the
3427 // current type index just in case we have a forward
3428 // declaration followed by an actual declarations in the
3429 // DWARF. If this fails, we need to look elsewhere...
3430
3431 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3432
3433 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00003434 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003435 // We weren't able to find a full declaration in
3436 // this DWARF, see if we have a declaration anywhere
3437 // else...
3438 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00003439 }
3440
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003441 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00003442 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003443 // We found a real definition for this type elsewhere
3444 // so lets use it and cache the fact that we found
3445 // a complete type for this die
3446 m_die_to_type[die] = type_sp.get();
3447 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003448 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003449 }
3450 assert (tag_decl_kind != -1);
3451 bool clang_type_was_created = false;
3452 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3453 if (clang_type == NULL)
3454 {
3455 clang_type_was_created = true;
3456 clang_type = ast.CreateRecordType (type_name_cstr,
3457 tag_decl_kind,
Sean Callanan72e49402011-08-05 23:43:37 +00003458 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003459 class_language);
3460 }
3461
3462 // Store a forward declaration to this class type in case any
3463 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00003464 // types for function prototypes.
3465 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003466 type_sp.reset (new Type (die->GetOffset(),
3467 this,
3468 type_name_const_str,
3469 byte_size,
3470 NULL,
3471 LLDB_INVALID_UID,
3472 Type::eEncodingIsUID,
3473 &decl,
3474 clang_type,
3475 Type::eResolveStateForward));
3476
3477
3478 // Add our type to the unique type map so we don't
3479 // end up creating many copies of the same type over
3480 // and over in the ASTContext for our module
3481 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00003482 unique_ast_entry.m_symfile = this;
3483 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003484 unique_ast_entry.m_die = die;
3485 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00003486 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
3487 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003488
3489 if (die->HasChildren() == false && is_forward_declaration == false)
3490 {
3491 // No children for this struct/union/class, lets finish it
3492 ast.StartTagDeclarationDefinition (clang_type);
3493 ast.CompleteTagDeclarationDefinition (clang_type);
3494 }
3495 else if (clang_type_was_created)
3496 {
3497 // Leave this as a forward declaration until we need
3498 // to know the details of the type. lldb_private::Type
3499 // will automatically call the SymbolFile virtual function
3500 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3501 // When the definition needs to be defined.
3502 m_forward_decl_die_to_clang_type[die] = clang_type;
3503 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
3504 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00003505 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003506 }
3507 break;
3508
3509 case DW_TAG_enumeration_type:
3510 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003511 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003512 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003513
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003514 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003515
Greg Claytond88d7592010-09-15 08:33:30 +00003516 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003517 if (num_attributes > 0)
3518 {
3519 uint32_t i;
3520
3521 for (i=0; i<num_attributes; ++i)
3522 {
3523 attr = attributes.AttributeAtIndex(i);
3524 DWARFFormValue form_value;
3525 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3526 {
3527 switch (attr)
3528 {
Greg Clayton7a345282010-11-09 23:46:37 +00003529 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3530 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3531 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003532 case DW_AT_name:
3533 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003534 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003535 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003536 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003537 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00003538 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3539 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003540 case DW_AT_allocated:
3541 case DW_AT_associated:
3542 case DW_AT_bit_stride:
3543 case DW_AT_byte_stride:
3544 case DW_AT_data_location:
3545 case DW_AT_description:
3546 case DW_AT_start_scope:
3547 case DW_AT_visibility:
3548 case DW_AT_specification:
3549 case DW_AT_abstract_origin:
3550 case DW_AT_sibling:
3551 break;
3552 }
3553 }
3554 }
3555
Greg Claytonc93237c2010-10-01 20:48:32 +00003556 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3557
Greg Clayton1be10fc2010-09-29 01:12:09 +00003558 clang_type_t enumerator_clang_type = NULL;
3559 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3560 if (clang_type == NULL)
3561 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003562 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3563 DW_ATE_signed,
3564 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00003565 clang_type = ast.CreateEnumerationType (type_name_cstr,
Sean Callanan72e49402011-08-05 23:43:37 +00003566 GetClangDeclContextContainingDIE (dwarf_cu, die),
Greg Claytonca512b32011-01-14 04:54:56 +00003567 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003568 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003569 }
3570 else
3571 {
3572 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3573 assert (enumerator_clang_type != NULL);
3574 }
3575
Greg Claytona2721472011-06-25 00:44:06 +00003576 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
3577
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003578 type_sp.reset( new Type (die->GetOffset(),
3579 this,
3580 type_name_const_str,
3581 byte_size,
3582 NULL,
3583 encoding_uid,
3584 Type::eEncodingIsUID,
3585 &decl,
3586 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003587 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003588
Greg Clayton6beaaa62011-01-17 03:46:26 +00003589#if LEAVE_ENUMS_FORWARD_DECLARED
Greg Clayton1be10fc2010-09-29 01:12:09 +00003590 // Leave this as a forward declaration until we need
3591 // to know the details of the type. lldb_private::Type
3592 // will automatically call the SymbolFile virtual function
3593 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3594 // When the definition needs to be defined.
3595 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003596 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003597 ClangASTContext::SetHasExternalStorage (clang_type, true);
3598#else
3599 ast.StartTagDeclarationDefinition (clang_type);
3600 if (die->HasChildren())
3601 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003602 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
3603 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00003604 }
3605 ast.CompleteTagDeclarationDefinition (clang_type);
3606#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003607 }
3608 }
3609 break;
3610
Jim Inghamb0be4422010-08-12 01:20:14 +00003611 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003612 case DW_TAG_subprogram:
3613 case DW_TAG_subroutine_type:
3614 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003615 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003616 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003617
3618 const char *mangled = NULL;
3619 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003620 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003621 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003622 bool is_static = false;
3623 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003624 bool is_explicit = false;
Greg Clayton72da3972011-08-16 18:40:23 +00003625 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
3626 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00003627
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003628 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003629 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003630
3631
Greg Claytond88d7592010-09-15 08:33:30 +00003632 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003633 if (num_attributes > 0)
3634 {
3635 uint32_t i;
3636 for (i=0; i<num_attributes; ++i)
3637 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00003638 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003639 DWARFFormValue form_value;
3640 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3641 {
3642 switch (attr)
3643 {
3644 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3645 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3646 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3647 case DW_AT_name:
3648 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003649 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003650 break;
3651
3652 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3653 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003654 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003655 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003656 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3657 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003658 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3659
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003660 case DW_AT_external:
3661 if (form_value.Unsigned())
3662 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003663 if (storage == clang::SC_None)
3664 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003665 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003666 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003667 }
3668 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003669
Greg Clayton72da3972011-08-16 18:40:23 +00003670 case DW_AT_specification:
3671 specification_die_offset = form_value.Reference(dwarf_cu);
3672 break;
3673
3674 case DW_AT_abstract_origin:
3675 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
3676 break;
3677
3678
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003679 case DW_AT_allocated:
3680 case DW_AT_associated:
3681 case DW_AT_address_class:
3682 case DW_AT_artificial:
3683 case DW_AT_calling_convention:
3684 case DW_AT_data_location:
3685 case DW_AT_elemental:
3686 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003687 case DW_AT_frame_base:
3688 case DW_AT_high_pc:
3689 case DW_AT_low_pc:
3690 case DW_AT_object_pointer:
3691 case DW_AT_prototyped:
3692 case DW_AT_pure:
3693 case DW_AT_ranges:
3694 case DW_AT_recursive:
3695 case DW_AT_return_addr:
3696 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003697 case DW_AT_start_scope:
3698 case DW_AT_static_link:
3699 case DW_AT_trampoline:
3700 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003701 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003702 case DW_AT_description:
3703 case DW_AT_sibling:
3704 break;
3705 }
3706 }
3707 }
Greg Clayton24739922010-10-13 03:15:28 +00003708 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003709
Greg Clayton24739922010-10-13 03:15:28 +00003710 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 +00003711
Greg Clayton24739922010-10-13 03:15:28 +00003712 clang_type_t return_clang_type = NULL;
3713 Type *func_type = NULL;
3714
3715 if (type_die_offset != DW_INVALID_OFFSET)
3716 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003717
Greg Clayton24739922010-10-13 03:15:28 +00003718 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003719 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003720 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003721 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003722
Greg Claytonf51de672010-10-01 02:31:07 +00003723
Greg Clayton24739922010-10-13 03:15:28 +00003724 std::vector<clang_type_t> function_param_types;
3725 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003726
Greg Clayton24739922010-10-13 03:15:28 +00003727 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00003728
Greg Clayton5113dc82011-08-12 06:47:54 +00003729 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
3730 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
3731
3732 const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord;
3733 // Start off static. This will be set to false in ParseChildParameters(...)
3734 // if we find a "this" paramters as the first parameter
3735 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00003736 is_static = true;
3737
Greg Clayton24739922010-10-13 03:15:28 +00003738 if (die->HasChildren())
3739 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003740 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003741 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00003742 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003743 type_sp,
3744 dwarf_cu,
3745 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00003746 skip_artificial,
3747 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003748 type_list,
3749 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003750 function_param_decls,
3751 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003752 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003753
Greg Clayton24739922010-10-13 03:15:28 +00003754 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003755 clang_type = ast.CreateFunctionType (return_clang_type,
3756 &function_param_types[0],
3757 function_param_types.size(),
3758 is_variadic,
3759 type_quals);
3760
Greg Clayton24739922010-10-13 03:15:28 +00003761 if (type_name_cstr)
3762 {
3763 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00003764 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003765 {
Jim Inghamb7f6b2f2011-09-08 22:13:49 +00003766 if (ObjCLanguageRuntime::IsPossibleObjCMethodName (type_name_cstr))
Greg Clayton0fffff52010-09-24 05:15:53 +00003767 {
Greg Clayton24739922010-10-13 03:15:28 +00003768 // We need to find the DW_TAG_class_type or
3769 // DW_TAG_struct_type by name so we can add this
3770 // as a member function of the class.
3771 const char *class_name_start = type_name_cstr + 2;
3772 const char *class_name_end = ::strchr (class_name_start, ' ');
3773 SymbolContext empty_sc;
3774 clang_type_t class_opaque_type = NULL;
3775 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003776 {
Greg Clayton24739922010-10-13 03:15:28 +00003777 ConstString class_name (class_name_start, class_name_end - class_name_start);
3778 TypeList types;
3779 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3780 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003781 {
Greg Clayton24739922010-10-13 03:15:28 +00003782 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003783 {
Greg Clayton24739922010-10-13 03:15:28 +00003784 Type *type = types.GetTypeAtIndex (i).get();
3785 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3786 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003787 {
Greg Clayton24739922010-10-13 03:15:28 +00003788 class_opaque_type = type_clang_forward_type;
3789 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003790 }
3791 }
3792 }
Greg Clayton24739922010-10-13 03:15:28 +00003793 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003794
Greg Clayton24739922010-10-13 03:15:28 +00003795 if (class_opaque_type)
3796 {
3797 // If accessibility isn't set to anything valid, assume public for
3798 // now...
3799 if (accessibility == eAccessNone)
3800 accessibility = eAccessPublic;
3801
3802 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003803 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3804 type_name_cstr,
3805 clang_type,
3806 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003807 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00003808 type_handled = objc_method_decl != NULL;
3809 }
3810 }
Greg Clayton5113dc82011-08-12 06:47:54 +00003811 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00003812 {
3813 // Look at the parent of this DIE and see if is is
3814 // a class or struct and see if this is actually a
3815 // C++ method
Greg Clayton5113dc82011-08-12 06:47:54 +00003816 Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]);
Greg Clayton24739922010-10-13 03:15:28 +00003817 if (class_type)
3818 {
Greg Clayton72da3972011-08-16 18:40:23 +00003819 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00003820 {
Greg Clayton72da3972011-08-16 18:40:23 +00003821 // If we have a specification, then the function type should have been
3822 // made with the specification and not with this die.
3823 DWARFCompileUnitSP spec_cu_sp;
3824 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
3825 if (m_die_to_decl_ctx[spec_die] == NULL)
Jim Inghamc1663042011-09-29 22:12:35 +00003826 {
3827 ReportWarning ("0x%8.8x: DW_AT_specification(0x%8.8x) has no decl\n",
3828 die->GetOffset(),
3829 specification_die_offset);
3830 }
Greg Clayton72da3972011-08-16 18:40:23 +00003831 type_handled = true;
3832 }
3833 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
3834 {
3835 DWARFCompileUnitSP abs_cu_sp;
3836 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
3837 if (m_die_to_decl_ctx[abs_die] == NULL)
Jim Inghamc1663042011-09-29 22:12:35 +00003838 {
3839 ReportWarning ("0x%8.8x: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
3840 die->GetOffset(),
3841 abstract_origin_die_offset);
3842 }
Greg Clayton72da3972011-08-16 18:40:23 +00003843 type_handled = true;
3844 }
3845 else
3846 {
3847 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3848 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00003849 {
Greg Clayton72da3972011-08-16 18:40:23 +00003850 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3851 // in the DWARF for C++ methods... Default to public for now...
3852 if (accessibility == eAccessNone)
3853 accessibility = eAccessPublic;
3854
3855 if (!is_static && !die->HasChildren())
3856 {
3857 // We have a C++ member function with no children (this pointer!)
3858 // and clang will get mad if we try and make a function that isn't
3859 // well formed in the DWARF, so we will just skip it...
3860 type_handled = true;
3861 }
3862 else
3863 {
3864 clang::CXXMethodDecl *cxx_method_decl;
3865 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3866 type_name_cstr,
3867 clang_type,
3868 accessibility,
3869 is_virtual,
3870 is_static,
3871 is_inline,
3872 is_explicit);
3873 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00003874
Greg Clayton72da3972011-08-16 18:40:23 +00003875 type_handled = cxx_method_decl != NULL;
3876 }
Greg Clayton931180e2011-01-27 06:44:37 +00003877 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003878 }
3879 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003880 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003881 }
Greg Clayton24739922010-10-13 03:15:28 +00003882
3883 if (!type_handled)
3884 {
3885 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003886 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3887 clang_type,
3888 storage,
3889 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003890
3891 // Add the decl to our DIE to decl context map
3892 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00003893 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00003894 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003895 ast.SetFunctionParameters (function_decl,
3896 &function_param_decls.front(),
3897 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003898 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003899 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003900 type_sp.reset( new Type (die->GetOffset(),
3901 this,
3902 type_name_const_str,
3903 0,
3904 NULL,
3905 LLDB_INVALID_UID,
3906 Type::eEncodingIsUID,
3907 &decl,
3908 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003909 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00003910 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003911 }
3912 break;
3913
3914 case DW_TAG_array_type:
3915 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003916 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003917 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003918
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003919 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003920 int64_t first_index = 0;
3921 uint32_t byte_stride = 0;
3922 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003923 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003924
3925 if (num_attributes > 0)
3926 {
3927 uint32_t i;
3928 for (i=0; i<num_attributes; ++i)
3929 {
3930 attr = attributes.AttributeAtIndex(i);
3931 DWARFFormValue form_value;
3932 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3933 {
3934 switch (attr)
3935 {
3936 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3937 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3938 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3939 case DW_AT_name:
3940 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003941 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003942 break;
3943
3944 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00003945 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003946 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3947 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003948 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003949 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003950 case DW_AT_allocated:
3951 case DW_AT_associated:
3952 case DW_AT_data_location:
3953 case DW_AT_description:
3954 case DW_AT_ordering:
3955 case DW_AT_start_scope:
3956 case DW_AT_visibility:
3957 case DW_AT_specification:
3958 case DW_AT_abstract_origin:
3959 case DW_AT_sibling:
3960 break;
3961 }
3962 }
3963 }
3964
Greg Claytonc93237c2010-10-01 20:48:32 +00003965 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3966
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003967 Type *element_type = ResolveTypeUID(type_die_offset);
3968
3969 if (element_type)
3970 {
3971 std::vector<uint64_t> element_orders;
3972 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00003973 // We have an array that claims to have no members, lets give it at least one member...
3974 if (element_orders.empty())
3975 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003976 if (byte_stride == 0 && bit_stride == 0)
3977 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00003978 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003979 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3980 uint64_t num_elements = 0;
3981 std::vector<uint64_t>::const_reverse_iterator pos;
3982 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3983 for (pos = element_orders.rbegin(); pos != end; ++pos)
3984 {
3985 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003986 clang_type = ast.CreateArrayType (array_element_type,
3987 num_elements,
3988 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003989 array_element_type = clang_type;
3990 array_element_bit_stride = array_element_bit_stride * num_elements;
3991 }
3992 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003993 type_sp.reset( new Type (die->GetOffset(),
3994 this,
3995 empty_name,
3996 array_element_bit_stride / 8,
3997 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00003998 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003999 Type::eEncodingIsUID,
4000 &decl,
4001 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004002 Type::eResolveStateFull));
4003 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004004 }
4005 }
4006 }
4007 break;
4008
Greg Clayton9b81a312010-06-12 01:20:30 +00004009 case DW_TAG_ptr_to_member_type:
4010 {
4011 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
4012 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
4013
Greg Claytond88d7592010-09-15 08:33:30 +00004014 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00004015
4016 if (num_attributes > 0) {
4017 uint32_t i;
4018 for (i=0; i<num_attributes; ++i)
4019 {
4020 attr = attributes.AttributeAtIndex(i);
4021 DWARFFormValue form_value;
4022 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4023 {
4024 switch (attr)
4025 {
4026 case DW_AT_type:
4027 type_die_offset = form_value.Reference(dwarf_cu); break;
4028 case DW_AT_containing_type:
4029 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
4030 }
4031 }
4032 }
4033
4034 Type *pointee_type = ResolveTypeUID(type_die_offset);
4035 Type *class_type = ResolveTypeUID(containing_type_die_offset);
4036
Greg Clayton526e5af2010-11-13 03:52:47 +00004037 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
4038 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00004039
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004040 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
4041 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00004042
Greg Clayton526e5af2010-11-13 03:52:47 +00004043 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
4044 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00004045
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004046 type_sp.reset( new Type (die->GetOffset(),
4047 this,
4048 type_name_const_str,
4049 byte_size,
4050 NULL,
4051 LLDB_INVALID_UID,
4052 Type::eEncodingIsUID,
4053 NULL,
4054 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004055 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00004056 }
4057
4058 break;
4059 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004060 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00004061 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004062 break;
4063 }
4064
4065 if (type_sp.get())
4066 {
4067 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4068 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4069
4070 SymbolContextScope * symbol_context_scope = NULL;
4071 if (sc_parent_tag == DW_TAG_compile_unit)
4072 {
4073 symbol_context_scope = sc.comp_unit;
4074 }
4075 else if (sc.function != NULL)
4076 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004077 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004078 if (symbol_context_scope == NULL)
4079 symbol_context_scope = sc.function;
4080 }
4081
4082 if (symbol_context_scope != NULL)
4083 {
4084 type_sp->SetSymbolContextScope(symbol_context_scope);
4085 }
4086
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004087 // We are ready to put this type into the uniqued list up at the module level
4088 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00004089
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004090 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004091 }
4092 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00004093 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004094 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004095 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004096 }
4097 }
4098 return type_sp;
4099}
4100
4101size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00004102SymbolFileDWARF::ParseTypes
4103(
4104 const SymbolContext& sc,
4105 DWARFCompileUnit* dwarf_cu,
4106 const DWARFDebugInfoEntry *die,
4107 bool parse_siblings,
4108 bool parse_children
4109)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004110{
4111 size_t types_added = 0;
4112 while (die != NULL)
4113 {
4114 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004115 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004116 {
4117 if (type_is_new)
4118 ++types_added;
4119 }
4120
4121 if (parse_children && die->HasChildren())
4122 {
4123 if (die->Tag() == DW_TAG_subprogram)
4124 {
4125 SymbolContext child_sc(sc);
4126 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
4127 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4128 }
4129 else
4130 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4131 }
4132
4133 if (parse_siblings)
4134 die = die->GetSibling();
4135 else
4136 die = NULL;
4137 }
4138 return types_added;
4139}
4140
4141
4142size_t
4143SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4144{
4145 assert(sc.comp_unit && sc.function);
4146 size_t functions_added = 0;
4147 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4148 if (dwarf_cu)
4149 {
4150 dw_offset_t function_die_offset = sc.function->GetID();
4151 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4152 if (function_die)
4153 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004154 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004155 }
4156 }
4157
4158 return functions_added;
4159}
4160
4161
4162size_t
4163SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4164{
4165 // At least a compile unit must be valid
4166 assert(sc.comp_unit);
4167 size_t types_added = 0;
4168 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4169 if (dwarf_cu)
4170 {
4171 if (sc.function)
4172 {
4173 dw_offset_t function_die_offset = sc.function->GetID();
4174 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4175 if (func_die && func_die->HasChildren())
4176 {
4177 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4178 }
4179 }
4180 else
4181 {
4182 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4183 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4184 {
4185 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4186 }
4187 }
4188 }
4189
4190 return types_added;
4191}
4192
4193size_t
4194SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4195{
4196 if (sc.comp_unit != NULL)
4197 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004198 DWARFDebugInfo* info = DebugInfo();
4199 if (info == NULL)
4200 return 0;
4201
4202 uint32_t cu_idx = UINT32_MAX;
4203 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004204
4205 if (dwarf_cu == NULL)
4206 return 0;
4207
4208 if (sc.function)
4209 {
4210 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004211
4212 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4213 assert (func_lo_pc != DW_INVALID_ADDRESS);
4214
Greg Claytonc662ec82011-06-17 22:10:16 +00004215 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4216
4217 // Let all blocks know they have parse all their variables
4218 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4219
4220 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004221 }
4222 else if (sc.comp_unit)
4223 {
4224 uint32_t vars_added = 0;
4225 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4226
4227 if (variables.get() == NULL)
4228 {
4229 variables.reset(new VariableList());
4230 sc.comp_unit->SetVariableList(variables);
4231
4232 // Index if we already haven't to make sure the compile units
4233 // get indexed and make their global DIE index list
4234 if (!m_indexed)
4235 Index ();
4236
Greg Claytond4a2b372011-09-12 23:21:58 +00004237 DWARFCompileUnit* match_dwarf_cu = NULL;
4238 const DWARFDebugInfoEntry* die = NULL;
4239 DIEArray die_offsets;
4240 const size_t num_matches = m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
4241 dwarf_cu->GetNextCompileUnitOffset(),
4242 die_offsets);
4243 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004244 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004245 DWARFDebugInfo* debug_info = DebugInfo();
4246 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004247 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004248 const dw_offset_t die_offset = die_offsets[i];
4249 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
4250 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
4251 if (var_sp)
4252 {
4253 variables->AddVariableIfUnique (var_sp);
4254 ++vars_added;
4255 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004256 }
4257 }
4258 }
4259 return vars_added;
4260 }
4261 }
4262 return 0;
4263}
4264
4265
4266VariableSP
4267SymbolFileDWARF::ParseVariableDIE
4268(
4269 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004270 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004271 const DWARFDebugInfoEntry *die,
4272 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004273)
4274{
4275
Greg Clayton83c5cd92010-11-14 22:13:40 +00004276 VariableSP var_sp (m_die_to_variable_sp[die]);
4277 if (var_sp)
4278 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004279
4280 const dw_tag_t tag = die->Tag();
4281 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00004282 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004283 if (num_attributes > 0)
4284 {
4285 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00004286 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004287 Declaration decl;
4288 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004289 Type *var_type = NULL;
4290 DWARFExpression location;
4291 bool is_external = false;
4292 bool is_artificial = false;
Greg Clayton007d5be2011-05-30 00:49:24 +00004293 bool location_is_const_value_data = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00004294 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004295
4296 for (i=0; i<num_attributes; ++i)
4297 {
4298 dw_attr_t attr = attributes.AttributeAtIndex(i);
4299 DWARFFormValue form_value;
4300 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4301 {
4302 switch (attr)
4303 {
4304 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4305 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4306 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4307 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00004308 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00004309 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004310 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
Greg Clayton007d5be2011-05-30 00:49:24 +00004311 case DW_AT_const_value:
4312 location_is_const_value_data = true;
4313 // Fall through...
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004314 case DW_AT_location:
4315 {
4316 if (form_value.BlockData())
4317 {
4318 const DataExtractor& debug_info_data = get_debug_info_data();
4319
4320 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4321 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00004322 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004323 }
4324 else
4325 {
4326 const DataExtractor& debug_loc_data = get_debug_loc_data();
4327 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4328
4329 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4330 if (loc_list_length > 0)
4331 {
Greg Clayton016a95e2010-09-14 02:20:48 +00004332 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
4333 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4334 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004335 }
4336 }
4337 }
4338 break;
4339
4340 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004341 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004342 case DW_AT_declaration:
4343 case DW_AT_description:
4344 case DW_AT_endianity:
4345 case DW_AT_segment:
4346 case DW_AT_start_scope:
4347 case DW_AT_visibility:
4348 default:
4349 case DW_AT_abstract_origin:
4350 case DW_AT_sibling:
4351 case DW_AT_specification:
4352 break;
4353 }
4354 }
4355 }
4356
4357 if (location.IsValid())
4358 {
4359 assert(var_type != DIE_IS_BEING_PARSED);
4360
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004361 ValueType scope = eValueTypeInvalid;
4362
4363 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4364 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4365
4366 if (tag == DW_TAG_formal_parameter)
4367 scope = eValueTypeVariableArgument;
4368 else if (is_external || parent_tag == DW_TAG_compile_unit)
4369 scope = eValueTypeVariableGlobal;
4370 else
4371 scope = eValueTypeVariableLocal;
4372
4373 SymbolContextScope * symbol_context_scope = NULL;
4374 if (parent_tag == DW_TAG_compile_unit)
4375 {
4376 symbol_context_scope = sc.comp_unit;
4377 }
4378 else if (sc.function != NULL)
4379 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00004380 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004381 if (symbol_context_scope == NULL)
4382 symbol_context_scope = sc.function;
4383 }
4384
4385 assert(symbol_context_scope != NULL);
4386 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00004387 name,
4388 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004389 var_type,
4390 scope,
4391 symbol_context_scope,
4392 &decl,
4393 location,
4394 is_external,
4395 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00004396
Greg Clayton007d5be2011-05-30 00:49:24 +00004397 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004398 }
4399 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00004400 // Cache var_sp even if NULL (the variable was just a specification or
4401 // was missing vital information to be able to be displayed in the debugger
4402 // (missing location due to optimization, etc)) so we don't re-parse
4403 // this DIE over and over later...
4404 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004405 return var_sp;
4406}
4407
Greg Claytonc662ec82011-06-17 22:10:16 +00004408
4409const DWARFDebugInfoEntry *
4410SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
4411 dw_offset_t spec_block_die_offset,
4412 DWARFCompileUnit **result_die_cu_handle)
4413{
4414 // Give the concrete function die specified by "func_die_offset", find the
4415 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4416 // to "spec_block_die_offset"
4417 DWARFDebugInfo* info = DebugInfo();
4418
4419 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
4420 if (die)
4421 {
4422 assert (*result_die_cu_handle);
4423 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
4424 }
4425 return NULL;
4426}
4427
4428
4429const DWARFDebugInfoEntry *
4430SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
4431 const DWARFDebugInfoEntry *die,
4432 dw_offset_t spec_block_die_offset,
4433 DWARFCompileUnit **result_die_cu_handle)
4434{
4435 if (die)
4436 {
4437 switch (die->Tag())
4438 {
4439 case DW_TAG_subprogram:
4440 case DW_TAG_inlined_subroutine:
4441 case DW_TAG_lexical_block:
4442 {
4443 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4444 {
4445 *result_die_cu_handle = dwarf_cu;
4446 return die;
4447 }
4448
4449 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4450 {
4451 *result_die_cu_handle = dwarf_cu;
4452 return die;
4453 }
4454 }
4455 break;
4456 }
4457
4458 // Give the concrete function die specified by "func_die_offset", find the
4459 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4460 // to "spec_block_die_offset"
4461 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
4462 {
4463 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
4464 child_die,
4465 spec_block_die_offset,
4466 result_die_cu_handle);
4467 if (result_die)
4468 return result_die;
4469 }
4470 }
4471
4472 *result_die_cu_handle = NULL;
4473 return NULL;
4474}
4475
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004476size_t
4477SymbolFileDWARF::ParseVariables
4478(
4479 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004480 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004481 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004482 const DWARFDebugInfoEntry *orig_die,
4483 bool parse_siblings,
4484 bool parse_children,
4485 VariableList* cc_variable_list
4486)
4487{
4488 if (orig_die == NULL)
4489 return 0;
4490
Greg Claytonc662ec82011-06-17 22:10:16 +00004491 VariableListSP variable_list_sp;
4492
4493 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004494 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004495 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004496 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004497 dw_tag_t tag = die->Tag();
4498
4499 // Check to see if we have already parsed this variable or constant?
4500 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004501 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004502 if (cc_variable_list)
4503 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004504 }
4505 else
4506 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004507 // We haven't already parsed it, lets do that now.
4508 if ((tag == DW_TAG_variable) ||
4509 (tag == DW_TAG_constant) ||
4510 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004511 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004512 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004513 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004514 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4515 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4516 switch (parent_tag)
4517 {
4518 case DW_TAG_compile_unit:
4519 if (sc.comp_unit != NULL)
4520 {
4521 variable_list_sp = sc.comp_unit->GetVariableList(false);
4522 if (variable_list_sp.get() == NULL)
4523 {
4524 variable_list_sp.reset(new VariableList());
4525 sc.comp_unit->SetVariableList(variable_list_sp);
4526 }
4527 }
4528 else
4529 {
Jim Inghamc1663042011-09-29 22:12:35 +00004530 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 +00004531 sc_parent_die->GetOffset(),
4532 DW_TAG_value_to_name (parent_tag),
4533 orig_die->GetOffset(),
4534 DW_TAG_value_to_name (orig_die->Tag()));
4535 }
4536 break;
4537
4538 case DW_TAG_subprogram:
4539 case DW_TAG_inlined_subroutine:
4540 case DW_TAG_lexical_block:
4541 if (sc.function != NULL)
4542 {
4543 // Check to see if we already have parsed the variables for the given scope
4544
4545 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
4546 if (block == NULL)
4547 {
4548 // This must be a specification or abstract origin with
4549 // a concrete block couterpart in the current function. We need
4550 // to find the concrete block so we can correctly add the
4551 // variable to it
4552 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
4553 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4554 sc_parent_die->GetOffset(),
4555 &concrete_block_die_cu);
4556 if (concrete_block_die)
4557 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die->GetOffset());
4558 }
4559
4560 if (block != NULL)
4561 {
4562 const bool can_create = false;
4563 variable_list_sp = block->GetBlockVariableList (can_create);
4564 if (variable_list_sp.get() == NULL)
4565 {
4566 variable_list_sp.reset(new VariableList());
4567 block->SetVariableList(variable_list_sp);
4568 }
4569 }
4570 }
4571 break;
4572
4573 default:
Jim Inghamc1663042011-09-29 22:12:35 +00004574 ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8x %s.\n",
Greg Claytonc662ec82011-06-17 22:10:16 +00004575 orig_die->GetOffset(),
4576 DW_TAG_value_to_name (orig_die->Tag()));
4577 break;
4578 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004579 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004580
4581 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004582 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00004583 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
4584 if (var_sp)
4585 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004586 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004587 if (cc_variable_list)
4588 cc_variable_list->AddVariableIfUnique (var_sp);
4589 ++vars_added;
4590 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004591 }
4592 }
4593 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004594
4595 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4596
4597 if (!skip_children && parse_children && die->HasChildren())
4598 {
4599 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
4600 }
4601
4602 if (parse_siblings)
4603 die = die->GetSibling();
4604 else
4605 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004606 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004607 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004608}
4609
4610//------------------------------------------------------------------
4611// PluginInterface protocol
4612//------------------------------------------------------------------
4613const char *
4614SymbolFileDWARF::GetPluginName()
4615{
4616 return "SymbolFileDWARF";
4617}
4618
4619const char *
4620SymbolFileDWARF::GetShortPluginName()
4621{
4622 return GetPluginNameStatic();
4623}
4624
4625uint32_t
4626SymbolFileDWARF::GetPluginVersion()
4627{
4628 return 1;
4629}
4630
4631void
Greg Clayton6beaaa62011-01-17 03:46:26 +00004632SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
4633{
4634 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4635 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4636 if (clang_type)
4637 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4638}
4639
4640void
4641SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
4642{
4643 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4644 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
4645 if (clang_type)
4646 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
4647}
4648
Greg Claytona2721472011-06-25 00:44:06 +00004649void
Sean Callanancc427fa2011-07-30 02:42:06 +00004650SymbolFileDWARF::DumpIndexes ()
4651{
4652 StreamFile s(stdout, false);
4653
4654 s.Printf ("DWARF index for (%s) '%s/%s':",
4655 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4656 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
4657 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
4658 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4659 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4660 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4661 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4662 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4663 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4664 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
4665 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
4666}
4667
4668void
4669SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
4670 const char *name,
4671 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00004672{
Sean Callanancc427fa2011-07-30 02:42:06 +00004673 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00004674
4675 if (iter == m_decl_ctx_to_die.end())
4676 return;
4677
Sean Callanancc427fa2011-07-30 02:42:06 +00004678 const DWARFDebugInfoEntry *context_die = iter->second;
Greg Claytona2721472011-06-25 00:44:06 +00004679
4680 if (!results)
4681 return;
4682
4683 DWARFDebugInfo* info = DebugInfo();
4684
Greg Claytond4a2b372011-09-12 23:21:58 +00004685 DIEArray die_offsets;
Greg Claytona2721472011-06-25 00:44:06 +00004686
Greg Claytond4a2b372011-09-12 23:21:58 +00004687 DWARFCompileUnit* dwarf_cu = NULL;
4688 const DWARFDebugInfoEntry* die = NULL;
4689 size_t num_matches = m_type_index.Find (ConstString(name), die_offsets);
Greg Claytona2721472011-06-25 00:44:06 +00004690
4691 if (num_matches)
4692 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004693 for (size_t i = 0; i < num_matches; ++i)
Greg Claytona2721472011-06-25 00:44:06 +00004694 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004695 const dw_offset_t die_offset = die_offsets[i];
4696 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4697
Sean Callanancc427fa2011-07-30 02:42:06 +00004698 if (die->GetParent() != context_die)
Greg Claytona2721472011-06-25 00:44:06 +00004699 continue;
4700
Greg Claytond4a2b372011-09-12 23:21:58 +00004701 Type *matching_type = ResolveType (dwarf_cu, die);
Greg Claytona2721472011-06-25 00:44:06 +00004702
4703 lldb::clang_type_t type = matching_type->GetClangFullType();
4704 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
4705
Sean Callanancc427fa2011-07-30 02:42:06 +00004706 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004707 {
4708 clang::TagDecl *tag_decl = tag_type->getDecl();
4709 results->push_back(tag_decl);
4710 }
Sean Callanancc427fa2011-07-30 02:42:06 +00004711 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
Greg Claytona2721472011-06-25 00:44:06 +00004712 {
4713 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
4714 results->push_back(typedef_decl);
4715 }
4716 }
4717 }
4718}
4719
4720void
4721SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
4722 const clang::DeclContext *DC,
4723 clang::DeclarationName Name,
4724 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
4725{
4726 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
4727
Sean Callanancc427fa2011-07-30 02:42:06 +00004728 symbol_file_dwarf->SearchDeclContext (DC, Name.getAsString().c_str(), results);
Greg Claytona2721472011-06-25 00:44:06 +00004729}