blob: 08b608808f8620a5e35208397dbc42c756ccc5d6 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
17#include "clang/Basic/Builtins.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/Basic/LangOptions.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000023#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
Sean Callanancc427fa2011-07-30 02:42:06 +000025#include "llvm/Support/Casting.h"
26
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/PluginManager.h"
29#include "lldb/Core/RegularExpression.h"
30#include "lldb/Core/Scalar.h"
31#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000032#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000033#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/Timer.h"
35#include "lldb/Core/Value.h"
36
Greg Clayton20568dd2011-10-13 23:13:20 +000037#include "lldb/Host/Host.h"
38
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/Block.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000040#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/CompileUnit.h"
42#include "lldb/Symbol/LineTable.h"
43#include "lldb/Symbol/ObjectFile.h"
44#include "lldb/Symbol/SymbolVendor.h"
45#include "lldb/Symbol/VariableList.h"
46
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000047#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000048#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000049
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "DWARFCompileUnit.h"
51#include "DWARFDebugAbbrev.h"
52#include "DWARFDebugAranges.h"
53#include "DWARFDebugInfo.h"
54#include "DWARFDebugInfoEntry.h"
55#include "DWARFDebugLine.h"
56#include "DWARFDebugPubnames.h"
57#include "DWARFDebugRanges.h"
58#include "DWARFDIECollection.h"
59#include "DWARFFormValue.h"
60#include "DWARFLocationList.h"
61#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000062#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64#include <map>
65
Greg Clayton62742b12010-11-11 01:09:45 +000066//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000067
68#ifdef ENABLE_DEBUG_PRINTF
69#include <stdio.h>
70#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
71#else
72#define DEBUG_PRINTF(fmt, ...)
73#endif
74
Greg Clayton594e5ed2010-09-27 21:07:38 +000075#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
77using namespace lldb;
78using namespace lldb_private;
79
80
Sean Callananc7fbf732010-08-06 00:32:49 +000081static AccessType
Greg Clayton8cf05932010-07-22 18:30:50 +000082DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083{
84 switch (dwarf_accessibility)
85 {
Sean Callananc7fbf732010-08-06 00:32:49 +000086 case DW_ACCESS_public: return eAccessPublic;
87 case DW_ACCESS_private: return eAccessPrivate;
88 case DW_ACCESS_protected: return eAccessProtected;
Greg Clayton8cf05932010-07-22 18:30:50 +000089 default: break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090 }
Sean Callananc7fbf732010-08-06 00:32:49 +000091 return eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092}
93
94void
95SymbolFileDWARF::Initialize()
96{
97 LogChannelDWARF::Initialize();
98 PluginManager::RegisterPlugin (GetPluginNameStatic(),
99 GetPluginDescriptionStatic(),
100 CreateInstance);
101}
102
103void
104SymbolFileDWARF::Terminate()
105{
106 PluginManager::UnregisterPlugin (CreateInstance);
107 LogChannelDWARF::Initialize();
108}
109
110
111const char *
112SymbolFileDWARF::GetPluginNameStatic()
113{
Greg Claytond4a2b372011-09-12 23:21:58 +0000114 return "dwarf";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115}
116
117const char *
118SymbolFileDWARF::GetPluginDescriptionStatic()
119{
120 return "DWARF and DWARF3 debug symbol file reader.";
121}
122
123
124SymbolFile*
125SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
126{
127 return new SymbolFileDWARF(obj_file);
128}
129
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000130TypeList *
131SymbolFileDWARF::GetTypeList ()
132{
133 if (m_debug_map_symfile)
134 return m_debug_map_symfile->GetTypeList();
135 return m_obj_file->GetModule()->GetTypeList();
136
137}
138
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139//----------------------------------------------------------------------
140// Gets the first parent that is a lexical block, function or inlined
141// subroutine, or compile unit.
142//----------------------------------------------------------------------
143static const DWARFDebugInfoEntry *
144GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
145{
146 const DWARFDebugInfoEntry *die;
147 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
148 {
149 dw_tag_t tag = die->Tag();
150
151 switch (tag)
152 {
153 case DW_TAG_compile_unit:
154 case DW_TAG_subprogram:
155 case DW_TAG_inlined_subroutine:
156 case DW_TAG_lexical_block:
157 return die;
158 }
159 }
160 return NULL;
161}
162
163
Greg Clayton450e3f32010-10-12 02:24:53 +0000164SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
165 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000166 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton450e3f32010-10-12 02:24:53 +0000167 m_debug_map_symfile (NULL),
Greg Clayton7a345282010-11-09 23:46:37 +0000168 m_clang_tu_decl (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000170 m_data_debug_abbrev (),
171 m_data_debug_aranges (),
172 m_data_debug_frame (),
173 m_data_debug_info (),
174 m_data_debug_line (),
175 m_data_debug_loc (),
176 m_data_debug_ranges (),
177 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000178 m_data_apple_names (),
179 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000180 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 m_info(),
183 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000184 m_apple_names_ap (),
185 m_apple_types_ap (),
186 m_apple_namespaces_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000187 m_function_basename_index(),
188 m_function_fullname_index(),
189 m_function_method_index(),
190 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000191 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000192 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000193 m_type_index(),
194 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000195 m_indexed (false),
196 m_is_external_ast_source (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000197 m_using_apple_tables (false),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000198 m_ranges(),
199 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200{
201}
202
203SymbolFileDWARF::~SymbolFileDWARF()
204{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000205 if (m_is_external_ast_source)
206 m_obj_file->GetModule()->GetClangASTContext().RemoveExternalSource ();
207}
208
209static const ConstString &
210GetDWARFMachOSegmentName ()
211{
212 static ConstString g_dwarf_section_name ("__DWARF");
213 return g_dwarf_section_name;
214}
215
Greg Claytone576ab22011-02-15 00:19:15 +0000216UniqueDWARFASTTypeMap &
217SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
218{
219 if (m_debug_map_symfile)
220 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
221 return m_unique_ast_type_map;
222}
223
Greg Clayton6beaaa62011-01-17 03:46:26 +0000224ClangASTContext &
225SymbolFileDWARF::GetClangASTContext ()
226{
227 if (m_debug_map_symfile)
228 return m_debug_map_symfile->GetClangASTContext ();
229
230 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
231 if (!m_is_external_ast_source)
232 {
233 m_is_external_ast_source = true;
234 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
235 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
236 SymbolFileDWARF::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000237 SymbolFileDWARF::FindExternalVisibleDeclsByName,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000238 this));
239
240 ast.SetExternalSource (ast_source_ap);
241 }
242 return ast;
243}
244
245void
246SymbolFileDWARF::InitializeObject()
247{
248 // Install our external AST source callbacks so we can complete Clang types.
249 Module *module = m_obj_file->GetModule();
250 if (module)
251 {
252 const SectionList *section_list = m_obj_file->GetSectionList();
253
254 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
255
256 // Memory map the DWARF mach-o segment so we have everything mmap'ed
257 // to keep our heap memory usage down.
258 if (section)
259 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
260 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000261 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000262 if (m_data_apple_names.GetByteSize() > 0)
263 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000264 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
265 if (m_apple_names_ap->IsValid())
266 m_using_apple_tables = true;
267 else
Greg Clayton7f995132011-10-04 22:41:51 +0000268 m_apple_names_ap.reset();
269 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000270 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000271 if (m_data_apple_types.GetByteSize() > 0)
272 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000273 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
274 if (m_apple_types_ap->IsValid())
275 m_using_apple_tables = true;
276 else
Greg Clayton7f995132011-10-04 22:41:51 +0000277 m_apple_types_ap.reset();
278 }
279
280 get_apple_namespaces_data();
281 if (m_data_apple_namespaces.GetByteSize() > 0)
282 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000283 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
284 if (m_apple_namespaces_ap->IsValid())
285 m_using_apple_tables = true;
286 else
Greg Clayton7f995132011-10-04 22:41:51 +0000287 m_apple_namespaces_ap.reset();
288 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000289
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290}
291
292bool
293SymbolFileDWARF::SupportedVersion(uint16_t version)
294{
295 return version == 2 || version == 3;
296}
297
298uint32_t
299SymbolFileDWARF::GetAbilities ()
300{
301 uint32_t abilities = 0;
302 if (m_obj_file != NULL)
303 {
304 const Section* section = NULL;
305 const SectionList *section_list = m_obj_file->GetSectionList();
306 if (section_list == NULL)
307 return 0;
308
309 uint64_t debug_abbrev_file_size = 0;
310 uint64_t debug_aranges_file_size = 0;
311 uint64_t debug_frame_file_size = 0;
312 uint64_t debug_info_file_size = 0;
313 uint64_t debug_line_file_size = 0;
314 uint64_t debug_loc_file_size = 0;
315 uint64_t debug_macinfo_file_size = 0;
316 uint64_t debug_pubnames_file_size = 0;
317 uint64_t debug_pubtypes_file_size = 0;
318 uint64_t debug_ranges_file_size = 0;
319 uint64_t debug_str_file_size = 0;
320
Greg Clayton6beaaa62011-01-17 03:46:26 +0000321 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322
323 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000324 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325
Greg Clayton4ceb9982010-07-21 22:54:26 +0000326 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327 if (section != NULL)
328 {
329 debug_info_file_size = section->GetByteSize();
330
Greg Clayton4ceb9982010-07-21 22:54:26 +0000331 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332 if (section)
333 debug_abbrev_file_size = section->GetByteSize();
334 else
335 m_flags.Set (flagsGotDebugAbbrevData);
336
Greg Clayton4ceb9982010-07-21 22:54:26 +0000337 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000338 if (section)
339 debug_aranges_file_size = section->GetByteSize();
340 else
341 m_flags.Set (flagsGotDebugArangesData);
342
Greg Clayton4ceb9982010-07-21 22:54:26 +0000343 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344 if (section)
345 debug_frame_file_size = section->GetByteSize();
346 else
347 m_flags.Set (flagsGotDebugFrameData);
348
Greg Clayton4ceb9982010-07-21 22:54:26 +0000349 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350 if (section)
351 debug_line_file_size = section->GetByteSize();
352 else
353 m_flags.Set (flagsGotDebugLineData);
354
Greg Clayton4ceb9982010-07-21 22:54:26 +0000355 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 if (section)
357 debug_loc_file_size = section->GetByteSize();
358 else
359 m_flags.Set (flagsGotDebugLocData);
360
Greg Clayton4ceb9982010-07-21 22:54:26 +0000361 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362 if (section)
363 debug_macinfo_file_size = section->GetByteSize();
364 else
365 m_flags.Set (flagsGotDebugMacInfoData);
366
Greg Clayton4ceb9982010-07-21 22:54:26 +0000367 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 if (section)
369 debug_pubnames_file_size = section->GetByteSize();
370 else
371 m_flags.Set (flagsGotDebugPubNamesData);
372
Greg Clayton4ceb9982010-07-21 22:54:26 +0000373 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 if (section)
375 debug_pubtypes_file_size = section->GetByteSize();
376 else
377 m_flags.Set (flagsGotDebugPubTypesData);
378
Greg Clayton4ceb9982010-07-21 22:54:26 +0000379 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 if (section)
381 debug_ranges_file_size = section->GetByteSize();
382 else
383 m_flags.Set (flagsGotDebugRangesData);
384
Greg Clayton4ceb9982010-07-21 22:54:26 +0000385 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386 if (section)
387 debug_str_file_size = section->GetByteSize();
388 else
389 m_flags.Set (flagsGotDebugStrData);
390 }
391
392 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
393 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
394
395 if (debug_line_file_size > 0)
396 abilities |= LineTables;
397
398 if (debug_aranges_file_size > 0)
399 abilities |= AddressAcceleratorTable;
400
401 if (debug_pubnames_file_size > 0)
402 abilities |= FunctionAcceleratorTable;
403
404 if (debug_pubtypes_file_size > 0)
405 abilities |= TypeAcceleratorTable;
406
407 if (debug_macinfo_file_size > 0)
408 abilities |= MacroInformation;
409
410 if (debug_frame_file_size > 0)
411 abilities |= CallFrameInformation;
412 }
413 return abilities;
414}
415
416const DataExtractor&
Greg Clayton4ceb9982010-07-21 22:54:26 +0000417SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418{
419 if (m_flags.IsClear (got_flag))
420 {
421 m_flags.Set (got_flag);
422 const SectionList *section_list = m_obj_file->GetSectionList();
423 if (section_list)
424 {
Greg Clayton4ceb9982010-07-21 22:54:26 +0000425 Section *section = section_list->FindSectionByType(sect_type, true).get();
426 if (section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 {
428 // See if we memory mapped the DWARF segment?
429 if (m_dwarf_data.GetByteSize())
430 {
431 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
432 }
433 else
434 {
435 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
436 data.Clear();
437 }
438 }
439 }
440 }
441 return data;
442}
443
444const DataExtractor&
445SymbolFileDWARF::get_debug_abbrev_data()
446{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000447 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448}
449
450const DataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000451SymbolFileDWARF::get_debug_aranges_data()
452{
453 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
454}
455
456const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457SymbolFileDWARF::get_debug_frame_data()
458{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000459 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460}
461
462const DataExtractor&
463SymbolFileDWARF::get_debug_info_data()
464{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000465 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466}
467
468const DataExtractor&
469SymbolFileDWARF::get_debug_line_data()
470{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000471 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472}
473
474const DataExtractor&
475SymbolFileDWARF::get_debug_loc_data()
476{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000477 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480const DataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481SymbolFileDWARF::get_debug_ranges_data()
482{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000483 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486const DataExtractor&
487SymbolFileDWARF::get_debug_str_data()
488{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000489 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
Greg Claytonf9eec202011-09-01 23:16:13 +0000492const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000493SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000494{
Greg Clayton17674402011-09-28 17:06:40 +0000495 return GetCachedSectionData (flagsGotDebugNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000496}
497
498const DataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000499SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000500{
Greg Clayton17674402011-09-28 17:06:40 +0000501 return GetCachedSectionData (flagsGotDebugTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000502}
503
Greg Clayton7f995132011-10-04 22:41:51 +0000504const DataExtractor&
505SymbolFileDWARF::get_apple_namespaces_data()
506{
Greg Clayton85ae2e12011-10-18 23:36:41 +0000507 return GetCachedSectionData (flagsGotDebugNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
Greg Clayton7f995132011-10-04 22:41:51 +0000508}
509
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510
511DWARFDebugAbbrev*
512SymbolFileDWARF::DebugAbbrev()
513{
514 if (m_abbr.get() == NULL)
515 {
516 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
517 if (debug_abbrev_data.GetByteSize() > 0)
518 {
519 m_abbr.reset(new DWARFDebugAbbrev());
520 if (m_abbr.get())
521 m_abbr->Parse(debug_abbrev_data);
522 }
523 }
524 return m_abbr.get();
525}
526
527const DWARFDebugAbbrev*
528SymbolFileDWARF::DebugAbbrev() const
529{
530 return m_abbr.get();
531}
532
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533
534DWARFDebugInfo*
535SymbolFileDWARF::DebugInfo()
536{
537 if (m_info.get() == NULL)
538 {
539 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
540 if (get_debug_info_data().GetByteSize() > 0)
541 {
542 m_info.reset(new DWARFDebugInfo());
543 if (m_info.get())
544 {
545 m_info->SetDwarfData(this);
546 }
547 }
548 }
549 return m_info.get();
550}
551
552const DWARFDebugInfo*
553SymbolFileDWARF::DebugInfo() const
554{
555 return m_info.get();
556}
557
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558DWARFCompileUnit*
559SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
560{
561 DWARFDebugInfo* info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +0000562 if (info && UserIDMatches(cu_uid))
563 return info->GetCompileUnit((dw_offset_t)cu_uid).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 return NULL;
565}
566
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567
568DWARFDebugRanges*
569SymbolFileDWARF::DebugRanges()
570{
571 if (m_ranges.get() == NULL)
572 {
573 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
574 if (get_debug_ranges_data().GetByteSize() > 0)
575 {
576 m_ranges.reset(new DWARFDebugRanges());
577 if (m_ranges.get())
578 m_ranges->Extract(this);
579 }
580 }
581 return m_ranges.get();
582}
583
584const DWARFDebugRanges*
585SymbolFileDWARF::DebugRanges() const
586{
587 return m_ranges.get();
588}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589
590bool
Greg Clayton96d7d742010-11-10 23:42:09 +0000591SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* curr_cu, CompUnitSP& compile_unit_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592{
Greg Clayton96d7d742010-11-10 23:42:09 +0000593 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000595 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 if (cu_die)
597 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000598 const char * cu_die_name = cu_die->GetName(this, curr_cu);
599 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
Jim Ingham0f35ac22011-08-24 23:34:20 +0000600 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, curr_cu, DW_AT_language, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 if (cu_die_name)
602 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000603 FileSpec cu_file_spec;
604
Greg Clayton7bd65b92011-02-09 23:39:34 +0000605 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606 {
Jim Ingham0909e5f2010-09-16 00:57:33 +0000607 // If we have a full path to the compile unit, we don't need to resolve
608 // the file. This can be expensive e.g. when the source files are NFS mounted.
609 cu_file_spec.SetFile (cu_die_name, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 }
611 else
612 {
613 std::string fullpath(cu_comp_dir);
614 if (*fullpath.rbegin() != '/')
615 fullpath += '/';
616 fullpath += cu_die_name;
Jim Ingham0909e5f2010-09-16 00:57:33 +0000617 cu_file_spec.SetFile (fullpath.c_str(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618 }
619
Greg Clayton81c22f62011-10-19 18:09:39 +0000620 compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
621 curr_cu,
622 cu_file_spec,
623 MakeUserID(curr_cu->GetOffset()),
624 cu_language));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 if (compile_unit_sp.get())
626 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000627 curr_cu->SetUserData(compile_unit_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 return true;
629 }
630 }
631 }
632 }
633 return false;
634}
635
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636uint32_t
637SymbolFileDWARF::GetNumCompileUnits()
638{
639 DWARFDebugInfo* info = DebugInfo();
640 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 return 0;
643}
644
645CompUnitSP
646SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
647{
648 CompUnitSP comp_unit;
649 DWARFDebugInfo* info = DebugInfo();
650 if (info)
651 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000652 DWARFCompileUnit* curr_cu = info->GetCompileUnitAtIndex(cu_idx);
653 if (curr_cu != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 {
655 // Our symbol vendor shouldn't be asking us to add a compile unit that
656 // has already been added to it, which this DWARF plug-in knows as it
657 // stores the lldb compile unit (CompileUnit) pointer in each
658 // DWARFCompileUnit object when it gets added.
Greg Clayton96d7d742010-11-10 23:42:09 +0000659 assert(curr_cu->GetUserData() == NULL);
660 ParseCompileUnit(curr_cu, comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661 }
662 }
663 return comp_unit;
664}
665
666static void
Greg Claytonea3e7d52011-10-08 00:49:15 +0000667AddRangesToBlock (Block& block,
668 DWARFDebugRanges::RangeList& ranges,
669 addr_t block_base_addr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670{
Greg Claytonea3e7d52011-10-08 00:49:15 +0000671 const size_t num_ranges = ranges.GetSize();
672 for (size_t i = 0; i<num_ranges; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673 {
Greg Claytonea3e7d52011-10-08 00:49:15 +0000674 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
675 const addr_t range_base = range.GetRangeBase();
676 assert (range_base >= block_base_addr);
677 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678 }
Greg Claytonea3e7d52011-10-08 00:49:15 +0000679 block.FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680}
681
682
683Function *
Greg Clayton0fffff52010-09-24 05:15:53 +0000684SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685{
686 DWARFDebugRanges::RangeList func_ranges;
687 const char *name = NULL;
688 const char *mangled = NULL;
689 int decl_file = 0;
690 int decl_line = 0;
691 int decl_column = 0;
692 int call_file = 0;
693 int call_line = 0;
694 int call_column = 0;
695 DWARFExpression frame_base;
696
Greg Claytonc93237c2010-10-01 20:48:32 +0000697 assert (die->Tag() == DW_TAG_subprogram);
698
699 if (die->Tag() != DW_TAG_subprogram)
700 return NULL;
701
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
703 {
704 // Union of all ranges in the function DIE (if the function is discontiguous)
705 AddressRange func_range;
Greg Claytonea3e7d52011-10-08 00:49:15 +0000706 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
707 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
709 {
710 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
711 if (func_range.GetBaseAddress().IsValid())
712 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
713 }
714
715 if (func_range.GetBaseAddress().IsValid())
716 {
717 Mangled func_name;
718 if (mangled)
719 func_name.SetValue(mangled, true);
720 else if (name)
721 func_name.SetValue(name, false);
722
723 FunctionSP func_sp;
724 std::auto_ptr<Declaration> decl_ap;
725 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Greg Claytond7e05462010-11-14 00:22:48 +0000726 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
727 decl_line,
728 decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000730 // Supply the type _only_ if it has already been parsed
Greg Clayton594e5ed2010-09-27 21:07:38 +0000731 Type *func_type = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732
733 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
734
735 func_range.GetBaseAddress().ResolveLinkedAddress();
736
Greg Clayton81c22f62011-10-19 18:09:39 +0000737 const user_id_t func_user_id = MakeUserID(die->GetOffset());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738 func_sp.reset(new Function (sc.comp_unit,
Greg Clayton81c22f62011-10-19 18:09:39 +0000739 func_user_id, // UserID is the DIE offset
740 func_user_id,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 func_name,
742 func_type,
743 func_range)); // first address range
744
745 if (func_sp.get() != NULL)
746 {
Greg Clayton0bd4e1b2011-09-30 20:52:25 +0000747 if (frame_base.IsValid())
748 func_sp->GetFrameBaseExpression() = frame_base;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749 sc.comp_unit->AddFunction(func_sp);
750 return func_sp.get();
751 }
752 }
753 }
754 return NULL;
755}
756
757size_t
758SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
759{
760 assert (sc.comp_unit);
761 size_t functions_added = 0;
Greg Clayton0fffff52010-09-24 05:15:53 +0000762 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 if (dwarf_cu)
764 {
765 DWARFDIECollection function_dies;
766 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
767 size_t func_idx;
768 for (func_idx = 0; func_idx < num_funtions; ++func_idx)
769 {
770 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +0000771 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772 {
773 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
774 ++functions_added;
775 }
776 }
777 //FixupTypes();
778 }
779 return functions_added;
780}
781
782bool
783SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
784{
785 assert (sc.comp_unit);
Greg Clayton96d7d742010-11-10 23:42:09 +0000786 DWARFCompileUnit* curr_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
787 assert (curr_cu);
788 const DWARFDebugInfoEntry * cu_die = curr_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789
790 if (cu_die)
791 {
Greg Clayton96d7d742010-11-10 23:42:09 +0000792 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, curr_cu, DW_AT_comp_dir, NULL);
793 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 +0000794
795 // All file indexes in DWARF are one based and a file of index zero is
796 // supposed to be the compile unit itself.
797 support_files.Append (*sc.comp_unit);
798
799 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
800 }
801 return false;
802}
803
804struct ParseDWARFLineTableCallbackInfo
805{
806 LineTable* line_table;
807 const SectionList *section_list;
808 lldb::addr_t prev_sect_file_base_addr;
809 lldb::addr_t curr_sect_file_base_addr;
810 bool is_oso_for_debug_map;
811 bool prev_in_final_executable;
812 DWARFDebugLine::Row prev_row;
813 SectionSP prev_section_sp;
814 SectionSP curr_section_sp;
815};
816
817//----------------------------------------------------------------------
818// ParseStatementTableCallback
819//----------------------------------------------------------------------
820static void
821ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
822{
823 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
824 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
825 {
826 // Just started parsing the line table
827 }
828 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
829 {
830 // Done parsing line table, nothing to do for the cleanup
831 }
832 else
833 {
834 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
835 // We have a new row, lets append it
836
837 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
838 {
839 info->prev_section_sp = info->curr_section_sp;
840 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
841 // If this is an end sequence entry, then we subtract one from the
842 // address to make sure we get an address that is not the end of
843 // a section.
844 if (state.end_sequence && state.address != 0)
845 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
846 else
847 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
848
849 if (info->curr_section_sp.get())
850 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
851 else
852 info->curr_sect_file_base_addr = 0;
853 }
854 if (info->curr_section_sp.get())
855 {
856 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
857 // Check for the fancy section magic to determine if we
858
859 if (info->is_oso_for_debug_map)
860 {
861 // When this is a debug map object file that contains DWARF
862 // (referenced from an N_OSO debug map nlist entry) we will have
863 // a file address in the file range for our section from the
864 // original .o file, and a load address in the executable that
865 // contains the debug map.
866 //
867 // If the sections for the file range and load range are
868 // different, we have a remapped section for the function and
869 // this address is resolved. If they are the same, then the
870 // function for this address didn't make it into the final
871 // executable.
872 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
873
874 // If we are doing DWARF with debug map, then we need to carefully
875 // add each line table entry as there may be gaps as functions
876 // get moved around or removed.
877 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
878 {
879 if (info->prev_in_final_executable)
880 {
881 bool terminate_previous_entry = false;
882 if (!curr_in_final_executable)
883 {
884 // Check for the case where the previous line entry
885 // in a function made it into the final executable,
886 // yet the current line entry falls in a function
887 // that didn't. The line table used to be contiguous
888 // through this address range but now it isn't. We
889 // need to terminate the previous line entry so
890 // that we can reconstruct the line range correctly
891 // for it and to keep the line table correct.
892 terminate_previous_entry = true;
893 }
894 else if (info->curr_section_sp.get() != info->prev_section_sp.get())
895 {
896 // Check for cases where the line entries used to be
897 // contiguous address ranges, but now they aren't.
898 // This can happen when order files specify the
899 // ordering of the functions.
900 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
901 Section *curr_sect = info->curr_section_sp.get();
902 Section *prev_sect = info->prev_section_sp.get();
903 assert (curr_sect->GetLinkedSection());
904 assert (prev_sect->GetLinkedSection());
905 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
906 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
907 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
908 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
909 if (object_file_addr_delta != linked_file_addr_delta)
910 terminate_previous_entry = true;
911 }
912
913 if (terminate_previous_entry)
914 {
915 line_table->InsertLineEntry (info->prev_section_sp,
916 state.address - info->prev_sect_file_base_addr,
917 info->prev_row.line,
918 info->prev_row.column,
919 info->prev_row.file,
920 false, // is_stmt
921 false, // basic_block
922 false, // state.prologue_end
923 false, // state.epilogue_begin
924 true); // end_sequence);
925 }
926 }
927 }
928
929 if (curr_in_final_executable)
930 {
931 line_table->InsertLineEntry (info->curr_section_sp,
932 curr_line_section_offset,
933 state.line,
934 state.column,
935 state.file,
936 state.is_stmt,
937 state.basic_block,
938 state.prologue_end,
939 state.epilogue_begin,
940 state.end_sequence);
941 info->prev_section_sp = info->curr_section_sp;
942 }
943 else
944 {
945 // If the current address didn't make it into the final
946 // executable, the current section will be the __text
947 // segment in the .o file, so we need to clear this so
948 // we can catch the next function that did make it into
949 // the final executable.
950 info->prev_section_sp.reset();
951 info->curr_section_sp.reset();
952 }
953
954 info->prev_in_final_executable = curr_in_final_executable;
955 }
956 else
957 {
958 // We are not in an object file that contains DWARF for an
959 // N_OSO, this is just a normal DWARF file. The DWARF spec
960 // guarantees that the addresses will be in increasing order
961 // so, since we store line tables in file address order, we
962 // can always just append the line entry without needing to
963 // search for the correct insertion point (we don't need to
964 // use LineEntry::InsertLineEntry()).
965 line_table->AppendLineEntry (info->curr_section_sp,
966 curr_line_section_offset,
967 state.line,
968 state.column,
969 state.file,
970 state.is_stmt,
971 state.basic_block,
972 state.prologue_end,
973 state.epilogue_begin,
974 state.end_sequence);
975 }
976 }
977
978 info->prev_row = state;
979 }
980}
981
982bool
983SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
984{
985 assert (sc.comp_unit);
986 if (sc.comp_unit->GetLineTable() != NULL)
987 return true;
988
989 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
990 if (dwarf_cu)
991 {
992 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
993 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
994 if (cu_line_offset != DW_INVALID_OFFSET)
995 {
996 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
997 if (line_table_ap.get())
998 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000999 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 +00001000 uint32_t offset = cu_line_offset;
1001 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1002 sc.comp_unit->SetLineTable(line_table_ap.release());
1003 return true;
1004 }
1005 }
1006 }
1007 return false;
1008}
1009
1010size_t
1011SymbolFileDWARF::ParseFunctionBlocks
1012(
1013 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001014 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001015 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016 const DWARFDebugInfoEntry *die,
1017 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001018 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019)
1020{
1021 size_t blocks_added = 0;
1022 while (die != NULL)
1023 {
1024 dw_tag_t tag = die->Tag();
1025
1026 switch (tag)
1027 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001028 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001029 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 case DW_TAG_lexical_block:
1031 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001032 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001033 if (tag == DW_TAG_subprogram)
1034 {
1035 // Skip any DW_TAG_subprogram DIEs that are inside
1036 // of a normal or inlined functions. These will be
1037 // parsed on their own as separate entities.
1038
1039 if (depth > 0)
1040 break;
1041
1042 block = parent_block;
1043 }
1044 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001045 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001046 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001047 parent_block->AddChild(block_sp);
1048 block = block_sp.get();
1049 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001050 DWARFDebugRanges::RangeList ranges;
1051 const char *name = NULL;
1052 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 int decl_file = 0;
1055 int decl_line = 0;
1056 int decl_column = 0;
1057 int call_file = 0;
1058 int call_line = 0;
1059 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001060 if (die->GetDIENamesAndRanges (this,
1061 dwarf_cu,
1062 name,
1063 mangled_name,
1064 ranges,
1065 decl_file, decl_line, decl_column,
1066 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001067 {
1068 if (tag == DW_TAG_subprogram)
1069 {
1070 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001071 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001073 else if (tag == DW_TAG_inlined_subroutine)
1074 {
1075 // We get called here for inlined subroutines in two ways.
1076 // The first time is when we are making the Function object
1077 // for this inlined concrete instance. Since we're creating a top level block at
1078 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1079 // adjust the containing address.
1080 // The second time is when we are parsing the blocks inside the function that contains
1081 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1082 // function the offset will be for that function.
1083 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1084 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001085 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001086 }
1087 }
1088
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001089 AddRangesToBlock (*block, ranges, subprogram_low_pc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001090
1091 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1092 {
1093 std::auto_ptr<Declaration> decl_ap;
1094 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001095 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1096 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097
1098 std::auto_ptr<Declaration> call_ap;
1099 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001100 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1101 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001103 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104 }
1105
1106 ++blocks_added;
1107
Greg Claytondd7feaf2011-08-12 17:54:33 +00001108 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001109 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001110 blocks_added += ParseFunctionBlocks (sc,
1111 block,
1112 dwarf_cu,
1113 die->GetFirstChild(),
1114 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001115 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116 }
1117 }
1118 }
1119 break;
1120 default:
1121 break;
1122 }
1123
Greg Claytondd7feaf2011-08-12 17:54:33 +00001124 // Only parse siblings of the block if we are not at depth zero. A depth
1125 // of zero indicates we are currently parsing the top level
1126 // DW_TAG_subprogram DIE
1127
1128 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001129 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001130 else
1131 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001132 }
1133 return blocks_added;
1134}
1135
Greg Claytonf0705c82011-10-22 03:33:13 +00001136bool
1137SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1138 const DWARFDebugInfoEntry *parent_die,
1139 ClangASTContext::TemplateParameterInfos &template_param_infos)
1140{
1141
1142 if (parent_die == NULL)
1143 return NULL;
1144
1145 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1146
1147 Args template_parameter_names;
1148 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1149 die != NULL;
1150 die = die->GetSibling())
1151 {
1152 const dw_tag_t tag = die->Tag();
1153
1154 switch (tag)
1155 {
1156 case DW_TAG_template_type_parameter:
1157 case DW_TAG_template_value_parameter:
1158 {
1159 DWARFDebugInfoEntry::Attributes attributes;
1160 const size_t num_attributes = die->GetAttributes (this,
1161 dwarf_cu,
1162 fixed_form_sizes,
1163 attributes);
1164 const char *name = NULL;
1165 Type *lldb_type = NULL;
1166 clang_type_t clang_type = NULL;
1167 uint64_t uval64 = 0;
1168 bool uval64_valid = false;
1169 if (num_attributes > 0)
1170 {
1171 DWARFFormValue form_value;
1172 for (size_t i=0; i<num_attributes; ++i)
1173 {
1174 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1175
1176 switch (attr)
1177 {
1178 case DW_AT_name:
1179 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1180 name = form_value.AsCString(&get_debug_str_data());
1181 break;
1182
1183 case DW_AT_type:
1184 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1185 {
1186 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1187 lldb_type = ResolveTypeUID(type_die_offset);
1188 if (lldb_type)
1189 clang_type = lldb_type->GetClangForwardType();
1190 }
1191 break;
1192
1193 case DW_AT_const_value:
1194 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1195 {
1196 uval64_valid = true;
1197 uval64 = form_value.Unsigned();
1198 }
1199 break;
1200 default:
1201 break;
1202 }
1203 }
1204
1205 if (name && lldb_type && clang_type)
1206 {
1207 bool is_signed = false;
1208 template_param_infos.names.push_back(name);
1209 clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1210 if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1211 {
1212 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1213 template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1214 }
1215 else
1216 {
1217 template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1218 }
1219 }
1220 else
1221 {
1222 return false;
1223 }
1224
1225 }
1226 }
1227 break;
1228
1229 default:
1230 break;
1231 }
1232 }
1233 if (template_param_infos.args.empty())
1234 return false;
1235 return template_param_infos.args.size() == template_param_infos.names.size();
1236}
1237
1238clang::ClassTemplateDecl *
1239SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001240 lldb::AccessType access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001241 const char *parent_name,
1242 int tag_decl_kind,
1243 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1244{
1245 if (template_param_infos.IsValid())
1246 {
1247 std::string template_basename(parent_name);
1248 template_basename.erase (template_basename.find('<'));
1249 ClangASTContext &ast = GetClangASTContext();
1250
1251 return ast.CreateClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00001252 access_type,
Greg Claytonf0705c82011-10-22 03:33:13 +00001253 template_basename.c_str(),
1254 tag_decl_kind,
1255 template_param_infos);
1256 }
1257 return NULL;
1258}
1259
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260size_t
1261SymbolFileDWARF::ParseChildMembers
1262(
1263 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00001264 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265 const DWARFDebugInfoEntry *parent_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00001266 clang_type_t class_clang_type,
Greg Clayton9e409562010-07-28 02:04:09 +00001267 const LanguageType class_language,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1269 std::vector<int>& member_accessibilities,
Greg Claytonc93237c2010-10-01 20:48:32 +00001270 DWARFDIECollection& member_function_dies,
Sean Callananc7fbf732010-08-06 00:32:49 +00001271 AccessType& default_accessibility,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272 bool &is_a_class
1273)
1274{
1275 if (parent_die == NULL)
1276 return 0;
1277
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 size_t count = 0;
1279 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00001280 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001281 uint32_t member_idx = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00001282
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1284 {
1285 dw_tag_t tag = die->Tag();
1286
1287 switch (tag)
1288 {
1289 case DW_TAG_member:
1290 {
1291 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001292 const size_t num_attributes = die->GetAttributes (this,
1293 dwarf_cu,
1294 fixed_form_sizes,
1295 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 if (num_attributes > 0)
1297 {
1298 Declaration decl;
Greg Clayton73b472d2010-10-27 03:32:59 +00001299 //DWARFExpression location;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 const char *name = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00001301 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001303 AccessType accessibility = eAccessNone;
Greg Clayton73b472d2010-10-27 03:32:59 +00001304 //off_t member_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001305 size_t byte_size = 0;
1306 size_t bit_offset = 0;
1307 size_t bit_size = 0;
1308 uint32_t i;
Greg Clayton24739922010-10-13 03:15:28 +00001309 for (i=0; i<num_attributes && !is_artificial; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 {
1311 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1312 DWARFFormValue form_value;
1313 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1314 {
1315 switch (attr)
1316 {
1317 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1318 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1319 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1320 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1321 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1322 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1323 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1324 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1325 case DW_AT_data_member_location:
Greg Clayton73b472d2010-10-27 03:32:59 +00001326// if (form_value.BlockData())
1327// {
1328// Value initialValue(0);
1329// Value memberOffset(0);
1330// const DataExtractor& debug_info_data = get_debug_info_data();
1331// uint32_t block_length = form_value.Unsigned();
1332// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1333// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1334// {
1335// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1336// }
1337// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001338 break;
1339
Greg Clayton8cf05932010-07-22 18:30:50 +00001340 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
Greg Clayton24739922010-10-13 03:15:28 +00001341 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 case DW_AT_declaration:
1343 case DW_AT_description:
1344 case DW_AT_mutable:
1345 case DW_AT_visibility:
1346 default:
1347 case DW_AT_sibling:
1348 break;
1349 }
1350 }
1351 }
Sean Callanan5a477cf2010-10-30 01:56:10 +00001352
Greg Clayton44953932011-10-25 01:25:35 +00001353 // Clang has a DWARF generation bug where sometimes it
1354 // represents fields that are references with bad byte size
1355 // and bit size/offset information such as:
1356 //
1357 // DW_AT_byte_size( 0x00 )
1358 // DW_AT_bit_size( 0x40 )
1359 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1360 //
1361 // So check the bit offset to make sure it is sane, and if
1362 // the values are not sane, remove them. If we don't do this
1363 // then we will end up with a crash if we try to use this
1364 // type in an expression when clang becomes unhappy with its
1365 // recycled debug info.
Sean Callanan5a477cf2010-10-30 01:56:10 +00001366
Greg Clayton44953932011-10-25 01:25:35 +00001367 if (bit_offset > 128)
1368 {
1369 bit_size = 0;
1370 bit_offset = 0;
1371 }
1372
1373 // FIXME: Make Clang ignore Objective-C accessibility for expressions
Sean Callanan5a477cf2010-10-30 01:56:10 +00001374 if (class_language == eLanguageTypeObjC ||
1375 class_language == eLanguageTypeObjC_plus_plus)
1376 accessibility = eAccessNone;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001377
1378 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1379 {
1380 // Not all compilers will mark the vtable pointer
1381 // member as artificial (llvm-gcc). We can't have
1382 // the virtual members in our classes otherwise it
1383 // throws off all child offsets since we end up
1384 // having and extra pointer sized member in our
1385 // class layouts.
1386 is_artificial = true;
1387 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388
Greg Clayton24739922010-10-13 03:15:28 +00001389 if (is_artificial == false)
1390 {
1391 Type *member_type = ResolveTypeUID(encoding_uid);
Greg Claytond16e1e52011-07-12 17:06:17 +00001392 if (member_type)
1393 {
1394 if (accessibility == eAccessNone)
1395 accessibility = default_accessibility;
1396 member_accessibilities.push_back(accessibility);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397
Greg Claytond16e1e52011-07-12 17:06:17 +00001398 GetClangASTContext().AddFieldToRecordType (class_clang_type,
1399 name,
1400 member_type->GetClangLayoutType(),
1401 accessibility,
1402 bit_size);
1403 }
1404 else
1405 {
1406 if (name)
Greg Clayton81c22f62011-10-19 18:09:39 +00001407 ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1408 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001409 name,
1410 encoding_uid);
1411 else
Greg Clayton81c22f62011-10-19 18:09:39 +00001412 ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1413 MakeUserID(die->GetOffset()),
Greg Claytond16e1e52011-07-12 17:06:17 +00001414 encoding_uid);
1415 }
Greg Clayton24739922010-10-13 03:15:28 +00001416 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417 }
Greg Clayton6beaaa62011-01-17 03:46:26 +00001418 ++member_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 }
1420 break;
1421
1422 case DW_TAG_subprogram:
Greg Claytonc93237c2010-10-01 20:48:32 +00001423 // Let the type parsing code handle this one for us.
1424 member_function_dies.Append (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 break;
1426
1427 case DW_TAG_inheritance:
1428 {
1429 is_a_class = true;
Sean Callananc7fbf732010-08-06 00:32:49 +00001430 if (default_accessibility == eAccessNone)
1431 default_accessibility = eAccessPrivate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001432 // TODO: implement DW_TAG_inheritance type parsing
1433 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonba2d22d2010-11-13 22:57:37 +00001434 const size_t num_attributes = die->GetAttributes (this,
1435 dwarf_cu,
1436 fixed_form_sizes,
1437 attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438 if (num_attributes > 0)
1439 {
1440 Declaration decl;
1441 DWARFExpression location;
1442 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
Sean Callananc7fbf732010-08-06 00:32:49 +00001443 AccessType accessibility = default_accessibility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 bool is_virtual = false;
1445 bool is_base_of_class = true;
1446 off_t member_offset = 0;
1447 uint32_t i;
1448 for (i=0; i<num_attributes; ++i)
1449 {
1450 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1451 DWARFFormValue form_value;
1452 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1453 {
1454 switch (attr)
1455 {
1456 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1457 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1458 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1459 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1460 case DW_AT_data_member_location:
1461 if (form_value.BlockData())
1462 {
1463 Value initialValue(0);
1464 Value memberOffset(0);
1465 const DataExtractor& debug_info_data = get_debug_info_data();
1466 uint32_t block_length = form_value.Unsigned();
1467 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
Greg Claytonba2d22d2010-11-13 22:57:37 +00001468 if (DWARFExpression::Evaluate (NULL,
1469 NULL,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001470 NULL,
1471 NULL,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001472 NULL,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001473 debug_info_data,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001474 block_offset,
1475 block_length,
1476 eRegisterKindDWARF,
1477 &initialValue,
1478 memberOffset,
1479 NULL))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480 {
1481 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1482 }
1483 }
1484 break;
1485
1486 case DW_AT_accessibility:
Greg Clayton8cf05932010-07-22 18:30:50 +00001487 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 break;
1489
1490 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1491 default:
1492 case DW_AT_sibling:
1493 break;
1494 }
1495 }
1496 }
1497
Greg Clayton526e5af2010-11-13 03:52:47 +00001498 Type *base_class_type = ResolveTypeUID(encoding_uid);
1499 assert(base_class_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001500
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001501 clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1502 assert (base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001503 if (class_language == eLanguageTypeObjC)
1504 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001505 GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
Greg Clayton9e409562010-07-28 02:04:09 +00001506 }
1507 else
1508 {
Greg Claytonf4ecaa52011-02-16 23:00:21 +00001509 base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
Greg Claytonba2d22d2010-11-13 22:57:37 +00001510 accessibility,
1511 is_virtual,
1512 is_base_of_class));
Greg Clayton9e409562010-07-28 02:04:09 +00001513 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001514 }
1515 }
1516 break;
1517
1518 default:
1519 break;
1520 }
1521 }
1522 return count;
1523}
1524
1525
1526clang::DeclContext*
Sean Callanan72e49402011-08-05 23:43:37 +00001527SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001528{
1529 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton81c22f62011-10-19 18:09:39 +00001530 if (debug_info && UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001531 {
1532 DWARFCompileUnitSP cu_sp;
1533 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1534 if (die)
Greg Claytoncb5860a2011-10-13 23:49:28 +00001535 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Sean Callanan72e49402011-08-05 23:43:37 +00001536 }
1537 return NULL;
1538}
1539
1540clang::DeclContext*
1541SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1542{
Greg Clayton81c22f62011-10-19 18:09:39 +00001543 if (UserIDMatches(type_uid))
1544 return GetClangDeclContextForDIEOffset (sc, type_uid);
1545 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001546}
1547
1548Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001549SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001550{
Greg Clayton81c22f62011-10-19 18:09:39 +00001551 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001552 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001553 DWARFDebugInfo* debug_info = DebugInfo();
1554 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001555 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001556 DWARFCompileUnitSP cu_sp;
1557 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1558 if (type_die != NULL)
Greg Claytonca512b32011-01-14 04:54:56 +00001559 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001560 // We might be coming in in the middle of a type tree (a class
1561 // withing a class, an enum within a class), so parse any needed
1562 // parent DIEs before we get to this one...
1563 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu_sp.get(), type_die);
1564 switch (decl_ctx_die->Tag())
1565 {
1566 case DW_TAG_structure_type:
1567 case DW_TAG_union_type:
1568 case DW_TAG_class_type:
1569 ResolveType(cu_sp.get(), decl_ctx_die);
1570 break;
1571 }
1572 return ResolveType (cu_sp.get(), type_die);
Greg Claytonca512b32011-01-14 04:54:56 +00001573 }
Greg Claytonca512b32011-01-14 04:54:56 +00001574 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575 }
1576 return NULL;
1577}
1578
Greg Clayton6beaaa62011-01-17 03:46:26 +00001579// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1580// SymbolFileDWARF objects to detect if this DWARF file is the one that
1581// can resolve a clang_type.
1582bool
1583SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1584{
1585 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1586 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1587 return die != NULL;
1588}
1589
1590
Greg Clayton1be10fc2010-09-29 01:12:09 +00001591lldb::clang_type_t
1592SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1593{
1594 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001595 clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1596 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001597 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001598 {
1599 // We have already resolved this type...
1600 return clang_type;
1601 }
1602 // Once we start resolving this type, remove it from the forward declaration
1603 // map in case anyone child members or other types require this type to get resolved.
1604 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1605 // are done.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001606 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
Greg Clayton73b472d2010-10-27 03:32:59 +00001607
Greg Clayton1be10fc2010-09-29 01:12:09 +00001608
Greg Clayton85ae2e12011-10-18 23:36:41 +00001609 // Disable external storage for this type so we don't get anymore
1610 // clang::ExternalASTSource queries for this type.
1611 ClangASTContext::SetHasExternalStorage (clang_type, false);
1612
Greg Clayton450e3f32010-10-12 02:24:53 +00001613 DWARFDebugInfo* debug_info = DebugInfo();
1614
Greg Clayton96d7d742010-11-10 23:42:09 +00001615 DWARFCompileUnit *curr_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001616 Type *type = m_die_to_type.lookup (die);
1617
1618 const dw_tag_t tag = die->Tag();
1619
Greg Clayton81c22f62011-10-19 18:09:39 +00001620 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") - resolve forward declaration...\n",
1621 MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001622 DW_TAG_value_to_name(tag),
1623 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001624 assert (clang_type);
1625 DWARFDebugInfoEntry::Attributes attributes;
1626
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001627 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001628
1629 switch (tag)
1630 {
1631 case DW_TAG_structure_type:
1632 case DW_TAG_union_type:
1633 case DW_TAG_class_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001634 ast.StartTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001635 if (die->HasChildren())
1636 {
1637 LanguageType class_language = eLanguageTypeUnknown;
Greg Clayton450e3f32010-10-12 02:24:53 +00001638 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1639 if (is_objc_class)
Greg Claytonc93237c2010-10-01 20:48:32 +00001640 class_language = eLanguageTypeObjC;
1641
1642 int tag_decl_kind = -1;
1643 AccessType default_accessibility = eAccessNone;
1644 if (tag == DW_TAG_structure_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001645 {
Greg Claytonc93237c2010-10-01 20:48:32 +00001646 tag_decl_kind = clang::TTK_Struct;
1647 default_accessibility = eAccessPublic;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001648 }
Greg Claytonc93237c2010-10-01 20:48:32 +00001649 else if (tag == DW_TAG_union_type)
1650 {
1651 tag_decl_kind = clang::TTK_Union;
1652 default_accessibility = eAccessPublic;
1653 }
1654 else if (tag == DW_TAG_class_type)
1655 {
1656 tag_decl_kind = clang::TTK_Class;
1657 default_accessibility = eAccessPrivate;
1658 }
1659
Greg Clayton96d7d742010-11-10 23:42:09 +00001660 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
Greg Claytonc93237c2010-10-01 20:48:32 +00001661 std::vector<clang::CXXBaseSpecifier *> base_classes;
1662 std::vector<int> member_accessibilities;
1663 bool is_a_class = false;
1664 // Parse members and base classes first
1665 DWARFDIECollection member_function_dies;
1666
1667 ParseChildMembers (sc,
Greg Clayton96d7d742010-11-10 23:42:09 +00001668 curr_cu,
Greg Claytonc93237c2010-10-01 20:48:32 +00001669 die,
1670 clang_type,
1671 class_language,
1672 base_classes,
1673 member_accessibilities,
1674 member_function_dies,
1675 default_accessibility,
1676 is_a_class);
1677
1678 // Now parse any methods if there were any...
1679 size_t num_functions = member_function_dies.Size();
1680 if (num_functions > 0)
1681 {
1682 for (size_t i=0; i<num_functions; ++i)
1683 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001684 ResolveType(curr_cu, member_function_dies.GetDIEPtrAtIndex(i));
Greg Claytonc93237c2010-10-01 20:48:32 +00001685 }
1686 }
1687
Greg Clayton450e3f32010-10-12 02:24:53 +00001688 if (class_language == eLanguageTypeObjC)
1689 {
Greg Claytone3055942011-06-30 02:28:26 +00001690 std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(clang_type));
Greg Clayton450e3f32010-10-12 02:24:53 +00001691 if (!class_str.empty())
1692 {
1693
1694 ConstString class_name (class_str.c_str());
Greg Claytond4a2b372011-09-12 23:21:58 +00001695 DIEArray method_die_offsets;
1696 if (m_objc_class_selectors_index.Find (class_name, method_die_offsets))
Greg Clayton450e3f32010-10-12 02:24:53 +00001697 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001698 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton450e3f32010-10-12 02:24:53 +00001699
Greg Claytond4a2b372011-09-12 23:21:58 +00001700 DWARFCompileUnit* method_cu = NULL;
1701 const size_t num_matches = method_die_offsets.size();
1702 for (size_t i=0; i<num_matches; ++i)
1703 {
1704 const dw_offset_t die_offset = method_die_offsets[i];
1705 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
Greg Clayton450e3f32010-10-12 02:24:53 +00001706
1707 ResolveType (method_cu, method_die);
1708 }
1709 }
1710 }
1711 }
1712
Greg Claytonc93237c2010-10-01 20:48:32 +00001713 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1714 // need to tell the clang type it is actually a class.
1715 if (class_language != eLanguageTypeObjC)
1716 {
1717 if (is_a_class && tag_decl_kind != clang::TTK_Class)
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001718 ast.SetTagTypeKind (clang_type, clang::TTK_Class);
Greg Claytonc93237c2010-10-01 20:48:32 +00001719 }
1720
1721 // Since DW_TAG_structure_type gets used for both classes
1722 // and structures, we may need to set any DW_TAG_member
1723 // fields to have a "private" access if none was specified.
1724 // When we parsed the child members we tracked that actual
1725 // accessibility value for each DW_TAG_member in the
1726 // "member_accessibilities" array. If the value for the
1727 // member is zero, then it was set to the "default_accessibility"
1728 // which for structs was "public". Below we correct this
1729 // by setting any fields to "private" that weren't correctly
1730 // set.
1731 if (is_a_class && !member_accessibilities.empty())
1732 {
1733 // This is a class and all members that didn't have
1734 // their access specified are private.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001735 ast.SetDefaultAccessForRecordFields (clang_type,
1736 eAccessPrivate,
1737 &member_accessibilities.front(),
1738 member_accessibilities.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001739 }
1740
1741 if (!base_classes.empty())
1742 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001743 ast.SetBaseClassesForClassType (clang_type,
1744 &base_classes.front(),
1745 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001746
1747 // Clang will copy each CXXBaseSpecifier in "base_classes"
1748 // so we have to free them all.
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001749 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
1750 base_classes.size());
Greg Claytonc93237c2010-10-01 20:48:32 +00001751 }
1752
1753 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001754 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Claytonc93237c2010-10-01 20:48:32 +00001755 return clang_type;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001756
1757 case DW_TAG_enumeration_type:
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001758 ast.StartTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001759 if (die->HasChildren())
1760 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001761 SymbolContext sc(GetCompUnitForDWARFCompUnit(curr_cu));
1762 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), curr_cu, die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001763 }
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001764 ast.CompleteTagDeclarationDefinition (clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001765 return clang_type;
1766
1767 default:
1768 assert(false && "not a forward clang type decl!");
1769 break;
1770 }
1771 return NULL;
1772}
1773
Greg Claytonc685f8e2010-09-15 04:15:46 +00001774Type*
Greg Clayton96d7d742010-11-10 23:42:09 +00001775SymbolFileDWARF::ResolveType (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001776{
1777 if (type_die != NULL)
1778 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001779 Type *type = m_die_to_type.lookup (type_die);
Greg Claytonc685f8e2010-09-15 04:15:46 +00001780 if (type == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001781 type = GetTypeForDIE (curr_cu, type_die).get();
Greg Clayton24739922010-10-13 03:15:28 +00001782 if (assert_not_being_parsed)
1783 assert (type != DIE_IS_BEING_PARSED);
Greg Clayton594e5ed2010-09-27 21:07:38 +00001784 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001785 }
1786 return NULL;
1787}
1788
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001789CompileUnit*
Greg Clayton96d7d742010-11-10 23:42:09 +00001790SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* curr_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791{
1792 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001793 if (curr_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794 {
1795 // The symbol vendor doesn't know about this compile unit, we
1796 // need to parse and add it to the symbol vendor object.
1797 CompUnitSP dc_cu;
Greg Clayton96d7d742010-11-10 23:42:09 +00001798 ParseCompileUnit(curr_cu, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001799 if (dc_cu.get())
1800 {
1801 // Figure out the compile unit index if we weren't given one
Greg Clayton016a95e2010-09-14 02:20:48 +00001802 if (cu_idx == UINT32_MAX)
Greg Clayton96d7d742010-11-10 23:42:09 +00001803 DebugInfo()->GetCompileUnit(curr_cu->GetOffset(), &cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804
1805 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
Greg Clayton450e3f32010-10-12 02:24:53 +00001806
1807 if (m_debug_map_symfile)
1808 m_debug_map_symfile->SetCompileUnit(this, dc_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809 }
1810 }
Greg Clayton96d7d742010-11-10 23:42:09 +00001811 return (CompileUnit*)curr_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812}
1813
1814bool
Greg Clayton96d7d742010-11-10 23:42:09 +00001815SymbolFileDWARF::GetFunction (DWARFCompileUnit* curr_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816{
1817 sc.Clear();
1818 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton96d7d742010-11-10 23:42:09 +00001819 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820
Greg Clayton81c22f62011-10-19 18:09:39 +00001821 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001822 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001823 sc.function = ParseCompileUnitFunction(sc, curr_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00001824
1825 if (sc.function)
1826 {
1827 sc.module_sp = sc.function->CalculateSymbolContextModule();
1828 return true;
1829 }
1830
1831 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001832}
1833
1834uint32_t
1835SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1836{
1837 Timer scoped_timer(__PRETTY_FUNCTION__,
1838 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1839 so_addr.GetSection(),
1840 so_addr.GetOffset(),
1841 resolve_scope);
1842 uint32_t resolved = 0;
1843 if (resolve_scope & ( eSymbolContextCompUnit |
1844 eSymbolContextFunction |
1845 eSymbolContextBlock |
1846 eSymbolContextLineEntry))
1847 {
1848 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1849
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001850 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001851 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852 {
Greg Claytond4a2b372011-09-12 23:21:58 +00001853 dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854 if (cu_offset != DW_INVALID_OFFSET)
1855 {
1856 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001857 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1858 if (curr_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001860 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 assert(sc.comp_unit != NULL);
1862 resolved |= eSymbolContextCompUnit;
1863
1864 if (resolve_scope & eSymbolContextLineEntry)
1865 {
1866 LineTable *line_table = sc.comp_unit->GetLineTable();
1867 if (line_table == NULL)
1868 {
1869 if (ParseCompileUnitLineTable(sc))
1870 line_table = sc.comp_unit->GetLineTable();
1871 }
1872 if (line_table != NULL)
1873 {
1874 if (so_addr.IsLinkedAddress())
1875 {
1876 Address linked_addr (so_addr);
1877 linked_addr.ResolveLinkedAddress();
1878 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1879 {
1880 resolved |= eSymbolContextLineEntry;
1881 }
1882 }
1883 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1884 {
1885 resolved |= eSymbolContextLineEntry;
1886 }
1887 }
1888 }
1889
1890 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1891 {
1892 DWARFDebugInfoEntry *function_die = NULL;
1893 DWARFDebugInfoEntry *block_die = NULL;
1894 if (resolve_scope & eSymbolContextBlock)
1895 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001896 curr_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897 }
1898 else
1899 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001900 curr_cu->LookupAddress(file_vm_addr, &function_die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901 }
1902
1903 if (function_die != NULL)
1904 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001905 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00001907 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001908 }
1909
1910 if (sc.function != NULL)
1911 {
1912 resolved |= eSymbolContextFunction;
1913
1914 if (resolve_scope & eSymbolContextBlock)
1915 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001916 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917
1918 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00001919 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 else
Greg Clayton81c22f62011-10-19 18:09:39 +00001921 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 if (sc.block)
1923 resolved |= eSymbolContextBlock;
1924 }
1925 }
1926 }
1927 }
1928 }
1929 }
1930 }
1931 return resolved;
1932}
1933
1934
1935
1936uint32_t
1937SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1938{
1939 const uint32_t prev_size = sc_list.GetSize();
1940 if (resolve_scope & eSymbolContextCompUnit)
1941 {
1942 DWARFDebugInfo* debug_info = DebugInfo();
1943 if (debug_info)
1944 {
1945 uint32_t cu_idx;
Greg Clayton96d7d742010-11-10 23:42:09 +00001946 DWARFCompileUnit* curr_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947
Greg Clayton96d7d742010-11-10 23:42:09 +00001948 for (cu_idx = 0; (curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949 {
Greg Clayton96d7d742010-11-10 23:42:09 +00001950 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001951 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1952 if (check_inlines || file_spec_matches_cu_file_spec)
1953 {
1954 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton96d7d742010-11-10 23:42:09 +00001955 sc.comp_unit = GetCompUnitForDWARFCompUnit(curr_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956 assert(sc.comp_unit != NULL);
1957
1958 uint32_t file_idx = UINT32_MAX;
1959
1960 // If we are looking for inline functions only and we don't
1961 // find it in the support files, we are done.
1962 if (check_inlines)
1963 {
Jim Ingham87df91b2011-09-23 00:54:11 +00001964 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965 if (file_idx == UINT32_MAX)
1966 continue;
1967 }
1968
1969 if (line != 0)
1970 {
1971 LineTable *line_table = sc.comp_unit->GetLineTable();
1972
1973 if (line_table != NULL && line != 0)
1974 {
1975 // We will have already looked up the file index if
1976 // we are searching for inline entries.
1977 if (!check_inlines)
Jim Ingham87df91b2011-09-23 00:54:11 +00001978 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001979
1980 if (file_idx != UINT32_MAX)
1981 {
1982 uint32_t found_line;
1983 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1984 found_line = sc.line_entry.line;
1985
Greg Clayton016a95e2010-09-14 02:20:48 +00001986 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987 {
1988 sc.function = NULL;
1989 sc.block = NULL;
1990 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1991 {
1992 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1993 if (file_vm_addr != LLDB_INVALID_ADDRESS)
1994 {
1995 DWARFDebugInfoEntry *function_die = NULL;
1996 DWARFDebugInfoEntry *block_die = NULL;
Greg Clayton96d7d742010-11-10 23:42:09 +00001997 curr_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001998
1999 if (function_die != NULL)
2000 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002001 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002 if (sc.function == NULL)
Greg Clayton96d7d742010-11-10 23:42:09 +00002003 sc.function = ParseCompileUnitFunction(sc, curr_cu, function_die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 }
2005
2006 if (sc.function != NULL)
2007 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00002008 Block& block = sc.function->GetBlock (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002009
2010 if (block_die != NULL)
Greg Clayton81c22f62011-10-19 18:09:39 +00002011 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012 else
Greg Clayton81c22f62011-10-19 18:09:39 +00002013 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 }
2015 }
2016 }
2017
2018 sc_list.Append(sc);
2019 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2020 }
2021 }
2022 }
2023 else if (file_spec_matches_cu_file_spec && !check_inlines)
2024 {
2025 // only append the context if we aren't looking for inline call sites
2026 // by file and line and if the file spec matches that of the compile unit
2027 sc_list.Append(sc);
2028 }
2029 }
2030 else if (file_spec_matches_cu_file_spec && !check_inlines)
2031 {
2032 // only append the context if we aren't looking for inline call sites
2033 // by file and line and if the file spec matches that of the compile unit
2034 sc_list.Append(sc);
2035 }
2036
2037 if (!check_inlines)
2038 break;
2039 }
2040 }
2041 }
2042 }
2043 return sc_list.GetSize() - prev_size;
2044}
2045
2046void
2047SymbolFileDWARF::Index ()
2048{
2049 if (m_indexed)
2050 return;
2051 m_indexed = true;
2052 Timer scoped_timer (__PRETTY_FUNCTION__,
2053 "SymbolFileDWARF::Index (%s)",
2054 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2055
2056 DWARFDebugInfo* debug_info = DebugInfo();
2057 if (debug_info)
2058 {
2059 uint32_t cu_idx = 0;
2060 const uint32_t num_compile_units = GetNumCompileUnits();
2061 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2062 {
Greg Clayton96d7d742010-11-10 23:42:09 +00002063 DWARFCompileUnit* curr_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002064
Greg Clayton96d7d742010-11-10 23:42:09 +00002065 bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066
Greg Clayton96d7d742010-11-10 23:42:09 +00002067 curr_cu->Index (cu_idx,
Greg Clayton83c5cd92010-11-14 22:13:40 +00002068 m_function_basename_index,
2069 m_function_fullname_index,
2070 m_function_method_index,
2071 m_function_selector_index,
2072 m_objc_class_selectors_index,
2073 m_global_index,
2074 m_type_index,
Greg Claytond4a2b372011-09-12 23:21:58 +00002075 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002076
2077 // Keep memory down by clearing DIEs if this generate function
2078 // caused them to be parsed
2079 if (clear_dies)
Greg Clayton96d7d742010-11-10 23:42:09 +00002080 curr_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002081 }
2082
Greg Claytond4a2b372011-09-12 23:21:58 +00002083 m_function_basename_index.Finalize();
2084 m_function_fullname_index.Finalize();
2085 m_function_method_index.Finalize();
2086 m_function_selector_index.Finalize();
2087 m_objc_class_selectors_index.Finalize();
2088 m_global_index.Finalize();
2089 m_type_index.Finalize();
2090 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002091
Greg Clayton24739922010-10-13 03:15:28 +00002092#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002093 StreamFile s(stdout, false);
Greg Claytonf9eec202011-09-01 23:16:13 +00002094 s.Printf ("DWARF index for '%s/%s':",
Greg Clayton24739922010-10-13 03:15:28 +00002095 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2096 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002097 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2098 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2099 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2100 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2101 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2102 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002103 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Greg Claytonba2d22d2010-11-13 22:57:37 +00002104 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002105#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002106 }
2107}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002108
2109bool
2110SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2111{
2112 if (namespace_decl == NULL)
2113 {
2114 // Invalid namespace decl which means we aren't matching only things
2115 // in this symbol file, so return true to indicate it matches this
2116 // symbol file.
2117 return true;
2118 }
2119
2120 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2121
2122 if (namespace_ast == NULL)
2123 return true; // No AST in the "namespace_decl", return true since it
2124 // could then match any symbol file, including this one
2125
2126 if (namespace_ast == GetClangASTContext().getASTContext())
2127 return true; // The ASTs match, return true
2128
2129 // The namespace AST was valid, and it does not match...
Sean Callananc41e68b2011-10-13 21:08:11 +00002130 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2131
2132 if (log)
2133 log->Printf("Valid namespace does not match symbol file");
2134
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002135 return false;
2136}
2137
Greg Clayton2506a7a2011-10-12 23:34:26 +00002138bool
2139SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2140 DWARFCompileUnit* cu,
2141 const DWARFDebugInfoEntry* die)
2142{
2143 // No namespace specified, so the answesr i
2144 if (namespace_decl == NULL)
2145 return true;
Sean Callananebe60672011-10-13 21:50:33 +00002146
2147 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002148
Greg Clayton2506a7a2011-10-12 23:34:26 +00002149 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2150 if (decl_ctx_die)
2151 {
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002152
Greg Clayton2506a7a2011-10-12 23:34:26 +00002153 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2154 if (clang_namespace_decl)
2155 {
2156 if (decl_ctx_die->Tag() != DW_TAG_namespace)
Sean Callananebe60672011-10-13 21:50:33 +00002157 {
2158 if (log)
2159 log->Printf("Found a match, but its parent is not a namespace");
Greg Clayton2506a7a2011-10-12 23:34:26 +00002160 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002161 }
2162
Greg Clayton2506a7a2011-10-12 23:34:26 +00002163 DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2164
2165 if (pos == m_decl_ctx_to_die.end())
Sean Callananebe60672011-10-13 21:50:33 +00002166 {
2167 if (log)
2168 log->Printf("Found a match in a namespace, but its parent is not the requested namespace");
2169
Greg Clayton2506a7a2011-10-12 23:34:26 +00002170 return false;
Sean Callananebe60672011-10-13 21:50:33 +00002171 }
Greg Clayton2506a7a2011-10-12 23:34:26 +00002172
Greg Claytoncb5860a2011-10-13 23:49:28 +00002173 return pos->second.count (decl_ctx_die);
Greg Clayton2506a7a2011-10-12 23:34:26 +00002174 }
2175 else
2176 {
2177 // We have a namespace_decl that was not NULL but it contained
2178 // a NULL "clang::NamespaceDecl", so this means the global namespace
2179 // So as long the the contained decl context DIE isn't a namespace
2180 // we should be ok.
2181 if (decl_ctx_die->Tag() != DW_TAG_namespace)
2182 return true;
2183 }
2184 }
Sean Callananebe60672011-10-13 21:50:33 +00002185
2186 if (log)
2187 log->Printf("Found a match, but its parent doesn't exist");
2188
Greg Clayton2506a7a2011-10-12 23:34:26 +00002189 return false;
2190}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002191uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002192SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002193{
Greg Clayton21f2a492011-10-06 00:09:08 +00002194 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2195
2196 if (log)
2197 {
2198 log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", name=\"%s\", append=%u, max_matches=%u, variables)",
2199 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2200 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2201 name.GetCString(), append, max_matches);
2202 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002203
2204 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2205 return 0;
2206
Greg Claytonc685f8e2010-09-15 04:15:46 +00002207 DWARFDebugInfo* info = DebugInfo();
2208 if (info == NULL)
2209 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002210
2211 // If we aren't appending the results to this list, then clear the list
2212 if (!append)
2213 variables.Clear();
2214
2215 // Remember how many variables are in the list before we search in case
2216 // we are appending the results to a variable list.
2217 const uint32_t original_size = variables.GetSize();
2218
Greg Claytond4a2b372011-09-12 23:21:58 +00002219 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002220
Greg Clayton97fbc342011-10-20 22:30:33 +00002221 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002222 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002223 if (m_apple_names_ap.get())
2224 {
2225 const char *name_cstr = name.GetCString();
2226 const char *base_name_start;
2227 const char *base_name_end = NULL;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002228
Greg Clayton97fbc342011-10-20 22:30:33 +00002229 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2230 base_name_start = name_cstr;
2231
2232 m_apple_names_ap->FindByName (base_name_start, die_offsets);
2233 }
Greg Clayton7f995132011-10-04 22:41:51 +00002234 }
2235 else
2236 {
2237 // Index the DWARF if we haven't already
2238 if (!m_indexed)
2239 Index ();
2240
2241 m_global_index.Find (name, die_offsets);
2242 }
2243
2244 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002245 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002246 {
Greg Clayton7f995132011-10-04 22:41:51 +00002247 SymbolContext sc;
2248 sc.module_sp = m_obj_file->GetModule();
2249 assert (sc.module_sp);
2250
Greg Claytond4a2b372011-09-12 23:21:58 +00002251 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002252 DWARFCompileUnit* dwarf_cu = NULL;
2253 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002254 for (size_t i=0; i<num_matches; ++i)
2255 {
2256 const dw_offset_t die_offset = die_offsets[i];
2257 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002258
Greg Claytond4a2b372011-09-12 23:21:58 +00002259 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2260 assert(sc.comp_unit != NULL);
Sean Callanan213fdb82011-10-13 01:49:10 +00002261
2262 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2263 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002264
Greg Claytond4a2b372011-09-12 23:21:58 +00002265 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002266
Greg Claytond4a2b372011-09-12 23:21:58 +00002267 if (variables.GetSize() - original_size >= max_matches)
2268 break;
2269 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002270 }
2271
2272 // Return the number of variable that were appended to the list
2273 return variables.GetSize() - original_size;
2274}
2275
2276uint32_t
2277SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2278{
Greg Clayton21f2a492011-10-06 00:09:08 +00002279 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2280
2281 if (log)
2282 {
2283 log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", regex=\"%s\", append=%u, max_matches=%u, variables)",
2284 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2285 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2286 regex.GetText(), append, max_matches);
2287 }
2288
Greg Claytonc685f8e2010-09-15 04:15:46 +00002289 DWARFDebugInfo* info = DebugInfo();
2290 if (info == NULL)
2291 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002292
2293 // If we aren't appending the results to this list, then clear the list
2294 if (!append)
2295 variables.Clear();
2296
2297 // Remember how many variables are in the list before we search in case
2298 // we are appending the results to a variable list.
2299 const uint32_t original_size = variables.GetSize();
2300
Greg Clayton7f995132011-10-04 22:41:51 +00002301 DIEArray die_offsets;
2302
Greg Clayton97fbc342011-10-20 22:30:33 +00002303 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002304 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002305 if (m_apple_names_ap.get())
2306 m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00002307 }
2308 else
2309 {
2310 // Index the DWARF if we haven't already
2311 if (!m_indexed)
2312 Index ();
2313
2314 m_global_index.Find (regex, die_offsets);
2315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002316
Greg Claytonc685f8e2010-09-15 04:15:46 +00002317 SymbolContext sc;
Greg Claytona2eee182011-09-17 07:23:18 +00002318 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002319 assert (sc.module_sp);
2320
Greg Claytond4a2b372011-09-12 23:21:58 +00002321 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002322 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002323 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002324 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002325 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002326 DWARFDebugInfo* debug_info = DebugInfo();
2327 for (size_t i=0; i<num_matches; ++i)
2328 {
2329 const dw_offset_t die_offset = die_offsets[i];
2330 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2331 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002332
Greg Claytond4a2b372011-09-12 23:21:58 +00002333 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002334
Greg Claytond4a2b372011-09-12 23:21:58 +00002335 if (variables.GetSize() - original_size >= max_matches)
2336 break;
2337 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002338 }
2339
2340 // Return the number of variable that were appended to the list
2341 return variables.GetSize() - original_size;
2342}
2343
Greg Claytonaa044962011-10-13 00:59:38 +00002344
Jim Ingham4cda6e02011-10-07 22:23:45 +00002345bool
2346SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2347 DWARFCompileUnit *&dwarf_cu,
2348 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002349{
Greg Claytonaa044962011-10-13 00:59:38 +00002350 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2351 return ResolveFunction (dwarf_cu, die, sc_list);
2352}
2353
2354
2355bool
2356SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2357 const DWARFDebugInfoEntry *die,
2358 SymbolContextList& sc_list)
2359{
Greg Clayton9e315582011-09-02 04:03:59 +00002360 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002361
2362 if (die == NULL)
2363 return false;
2364
Jim Ingham4cda6e02011-10-07 22:23:45 +00002365 // If we were passed a die that is not a function, just return false...
2366 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2367 return false;
2368
2369 const DWARFDebugInfoEntry* inlined_die = NULL;
2370 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002371 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002372 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002373
Jim Ingham4cda6e02011-10-07 22:23:45 +00002374 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002375 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002376 if (die->Tag() == DW_TAG_subprogram)
2377 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002378 }
2379 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002380 assert (die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002381 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002382 {
2383 Address addr;
2384 // Parse all blocks if needed
2385 if (inlined_die)
2386 {
Greg Clayton81c22f62011-10-19 18:09:39 +00002387 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
Jim Ingham4cda6e02011-10-07 22:23:45 +00002388 assert (sc.block != NULL);
2389 if (sc.block->GetStartAddress (addr) == false)
2390 addr.Clear();
2391 }
2392 else
2393 {
2394 sc.block = NULL;
2395 addr = sc.function->GetAddressRange().GetBaseAddress();
2396 }
2397
2398 if (addr.IsValid())
2399 {
2400
2401 // We found the function, so we should find the line table
2402 // and line table entry as well
2403 LineTable *line_table = sc.comp_unit->GetLineTable();
2404 if (line_table == NULL)
2405 {
2406 if (ParseCompileUnitLineTable(sc))
2407 line_table = sc.comp_unit->GetLineTable();
2408 }
2409 if (line_table != NULL)
2410 line_table->FindLineEntryByAddress (addr, sc.line_entry);
2411
2412 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002413 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002414 }
2415 }
2416
Greg Claytonaa044962011-10-13 00:59:38 +00002417 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002418}
2419
Greg Clayton7f995132011-10-04 22:41:51 +00002420void
2421SymbolFileDWARF::FindFunctions (const ConstString &name,
2422 const NameToDIE &name_to_die,
2423 SymbolContextList& sc_list)
2424{
Greg Claytond4a2b372011-09-12 23:21:58 +00002425 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002426 if (name_to_die.Find (name, die_offsets))
2427 {
2428 ParseFunctions (die_offsets, sc_list);
2429 }
2430}
2431
2432
2433void
2434SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2435 const NameToDIE &name_to_die,
2436 SymbolContextList& sc_list)
2437{
2438 DIEArray die_offsets;
2439 if (name_to_die.Find (regex, die_offsets))
2440 {
2441 ParseFunctions (die_offsets, sc_list);
2442 }
2443}
2444
2445
2446void
2447SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2448 const DWARFMappedHash::MemoryTable &memory_table,
2449 SymbolContextList& sc_list)
2450{
2451 DIEArray die_offsets;
2452 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, die_offsets))
2453 {
2454 ParseFunctions (die_offsets, sc_list);
2455 }
2456}
2457
2458void
2459SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2460 SymbolContextList& sc_list)
2461{
2462 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002463 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002464 {
Greg Clayton7f995132011-10-04 22:41:51 +00002465 SymbolContext sc;
Greg Clayton7f995132011-10-04 22:41:51 +00002466
2467 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002468 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002469 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002470 const dw_offset_t die_offset = die_offsets[i];
Jim Ingham4cda6e02011-10-07 22:23:45 +00002471 ResolveFunction (die_offset, dwarf_cu, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002472 }
2473 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002474}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002475
Jim Ingham4cda6e02011-10-07 22:23:45 +00002476bool
2477SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2478 const DWARFCompileUnit *dwarf_cu,
2479 uint32_t name_type_mask,
2480 const char *partial_name,
2481 const char *base_name_start,
2482 const char *base_name_end)
2483{
2484 // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2485 if (name_type_mask == eFunctionNameTypeMethod
2486 || name_type_mask == eFunctionNameTypeBase)
2487 {
Greg Claytonf0705c82011-10-22 03:33:13 +00002488 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2489 if (!containing_decl_ctx)
2490 return false;
2491
2492 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2493
2494 if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2495 return false;
2496 if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2497 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002498 }
2499
2500 // Now we need to check whether the name we got back for this type matches the extra specifications
2501 // that were in the name we're looking up:
2502 if (base_name_start != partial_name || *base_name_end != '\0')
2503 {
2504 // First see if the stuff to the left matches the full name. To do that let's see if
2505 // we can pull out the mips linkage name attribute:
2506
2507 Mangled best_name;
2508
2509 DWARFDebugInfoEntry::Attributes attributes;
2510 die->GetAttributes(this, dwarf_cu, NULL, attributes);
2511 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2512 if (idx != UINT32_MAX)
2513 {
2514 DWARFFormValue form_value;
2515 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2516 {
2517 const char *name = form_value.AsCString(&get_debug_str_data());
2518 best_name.SetValue (name, true);
2519 }
2520 }
2521 if (best_name)
2522 {
2523 const char *demangled = best_name.GetDemangledName().GetCString();
2524 if (demangled)
2525 {
2526 std::string name_no_parens(partial_name, base_name_end - partial_name);
2527 if (strstr (demangled, name_no_parens.c_str()) == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002528 return false;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002529 }
2530 }
2531 }
2532
2533 return true;
2534}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002535
Greg Clayton0c5cd902010-06-28 21:30:43 +00002536uint32_t
Greg Clayton2bc22f82011-09-30 03:20:47 +00002537SymbolFileDWARF::FindFunctions (const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +00002538 const lldb_private::ClangNamespaceDecl *namespace_decl,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002539 uint32_t name_type_mask,
2540 bool append,
2541 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002542{
2543 Timer scoped_timer (__PRETTY_FUNCTION__,
2544 "SymbolFileDWARF::FindFunctions (name = '%s')",
2545 name.AsCString());
2546
Greg Clayton21f2a492011-10-06 00:09:08 +00002547 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2548
2549 if (log)
2550 {
2551 log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2552 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2553 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2554 name.GetCString(), name_type_mask, append);
2555 }
2556
Greg Clayton0c5cd902010-06-28 21:30:43 +00002557 // If we aren't appending the results to this list, then clear the list
2558 if (!append)
2559 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002560
2561 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2562 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002563
2564 // If name is empty then we won't find anything.
2565 if (name.IsEmpty())
2566 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002567
2568 // Remember how many sc_list are in the list before we search in case
2569 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002570
Greg Clayton9e315582011-09-02 04:03:59 +00002571 const uint32_t original_size = sc_list.GetSize();
Greg Clayton0c5cd902010-06-28 21:30:43 +00002572
Jim Ingham4cda6e02011-10-07 22:23:45 +00002573 const char *name_cstr = name.GetCString();
2574 uint32_t effective_name_type_mask = eFunctionNameTypeNone;
2575 const char *base_name_start = name_cstr;
2576 const char *base_name_end = name_cstr + strlen(name_cstr);
2577
2578 if (name_type_mask & eFunctionNameTypeAuto)
2579 {
2580 if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
2581 effective_name_type_mask = eFunctionNameTypeFull;
2582 else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
2583 effective_name_type_mask = eFunctionNameTypeFull;
2584 else
2585 {
2586 if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2587 effective_name_type_mask |= eFunctionNameTypeSelector;
2588
2589 if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2590 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
2591 }
2592 }
2593 else
2594 {
2595 effective_name_type_mask = name_type_mask;
2596 if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
2597 {
2598 // If they've asked for a CPP method or function name and it can't be that, we don't
2599 // even need to search for CPP methods or names.
2600 if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
2601 {
2602 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
2603 if (effective_name_type_mask == eFunctionNameTypeNone)
2604 return 0;
2605 }
2606 }
2607
2608 if (effective_name_type_mask & eFunctionNameTypeSelector)
2609 {
2610 if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
2611 {
2612 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
2613 if (effective_name_type_mask == eFunctionNameTypeNone)
2614 return 0;
2615 }
2616 }
2617 }
2618
2619 DWARFDebugInfo* info = DebugInfo();
2620 if (info == NULL)
2621 return 0;
2622
Greg Claytonaa044962011-10-13 00:59:38 +00002623 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton97fbc342011-10-20 22:30:33 +00002624 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002625 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002626 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002627 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002628
2629 DIEArray die_offsets;
2630
2631 uint32_t num_matches = 0;
2632
2633 if (effective_name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002634 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002635 // If they asked for the full name, match what they typed. At some point we may
2636 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2637 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002638 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002639 for (uint32_t i = 0; i < num_matches; i++)
2640 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002641 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002642 if (die)
2643 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002644 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2645 continue;
2646
Greg Claytonaa044962011-10-13 00:59:38 +00002647 ResolveFunction (dwarf_cu, die, sc_list);
2648 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002649 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002650 }
2651 else
2652 {
2653 if (effective_name_type_mask & eFunctionNameTypeSelector)
2654 {
2655 if (namespace_decl && *namespace_decl)
2656 return 0; // no selectors in namespaces
2657
2658 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2659 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2660 // and if it is an ObjC method name, we're good.
2661
2662 for (uint32_t i = 0; i < num_matches; i++)
2663 {
2664 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2665 if (die)
2666 {
2667 const char *die_name = die->GetName(this, dwarf_cu);
2668 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
2669 ResolveFunction (dwarf_cu, die, sc_list);
2670 }
2671 }
2672 die_offsets.clear();
2673 }
2674
2675 if (effective_name_type_mask & eFunctionNameTypeMethod
2676 || effective_name_type_mask & eFunctionNameTypeBase)
2677 {
2678 if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
2679 (namespace_decl && *namespace_decl))
2680 return 0; // no methods in namespaces
2681
2682 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2683 // extract the base name, look that up, and if there is any other information in the name we were
2684 // passed in we have to post-filter based on that.
2685
2686 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2687 std::string base_name(base_name_start, base_name_end - base_name_start);
2688 num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
2689
2690 for (uint32_t i = 0; i < num_matches; i++)
2691 {
2692 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2693 if (die)
2694 {
2695 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2696 continue;
2697
2698 if (!FunctionDieMatchesPartialName(die,
2699 dwarf_cu,
2700 effective_name_type_mask,
2701 name_cstr,
2702 base_name_start,
2703 base_name_end))
2704 continue;
2705
2706 // If we get to here, the die is good, and we should add it:
2707 ResolveFunction (dwarf_cu, die, sc_list);
2708 }
2709 }
2710 die_offsets.clear();
2711 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002712 }
2713 }
Greg Clayton7f995132011-10-04 22:41:51 +00002714 }
2715 else
2716 {
2717
2718 // Index the DWARF if we haven't already
2719 if (!m_indexed)
2720 Index ();
2721
Greg Clayton7f995132011-10-04 22:41:51 +00002722 if (name_type_mask & eFunctionNameTypeFull)
2723 FindFunctions (name, m_function_fullname_index, sc_list);
2724
Jim Ingham4cda6e02011-10-07 22:23:45 +00002725 std::string base_name(base_name_start, base_name_end - base_name_start);
2726 ConstString base_name_const(base_name.c_str());
2727 DIEArray die_offsets;
2728 DWARFCompileUnit *dwarf_cu = NULL;
2729
2730 if (effective_name_type_mask & eFunctionNameTypeBase)
2731 {
2732 uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002733 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002734 {
Greg Claytonaa044962011-10-13 00:59:38 +00002735 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2736 if (die)
2737 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002738 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2739 continue;
2740
Greg Claytonaa044962011-10-13 00:59:38 +00002741 if (!FunctionDieMatchesPartialName(die,
2742 dwarf_cu,
2743 effective_name_type_mask,
2744 name_cstr,
2745 base_name_start,
2746 base_name_end))
2747 continue;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002748
Greg Claytonaa044962011-10-13 00:59:38 +00002749 // If we get to here, the die is good, and we should add it:
2750 ResolveFunction (dwarf_cu, die, sc_list);
2751 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002752 }
2753 die_offsets.clear();
2754 }
2755
Jim Inghamea8005a2011-10-11 01:18:11 +00002756 if (effective_name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002757 {
Sean Callanan213fdb82011-10-13 01:49:10 +00002758 if (namespace_decl && *namespace_decl)
2759 return 0; // no methods in namespaces
2760
Jim Ingham4cda6e02011-10-07 22:23:45 +00002761 uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
2762 {
Greg Claytonaa044962011-10-13 00:59:38 +00002763 for (uint32_t i = 0; i < num_base; i++)
2764 {
2765 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2766 if (die)
2767 {
2768 if (!FunctionDieMatchesPartialName(die,
2769 dwarf_cu,
2770 effective_name_type_mask,
2771 name_cstr,
2772 base_name_start,
2773 base_name_end))
2774 continue;
2775
2776 // If we get to here, the die is good, and we should add it:
2777 ResolveFunction (dwarf_cu, die, sc_list);
2778 }
2779 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002780 }
2781 die_offsets.clear();
2782 }
Greg Clayton7f995132011-10-04 22:41:51 +00002783
Sean Callanan213fdb82011-10-13 01:49:10 +00002784 if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002785 {
Greg Clayton7f995132011-10-04 22:41:51 +00002786 FindFunctions (name, m_function_selector_index, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002787 }
2788
Greg Clayton4d01ace2011-09-29 16:58:15 +00002789 }
2790
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002791 // Return the number of variable that were appended to the list
2792 return sc_list.GetSize() - original_size;
2793}
2794
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002795uint32_t
2796SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
2797{
2798 Timer scoped_timer (__PRETTY_FUNCTION__,
2799 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2800 regex.GetText());
2801
Greg Clayton21f2a492011-10-06 00:09:08 +00002802 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2803
2804 if (log)
2805 {
2806 log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", regex=\"%s\"append=%u, sc_list)",
2807 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2808 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2809 regex.GetText(), append);
2810 }
2811
2812
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002813 // If we aren't appending the results to this list, then clear the list
2814 if (!append)
2815 sc_list.Clear();
2816
2817 // Remember how many sc_list are in the list before we search in case
2818 // we are appending the results to a variable list.
2819 uint32_t original_size = sc_list.GetSize();
2820
Greg Clayton97fbc342011-10-20 22:30:33 +00002821 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002822 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002823 if (m_apple_names_ap.get())
2824 FindFunctions (regex, *m_apple_names_ap, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002825 }
2826 else
2827 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002828 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002829 if (!m_indexed)
2830 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002831
Greg Clayton7f995132011-10-04 22:41:51 +00002832 FindFunctions (regex, m_function_basename_index, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002833
Greg Clayton7f995132011-10-04 22:41:51 +00002834 FindFunctions (regex, m_function_fullname_index, sc_list);
2835 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836
2837 // Return the number of variable that were appended to the list
2838 return sc_list.GetSize() - original_size;
2839}
Jim Ingham318c9f22011-08-26 19:44:13 +00002840
Greg Claytond16e1e52011-07-12 17:06:17 +00002841void
2842SymbolFileDWARF::ReportError (const char *format, ...)
2843{
2844 ::fprintf (stderr,
2845 "error: %s/%s ",
2846 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2847 m_obj_file->GetFileSpec().GetFilename().GetCString());
2848
Greg Claytoncfebbcf2011-10-01 01:37:20 +00002849 if (m_obj_file->GetModule()->GetObjectName())
2850 ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
2851
Greg Claytond16e1e52011-07-12 17:06:17 +00002852 va_list args;
2853 va_start (args, format);
2854 vfprintf (stderr, format, args);
2855 va_end (args);
2856}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002857
Jim Inghamc1663042011-09-29 22:12:35 +00002858void
2859SymbolFileDWARF::ReportWarning (const char *format, ...)
2860{
2861 ::fprintf (stderr,
2862 "warning: %s/%s ",
2863 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2864 m_obj_file->GetFileSpec().GetFilename().GetCString());
2865
Greg Claytoncfebbcf2011-10-01 01:37:20 +00002866 if (m_obj_file->GetModule()->GetObjectName())
2867 ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
2868
Jim Inghamc1663042011-09-29 22:12:35 +00002869 va_list args;
2870 va_start (args, format);
2871 vfprintf (stderr, format, args);
2872 va_end (args);
2873}
2874
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002875uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +00002876SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002877{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002878 DWARFDebugInfo* info = DebugInfo();
2879 if (info == NULL)
2880 return 0;
2881
Greg Clayton21f2a492011-10-06 00:09:08 +00002882 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2883
2884 if (log)
2885 {
Sean Callananc41e68b2011-10-13 21:08:11 +00002886 log->Printf ("SymbolFileDWARF::FindTypes (file=\"%s/%s\", sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
Greg Clayton21f2a492011-10-06 00:09:08 +00002887 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2888 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2889 name.GetCString(), append, max_matches);
2890 }
2891
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002892 // If we aren't appending the results to this list, then clear the list
2893 if (!append)
2894 types.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002895
2896 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2897 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002898
Greg Claytond4a2b372011-09-12 23:21:58 +00002899 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002900
Greg Clayton97fbc342011-10-20 22:30:33 +00002901 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002902 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002903 if (m_apple_types_ap.get())
2904 {
2905 const char *name_cstr = name.GetCString();
2906 m_apple_types_ap->FindByName (name_cstr, die_offsets);
2907 }
Greg Clayton7f995132011-10-04 22:41:51 +00002908 }
2909 else
2910 {
2911 if (!m_indexed)
2912 Index ();
2913
2914 m_type_index.Find (name, die_offsets);
2915 }
2916
2917
2918 const size_t num_matches = die_offsets.size();
2919
Greg Claytond4a2b372011-09-12 23:21:58 +00002920 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002921 {
Greg Clayton7f995132011-10-04 22:41:51 +00002922 const uint32_t initial_types_size = types.GetSize();
2923 DWARFCompileUnit* dwarf_cu = NULL;
2924 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002925 DWARFDebugInfo* debug_info = DebugInfo();
2926 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002927 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002928 const dw_offset_t die_offset = die_offsets[i];
2929 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2930
Sean Callanan213fdb82011-10-13 01:49:10 +00002931 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2932 continue;
2933
Greg Claytond4a2b372011-09-12 23:21:58 +00002934 Type *matching_type = ResolveType (dwarf_cu, die);
2935 if (matching_type)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002936 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002937 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton85ae2e12011-10-18 23:36:41 +00002938 types.InsertUnique (TypeSP (matching_type));
2939 if (types.GetSize() >= max_matches)
2940 break;
Greg Clayton73bf5db2011-06-17 01:22:15 +00002941 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002942 }
Greg Clayton7f995132011-10-04 22:41:51 +00002943 return types.GetSize() - initial_types_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002944 }
Greg Clayton7f995132011-10-04 22:41:51 +00002945 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002946}
2947
2948
Greg Clayton526e5af2010-11-13 03:52:47 +00002949ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00002950SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00002951 const ConstString &name,
2952 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00002953{
Greg Clayton21f2a492011-10-06 00:09:08 +00002954 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2955
2956 if (log)
2957 {
2958 log->Printf ("SymbolFileDWARF::FindNamespace (file=\"%s/%s\", sc, name=\"%s\")",
2959 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
2960 m_obj_file->GetFileSpec().GetFilename().GetCString(),
2961 name.GetCString());
2962 }
Sean Callanan213fdb82011-10-13 01:49:10 +00002963
2964 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
2965 return ClangNamespaceDecl();
Greg Clayton21f2a492011-10-06 00:09:08 +00002966
Greg Clayton526e5af2010-11-13 03:52:47 +00002967 ClangNamespaceDecl namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00002968 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002969 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002970 {
Greg Clayton7f995132011-10-04 22:41:51 +00002971 DIEArray die_offsets;
2972
Greg Clayton526e5af2010-11-13 03:52:47 +00002973 // Index if we already haven't to make sure the compile units
2974 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00002975 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002976 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002977 if (m_apple_namespaces_ap.get())
2978 {
2979 const char *name_cstr = name.GetCString();
2980 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
2981 }
Greg Clayton7f995132011-10-04 22:41:51 +00002982 }
2983 else
2984 {
2985 if (!m_indexed)
2986 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002987
Greg Clayton7f995132011-10-04 22:41:51 +00002988 m_namespace_index.Find (name, die_offsets);
2989 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002990
2991 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00002992 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002993 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002994 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00002995 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002996 DWARFDebugInfo* debug_info = DebugInfo();
2997 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00002998 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002999 const dw_offset_t die_offset = die_offsets[i];
3000 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003001
3002 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3003 continue;
Greg Claytond4a2b372011-09-12 23:21:58 +00003004
3005 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3006 if (clang_namespace_decl)
3007 {
3008 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3009 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
3010 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003011 }
3012 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003013 }
Greg Clayton526e5af2010-11-13 03:52:47 +00003014 return namespace_decl;
Greg Clayton96d7d742010-11-10 23:42:09 +00003015}
3016
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003017uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003018SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003019{
3020 // Remember how many sc_list are in the list before we search in case
3021 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003022 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023
3024 const uint32_t num_die_offsets = die_offsets.size();
3025 // Parse all of the types we found from the pubtypes matches
3026 uint32_t i;
3027 uint32_t num_matches = 0;
3028 for (i = 0; i < num_die_offsets; ++i)
3029 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003030 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3031 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003032 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003033 // We found a type pointer, now find the shared pointer form our type list
Greg Clayton85ae2e12011-10-18 23:36:41 +00003034 types.InsertUnique (TypeSP (matching_type));
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003035 ++num_matches;
3036 if (num_matches >= max_matches)
3037 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003038 }
3039 }
3040
3041 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003042 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003043}
3044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003045
3046size_t
Greg Clayton5113dc82011-08-12 06:47:54 +00003047SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3048 clang::DeclContext *containing_decl_ctx,
3049 TypeSP& type_sp,
3050 DWARFCompileUnit* dwarf_cu,
3051 const DWARFDebugInfoEntry *parent_die,
3052 bool skip_artificial,
3053 bool &is_static,
3054 TypeList* type_list,
3055 std::vector<clang_type_t>& function_param_types,
3056 std::vector<clang::ParmVarDecl*>& function_param_decls,
3057 unsigned &type_quals)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003058{
3059 if (parent_die == NULL)
3060 return 0;
3061
Greg Claytond88d7592010-09-15 08:33:30 +00003062 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3063
Greg Clayton7fedea22010-11-16 02:10:54 +00003064 size_t arg_idx = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003065 const DWARFDebugInfoEntry *die;
3066 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3067 {
3068 dw_tag_t tag = die->Tag();
3069 switch (tag)
3070 {
3071 case DW_TAG_formal_parameter:
3072 {
3073 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003074 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003075 if (num_attributes > 0)
3076 {
3077 const char *name = NULL;
3078 Declaration decl;
3079 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003080 bool is_artificial = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003081 // one of None, Auto, Register, Extern, Static, PrivateExtern
3082
Sean Callanane2ef6e32010-09-23 03:01:22 +00003083 clang::StorageClass storage = clang::SC_None;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003084 uint32_t i;
3085 for (i=0; i<num_attributes; ++i)
3086 {
3087 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3088 DWARFFormValue form_value;
3089 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3090 {
3091 switch (attr)
3092 {
3093 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3094 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3095 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3096 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
3097 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Claytona51ed9b2010-09-23 01:09:21 +00003098 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003099 case DW_AT_location:
3100 // if (form_value.BlockData())
3101 // {
3102 // const DataExtractor& debug_info_data = debug_info();
3103 // uint32_t block_length = form_value.Unsigned();
3104 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3105 // }
3106 // else
3107 // {
3108 // }
3109 // break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003110 case DW_AT_const_value:
3111 case DW_AT_default_value:
3112 case DW_AT_description:
3113 case DW_AT_endianity:
3114 case DW_AT_is_optional:
3115 case DW_AT_segment:
3116 case DW_AT_variable_parameter:
3117 default:
3118 case DW_AT_abstract_origin:
3119 case DW_AT_sibling:
3120 break;
3121 }
3122 }
3123 }
Greg Claytona51ed9b2010-09-23 01:09:21 +00003124
Greg Clayton0fffff52010-09-24 05:15:53 +00003125 bool skip = false;
3126 if (skip_artificial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003127 {
Greg Clayton0fffff52010-09-24 05:15:53 +00003128 if (is_artificial)
Greg Clayton7fedea22010-11-16 02:10:54 +00003129 {
3130 // In order to determine if a C++ member function is
3131 // "const" we have to look at the const-ness of "this"...
3132 // Ugly, but that
3133 if (arg_idx == 0)
3134 {
Greg Claytonf0705c82011-10-22 03:33:13 +00003135 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
Sean Callanan763d72a2011-08-02 22:21:50 +00003136 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003137 // Often times compilers omit the "this" name for the
3138 // specification DIEs, so we can't rely upon the name
3139 // being in the formal parameter DIE...
3140 if (name == NULL || ::strcmp(name, "this")==0)
Greg Clayton7fedea22010-11-16 02:10:54 +00003141 {
Greg Clayton5113dc82011-08-12 06:47:54 +00003142 Type *this_type = ResolveTypeUID (param_type_die_offset);
3143 if (this_type)
3144 {
3145 uint32_t encoding_mask = this_type->GetEncodingMask();
3146 if (encoding_mask & Type::eEncodingIsPointerUID)
3147 {
3148 is_static = false;
3149
3150 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3151 type_quals |= clang::Qualifiers::Const;
3152 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3153 type_quals |= clang::Qualifiers::Volatile;
Greg Clayton7fedea22010-11-16 02:10:54 +00003154 }
3155 }
3156 }
3157 }
3158 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003159 skip = true;
Greg Clayton7fedea22010-11-16 02:10:54 +00003160 }
Greg Clayton0fffff52010-09-24 05:15:53 +00003161 else
3162 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003163
Greg Clayton0fffff52010-09-24 05:15:53 +00003164 // HACK: Objective C formal parameters "self" and "_cmd"
3165 // are not marked as artificial in the DWARF...
Greg Clayton96d7d742010-11-10 23:42:09 +00003166 CompileUnit *curr_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3167 if (curr_cu && (curr_cu->GetLanguage() == eLanguageTypeObjC || curr_cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
Greg Clayton0fffff52010-09-24 05:15:53 +00003168 {
3169 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3170 skip = true;
3171 }
3172 }
3173 }
3174
3175 if (!skip)
3176 {
3177 Type *type = ResolveTypeUID(param_type_die_offset);
3178 if (type)
3179 {
Greg Claytonc93237c2010-10-01 20:48:32 +00003180 function_param_types.push_back (type->GetClangForwardType());
Greg Clayton0fffff52010-09-24 05:15:53 +00003181
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003182 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
Greg Clayton0fffff52010-09-24 05:15:53 +00003183 assert(param_var_decl);
3184 function_param_decls.push_back(param_var_decl);
3185 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003186 }
3187 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003188 arg_idx++;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003189 }
3190 break;
3191
3192 default:
3193 break;
3194 }
3195 }
Greg Clayton7fedea22010-11-16 02:10:54 +00003196 return arg_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003197}
3198
3199size_t
3200SymbolFileDWARF::ParseChildEnumerators
3201(
3202 const SymbolContext& sc,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003203 clang_type_t enumerator_clang_type,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003204 uint32_t enumerator_byte_size,
Greg Clayton0fffff52010-09-24 05:15:53 +00003205 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003206 const DWARFDebugInfoEntry *parent_die
3207)
3208{
3209 if (parent_die == NULL)
3210 return 0;
3211
3212 size_t enumerators_added = 0;
3213 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003214 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3215
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003216 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3217 {
3218 const dw_tag_t tag = die->Tag();
3219 if (tag == DW_TAG_enumerator)
3220 {
3221 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003222 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003223 if (num_child_attributes > 0)
3224 {
3225 const char *name = NULL;
3226 bool got_value = false;
3227 int64_t enum_value = 0;
3228 Declaration decl;
3229
3230 uint32_t i;
3231 for (i=0; i<num_child_attributes; ++i)
3232 {
3233 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3234 DWARFFormValue form_value;
3235 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3236 {
3237 switch (attr)
3238 {
3239 case DW_AT_const_value:
3240 got_value = true;
3241 enum_value = form_value.Unsigned();
3242 break;
3243
3244 case DW_AT_name:
3245 name = form_value.AsCString(&get_debug_str_data());
3246 break;
3247
3248 case DW_AT_description:
3249 default:
3250 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3251 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3252 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3253 case DW_AT_sibling:
3254 break;
3255 }
3256 }
3257 }
3258
3259 if (name && name[0] && got_value)
3260 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003261 GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3262 enumerator_clang_type,
3263 decl,
3264 name,
3265 enum_value,
3266 enumerator_byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003267 ++enumerators_added;
3268 }
3269 }
3270 }
3271 }
3272 return enumerators_added;
3273}
3274
3275void
3276SymbolFileDWARF::ParseChildArrayInfo
3277(
3278 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003279 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003280 const DWARFDebugInfoEntry *parent_die,
3281 int64_t& first_index,
3282 std::vector<uint64_t>& element_orders,
3283 uint32_t& byte_stride,
3284 uint32_t& bit_stride
3285)
3286{
3287 if (parent_die == NULL)
3288 return;
3289
3290 const DWARFDebugInfoEntry *die;
Greg Claytond88d7592010-09-15 08:33:30 +00003291 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003292 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3293 {
3294 const dw_tag_t tag = die->Tag();
3295 switch (tag)
3296 {
3297 case DW_TAG_enumerator:
3298 {
3299 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003300 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003301 if (num_child_attributes > 0)
3302 {
3303 const char *name = NULL;
3304 bool got_value = false;
3305 int64_t enum_value = 0;
3306
3307 uint32_t i;
3308 for (i=0; i<num_child_attributes; ++i)
3309 {
3310 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3311 DWARFFormValue form_value;
3312 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3313 {
3314 switch (attr)
3315 {
3316 case DW_AT_const_value:
3317 got_value = true;
3318 enum_value = form_value.Unsigned();
3319 break;
3320
3321 case DW_AT_name:
3322 name = form_value.AsCString(&get_debug_str_data());
3323 break;
3324
3325 case DW_AT_description:
3326 default:
3327 case DW_AT_decl_file:
3328 case DW_AT_decl_line:
3329 case DW_AT_decl_column:
3330 case DW_AT_sibling:
3331 break;
3332 }
3333 }
3334 }
3335 }
3336 }
3337 break;
3338
3339 case DW_TAG_subrange_type:
3340 {
3341 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytond88d7592010-09-15 08:33:30 +00003342 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003343 if (num_child_attributes > 0)
3344 {
3345 const char *name = NULL;
3346 bool got_value = false;
3347 uint64_t byte_size = 0;
3348 int64_t enum_value = 0;
3349 uint64_t num_elements = 0;
3350 uint64_t lower_bound = 0;
3351 uint64_t upper_bound = 0;
3352 uint32_t i;
3353 for (i=0; i<num_child_attributes; ++i)
3354 {
3355 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3356 DWARFFormValue form_value;
3357 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3358 {
3359 switch (attr)
3360 {
3361 case DW_AT_const_value:
3362 got_value = true;
3363 enum_value = form_value.Unsigned();
3364 break;
3365
3366 case DW_AT_name:
3367 name = form_value.AsCString(&get_debug_str_data());
3368 break;
3369
3370 case DW_AT_count:
3371 num_elements = form_value.Unsigned();
3372 break;
3373
3374 case DW_AT_bit_stride:
3375 bit_stride = form_value.Unsigned();
3376 break;
3377
3378 case DW_AT_byte_stride:
3379 byte_stride = form_value.Unsigned();
3380 break;
3381
3382 case DW_AT_byte_size:
3383 byte_size = form_value.Unsigned();
3384 break;
3385
3386 case DW_AT_lower_bound:
3387 lower_bound = form_value.Unsigned();
3388 break;
3389
3390 case DW_AT_upper_bound:
3391 upper_bound = form_value.Unsigned();
3392 break;
3393
3394 default:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003395 case DW_AT_abstract_origin:
3396 case DW_AT_accessibility:
3397 case DW_AT_allocated:
3398 case DW_AT_associated:
3399 case DW_AT_data_location:
3400 case DW_AT_declaration:
3401 case DW_AT_description:
3402 case DW_AT_sibling:
3403 case DW_AT_threads_scaled:
3404 case DW_AT_type:
3405 case DW_AT_visibility:
3406 break;
3407 }
3408 }
3409 }
3410
3411 if (upper_bound > lower_bound)
3412 num_elements = upper_bound - lower_bound + 1;
3413
3414 if (num_elements > 0)
3415 element_orders.push_back (num_elements);
3416 }
3417 }
3418 break;
3419 }
3420 }
3421}
3422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003423TypeSP
Greg Clayton96d7d742010-11-10 23:42:09 +00003424SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003425{
3426 TypeSP type_sp;
3427 if (die != NULL)
3428 {
Greg Clayton96d7d742010-11-10 23:42:09 +00003429 assert(curr_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003430 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003431 if (type_ptr == NULL)
3432 {
Greg Claytonca512b32011-01-14 04:54:56 +00003433 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(curr_cu);
3434 assert (lldb_cu);
3435 SymbolContext sc(lldb_cu);
Greg Clayton96d7d742010-11-10 23:42:09 +00003436 type_sp = ParseType(sc, curr_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003437 }
3438 else if (type_ptr != DIE_IS_BEING_PARSED)
3439 {
3440 // Grab the existing type from the master types lists
Greg Clayton85ae2e12011-10-18 23:36:41 +00003441 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003442 }
3443
3444 }
3445 return type_sp;
3446}
3447
3448clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003449SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003450{
3451 if (die_offset != DW_INVALID_OFFSET)
3452 {
3453 DWARFCompileUnitSP cu_sp;
3454 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003455 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003456 }
3457 return NULL;
3458}
3459
Sean Callanan72e49402011-08-05 23:43:37 +00003460clang::DeclContext *
3461SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
3462{
3463 if (die_offset != DW_INVALID_OFFSET)
3464 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00003465 DWARFDebugInfo* debug_info = DebugInfo();
3466 if (debug_info)
3467 {
3468 DWARFCompileUnitSP cu_sp;
3469 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
3470 if (die)
3471 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
3472 }
Sean Callanan72e49402011-08-05 23:43:37 +00003473 }
3474 return NULL;
3475}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003476
Greg Clayton96d7d742010-11-10 23:42:09 +00003477clang::NamespaceDecl *
3478SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3479{
Greg Clayton030a2042011-10-14 21:34:45 +00003480 if (die && die->Tag() == DW_TAG_namespace)
Greg Clayton96d7d742010-11-10 23:42:09 +00003481 {
Greg Clayton030a2042011-10-14 21:34:45 +00003482 // See if we already parsed this namespace DIE and associated it with a
3483 // uniqued namespace declaration
3484 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
3485 if (namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00003486 return namespace_decl;
Greg Clayton030a2042011-10-14 21:34:45 +00003487 else
3488 {
3489 const char *namespace_name = die->GetAttributeValueAsString(this, curr_cu, DW_AT_name, NULL);
3490 if (namespace_name)
3491 {
3492 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (curr_cu, die, NULL);
3493 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3494 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3495 if (log)
3496 {
3497 const char *object_name = m_obj_file->GetModule()->GetObjectName().GetCString();
Greg Clayton81c22f62011-10-19 18:09:39 +00003498 log->Printf ("ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)",
Greg Clayton030a2042011-10-14 21:34:45 +00003499 GetClangASTContext().getASTContext(),
Greg Clayton81c22f62011-10-19 18:09:39 +00003500 MakeUserID(die->GetOffset()),
Greg Clayton030a2042011-10-14 21:34:45 +00003501 namespace_name,
3502 namespace_decl,
3503 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
3504 m_obj_file->GetFileSpec().GetFilename().GetCString(),
3505 object_name ? "(" : "",
3506 object_name ? object_name : "",
3507 object_name ? "(" : "",
3508 namespace_decl->getOriginalNamespace());
3509 }
3510
3511 if (namespace_decl)
3512 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3513 return namespace_decl;
3514 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003515 }
3516 }
3517 return NULL;
3518}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003519
3520clang::DeclContext *
Sean Callanan72e49402011-08-05 23:43:37 +00003521SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die)
3522{
Greg Clayton5cf58b92011-10-05 22:22:08 +00003523 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3524 if (clang_decl_ctx)
3525 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003526 // If this DIE has a specification, or an abstract origin, then trace to those.
3527
3528 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_specification, DW_INVALID_OFFSET);
3529 if (die_offset != DW_INVALID_OFFSET)
3530 return GetClangDeclContextForDIEOffset (sc, die_offset);
3531
3532 die_offset = die->GetAttributeValueAsReference(this, curr_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3533 if (die_offset != DW_INVALID_OFFSET)
3534 return GetClangDeclContextForDIEOffset (sc, die_offset);
3535
3536 // This is the DIE we want. Parse it, then query our map.
3537
3538 ParseType(sc, curr_cu, die, NULL);
3539
Greg Clayton5cf58b92011-10-05 22:22:08 +00003540 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
3541
3542 return clang_decl_ctx;
Sean Callanan72e49402011-08-05 23:43:37 +00003543}
3544
3545clang::DeclContext *
Greg Claytoncb5860a2011-10-13 23:49:28 +00003546SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003547{
Greg Claytonca512b32011-01-14 04:54:56 +00003548 if (m_clang_tu_decl == NULL)
3549 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003550
Greg Clayton2bc22f82011-09-30 03:20:47 +00003551 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
Greg Claytoncb5860a2011-10-13 23:49:28 +00003552
3553 if (decl_ctx_die_copy)
3554 *decl_ctx_die_copy = decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003555
3556 if (decl_ctx_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003557 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00003558
Greg Clayton2bc22f82011-09-30 03:20:47 +00003559 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
3560 if (pos != m_die_to_decl_ctx.end())
3561 return pos->second;
3562
3563 switch (decl_ctx_die->Tag())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003564 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003565 case DW_TAG_compile_unit:
3566 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003567
Greg Clayton2bc22f82011-09-30 03:20:47 +00003568 case DW_TAG_namespace:
Greg Clayton030a2042011-10-14 21:34:45 +00003569 return ResolveNamespaceDIE (cu, decl_ctx_die);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003570 break;
3571
3572 case DW_TAG_structure_type:
3573 case DW_TAG_union_type:
3574 case DW_TAG_class_type:
3575 {
3576 Type* type = ResolveType (cu, decl_ctx_die);
3577 if (type)
3578 {
3579 clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
3580 if (decl_ctx)
Greg Claytonca512b32011-01-14 04:54:56 +00003581 {
Greg Clayton2bc22f82011-09-30 03:20:47 +00003582 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
3583 if (decl_ctx)
3584 return decl_ctx;
Greg Claytonca512b32011-01-14 04:54:56 +00003585 }
3586 }
Greg Claytonca512b32011-01-14 04:54:56 +00003587 }
Greg Clayton2bc22f82011-09-30 03:20:47 +00003588 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003589
Greg Clayton2bc22f82011-09-30 03:20:47 +00003590 default:
3591 break;
Greg Claytonca512b32011-01-14 04:54:56 +00003592 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003593 }
Greg Clayton7a345282010-11-09 23:46:37 +00003594 return m_clang_tu_decl;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003595}
3596
Greg Clayton2bc22f82011-09-30 03:20:47 +00003597
3598const DWARFDebugInfoEntry *
3599SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
3600{
3601 if (cu && die)
3602 {
3603 const DWARFDebugInfoEntry * const decl_die = die;
3604
3605 while (die != NULL)
3606 {
3607 // If this is the original DIE that we are searching for a declaration
3608 // for, then don't look in the cache as we don't want our own decl
3609 // context to be our decl context...
3610 if (decl_die != die)
3611 {
3612 switch (die->Tag())
3613 {
3614 case DW_TAG_compile_unit:
3615 case DW_TAG_namespace:
3616 case DW_TAG_structure_type:
3617 case DW_TAG_union_type:
3618 case DW_TAG_class_type:
3619 return die;
3620
3621 default:
3622 break;
3623 }
3624 }
3625
3626 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3627 if (die_offset != DW_INVALID_OFFSET)
3628 {
3629 DWARFCompileUnit *spec_cu = cu;
3630 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3631 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3632 if (spec_die_decl_ctx_die)
3633 return spec_die_decl_ctx_die;
3634 }
3635
3636 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3637 if (die_offset != DW_INVALID_OFFSET)
3638 {
3639 DWARFCompileUnit *abs_cu = cu;
3640 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3641 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3642 if (abs_die_decl_ctx_die)
3643 return abs_die_decl_ctx_die;
3644 }
3645
3646 die = die->GetParent();
3647 }
3648 }
3649 return NULL;
3650}
3651
3652
3653
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003654// This function can be used when a DIE is found that is a forward declaration
3655// DIE and we want to try and find a type that has the complete definition.
3656TypeSP
Greg Clayton7f995132011-10-04 22:41:51 +00003657SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
3658 const DWARFDebugInfoEntry *die,
3659 const ConstString &type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003660{
3661 TypeSP type_sp;
3662
Greg Clayton1a65ae12011-01-25 23:55:37 +00003663 if (cu == NULL || die == NULL || !type_name)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003664 return type_sp;
3665
Greg Clayton7f995132011-10-04 22:41:51 +00003666 DIEArray die_offsets;
3667
Greg Clayton97fbc342011-10-20 22:30:33 +00003668 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003669 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003670 if (m_apple_types_ap.get())
3671 {
3672 const char *name_cstr = type_name.GetCString();
3673 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3674 }
Greg Clayton7f995132011-10-04 22:41:51 +00003675 }
3676 else
3677 {
3678 if (!m_indexed)
3679 Index ();
3680
3681 m_type_index.Find (type_name, die_offsets);
3682 }
3683
3684
3685 const size_t num_matches = die_offsets.size();
Greg Clayton69974892010-12-03 21:42:06 +00003686
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003687 const dw_tag_t type_tag = die->Tag();
Greg Claytond4a2b372011-09-12 23:21:58 +00003688
3689 DWARFCompileUnit* type_cu = NULL;
3690 const DWARFDebugInfoEntry* type_die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003691 if (num_matches)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003692 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003693 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003694 for (size_t i=0; i<num_matches; ++i)
3695 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003696 const dw_offset_t die_offset = die_offsets[i];
3697 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003698
3699 if (type_die != die && type_die->Tag() == type_tag)
3700 {
3701 // Hold off on comparing parent DIE tags until
3702 // we know what happens with stuff in namespaces
3703 // for gcc and clang...
3704 //DWARFDebugInfoEntry *parent_die = die->GetParent();
3705 //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
3706 //if (parent_die->Tag() == parent_type_die->Tag())
3707 {
3708 Type *resolved_type = ResolveType (type_cu, type_die, false);
3709 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3710 {
Greg Clayton81c22f62011-10-19 18:09:39 +00003711 DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
3712 MakeUserID(die->GetOffset()),
3713 MakeUserID(curr_cu->GetOffset()),
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003714 m_obj_file->GetFileSpec().GetFilename().AsCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00003715 MakeUserID(type_die->GetOffset()),
3716 MakeUserID(type_cu->GetOffset()));
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003717
3718 m_die_to_type[die] = resolved_type;
Greg Clayton85ae2e12011-10-18 23:36:41 +00003719 type_sp = resolved_type;
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003720 break;
3721 }
3722 }
3723 }
3724 }
3725 }
3726 return type_sp;
3727}
3728
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003729TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003730SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003731{
3732 TypeSP type_sp;
3733
Greg Clayton1be10fc2010-09-29 01:12:09 +00003734 if (type_is_new_ptr)
3735 *type_is_new_ptr = false;
3736
Sean Callananc7fbf732010-08-06 00:32:49 +00003737 AccessType accessibility = eAccessNone;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003738 if (die != NULL)
3739 {
Greg Clayton21f2a492011-10-06 00:09:08 +00003740 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Jim Ingham16746d12011-08-25 23:21:43 +00003741 if (log && dwarf_cu)
3742 {
Jim Ingham318c9f22011-08-26 19:44:13 +00003743 StreamString s;
Jim Inghamd3d25d92011-08-27 01:24:54 +00003744 die->DumpLocation (this, dwarf_cu, s);
Jim Ingham318c9f22011-08-26 19:44:13 +00003745 log->Printf ("SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
3746
Jim Ingham16746d12011-08-25 23:21:43 +00003747 }
3748
Greg Clayton594e5ed2010-09-27 21:07:38 +00003749 Type *type_ptr = m_die_to_type.lookup (die);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003750 TypeList* type_list = GetTypeList();
Greg Clayton594e5ed2010-09-27 21:07:38 +00003751 if (type_ptr == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003752 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003753 ClangASTContext &ast = GetClangASTContext();
Greg Clayton1be10fc2010-09-29 01:12:09 +00003754 if (type_is_new_ptr)
3755 *type_is_new_ptr = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003756
Greg Clayton594e5ed2010-09-27 21:07:38 +00003757 const dw_tag_t tag = die->Tag();
3758
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759 bool is_forward_declaration = false;
3760 DWARFDebugInfoEntry::Attributes attributes;
3761 const char *type_name_cstr = NULL;
Greg Clayton24739922010-10-13 03:15:28 +00003762 ConstString type_name_const_str;
Greg Clayton526e5af2010-11-13 03:52:47 +00003763 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
3764 size_t byte_size = 0;
Greg Clayton36909642011-03-15 04:38:20 +00003765 bool byte_size_valid = false;
Greg Clayton526e5af2010-11-13 03:52:47 +00003766 Declaration decl;
3767
Greg Clayton4957bf62010-09-30 21:49:03 +00003768 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003769 clang_type_t clang_type = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003770
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003771 dw_attr_t attr;
3772
3773 switch (tag)
3774 {
3775 case DW_TAG_base_type:
3776 case DW_TAG_pointer_type:
3777 case DW_TAG_reference_type:
3778 case DW_TAG_typedef:
3779 case DW_TAG_const_type:
3780 case DW_TAG_restrict_type:
3781 case DW_TAG_volatile_type:
3782 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003783 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003784 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003785
Greg Claytond88d7592010-09-15 08:33:30 +00003786 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003787 uint32_t encoding = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003788 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
3789
3790 if (num_attributes > 0)
3791 {
3792 uint32_t i;
3793 for (i=0; i<num_attributes; ++i)
3794 {
3795 attr = attributes.AttributeAtIndex(i);
3796 DWARFFormValue form_value;
3797 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3798 {
3799 switch (attr)
3800 {
3801 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3802 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3803 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3804 case DW_AT_name:
Jim Ingham337030f2011-04-15 23:41:23 +00003805
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003806 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Jim Ingham337030f2011-04-15 23:41:23 +00003807 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
3808 // include the "&"...
3809 if (tag == DW_TAG_reference_type)
3810 {
3811 if (strchr (type_name_cstr, '&') == NULL)
3812 type_name_cstr = NULL;
3813 }
3814 if (type_name_cstr)
3815 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003816 break;
Greg Clayton36909642011-03-15 04:38:20 +00003817 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003818 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
3819 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
3820 default:
3821 case DW_AT_sibling:
3822 break;
3823 }
3824 }
3825 }
3826 }
3827
Greg Clayton81c22f62011-10-19 18:09:39 +00003828 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
Greg Claytonc93237c2010-10-01 20:48:32 +00003829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003830 switch (tag)
3831 {
3832 default:
Greg Clayton526e5af2010-11-13 03:52:47 +00003833 break;
3834
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003835 case DW_TAG_base_type:
Greg Clayton526e5af2010-11-13 03:52:47 +00003836 resolve_state = Type::eResolveStateFull;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003837 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
3838 encoding,
3839 byte_size * 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003840 break;
3841
Greg Clayton526e5af2010-11-13 03:52:47 +00003842 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
3843 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
3844 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
3845 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
3846 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
3847 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003848 }
3849
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003850 if (type_name_cstr != NULL && sc.comp_unit != NULL &&
3851 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
3852 {
3853 static ConstString g_objc_type_name_id("id");
3854 static ConstString g_objc_type_name_Class("Class");
3855 static ConstString g_objc_type_name_selector("SEL");
3856
Greg Clayton24739922010-10-13 03:15:28 +00003857 if (type_name_const_str == g_objc_type_name_id)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003858 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003859 clang_type = ast.GetBuiltInType_objc_id();
Greg Clayton526e5af2010-11-13 03:52:47 +00003860 resolve_state = Type::eResolveStateFull;
3861
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003862 }
Greg Clayton24739922010-10-13 03:15:28 +00003863 else if (type_name_const_str == g_objc_type_name_Class)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003864 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003865 clang_type = ast.GetBuiltInType_objc_Class();
Greg Clayton526e5af2010-11-13 03:52:47 +00003866 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003867 }
Greg Clayton24739922010-10-13 03:15:28 +00003868 else if (type_name_const_str == g_objc_type_name_selector)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003869 {
Sean Callananf6c73082010-12-06 23:53:20 +00003870 clang_type = ast.GetBuiltInType_objc_selector();
Greg Clayton526e5af2010-11-13 03:52:47 +00003871 resolve_state = Type::eResolveStateFull;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003872 }
3873 }
3874
Greg Clayton81c22f62011-10-19 18:09:39 +00003875 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003876 this,
3877 type_name_const_str,
3878 byte_size,
3879 NULL,
3880 encoding_uid,
3881 encoding_data_type,
3882 &decl,
3883 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00003884 resolve_state));
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00003885
Greg Clayton594e5ed2010-09-27 21:07:38 +00003886 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003887
3888// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
3889// if (encoding_type != NULL)
3890// {
3891// if (encoding_type != DIE_IS_BEING_PARSED)
3892// type_sp->SetEncodingType(encoding_type);
3893// else
3894// m_indirect_fixups.push_back(type_sp.get());
3895// }
3896 }
3897 break;
3898
3899 case DW_TAG_structure_type:
3900 case DW_TAG_union_type:
3901 case DW_TAG_class_type:
3902 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003903 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00003904 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003905
Greg Clayton9e409562010-07-28 02:04:09 +00003906 LanguageType class_language = eLanguageTypeUnknown;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003907 //bool struct_is_class = false;
Greg Claytond88d7592010-09-15 08:33:30 +00003908 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003909 if (num_attributes > 0)
3910 {
3911 uint32_t i;
3912 for (i=0; i<num_attributes; ++i)
3913 {
3914 attr = attributes.AttributeAtIndex(i);
3915 DWARFFormValue form_value;
3916 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3917 {
3918 switch (attr)
3919 {
Greg Clayton9e409562010-07-28 02:04:09 +00003920 case DW_AT_decl_file:
3921 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
3922 break;
3923
3924 case DW_AT_decl_line:
3925 decl.SetLine(form_value.Unsigned());
3926 break;
3927
3928 case DW_AT_decl_column:
3929 decl.SetColumn(form_value.Unsigned());
3930 break;
3931
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003932 case DW_AT_name:
3933 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00003934 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003935 break;
Greg Clayton9e409562010-07-28 02:04:09 +00003936
3937 case DW_AT_byte_size:
3938 byte_size = form_value.Unsigned();
Greg Clayton36909642011-03-15 04:38:20 +00003939 byte_size_valid = true;
Greg Clayton9e409562010-07-28 02:04:09 +00003940 break;
3941
3942 case DW_AT_accessibility:
3943 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3944 break;
3945
3946 case DW_AT_declaration:
Greg Clayton7a345282010-11-09 23:46:37 +00003947 is_forward_declaration = form_value.Unsigned() != 0;
Greg Clayton9e409562010-07-28 02:04:09 +00003948 break;
3949
3950 case DW_AT_APPLE_runtime_class:
3951 class_language = (LanguageType)form_value.Signed();
3952 break;
3953
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003954 case DW_AT_allocated:
3955 case DW_AT_associated:
3956 case DW_AT_data_location:
3957 case DW_AT_description:
3958 case DW_AT_start_scope:
3959 case DW_AT_visibility:
3960 default:
3961 case DW_AT_sibling:
3962 break;
3963 }
3964 }
3965 }
3966 }
3967
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003968 UniqueDWARFASTType unique_ast_entry;
3969 if (decl.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003970 {
Greg Claytone576ab22011-02-15 00:19:15 +00003971 if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
Greg Clayton36909642011-03-15 04:38:20 +00003972 this,
3973 dwarf_cu,
Greg Claytone576ab22011-02-15 00:19:15 +00003974 die,
3975 decl,
Greg Clayton36909642011-03-15 04:38:20 +00003976 byte_size_valid ? byte_size : -1,
Greg Claytone576ab22011-02-15 00:19:15 +00003977 unique_ast_entry))
Greg Claytonc615ce42010-11-09 04:42:43 +00003978 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003979 // We have already parsed this type or from another
3980 // compile unit. GCC loves to use the "one definition
3981 // rule" which can result in multiple definitions
3982 // of the same class over and over in each compile
3983 // unit.
3984 type_sp = unique_ast_entry.m_type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00003985 if (type_sp)
3986 {
Greg Clayton4272cc72011-02-02 02:24:04 +00003987 m_die_to_type[die] = type_sp.get();
3988 return type_sp;
3989 }
3990 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003991 }
3992
Greg Clayton81c22f62011-10-19 18:09:39 +00003993 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00003994
3995 int tag_decl_kind = -1;
3996 AccessType default_accessibility = eAccessNone;
3997 if (tag == DW_TAG_structure_type)
3998 {
3999 tag_decl_kind = clang::TTK_Struct;
4000 default_accessibility = eAccessPublic;
4001 }
4002 else if (tag == DW_TAG_union_type)
4003 {
4004 tag_decl_kind = clang::TTK_Union;
4005 default_accessibility = eAccessPublic;
4006 }
4007 else if (tag == DW_TAG_class_type)
4008 {
4009 tag_decl_kind = clang::TTK_Class;
4010 default_accessibility = eAccessPrivate;
4011 }
4012
4013
4014 if (is_forward_declaration)
4015 {
4016 // We have a forward declaration to a type and we need
4017 // to try and find a full declaration. We look in the
4018 // current type index just in case we have a forward
4019 // declaration followed by an actual declarations in the
4020 // DWARF. If this fails, we need to look elsewhere...
4021
4022 type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
4023
4024 if (!type_sp && m_debug_map_symfile)
Greg Clayton4272cc72011-02-02 02:24:04 +00004025 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004026 // We weren't able to find a full declaration in
4027 // this DWARF, see if we have a declaration anywhere
4028 // else...
4029 type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
Greg Clayton4272cc72011-02-02 02:24:04 +00004030 }
4031
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004032 if (type_sp)
Greg Clayton4272cc72011-02-02 02:24:04 +00004033 {
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004034 // We found a real definition for this type elsewhere
4035 // so lets use it and cache the fact that we found
4036 // a complete type for this die
4037 m_die_to_type[die] = type_sp.get();
4038 return type_sp;
Greg Clayton4272cc72011-02-02 02:24:04 +00004039 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004040 }
4041 assert (tag_decl_kind != -1);
4042 bool clang_type_was_created = false;
4043 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4044 if (clang_type == NULL)
4045 {
Greg Claytonf0705c82011-10-22 03:33:13 +00004046 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
Greg Clayton55561e92011-10-26 03:31:36 +00004047 if (accessibility == eAccessNone && decl_ctx)
4048 {
4049 // Check the decl context that contains this class/struct/union.
4050 // If it is a class we must give it an accessability.
4051 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
4052 if (DeclKindIsCXXClass (containing_decl_kind))
4053 accessibility = default_accessibility;
4054 }
4055
Greg Claytonf0705c82011-10-22 03:33:13 +00004056 if (type_name_cstr && strchr (type_name_cstr, '<'))
4057 {
4058 ClangASTContext::TemplateParameterInfos template_param_infos;
4059 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
4060 {
4061 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
Greg Clayton55561e92011-10-26 03:31:36 +00004062 accessibility,
Greg Claytonf0705c82011-10-22 03:33:13 +00004063 type_name_cstr,
4064 tag_decl_kind,
4065 template_param_infos);
4066
4067 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
4068 class_template_decl,
4069 tag_decl_kind,
4070 template_param_infos);
4071 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
4072 clang_type_was_created = true;
4073 }
4074 }
4075
4076 if (!clang_type_was_created)
4077 {
4078 clang_type_was_created = true;
Greg Clayton55561e92011-10-26 03:31:36 +00004079 clang_type = ast.CreateRecordType (decl_ctx,
4080 accessibility,
4081 type_name_cstr,
Greg Claytonf0705c82011-10-22 03:33:13 +00004082 tag_decl_kind,
Greg Claytonf0705c82011-10-22 03:33:13 +00004083 class_language);
4084 }
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004085 }
4086
4087 // Store a forward declaration to this class type in case any
4088 // parameters in any class methods need it for the clang
Greg Claytona2721472011-06-25 00:44:06 +00004089 // types for function prototypes.
4090 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
Greg Clayton81c22f62011-10-19 18:09:39 +00004091 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004092 this,
4093 type_name_const_str,
4094 byte_size,
4095 NULL,
4096 LLDB_INVALID_UID,
4097 Type::eEncodingIsUID,
4098 &decl,
4099 clang_type,
4100 Type::eResolveStateForward));
4101
4102
4103 // Add our type to the unique type map so we don't
4104 // end up creating many copies of the same type over
4105 // and over in the ASTContext for our module
4106 unique_ast_entry.m_type_sp = type_sp;
Greg Clayton36909642011-03-15 04:38:20 +00004107 unique_ast_entry.m_symfile = this;
4108 unique_ast_entry.m_cu = dwarf_cu;
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004109 unique_ast_entry.m_die = die;
4110 unique_ast_entry.m_declaration = decl;
Greg Claytone576ab22011-02-15 00:19:15 +00004111 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
4112 unique_ast_entry);
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004113
4114 if (die->HasChildren() == false && is_forward_declaration == false)
4115 {
4116 // No children for this struct/union/class, lets finish it
4117 ast.StartTagDeclarationDefinition (clang_type);
4118 ast.CompleteTagDeclarationDefinition (clang_type);
4119 }
4120 else if (clang_type_was_created)
4121 {
4122 // Leave this as a forward declaration until we need
4123 // to know the details of the type. lldb_private::Type
4124 // will automatically call the SymbolFile virtual function
4125 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
4126 // When the definition needs to be defined.
4127 m_forward_decl_die_to_clang_type[die] = clang_type;
4128 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
4129 ClangASTContext::SetHasExternalStorage (clang_type, true);
Greg Claytonc615ce42010-11-09 04:42:43 +00004130 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004131 }
4132 break;
4133
4134 case DW_TAG_enumeration_type:
4135 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004136 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004137 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004138
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004139 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004140
Greg Claytond88d7592010-09-15 08:33:30 +00004141 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004142 if (num_attributes > 0)
4143 {
4144 uint32_t i;
4145
4146 for (i=0; i<num_attributes; ++i)
4147 {
4148 attr = attributes.AttributeAtIndex(i);
4149 DWARFFormValue form_value;
4150 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4151 {
4152 switch (attr)
4153 {
Greg Clayton7a345282010-11-09 23:46:37 +00004154 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4155 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4156 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004157 case DW_AT_name:
4158 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004159 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004160 break;
Greg Clayton7a345282010-11-09 23:46:37 +00004161 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004162 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Greg Clayton7a345282010-11-09 23:46:37 +00004163 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4164 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004165 case DW_AT_allocated:
4166 case DW_AT_associated:
4167 case DW_AT_bit_stride:
4168 case DW_AT_byte_stride:
4169 case DW_AT_data_location:
4170 case DW_AT_description:
4171 case DW_AT_start_scope:
4172 case DW_AT_visibility:
4173 case DW_AT_specification:
4174 case DW_AT_abstract_origin:
4175 case DW_AT_sibling:
4176 break;
4177 }
4178 }
4179 }
4180
Greg Clayton81c22f62011-10-19 18:09:39 +00004181 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00004182
Greg Clayton1be10fc2010-09-29 01:12:09 +00004183 clang_type_t enumerator_clang_type = NULL;
4184 clang_type = m_forward_decl_die_to_clang_type.lookup (die);
4185 if (clang_type == NULL)
4186 {
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004187 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
4188 DW_ATE_signed,
4189 byte_size * 8);
Greg Claytonca512b32011-01-14 04:54:56 +00004190 clang_type = ast.CreateEnumerationType (type_name_cstr,
Greg Claytoncb5860a2011-10-13 23:49:28 +00004191 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
Greg Claytonca512b32011-01-14 04:54:56 +00004192 decl,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004193 enumerator_clang_type);
Greg Clayton1be10fc2010-09-29 01:12:09 +00004194 }
4195 else
4196 {
4197 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
4198 assert (enumerator_clang_type != NULL);
4199 }
4200
Greg Claytona2721472011-06-25 00:44:06 +00004201 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
4202
Greg Clayton81c22f62011-10-19 18:09:39 +00004203 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004204 this,
4205 type_name_const_str,
4206 byte_size,
4207 NULL,
4208 encoding_uid,
4209 Type::eEncodingIsUID,
4210 &decl,
4211 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004212 Type::eResolveStateForward));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004213
Greg Clayton6beaaa62011-01-17 03:46:26 +00004214 ast.StartTagDeclarationDefinition (clang_type);
4215 if (die->HasChildren())
4216 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004217 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
4218 ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
Greg Clayton6beaaa62011-01-17 03:46:26 +00004219 }
4220 ast.CompleteTagDeclarationDefinition (clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004221 }
4222 }
4223 break;
4224
Jim Inghamb0be4422010-08-12 01:20:14 +00004225 case DW_TAG_inlined_subroutine:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004226 case DW_TAG_subprogram:
4227 case DW_TAG_subroutine_type:
4228 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004229 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004230 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004231
4232 const char *mangled = NULL;
4233 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
Greg Claytona51ed9b2010-09-23 01:09:21 +00004234 bool is_variadic = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004235 bool is_inline = false;
Greg Clayton0fffff52010-09-24 05:15:53 +00004236 bool is_static = false;
4237 bool is_virtual = false;
Greg Claytonf51de672010-10-01 02:31:07 +00004238 bool is_explicit = false;
Greg Clayton72da3972011-08-16 18:40:23 +00004239 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
4240 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
Greg Clayton0fffff52010-09-24 05:15:53 +00004241
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004242 unsigned type_quals = 0;
Sean Callanane2ef6e32010-09-23 03:01:22 +00004243 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004244
4245
Greg Claytond88d7592010-09-15 08:33:30 +00004246 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004247 if (num_attributes > 0)
4248 {
4249 uint32_t i;
4250 for (i=0; i<num_attributes; ++i)
4251 {
Greg Clayton1a65ae12011-01-25 23:55:37 +00004252 attr = attributes.AttributeAtIndex(i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004253 DWARFFormValue form_value;
4254 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4255 {
4256 switch (attr)
4257 {
4258 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4259 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4260 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4261 case DW_AT_name:
4262 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004263 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004264 break;
4265
4266 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
4267 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004268 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00004269 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004270 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break;
4271 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
Greg Claytonf51de672010-10-01 02:31:07 +00004272 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break;
4273
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004274 case DW_AT_external:
4275 if (form_value.Unsigned())
4276 {
Sean Callanane2ef6e32010-09-23 03:01:22 +00004277 if (storage == clang::SC_None)
4278 storage = clang::SC_Extern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004279 else
Sean Callanane2ef6e32010-09-23 03:01:22 +00004280 storage = clang::SC_PrivateExtern;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004281 }
4282 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004283
Greg Clayton72da3972011-08-16 18:40:23 +00004284 case DW_AT_specification:
4285 specification_die_offset = form_value.Reference(dwarf_cu);
4286 break;
4287
4288 case DW_AT_abstract_origin:
4289 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
4290 break;
4291
4292
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004293 case DW_AT_allocated:
4294 case DW_AT_associated:
4295 case DW_AT_address_class:
4296 case DW_AT_artificial:
4297 case DW_AT_calling_convention:
4298 case DW_AT_data_location:
4299 case DW_AT_elemental:
4300 case DW_AT_entry_pc:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004301 case DW_AT_frame_base:
4302 case DW_AT_high_pc:
4303 case DW_AT_low_pc:
4304 case DW_AT_object_pointer:
4305 case DW_AT_prototyped:
4306 case DW_AT_pure:
4307 case DW_AT_ranges:
4308 case DW_AT_recursive:
4309 case DW_AT_return_addr:
4310 case DW_AT_segment:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004311 case DW_AT_start_scope:
4312 case DW_AT_static_link:
4313 case DW_AT_trampoline:
4314 case DW_AT_visibility:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004315 case DW_AT_vtable_elem_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004316 case DW_AT_description:
4317 case DW_AT_sibling:
4318 break;
4319 }
4320 }
4321 }
Greg Clayton24739922010-10-13 03:15:28 +00004322 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004323
Greg Clayton81c22f62011-10-19 18:09:39 +00004324 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00004325
Greg Clayton24739922010-10-13 03:15:28 +00004326 clang_type_t return_clang_type = NULL;
4327 Type *func_type = NULL;
4328
4329 if (type_die_offset != DW_INVALID_OFFSET)
4330 func_type = ResolveTypeUID(type_die_offset);
Greg Claytonf51de672010-10-01 02:31:07 +00004331
Greg Clayton24739922010-10-13 03:15:28 +00004332 if (func_type)
Greg Clayton526e5af2010-11-13 03:52:47 +00004333 return_clang_type = func_type->GetClangLayoutType();
Greg Clayton24739922010-10-13 03:15:28 +00004334 else
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004335 return_clang_type = ast.GetBuiltInType_void();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004336
Greg Claytonf51de672010-10-01 02:31:07 +00004337
Greg Clayton24739922010-10-13 03:15:28 +00004338 std::vector<clang_type_t> function_param_types;
4339 std::vector<clang::ParmVarDecl*> function_param_decls;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004340
Greg Clayton24739922010-10-13 03:15:28 +00004341 // Parse the function children for the parameters
Sean Callanan763d72a2011-08-02 22:21:50 +00004342
Greg Claytoncb5860a2011-10-13 23:49:28 +00004343 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
4344 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
Greg Clayton5113dc82011-08-12 06:47:54 +00004345 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
4346
Greg Claytonf0705c82011-10-22 03:33:13 +00004347 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
Greg Clayton5113dc82011-08-12 06:47:54 +00004348 // Start off static. This will be set to false in ParseChildParameters(...)
4349 // if we find a "this" paramters as the first parameter
4350 if (is_cxx_method)
Sean Callanan763d72a2011-08-02 22:21:50 +00004351 is_static = true;
4352
Greg Clayton24739922010-10-13 03:15:28 +00004353 if (die->HasChildren())
4354 {
Greg Clayton0fffff52010-09-24 05:15:53 +00004355 bool skip_artificial = true;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004356 ParseChildParameters (sc,
Greg Clayton5113dc82011-08-12 06:47:54 +00004357 containing_decl_ctx,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004358 type_sp,
4359 dwarf_cu,
4360 die,
Sean Callanan763d72a2011-08-02 22:21:50 +00004361 skip_artificial,
4362 is_static,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004363 type_list,
4364 function_param_types,
Greg Clayton7fedea22010-11-16 02:10:54 +00004365 function_param_decls,
4366 type_quals);
Greg Clayton24739922010-10-13 03:15:28 +00004367 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004368
Greg Clayton24739922010-10-13 03:15:28 +00004369 // clang_type will get the function prototype clang type after this call
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004370 clang_type = ast.CreateFunctionType (return_clang_type,
4371 &function_param_types[0],
4372 function_param_types.size(),
4373 is_variadic,
4374 type_quals);
4375
Greg Clayton24739922010-10-13 03:15:28 +00004376 if (type_name_cstr)
4377 {
4378 bool type_handled = false;
Greg Clayton24739922010-10-13 03:15:28 +00004379 if (tag == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004380 {
Jim Inghamb7f6b2f2011-09-08 22:13:49 +00004381 if (ObjCLanguageRuntime::IsPossibleObjCMethodName (type_name_cstr))
Greg Clayton0fffff52010-09-24 05:15:53 +00004382 {
Greg Clayton24739922010-10-13 03:15:28 +00004383 // We need to find the DW_TAG_class_type or
4384 // DW_TAG_struct_type by name so we can add this
4385 // as a member function of the class.
4386 const char *class_name_start = type_name_cstr + 2;
4387 const char *class_name_end = ::strchr (class_name_start, ' ');
4388 SymbolContext empty_sc;
4389 clang_type_t class_opaque_type = NULL;
4390 if (class_name_start < class_name_end)
Greg Clayton0fffff52010-09-24 05:15:53 +00004391 {
Greg Clayton24739922010-10-13 03:15:28 +00004392 ConstString class_name (class_name_start, class_name_end - class_name_start);
4393 TypeList types;
Sean Callanan213fdb82011-10-13 01:49:10 +00004394 const uint32_t match_count = FindTypes (empty_sc, class_name, NULL, true, UINT32_MAX, types);
Greg Clayton24739922010-10-13 03:15:28 +00004395 if (match_count > 0)
Greg Clayton0fffff52010-09-24 05:15:53 +00004396 {
Greg Clayton24739922010-10-13 03:15:28 +00004397 for (uint32_t i=0; i<match_count; ++i)
Greg Clayton0fffff52010-09-24 05:15:53 +00004398 {
Greg Clayton24739922010-10-13 03:15:28 +00004399 Type *type = types.GetTypeAtIndex (i).get();
4400 clang_type_t type_clang_forward_type = type->GetClangForwardType();
4401 if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
Greg Clayton0fffff52010-09-24 05:15:53 +00004402 {
Greg Clayton24739922010-10-13 03:15:28 +00004403 class_opaque_type = type_clang_forward_type;
4404 break;
Greg Clayton0fffff52010-09-24 05:15:53 +00004405 }
4406 }
4407 }
Greg Clayton24739922010-10-13 03:15:28 +00004408 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004409
Greg Clayton24739922010-10-13 03:15:28 +00004410 if (class_opaque_type)
4411 {
4412 // If accessibility isn't set to anything valid, assume public for
4413 // now...
4414 if (accessibility == eAccessNone)
4415 accessibility = eAccessPublic;
4416
4417 clang::ObjCMethodDecl *objc_method_decl;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004418 objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
4419 type_name_cstr,
4420 clang_type,
4421 accessibility);
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004422 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
Greg Clayton24739922010-10-13 03:15:28 +00004423 type_handled = objc_method_decl != NULL;
4424 }
4425 }
Greg Clayton5113dc82011-08-12 06:47:54 +00004426 else if (is_cxx_method)
Greg Clayton24739922010-10-13 03:15:28 +00004427 {
4428 // Look at the parent of this DIE and see if is is
4429 // a class or struct and see if this is actually a
4430 // C++ method
Greg Claytoncb5860a2011-10-13 23:49:28 +00004431 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
Greg Clayton24739922010-10-13 03:15:28 +00004432 if (class_type)
4433 {
Greg Clayton72da3972011-08-16 18:40:23 +00004434 if (specification_die_offset != DW_INVALID_OFFSET)
Greg Clayton0fffff52010-09-24 05:15:53 +00004435 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004436 // We have a specification which we are going to base our function
4437 // prototype off of, so we need this type to be completed so that the
4438 // m_die_to_decl_ctx for the method in the specification has a valid
4439 // clang decl context.
4440 class_type->GetClangFullType();
Greg Clayton72da3972011-08-16 18:40:23 +00004441 // If we have a specification, then the function type should have been
4442 // made with the specification and not with this die.
4443 DWARFCompileUnitSP spec_cu_sp;
4444 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004445 clang::DeclContext *spec_clang_decl_ctx = GetCachedClangDeclContextForDIE (spec_die);
4446 if (spec_clang_decl_ctx)
4447 {
4448 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
4449 }
4450 else
Jim Inghamc1663042011-09-29 22:12:35 +00004451 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004452 ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
4453 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004454 specification_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004455 }
Greg Clayton72da3972011-08-16 18:40:23 +00004456 type_handled = true;
4457 }
4458 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
4459 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00004460 // We have a specification which we are going to base our function
4461 // prototype off of, so we need this type to be completed so that the
4462 // m_die_to_decl_ctx for the method in the abstract origin has a valid
4463 // clang decl context.
4464 class_type->GetClangFullType();
4465
Greg Clayton72da3972011-08-16 18:40:23 +00004466 DWARFCompileUnitSP abs_cu_sp;
4467 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
Greg Clayton5cf58b92011-10-05 22:22:08 +00004468 clang::DeclContext *abs_clang_decl_ctx = GetCachedClangDeclContextForDIE (abs_die);
4469 if (abs_clang_decl_ctx)
4470 {
4471 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
4472 }
4473 else
Jim Inghamc1663042011-09-29 22:12:35 +00004474 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004475 ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
4476 MakeUserID(die->GetOffset()),
Greg Clayton5cf58b92011-10-05 22:22:08 +00004477 abstract_origin_die_offset);
Jim Inghamc1663042011-09-29 22:12:35 +00004478 }
Greg Clayton72da3972011-08-16 18:40:23 +00004479 type_handled = true;
4480 }
4481 else
4482 {
4483 clang_type_t class_opaque_type = class_type->GetClangForwardType();
4484 if (ClangASTContext::IsCXXClassType (class_opaque_type))
Greg Clayton931180e2011-01-27 06:44:37 +00004485 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004486 if (ClangASTContext::IsBeingDefined (class_opaque_type))
Greg Clayton72da3972011-08-16 18:40:23 +00004487 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004488 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
4489 // in the DWARF for C++ methods... Default to public for now...
4490 if (accessibility == eAccessNone)
4491 accessibility = eAccessPublic;
4492
4493 if (!is_static && !die->HasChildren())
4494 {
4495 // We have a C++ member function with no children (this pointer!)
4496 // and clang will get mad if we try and make a function that isn't
4497 // well formed in the DWARF, so we will just skip it...
4498 type_handled = true;
4499 }
4500 else
4501 {
4502 clang::CXXMethodDecl *cxx_method_decl;
4503 // REMOVE THE CRASH DESCRIPTION BELOW
Greg Clayton81c22f62011-10-19 18:09:39 +00004504 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s",
Greg Clayton20568dd2011-10-13 23:13:20 +00004505 type_name_cstr,
4506 class_type->GetName().GetCString(),
Greg Clayton81c22f62011-10-19 18:09:39 +00004507 MakeUserID(die->GetOffset()),
Greg Clayton20568dd2011-10-13 23:13:20 +00004508 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
4509 m_obj_file->GetFileSpec().GetFilename().GetCString());
4510
4511 cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
4512 type_name_cstr,
4513 clang_type,
4514 accessibility,
4515 is_virtual,
4516 is_static,
4517 is_inline,
4518 is_explicit);
4519 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
4520
4521 type_handled = cxx_method_decl != NULL;
4522 }
Greg Clayton72da3972011-08-16 18:40:23 +00004523 }
4524 else
4525 {
Greg Clayton20568dd2011-10-13 23:13:20 +00004526 // We were asked to parse the type for a method in a class, yet the
4527 // class hasn't been asked to complete itself through the
4528 // clang::ExternalASTSource protocol, so we need to just have the
4529 // class complete itself and do things the right way, then our
4530 // DIE should then have an entry in the m_die_to_type map. First
4531 // we need to modify the m_die_to_type so it doesn't think we are
4532 // trying to parse this DIE anymore...
4533 m_die_to_type[die] = NULL;
4534
4535 // Now we get the full type to force our class type to complete itself
4536 // using the clang::ExternalASTSource protocol which will parse all
4537 // base classes and all methods (including the method for this DIE).
4538 class_type->GetClangFullType();
Greg Clayton2c5f0e92011-08-04 21:02:57 +00004539
Greg Clayton20568dd2011-10-13 23:13:20 +00004540 // The type for this DIE should have been filled in the function call above
4541 type_ptr = m_die_to_type[die];
4542 if (type_ptr)
4543 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00004544 type_sp = type_ptr;
Greg Clayton20568dd2011-10-13 23:13:20 +00004545 break;
4546 }
Greg Clayton72da3972011-08-16 18:40:23 +00004547 }
Greg Clayton931180e2011-01-27 06:44:37 +00004548 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004549 }
4550 }
Greg Clayton0fffff52010-09-24 05:15:53 +00004551 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004552 }
Greg Clayton24739922010-10-13 03:15:28 +00004553
4554 if (!type_handled)
4555 {
4556 // We just have a function that isn't part of a class
Greg Clayton147e1fa2011-10-14 22:47:18 +00004557 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
4558 type_name_cstr,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004559 clang_type,
4560 storage,
4561 is_inline);
Greg Clayton24739922010-10-13 03:15:28 +00004562
4563 // Add the decl to our DIE to decl context map
4564 assert (function_decl);
Greg Claytona2721472011-06-25 00:44:06 +00004565 LinkDeclContextToDIE(function_decl, die);
Greg Clayton24739922010-10-13 03:15:28 +00004566 if (!function_param_decls.empty())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004567 ast.SetFunctionParameters (function_decl,
4568 &function_param_decls.front(),
4569 function_param_decls.size());
Greg Clayton24739922010-10-13 03:15:28 +00004570 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004571 }
Greg Clayton81c22f62011-10-19 18:09:39 +00004572 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004573 this,
4574 type_name_const_str,
4575 0,
4576 NULL,
4577 LLDB_INVALID_UID,
4578 Type::eEncodingIsUID,
4579 &decl,
4580 clang_type,
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004581 Type::eResolveStateFull));
Greg Clayton24739922010-10-13 03:15:28 +00004582 assert(type_sp.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004583 }
4584 break;
4585
4586 case DW_TAG_array_type:
4587 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004588 // Set a bit that lets us know that we are currently parsing this
Greg Clayton594e5ed2010-09-27 21:07:38 +00004589 m_die_to_type[die] = DIE_IS_BEING_PARSED;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004590
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004591 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004592 int64_t first_index = 0;
4593 uint32_t byte_stride = 0;
4594 uint32_t bit_stride = 0;
Greg Claytond88d7592010-09-15 08:33:30 +00004595 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004596
4597 if (num_attributes > 0)
4598 {
4599 uint32_t i;
4600 for (i=0; i<num_attributes; ++i)
4601 {
4602 attr = attributes.AttributeAtIndex(i);
4603 DWARFFormValue form_value;
4604 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4605 {
4606 switch (attr)
4607 {
4608 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4609 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4610 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4611 case DW_AT_name:
4612 type_name_cstr = form_value.AsCString(&get_debug_str_data());
Greg Clayton24739922010-10-13 03:15:28 +00004613 type_name_const_str.SetCString(type_name_cstr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004614 break;
4615
4616 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
Greg Clayton36909642011-03-15 04:38:20 +00004617 case DW_AT_byte_size: byte_size = form_value.Unsigned(); byte_size_valid = true; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004618 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
4619 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
Greg Clayton8cf05932010-07-22 18:30:50 +00004620 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7a345282010-11-09 23:46:37 +00004621 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004622 case DW_AT_allocated:
4623 case DW_AT_associated:
4624 case DW_AT_data_location:
4625 case DW_AT_description:
4626 case DW_AT_ordering:
4627 case DW_AT_start_scope:
4628 case DW_AT_visibility:
4629 case DW_AT_specification:
4630 case DW_AT_abstract_origin:
4631 case DW_AT_sibling:
4632 break;
4633 }
4634 }
4635 }
4636
Greg Clayton81c22f62011-10-19 18:09:39 +00004637 DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
Greg Claytonc93237c2010-10-01 20:48:32 +00004638
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004639 Type *element_type = ResolveTypeUID(type_die_offset);
4640
4641 if (element_type)
4642 {
4643 std::vector<uint64_t> element_orders;
4644 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
Greg Claytona134cc12010-09-13 02:37:44 +00004645 // We have an array that claims to have no members, lets give it at least one member...
4646 if (element_orders.empty())
4647 element_orders.push_back (1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004648 if (byte_stride == 0 && bit_stride == 0)
4649 byte_stride = element_type->GetByteSize();
Greg Claytonf4ecaa52011-02-16 23:00:21 +00004650 clang_type_t array_element_type = element_type->GetClangFullType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004651 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
4652 uint64_t num_elements = 0;
4653 std::vector<uint64_t>::const_reverse_iterator pos;
4654 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
4655 for (pos = element_orders.rbegin(); pos != end; ++pos)
4656 {
4657 num_elements = *pos;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004658 clang_type = ast.CreateArrayType (array_element_type,
4659 num_elements,
4660 num_elements * array_element_bit_stride);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004661 array_element_type = clang_type;
4662 array_element_bit_stride = array_element_bit_stride * num_elements;
4663 }
4664 ConstString empty_name;
Greg Clayton81c22f62011-10-19 18:09:39 +00004665 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004666 this,
4667 empty_name,
4668 array_element_bit_stride / 8,
4669 NULL,
Greg Clayton526e5af2010-11-13 03:52:47 +00004670 type_die_offset,
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004671 Type::eEncodingIsUID,
4672 &decl,
4673 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004674 Type::eResolveStateFull));
4675 type_sp->SetEncodingType (element_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004676 }
4677 }
4678 }
4679 break;
4680
Greg Clayton9b81a312010-06-12 01:20:30 +00004681 case DW_TAG_ptr_to_member_type:
4682 {
4683 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
4684 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
4685
Greg Claytond88d7592010-09-15 08:33:30 +00004686 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
Greg Clayton9b81a312010-06-12 01:20:30 +00004687
4688 if (num_attributes > 0) {
4689 uint32_t i;
4690 for (i=0; i<num_attributes; ++i)
4691 {
4692 attr = attributes.AttributeAtIndex(i);
4693 DWARFFormValue form_value;
4694 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4695 {
4696 switch (attr)
4697 {
4698 case DW_AT_type:
4699 type_die_offset = form_value.Reference(dwarf_cu); break;
4700 case DW_AT_containing_type:
4701 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
4702 }
4703 }
4704 }
4705
4706 Type *pointee_type = ResolveTypeUID(type_die_offset);
4707 Type *class_type = ResolveTypeUID(containing_type_die_offset);
4708
Greg Clayton526e5af2010-11-13 03:52:47 +00004709 clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
4710 clang_type_t class_clang_type = class_type->GetClangLayoutType();
Greg Clayton9b81a312010-06-12 01:20:30 +00004711
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004712 clang_type = ast.CreateMemberPointerType(pointee_clang_type,
4713 class_clang_type);
Greg Clayton9b81a312010-06-12 01:20:30 +00004714
Greg Clayton526e5af2010-11-13 03:52:47 +00004715 byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
4716 clang_type) / 8;
Greg Clayton9b81a312010-06-12 01:20:30 +00004717
Greg Clayton81c22f62011-10-19 18:09:39 +00004718 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00004719 this,
4720 type_name_const_str,
4721 byte_size,
4722 NULL,
4723 LLDB_INVALID_UID,
4724 Type::eEncodingIsUID,
4725 NULL,
4726 clang_type,
Greg Clayton526e5af2010-11-13 03:52:47 +00004727 Type::eResolveStateForward));
Greg Clayton9b81a312010-06-12 01:20:30 +00004728 }
4729
4730 break;
4731 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004732 default:
Greg Clayton9b81a312010-06-12 01:20:30 +00004733 assert(false && "Unhandled type tag!");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004734 break;
4735 }
4736
4737 if (type_sp.get())
4738 {
4739 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4740 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4741
4742 SymbolContextScope * symbol_context_scope = NULL;
4743 if (sc_parent_tag == DW_TAG_compile_unit)
4744 {
4745 symbol_context_scope = sc.comp_unit;
4746 }
4747 else if (sc.function != NULL)
4748 {
Greg Clayton81c22f62011-10-19 18:09:39 +00004749 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004750 if (symbol_context_scope == NULL)
4751 symbol_context_scope = sc.function;
4752 }
4753
4754 if (symbol_context_scope != NULL)
4755 {
4756 type_sp->SetSymbolContextScope(symbol_context_scope);
4757 }
4758
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004759 // We are ready to put this type into the uniqued list up at the module level
4760 type_list->Insert (type_sp);
Greg Clayton450e3f32010-10-12 02:24:53 +00004761
Greg Clayton1c9e5ac2011-02-09 19:06:17 +00004762 m_die_to_type[die] = type_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004763 }
4764 }
Greg Clayton594e5ed2010-09-27 21:07:38 +00004765 else if (type_ptr != DIE_IS_BEING_PARSED)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004766 {
Greg Clayton85ae2e12011-10-18 23:36:41 +00004767 type_sp = type_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004768 }
4769 }
4770 return type_sp;
4771}
4772
4773size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00004774SymbolFileDWARF::ParseTypes
4775(
4776 const SymbolContext& sc,
4777 DWARFCompileUnit* dwarf_cu,
4778 const DWARFDebugInfoEntry *die,
4779 bool parse_siblings,
4780 bool parse_children
4781)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004782{
4783 size_t types_added = 0;
4784 while (die != NULL)
4785 {
4786 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00004787 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004788 {
4789 if (type_is_new)
4790 ++types_added;
4791 }
4792
4793 if (parse_children && die->HasChildren())
4794 {
4795 if (die->Tag() == DW_TAG_subprogram)
4796 {
4797 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00004798 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004799 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
4800 }
4801 else
4802 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
4803 }
4804
4805 if (parse_siblings)
4806 die = die->GetSibling();
4807 else
4808 die = NULL;
4809 }
4810 return types_added;
4811}
4812
4813
4814size_t
4815SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
4816{
4817 assert(sc.comp_unit && sc.function);
4818 size_t functions_added = 0;
4819 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4820 if (dwarf_cu)
4821 {
4822 dw_offset_t function_die_offset = sc.function->GetID();
4823 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
4824 if (function_die)
4825 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00004826 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004827 }
4828 }
4829
4830 return functions_added;
4831}
4832
4833
4834size_t
4835SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
4836{
4837 // At least a compile unit must be valid
4838 assert(sc.comp_unit);
4839 size_t types_added = 0;
4840 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
4841 if (dwarf_cu)
4842 {
4843 if (sc.function)
4844 {
4845 dw_offset_t function_die_offset = sc.function->GetID();
4846 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
4847 if (func_die && func_die->HasChildren())
4848 {
4849 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
4850 }
4851 }
4852 else
4853 {
4854 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
4855 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
4856 {
4857 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
4858 }
4859 }
4860 }
4861
4862 return types_added;
4863}
4864
4865size_t
4866SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
4867{
4868 if (sc.comp_unit != NULL)
4869 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00004870 DWARFDebugInfo* info = DebugInfo();
4871 if (info == NULL)
4872 return 0;
4873
4874 uint32_t cu_idx = UINT32_MAX;
4875 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004876
4877 if (dwarf_cu == NULL)
4878 return 0;
4879
4880 if (sc.function)
4881 {
4882 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00004883
4884 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
4885 assert (func_lo_pc != DW_INVALID_ADDRESS);
4886
Greg Claytonc662ec82011-06-17 22:10:16 +00004887 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
4888
4889 // Let all blocks know they have parse all their variables
4890 sc.function->GetBlock (false).SetDidParseVariables (true, true);
4891
4892 return num_variables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004893 }
4894 else if (sc.comp_unit)
4895 {
4896 uint32_t vars_added = 0;
4897 VariableListSP variables (sc.comp_unit->GetVariableList(false));
4898
4899 if (variables.get() == NULL)
4900 {
4901 variables.reset(new VariableList());
4902 sc.comp_unit->SetVariableList(variables);
4903
Greg Claytond4a2b372011-09-12 23:21:58 +00004904 DWARFCompileUnit* match_dwarf_cu = NULL;
4905 const DWARFDebugInfoEntry* die = NULL;
4906 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00004907 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00004908 {
Greg Clayton97fbc342011-10-20 22:30:33 +00004909 if (m_apple_names_ap.get())
4910 m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
4911 dwarf_cu->GetNextCompileUnitOffset(),
4912 die_offsets);
Greg Clayton7f995132011-10-04 22:41:51 +00004913 }
4914 else
4915 {
4916 // Index if we already haven't to make sure the compile units
4917 // get indexed and make their global DIE index list
4918 if (!m_indexed)
4919 Index ();
4920
4921 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
4922 dwarf_cu->GetNextCompileUnitOffset(),
4923 die_offsets);
4924 }
4925
4926 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00004927 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004928 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004929 DWARFDebugInfo* debug_info = DebugInfo();
4930 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004931 {
Greg Claytond4a2b372011-09-12 23:21:58 +00004932 const dw_offset_t die_offset = die_offsets[i];
4933 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
4934 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
4935 if (var_sp)
4936 {
4937 variables->AddVariableIfUnique (var_sp);
4938 ++vars_added;
4939 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004940 }
4941 }
4942 }
4943 return vars_added;
4944 }
4945 }
4946 return 0;
4947}
4948
4949
4950VariableSP
4951SymbolFileDWARF::ParseVariableDIE
4952(
4953 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004954 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004955 const DWARFDebugInfoEntry *die,
4956 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004957)
4958{
4959
Greg Clayton83c5cd92010-11-14 22:13:40 +00004960 VariableSP var_sp (m_die_to_variable_sp[die]);
4961 if (var_sp)
4962 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004963
4964 const dw_tag_t tag = die->Tag();
Greg Clayton7f995132011-10-04 22:41:51 +00004965
4966 if ((tag == DW_TAG_variable) ||
4967 (tag == DW_TAG_constant) ||
4968 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004969 {
Greg Clayton7f995132011-10-04 22:41:51 +00004970 DWARFDebugInfoEntry::Attributes attributes;
4971 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
4972 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004973 {
Greg Clayton7f995132011-10-04 22:41:51 +00004974 const char *name = NULL;
4975 const char *mangled = NULL;
4976 Declaration decl;
4977 uint32_t i;
4978 Type *var_type = NULL;
4979 DWARFExpression location;
4980 bool is_external = false;
4981 bool is_artificial = false;
4982 bool location_is_const_value_data = false;
4983 AccessType accessibility = eAccessNone;
4984
4985 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004986 {
Greg Clayton7f995132011-10-04 22:41:51 +00004987 dw_attr_t attr = attributes.AttributeAtIndex(i);
4988 DWARFFormValue form_value;
4989 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004990 {
Greg Clayton7f995132011-10-04 22:41:51 +00004991 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004992 {
Greg Clayton7f995132011-10-04 22:41:51 +00004993 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4994 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4995 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4996 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4997 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
4998 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
4999 case DW_AT_external: is_external = form_value.Unsigned() != 0; break;
5000 case DW_AT_const_value:
5001 location_is_const_value_data = true;
5002 // Fall through...
5003 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005004 {
Greg Clayton7f995132011-10-04 22:41:51 +00005005 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005006 {
Greg Clayton7f995132011-10-04 22:41:51 +00005007 const DataExtractor& debug_info_data = get_debug_info_data();
5008
5009 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
5010 uint32_t block_length = form_value.Unsigned();
5011 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
5012 }
5013 else
5014 {
5015 const DataExtractor& debug_loc_data = get_debug_loc_data();
5016 const dw_offset_t debug_loc_offset = form_value.Unsigned();
5017
5018 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
5019 if (loc_list_length > 0)
5020 {
5021 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
5022 assert (func_low_pc != LLDB_INVALID_ADDRESS);
5023 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
5024 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005025 }
5026 }
Greg Clayton7f995132011-10-04 22:41:51 +00005027 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005028
Greg Clayton7f995132011-10-04 22:41:51 +00005029 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
5030 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5031 case DW_AT_declaration:
5032 case DW_AT_description:
5033 case DW_AT_endianity:
5034 case DW_AT_segment:
5035 case DW_AT_start_scope:
5036 case DW_AT_visibility:
5037 default:
5038 case DW_AT_abstract_origin:
5039 case DW_AT_sibling:
5040 case DW_AT_specification:
5041 break;
5042 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005043 }
5044 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005045
Greg Clayton7f995132011-10-04 22:41:51 +00005046 if (location.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005047 {
Greg Clayton7f995132011-10-04 22:41:51 +00005048 assert(var_type != DIE_IS_BEING_PARSED);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005049
Greg Clayton7f995132011-10-04 22:41:51 +00005050 ValueType scope = eValueTypeInvalid;
5051
5052 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5053 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5054
5055 if (tag == DW_TAG_formal_parameter)
5056 scope = eValueTypeVariableArgument;
5057 else if (is_external || parent_tag == DW_TAG_compile_unit)
5058 scope = eValueTypeVariableGlobal;
5059 else
5060 scope = eValueTypeVariableLocal;
5061
5062 SymbolContextScope * symbol_context_scope = NULL;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005063 switch (parent_tag)
Greg Clayton7f995132011-10-04 22:41:51 +00005064 {
Greg Clayton5cf58b92011-10-05 22:22:08 +00005065 case DW_TAG_subprogram:
5066 case DW_TAG_inlined_subroutine:
5067 case DW_TAG_lexical_block:
5068 if (sc.function)
5069 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005070 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Clayton5cf58b92011-10-05 22:22:08 +00005071 if (symbol_context_scope == NULL)
5072 symbol_context_scope = sc.function;
5073 }
5074 break;
5075
5076 default:
Greg Clayton7f995132011-10-04 22:41:51 +00005077 symbol_context_scope = sc.comp_unit;
Greg Clayton5cf58b92011-10-05 22:22:08 +00005078 break;
Greg Clayton7f995132011-10-04 22:41:51 +00005079 }
5080
Greg Clayton5cf58b92011-10-05 22:22:08 +00005081 if (symbol_context_scope)
5082 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005083 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
5084 name,
5085 mangled,
5086 var_type,
5087 scope,
5088 symbol_context_scope,
5089 &decl,
5090 location,
5091 is_external,
5092 is_artificial));
Greg Clayton5cf58b92011-10-05 22:22:08 +00005093
5094 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
5095 }
5096 else
5097 {
5098 // Not ready to parse this variable yet. It might be a global
5099 // or static variable that is in a function scope and the function
5100 // in the symbol context wasn't filled in yet
5101 return var_sp;
5102 }
Greg Clayton7f995132011-10-04 22:41:51 +00005103 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005104 }
Greg Clayton7f995132011-10-04 22:41:51 +00005105 // Cache var_sp even if NULL (the variable was just a specification or
5106 // was missing vital information to be able to be displayed in the debugger
5107 // (missing location due to optimization, etc)) so we don't re-parse
5108 // this DIE over and over later...
5109 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005110 }
5111 return var_sp;
5112}
5113
Greg Claytonc662ec82011-06-17 22:10:16 +00005114
5115const DWARFDebugInfoEntry *
5116SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
5117 dw_offset_t spec_block_die_offset,
5118 DWARFCompileUnit **result_die_cu_handle)
5119{
5120 // Give the concrete function die specified by "func_die_offset", find the
5121 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5122 // to "spec_block_die_offset"
5123 DWARFDebugInfo* info = DebugInfo();
5124
5125 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
5126 if (die)
5127 {
5128 assert (*result_die_cu_handle);
5129 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
5130 }
5131 return NULL;
5132}
5133
5134
5135const DWARFDebugInfoEntry *
5136SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
5137 const DWARFDebugInfoEntry *die,
5138 dw_offset_t spec_block_die_offset,
5139 DWARFCompileUnit **result_die_cu_handle)
5140{
5141 if (die)
5142 {
5143 switch (die->Tag())
5144 {
5145 case DW_TAG_subprogram:
5146 case DW_TAG_inlined_subroutine:
5147 case DW_TAG_lexical_block:
5148 {
5149 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
5150 {
5151 *result_die_cu_handle = dwarf_cu;
5152 return die;
5153 }
5154
5155 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
5156 {
5157 *result_die_cu_handle = dwarf_cu;
5158 return die;
5159 }
5160 }
5161 break;
5162 }
5163
5164 // Give the concrete function die specified by "func_die_offset", find the
5165 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
5166 // to "spec_block_die_offset"
5167 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
5168 {
5169 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
5170 child_die,
5171 spec_block_die_offset,
5172 result_die_cu_handle);
5173 if (result_die)
5174 return result_die;
5175 }
5176 }
5177
5178 *result_die_cu_handle = NULL;
5179 return NULL;
5180}
5181
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005182size_t
5183SymbolFileDWARF::ParseVariables
5184(
5185 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00005186 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00005187 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005188 const DWARFDebugInfoEntry *orig_die,
5189 bool parse_siblings,
5190 bool parse_children,
5191 VariableList* cc_variable_list
5192)
5193{
5194 if (orig_die == NULL)
5195 return 0;
5196
Greg Claytonc662ec82011-06-17 22:10:16 +00005197 VariableListSP variable_list_sp;
5198
5199 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005200 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00005201 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005202 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005203 dw_tag_t tag = die->Tag();
5204
5205 // Check to see if we have already parsed this variable or constant?
5206 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005207 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005208 if (cc_variable_list)
5209 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005210 }
5211 else
5212 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005213 // We haven't already parsed it, lets do that now.
5214 if ((tag == DW_TAG_variable) ||
5215 (tag == DW_TAG_constant) ||
5216 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005217 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005218 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00005219 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005220 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
5221 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5222 switch (parent_tag)
5223 {
5224 case DW_TAG_compile_unit:
5225 if (sc.comp_unit != NULL)
5226 {
5227 variable_list_sp = sc.comp_unit->GetVariableList(false);
5228 if (variable_list_sp.get() == NULL)
5229 {
5230 variable_list_sp.reset(new VariableList());
5231 sc.comp_unit->SetVariableList(variable_list_sp);
5232 }
5233 }
5234 else
5235 {
Greg Clayton81c22f62011-10-19 18:09:39 +00005236 ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
5237 MakeUserID(sc_parent_die->GetOffset()),
5238 DW_TAG_value_to_name (parent_tag),
5239 MakeUserID(orig_die->GetOffset()),
5240 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005241 }
5242 break;
5243
5244 case DW_TAG_subprogram:
5245 case DW_TAG_inlined_subroutine:
5246 case DW_TAG_lexical_block:
5247 if (sc.function != NULL)
5248 {
5249 // Check to see if we already have parsed the variables for the given scope
5250
Greg Clayton81c22f62011-10-19 18:09:39 +00005251 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005252 if (block == NULL)
5253 {
5254 // This must be a specification or abstract origin with
5255 // a concrete block couterpart in the current function. We need
5256 // to find the concrete block so we can correctly add the
5257 // variable to it
5258 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
5259 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
5260 sc_parent_die->GetOffset(),
5261 &concrete_block_die_cu);
5262 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00005263 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005264 }
5265
5266 if (block != NULL)
5267 {
5268 const bool can_create = false;
5269 variable_list_sp = block->GetBlockVariableList (can_create);
5270 if (variable_list_sp.get() == NULL)
5271 {
5272 variable_list_sp.reset(new VariableList());
5273 block->SetVariableList(variable_list_sp);
5274 }
5275 }
5276 }
5277 break;
5278
5279 default:
Greg Clayton81c22f62011-10-19 18:09:39 +00005280 ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
5281 MakeUserID(orig_die->GetOffset()),
5282 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00005283 break;
5284 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00005285 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005286
5287 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005288 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00005289 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
5290 if (var_sp)
5291 {
Greg Claytonc662ec82011-06-17 22:10:16 +00005292 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00005293 if (cc_variable_list)
5294 cc_variable_list->AddVariableIfUnique (var_sp);
5295 ++vars_added;
5296 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005297 }
5298 }
5299 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005300
5301 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
5302
5303 if (!skip_children && parse_children && die->HasChildren())
5304 {
5305 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
5306 }
5307
5308 if (parse_siblings)
5309 die = die->GetSibling();
5310 else
5311 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005312 }
Greg Claytonc662ec82011-06-17 22:10:16 +00005313 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00005314}
5315
5316//------------------------------------------------------------------
5317// PluginInterface protocol
5318//------------------------------------------------------------------
5319const char *
5320SymbolFileDWARF::GetPluginName()
5321{
5322 return "SymbolFileDWARF";
5323}
5324
5325const char *
5326SymbolFileDWARF::GetShortPluginName()
5327{
5328 return GetPluginNameStatic();
5329}
5330
5331uint32_t
5332SymbolFileDWARF::GetPluginVersion()
5333{
5334 return 1;
5335}
5336
5337void
Greg Clayton6beaaa62011-01-17 03:46:26 +00005338SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
5339{
5340 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5341 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5342 if (clang_type)
5343 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5344}
5345
5346void
5347SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
5348{
5349 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5350 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
5351 if (clang_type)
5352 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
5353}
5354
Greg Claytona2721472011-06-25 00:44:06 +00005355void
Sean Callanancc427fa2011-07-30 02:42:06 +00005356SymbolFileDWARF::DumpIndexes ()
5357{
5358 StreamFile s(stdout, false);
5359
5360 s.Printf ("DWARF index for (%s) '%s/%s':",
5361 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
5362 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
5363 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
5364 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
5365 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
5366 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
5367 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
5368 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
5369 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
5370 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
5371 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
5372}
5373
5374void
5375SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
5376 const char *name,
5377 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
Greg Claytona2721472011-06-25 00:44:06 +00005378{
Sean Callanancc427fa2011-07-30 02:42:06 +00005379 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
Greg Claytona2721472011-06-25 00:44:06 +00005380
5381 if (iter == m_decl_ctx_to_die.end())
5382 return;
5383
Greg Claytoncb5860a2011-10-13 23:49:28 +00005384 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
Greg Claytona2721472011-06-25 00:44:06 +00005385 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005386 const DWARFDebugInfoEntry *context_die = *pos;
5387
5388 if (!results)
5389 return;
5390
5391 DWARFDebugInfo* info = DebugInfo();
5392
5393 DIEArray die_offsets;
5394
5395 DWARFCompileUnit* dwarf_cu = NULL;
5396 const DWARFDebugInfoEntry* die = NULL;
5397 size_t num_matches = m_type_index.Find (ConstString(name), die_offsets);
5398
5399 if (num_matches)
Greg Claytona2721472011-06-25 00:44:06 +00005400 {
Greg Claytoncb5860a2011-10-13 23:49:28 +00005401 for (size_t i = 0; i < num_matches; ++i)
5402 {
5403 const dw_offset_t die_offset = die_offsets[i];
5404 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytond4a2b372011-09-12 23:21:58 +00005405
Greg Claytoncb5860a2011-10-13 23:49:28 +00005406 if (die->GetParent() != context_die)
5407 continue;
5408
5409 Type *matching_type = ResolveType (dwarf_cu, die);
5410
5411 lldb::clang_type_t type = matching_type->GetClangFullType();
5412 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
5413
5414 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
5415 {
5416 clang::TagDecl *tag_decl = tag_type->getDecl();
5417 results->push_back(tag_decl);
5418 }
5419 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
5420 {
5421 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
5422 results->push_back(typedef_decl);
5423 }
Greg Claytona2721472011-06-25 00:44:06 +00005424 }
5425 }
5426 }
5427}
5428
5429void
5430SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
Greg Clayton85ae2e12011-10-18 23:36:41 +00005431 const clang::DeclContext *decl_context,
5432 clang::DeclarationName decl_name,
Greg Claytona2721472011-06-25 00:44:06 +00005433 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
5434{
Greg Clayton85ae2e12011-10-18 23:36:41 +00005435
5436 switch (decl_context->getDeclKind())
5437 {
5438 case clang::Decl::Namespace:
5439 case clang::Decl::TranslationUnit:
5440 {
5441 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
5442 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
5443 }
5444 break;
5445 default:
5446 break;
5447 }
Greg Claytona2721472011-06-25 00:44:06 +00005448}