blob: ce300727f7b4d2add3d431ba25467a6136db321f [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
25#include "lldb/Core/Module.h"
26#include "lldb/Core/PluginManager.h"
27#include "lldb/Core/RegularExpression.h"
28#include "lldb/Core/Scalar.h"
29#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000030#include "lldb/Core/StreamFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/Timer.h"
32#include "lldb/Core/Value.h"
33
34#include "lldb/Symbol/Block.h"
35#include "lldb/Symbol/CompileUnit.h"
36#include "lldb/Symbol/LineTable.h"
37#include "lldb/Symbol/ObjectFile.h"
38#include "lldb/Symbol/SymbolVendor.h"
39#include "lldb/Symbol/VariableList.h"
40
41#include "DWARFCompileUnit.h"
42#include "DWARFDebugAbbrev.h"
43#include "DWARFDebugAranges.h"
44#include "DWARFDebugInfo.h"
45#include "DWARFDebugInfoEntry.h"
46#include "DWARFDebugLine.h"
47#include "DWARFDebugPubnames.h"
48#include "DWARFDebugRanges.h"
49#include "DWARFDIECollection.h"
50#include "DWARFFormValue.h"
51#include "DWARFLocationList.h"
52#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000053#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55#include <map>
56
Greg Clayton62742b12010-11-11 01:09:45 +000057//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000058
59#ifdef ENABLE_DEBUG_PRINTF
60#include <stdio.h>
61#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
62#else
63#define DEBUG_PRINTF(fmt, ...)
64#endif
65
Greg Clayton594e5ed2010-09-27 21:07:38 +000066#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68using namespace lldb;
69using namespace lldb_private;
70
71
Sean Callananc7fbf732010-08-06 00:32:49 +000072static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000073DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074{
75 switch (dwarf_accessibility)
76 {
Sean Callananc7fbf732010-08-06 00:32:49 +000077 case DW_ACCESS_public: return eAccessPublic;
78 case DW_ACCESS_private: return eAccessPrivate;
79 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000080 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081 }
Sean Callananc7fbf732010-08-06 00:32:49 +000082 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083}
84
85void
86SymbolFileDWARF::Initialize()
87{
88 LogChannelDWARF::Initialize();
89 PluginManager::RegisterPlugin (GetPluginNameStatic(),
90 GetPluginDescriptionStatic(),
91 CreateInstance);
92}
93
94void
95SymbolFileDWARF::Terminate()
96{
97 PluginManager::UnregisterPlugin (CreateInstance);
98 LogChannelDWARF::Initialize();
99}
100
101
102const char *
103SymbolFileDWARF::GetPluginNameStatic()
104{
105 return "symbol-file.dwarf2";
106}
107
108const char *
109SymbolFileDWARF::GetPluginDescriptionStatic()
110{
111 return "DWARF and DWARF3 debug symbol file reader.";
112}
113
114
115SymbolFile*
116SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
117{
118 return new SymbolFileDWARF(obj_file);
119}
120
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000121
122ClangASTContext &
123SymbolFileDWARF::GetClangASTContext()
124{
125 return GetTypeList()->GetClangASTContext();
126}
127
128TypeList *
129SymbolFileDWARF::GetTypeList ()
130{
131 if (m_debug_map_symfile)
132 return m_debug_map_symfile->GetTypeList();
133 return m_obj_file->GetModule()->GetTypeList();
134
135}
136
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137//----------------------------------------------------------------------
138// Gets the first parent that is a lexical block, function or inlined
139// subroutine, or compile unit.
140//----------------------------------------------------------------------
141static const DWARFDebugInfoEntry *
142GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
143{
144 const DWARFDebugInfoEntry *die;
145 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
146 {
147 dw_tag_t tag = die->Tag();
148
149 switch (tag)
150 {
151 case DW_TAG_compile_unit:
152 case DW_TAG_subprogram:
153 case DW_TAG_inlined_subroutine:
154 case DW_TAG_lexical_block:
155 return die;
156 }
157 }
158 return NULL;
159}
160
161
Greg Clayton450e3f32010-10-12 02:24:53 +0000162SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
163 SymbolFile (objfile),
164 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000165 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166 m_flags(),
167 m_data_debug_abbrev(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168 m_data_debug_frame(),
169 m_data_debug_info(),
170 m_data_debug_line(),
171 m_data_debug_loc(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172 m_data_debug_ranges(),
173 m_data_debug_str(),
174 m_abbr(),
175 m_aranges(),
176 m_info(),
177 m_line(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000178 m_function_basename_index(),
179 m_function_fullname_index(),
180 m_function_method_index(),
181 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000182 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000183 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000184 m_type_index(),
185 m_namespace_index(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 m_indexed(false),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000187 m_ranges()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188{
189}
190
191SymbolFileDWARF::~SymbolFileDWARF()
192{
193}
194
195bool
196SymbolFileDWARF::SupportedVersion(uint16_t version)
197{
198 return version == 2 || version == 3;
199}
200
201uint32_t
202SymbolFileDWARF::GetAbilities ()
203{
204 uint32_t abilities = 0;
205 if (m_obj_file != NULL)
206 {
207 const Section* section = NULL;
208 const SectionList *section_list = m_obj_file->GetSectionList();
209 if (section_list == NULL)
210 return 0;
211
212 uint64_t debug_abbrev_file_size = 0;
213 uint64_t debug_aranges_file_size = 0;
214 uint64_t debug_frame_file_size = 0;
215 uint64_t debug_info_file_size = 0;
216 uint64_t debug_line_file_size = 0;
217 uint64_t debug_loc_file_size = 0;
218 uint64_t debug_macinfo_file_size = 0;
219 uint64_t debug_pubnames_file_size = 0;
220 uint64_t debug_pubtypes_file_size = 0;
221 uint64_t debug_ranges_file_size = 0;
222 uint64_t debug_str_file_size = 0;
223
224 static ConstString g_dwarf_section_name ("__DWARF");
225
226 section = section_list->FindSectionByName(g_dwarf_section_name).get();
227
228 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000229 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
Greg Clayton4ceb9982010-07-21 22:54:26 +0000231 section_list = &section->GetChildren ();
232 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233
Greg Clayton4ceb9982010-07-21 22:54:26 +0000234 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 if (section != NULL)
236 {
237 debug_info_file_size = section->GetByteSize();
238
Greg Clayton4ceb9982010-07-21 22:54:26 +0000239 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 if (section)
241 debug_abbrev_file_size = section->GetByteSize();
242 else
243 m_flags.Set (flagsGotDebugAbbrevData);
244
Greg Clayton4ceb9982010-07-21 22:54:26 +0000245 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246 if (section)
247 debug_aranges_file_size = section->GetByteSize();
248 else
249 m_flags.Set (flagsGotDebugArangesData);
250
Greg Clayton4ceb9982010-07-21 22:54:26 +0000251 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 if (section)
253 debug_frame_file_size = section->GetByteSize();
254 else
255 m_flags.Set (flagsGotDebugFrameData);
256
Greg Clayton4ceb9982010-07-21 22:54:26 +0000257 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 if (section)
259 debug_line_file_size = section->GetByteSize();
260 else
261 m_flags.Set (flagsGotDebugLineData);
262
Greg Clayton4ceb9982010-07-21 22:54:26 +0000263 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264 if (section)
265 debug_loc_file_size = section->GetByteSize();
266 else
267 m_flags.Set (flagsGotDebugLocData);
268
Greg Clayton4ceb9982010-07-21 22:54:26 +0000269 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 if (section)
271 debug_macinfo_file_size = section->GetByteSize();
272 else
273 m_flags.Set (flagsGotDebugMacInfoData);
274
Greg Clayton4ceb9982010-07-21 22:54:26 +0000275 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 if (section)
277 debug_pubnames_file_size = section->GetByteSize();
278 else
279 m_flags.Set (flagsGotDebugPubNamesData);
280
Greg Clayton4ceb9982010-07-21 22:54:26 +0000281 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 if (section)
283 debug_pubtypes_file_size = section->GetByteSize();
284 else
285 m_flags.Set (flagsGotDebugPubTypesData);
286
Greg Clayton4ceb9982010-07-21 22:54:26 +0000287 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288 if (section)
289 debug_ranges_file_size = section->GetByteSize();
290 else
291 m_flags.Set (flagsGotDebugRangesData);
292
Greg Clayton4ceb9982010-07-21 22:54:26 +0000293 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294 if (section)
295 debug_str_file_size = section->GetByteSize();
296 else
297 m_flags.Set (flagsGotDebugStrData);
298 }
299
300 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
301 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
302
303 if (debug_line_file_size > 0)
304 abilities |= LineTables;
305
306 if (debug_aranges_file_size > 0)
307 abilities |= AddressAcceleratorTable;
308
309 if (debug_pubnames_file_size > 0)
310 abilities |= FunctionAcceleratorTable;
311
312 if (debug_pubtypes_file_size > 0)
313 abilities |= TypeAcceleratorTable;
314
315 if (debug_macinfo_file_size > 0)
316 abilities |= MacroInformation;
317
318 if (debug_frame_file_size > 0)
319 abilities |= CallFrameInformation;
320 }
321 return abilities;
322}
323
324const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000325SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000326{
327 if (m_flags.IsClear (got_flag))
328 {
329 m_flags.Set (got_flag);
330 const SectionList *section_list = m_obj_file->GetSectionList();
331 if (section_list)
332 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000333 Section *section = section_list->FindSectionByType(sect_type, true).get();
334 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335 {
336 // See if we memory mapped the DWARF segment?
337 if (m_dwarf_data.GetByteSize())
338 {
339 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
340 }
341 else
342 {
343 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
344 data.Clear();
345 }
346 }
347 }
348 }
349 return data;
350}
351
352const DataExtractor&
353SymbolFileDWARF::get_debug_abbrev_data()
354{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000355 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356}
357
358const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359SymbolFileDWARF::get_debug_frame_data()
360{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000361 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
364const DataExtractor&
365SymbolFileDWARF::get_debug_info_data()
366{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000367 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368}
369
370const DataExtractor&
371SymbolFileDWARF::get_debug_line_data()
372{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000373 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374}
375
376const DataExtractor&
377SymbolFileDWARF::get_debug_loc_data()
378{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000379 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380}
381
382const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383SymbolFileDWARF::get_debug_ranges_data()
384{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000385 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386}
387
388const DataExtractor&
389SymbolFileDWARF::get_debug_str_data()
390{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000391 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392}
393
394
395DWARFDebugAbbrev*
396SymbolFileDWARF::DebugAbbrev()
397{
398 if (m_abbr.get() == NULL)
399 {
400 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
401 if (debug_abbrev_data.GetByteSize() > 0)
402 {
403 m_abbr.reset(new DWARFDebugAbbrev());
404 if (m_abbr.get())
405 m_abbr->Parse(debug_abbrev_data);
406 }
407 }
408 return m_abbr.get();
409}
410
411const DWARFDebugAbbrev*
412SymbolFileDWARF::DebugAbbrev() const
413{
414 return m_abbr.get();
415}
416
417DWARFDebugAranges*
418SymbolFileDWARF::DebugAranges()
419{
Greg Clayton016a95e2010-09-14 02:20:48 +0000420 // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files
421 // and we are already parsing all of the DWARF because the .debug_pubnames
422 // is useless (it only mentions symbols that are externally visible), so
423 // don't use the .debug_aranges section, we should be using a debug aranges
424 // we got from SymbolFileDWARF::Index().
425
426 if (!m_indexed)
427 Index();
428
429
430// if (m_aranges.get() == NULL)
431// {
432// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
433// m_aranges.reset(new DWARFDebugAranges());
434// if (m_aranges.get())
435// {
436// const DataExtractor &debug_aranges_data = get_debug_aranges_data();
437// if (debug_aranges_data.GetByteSize() > 0)
438// m_aranges->Extract(debug_aranges_data);
439// else
440// m_aranges->Generate(this);
441// }
442// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 return m_aranges.get();
444}
445
446const DWARFDebugAranges*
447SymbolFileDWARF::DebugAranges() const
448{
449 return m_aranges.get();
450}
451
452
453DWARFDebugInfo*
454SymbolFileDWARF::DebugInfo()
455{
456 if (m_info.get() == NULL)
457 {
458 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
459 if (get_debug_info_data().GetByteSize() > 0)
460 {
461 m_info.reset(new DWARFDebugInfo());
462 if (m_info.get())
463 {
464 m_info->SetDwarfData(this);
465 }
466 }
467 }
468 return m_info.get();
469}
470
471const DWARFDebugInfo*
472SymbolFileDWARF::DebugInfo() const
473{
474 return m_info.get();
475}
476
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477DWARFCompileUnit*
478SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
479{
480 DWARFDebugInfo* info = DebugInfo();
481 if (info)
482 return info->GetCompileUnit(cu_uid).get();
483 return NULL;
484}
485
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486
487DWARFDebugRanges*
488SymbolFileDWARF::DebugRanges()
489{
490 if (m_ranges.get() == NULL)
491 {
492 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
493 if (get_debug_ranges_data().GetByteSize() > 0)
494 {
495 m_ranges.reset(new DWARFDebugRanges());
496 if (m_ranges.get())
497 m_ranges->Extract(this);
498 }
499 }
500 return m_ranges.get();
501}
502
503const DWARFDebugRanges*
504SymbolFileDWARF::DebugRanges() const
505{
506 return m_ranges.get();
507}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508
509bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000510SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511{
Greg Clayton96d7d742010-11-10 23:42:09 +0000512 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000514 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515 if (cu_die)
516 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000517 const char * cu_die_name = cu_die->GetName(this, curr_cu);
518 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
519 LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 if (cu_die_name)
521 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000522 FileSpec cu_file_spec;
523
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 if (cu_die_name[0] == '/' || cu_comp_dir == NULL && cu_comp_dir[0])
525 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000526 // If we have a full path to the compile unit, we don't need to resolve
527 // the file. This can be expensive e.g. when the source files are NFS mounted.
528 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 }
530 else
531 {
532 std::string fullpath(cu_comp_dir);
533 if (*fullpath.rbegin() != '/')
534 fullpath += '/';
535 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000536 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 }
538
Greg Clayton96d7d742010-11-10 23:42:09 +0000539 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), curr_cu, cu_file_spec, curr_cu->GetOffset(), class_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540 if (compile_unit_sp.get())
541 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000542 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 return true;
544 }
545 }
546 }
547 }
548 return false;
549}
550
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551uint32_t
552SymbolFileDWARF::GetNumCompileUnits()
553{
554 DWARFDebugInfo* info = DebugInfo();
555 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 return 0;
558}
559
560CompUnitSP
561SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
562{
563 CompUnitSP comp_unit;
564 DWARFDebugInfo* info = DebugInfo();
565 if (info)
566 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000567 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
568 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
570 // Our symbol vendor shouldn't be asking us to add a compile unit that
571 // has already been added to it, which this DWARF plug-in knows as it
572 // stores the lldb compile unit (CompileUnit) pointer in each
573 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000574 assert(curr_cu->GetUserData() == NULL);
575 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 }
577 }
578 return comp_unit;
579}
580
581static void
582AddRangesToBlock
583(
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000584 Block& block,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585 DWARFDebugRanges::RangeList& ranges,
586 addr_t block_base_addr
587)
588{
589 ranges.SubtractOffset (block_base_addr);
590 size_t range_idx = 0;
591 const DWARFDebugRanges::Range *debug_range;
592 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
593 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000594 block.AddRange(debug_range->begin_offset, debug_range->end_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 }
596}
597
598
599Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000600SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601{
602 DWARFDebugRanges::RangeList func_ranges;
603 const char *name = NULL;
604 const char *mangled = NULL;
605 int decl_file = 0;
606 int decl_line = 0;
607 int decl_column = 0;
608 int call_file = 0;
609 int call_line = 0;
610 int call_column = 0;
611 DWARFExpression frame_base;
612
Greg Claytonc93237c2010-10-01 20:48:32 +0000613 assert (die->Tag() == DW_TAG_subprogram);
614
615 if (die->Tag() != DW_TAG_subprogram)
616 return NULL;
617
618 const DWARFDebugInfoEntry *parent_die = die->GetParent();
619 switch (parent_die->Tag())
620 {
621 case DW_TAG_structure_type:
622 case DW_TAG_class_type:
623 // We have methods of a class or struct
624 {
625 Type *class_type = ResolveType (dwarf_cu, parent_die);
626 if (class_type)
627 class_type->GetClangType();
628 }
629 break;
630
631 default:
632 // Parse the function prototype as a type that can then be added to concrete function instance
633 ParseTypes (sc, dwarf_cu, die, false, false);
634 break;
635 }
636
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 //FixupTypes();
638
639 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
640 {
641 // Union of all ranges in the function DIE (if the function is discontiguous)
642 AddressRange func_range;
643 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
644 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
645 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
646 {
647 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
648 if (func_range.GetBaseAddress().IsValid())
649 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
650 }
651
652 if (func_range.GetBaseAddress().IsValid())
653 {
654 Mangled func_name;
655 if (mangled)
656 func_name.SetValue(mangled, true);
657 else if (name)
658 func_name.SetValue(name, false);
659
660 FunctionSP func_sp;
661 std::auto_ptr<Declaration> decl_ap;
662 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000663 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
664 decl_line,
665 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000666
Greg Clayton594e5ed2010-09-27 21:07:38 +0000667 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668
669 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
670
671 func_range.GetBaseAddress().ResolveLinkedAddress();
672
673 func_sp.reset(new Function (sc.comp_unit,
674 die->GetOffset(), // UserID is the DIE offset
675 die->GetOffset(),
676 func_name,
677 func_type,
678 func_range)); // first address range
679
680 if (func_sp.get() != NULL)
681 {
682 func_sp->GetFrameBaseExpression() = frame_base;
683 sc.comp_unit->AddFunction(func_sp);
684 return func_sp.get();
685 }
686 }
687 }
688 return NULL;
689}
690
691size_t
692SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
693{
694 assert (sc.comp_unit);
695 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000696 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 if (dwarf_cu)
698 {
699 DWARFDIECollection function_dies;
700 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
701 size_t func_idx;
702 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
703 {
704 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
705 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
706 {
707 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
708 ++functions_added;
709 }
710 }
711 //FixupTypes();
712 }
713 return functions_added;
714}
715
716bool
717SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
718{
719 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000720 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
721 assert (curr_cu);
722 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000723
724 if (cu_die)
725 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000726 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
727 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 +0000728
729 // All file indexes in DWARF are one based and a file of index zero is
730 // supposed to be the compile unit itself.
731 support_files.Append (*sc.comp_unit);
732
733 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
734 }
735 return false;
736}
737
738struct ParseDWARFLineTableCallbackInfo
739{
740 LineTable* line_table;
741 const SectionList *section_list;
742 lldb::addr_t prev_sect_file_base_addr;
743 lldb::addr_t curr_sect_file_base_addr;
744 bool is_oso_for_debug_map;
745 bool prev_in_final_executable;
746 DWARFDebugLine::Row prev_row;
747 SectionSP prev_section_sp;
748 SectionSP curr_section_sp;
749};
750
751//----------------------------------------------------------------------
752// ParseStatementTableCallback
753//----------------------------------------------------------------------
754static void
755ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
756{
757 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
758 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
759 {
760 // Just started parsing the line table
761 }
762 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
763 {
764 // Done parsing line table, nothing to do for the cleanup
765 }
766 else
767 {
768 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
769 // We have a new row, lets append it
770
771 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
772 {
773 info->prev_section_sp = info->curr_section_sp;
774 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
775 // If this is an end sequence entry, then we subtract one from the
776 // address to make sure we get an address that is not the end of
777 // a section.
778 if (state.end_sequence && state.address != 0)
779 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
780 else
781 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
782
783 if (info->curr_section_sp.get())
784 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
785 else
786 info->curr_sect_file_base_addr = 0;
787 }
788 if (info->curr_section_sp.get())
789 {
790 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
791 // Check for the fancy section magic to determine if we
792
793 if (info->is_oso_for_debug_map)
794 {
795 // When this is a debug map object file that contains DWARF
796 // (referenced from an N_OSO debug map nlist entry) we will have
797 // a file address in the file range for our section from the
798 // original .o file, and a load address in the executable that
799 // contains the debug map.
800 //
801 // If the sections for the file range and load range are
802 // different, we have a remapped section for the function and
803 // this address is resolved. If they are the same, then the
804 // function for this address didn't make it into the final
805 // executable.
806 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
807
808 // If we are doing DWARF with debug map, then we need to carefully
809 // add each line table entry as there may be gaps as functions
810 // get moved around or removed.
811 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
812 {
813 if (info->prev_in_final_executable)
814 {
815 bool terminate_previous_entry = false;
816 if (!curr_in_final_executable)
817 {
818 // Check for the case where the previous line entry
819 // in a function made it into the final executable,
820 // yet the current line entry falls in a function
821 // that didn't. The line table used to be contiguous
822 // through this address range but now it isn't. We
823 // need to terminate the previous line entry so
824 // that we can reconstruct the line range correctly
825 // for it and to keep the line table correct.
826 terminate_previous_entry = true;
827 }
828 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
829 {
830 // Check for cases where the line entries used to be
831 // contiguous address ranges, but now they aren't.
832 // This can happen when order files specify the
833 // ordering of the functions.
834 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
835 Section *curr_sect = info->curr_section_sp.get();
836 Section *prev_sect = info->prev_section_sp.get();
837 assert (curr_sect->GetLinkedSection());
838 assert (prev_sect->GetLinkedSection());
839 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
840 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
841 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
842 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
843 if (object_file_addr_delta != linked_file_addr_delta)
844 terminate_previous_entry = true;
845 }
846
847 if (terminate_previous_entry)
848 {
849 line_table->InsertLineEntry (info->prev_section_sp,
850 state.address - info->prev_sect_file_base_addr,
851 info->prev_row.line,
852 info->prev_row.column,
853 info->prev_row.file,
854 false, // is_stmt
855 false, // basic_block
856 false, // state.prologue_end
857 false, // state.epilogue_begin
858 true); // end_sequence);
859 }
860 }
861 }
862
863 if (curr_in_final_executable)
864 {
865 line_table->InsertLineEntry (info->curr_section_sp,
866 curr_line_section_offset,
867 state.line,
868 state.column,
869 state.file,
870 state.is_stmt,
871 state.basic_block,
872 state.prologue_end,
873 state.epilogue_begin,
874 state.end_sequence);
875 info->prev_section_sp = info->curr_section_sp;
876 }
877 else
878 {
879 // If the current address didn't make it into the final
880 // executable, the current section will be the __text
881 // segment in the .o file, so we need to clear this so
882 // we can catch the next function that did make it into
883 // the final executable.
884 info->prev_section_sp.reset();
885 info->curr_section_sp.reset();
886 }
887
888 info->prev_in_final_executable = curr_in_final_executable;
889 }
890 else
891 {
892 // We are not in an object file that contains DWARF for an
893 // N_OSO, this is just a normal DWARF file. The DWARF spec
894 // guarantees that the addresses will be in increasing order
895 // so, since we store line tables in file address order, we
896 // can always just append the line entry without needing to
897 // search for the correct insertion point (we don't need to
898 // use LineEntry::InsertLineEntry()).
899 line_table->AppendLineEntry (info->curr_section_sp,
900 curr_line_section_offset,
901 state.line,
902 state.column,
903 state.file,
904 state.is_stmt,
905 state.basic_block,
906 state.prologue_end,
907 state.epilogue_begin,
908 state.end_sequence);
909 }
910 }
911
912 info->prev_row = state;
913 }
914}
915
916bool
917SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
918{
919 assert (sc.comp_unit);
920 if (sc.comp_unit->GetLineTable() != NULL)
921 return true;
922
923 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
924 if (dwarf_cu)
925 {
926 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
927 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
928 if (cu_line_offset != DW_INVALID_OFFSET)
929 {
930 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
931 if (line_table_ap.get())
932 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000933 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 +0000934 uint32_t offset = cu_line_offset;
935 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
936 sc.comp_unit->SetLineTable(line_table_ap.release());
937 return true;
938 }
939 }
940 }
941 return false;
942}
943
944size_t
945SymbolFileDWARF::ParseFunctionBlocks
946(
947 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000948 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +0000949 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000950 const DWARFDebugInfoEntry *die,
951 addr_t subprogram_low_pc,
952 bool parse_siblings,
953 bool parse_children
954)
955{
956 size_t blocks_added = 0;
957 while (die != NULL)
958 {
959 dw_tag_t tag = die->Tag();
960
961 switch (tag)
962 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000963 case DW_TAG_inlined_subroutine:
Jim Inghamb0be4422010-08-12 01:20:14 +0000964 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 case DW_TAG_lexical_block:
966 {
967 DWARFDebugRanges::RangeList ranges;
968 const char *name = NULL;
969 const char *mangled_name = NULL;
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000970 Block *block = NULL;
971 if (tag != DW_TAG_subprogram)
972 {
973 BlockSP block_sp(new Block (die->GetOffset()));
974 parent_block->AddChild(block_sp);
975 block = block_sp.get();
976 }
977 else
978 {
979 block = parent_block;
980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000982 int decl_file = 0;
983 int decl_line = 0;
984 int decl_column = 0;
985 int call_file = 0;
986 int call_line = 0;
987 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000988 if (die->GetDIENamesAndRanges (this,
989 dwarf_cu,
990 name,
991 mangled_name,
992 ranges,
993 decl_file, decl_line, decl_column,
994 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 {
996 if (tag == DW_TAG_subprogram)
997 {
998 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
999 subprogram_low_pc = ranges.LowestAddress(0);
1000 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001001 else if (tag == DW_TAG_inlined_subroutine)
1002 {
1003 // We get called here for inlined subroutines in two ways.
1004 // The first time is when we are making the Function object
1005 // for this inlined concrete instance. Since we're creating a top level block at
1006 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1007 // adjust the containing address.
1008 // The second time is when we are parsing the blocks inside the function that contains
1009 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1010 // function the offset will be for that function.
1011 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1012 {
1013 subprogram_low_pc = ranges.LowestAddress(0);
1014 }
1015 }
1016
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001017 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018
1019 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1020 {
1021 std::auto_ptr<Declaration> decl_ap;
1022 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001023 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1024 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025
1026 std::auto_ptr<Declaration> call_ap;
1027 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001028 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1029 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001031 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032 }
1033
1034 ++blocks_added;
1035
1036 if (parse_children && die->HasChildren())
1037 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001038 blocks_added += ParseFunctionBlocks (sc,
1039 block,
1040 dwarf_cu,
1041 die->GetFirstChild(),
1042 subprogram_low_pc,
1043 true,
1044 true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 }
1046 }
1047 }
1048 break;
1049 default:
1050 break;
1051 }
1052
1053 if (parse_siblings)
1054 die = die->GetSibling();
1055 else
1056 die = NULL;
1057 }
1058 return blocks_added;
1059}
1060
1061size_t
1062SymbolFileDWARF::ParseChildMembers
1063(
1064 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001065 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001067 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001068 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001069 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1070 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001071 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001072 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073 bool &is_a_class
1074)
1075{
1076 if (parent_die == NULL)
1077 return 0;
1078
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079 size_t count = 0;
1080 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001081 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1082
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001083 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1084 {
1085 dw_tag_t tag = die->Tag();
1086
1087 switch (tag)
1088 {
1089 case DW_TAG_member:
1090 {
1091 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001092 const size_t num_attributes = die->GetAttributes (this,
1093 dwarf_cu,
1094 fixed_form_sizes,
1095 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001096 if (num_attributes > 0)
1097 {
1098 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001099 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001101 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001103 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001104 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001105 size_t byte_size = 0;
1106 size_t bit_offset = 0;
1107 size_t bit_size = 0;
1108 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001109 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 {
1111 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1112 DWARFFormValue form_value;
1113 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1114 {
1115 switch (attr)
1116 {
1117 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1118 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1119 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1120 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1121 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1122 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1123 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1124 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1125 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001126// if (form_value.BlockData())
1127// {
1128// Value initialValue(0);
1129// Value memberOffset(0);
1130// const DataExtractor& debug_info_data = get_debug_info_data();
1131// uint32_t block_length = form_value.Unsigned();
1132// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1133// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1134// {
1135// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1136// }
1137// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 break;
1139
Greg Clayton8cf05932010-07-22 18:30:50 +00001140 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001141 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 case DW_AT_declaration:
1143 case DW_AT_description:
1144 case DW_AT_mutable:
1145 case DW_AT_visibility:
1146 default:
1147 case DW_AT_sibling:
1148 break;
1149 }
1150 }
1151 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001152
1153 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1154
1155 if (class_language == eLanguageTypeObjC ||
1156 class_language == eLanguageTypeObjC_plus_plus)
1157 accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158
Greg Clayton24739922010-10-13 03:15:28 +00001159 if (is_artificial == false)
1160 {
1161 Type *member_type = ResolveTypeUID(encoding_uid);
1162 assert(member_type);
1163 if (accessibility == eAccessNone)
1164 accessibility = default_accessibility;
1165 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166
Greg Claytonba2d22d2010-11-13 22:57:37 +00001167 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1168 name,
1169 member_type->GetClangLayoutType(),
1170 accessibility,
1171 bit_size);
Greg Clayton24739922010-10-13 03:15:28 +00001172 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173 }
1174 }
1175 break;
1176
1177 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001178 // Let the type parsing code handle this one for us.
1179 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180 break;
1181
1182 case DW_TAG_inheritance:
1183 {
1184 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001185 if (default_accessibility == eAccessNone)
1186 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 // TODO: implement DW_TAG_inheritance type parsing
1188 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001189 const size_t num_attributes = die->GetAttributes (this,
1190 dwarf_cu,
1191 fixed_form_sizes,
1192 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193 if (num_attributes > 0)
1194 {
1195 Declaration decl;
1196 DWARFExpression location;
1197 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001198 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199 bool is_virtual = false;
1200 bool is_base_of_class = true;
1201 off_t member_offset = 0;
1202 uint32_t i;
1203 for (i=0; i<num_attributes; ++i)
1204 {
1205 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1206 DWARFFormValue form_value;
1207 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1208 {
1209 switch (attr)
1210 {
1211 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1212 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1213 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1214 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1215 case DW_AT_data_member_location:
1216 if (form_value.BlockData())
1217 {
1218 Value initialValue(0);
1219 Value memberOffset(0);
1220 const DataExtractor& debug_info_data = get_debug_info_data();
1221 uint32_t block_length = form_value.Unsigned();
1222 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001223 if (DWARFExpression::Evaluate (NULL,
1224 NULL,
1225 debug_info_data,
1226 NULL,
1227 NULL,
1228 block_offset,
1229 block_length,
1230 eRegisterKindDWARF,
1231 &initialValue,
1232 memberOffset,
1233 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 {
1235 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1236 }
1237 }
1238 break;
1239
1240 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001241 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 break;
1243
1244 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1245 default:
1246 case DW_AT_sibling:
1247 break;
1248 }
1249 }
1250 }
1251
Greg Clayton526e5af2010-11-13 03:52:47 +00001252 Type *base_class_type = ResolveTypeUID(encoding_uid);
1253 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001254
1255 if (class_language == eLanguageTypeObjC)
1256 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001257 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_type->GetClangType());
Greg Clayton9e409562010-07-28 02:04:09 +00001258 }
1259 else
1260 {
Greg Claytonba2d22d2010-11-13 22:57:37 +00001261 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_type->GetClangType(),
1262 accessibility,
1263 is_virtual,
1264 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001265 assert(base_classes.back());
1266 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 }
1268 }
1269 break;
1270
1271 default:
1272 break;
1273 }
1274 }
1275 return count;
1276}
1277
1278
1279clang::DeclContext*
1280SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid)
1281{
1282 DWARFDebugInfo* debug_info = DebugInfo();
1283 if (debug_info)
1284 {
1285 DWARFCompileUnitSP cu_sp;
1286 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1287 if (die)
1288 return GetClangDeclContextForDIE (cu_sp.get(), die);
1289 }
1290 return NULL;
1291}
1292
1293Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001294SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001295{
1296 DWARFDebugInfo* debug_info = DebugInfo();
1297 if (debug_info)
1298 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00001299 DWARFCompileUnitSP cu_sp;
1300 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 if (type_die != NULL)
Greg Clayton594e5ed2010-09-27 21:07:38 +00001302 return ResolveType (cu_sp.get(), type_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303 }
1304 return NULL;
1305}
1306
Greg Clayton1be10fc2010-09-29 01:12:09 +00001307lldb::clang_type_t
1308SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1309{
1310 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Claytonc93237c2010-10-01 20:48:32 +00001311 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (ClangASTType::RemoveFastQualifiers(clang_type));
Greg Clayton1be10fc2010-09-29 01:12:09 +00001312 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001313 {
1314 // We have already resolved this type...
1315 return clang_type;
1316 }
1317 // Once we start resolving this type, remove it from the forward declaration
1318 // map in case anyone child members or other types require this type to get resolved.
1319 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1320 // are done.
1321 m_forward_decl_clang_type_to_die.erase (ClangASTType::RemoveFastQualifiers(clang_type));
1322
Greg Clayton1be10fc2010-09-29 01:12:09 +00001323
Greg Clayton450e3f32010-10-12 02:24:53 +00001324 DWARFDebugInfo* debug_info = DebugInfo();
1325
Greg Clayton96d7d742010-11-10 23:42:09 +00001326 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001327 Type *type = m_die_to_type.lookup (die);
1328
1329 const dw_tag_t tag = die->Tag();
1330
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001331 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n",
1332 die->GetOffset(),
1333 DW_TAG_value_to_name(tag),
1334 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001335 assert (clang_type);
1336 DWARFDebugInfoEntry::Attributes attributes;
1337
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001338 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001339
1340 switch (tag)
1341 {
1342 case DW_TAG_structure_type:
1343 case DW_TAG_union_type:
1344 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001345 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001346 if (die->HasChildren())
1347 {
1348 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001349 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1350 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001351 class_language = eLanguageTypeObjC;
1352
1353 int tag_decl_kind = -1;
1354 AccessType default_accessibility = eAccessNone;
1355 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001356 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001357 tag_decl_kind = clang::TTK_Struct;
1358 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001359 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001360 else if (tag == DW_TAG_union_type)
1361 {
1362 tag_decl_kind = clang::TTK_Union;
1363 default_accessibility = eAccessPublic;
1364 }
1365 else if (tag == DW_TAG_class_type)
1366 {
1367 tag_decl_kind = clang::TTK_Class;
1368 default_accessibility = eAccessPrivate;
1369 }
1370
Greg Clayton96d7d742010-11-10 23:42:09 +00001371 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001372 std::vector<clang::CXXBaseSpecifier *> base_classes;
1373 std::vector<int> member_accessibilities;
1374 bool is_a_class = false;
1375 // Parse members and base classes first
1376 DWARFDIECollection member_function_dies;
1377
1378 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001379 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001380 die,
1381 clang_type,
1382 class_language,
1383 base_classes,
1384 member_accessibilities,
1385 member_function_dies,
1386 default_accessibility,
1387 is_a_class);
1388
1389 // Now parse any methods if there were any...
1390 size_t num_functions = member_function_dies.Size();
1391 if (num_functions > 0)
1392 {
1393 for (size_t i=0; i<num_functions; ++i)
1394 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001395 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001396 }
1397 }
1398
Greg Clayton450e3f32010-10-12 02:24:53 +00001399 if (class_language == eLanguageTypeObjC)
1400 {
1401 std::string class_str (ClangASTContext::GetTypeName (clang_type));
1402 if (!class_str.empty())
1403 {
1404
1405 ConstString class_name (class_str.c_str());
1406 std::vector<NameToDIE::Info> method_die_infos;
1407 if (m_objc_class_selectors_index.Find (class_name, method_die_infos))
1408 {
1409 DWARFCompileUnit* method_cu = NULL;
1410 DWARFCompileUnit* prev_method_cu = NULL;
1411 const size_t num_objc_methods = method_die_infos.size();
1412 for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu)
1413 {
1414 method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx);
1415
1416 if (method_cu != prev_method_cu)
1417 method_cu->ExtractDIEsIfNeeded (false);
1418
1419 DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx);
1420
1421 ResolveType (method_cu, method_die);
1422 }
1423 }
1424 }
1425 }
1426
Greg Claytonc93237c2010-10-01 20:48:32 +00001427 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1428 // need to tell the clang type it is actually a class.
1429 if (class_language != eLanguageTypeObjC)
1430 {
1431 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001432 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001433 }
1434
1435 // Since DW_TAG_structure_type gets used for both classes
1436 // and structures, we may need to set any DW_TAG_member
1437 // fields to have a "private" access if none was specified.
1438 // When we parsed the child members we tracked that actual
1439 // accessibility value for each DW_TAG_member in the
1440 // "member_accessibilities" array. If the value for the
1441 // member is zero, then it was set to the "default_accessibility"
1442 // which for structs was "public". Below we correct this
1443 // by setting any fields to "private" that weren't correctly
1444 // set.
1445 if (is_a_class && !member_accessibilities.empty())
1446 {
1447 // This is a class and all members that didn't have
1448 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001449 ast.SetDefaultAccessForRecordFields (clang_type,
1450 eAccessPrivate,
1451 &member_accessibilities.front(),
1452 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001453 }
1454
1455 if (!base_classes.empty())
1456 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001457 ast.SetBaseClassesForClassType (clang_type,
1458 &base_classes.front(),
1459 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001460
1461 // Clang will copy each CXXBaseSpecifier in "base_classes"
1462 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001463 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1464 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001465 }
1466
1467 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001468 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001469 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001470
1471 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001472 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001473 if (die->HasChildren())
1474 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001475 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1476 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001477 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001478 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001479 return clang_type;
1480
1481 default:
1482 assert(false && "not a forward clang type decl!");
1483 break;
1484 }
1485 return NULL;
1486}
1487
Greg Claytonc685f8e2010-09-15 04:15:46 +00001488Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001489SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001490{
1491 if (type_die != NULL)
1492 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001493 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001494 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001495 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001496 if (assert_not_being_parsed)
1497 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001498 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001499 }
1500 return NULL;
1501}
1502
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001504SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505{
1506 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001507 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 {
1509 // The symbol vendor doesn't know about this compile unit, we
1510 // need to parse and add it to the symbol vendor object.
1511 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001512 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001513 if (dc_cu.get())
1514 {
1515 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001516 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001517 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001518
1519 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001520
1521 if (m_debug_map_symfile)
1522 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 }
1524 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001525 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526}
1527
1528bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001529SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001530{
1531 sc.Clear();
1532 // Check if the symbol vendor already knows about this compile unit?
1533 sc.module_sp = m_obj_file->GetModule()->GetSP();
Greg Clayton96d7d742010-11-10 23:42:09 +00001534 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001535
1536 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1537 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001538 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001539
1540 return sc.function != NULL;
1541}
1542
1543uint32_t
1544SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1545{
1546 Timer scoped_timer(__PRETTY_FUNCTION__,
1547 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1548 so_addr.GetSection(),
1549 so_addr.GetOffset(),
1550 resolve_scope);
1551 uint32_t resolved = 0;
1552 if (resolve_scope & ( eSymbolContextCompUnit |
1553 eSymbolContextFunction |
1554 eSymbolContextBlock |
1555 eSymbolContextLineEntry))
1556 {
1557 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1558
1559 DWARFDebugAranges* debug_aranges = DebugAranges();
1560 DWARFDebugInfo* debug_info = DebugInfo();
1561 if (debug_aranges)
1562 {
1563 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1564 if (cu_offset != DW_INVALID_OFFSET)
1565 {
1566 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001567 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1568 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001570 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571 assert(sc.comp_unit != NULL);
1572 resolved |= eSymbolContextCompUnit;
1573
1574 if (resolve_scope & eSymbolContextLineEntry)
1575 {
1576 LineTable *line_table = sc.comp_unit->GetLineTable();
1577 if (line_table == NULL)
1578 {
1579 if (ParseCompileUnitLineTable(sc))
1580 line_table = sc.comp_unit->GetLineTable();
1581 }
1582 if (line_table != NULL)
1583 {
1584 if (so_addr.IsLinkedAddress())
1585 {
1586 Address linked_addr (so_addr);
1587 linked_addr.ResolveLinkedAddress();
1588 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1589 {
1590 resolved |= eSymbolContextLineEntry;
1591 }
1592 }
1593 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1594 {
1595 resolved |= eSymbolContextLineEntry;
1596 }
1597 }
1598 }
1599
1600 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1601 {
1602 DWARFDebugInfoEntry *function_die = NULL;
1603 DWARFDebugInfoEntry *block_die = NULL;
1604 if (resolve_scope & eSymbolContextBlock)
1605 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001606 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001607 }
1608 else
1609 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001610 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611 }
1612
1613 if (function_die != NULL)
1614 {
1615 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1616 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001617 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618 }
1619
1620 if (sc.function != NULL)
1621 {
1622 resolved |= eSymbolContextFunction;
1623
1624 if (resolve_scope & eSymbolContextBlock)
1625 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001626 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001627
1628 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001629 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001630 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001631 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001632 if (sc.block)
1633 resolved |= eSymbolContextBlock;
1634 }
1635 }
1636 }
1637 }
1638 }
1639 }
1640 }
1641 return resolved;
1642}
1643
1644
1645
1646uint32_t
1647SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1648{
1649 const uint32_t prev_size = sc_list.GetSize();
1650 if (resolve_scope & eSymbolContextCompUnit)
1651 {
1652 DWARFDebugInfo* debug_info = DebugInfo();
1653 if (debug_info)
1654 {
1655 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001656 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657
Greg Clayton96d7d742010-11-10 23:42:09 +00001658 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001660 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001661 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1662 if (check_inlines || file_spec_matches_cu_file_spec)
1663 {
1664 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001665 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666 assert(sc.comp_unit != NULL);
1667
1668 uint32_t file_idx = UINT32_MAX;
1669
1670 // If we are looking for inline functions only and we don't
1671 // find it in the support files, we are done.
1672 if (check_inlines)
1673 {
1674 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1675 if (file_idx == UINT32_MAX)
1676 continue;
1677 }
1678
1679 if (line != 0)
1680 {
1681 LineTable *line_table = sc.comp_unit->GetLineTable();
1682
1683 if (line_table != NULL && line != 0)
1684 {
1685 // We will have already looked up the file index if
1686 // we are searching for inline entries.
1687 if (!check_inlines)
1688 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1689
1690 if (file_idx != UINT32_MAX)
1691 {
1692 uint32_t found_line;
1693 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1694 found_line = sc.line_entry.line;
1695
Greg Clayton016a95e2010-09-14 02:20:48 +00001696 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001697 {
1698 sc.function = NULL;
1699 sc.block = NULL;
1700 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1701 {
1702 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1703 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1704 {
1705 DWARFDebugInfoEntry *function_die = NULL;
1706 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001707 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708
1709 if (function_die != NULL)
1710 {
1711 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1712 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001713 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001714 }
1715
1716 if (sc.function != NULL)
1717 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001718 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719
1720 if (block_die != NULL)
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001721 sc.block = block.FindBlockByID (block_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001723 sc.block = block.FindBlockByID (function_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 }
1725 }
1726 }
1727
1728 sc_list.Append(sc);
1729 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1730 }
1731 }
1732 }
1733 else if (file_spec_matches_cu_file_spec && !check_inlines)
1734 {
1735 // only append the context if we aren't looking for inline call sites
1736 // by file and line and if the file spec matches that of the compile unit
1737 sc_list.Append(sc);
1738 }
1739 }
1740 else if (file_spec_matches_cu_file_spec && !check_inlines)
1741 {
1742 // only append the context if we aren't looking for inline call sites
1743 // by file and line and if the file spec matches that of the compile unit
1744 sc_list.Append(sc);
1745 }
1746
1747 if (!check_inlines)
1748 break;
1749 }
1750 }
1751 }
1752 }
1753 return sc_list.GetSize() - prev_size;
1754}
1755
1756void
1757SymbolFileDWARF::Index ()
1758{
1759 if (m_indexed)
1760 return;
1761 m_indexed = true;
1762 Timer scoped_timer (__PRETTY_FUNCTION__,
1763 "SymbolFileDWARF::Index (%s)",
1764 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1765
1766 DWARFDebugInfo* debug_info = DebugInfo();
1767 if (debug_info)
1768 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001769 m_aranges.reset(new DWARFDebugAranges());
1770
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771 uint32_t cu_idx = 0;
1772 const uint32_t num_compile_units = GetNumCompileUnits();
1773 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1774 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001775 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776
Greg Clayton96d7d742010-11-10 23:42:09 +00001777 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001778
Greg Clayton96d7d742010-11-10 23:42:09 +00001779 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00001780 m_function_basename_index,
1781 m_function_fullname_index,
1782 m_function_method_index,
1783 m_function_selector_index,
1784 m_objc_class_selectors_index,
1785 m_global_index,
1786 m_type_index,
1787 m_namespace_index,
1788 DebugRanges(),
1789 m_aranges.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790
1791 // Keep memory down by clearing DIEs if this generate function
1792 // caused them to be parsed
1793 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00001794 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 }
1796
Greg Clayton016a95e2010-09-14 02:20:48 +00001797 m_aranges->Sort();
Greg Claytonc685f8e2010-09-15 04:15:46 +00001798
Greg Clayton24739922010-10-13 03:15:28 +00001799#if defined (ENABLE_DEBUG_PRINTF)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001800 StreamFile s(stdout);
Greg Clayton24739922010-10-13 03:15:28 +00001801 s.Printf ("DWARF index for (%s) '%s/%s':",
1802 GetObjectFile()->GetModule()->GetArchitecture().AsCString(),
1803 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1804 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00001805 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
1806 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
1807 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
1808 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
1809 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
1810 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00001811 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00001812 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001813#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814 }
1815}
1816
1817uint32_t
1818SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1819{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001820 DWARFDebugInfo* info = DebugInfo();
1821 if (info == NULL)
1822 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001823
1824 // If we aren't appending the results to this list, then clear the list
1825 if (!append)
1826 variables.Clear();
1827
1828 // Remember how many variables are in the list before we search in case
1829 // we are appending the results to a variable list.
1830 const uint32_t original_size = variables.GetSize();
1831
1832 // Index the DWARF if we haven't already
1833 if (!m_indexed)
1834 Index ();
1835
Greg Claytonc685f8e2010-09-15 04:15:46 +00001836 SymbolContext sc;
1837 sc.module_sp = m_obj_file->GetModule()->GetSP();
1838 assert (sc.module_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001839
Greg Clayton96d7d742010-11-10 23:42:09 +00001840 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001841 DWARFCompileUnit* prev_cu = NULL;
1842 const DWARFDebugInfoEntry* die = NULL;
1843 std::vector<NameToDIE::Info> die_info_array;
1844 const size_t num_matches = m_global_index.Find(name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001845 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001847 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001848
Greg Clayton96d7d742010-11-10 23:42:09 +00001849 if (curr_cu != prev_cu)
1850 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851
Greg Clayton96d7d742010-11-10 23:42:09 +00001852 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853
Greg Clayton96d7d742010-11-10 23:42:09 +00001854 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001855 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001856
Greg Clayton96d7d742010-11-10 23:42:09 +00001857 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001858
1859 if (variables.GetSize() - original_size >= max_matches)
1860 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 }
1862
1863 // Return the number of variable that were appended to the list
1864 return variables.GetSize() - original_size;
1865}
1866
1867uint32_t
1868SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
1869{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001870 DWARFDebugInfo* info = DebugInfo();
1871 if (info == NULL)
1872 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873
1874 // If we aren't appending the results to this list, then clear the list
1875 if (!append)
1876 variables.Clear();
1877
1878 // Remember how many variables are in the list before we search in case
1879 // we are appending the results to a variable list.
1880 const uint32_t original_size = variables.GetSize();
1881
1882 // Index the DWARF if we haven't already
1883 if (!m_indexed)
1884 Index ();
1885
Greg Claytonc685f8e2010-09-15 04:15:46 +00001886 SymbolContext sc;
1887 sc.module_sp = m_obj_file->GetModule()->GetSP();
1888 assert (sc.module_sp);
1889
Greg Clayton96d7d742010-11-10 23:42:09 +00001890 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001891 DWARFCompileUnit* prev_cu = NULL;
1892 const DWARFDebugInfoEntry* die = NULL;
1893 std::vector<NameToDIE::Info> die_info_array;
1894 const size_t num_matches = m_global_index.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001895 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001896 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001897 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001898
Greg Clayton96d7d742010-11-10 23:42:09 +00001899 if (curr_cu != prev_cu)
1900 curr_cu->ExtractDIEsIfNeeded (false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901
Greg Clayton96d7d742010-11-10 23:42:09 +00001902 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001903
Greg Clayton96d7d742010-11-10 23:42:09 +00001904 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001905 assert(sc.comp_unit != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906
Greg Clayton96d7d742010-11-10 23:42:09 +00001907 ParseVariables(sc, curr_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001908
Greg Claytonc685f8e2010-09-15 04:15:46 +00001909 if (variables.GetSize() - original_size >= max_matches)
1910 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001911 }
1912
1913 // Return the number of variable that were appended to the list
1914 return variables.GetSize() - original_size;
1915}
1916
1917
Greg Clayton0c5cd902010-06-28 21:30:43 +00001918void
1919SymbolFileDWARF::FindFunctions
1920(
1921 const ConstString &name,
Greg Claytonc685f8e2010-09-15 04:15:46 +00001922 const NameToDIE &name_to_die,
Greg Clayton0c5cd902010-06-28 21:30:43 +00001923 SymbolContextList& sc_list
1924)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925{
Greg Claytonc685f8e2010-09-15 04:15:46 +00001926 DWARFDebugInfo* info = DebugInfo();
1927 if (info == NULL)
1928 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929
Greg Claytonc685f8e2010-09-15 04:15:46 +00001930 SymbolContext sc;
1931 sc.module_sp = m_obj_file->GetModule()->GetSP();
1932 assert (sc.module_sp);
1933
Greg Clayton96d7d742010-11-10 23:42:09 +00001934 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001935 DWARFCompileUnit* prev_cu = NULL;
1936 const DWARFDebugInfoEntry* die = NULL;
1937 std::vector<NameToDIE::Info> die_info_array;
Greg Claytond7e05462010-11-14 00:22:48 +00001938 const size_t num_matches = name_to_die.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00001939 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001940 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001941 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001942
Greg Clayton96d7d742010-11-10 23:42:09 +00001943 if (curr_cu != prev_cu)
1944 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001945
Greg Clayton96d7d742010-11-10 23:42:09 +00001946 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytond7e05462010-11-14 00:22:48 +00001947
1948 const DWARFDebugInfoEntry* inlined_die = NULL;
1949 if (die->Tag() == DW_TAG_inlined_subroutine)
1950 {
1951 inlined_die = die;
1952
1953 while ((die = die->GetParent()) != NULL)
1954 {
1955 if (die->Tag() == DW_TAG_subprogram)
1956 break;
1957 }
1958 }
1959 assert (die->Tag() == DW_TAG_subprogram);
Greg Clayton96d7d742010-11-10 23:42:09 +00001960 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00001961 {
Greg Claytond7e05462010-11-14 00:22:48 +00001962 Address addr;
1963 // Parse all blocks if needed
1964 if (inlined_die)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001965 {
Greg Claytond7e05462010-11-14 00:22:48 +00001966 sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset());
1967 assert (sc.block != NULL);
1968 if (sc.block->GetStartAddress (addr) == false)
1969 addr.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970 }
Greg Claytond7e05462010-11-14 00:22:48 +00001971 else
1972 {
1973 sc.block = NULL;
1974 addr = sc.function->GetAddressRange().GetBaseAddress();
1975 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00001976
Greg Claytond7e05462010-11-14 00:22:48 +00001977 if (addr.IsValid())
1978 {
1979
1980 // We found the function, so we should find the line table
1981 // and line table entry as well
1982 LineTable *line_table = sc.comp_unit->GetLineTable();
1983 if (line_table == NULL)
1984 {
1985 if (ParseCompileUnitLineTable(sc))
1986 line_table = sc.comp_unit->GetLineTable();
1987 }
1988 if (line_table != NULL)
1989 line_table->FindLineEntryByAddress (addr, sc.line_entry);
1990
1991 sc_list.Append(sc);
1992 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993 }
1994 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00001995}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996
Greg Claytonc685f8e2010-09-15 04:15:46 +00001997
1998void
1999SymbolFileDWARF::FindFunctions
2000(
2001 const RegularExpression &regex,
2002 const NameToDIE &name_to_die,
2003 SymbolContextList& sc_list
2004)
2005{
2006 DWARFDebugInfo* info = DebugInfo();
2007 if (info == NULL)
2008 return;
2009
2010 SymbolContext sc;
2011 sc.module_sp = m_obj_file->GetModule()->GetSP();
2012 assert (sc.module_sp);
2013
Greg Clayton96d7d742010-11-10 23:42:09 +00002014 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002015 DWARFCompileUnit* prev_cu = NULL;
2016 const DWARFDebugInfoEntry* die = NULL;
2017 std::vector<NameToDIE::Info> die_info_array;
2018 const size_t num_matches = name_to_die.Find(regex, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002019 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002020 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002021 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002022
Greg Clayton96d7d742010-11-10 23:42:09 +00002023 if (curr_cu != prev_cu)
2024 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002025
Greg Clayton96d7d742010-11-10 23:42:09 +00002026 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2027 if (GetFunction (curr_cu, die, sc))
Greg Claytonc685f8e2010-09-15 04:15:46 +00002028 {
2029 // We found the function, so we should find the line table
2030 // and line table entry as well
2031 LineTable *line_table = sc.comp_unit->GetLineTable();
2032 if (line_table == NULL)
2033 {
2034 if (ParseCompileUnitLineTable(sc))
2035 line_table = sc.comp_unit->GetLineTable();
2036 }
2037 if (line_table != NULL)
2038 line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry);
2039
2040 sc_list.Append(sc);
2041 }
2042 }
Greg Clayton0c5cd902010-06-28 21:30:43 +00002043}
2044
2045uint32_t
2046SymbolFileDWARF::FindFunctions
2047(
2048 const ConstString &name,
2049 uint32_t name_type_mask,
2050 bool append,
2051 SymbolContextList& sc_list
2052)
2053{
2054 Timer scoped_timer (__PRETTY_FUNCTION__,
2055 "SymbolFileDWARF::FindFunctions (name = '%s')",
2056 name.AsCString());
2057
Greg Clayton0c5cd902010-06-28 21:30:43 +00002058 // If we aren't appending the results to this list, then clear the list
2059 if (!append)
2060 sc_list.Clear();
2061
2062 // Remember how many sc_list are in the list before we search in case
2063 // we are appending the results to a variable list.
2064 uint32_t original_size = sc_list.GetSize();
2065
2066 // Index the DWARF if we haven't already
2067 if (!m_indexed)
2068 Index ();
2069
2070 if (name_type_mask & eFunctionNameTypeBase)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002071 FindFunctions (name, m_function_basename_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002072
2073 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002074 FindFunctions (name, m_function_fullname_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002075
2076 if (name_type_mask & eFunctionNameTypeMethod)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002077 FindFunctions (name, m_function_method_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002078
2079 if (name_type_mask & eFunctionNameTypeSelector)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002080 FindFunctions (name, m_function_selector_index, sc_list);
Greg Clayton0c5cd902010-06-28 21:30:43 +00002081
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002082 // Return the number of variable that were appended to the list
2083 return sc_list.GetSize() - original_size;
2084}
2085
2086
2087uint32_t
2088SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2089{
2090 Timer scoped_timer (__PRETTY_FUNCTION__,
2091 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2092 regex.GetText());
2093
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002094 // If we aren't appending the results to this list, then clear the list
2095 if (!append)
2096 sc_list.Clear();
2097
2098 // Remember how many sc_list are in the list before we search in case
2099 // we are appending the results to a variable list.
2100 uint32_t original_size = sc_list.GetSize();
2101
2102 // Index the DWARF if we haven't already
2103 if (!m_indexed)
2104 Index ();
2105
Greg Claytonc685f8e2010-09-15 04:15:46 +00002106 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002107
Greg Claytonc685f8e2010-09-15 04:15:46 +00002108 FindFunctions (regex, m_function_fullname_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002109
2110 // Return the number of variable that were appended to the list
2111 return sc_list.GetSize() - original_size;
2112}
2113
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002114uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002115SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002117 DWARFDebugInfo* info = DebugInfo();
2118 if (info == NULL)
2119 return 0;
2120
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002121 // If we aren't appending the results to this list, then clear the list
2122 if (!append)
2123 types.Clear();
2124
Greg Clayton6dbd3982010-09-15 05:51:24 +00002125 // Index if we already haven't to make sure the compile units
2126 // get indexed and make their global DIE index list
2127 if (!m_indexed)
2128 Index ();
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002129
Greg Claytonc685f8e2010-09-15 04:15:46 +00002130 const uint32_t initial_types_size = types.GetSize();
Greg Clayton96d7d742010-11-10 23:42:09 +00002131 DWARFCompileUnit* curr_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002132 DWARFCompileUnit* prev_cu = NULL;
2133 const DWARFDebugInfoEntry* die = NULL;
2134 std::vector<NameToDIE::Info> die_info_array;
Greg Clayton69b04882010-10-15 02:03:22 +00002135 const size_t num_matches = m_type_index.Find (name, die_info_array);
Greg Clayton96d7d742010-11-10 23:42:09 +00002136 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002137 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002138 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002139
Greg Clayton96d7d742010-11-10 23:42:09 +00002140 if (curr_cu != prev_cu)
2141 curr_cu->ExtractDIEsIfNeeded (false);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002142
Greg Clayton96d7d742010-11-10 23:42:09 +00002143 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002144
Greg Clayton96d7d742010-11-10 23:42:09 +00002145 Type *matching_type = ResolveType (curr_cu, die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002146 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002147 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00002148 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002149 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonc685f8e2010-09-15 04:15:46 +00002150 assert (type_sp.get() != NULL);
2151 types.InsertUnique (type_sp);
2152 if (types.GetSize() >= max_matches)
2153 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002154 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002155 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002156 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002157}
2158
2159
Greg Clayton526e5af2010-11-13 03:52:47 +00002160ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002161SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
2162 const ConstString &name)
2163{
Greg Clayton526e5af2010-11-13 03:52:47 +00002164 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002165 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002166 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002167 {
Greg Clayton526e5af2010-11-13 03:52:47 +00002168 // Index if we already haven't to make sure the compile units
2169 // get indexed and make their global DIE index list
2170 if (!m_indexed)
2171 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002172
Greg Clayton526e5af2010-11-13 03:52:47 +00002173 DWARFCompileUnit* curr_cu = NULL;
2174 DWARFCompileUnit* prev_cu = NULL;
2175 const DWARFDebugInfoEntry* die = NULL;
2176 std::vector<NameToDIE::Info> die_info_array;
2177 const size_t num_matches = m_namespace_index.Find (name, die_info_array);
2178 for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
2179 {
2180 curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
2181
2182 if (curr_cu != prev_cu)
2183 curr_cu->ExtractDIEsIfNeeded (false);
Greg Clayton96d7d742010-11-10 23:42:09 +00002184
Greg Clayton526e5af2010-11-13 03:52:47 +00002185 die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2186
2187 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die);
2188 if (clang_namespace_decl)
2189 {
2190 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
2191 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
2192 }
2193 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002194 }
Greg Clayton526e5af2010-11-13 03:52:47 +00002195 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002196}
2197
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002198uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002199SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002200{
2201 // Remember how many sc_list are in the list before we search in case
2202 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002203 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002204
2205 const uint32_t num_die_offsets = die_offsets.size();
2206 // Parse all of the types we found from the pubtypes matches
2207 uint32_t i;
2208 uint32_t num_matches = 0;
2209 for (i = 0; i < num_die_offsets; ++i)
2210 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002211 Type *matching_type = ResolveTypeUID (die_offsets[i]);
2212 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002213 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002214 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002215 TypeSP type_sp (GetTypeList()->FindType(matching_type->GetID()));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002216 assert (type_sp.get() != NULL);
2217 types.InsertUnique (type_sp);
2218 ++num_matches;
2219 if (num_matches >= max_matches)
2220 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002221 }
2222 }
2223
2224 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002225 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002226}
2227
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002228
2229size_t
2230SymbolFileDWARF::ParseChildParameters
2231(
2232 const SymbolContext& sc,
2233 TypeSP& type_sp,
Greg Clayton0fffff52010-09-24 05:15:53 +00002234 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002235 const DWARFDebugInfoEntry *parent_die,
Greg Claytona51ed9b2010-09-23 01:09:21 +00002236 bool skip_artificial,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002237 TypeList* type_list,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002238 std::vector<clang_type_t>& function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00002239 std::vector<clang::ParmVarDecl*>& function_param_decls,
2240 unsigned &type_quals
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241)
2242{
2243 if (parent_die == NULL)
2244 return 0;
2245
Greg Claytond88d7592010-09-15 08:33:30 +00002246 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2247
Greg Clayton7fedea22010-11-16 02:10:54 +00002248 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002249 const DWARFDebugInfoEntry *die;
2250 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2251 {
2252 dw_tag_t tag = die->Tag();
2253 switch (tag)
2254 {
2255 case DW_TAG_formal_parameter:
2256 {
2257 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002258 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002259 if (num_attributes > 0)
2260 {
2261 const char *name = NULL;
2262 Declaration decl;
2263 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002264 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002265 // one of None, Auto, Register, Extern, Static, PrivateExtern
2266
Sean Callanane2ef6e32010-09-23 03:01:22 +00002267 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002268 uint32_t i;
2269 for (i=0; i<num_attributes; ++i)
2270 {
2271 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2272 DWARFFormValue form_value;
2273 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2274 {
2275 switch (attr)
2276 {
2277 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2278 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2279 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2280 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
2281 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00002282 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002283 case DW_AT_location:
2284 // if (form_value.BlockData())
2285 // {
2286 // const DataExtractor& debug_info_data = debug_info();
2287 // uint32_t block_length = form_value.Unsigned();
2288 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2289 // }
2290 // else
2291 // {
2292 // }
2293 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002294 case DW_AT_const_value:
2295 case DW_AT_default_value:
2296 case DW_AT_description:
2297 case DW_AT_endianity:
2298 case DW_AT_is_optional:
2299 case DW_AT_segment:
2300 case DW_AT_variable_parameter:
2301 default:
2302 case DW_AT_abstract_origin:
2303 case DW_AT_sibling:
2304 break;
2305 }
2306 }
2307 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00002308
Greg Clayton0fffff52010-09-24 05:15:53 +00002309 bool skip = false;
2310 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002311 {
Greg Clayton0fffff52010-09-24 05:15:53 +00002312 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00002313 {
2314 // In order to determine if a C++ member function is
2315 // "const" we have to look at the const-ness of "this"...
2316 // Ugly, but that
2317 if (arg_idx == 0)
2318 {
2319 const DWARFDebugInfoEntry *grandparent_die = parent_die->GetParent();
2320 if (grandparent_die && (grandparent_die->Tag() == DW_TAG_structure_type ||
2321 grandparent_die->Tag() == DW_TAG_class_type))
2322 {
2323 LanguageType language = sc.comp_unit->GetLanguage();
2324 if (language == eLanguageTypeObjC_plus_plus || language == eLanguageTypeC_plus_plus)
2325 {
2326 // Often times compilers omit the "this" name for the
2327 // specification DIEs, so we can't rely upon the name
2328 // being in the formal parameter DIE...
2329 if (name == NULL || ::strcmp(name, "this")==0)
2330 {
2331 Type *this_type = ResolveTypeUID (param_type_die_offset);
2332 if (this_type)
2333 {
2334 uint32_t encoding_mask = this_type->GetEncodingMask();
2335 if (encoding_mask & Type::eEncodingIsPointerUID)
2336 {
2337 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
Greg Clayton47fbf1a2010-11-16 22:09:25 +00002338 type_quals |= clang::Qualifiers::Const;
Greg Clayton7fedea22010-11-16 02:10:54 +00002339 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
Greg Clayton47fbf1a2010-11-16 22:09:25 +00002340 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00002341 }
2342 }
2343 }
2344 }
2345 }
2346 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002347 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00002348 }
Greg Clayton0fffff52010-09-24 05:15:53 +00002349 else
2350 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351
Greg Clayton0fffff52010-09-24 05:15:53 +00002352 // HACK: Objective C formal parameters "self" and "_cmd"
2353 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00002354 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2355 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00002356 {
2357 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2358 skip = true;
2359 }
2360 }
2361 }
2362
2363 if (!skip)
2364 {
2365 Type *type = ResolveTypeUID(param_type_die_offset);
2366 if (type)
2367 {
Greg Claytonc93237c2010-10-01 20:48:32 +00002368 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00002369
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002370 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00002371 assert(param_var_decl);
2372 function_param_decls.push_back(param_var_decl);
2373 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002374 }
2375 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002376 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002377 }
2378 break;
2379
2380 default:
2381 break;
2382 }
2383 }
Greg Clayton7fedea22010-11-16 02:10:54 +00002384 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002385}
2386
2387size_t
2388SymbolFileDWARF::ParseChildEnumerators
2389(
2390 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00002391 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002392 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00002393 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002394 const DWARFDebugInfoEntry *parent_die
2395)
2396{
2397 if (parent_die == NULL)
2398 return 0;
2399
2400 size_t enumerators_added = 0;
2401 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002402 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2403
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002404 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2405 {
2406 const dw_tag_t tag = die->Tag();
2407 if (tag == DW_TAG_enumerator)
2408 {
2409 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002410 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002411 if (num_child_attributes > 0)
2412 {
2413 const char *name = NULL;
2414 bool got_value = false;
2415 int64_t enum_value = 0;
2416 Declaration decl;
2417
2418 uint32_t i;
2419 for (i=0; i<num_child_attributes; ++i)
2420 {
2421 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2422 DWARFFormValue form_value;
2423 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2424 {
2425 switch (attr)
2426 {
2427 case DW_AT_const_value:
2428 got_value = true;
2429 enum_value = form_value.Unsigned();
2430 break;
2431
2432 case DW_AT_name:
2433 name = form_value.AsCString(&get_debug_str_data());
2434 break;
2435
2436 case DW_AT_description:
2437 default:
2438 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2439 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2440 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2441 case DW_AT_sibling:
2442 break;
2443 }
2444 }
2445 }
2446
2447 if (name && name[0] && got_value)
2448 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002449 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2450 enumerator_clang_type,
2451 decl,
2452 name,
2453 enum_value,
2454 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002455 ++enumerators_added;
2456 }
2457 }
2458 }
2459 }
2460 return enumerators_added;
2461}
2462
2463void
2464SymbolFileDWARF::ParseChildArrayInfo
2465(
2466 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00002467 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002468 const DWARFDebugInfoEntry *parent_die,
2469 int64_t& first_index,
2470 std::vector<uint64_t>& element_orders,
2471 uint32_t& byte_stride,
2472 uint32_t& bit_stride
2473)
2474{
2475 if (parent_die == NULL)
2476 return;
2477
2478 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00002479 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002480 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2481 {
2482 const dw_tag_t tag = die->Tag();
2483 switch (tag)
2484 {
2485 case DW_TAG_enumerator:
2486 {
2487 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002488 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002489 if (num_child_attributes > 0)
2490 {
2491 const char *name = NULL;
2492 bool got_value = false;
2493 int64_t enum_value = 0;
2494
2495 uint32_t i;
2496 for (i=0; i<num_child_attributes; ++i)
2497 {
2498 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2499 DWARFFormValue form_value;
2500 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2501 {
2502 switch (attr)
2503 {
2504 case DW_AT_const_value:
2505 got_value = true;
2506 enum_value = form_value.Unsigned();
2507 break;
2508
2509 case DW_AT_name:
2510 name = form_value.AsCString(&get_debug_str_data());
2511 break;
2512
2513 case DW_AT_description:
2514 default:
2515 case DW_AT_decl_file:
2516 case DW_AT_decl_line:
2517 case DW_AT_decl_column:
2518 case DW_AT_sibling:
2519 break;
2520 }
2521 }
2522 }
2523 }
2524 }
2525 break;
2526
2527 case DW_TAG_subrange_type:
2528 {
2529 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00002530 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002531 if (num_child_attributes > 0)
2532 {
2533 const char *name = NULL;
2534 bool got_value = false;
2535 uint64_t byte_size = 0;
2536 int64_t enum_value = 0;
2537 uint64_t num_elements = 0;
2538 uint64_t lower_bound = 0;
2539 uint64_t upper_bound = 0;
2540 uint32_t i;
2541 for (i=0; i<num_child_attributes; ++i)
2542 {
2543 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2544 DWARFFormValue form_value;
2545 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2546 {
2547 switch (attr)
2548 {
2549 case DW_AT_const_value:
2550 got_value = true;
2551 enum_value = form_value.Unsigned();
2552 break;
2553
2554 case DW_AT_name:
2555 name = form_value.AsCString(&get_debug_str_data());
2556 break;
2557
2558 case DW_AT_count:
2559 num_elements = form_value.Unsigned();
2560 break;
2561
2562 case DW_AT_bit_stride:
2563 bit_stride = form_value.Unsigned();
2564 break;
2565
2566 case DW_AT_byte_stride:
2567 byte_stride = form_value.Unsigned();
2568 break;
2569
2570 case DW_AT_byte_size:
2571 byte_size = form_value.Unsigned();
2572 break;
2573
2574 case DW_AT_lower_bound:
2575 lower_bound = form_value.Unsigned();
2576 break;
2577
2578 case DW_AT_upper_bound:
2579 upper_bound = form_value.Unsigned();
2580 break;
2581
2582 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002583 case DW_AT_abstract_origin:
2584 case DW_AT_accessibility:
2585 case DW_AT_allocated:
2586 case DW_AT_associated:
2587 case DW_AT_data_location:
2588 case DW_AT_declaration:
2589 case DW_AT_description:
2590 case DW_AT_sibling:
2591 case DW_AT_threads_scaled:
2592 case DW_AT_type:
2593 case DW_AT_visibility:
2594 break;
2595 }
2596 }
2597 }
2598
2599 if (upper_bound > lower_bound)
2600 num_elements = upper_bound - lower_bound + 1;
2601
2602 if (num_elements > 0)
2603 element_orders.push_back (num_elements);
2604 }
2605 }
2606 break;
2607 }
2608 }
2609}
2610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002611TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00002612SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002613{
2614 TypeSP type_sp;
2615 if (die != NULL)
2616 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002617 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00002618 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002619 if (type_ptr == NULL)
2620 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002621 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
2622 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002623 }
2624 else if (type_ptr != DIE_IS_BEING_PARSED)
2625 {
2626 // Grab the existing type from the master types lists
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002627 type_sp = GetTypeList()->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002628 }
2629
2630 }
2631 return type_sp;
2632}
2633
2634clang::DeclContext *
2635SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset)
2636{
2637 if (die_offset != DW_INVALID_OFFSET)
2638 {
2639 DWARFCompileUnitSP cu_sp;
2640 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2641 return GetClangDeclContextForDIE (cu_sp.get(), die);
2642 }
2643 return NULL;
2644}
2645
2646
Greg Clayton96d7d742010-11-10 23:42:09 +00002647clang::NamespaceDecl *
2648SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
2649{
2650 if (die->Tag() == DW_TAG_namespace)
2651 {
2652 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
2653 if (namespace_name)
2654 {
2655 Declaration decl; // TODO: fill in the decl object
2656 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent()));
2657 if (namespace_decl)
2658 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2659 return namespace_decl;
2660 }
2661 }
2662 return NULL;
2663}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002664
2665clang::DeclContext *
Greg Clayton96d7d742010-11-10 23:42:09 +00002666SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002667{
2668 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2669 if (pos != m_die_to_decl_ctx.end())
2670 return pos->second;
2671
2672 while (die != NULL)
2673 {
2674 switch (die->Tag())
2675 {
2676 case DW_TAG_namespace:
2677 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002678 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002679 if (namespace_name)
2680 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002681 Declaration decl; // TODO: fill in the decl object
Greg Clayton96d7d742010-11-10 23:42:09 +00002682 clang::NamespaceDecl *namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (curr_cu, die->GetParent()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002683 if (namespace_decl)
2684 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2685 return namespace_decl;
2686 }
2687 }
2688 break;
2689
2690 default:
2691 break;
2692 }
2693 clang::DeclContext *decl_ctx;
Greg Clayton96d7d742010-11-10 23:42:09 +00002694 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002695 if (decl_ctx)
2696 return decl_ctx;
2697
Greg Clayton96d7d742010-11-10 23:42:09 +00002698 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002699 if (decl_ctx)
2700 return decl_ctx;
2701
2702 die = die->GetParent();
2703 }
Greg Clayton7a345282010-11-09 23:46:37 +00002704 // Right now we have only one translation unit per module...
2705 if (m_clang_tu_decl == NULL)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002706 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Greg Clayton7a345282010-11-09 23:46:37 +00002707 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002708}
2709
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002710// This function can be used when a DIE is found that is a forward declaration
2711// DIE and we want to try and find a type that has the complete definition.
2712TypeSP
2713SymbolFileDWARF::FindDefinitionTypeForDIE (
Greg Clayton96d7d742010-11-10 23:42:09 +00002714 DWARFCompileUnit* curr_cu,
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002715 const DWARFDebugInfoEntry *die,
2716 const ConstString &type_name
2717)
2718{
2719 TypeSP type_sp;
2720
Greg Clayton96d7d742010-11-10 23:42:09 +00002721 if (curr_cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002722 return type_sp;
2723
2724 const dw_tag_t type_tag = die->Tag();
2725 std::vector<NameToDIE::Info> die_info_array;
2726 const size_t num_matches = m_type_index.Find (type_name, die_info_array);
2727 if (num_matches > 0)
2728 {
2729 DWARFCompileUnit* type_cu = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00002730 DWARFCompileUnit* curr_cu = curr_cu;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002731 DWARFDebugInfo *info = DebugInfo();
2732 for (size_t i=0; i<num_matches; ++i)
2733 {
2734 type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx);
2735
2736 if (type_cu != curr_cu)
2737 {
2738 type_cu->ExtractDIEsIfNeeded (false);
2739 curr_cu = type_cu;
2740 }
2741
2742 DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx);
2743
2744 if (type_die != die && type_die->Tag() == type_tag)
2745 {
2746 // Hold off on comparing parent DIE tags until
2747 // we know what happens with stuff in namespaces
2748 // for gcc and clang...
2749 //DWARFDebugInfoEntry *parent_die = die->GetParent();
2750 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
2751 //if (parent_die->Tag() == parent_type_die->Tag())
2752 {
2753 Type *resolved_type = ResolveType (type_cu, type_die, false);
2754 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
2755 {
2756 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
2757 die->GetOffset(),
Greg Clayton96d7d742010-11-10 23:42:09 +00002758 curr_cu->GetOffset(),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002759 m_obj_file->GetFileSpec().GetFilename().AsCString(),
2760 type_die->GetOffset(),
2761 type_cu->GetOffset());
2762
2763 m_die_to_type[die] = resolved_type;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002764 type_sp = GetTypeList()->FindType(resolved_type->GetID());
Greg Clayton40328bf2010-11-08 02:05:08 +00002765 if (!type_sp)
2766 {
2767 DEBUG_PRINTF("unable to resolve type '%s' from DIE 0x%8.8x\n", type_name.GetCString(), die->GetOffset());
2768 }
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00002769 break;
2770 }
2771 }
2772 }
2773 }
2774 }
2775 return type_sp;
2776}
2777
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002778TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00002779SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002780{
2781 TypeSP type_sp;
2782
Greg Clayton1be10fc2010-09-29 01:12:09 +00002783 if (type_is_new_ptr)
2784 *type_is_new_ptr = false;
2785
Sean Callananc7fbf732010-08-06 00:32:49 +00002786 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002787 if (die != NULL)
2788 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00002789 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002790 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00002791 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002792 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002793 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00002794 if (type_is_new_ptr)
2795 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002796
Greg Clayton594e5ed2010-09-27 21:07:38 +00002797 const dw_tag_t tag = die->Tag();
2798
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002799 bool is_forward_declaration = false;
2800 DWARFDebugInfoEntry::Attributes attributes;
2801 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00002802 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00002803 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
2804 size_t byte_size = 0;
2805 Declaration decl;
2806
Greg Clayton4957bf62010-09-30 21:49:03 +00002807 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00002808 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002809
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002810 dw_attr_t attr;
2811
2812 switch (tag)
2813 {
2814 case DW_TAG_base_type:
2815 case DW_TAG_pointer_type:
2816 case DW_TAG_reference_type:
2817 case DW_TAG_typedef:
2818 case DW_TAG_const_type:
2819 case DW_TAG_restrict_type:
2820 case DW_TAG_volatile_type:
2821 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002822 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00002823 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002824
Greg Claytond88d7592010-09-15 08:33:30 +00002825 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002826 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002827 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
2828
2829 if (num_attributes > 0)
2830 {
2831 uint32_t i;
2832 for (i=0; i<num_attributes; ++i)
2833 {
2834 attr = attributes.AttributeAtIndex(i);
2835 DWARFFormValue form_value;
2836 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2837 {
2838 switch (attr)
2839 {
2840 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2841 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2842 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2843 case DW_AT_name:
2844 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00002845 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002846 break;
2847 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
2848 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
2849 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
2850 default:
2851 case DW_AT_sibling:
2852 break;
2853 }
2854 }
2855 }
2856 }
2857
Greg Claytonc93237c2010-10-01 20:48:32 +00002858 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);
2859
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002860 switch (tag)
2861 {
2862 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00002863 break;
2864
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002865 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00002866 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002867 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
2868 encoding,
2869 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002870 break;
2871
Greg Clayton526e5af2010-11-13 03:52:47 +00002872 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
2873 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
2874 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
2875 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
2876 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
2877 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002878 }
2879
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002880 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
2881 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
2882 {
2883 static ConstString g_objc_type_name_id("id");
2884 static ConstString g_objc_type_name_Class("Class");
2885 static ConstString g_objc_type_name_selector("SEL");
2886
Greg Clayton24739922010-10-13 03:15:28 +00002887 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002888 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002889 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00002890 resolve_state = Type::eResolveStateFull;
2891
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002892 }
Greg Clayton24739922010-10-13 03:15:28 +00002893 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002894 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002895 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00002896 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002897 }
Greg Clayton24739922010-10-13 03:15:28 +00002898 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002899 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002900 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00002901 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00002902 }
2903 }
2904
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002905 type_sp.reset( new Type (die->GetOffset(),
2906 this,
2907 type_name_const_str,
2908 byte_size,
2909 NULL,
2910 encoding_uid,
2911 encoding_data_type,
2912 &decl,
2913 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00002914 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00002915
Greg Clayton594e5ed2010-09-27 21:07:38 +00002916 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917
2918// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
2919// if (encoding_type != NULL)
2920// {
2921// if (encoding_type != DIE_IS_BEING_PARSED)
2922// type_sp->SetEncodingType(encoding_type);
2923// else
2924// m_indirect_fixups.push_back(type_sp.get());
2925// }
2926 }
2927 break;
2928
2929 case DW_TAG_structure_type:
2930 case DW_TAG_union_type:
2931 case DW_TAG_class_type:
2932 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002933 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00002934 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002935
Greg Clayton9e409562010-07-28 02:04:09 +00002936 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002937 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00002938 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002939 if (num_attributes > 0)
2940 {
2941 uint32_t i;
2942 for (i=0; i<num_attributes; ++i)
2943 {
2944 attr = attributes.AttributeAtIndex(i);
2945 DWARFFormValue form_value;
2946 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2947 {
2948 switch (attr)
2949 {
Greg Clayton9e409562010-07-28 02:04:09 +00002950 case DW_AT_decl_file:
2951 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
2952 break;
2953
2954 case DW_AT_decl_line:
2955 decl.SetLine(form_value.Unsigned());
2956 break;
2957
2958 case DW_AT_decl_column:
2959 decl.SetColumn(form_value.Unsigned());
2960 break;
2961
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002962 case DW_AT_name:
2963 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00002964 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002965 break;
Greg Clayton9e409562010-07-28 02:04:09 +00002966
2967 case DW_AT_byte_size:
2968 byte_size = form_value.Unsigned();
2969 break;
2970
2971 case DW_AT_accessibility:
2972 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
2973 break;
2974
2975 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00002976 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00002977 break;
2978
2979 case DW_AT_APPLE_runtime_class:
2980 class_language = (LanguageType)form_value.Signed();
2981 break;
2982
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002983 case DW_AT_allocated:
2984 case DW_AT_associated:
2985 case DW_AT_data_location:
2986 case DW_AT_description:
2987 case DW_AT_start_scope:
2988 case DW_AT_visibility:
2989 default:
2990 case DW_AT_sibling:
2991 break;
2992 }
2993 }
2994 }
2995 }
2996
Greg Claytonc93237c2010-10-01 20:48:32 +00002997 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
2998
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002999 int tag_decl_kind = -1;
Sean Callananc7fbf732010-08-06 00:32:49 +00003000 AccessType default_accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003001 if (tag == DW_TAG_structure_type)
3002 {
3003 tag_decl_kind = clang::TTK_Struct;
Sean Callananc7fbf732010-08-06 00:32:49 +00003004 default_accessibility = eAccessPublic;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003005 }
3006 else if (tag == DW_TAG_union_type)
3007 {
3008 tag_decl_kind = clang::TTK_Union;
Sean Callananc7fbf732010-08-06 00:32:49 +00003009 default_accessibility = eAccessPublic;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003010 }
3011 else if (tag == DW_TAG_class_type)
3012 {
3013 tag_decl_kind = clang::TTK_Class;
Sean Callananc7fbf732010-08-06 00:32:49 +00003014 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003015 }
3016
Greg Clayton24739922010-10-13 03:15:28 +00003017
Greg Claytonc615ce42010-11-09 04:42:43 +00003018 if (is_forward_declaration)
3019 {
3020 // We have a forward declaration to a type and we need
3021 // to try and find a full declaration. We look in the
3022 // current type index just in case we have a forward
3023 // declaration followed by an actual declarations in the
3024 // DWARF. If this fails, we need to look elsewhere...
3025
3026 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3027
3028 if (!type_sp)
3029 {
3030 // We weren't able to find a full declaration in
3031 // this DWARF, see if we have a declaration anywhere
3032 // else...
3033 if (m_debug_map_symfile)
3034 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
3035 }
3036 if (type_sp)
3037 return type_sp;
3038 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039 assert (tag_decl_kind != -1);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003040 bool clang_type_was_created = false;
3041 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3042 if (clang_type == NULL)
3043 {
3044 clang_type_was_created = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003045 clang_type = ast.CreateRecordType (type_name_cstr,
3046 tag_decl_kind,
3047 GetClangDeclContextForDIE (dwarf_cu, die),
3048 class_language);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003049 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003050
Greg Clayton6adffa22010-09-28 01:04:25 +00003051 // Store a forward declaration to this class type in case any
3052 // parameters in any class methods need it for the clang
3053 // types for function prototypes.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003054 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003055 type_sp.reset (new Type (die->GetOffset(),
3056 this,
3057 type_name_const_str,
3058 byte_size,
3059 NULL,
3060 LLDB_INVALID_UID,
3061 Type::eEncodingIsUID,
3062 &decl,
3063 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003064 Type::eResolveStateForward));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003065
Greg Clayton594e5ed2010-09-27 21:07:38 +00003066 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003067
Greg Clayton40328bf2010-11-08 02:05:08 +00003068 if (die->HasChildren() == false && is_forward_declaration == false)
Greg Clayton1be10fc2010-09-29 01:12:09 +00003069 {
Greg Clayton4957bf62010-09-30 21:49:03 +00003070 // No children for this struct/union/class, lets finish it
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003071 ast.StartTagDeclarationDefinition (clang_type);
3072 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton4957bf62010-09-30 21:49:03 +00003073 }
3074 else if (clang_type_was_created)
3075 {
3076 // Leave this as a forward declaration until we need
3077 // to know the details of the type. lldb_private::Type
3078 // will automatically call the SymbolFile virtual function
3079 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3080 // When the definition needs to be defined.
Greg Clayton1be10fc2010-09-29 01:12:09 +00003081 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003082 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003083 }
Greg Clayton4957bf62010-09-30 21:49:03 +00003084
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003085 }
3086 break;
3087
3088 case DW_TAG_enumeration_type:
3089 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003090 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003091 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003092
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003093 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003094
Greg Claytond88d7592010-09-15 08:33:30 +00003095 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003096 if (num_attributes > 0)
3097 {
3098 uint32_t i;
3099
3100 for (i=0; i<num_attributes; ++i)
3101 {
3102 attr = attributes.AttributeAtIndex(i);
3103 DWARFFormValue form_value;
3104 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3105 {
3106 switch (attr)
3107 {
Greg Clayton7a345282010-11-09 23:46:37 +00003108 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3109 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3110 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003111 case DW_AT_name:
3112 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003113 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003114 break;
Greg Clayton7a345282010-11-09 23:46:37 +00003115 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3116 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3117 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3118 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003119 case DW_AT_allocated:
3120 case DW_AT_associated:
3121 case DW_AT_bit_stride:
3122 case DW_AT_byte_stride:
3123 case DW_AT_data_location:
3124 case DW_AT_description:
3125 case DW_AT_start_scope:
3126 case DW_AT_visibility:
3127 case DW_AT_specification:
3128 case DW_AT_abstract_origin:
3129 case DW_AT_sibling:
3130 break;
3131 }
3132 }
3133 }
3134
Greg Claytonc93237c2010-10-01 20:48:32 +00003135 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3136
Greg Clayton1be10fc2010-09-29 01:12:09 +00003137 clang_type_t enumerator_clang_type = NULL;
3138 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
3139 if (clang_type == NULL)
3140 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003141 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
3142 DW_ATE_signed,
3143 byte_size * 8);
3144 clang_type = ast.CreateEnumerationType (decl,
3145 type_name_cstr,
3146 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003147 }
3148 else
3149 {
3150 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
3151 assert (enumerator_clang_type != NULL);
3152 }
3153
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003154 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003155 type_sp.reset( new Type (die->GetOffset(),
3156 this,
3157 type_name_const_str,
3158 byte_size,
3159 NULL,
3160 encoding_uid,
3161 Type::eEncodingIsUID,
3162 &decl,
3163 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003164 Type::eResolveStateForward));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003165
Greg Clayton594e5ed2010-09-27 21:07:38 +00003166 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003167
Greg Clayton1be10fc2010-09-29 01:12:09 +00003168 // Leave this as a forward declaration until we need
3169 // to know the details of the type. lldb_private::Type
3170 // will automatically call the SymbolFile virtual function
3171 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
3172 // When the definition needs to be defined.
3173 m_forward_decl_die_to_clang_type[die] = clang_type;
Greg Claytonc93237c2010-10-01 20:48:32 +00003174 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003176 }
3177 }
3178 break;
3179
Jim Inghamb0be4422010-08-12 01:20:14 +00003180 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003181 case DW_TAG_subprogram:
3182 case DW_TAG_subroutine_type:
3183 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003184 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003185 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003186
3187 const char *mangled = NULL;
3188 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003189 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003190 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003191 bool is_static = false;
3192 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00003193 bool is_explicit = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00003194
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003195 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00003196 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197
3198
Greg Claytond88d7592010-09-15 08:33:30 +00003199 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003200 if (num_attributes > 0)
3201 {
3202 uint32_t i;
3203 for (i=0; i<num_attributes; ++i)
3204 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003205 const dw_attr_t attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003206 DWARFFormValue form_value;
3207 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3208 {
3209 switch (attr)
3210 {
3211 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3212 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3213 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3214 case DW_AT_name:
3215 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003216 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003217 break;
3218
3219 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3220 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003221 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003222 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003223 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
3224 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00003225 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
3226
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003227 case DW_AT_external:
3228 if (form_value.Unsigned())
3229 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00003230 if (storage == clang::SC_None)
3231 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003232 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00003233 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003234 }
3235 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003236
3237 case DW_AT_allocated:
3238 case DW_AT_associated:
3239 case DW_AT_address_class:
3240 case DW_AT_artificial:
3241 case DW_AT_calling_convention:
3242 case DW_AT_data_location:
3243 case DW_AT_elemental:
3244 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003245 case DW_AT_frame_base:
3246 case DW_AT_high_pc:
3247 case DW_AT_low_pc:
3248 case DW_AT_object_pointer:
3249 case DW_AT_prototyped:
3250 case DW_AT_pure:
3251 case DW_AT_ranges:
3252 case DW_AT_recursive:
3253 case DW_AT_return_addr:
3254 case DW_AT_segment:
3255 case DW_AT_specification:
3256 case DW_AT_start_scope:
3257 case DW_AT_static_link:
3258 case DW_AT_trampoline:
3259 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003260 case DW_AT_vtable_elem_location:
3261 case DW_AT_abstract_origin:
3262 case DW_AT_description:
3263 case DW_AT_sibling:
3264 break;
3265 }
3266 }
3267 }
Greg Clayton24739922010-10-13 03:15:28 +00003268 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003269
Greg Clayton24739922010-10-13 03:15:28 +00003270 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 +00003271
Greg Clayton24739922010-10-13 03:15:28 +00003272 clang_type_t return_clang_type = NULL;
3273 Type *func_type = NULL;
3274
3275 if (type_die_offset != DW_INVALID_OFFSET)
3276 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00003277
Greg Clayton24739922010-10-13 03:15:28 +00003278 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00003279 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00003280 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003281 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003282
Greg Claytonf51de672010-10-01 02:31:07 +00003283
Greg Clayton24739922010-10-13 03:15:28 +00003284 std::vector<clang_type_t> function_param_types;
3285 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003286
Greg Clayton24739922010-10-13 03:15:28 +00003287 // Parse the function children for the parameters
3288 if (die->HasChildren())
3289 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003290 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003291 ParseChildParameters (sc,
3292 type_sp,
3293 dwarf_cu,
3294 die,
3295 skip_artificial,
3296 type_list,
3297 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00003298 function_param_decls,
3299 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00003300 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003301
Greg Clayton24739922010-10-13 03:15:28 +00003302 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003303 clang_type = ast.CreateFunctionType (return_clang_type,
3304 &function_param_types[0],
3305 function_param_types.size(),
3306 is_variadic,
3307 type_quals);
3308
Greg Clayton24739922010-10-13 03:15:28 +00003309 if (type_name_cstr)
3310 {
3311 bool type_handled = false;
3312 const DWARFDebugInfoEntry *parent_die = die->GetParent();
3313 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003314 {
Greg Clayton24739922010-10-13 03:15:28 +00003315 if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
Greg Clayton0fffff52010-09-24 05:15:53 +00003316 {
Greg Clayton24739922010-10-13 03:15:28 +00003317 // We need to find the DW_TAG_class_type or
3318 // DW_TAG_struct_type by name so we can add this
3319 // as a member function of the class.
3320 const char *class_name_start = type_name_cstr + 2;
3321 const char *class_name_end = ::strchr (class_name_start, ' ');
3322 SymbolContext empty_sc;
3323 clang_type_t class_opaque_type = NULL;
3324 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00003325 {
Greg Clayton24739922010-10-13 03:15:28 +00003326 ConstString class_name (class_name_start, class_name_end - class_name_start);
3327 TypeList types;
3328 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3329 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00003330 {
Greg Clayton24739922010-10-13 03:15:28 +00003331 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00003332 {
Greg Clayton24739922010-10-13 03:15:28 +00003333 Type *type = types.GetTypeAtIndex (i).get();
3334 clang_type_t type_clang_forward_type = type->GetClangForwardType();
3335 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003336 {
Greg Clayton24739922010-10-13 03:15:28 +00003337 class_opaque_type = type_clang_forward_type;
3338 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00003339 }
3340 }
3341 }
Greg Clayton24739922010-10-13 03:15:28 +00003342 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003343
Greg Clayton24739922010-10-13 03:15:28 +00003344 if (class_opaque_type)
3345 {
3346 // If accessibility isn't set to anything valid, assume public for
3347 // now...
3348 if (accessibility == eAccessNone)
3349 accessibility = eAccessPublic;
3350
3351 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003352 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
3353 type_name_cstr,
3354 clang_type,
3355 accessibility);
Greg Clayton24739922010-10-13 03:15:28 +00003356 type_handled = objc_method_decl != NULL;
3357 }
3358 }
3359 else if (parent_die->Tag() == DW_TAG_class_type ||
3360 parent_die->Tag() == DW_TAG_structure_type)
3361 {
3362 // Look at the parent of this DIE and see if is is
3363 // a class or struct and see if this is actually a
3364 // C++ method
3365 Type *class_type = ResolveType (dwarf_cu, parent_die);
3366 if (class_type)
3367 {
3368 clang_type_t class_opaque_type = class_type->GetClangForwardType();
3369 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00003370 {
Greg Clayton24739922010-10-13 03:15:28 +00003371 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3372 // in the DWARF for C++ methods... Default to public for now...
Greg Clayton6d01ad92010-09-29 01:57:37 +00003373 if (accessibility == eAccessNone)
3374 accessibility = eAccessPublic;
3375
Greg Clayton24739922010-10-13 03:15:28 +00003376 clang::CXXMethodDecl *cxx_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003377 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
3378 type_name_cstr,
3379 clang_type,
3380 accessibility,
3381 is_virtual,
3382 is_static,
3383 is_inline,
3384 is_explicit);
Greg Clayton24739922010-10-13 03:15:28 +00003385 type_handled = cxx_method_decl != NULL;
Greg Clayton0fffff52010-09-24 05:15:53 +00003386 }
3387 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003388 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003389 }
Greg Clayton24739922010-10-13 03:15:28 +00003390
3391 if (!type_handled)
3392 {
3393 // We just have a function that isn't part of a class
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003394 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (type_name_cstr,
3395 clang_type,
3396 storage,
3397 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00003398
3399 // Add the decl to our DIE to decl context map
3400 assert (function_decl);
3401 m_die_to_decl_ctx[die] = function_decl;
3402 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003403 ast.SetFunctionParameters (function_decl,
3404 &function_param_decls.front(),
3405 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00003406 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003407 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003408 type_sp.reset( new Type (die->GetOffset(),
3409 this,
3410 type_name_const_str,
3411 0,
3412 NULL,
3413 LLDB_INVALID_UID,
3414 Type::eEncodingIsUID,
3415 &decl,
3416 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003417 Type::eResolveStateFull));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003418
Greg Clayton24739922010-10-13 03:15:28 +00003419 m_die_to_type[die] = type_sp.get();
3420 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003421 }
3422 break;
3423
3424 case DW_TAG_array_type:
3425 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003426 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003427 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003428
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003429 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003430 int64_t first_index = 0;
3431 uint32_t byte_stride = 0;
3432 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00003433 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003434
3435 if (num_attributes > 0)
3436 {
3437 uint32_t i;
3438 for (i=0; i<num_attributes; ++i)
3439 {
3440 attr = attributes.AttributeAtIndex(i);
3441 DWARFFormValue form_value;
3442 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3443 {
3444 switch (attr)
3445 {
3446 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3447 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3448 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3449 case DW_AT_name:
3450 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003451 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003452 break;
3453
3454 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
3455 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
3456 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
3457 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003458 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00003459 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003460 case DW_AT_allocated:
3461 case DW_AT_associated:
3462 case DW_AT_data_location:
3463 case DW_AT_description:
3464 case DW_AT_ordering:
3465 case DW_AT_start_scope:
3466 case DW_AT_visibility:
3467 case DW_AT_specification:
3468 case DW_AT_abstract_origin:
3469 case DW_AT_sibling:
3470 break;
3471 }
3472 }
3473 }
3474
Greg Claytonc93237c2010-10-01 20:48:32 +00003475 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3476
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003477 Type *element_type = ResolveTypeUID(type_die_offset);
3478
3479 if (element_type)
3480 {
3481 std::vector<uint64_t> element_orders;
3482 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00003483 // We have an array that claims to have no members, lets give it at least one member...
3484 if (element_orders.empty())
3485 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003486 if (byte_stride == 0 && bit_stride == 0)
3487 byte_stride = element_type->GetByteSize();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003488 clang_type_t array_element_type = element_type->GetClangType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003489 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3490 uint64_t num_elements = 0;
3491 std::vector<uint64_t>::const_reverse_iterator pos;
3492 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3493 for (pos = element_orders.rbegin(); pos != end; ++pos)
3494 {
3495 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003496 clang_type = ast.CreateArrayType (array_element_type,
3497 num_elements,
3498 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003499 array_element_type = clang_type;
3500 array_element_bit_stride = array_element_bit_stride * num_elements;
3501 }
3502 ConstString empty_name;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003503 type_sp.reset( new Type (die->GetOffset(),
3504 this,
3505 empty_name,
3506 array_element_bit_stride / 8,
3507 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00003508 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003509 Type::eEncodingIsUID,
3510 &decl,
3511 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003512 Type::eResolveStateFull));
3513 type_sp->SetEncodingType (element_type);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003514 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003515 }
3516 }
3517 }
3518 break;
3519
Greg Clayton9b81a312010-06-12 01:20:30 +00003520 case DW_TAG_ptr_to_member_type:
3521 {
3522 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3523 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3524
Greg Claytond88d7592010-09-15 08:33:30 +00003525 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00003526
3527 if (num_attributes > 0) {
3528 uint32_t i;
3529 for (i=0; i<num_attributes; ++i)
3530 {
3531 attr = attributes.AttributeAtIndex(i);
3532 DWARFFormValue form_value;
3533 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3534 {
3535 switch (attr)
3536 {
3537 case DW_AT_type:
3538 type_die_offset = form_value.Reference(dwarf_cu); break;
3539 case DW_AT_containing_type:
3540 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3541 }
3542 }
3543 }
3544
3545 Type *pointee_type = ResolveTypeUID(type_die_offset);
3546 Type *class_type = ResolveTypeUID(containing_type_die_offset);
3547
Greg Clayton526e5af2010-11-13 03:52:47 +00003548 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
3549 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00003550
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003551 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
3552 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00003553
Greg Clayton526e5af2010-11-13 03:52:47 +00003554 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
3555 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00003556
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003557 type_sp.reset( new Type (die->GetOffset(),
3558 this,
3559 type_name_const_str,
3560 byte_size,
3561 NULL,
3562 LLDB_INVALID_UID,
3563 Type::eEncodingIsUID,
3564 NULL,
3565 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003566 Type::eResolveStateForward));
Greg Clayton594e5ed2010-09-27 21:07:38 +00003567 m_die_to_type[die] = type_sp.get();
Greg Clayton9b81a312010-06-12 01:20:30 +00003568 }
3569
3570 break;
3571 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003572 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00003573 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003574 break;
3575 }
3576
3577 if (type_sp.get())
3578 {
3579 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3580 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3581
3582 SymbolContextScope * symbol_context_scope = NULL;
3583 if (sc_parent_tag == DW_TAG_compile_unit)
3584 {
3585 symbol_context_scope = sc.comp_unit;
3586 }
3587 else if (sc.function != NULL)
3588 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003589 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003590 if (symbol_context_scope == NULL)
3591 symbol_context_scope = sc.function;
3592 }
3593
3594 if (symbol_context_scope != NULL)
3595 {
3596 type_sp->SetSymbolContextScope(symbol_context_scope);
3597 }
3598
3599// if (udt_sp.get())
3600// {
3601// if (is_forward_declaration)
3602// udt_sp->GetFlags().Set(UserDefType::flagIsForwardDefinition);
3603// type_sp->SetUserDefinedType(udt_sp);
3604// }
3605
3606 if (type_sp.unique())
3607 {
3608 // We are ready to put this type into the uniqued list up at the module level
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003609 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00003610
Greg Clayton594e5ed2010-09-27 21:07:38 +00003611 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003612 }
3613 }
3614 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00003615 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003616 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003617 type_sp = type_list->FindType(type_ptr->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003618 }
3619 }
3620 return type_sp;
3621}
3622
3623size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003624SymbolFileDWARF::ParseTypes
3625(
3626 const SymbolContext& sc,
3627 DWARFCompileUnit* dwarf_cu,
3628 const DWARFDebugInfoEntry *die,
3629 bool parse_siblings,
3630 bool parse_children
3631)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003632{
3633 size_t types_added = 0;
3634 while (die != NULL)
3635 {
3636 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003637 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003638 {
3639 if (type_is_new)
3640 ++types_added;
3641 }
3642
3643 if (parse_children && die->HasChildren())
3644 {
3645 if (die->Tag() == DW_TAG_subprogram)
3646 {
3647 SymbolContext child_sc(sc);
3648 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
3649 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
3650 }
3651 else
3652 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
3653 }
3654
3655 if (parse_siblings)
3656 die = die->GetSibling();
3657 else
3658 die = NULL;
3659 }
3660 return types_added;
3661}
3662
3663
3664size_t
3665SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3666{
3667 assert(sc.comp_unit && sc.function);
3668 size_t functions_added = 0;
3669 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3670 if (dwarf_cu)
3671 {
3672 dw_offset_t function_die_offset = sc.function->GetID();
3673 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
3674 if (function_die)
3675 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003676 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, false, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003677 }
3678 }
3679
3680 return functions_added;
3681}
3682
3683
3684size_t
3685SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3686{
3687 // At least a compile unit must be valid
3688 assert(sc.comp_unit);
3689 size_t types_added = 0;
3690 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3691 if (dwarf_cu)
3692 {
3693 if (sc.function)
3694 {
3695 dw_offset_t function_die_offset = sc.function->GetID();
3696 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
3697 if (func_die && func_die->HasChildren())
3698 {
3699 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
3700 }
3701 }
3702 else
3703 {
3704 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
3705 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
3706 {
3707 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
3708 }
3709 }
3710 }
3711
3712 return types_added;
3713}
3714
3715size_t
3716SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3717{
3718 if (sc.comp_unit != NULL)
3719 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00003720 DWARFDebugInfo* info = DebugInfo();
3721 if (info == NULL)
3722 return 0;
3723
3724 uint32_t cu_idx = UINT32_MAX;
3725 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003726
3727 if (dwarf_cu == NULL)
3728 return 0;
3729
3730 if (sc.function)
3731 {
3732 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00003733
3734 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
3735 assert (func_lo_pc != DW_INVALID_ADDRESS);
3736
3737 return ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003738 }
3739 else if (sc.comp_unit)
3740 {
3741 uint32_t vars_added = 0;
3742 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3743
3744 if (variables.get() == NULL)
3745 {
3746 variables.reset(new VariableList());
3747 sc.comp_unit->SetVariableList(variables);
3748
3749 // Index if we already haven't to make sure the compile units
3750 // get indexed and make their global DIE index list
3751 if (!m_indexed)
3752 Index ();
3753
Greg Claytonc685f8e2010-09-15 04:15:46 +00003754 std::vector<NameToDIE::Info> global_die_info_array;
Greg Clayton4b3dc102010-11-01 20:32:12 +00003755 const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003756 for (size_t idx=0; idx<num_globals; ++idx)
3757 {
Greg Claytonc685f8e2010-09-15 04:15:46 +00003758 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759 if (var_sp)
3760 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00003761 variables->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003762 ++vars_added;
3763 }
3764 }
3765 }
3766 return vars_added;
3767 }
3768 }
3769 return 0;
3770}
3771
3772
3773VariableSP
3774SymbolFileDWARF::ParseVariableDIE
3775(
3776 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003777 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00003778 const DWARFDebugInfoEntry *die,
3779 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003780)
3781{
3782
Greg Clayton83c5cd92010-11-14 22:13:40 +00003783 VariableSP var_sp (m_die_to_variable_sp[die]);
3784 if (var_sp)
3785 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003786
3787 const dw_tag_t tag = die->Tag();
3788 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003789 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003790 if (num_attributes > 0)
3791 {
3792 const char *name = NULL;
Greg Claytona134cc12010-09-13 02:37:44 +00003793 const char *mangled = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003794 Declaration decl;
3795 uint32_t i;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003796 Type *var_type = NULL;
3797 DWARFExpression location;
3798 bool is_external = false;
3799 bool is_artificial = false;
Sean Callananc7fbf732010-08-06 00:32:49 +00003800 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003801
3802 for (i=0; i<num_attributes; ++i)
3803 {
3804 dw_attr_t attr = attributes.AttributeAtIndex(i);
3805 DWARFFormValue form_value;
3806 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3807 {
3808 switch (attr)
3809 {
3810 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3811 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3812 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3813 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Claytona134cc12010-09-13 02:37:44 +00003814 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton594e5ed2010-09-27 21:07:38 +00003815 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003816 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
3817 case DW_AT_location:
3818 {
3819 if (form_value.BlockData())
3820 {
3821 const DataExtractor& debug_info_data = get_debug_info_data();
3822
3823 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3824 uint32_t block_length = form_value.Unsigned();
Greg Clayton016a95e2010-09-14 02:20:48 +00003825 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003826 }
3827 else
3828 {
3829 const DataExtractor& debug_loc_data = get_debug_loc_data();
3830 const dw_offset_t debug_loc_offset = form_value.Unsigned();
3831
3832 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
3833 if (loc_list_length > 0)
3834 {
Greg Clayton016a95e2010-09-14 02:20:48 +00003835 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
3836 assert (func_low_pc != LLDB_INVALID_ADDRESS);
3837 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003838 }
3839 }
3840 }
3841 break;
3842
3843 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Greg Clayton8cf05932010-07-22 18:30:50 +00003844 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003845 case DW_AT_const_value:
3846 case DW_AT_declaration:
3847 case DW_AT_description:
3848 case DW_AT_endianity:
3849 case DW_AT_segment:
3850 case DW_AT_start_scope:
3851 case DW_AT_visibility:
3852 default:
3853 case DW_AT_abstract_origin:
3854 case DW_AT_sibling:
3855 case DW_AT_specification:
3856 break;
3857 }
3858 }
3859 }
3860
3861 if (location.IsValid())
3862 {
3863 assert(var_type != DIE_IS_BEING_PARSED);
3864
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003865 ValueType scope = eValueTypeInvalid;
3866
3867 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3868 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3869
3870 if (tag == DW_TAG_formal_parameter)
3871 scope = eValueTypeVariableArgument;
3872 else if (is_external || parent_tag == DW_TAG_compile_unit)
3873 scope = eValueTypeVariableGlobal;
3874 else
3875 scope = eValueTypeVariableLocal;
3876
3877 SymbolContextScope * symbol_context_scope = NULL;
3878 if (parent_tag == DW_TAG_compile_unit)
3879 {
3880 symbol_context_scope = sc.comp_unit;
3881 }
3882 else if (sc.function != NULL)
3883 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003884 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003885 if (symbol_context_scope == NULL)
3886 symbol_context_scope = sc.function;
3887 }
3888
3889 assert(symbol_context_scope != NULL);
3890 var_sp.reset (new Variable(die->GetOffset(),
Greg Clayton83c5cd92010-11-14 22:13:40 +00003891 name,
3892 mangled,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003893 var_type,
3894 scope,
3895 symbol_context_scope,
3896 &decl,
3897 location,
3898 is_external,
3899 is_artificial));
Greg Clayton594e5ed2010-09-27 21:07:38 +00003900
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003901 }
3902 }
Greg Clayton83c5cd92010-11-14 22:13:40 +00003903 // Cache var_sp even if NULL (the variable was just a specification or
3904 // was missing vital information to be able to be displayed in the debugger
3905 // (missing location due to optimization, etc)) so we don't re-parse
3906 // this DIE over and over later...
3907 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003908 return var_sp;
3909}
3910
3911size_t
3912SymbolFileDWARF::ParseVariables
3913(
3914 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003915 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00003916 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003917 const DWARFDebugInfoEntry *orig_die,
3918 bool parse_siblings,
3919 bool parse_children,
3920 VariableList* cc_variable_list
3921)
3922{
3923 if (orig_die == NULL)
3924 return 0;
3925
3926 size_t vars_added = 0;
3927 const DWARFDebugInfoEntry *die = orig_die;
3928 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
3929 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3930 VariableListSP variables;
3931 switch (parent_tag)
3932 {
3933 case DW_TAG_compile_unit:
3934 if (sc.comp_unit != NULL)
3935 {
3936 variables = sc.comp_unit->GetVariableList(false);
3937 if (variables.get() == NULL)
3938 {
3939 variables.reset(new VariableList());
3940 sc.comp_unit->SetVariableList(variables);
3941 }
3942 }
3943 else
3944 {
3945 assert(!"Parent DIE was a compile unit, yet we don't have a valid compile unit in the symbol context...");
3946 vars_added = 0;
3947 }
3948 break;
3949
3950 case DW_TAG_subprogram:
3951 case DW_TAG_inlined_subroutine:
3952 case DW_TAG_lexical_block:
3953 if (sc.function != NULL)
3954 {
3955 // Check to see if we already have parsed the variables for the given scope
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003956
3957 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
3958 assert (block != NULL);
Greg Clayton1be10fc2010-09-29 01:12:09 +00003959 variables = block->GetVariableList(false, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003960 if (variables.get() == NULL)
3961 {
3962 variables.reset(new VariableList());
Greg Clayton0b76a2c2010-08-21 02:22:51 +00003963 block->SetVariableList(variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003964 }
3965 }
3966 else
3967 {
3968 assert(!"Parent DIE was a function or block, yet we don't have a function in the symbol context...");
3969 vars_added = 0;
3970 }
3971 break;
3972
3973 default:
3974 assert(!"Didn't find appropriate parent DIE for variable list...");
3975 break;
3976 }
3977
3978 // We need to have a variable list at this point that we can add variables to
3979 assert(variables.get());
3980
3981 while (die != NULL)
3982 {
3983 dw_tag_t tag = die->Tag();
3984
3985 // Check to see if we have already parsed this variable or constant?
Greg Claytonbcf12172010-10-28 00:56:11 +00003986 if (m_die_to_variable_sp[die])
3987 {
3988 if (cc_variable_list)
Greg Clayton83c5cd92010-11-14 22:13:40 +00003989 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Greg Claytonbcf12172010-10-28 00:56:11 +00003990 }
3991 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003992 {
3993 // We haven't already parsed it, lets do that now.
3994 if ((tag == DW_TAG_variable) ||
3995 (tag == DW_TAG_constant) ||
3996 (tag == DW_TAG_formal_parameter && sc.function))
3997 {
Greg Clayton016a95e2010-09-14 02:20:48 +00003998 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003999 if (var_sp)
4000 {
Greg Clayton83c5cd92010-11-14 22:13:40 +00004001 variables->AddVariableIfUnique (var_sp);
Greg Claytonbcf12172010-10-28 00:56:11 +00004002 if (cc_variable_list)
Greg Clayton83c5cd92010-11-14 22:13:40 +00004003 cc_variable_list->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004004 ++vars_added;
4005 }
4006 }
4007 }
4008
4009 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4010
4011 if (!skip_children && parse_children && die->HasChildren())
4012 {
Greg Claytonbcf12172010-10-28 00:56:11 +00004013 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004014 }
4015
4016 if (parse_siblings)
4017 die = die->GetSibling();
4018 else
4019 die = NULL;
4020 }
4021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004022 return vars_added;
4023}
4024
4025//------------------------------------------------------------------
4026// PluginInterface protocol
4027//------------------------------------------------------------------
4028const char *
4029SymbolFileDWARF::GetPluginName()
4030{
4031 return "SymbolFileDWARF";
4032}
4033
4034const char *
4035SymbolFileDWARF::GetShortPluginName()
4036{
4037 return GetPluginNameStatic();
4038}
4039
4040uint32_t
4041SymbolFileDWARF::GetPluginVersion()
4042{
4043 return 1;
4044}
4045
4046void
4047SymbolFileDWARF::GetPluginCommandHelp (const char *command, Stream *strm)
4048{
4049}
4050
4051Error
4052SymbolFileDWARF::ExecutePluginCommand (Args &command, Stream *strm)
4053{
4054 Error error;
4055 error.SetErrorString("No plug-in command are currently supported.");
4056 return error;
4057}
4058
4059Log *
4060SymbolFileDWARF::EnablePluginLogging (Stream *strm, Args &command)
4061{
4062 return NULL;
4063}
4064