blob: a8bcd3b6ea6a346f22ec46b9dc117c69c2231494 [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"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Robert Flackeb83fab2015-05-15 18:59:59 +000029#include "lldb/Core/ArchSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/Module.h"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000031#include "lldb/Core/ModuleList.h"
32#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/PluginManager.h"
34#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/Scalar.h"
36#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000037#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000038#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Core/Timer.h"
40#include "lldb/Core/Value.h"
41
Sean Callananf0c5aeb2015-04-20 16:31:29 +000042#include "lldb/Expression/ClangModulesDeclVendor.h"
43
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +000044#include "lldb/Host/FileSystem.h"
Greg Clayton20568dd2011-10-13 23:13:20 +000045#include "lldb/Host/Host.h"
46
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +000047#include "lldb/Interpreter/OptionValueFileSpecList.h"
48#include "lldb/Interpreter/OptionValueProperties.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Symbol/Block.h"
51#include "lldb/Symbol/CompileUnit.h"
52#include "lldb/Symbol/LineTable.h"
53#include "lldb/Symbol/ObjectFile.h"
54#include "lldb/Symbol/SymbolVendor.h"
55#include "lldb/Symbol/VariableList.h"
56
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000057#include "lldb/Target/ObjCLanguageRuntime.h"
Jim Ingham4cda6e02011-10-07 22:23:45 +000058#include "lldb/Target/CPPLanguageRuntime.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000059
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "DWARFCompileUnit.h"
61#include "DWARFDebugAbbrev.h"
62#include "DWARFDebugAranges.h"
63#include "DWARFDebugInfo.h"
64#include "DWARFDebugInfoEntry.h"
65#include "DWARFDebugLine.h"
66#include "DWARFDebugPubnames.h"
67#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000068#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069#include "DWARFDIECollection.h"
70#include "DWARFFormValue.h"
71#include "DWARFLocationList.h"
72#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000073#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074
75#include <map>
76
Matthew Gardinere81df3b2014-08-26 06:57:23 +000077#include <ctype.h>
78#include <string.h>
79
Greg Clayton62742b12010-11-11 01:09:45 +000080//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000081
82#ifdef ENABLE_DEBUG_PRINTF
83#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000084#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000085#else
86#define DEBUG_PRINTF(fmt, ...)
87#endif
88
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089using namespace lldb;
90using namespace lldb_private;
91
Greg Clayton219cf312012-03-30 00:51:13 +000092//static inline bool
93//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
94//{
95// switch (tag)
96// {
97// default:
98// break;
99// case DW_TAG_subprogram:
100// case DW_TAG_inlined_subroutine:
101// case DW_TAG_class_type:
102// case DW_TAG_structure_type:
103// case DW_TAG_union_type:
104// return true;
105// }
106// return false;
107//}
108//
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000109
110namespace {
111
112 PropertyDefinition
113 g_properties[] =
114 {
115 { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." },
116 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
117 };
118
119 enum
120 {
121 ePropertySymLinkPaths
122 };
123
124
125 class PluginProperties : public Properties
126 {
127 public:
128 static ConstString
129 GetSettingName()
130 {
131 return SymbolFileDWARF::GetPluginNameStatic();
132 }
133
134 PluginProperties()
135 {
136 m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
137 m_collection_sp->Initialize(g_properties);
138 }
139
140 FileSpecList&
141 GetSymLinkPaths()
142 {
143 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
144 assert(option_value);
145 return option_value->GetCurrentValue();
146 }
147
148 };
149
150 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
151
152 static const SymbolFileDWARFPropertiesSP&
153 GetGlobalPluginProperties()
154 {
155 static const auto g_settings_sp(std::make_shared<PluginProperties>());
156 return g_settings_sp;
157 }
158
159} // anonymous namespace end
160
161
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000162static const char*
163removeHostnameFromPathname(const char* path_from_dwarf)
164{
165 if (!path_from_dwarf || !path_from_dwarf[0])
166 {
167 return path_from_dwarf;
168 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000169
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000170 const char *colon_pos = strchr(path_from_dwarf, ':');
Enrico Granata99e5e222015-07-27 21:27:02 +0000171 if (nullptr == colon_pos)
172 {
173 return path_from_dwarf;
174 }
175
176 const char *slash_pos = strchr(path_from_dwarf, '/');
177 if (slash_pos && (slash_pos < colon_pos))
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000178 {
179 return path_from_dwarf;
180 }
181
182 // check whether we have a windows path, and so the first character
183 // is a drive-letter not a hostname.
184 if (
185 colon_pos == path_from_dwarf + 1 &&
186 isalpha(*path_from_dwarf) &&
187 strlen(path_from_dwarf) > 2 &&
188 '\\' == path_from_dwarf[2])
189 {
190 return path_from_dwarf;
191 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000192
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000193 return colon_pos + 1;
194}
195
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000196static const char*
197resolveCompDir(const char* path_from_dwarf)
198{
199 if (!path_from_dwarf)
200 return nullptr;
201
202 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
203 // Remove the host part if present.
204 const char* local_path = removeHostnameFromPathname(path_from_dwarf);
205 if (!local_path)
206 return nullptr;
207
208 bool is_symlink = false;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000209 FileSpec local_path_spec(local_path, false);
210 const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
211 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
212 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000213
214 if (!is_symlink)
215 return local_path;
216
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000217 if (!local_path_spec.IsSymbolicLink())
218 return local_path;
219
220 FileSpec resolved_local_path_spec;
221 const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
222 if (error.Success())
223 return resolved_local_path_spec.GetCString();
224
225 return nullptr;
226}
227
228
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229void
230SymbolFileDWARF::Initialize()
231{
232 LogChannelDWARF::Initialize();
233 PluginManager::RegisterPlugin (GetPluginNameStatic(),
234 GetPluginDescriptionStatic(),
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000235 CreateInstance,
236 DebuggerInitialize);
237}
238
239void
240SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
241{
242 if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
243 {
244 const bool is_global_setting = true;
245 PluginManager::CreateSettingForSymbolFilePlugin(debugger,
246 GetGlobalPluginProperties()->GetValueProperties(),
247 ConstString ("Properties for the dwarf symbol-file plug-in."),
248 is_global_setting);
249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250}
251
252void
253SymbolFileDWARF::Terminate()
254{
255 PluginManager::UnregisterPlugin (CreateInstance);
256 LogChannelDWARF::Initialize();
257}
258
259
Greg Clayton57abc5d2013-05-10 21:47:16 +0000260lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261SymbolFileDWARF::GetPluginNameStatic()
262{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000263 static ConstString g_name("dwarf");
264 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265}
266
267const char *
268SymbolFileDWARF::GetPluginDescriptionStatic()
269{
270 return "DWARF and DWARF3 debug symbol file reader.";
271}
272
273
274SymbolFile*
275SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
276{
277 return new SymbolFileDWARF(obj_file);
278}
279
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000280TypeList *
281SymbolFileDWARF::GetTypeList ()
282{
Greg Clayton1f746072012-08-29 21:13:06 +0000283 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000284 return m_debug_map_symfile->GetTypeList();
285 return m_obj_file->GetModule()->GetTypeList();
286
287}
Greg Claytonf02500c2013-06-18 22:51:05 +0000288void
289SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
290 const DWARFDebugInfoEntry *die,
291 dw_offset_t min_die_offset,
292 dw_offset_t max_die_offset,
293 uint32_t type_mask,
294 TypeSet &type_set)
295{
296 if (cu)
297 {
298 if (die)
299 {
300 const dw_offset_t die_offset = die->GetOffset();
301
302 if (die_offset >= max_die_offset)
303 return;
304
305 if (die_offset >= min_die_offset)
306 {
307 const dw_tag_t tag = die->Tag();
308
309 bool add_type = false;
310
311 switch (tag)
312 {
313 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
314 case DW_TAG_unspecified_type:
315 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
316 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
317 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
318 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
319 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
320 case DW_TAG_subroutine_type:
321 case DW_TAG_subprogram:
322 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
323 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
324 case DW_TAG_rvalue_reference_type:
325 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
326 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
327 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
328 }
329
330 if (add_type)
331 {
332 const bool assert_not_being_parsed = true;
333 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
334 if (type)
335 {
336 if (type_set.find(type) == type_set.end())
337 type_set.insert(type);
338 }
339 }
340 }
341
342 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
343 child_die != NULL;
344 child_die = child_die->GetSibling())
345 {
346 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
347 }
348 }
349 }
350}
351
352size_t
353SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
354 uint32_t type_mask,
355 TypeList &type_list)
356
357{
358 TypeSet type_set;
359
360 CompileUnit *comp_unit = NULL;
361 DWARFCompileUnit* dwarf_cu = NULL;
362 if (sc_scope)
363 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
364
365 if (comp_unit)
366 {
367 dwarf_cu = GetDWARFCompileUnit(comp_unit);
368 if (dwarf_cu == 0)
369 return 0;
370 GetTypes (dwarf_cu,
371 dwarf_cu->DIE(),
372 dwarf_cu->GetOffset(),
373 dwarf_cu->GetNextCompileUnitOffset(),
374 type_mask,
375 type_set);
376 }
377 else
378 {
379 DWARFDebugInfo* info = DebugInfo();
380 if (info)
381 {
382 const size_t num_cus = info->GetNumCompileUnits();
383 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
384 {
385 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
386 if (dwarf_cu)
387 {
388 GetTypes (dwarf_cu,
389 dwarf_cu->DIE(),
390 0,
391 UINT32_MAX,
392 type_mask,
393 type_set);
394 }
395 }
396 }
397 }
398// if (m_using_apple_tables)
399// {
400// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
401// if (apple_types)
402// {
403// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
404//
405// for (auto die_info: die_info_array)
406// {
407// bool add_type = TagMatchesTypeMask (type_mask, 0);
408// if (!add_type)
409// {
410// dw_tag_t tag = die_info.tag;
411// if (tag == 0)
412// {
413// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
414// tag = die->Tag();
415// }
416// add_type = TagMatchesTypeMask (type_mask, tag);
417// }
418// if (add_type)
419// {
420// Type *type = ResolveTypeUID(die_info.offset);
421//
422// if (type_set.find(type) == type_set.end())
423// type_set.insert(type);
424// }
425// }
426// return true; // Keep iterating
427// });
428// }
429// }
430// else
431// {
432// if (!m_indexed)
433// Index ();
434//
435// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
436//
437// bool add_type = TagMatchesTypeMask (type_mask, 0);
438//
439// if (!add_type)
440// {
441// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
442// if (die)
443// {
444// const dw_tag_t tag = die->Tag();
445// add_type = TagMatchesTypeMask (type_mask, tag);
446// }
447// }
448//
449// if (add_type)
450// {
451// Type *type = ResolveTypeUID(die_offset);
452//
453// if (type_set.find(type) == type_set.end())
454// type_set.insert(type);
455// }
456// return true; // Keep iterating
457// });
458// }
459
Greg Claytona1e5dc82015-08-11 22:53:00 +0000460 std::set<CompilerType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000461 size_t num_types_added = 0;
462 for (Type *type : type_set)
463 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000464 CompilerType clang_type = type->GetForwardCompilerType ();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000465 if (clang_type_set.find(clang_type) == clang_type_set.end())
466 {
467 clang_type_set.insert(clang_type);
468 type_list.Insert (type->shared_from_this());
469 ++num_types_added;
470 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000471 }
472 return num_types_added;
473}
474
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000475
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476//----------------------------------------------------------------------
477// Gets the first parent that is a lexical block, function or inlined
478// subroutine, or compile unit.
479//----------------------------------------------------------------------
Greg Clayton8b4edba2015-08-14 20:02:05 +0000480const DWARFDebugInfoEntry *
481SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482{
483 const DWARFDebugInfoEntry *die;
484 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
485 {
486 dw_tag_t tag = die->Tag();
487
488 switch (tag)
489 {
490 case DW_TAG_compile_unit:
491 case DW_TAG_subprogram:
492 case DW_TAG_inlined_subroutine:
493 case DW_TAG_lexical_block:
494 return die;
495 }
496 }
497 return NULL;
498}
499
500
Greg Clayton450e3f32010-10-12 02:24:53 +0000501SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
502 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000503 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
Greg Clayton1f746072012-08-29 21:13:06 +0000504 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000505 m_debug_map_symfile (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000507 m_data_debug_abbrev (),
508 m_data_debug_aranges (),
509 m_data_debug_frame (),
510 m_data_debug_info (),
511 m_data_debug_line (),
512 m_data_debug_loc (),
513 m_data_debug_ranges (),
514 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000515 m_data_apple_names (),
516 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000517 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 m_info(),
520 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000521 m_apple_names_ap (),
522 m_apple_types_ap (),
523 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000524 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000525 m_function_basename_index(),
526 m_function_fullname_index(),
527 m_function_method_index(),
528 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000529 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000530 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000531 m_type_index(),
532 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000533 m_indexed (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000534 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000535 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000536 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000537 m_ranges(),
538 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
540}
541
542SymbolFileDWARF::~SymbolFileDWARF()
543{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000544}
545
546static const ConstString &
547GetDWARFMachOSegmentName ()
548{
549 static ConstString g_dwarf_section_name ("__DWARF");
550 return g_dwarf_section_name;
551}
552
Greg Claytone576ab22011-02-15 00:19:15 +0000553UniqueDWARFASTTypeMap &
554SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
555{
Greg Clayton1f746072012-08-29 21:13:06 +0000556 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000557 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
558 return m_unique_ast_type_map;
559}
560
Greg Clayton8b4edba2015-08-14 20:02:05 +0000561ClangASTContext &
Greg Clayton6beaaa62011-01-17 03:46:26 +0000562SymbolFileDWARF::GetClangASTContext ()
563{
Greg Clayton1f746072012-08-29 21:13:06 +0000564 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000565 return m_debug_map_symfile->GetClangASTContext ();
Greg Clayton6dc8d582015-08-18 22:32:36 +0000566 else
567 return m_obj_file->GetModule()->GetClangASTContext();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000568}
569
Greg Clayton8b4edba2015-08-14 20:02:05 +0000570TypeSystem *
571SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language)
572{
573 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
574 if (debug_map_symfile)
575 return debug_map_symfile->GetTypeSystemForLanguage (language);
576 else
Greg Clayton6dc8d582015-08-18 22:32:36 +0000577 return m_obj_file->GetModule()->GetTypeSystemForLanguage (language);
Greg Clayton8b4edba2015-08-14 20:02:05 +0000578}
579
Greg Clayton6beaaa62011-01-17 03:46:26 +0000580void
581SymbolFileDWARF::InitializeObject()
582{
Greg Claytone72dfb32012-02-24 01:59:29 +0000583 ModuleSP module_sp (m_obj_file->GetModule());
584 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000585 {
Greg Clayton3046e662013-07-10 01:23:25 +0000586 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000587
588 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
589
590 // Memory map the DWARF mach-o segment so we have everything mmap'ed
591 // to keep our heap memory usage down.
592 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000593 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000594 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000595 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000596 if (m_data_apple_names.GetByteSize() > 0)
597 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000598 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
599 if (m_apple_names_ap->IsValid())
600 m_using_apple_tables = true;
601 else
Greg Clayton7f995132011-10-04 22:41:51 +0000602 m_apple_names_ap.reset();
603 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000604 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000605 if (m_data_apple_types.GetByteSize() > 0)
606 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000607 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
608 if (m_apple_types_ap->IsValid())
609 m_using_apple_tables = true;
610 else
Greg Clayton7f995132011-10-04 22:41:51 +0000611 m_apple_types_ap.reset();
612 }
613
614 get_apple_namespaces_data();
615 if (m_data_apple_namespaces.GetByteSize() > 0)
616 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000617 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
618 if (m_apple_namespaces_ap->IsValid())
619 m_using_apple_tables = true;
620 else
Greg Clayton7f995132011-10-04 22:41:51 +0000621 m_apple_namespaces_ap.reset();
622 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000623
Greg Clayton5009f9d2011-10-27 17:55:14 +0000624 get_apple_objc_data();
625 if (m_data_apple_objc.GetByteSize() > 0)
626 {
627 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
628 if (m_apple_objc_ap->IsValid())
629 m_using_apple_tables = true;
630 else
631 m_apple_objc_ap.reset();
632 }
Greg Clayton6dc8d582015-08-18 22:32:36 +0000633
634 // Set the symbol file to this file if we don't have a debug map symbol
635 // file as our main symbol file. This allows the clang ASTContext to complete
636 // types using this symbol file when it needs to complete classes and structures.
637 if (GetDebugMapSymfile () == nullptr)
638 GetClangASTContext().SetSymbolFile(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639}
640
641bool
642SymbolFileDWARF::SupportedVersion(uint16_t version)
643{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000644 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645}
646
647uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000648SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649{
650 uint32_t abilities = 0;
651 if (m_obj_file != NULL)
652 {
653 const Section* section = NULL;
654 const SectionList *section_list = m_obj_file->GetSectionList();
655 if (section_list == NULL)
656 return 0;
657
658 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659 uint64_t debug_info_file_size = 0;
660 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661
Greg Clayton6beaaa62011-01-17 03:46:26 +0000662 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663
664 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000665 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000666
Greg Clayton4ceb9982010-07-21 22:54:26 +0000667 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668 if (section != NULL)
669 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000670 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671
Greg Clayton4ceb9982010-07-21 22:54:26 +0000672 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000674 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000675 else
676 m_flags.Set (flagsGotDebugAbbrevData);
677
Greg Clayton4ceb9982010-07-21 22:54:26 +0000678 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000679 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680 m_flags.Set (flagsGotDebugArangesData);
681
Greg Clayton4ceb9982010-07-21 22:54:26 +0000682 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000683 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684 m_flags.Set (flagsGotDebugFrameData);
685
Greg Clayton4ceb9982010-07-21 22:54:26 +0000686 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000688 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 else
690 m_flags.Set (flagsGotDebugLineData);
691
Greg Clayton4ceb9982010-07-21 22:54:26 +0000692 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000693 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694 m_flags.Set (flagsGotDebugLocData);
695
Greg Clayton4ceb9982010-07-21 22:54:26 +0000696 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000697 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698 m_flags.Set (flagsGotDebugMacInfoData);
699
Greg Clayton4ceb9982010-07-21 22:54:26 +0000700 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000701 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702 m_flags.Set (flagsGotDebugPubNamesData);
703
Greg Clayton4ceb9982010-07-21 22:54:26 +0000704 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000705 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 m_flags.Set (flagsGotDebugPubTypesData);
707
Greg Clayton4ceb9982010-07-21 22:54:26 +0000708 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000709 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710 m_flags.Set (flagsGotDebugRangesData);
711
Greg Clayton4ceb9982010-07-21 22:54:26 +0000712 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000713 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 m_flags.Set (flagsGotDebugStrData);
715 }
Greg Clayton6c596612012-05-18 21:47:20 +0000716 else
717 {
718 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
719 if (symfile_dir_cstr)
720 {
721 if (strcasestr(symfile_dir_cstr, ".dsym"))
722 {
723 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
724 {
725 // We have a dSYM file that didn't have a any debug info.
726 // If the string table has a size of 1, then it was made from
727 // an executable with no debug info, or from an executable that
728 // was stripped.
729 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
730 if (section && section->GetFileSize() == 1)
731 {
732 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
733 }
734 }
735 }
736 }
737 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738
739 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
740 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
741
742 if (debug_line_file_size > 0)
743 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744 }
745 return abilities;
746}
747
Ed Masteeeae7212013-10-24 20:43:47 +0000748const DWARFDataExtractor&
749SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750{
751 if (m_flags.IsClear (got_flag))
752 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000753 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000755 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 if (section_list)
757 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000758 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
759 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 {
761 // See if we memory mapped the DWARF segment?
762 if (m_dwarf_data.GetByteSize())
763 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000764 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765 }
766 else
767 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000768 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769 data.Clear();
770 }
771 }
772 }
773 }
774 return data;
775}
776
Ed Masteeeae7212013-10-24 20:43:47 +0000777const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778SymbolFileDWARF::get_debug_abbrev_data()
779{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000780 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781}
782
Ed Masteeeae7212013-10-24 20:43:47 +0000783const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000784SymbolFileDWARF::get_debug_aranges_data()
785{
786 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
787}
788
Ed Masteeeae7212013-10-24 20:43:47 +0000789const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790SymbolFileDWARF::get_debug_frame_data()
791{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000792 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793}
794
Ed Masteeeae7212013-10-24 20:43:47 +0000795const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796SymbolFileDWARF::get_debug_info_data()
797{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000798 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799}
800
Ed Masteeeae7212013-10-24 20:43:47 +0000801const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802SymbolFileDWARF::get_debug_line_data()
803{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000804 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805}
806
Ed Masteeeae7212013-10-24 20:43:47 +0000807const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808SymbolFileDWARF::get_debug_loc_data()
809{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000810 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811}
812
Ed Masteeeae7212013-10-24 20:43:47 +0000813const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814SymbolFileDWARF::get_debug_ranges_data()
815{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000816 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817}
818
Ed Masteeeae7212013-10-24 20:43:47 +0000819const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820SymbolFileDWARF::get_debug_str_data()
821{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000822 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823}
824
Ed Masteeeae7212013-10-24 20:43:47 +0000825const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000826SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000827{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000828 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000829}
830
Ed Masteeeae7212013-10-24 20:43:47 +0000831const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000832SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000833{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000834 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000835}
836
Ed Masteeeae7212013-10-24 20:43:47 +0000837const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000838SymbolFileDWARF::get_apple_namespaces_data()
839{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000840 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
841}
842
Ed Masteeeae7212013-10-24 20:43:47 +0000843const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000844SymbolFileDWARF::get_apple_objc_data()
845{
846 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000847}
848
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849
850DWARFDebugAbbrev*
851SymbolFileDWARF::DebugAbbrev()
852{
853 if (m_abbr.get() == NULL)
854 {
Ed Masteeeae7212013-10-24 20:43:47 +0000855 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000856 if (debug_abbrev_data.GetByteSize() > 0)
857 {
858 m_abbr.reset(new DWARFDebugAbbrev());
859 if (m_abbr.get())
860 m_abbr->Parse(debug_abbrev_data);
861 }
862 }
863 return m_abbr.get();
864}
865
866const DWARFDebugAbbrev*
867SymbolFileDWARF::DebugAbbrev() const
868{
869 return m_abbr.get();
870}
871
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872
873DWARFDebugInfo*
874SymbolFileDWARF::DebugInfo()
875{
876 if (m_info.get() == NULL)
877 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000878 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
879 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880 if (get_debug_info_data().GetByteSize() > 0)
881 {
882 m_info.reset(new DWARFDebugInfo());
883 if (m_info.get())
884 {
885 m_info->SetDwarfData(this);
886 }
887 }
888 }
889 return m_info.get();
890}
891
892const DWARFDebugInfo*
893SymbolFileDWARF::DebugInfo() const
894{
895 return m_info.get();
896}
897
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000898DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000899SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900{
901 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000902 if (info)
903 {
904 if (GetDebugMapSymfile ())
905 {
906 // The debug map symbol file made the compile units for this DWARF
907 // file which is .o file with DWARF in it, and we should have
908 // only 1 compile unit which is at offset zero in the DWARF.
909 // TODO: modify to support LTO .o files where each .o file might
910 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000911
912 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get();
913 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
914 dwarf_cu->SetUserData(comp_unit);
915 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000916 }
917 else
918 {
919 // Just a normal DWARF file whose user ID for the compile unit is
920 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000921
922 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
923 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
924 dwarf_cu->SetUserData(comp_unit);
925 return dwarf_cu;
926
Greg Clayton1f746072012-08-29 21:13:06 +0000927 }
928 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000929 return NULL;
930}
931
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932
933DWARFDebugRanges*
934SymbolFileDWARF::DebugRanges()
935{
936 if (m_ranges.get() == NULL)
937 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000938 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
939 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000940 if (get_debug_ranges_data().GetByteSize() > 0)
941 {
942 m_ranges.reset(new DWARFDebugRanges());
943 if (m_ranges.get())
944 m_ranges->Extract(this);
945 }
946 }
947 return m_ranges.get();
948}
949
950const DWARFDebugRanges*
951SymbolFileDWARF::DebugRanges() const
952{
953 return m_ranges.get();
954}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000955
Greg Clayton53eb1c22012-04-02 22:59:12 +0000956lldb::CompUnitSP
957SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000959 CompUnitSP cu_sp;
960 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000962 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
963 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000964 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000965 // We already parsed this compile unit, had out a shared pointer to it
966 cu_sp = comp_unit->shared_from_this();
967 }
968 else
969 {
Greg Clayton1f746072012-08-29 21:13:06 +0000970 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000971 {
Greg Clayton1f746072012-08-29 21:13:06 +0000972 // Let the debug map create the compile unit
973 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
974 dwarf_cu->SetUserData(cu_sp.get());
975 }
976 else
977 {
978 ModuleSP module_sp (m_obj_file->GetModule());
979 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000980 {
Greg Clayton1f746072012-08-29 21:13:06 +0000981 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
982 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000983 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000984 FileSpec cu_file_spec{cu_die->GetName(this, dwarf_cu), false};
985 if (cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000986 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000987 // If we have a full path to the compile unit, we don't need to resolve
988 // the file. This can be expensive e.g. when the source files are NFS mounted.
Chaoren Lin372e9062015-06-09 17:54:27 +0000989 if (cu_file_spec.IsRelative())
Greg Clayton53eb1c22012-04-02 22:59:12 +0000990 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000991 const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)};
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000992 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
Greg Clayton1f746072012-08-29 21:13:06 +0000993 }
994
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000995 std::string remapped_file;
996 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
997 cu_file_spec.SetFile(remapped_file, false);
David Srbeckyd515e942015-07-08 14:00:04 +0000998 }
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000999
David Srbeckyd515e942015-07-08 14:00:04 +00001000 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Chaoren Lin0c5a9c12015-06-05 00:28:06 +00001001
Jason Molendac7099582015-07-31 05:47:00 +00001002 bool is_optimized = dwarf_cu->GetIsOptimized ();
David Srbeckyd515e942015-07-08 14:00:04 +00001003 cu_sp.reset(new CompileUnit (module_sp,
1004 dwarf_cu,
1005 cu_file_spec,
1006 MakeUserID(dwarf_cu->GetOffset()),
Jason Molenda6ab659a2015-07-29 00:42:47 +00001007 cu_language,
1008 is_optimized));
David Srbeckyd515e942015-07-08 14:00:04 +00001009 if (cu_sp)
1010 {
1011 // If we just created a compile unit with an invalid file spec, try and get the
1012 // first entry in the supports files from the line table as that should be the
1013 // compile unit.
1014 if (!cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +00001015 {
David Srbeckyd515e942015-07-08 14:00:04 +00001016 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
1017 if (cu_file_spec)
1018 {
1019 (FileSpec &)(*cu_sp) = cu_file_spec;
1020 // Also fix the invalid file spec which was copied from the compile unit.
1021 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
1022 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001023 }
David Srbeckyd515e942015-07-08 14:00:04 +00001024
1025 dwarf_cu->SetUserData(cu_sp.get());
1026
1027 // Figure out the compile unit index if we weren't given one
1028 if (cu_idx == UINT32_MAX)
1029 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
1030
1031 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
Greg Clayton53eb1c22012-04-02 22:59:12 +00001032 }
1033 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001034 }
1035 }
1036 }
1037 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001038 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039}
1040
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041uint32_t
1042SymbolFileDWARF::GetNumCompileUnits()
1043{
1044 DWARFDebugInfo* info = DebugInfo();
1045 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001047 return 0;
1048}
1049
1050CompUnitSP
1051SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1052{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001053 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 DWARFDebugInfo* info = DebugInfo();
1055 if (info)
1056 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001057 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1058 if (dwarf_cu)
1059 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001061 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062}
1063
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064Function *
Greg Clayton0fffff52010-09-24 05:15:53 +00001065SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066{
Greg Clayton8b4edba2015-08-14 20:02:05 +00001067 TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068
Greg Clayton8b4edba2015-08-14 20:02:05 +00001069 if (type_system)
1070 return type_system->ParseFunctionFromDWARF(sc, this, dwarf_cu, die);
1071 else
1072 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073}
1074
Greg Clayton9422dd62013-03-04 21:46:16 +00001075bool
1076SymbolFileDWARF::FixupAddress (Address &addr)
1077{
1078 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1079 if (debug_map_symfile)
1080 {
1081 return debug_map_symfile->LinkOSOAddress(addr);
1082 }
1083 // This is a normal DWARF file, no address fixups need to happen
1084 return true;
1085}
Greg Clayton1f746072012-08-29 21:13:06 +00001086lldb::LanguageType
1087SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1088{
1089 assert (sc.comp_unit);
1090 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1091 if (dwarf_cu)
1092 {
1093 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
Jim Ingham28eb5712012-10-12 17:34:26 +00001094 if (die)
Dawn Perchikd0e87eb2015-06-17 22:30:24 +00001095 return DWARFCompileUnit::LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0));
Greg Clayton1f746072012-08-29 21:13:06 +00001096 }
1097 return eLanguageTypeUnknown;
1098}
1099
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100size_t
1101SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1102{
1103 assert (sc.comp_unit);
1104 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001105 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001106 if (dwarf_cu)
1107 {
1108 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001109 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001111 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112 {
1113 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
Greg Clayton81c22f62011-10-19 18:09:39 +00001114 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001115 {
1116 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1117 ++functions_added;
1118 }
1119 }
1120 //FixupTypes();
1121 }
1122 return functions_added;
1123}
1124
1125bool
1126SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1127{
1128 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001129 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001130 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001131 {
Greg Claytonda2455b2012-11-01 17:28:37 +00001132 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133
Greg Claytonda2455b2012-11-01 17:28:37 +00001134 if (cu_die)
1135 {
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +00001136 const char * cu_comp_dir = resolveCompDir(cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr));
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001137
Greg Claytonda2455b2012-11-01 17:28:37 +00001138 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139
Greg Claytonda2455b2012-11-01 17:28:37 +00001140 // All file indexes in DWARF are one based and a file of index zero is
1141 // supposed to be the compile unit itself.
1142 support_files.Append (*sc.comp_unit);
1143
1144 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1145 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146 }
1147 return false;
1148}
1149
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001150bool
1151SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1152{
1153 assert (sc.comp_unit);
1154 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1155 if (dwarf_cu)
1156 {
1157 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1158 {
1159 UpdateExternalModuleListIfNeeded();
1160 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1161 {
1162 imported_modules.push_back(external_type_module.second.m_name);
1163 }
1164 }
1165 }
1166 return false;
1167}
1168
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001169struct ParseDWARFLineTableCallbackInfo
1170{
1171 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001172 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173};
1174
1175//----------------------------------------------------------------------
1176// ParseStatementTableCallback
1177//----------------------------------------------------------------------
1178static void
1179ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1180{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1182 {
1183 // Just started parsing the line table
1184 }
1185 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1186 {
1187 // Done parsing line table, nothing to do for the cleanup
1188 }
1189 else
1190 {
1191 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001192 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193
Greg Clayton9422dd62013-03-04 21:46:16 +00001194 // If this is our first time here, we need to create a
1195 // sequence container.
1196 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001198 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1199 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001200 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001201 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1202 state.address,
1203 state.line,
1204 state.column,
1205 state.file,
1206 state.is_stmt,
1207 state.basic_block,
1208 state.prologue_end,
1209 state.epilogue_begin,
1210 state.end_sequence);
1211 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001213 // First, put the current sequence into the line table.
1214 line_table->InsertSequence(info->sequence_ap.get());
1215 // Then, empty it to prepare for the next sequence.
1216 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 }
1219}
1220
1221bool
1222SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1223{
1224 assert (sc.comp_unit);
1225 if (sc.comp_unit->GetLineTable() != NULL)
1226 return true;
1227
Greg Clayton1f746072012-08-29 21:13:06 +00001228 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 if (dwarf_cu)
1230 {
1231 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001232 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 {
Greg Clayton129d12c2011-11-28 03:29:03 +00001234 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1235 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001236 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001237 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001238 if (line_table_ap.get())
1239 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001240 ParseDWARFLineTableCallbackInfo info;
1241 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001242 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001243 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001244 if (m_debug_map_symfile)
1245 {
1246 // We have an object file that has a line table with addresses
1247 // that are not linked. We need to link the line table and convert
1248 // the addresses that are relative to the .o file into addresses
1249 // for the main executable.
1250 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1251 }
1252 else
1253 {
1254 sc.comp_unit->SetLineTable(line_table_ap.release());
1255 return true;
1256 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001257 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 }
1259 }
1260 }
1261 return false;
1262}
1263
1264size_t
1265SymbolFileDWARF::ParseFunctionBlocks
1266(
1267 const SymbolContext& sc,
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001268 Block *parent_block,
Greg Clayton0fffff52010-09-24 05:15:53 +00001269 DWARFCompileUnit* dwarf_cu,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 const DWARFDebugInfoEntry *die,
1271 addr_t subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001272 uint32_t depth
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273)
1274{
1275 size_t blocks_added = 0;
1276 while (die != NULL)
1277 {
1278 dw_tag_t tag = die->Tag();
1279
1280 switch (tag)
1281 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001283 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 case DW_TAG_lexical_block:
1285 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001286 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001287 if (tag == DW_TAG_subprogram)
1288 {
1289 // Skip any DW_TAG_subprogram DIEs that are inside
1290 // of a normal or inlined functions. These will be
1291 // parsed on their own as separate entities.
1292
1293 if (depth > 0)
1294 break;
1295
1296 block = parent_block;
1297 }
1298 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001299 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001300 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001301 parent_block->AddChild(block_sp);
1302 block = block_sp.get();
1303 }
Greg Claytondd7feaf2011-08-12 17:54:33 +00001304 DWARFDebugRanges::RangeList ranges;
1305 const char *name = NULL;
1306 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 int decl_file = 0;
1309 int decl_line = 0;
1310 int decl_column = 0;
1311 int call_file = 0;
1312 int call_line = 0;
1313 int call_column = 0;
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001314 if (die->GetDIENamesAndRanges (this,
1315 dwarf_cu,
1316 name,
1317 mangled_name,
1318 ranges,
1319 decl_file, decl_line, decl_column,
1320 call_file, call_line, call_column))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 {
1322 if (tag == DW_TAG_subprogram)
1323 {
1324 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001325 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001327 else if (tag == DW_TAG_inlined_subroutine)
1328 {
1329 // We get called here for inlined subroutines in two ways.
1330 // The first time is when we are making the Function object
1331 // for this inlined concrete instance. Since we're creating a top level block at
1332 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1333 // adjust the containing address.
1334 // The second time is when we are parsing the blocks inside the function that contains
1335 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1336 // function the offset will be for that function.
1337 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1338 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001339 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001340 }
1341 }
Greg Clayton103f3092015-01-15 03:04:37 +00001342
1343 const size_t num_ranges = ranges.GetSize();
1344 for (size_t i = 0; i<num_ranges; ++i)
1345 {
1346 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1347 const addr_t range_base = range.GetRangeBase();
1348 if (range_base >= subprogram_low_pc)
1349 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1350 else
1351 {
1352 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message",
1353 block->GetID(),
1354 range_base,
1355 range.GetRangeEnd(),
1356 subprogram_low_pc);
1357 }
1358 }
1359 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360
1361 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1362 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001363 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001365 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1366 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367
Greg Clayton7b0992d2013-04-18 22:45:39 +00001368 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001370 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1371 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001373 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374 }
1375
1376 ++blocks_added;
1377
Greg Claytondd7feaf2011-08-12 17:54:33 +00001378 if (die->HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001380 blocks_added += ParseFunctionBlocks (sc,
1381 block,
1382 dwarf_cu,
1383 die->GetFirstChild(),
1384 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001385 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386 }
1387 }
1388 }
1389 break;
1390 default:
1391 break;
1392 }
1393
Greg Claytondd7feaf2011-08-12 17:54:33 +00001394 // Only parse siblings of the block if we are not at depth zero. A depth
1395 // of zero indicates we are currently parsing the top level
1396 // DW_TAG_subprogram DIE
1397
1398 if (depth == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001399 die = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001400 else
1401 die = die->GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001402 }
1403 return blocks_added;
1404}
1405
Greg Claytonf0705c82011-10-22 03:33:13 +00001406bool
Greg Claytonc4ffd662013-03-08 01:37:30 +00001407SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1408 const DWARFDebugInfoEntry *parent_die)
1409{
1410 if (parent_die)
1411 {
1412 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1413 {
1414 dw_tag_t tag = die->Tag();
1415 bool check_virtuality = false;
1416 switch (tag)
1417 {
1418 case DW_TAG_inheritance:
1419 case DW_TAG_subprogram:
1420 check_virtuality = true;
1421 break;
1422 default:
1423 break;
1424 }
1425 if (check_virtuality)
1426 {
1427 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1428 return true;
1429 }
1430 }
1431 }
1432 return false;
1433}
1434
Greg Clayton99558cc42015-08-24 23:46:31 +00001435CompilerDeclContext
1436SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437{
Greg Clayton8b4edba2015-08-14 20:02:05 +00001438 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00001440 DWARFDebugInfo* debug_info = DebugInfo();
1441 if (debug_info)
1442 {
1443 DWARFCompileUnitSP cu_sp;
1444 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1445 if (die)
1446 {
1447 TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType());
1448 if (type_system)
Greg Clayton99558cc42015-08-24 23:46:31 +00001449 return type_system->GetDeclContextForUIDFromDWARF(this, cu_sp.get(), die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001450 }
1451 }
Sean Callanan72e49402011-08-05 23:43:37 +00001452 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001453 return CompilerDeclContext();
Sean Callanan72e49402011-08-05 23:43:37 +00001454}
1455
Greg Clayton99558cc42015-08-24 23:46:31 +00001456CompilerDeclContext
1457SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid)
Sean Callanan72e49402011-08-05 23:43:37 +00001458{
Greg Clayton81c22f62011-10-19 18:09:39 +00001459 if (UserIDMatches(type_uid))
Greg Clayton8b4edba2015-08-14 20:02:05 +00001460 {
1461 DWARFDebugInfo* debug_info = DebugInfo();
1462 if (debug_info)
1463 {
1464 DWARFCompileUnitSP cu_sp;
1465 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1466 if (die)
1467 {
1468 TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType());
1469 if (type_system)
Greg Clayton99558cc42015-08-24 23:46:31 +00001470 return type_system->GetDeclContextContainingUIDFromDWARF(this, cu_sp.get(), die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001471 }
1472 }
1473 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001474 return CompilerDeclContext();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475}
1476
Greg Clayton99558cc42015-08-24 23:46:31 +00001477
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001479SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480{
Greg Clayton81c22f62011-10-19 18:09:39 +00001481 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001483 DWARFDebugInfo* debug_info = DebugInfo();
1484 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001485 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001486 DWARFCompileUnitSP cu_sp;
1487 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
Greg Claytoncab36a32011-12-08 05:16:30 +00001488 const bool assert_not_being_parsed = true;
1489 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
Greg Claytonca512b32011-01-14 04:54:56 +00001490 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 }
1492 return NULL;
1493}
1494
Greg Claytoncab36a32011-12-08 05:16:30 +00001495Type*
1496SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001497{
Greg Claytoncab36a32011-12-08 05:16:30 +00001498 if (die != NULL)
1499 {
Greg Clayton5160ce52013-03-27 23:08:40 +00001500 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00001501 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001502 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00001503 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1504 die->GetOffset(),
1505 DW_TAG_value_to_name(die->Tag()),
1506 die->GetName(this, cu));
Greg Clayton3bffb082011-12-10 02:15:28 +00001507
Greg Claytoncab36a32011-12-08 05:16:30 +00001508 // We might be coming in in the middle of a type tree (a class
1509 // withing a class, an enum within a class), so parse any needed
1510 // parent DIEs before we get to this one...
1511 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1512 switch (decl_ctx_die->Tag())
1513 {
1514 case DW_TAG_structure_type:
1515 case DW_TAG_union_type:
1516 case DW_TAG_class_type:
1517 {
1518 // Get the type, which could be a forward declaration
Greg Clayton3bffb082011-12-10 02:15:28 +00001519 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001520 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00001521 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1522 die->GetOffset(),
1523 DW_TAG_value_to_name(die->Tag()),
1524 die->GetName(this, cu),
1525 decl_ctx_die->GetOffset());
Greg Clayton219cf312012-03-30 00:51:13 +00001526//
1527// Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1528// if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1529// {
1530// if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001531// GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton219cf312012-03-30 00:51:13 +00001532// "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1533// die->GetOffset(),
1534// DW_TAG_value_to_name(die->Tag()),
1535// die->GetName(this, cu),
1536// decl_ctx_die->GetOffset());
1537// // Ask the type to complete itself if it already hasn't since if we
1538// // want a function (method or static) from a class, the class must
1539// // create itself and add it's own methods and class functions.
1540// if (parent_type)
Greg Clayton99558cc42015-08-24 23:46:31 +00001541// parent_type->GetFullCompilerType ();
Greg Clayton219cf312012-03-30 00:51:13 +00001542// }
Greg Claytoncab36a32011-12-08 05:16:30 +00001543 }
1544 break;
1545
1546 default:
1547 break;
1548 }
1549 return ResolveType (cu, die);
1550 }
1551 return NULL;
1552}
1553
Greg Clayton6beaaa62011-01-17 03:46:26 +00001554// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1555// SymbolFileDWARF objects to detect if this DWARF file is the one that
1556// can resolve a clang_type.
1557bool
Greg Claytona1e5dc82015-08-11 22:53:00 +00001558SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001559{
Greg Claytona1e5dc82015-08-11 22:53:00 +00001560 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +00001561 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001562 return die != NULL;
1563}
1564
1565
Greg Clayton57ee3062013-07-11 22:46:58 +00001566bool
Greg Clayton6dc8d582015-08-18 22:32:36 +00001567SymbolFileDWARF::CompleteType (CompilerType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001568{
1569 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Claytona1e5dc82015-08-11 22:53:00 +00001570 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +00001571 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001572 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001573 {
1574 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00001575 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00001576 }
1577 // Once we start resolving this type, remove it from the forward declaration
1578 // map in case anyone child members or other types require this type to get resolved.
1579 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1580 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00001581 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001582
Greg Clayton450e3f32010-10-12 02:24:53 +00001583 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton53eb1c22012-04-02 22:59:12 +00001584 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
Greg Clayton1be10fc2010-09-29 01:12:09 +00001585 Type *type = m_die_to_type.lookup (die);
1586
Greg Clayton5160ce52013-03-27 23:08:40 +00001587 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001588 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001589 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00001590 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Claytond61c0fc2012-04-23 22:55:20 +00001591 MakeUserID(die->GetOffset()),
Greg Clayton8b4edba2015-08-14 20:02:05 +00001592 DW_TAG_value_to_name(die->Tag()),
Greg Claytond61c0fc2012-04-23 22:55:20 +00001593 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001594 assert (clang_type);
1595 DWARFDebugInfoEntry::Attributes attributes;
1596
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001597
Greg Clayton8b4edba2015-08-14 20:02:05 +00001598 TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001599
Greg Clayton8b4edba2015-08-14 20:02:05 +00001600 if (type_system)
Greg Clayton6dc8d582015-08-18 22:32:36 +00001601 return type_system->CompleteTypeFromDWARF (this, dwarf_cu, die, type, clang_type);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001602
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001603 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001604}
1605
Greg Clayton8b4edba2015-08-14 20:02:05 +00001606void
1607SymbolFileDWARF::ClearDIEBeingParsed (const DWARFDebugInfoEntry* type_die)
1608{
1609 if (type_die)
1610 {
1611 if (m_die_to_type.lookup (type_die) == DIE_IS_BEING_PARSED)
1612 m_die_to_type[type_die] = nullptr;
1613 }
1614}
1615Type*
1616SymbolFileDWARF::GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const
1617{
1618 if (type_die)
1619 {
1620 Type *type = m_die_to_type.lookup (type_die);
1621 if (type != DIE_IS_BEING_PARSED)
1622 return type;
1623 }
1624 return nullptr;
1625}
1626
Greg Claytonc685f8e2010-09-15 04:15:46 +00001627Type*
Greg Clayton53eb1c22012-04-02 22:59:12 +00001628SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
Greg Claytonc685f8e2010-09-15 04:15:46 +00001629{
1630 if (type_die != NULL)
1631 {
Greg Clayton594e5ed2010-09-27 21:07:38 +00001632 Type *type = m_die_to_type.lookup (type_die);
Greg Claytoncab36a32011-12-08 05:16:30 +00001633
Greg Claytonc685f8e2010-09-15 04:15:46 +00001634 if (type == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00001635 type = GetTypeForDIE (dwarf_cu, type_die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00001636
Greg Clayton24739922010-10-13 03:15:28 +00001637 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00001638 {
1639 if (type != DIE_IS_BEING_PARSED)
1640 return type;
1641
1642 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton53eb1c22012-04-02 22:59:12 +00001643 type_die->GetOffset(),
1644 DW_TAG_value_to_name(type_die->Tag()),
1645 type_die->GetName(this, dwarf_cu));
Jim Inghamc3549282012-01-11 02:21:12 +00001646
1647 }
1648 else
1649 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001650 }
1651 return NULL;
1652}
1653
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001654CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00001655SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001656{
1657 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00001658 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 {
1660 // The symbol vendor doesn't know about this compile unit, we
1661 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00001662 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001663 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001664 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001665}
1666
Greg Clayton8b4edba2015-08-14 20:02:05 +00001667size_t
1668SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets)
1669{
1670 method_die_offsets.clear();
1671 if (m_using_apple_tables)
1672 {
1673 if (m_apple_objc_ap.get())
1674 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
1675 }
1676 else
1677 {
1678 if (!m_indexed)
1679 Index ();
1680
1681 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1682 }
1683 return method_die_offsets.size();
1684}
1685
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686bool
Greg Clayton53eb1c22012-04-02 22:59:12 +00001687SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688{
Greg Clayton72310352013-02-23 04:12:47 +00001689 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001690 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00001691 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001692
Greg Clayton81c22f62011-10-19 18:09:39 +00001693 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001694 if (sc.function == NULL)
Greg Clayton53eb1c22012-04-02 22:59:12 +00001695 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
Jim Ingham4cda6e02011-10-07 22:23:45 +00001696
1697 if (sc.function)
1698 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001699 sc.module_sp = sc.function->CalculateSymbolContextModule();
Jim Ingham4cda6e02011-10-07 22:23:45 +00001700 return true;
1701 }
1702
1703 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704}
1705
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001706void
1707SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
1708{
1709 if (m_fetched_external_modules)
1710 return;
1711 m_fetched_external_modules = true;
1712
1713 DWARFDebugInfo * debug_info = DebugInfo();
1714 debug_info->GetNumCompileUnits();
1715
1716 const uint32_t num_compile_units = GetNumCompileUnits();
1717 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1718 {
1719 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1720
1721 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
1722 if (die && die->HasChildren() == false)
1723 {
1724 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX);
1725 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX);
1726
1727 if (name_strp != UINT64_MAX)
1728 {
1729 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
1730 {
1731 const char *name = get_debug_str_data().PeekCStr(name_strp);
1732 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
1733 if (name || dwo_path)
1734 {
1735 ModuleSP module_sp;
1736 if (dwo_path)
1737 {
1738 ModuleSpec dwo_module_spec;
1739 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
1740 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
1741 //printf ("Loading dwo = '%s'\n", dwo_path);
1742 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
1743 }
1744
1745 if (dwo_path_strp != LLDB_INVALID_UID)
1746 {
1747 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
1748 }
1749 else
1750 {
1751 // This hack should be removed promptly once clang emits both.
1752 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
1753 }
1754 }
1755 }
1756 }
1757 }
1758 }
1759}
Greg Clayton2501e5e2015-01-15 02:59:20 +00001760
1761SymbolFileDWARF::GlobalVariableMap &
1762SymbolFileDWARF::GetGlobalAranges()
1763{
1764 if (!m_global_aranges_ap)
1765 {
1766 m_global_aranges_ap.reset (new GlobalVariableMap());
1767
1768 ModuleSP module_sp = GetObjectFile()->GetModule();
1769 if (module_sp)
1770 {
1771 const size_t num_cus = module_sp->GetNumCompileUnits();
1772 for (size_t i = 0; i < num_cus; ++i)
1773 {
1774 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1775 if (cu_sp)
1776 {
1777 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1778 if (globals_sp)
1779 {
1780 const size_t num_globals = globals_sp->GetSize();
1781 for (size_t g = 0; g < num_globals; ++g)
1782 {
1783 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1784 if (var_sp && !var_sp->GetLocationIsConstantValueData())
1785 {
1786 const DWARFExpression &location = var_sp->LocationExpression();
1787 Value location_result;
1788 Error error;
1789 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
1790 {
1791 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
1792 {
1793 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
1794 lldb::addr_t byte_size = 1;
1795 if (var_sp->GetType())
1796 byte_size = var_sp->GetType()->GetByteSize();
1797 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
1798 }
1799 }
1800 }
1801 }
1802 }
1803 }
1804 }
1805 }
1806 m_global_aranges_ap->Sort();
1807 }
1808 return *m_global_aranges_ap;
1809}
1810
1811
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001812uint32_t
1813SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1814{
1815 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00001816 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001817 static_cast<void*>(so_addr.GetSection().get()),
1818 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001819 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00001820 if (resolve_scope & ( eSymbolContextCompUnit |
1821 eSymbolContextFunction |
1822 eSymbolContextBlock |
1823 eSymbolContextLineEntry |
1824 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001825 {
1826 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1827
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001828 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001829 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001831 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00001832 if (cu_offset == DW_INVALID_OFFSET)
1833 {
1834 // Global variables are not in the compile unit address ranges. The only way to
1835 // currently find global variables is to iterate over the .debug_pubnames or the
1836 // __apple_names table and find all items in there that point to DW_TAG_variable
1837 // DIEs and then find the address that matches.
1838 if (resolve_scope & eSymbolContextVariable)
1839 {
1840 GlobalVariableMap &map = GetGlobalAranges();
1841 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
1842 if (entry && entry->data)
1843 {
1844 Variable *variable = entry->data;
1845 SymbolContextScope *scc = variable->GetSymbolContextScope();
1846 if (scc)
1847 {
1848 scc->CalculateSymbolContext(&sc);
1849 sc.variable = variable;
1850 }
1851 return sc.GetResolvedMask();
1852 }
1853 }
1854 }
1855 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001856 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001857 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton53eb1c22012-04-02 22:59:12 +00001858 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1859 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001861 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001862 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001863 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001864 resolved |= eSymbolContextCompUnit;
1865
Greg Clayton6ab80132012-12-12 17:30:52 +00001866 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001867 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1868 {
1869 DWARFDebugInfoEntry *function_die = NULL;
1870 DWARFDebugInfoEntry *block_die = NULL;
1871 if (resolve_scope & eSymbolContextBlock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001873 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
1874 }
1875 else
1876 {
1877 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
1878 }
1879
1880 if (function_die != NULL)
1881 {
1882 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
1883 if (sc.function == NULL)
1884 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
1885 }
1886 else
1887 {
1888 // We might have had a compile unit that had discontiguous
1889 // address ranges where the gaps are symbols that don't have
1890 // any debug info. Discontiguous compile unit address ranges
1891 // should only happen when there aren't other functions from
1892 // other compile units in these gaps. This helps keep the size
1893 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00001894 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001895 }
1896
1897 if (sc.function != NULL)
1898 {
1899 resolved |= eSymbolContextFunction;
1900
1901 if (resolve_scope & eSymbolContextBlock)
1902 {
1903 Block& block = sc.function->GetBlock (true);
1904
1905 if (block_die != NULL)
1906 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
1907 else
1908 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
1909 if (sc.block)
1910 resolved |= eSymbolContextBlock;
1911 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001912 }
1913 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001914
1915 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
1916 {
1917 LineTable *line_table = sc.comp_unit->GetLineTable();
1918 if (line_table != NULL)
1919 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001920 // And address that makes it into this function should be in terms
1921 // of this debug file if there is no debug map, or it will be an
1922 // address in the .o file which needs to be fixed up to be in terms
1923 // of the debug map executable. Either way, calling FixupAddress()
1924 // will work for us.
1925 Address exe_so_addr (so_addr);
1926 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00001927 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001928 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00001929 {
1930 resolved |= eSymbolContextLineEntry;
1931 }
1932 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001933 }
1934 }
1935
1936 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
1937 {
1938 // We might have had a compile unit that had discontiguous
1939 // address ranges where the gaps are symbols that don't have
1940 // any debug info. Discontiguous compile unit address ranges
1941 // should only happen when there aren't other functions from
1942 // other compile units in these gaps. This helps keep the size
1943 // of the aranges down.
1944 sc.comp_unit = NULL;
1945 resolved &= ~eSymbolContextCompUnit;
1946 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00001948 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001950 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
1951 cu_offset,
1952 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 }
1954 }
1955 }
1956 }
1957 }
1958 return resolved;
1959}
1960
1961
1962
1963uint32_t
1964SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1965{
1966 const uint32_t prev_size = sc_list.GetSize();
1967 if (resolve_scope & eSymbolContextCompUnit)
1968 {
1969 DWARFDebugInfo* debug_info = DebugInfo();
1970 if (debug_info)
1971 {
1972 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00001973 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001974
Greg Clayton53eb1c22012-04-02 22:59:12 +00001975 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001976 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001977 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00001978 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00001979 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001980 if (check_inlines || file_spec_matches_cu_file_spec)
1981 {
1982 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00001983 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001984 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001985 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001986 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987
Greg Clayton526a4ae2012-05-16 22:09:01 +00001988 // If we are looking for inline functions only and we don't
1989 // find it in the support files, we are done.
1990 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001991 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001992 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
1993 if (file_idx == UINT32_MAX)
1994 continue;
1995 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996
Greg Clayton526a4ae2012-05-16 22:09:01 +00001997 if (line != 0)
1998 {
1999 LineTable *line_table = sc.comp_unit->GetLineTable();
2000
2001 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002003 // We will have already looked up the file index if
2004 // we are searching for inline entries.
2005 if (!check_inlines)
2006 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007
Greg Clayton526a4ae2012-05-16 22:09:01 +00002008 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002009 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002010 uint32_t found_line;
2011 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2012 found_line = sc.line_entry.line;
2013
2014 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002015 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002016 sc.function = NULL;
2017 sc.block = NULL;
2018 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002020 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2021 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00002023 DWARFDebugInfoEntry *function_die = NULL;
2024 DWARFDebugInfoEntry *block_die = NULL;
2025 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002026
Greg Clayton526a4ae2012-05-16 22:09:01 +00002027 if (function_die != NULL)
2028 {
2029 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2030 if (sc.function == NULL)
2031 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2032 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002033
Greg Clayton526a4ae2012-05-16 22:09:01 +00002034 if (sc.function != NULL)
2035 {
2036 Block& block = sc.function->GetBlock (true);
2037
2038 if (block_die != NULL)
2039 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
Jason Molenda60db6e42014-10-16 01:40:16 +00002040 else if (function_die != NULL)
Greg Clayton526a4ae2012-05-16 22:09:01 +00002041 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2042 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002043 }
2044 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045
Greg Clayton526a4ae2012-05-16 22:09:01 +00002046 sc_list.Append(sc);
2047 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2048 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049 }
2050 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00002051 else if (file_spec_matches_cu_file_spec && !check_inlines)
2052 {
2053 // only append the context if we aren't looking for inline call sites
2054 // by file and line and if the file spec matches that of the compile unit
2055 sc_list.Append(sc);
2056 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002057 }
2058 else if (file_spec_matches_cu_file_spec && !check_inlines)
2059 {
2060 // only append the context if we aren't looking for inline call sites
2061 // by file and line and if the file spec matches that of the compile unit
2062 sc_list.Append(sc);
2063 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002064
Greg Clayton526a4ae2012-05-16 22:09:01 +00002065 if (!check_inlines)
2066 break;
2067 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068 }
2069 }
2070 }
2071 }
2072 return sc_list.GetSize() - prev_size;
2073}
2074
2075void
2076SymbolFileDWARF::Index ()
2077{
2078 if (m_indexed)
2079 return;
2080 m_indexed = true;
2081 Timer scoped_timer (__PRETTY_FUNCTION__,
2082 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00002083 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002084
2085 DWARFDebugInfo* debug_info = DebugInfo();
2086 if (debug_info)
2087 {
2088 uint32_t cu_idx = 0;
2089 const uint32_t num_compile_units = GetNumCompileUnits();
2090 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2091 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002092 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002093
Greg Clayton53eb1c22012-04-02 22:59:12 +00002094 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002095
Greg Clayton53eb1c22012-04-02 22:59:12 +00002096 dwarf_cu->Index (cu_idx,
2097 m_function_basename_index,
2098 m_function_fullname_index,
2099 m_function_method_index,
2100 m_function_selector_index,
2101 m_objc_class_selectors_index,
2102 m_global_index,
2103 m_type_index,
2104 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002105
2106 // Keep memory down by clearing DIEs if this generate function
2107 // caused them to be parsed
2108 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002109 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002110 }
2111
Greg Claytond4a2b372011-09-12 23:21:58 +00002112 m_function_basename_index.Finalize();
2113 m_function_fullname_index.Finalize();
2114 m_function_method_index.Finalize();
2115 m_function_selector_index.Finalize();
2116 m_objc_class_selectors_index.Finalize();
2117 m_global_index.Finalize();
2118 m_type_index.Finalize();
2119 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002120
Greg Clayton24739922010-10-13 03:15:28 +00002121#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002122 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002123 s.Printf ("DWARF index for '%s':",
2124 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002125 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2126 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2127 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2128 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2129 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2130 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002131 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00002132 s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002133#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002134 }
2135}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002136
2137bool
Greg Clayton99558cc42015-08-24 23:46:31 +00002138SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx)
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002139{
Greg Clayton99558cc42015-08-24 23:46:31 +00002140 if (decl_ctx == nullptr || !decl_ctx->IsValid())
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002141 {
2142 // Invalid namespace decl which means we aren't matching only things
2143 // in this symbol file, so return true to indicate it matches this
2144 // symbol file.
2145 return true;
2146 }
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002147
Greg Clayton99558cc42015-08-24 23:46:31 +00002148 if ((TypeSystem *)&GetClangASTContext() == decl_ctx->GetTypeSystem())
2149 return true; // The type systems match, return true
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002150
2151 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002152 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002153
2154 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002155 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002156
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002157 return false;
2158}
2159
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002160uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002161SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002162{
Greg Clayton5160ce52013-03-27 23:08:40 +00002163 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002164
2165 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002166 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002167 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00002168 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002169 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002170 append, max_matches);
2171
Greg Clayton99558cc42015-08-24 23:46:31 +00002172 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002173 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002174
Greg Claytonc685f8e2010-09-15 04:15:46 +00002175 DWARFDebugInfo* info = DebugInfo();
2176 if (info == NULL)
2177 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002178
2179 // If we aren't appending the results to this list, then clear the list
2180 if (!append)
2181 variables.Clear();
2182
2183 // Remember how many variables are in the list before we search in case
2184 // we are appending the results to a variable list.
2185 const uint32_t original_size = variables.GetSize();
2186
Greg Claytond4a2b372011-09-12 23:21:58 +00002187 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002188
Greg Clayton97fbc342011-10-20 22:30:33 +00002189 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002190 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002191 if (m_apple_names_ap.get())
2192 {
2193 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00002194 llvm::StringRef basename;
2195 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002196
Jim Inghamfa39bb42014-10-25 00:33:55 +00002197 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename))
2198 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002199
Jim Inghamfa39bb42014-10-25 00:33:55 +00002200 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00002201 }
Greg Clayton7f995132011-10-04 22:41:51 +00002202 }
2203 else
2204 {
2205 // Index the DWARF if we haven't already
2206 if (!m_indexed)
2207 Index ();
2208
2209 m_global_index.Find (name, die_offsets);
2210 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002211
Greg Clayton437a1352012-04-09 22:43:43 +00002212 const size_t num_die_matches = die_offsets.size();
2213 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002214 {
Greg Clayton7f995132011-10-04 22:41:51 +00002215 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002216 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002217 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002218
Greg Claytond4a2b372011-09-12 23:21:58 +00002219 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton7f995132011-10-04 22:41:51 +00002220 DWARFCompileUnit* dwarf_cu = NULL;
2221 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton437a1352012-04-09 22:43:43 +00002222 bool done = false;
2223 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002224 {
2225 const dw_offset_t die_offset = die_offsets[i];
2226 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002227
Greg Clayton95d87902011-11-11 03:16:25 +00002228 if (die)
2229 {
Greg Clayton437a1352012-04-09 22:43:43 +00002230 switch (die->Tag())
2231 {
2232 default:
2233 case DW_TAG_subprogram:
2234 case DW_TAG_inlined_subroutine:
2235 case DW_TAG_try_block:
2236 case DW_TAG_catch_block:
2237 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002238
Greg Clayton437a1352012-04-09 22:43:43 +00002239 case DW_TAG_variable:
2240 {
2241 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002242
Greg Clayton99558cc42015-08-24 23:46:31 +00002243 if (parent_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00002244 {
2245 TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
2246
Greg Clayton99558cc42015-08-24 23:46:31 +00002247 if (type_system)
2248 {
2249 CompilerDeclContext actual_parent_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, dwarf_cu, die);
2250 if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx)
2251 continue;
2252 }
Greg Clayton8b4edba2015-08-14 20:02:05 +00002253 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002254
Greg Clayton437a1352012-04-09 22:43:43 +00002255 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256
Greg Clayton437a1352012-04-09 22:43:43 +00002257 if (variables.GetSize() - original_size >= max_matches)
2258 done = true;
2259 }
2260 break;
2261 }
Greg Clayton95d87902011-11-11 03:16:25 +00002262 }
2263 else
2264 {
2265 if (m_using_apple_tables)
2266 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002267 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2268 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002269 }
2270 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002271 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 }
2273
2274 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002275 const uint32_t num_matches = variables.GetSize() - original_size;
2276 if (log && num_matches > 0)
2277 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002278 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002279 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002280 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002281 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002282 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002283 num_matches);
2284 }
2285 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002286}
2287
2288uint32_t
2289SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2290{
Greg Clayton5160ce52013-03-27 23:08:40 +00002291 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002292
Greg Clayton21f2a492011-10-06 00:09:08 +00002293 if (log)
2294 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002295 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002296 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002297 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002298 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002299 }
2300
Greg Claytonc685f8e2010-09-15 04:15:46 +00002301 DWARFDebugInfo* info = DebugInfo();
2302 if (info == NULL)
2303 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002304
2305 // If we aren't appending the results to this list, then clear the list
2306 if (!append)
2307 variables.Clear();
2308
2309 // Remember how many variables are in the list before we search in case
2310 // we are appending the results to a variable list.
2311 const uint32_t original_size = variables.GetSize();
2312
Greg Clayton7f995132011-10-04 22:41:51 +00002313 DIEArray die_offsets;
2314
Greg Clayton97fbc342011-10-20 22:30:33 +00002315 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002316 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002317 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002318 {
2319 DWARFMappedHash::DIEInfoArray hash_data_array;
2320 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2321 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2322 }
Greg Clayton7f995132011-10-04 22:41:51 +00002323 }
2324 else
2325 {
2326 // Index the DWARF if we haven't already
2327 if (!m_indexed)
2328 Index ();
2329
2330 m_global_index.Find (regex, die_offsets);
2331 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002332
Greg Claytonc685f8e2010-09-15 04:15:46 +00002333 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002334 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002335 assert (sc.module_sp);
2336
Greg Claytond4a2b372011-09-12 23:21:58 +00002337 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytonc685f8e2010-09-15 04:15:46 +00002338 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00002339 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002340 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002341 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002342 DWARFDebugInfo* debug_info = DebugInfo();
2343 for (size_t i=0; i<num_matches; ++i)
2344 {
2345 const dw_offset_t die_offset = die_offsets[i];
2346 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00002347
2348 if (die)
2349 {
2350 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002351
Greg Clayton95d87902011-11-11 03:16:25 +00002352 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002353
Greg Clayton95d87902011-11-11 03:16:25 +00002354 if (variables.GetSize() - original_size >= max_matches)
2355 break;
2356 }
2357 else
2358 {
2359 if (m_using_apple_tables)
2360 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002361 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2362 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002363 }
2364 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002366 }
2367
2368 // Return the number of variable that were appended to the list
2369 return variables.GetSize() - original_size;
2370}
2371
Greg Claytonaa044962011-10-13 00:59:38 +00002372
Jim Ingham4cda6e02011-10-07 22:23:45 +00002373bool
2374SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2375 DWARFCompileUnit *&dwarf_cu,
Pavel Labatha73d6572015-03-13 10:22:00 +00002376 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00002377 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002378{
Greg Claytonaa044962011-10-13 00:59:38 +00002379 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Pavel Labatha73d6572015-03-13 10:22:00 +00002380 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00002381}
2382
2383
2384bool
2385SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2386 const DWARFDebugInfoEntry *die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002387 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00002388 SymbolContextList& sc_list)
2389{
Greg Clayton9e315582011-09-02 04:03:59 +00002390 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002391
2392 if (die == NULL)
2393 return false;
2394
Jim Ingham4cda6e02011-10-07 22:23:45 +00002395 // If we were passed a die that is not a function, just return false...
Pavel Labatha73d6572015-03-13 10:22:00 +00002396 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002397 return false;
2398
2399 const DWARFDebugInfoEntry* inlined_die = NULL;
2400 if (die->Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002401 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002402 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002403
Jim Ingham4cda6e02011-10-07 22:23:45 +00002404 while ((die = die->GetParent()) != NULL)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002405 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002406 if (die->Tag() == DW_TAG_subprogram)
2407 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002408 }
2409 }
Jason Molenda60db6e42014-10-16 01:40:16 +00002410 assert (die && die->Tag() == DW_TAG_subprogram);
Greg Claytonaa044962011-10-13 00:59:38 +00002411 if (GetFunction (cu, die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002412 {
2413 Address addr;
2414 // Parse all blocks if needed
2415 if (inlined_die)
2416 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002417 Block &function_block = sc.function->GetBlock (true);
2418 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset()));
2419 if (sc.block == NULL)
2420 sc.block = function_block.FindBlockByID (inlined_die->GetOffset());
2421 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002422 addr.Clear();
2423 }
2424 else
2425 {
2426 sc.block = NULL;
2427 addr = sc.function->GetAddressRange().GetBaseAddress();
2428 }
2429
2430 if (addr.IsValid())
2431 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002432 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002433 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002434 }
2435 }
2436
Greg Claytonaa044962011-10-13 00:59:38 +00002437 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002438}
2439
Greg Clayton7f995132011-10-04 22:41:51 +00002440void
2441SymbolFileDWARF::FindFunctions (const ConstString &name,
2442 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002443 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002444 SymbolContextList& sc_list)
2445{
Greg Claytond4a2b372011-09-12 23:21:58 +00002446 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002447 if (name_to_die.Find (name, die_offsets))
2448 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002449 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002450 }
2451}
2452
2453
2454void
2455SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2456 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002457 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002458 SymbolContextList& sc_list)
2459{
2460 DIEArray die_offsets;
2461 if (name_to_die.Find (regex, die_offsets))
2462 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002463 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002464 }
2465}
2466
2467
2468void
2469SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2470 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00002471 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002472 SymbolContextList& sc_list)
2473{
2474 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002475 DWARFMappedHash::DIEInfoArray hash_data_array;
2476 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002477 {
Greg Claytond1767f02011-12-08 02:13:16 +00002478 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00002479 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002480 }
2481}
2482
2483void
2484SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00002485 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002486 SymbolContextList& sc_list)
2487{
2488 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002489 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002490 {
Greg Clayton7f995132011-10-04 22:41:51 +00002491 DWARFCompileUnit* dwarf_cu = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00002492 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002493 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002494 const dw_offset_t die_offset = die_offsets[i];
Pavel Labatha73d6572015-03-13 10:22:00 +00002495 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002496 }
2497 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002498}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002499
Jim Ingham4cda6e02011-10-07 22:23:45 +00002500bool
2501SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2502 const DWARFCompileUnit *dwarf_cu,
2503 uint32_t name_type_mask,
2504 const char *partial_name,
2505 const char *base_name_start,
2506 const char *base_name_end)
2507{
Greg Claytonfbea0f62012-11-15 18:05:43 +00002508 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
2509 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002510 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00002511 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (dwarf_cu, die);
2512
2513 if (decl_ctx_die == nullptr)
Greg Claytonf0705c82011-10-22 03:33:13 +00002514 return false;
Greg Clayton8b4edba2015-08-14 20:02:05 +00002515
2516 const dw_tag_t decl_ctx_tag = decl_ctx_die->Tag();
2517
2518 bool is_cxx_method = (decl_ctx_tag == DW_TAG_structure_type) || (decl_ctx_tag == DW_TAG_class_type);
Greg Claytonf0705c82011-10-22 03:33:13 +00002519
Greg Claytonfbea0f62012-11-15 18:05:43 +00002520 if (name_type_mask == eFunctionNameTypeMethod)
2521 {
2522 if (is_cxx_method == false)
2523 return false;
2524 }
2525
2526 if (name_type_mask == eFunctionNameTypeBase)
2527 {
2528 if (is_cxx_method == true)
2529 return false;
2530 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002531 }
2532
2533 // Now we need to check whether the name we got back for this type matches the extra specifications
2534 // that were in the name we're looking up:
2535 if (base_name_start != partial_name || *base_name_end != '\0')
2536 {
2537 // First see if the stuff to the left matches the full name. To do that let's see if
2538 // we can pull out the mips linkage name attribute:
2539
2540 Mangled best_name;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002541 DWARFDebugInfoEntry::Attributes attributes;
Greg Claytonfbea0f62012-11-15 18:05:43 +00002542 DWARFFormValue form_value;
Tamas Berghammerb7c64652015-08-25 11:45:46 +00002543 die->GetAttributes(this, dwarf_cu, DWARFFormValue::FixedFormSizes(), attributes);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002544 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
Greg Clayton71415542012-12-08 00:24:40 +00002545 if (idx == UINT32_MAX)
2546 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002547 if (idx != UINT32_MAX)
2548 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002549 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2550 {
Greg Claytonfbea0f62012-11-15 18:05:43 +00002551 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
2552 if (mangled_name)
2553 best_name.SetValue (ConstString(mangled_name), true);
2554 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002555 }
Greg Claytonfbea0f62012-11-15 18:05:43 +00002556
2557 if (!best_name)
2558 {
2559 idx = attributes.FindAttributeIndex(DW_AT_name);
2560 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
2561 {
2562 const char *name = form_value.AsCString(&get_debug_str_data());
2563 best_name.SetValue (ConstString(name), false);
2564 }
2565 }
2566
Greg Claytonddaf6a72015-07-08 22:32:23 +00002567 const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType();
2568 if (best_name.GetDemangledName(cu_language))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002569 {
Greg Claytonddaf6a72015-07-08 22:32:23 +00002570 const char *demangled = best_name.GetDemangledName(cu_language).GetCString();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002571 if (demangled)
2572 {
2573 std::string name_no_parens(partial_name, base_name_end - partial_name);
Jim Ingham85c13d72012-03-02 02:24:42 +00002574 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
2575 if (partial_in_demangled == NULL)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002576 return false;
Jim Ingham85c13d72012-03-02 02:24:42 +00002577 else
2578 {
2579 // Sort out the case where our name is something like "Process::Destroy" and the match is
2580 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
2581 // namespace boundaries...
2582
2583 if (partial_name[0] == ':' && partial_name[1] == ':')
2584 {
2585 // The partial name was already on a namespace boundary so all matches are good.
2586 return true;
2587 }
2588 else if (partial_in_demangled == demangled)
2589 {
2590 // They both start the same, so this is an good match.
2591 return true;
2592 }
2593 else
2594 {
2595 if (partial_in_demangled - demangled == 1)
2596 {
2597 // Only one character difference, can't be a namespace boundary...
2598 return false;
2599 }
2600 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
2601 {
2602 // We are on a namespace boundary, so this is also good.
2603 return true;
2604 }
2605 else
2606 return false;
2607 }
2608 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002609 }
2610 }
2611 }
2612
2613 return true;
2614}
Greg Claytonc685f8e2010-09-15 04:15:46 +00002615
Greg Clayton99558cc42015-08-24 23:46:31 +00002616bool
2617SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx,
2618 DWARFCompileUnit *cu,
2619 const DWARFDebugInfoEntry *die)
2620{
2621 // If we have no parent decl context to match this DIE matches, and if the parent
2622 // decl context isn't valid, we aren't trying to look for any particular decl
2623 // context so any die matches.
2624 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2625 return true;
2626
2627 if (cu && die)
2628 {
2629 TypeSystem *type_system = GetTypeSystemForLanguage(cu->GetLanguageType());
2630
2631 if (type_system)
2632 {
2633 CompilerDeclContext actual_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, cu, die);
2634 if (actual_decl_ctx)
2635 return actual_decl_ctx == *decl_ctx;
2636 }
2637 }
2638 return false;
2639}
2640
Greg Clayton0c5cd902010-06-28 21:30:43 +00002641uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002642SymbolFileDWARF::FindFunctions (const ConstString &name,
2643 const CompilerDeclContext *parent_decl_ctx,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002644 uint32_t name_type_mask,
2645 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002646 bool append,
2647 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002648{
2649 Timer scoped_timer (__PRETTY_FUNCTION__,
2650 "SymbolFileDWARF::FindFunctions (name = '%s')",
2651 name.AsCString());
2652
Greg Clayton43fe2172013-04-03 02:00:15 +00002653 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
2654 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
2655
Greg Clayton5160ce52013-03-27 23:08:40 +00002656 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002657
2658 if (log)
2659 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002660 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002661 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2662 name.GetCString(),
2663 name_type_mask,
2664 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002665 }
2666
Greg Clayton0c5cd902010-06-28 21:30:43 +00002667 // If we aren't appending the results to this list, then clear the list
2668 if (!append)
2669 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002670
Greg Clayton99558cc42015-08-24 23:46:31 +00002671 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002672 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002673
2674 // If name is empty then we won't find anything.
2675 if (name.IsEmpty())
2676 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002677
2678 // Remember how many sc_list are in the list before we search in case
2679 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002680
Jim Ingham4cda6e02011-10-07 22:23:45 +00002681 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00002682
2683 const uint32_t original_size = sc_list.GetSize();
2684
Jim Ingham4cda6e02011-10-07 22:23:45 +00002685 DWARFDebugInfo* info = DebugInfo();
2686 if (info == NULL)
2687 return 0;
2688
Greg Claytonaa044962011-10-13 00:59:38 +00002689 DWARFCompileUnit *dwarf_cu = NULL;
Greg Clayton43fe2172013-04-03 02:00:15 +00002690 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00002691 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002692 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002693 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002694 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002695
2696 DIEArray die_offsets;
2697
2698 uint32_t num_matches = 0;
2699
Greg Clayton43fe2172013-04-03 02:00:15 +00002700 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002701 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002702 // If they asked for the full name, match what they typed. At some point we may
2703 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2704 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002705 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002706 for (uint32_t i = 0; i < num_matches; i++)
2707 {
Greg Clayton95d87902011-11-11 03:16:25 +00002708 const dw_offset_t die_offset = die_offsets[i];
2709 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Greg Claytonaa044962011-10-13 00:59:38 +00002710 if (die)
2711 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002712 if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die))
2713 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002714
Greg Clayton43fe2172013-04-03 02:00:15 +00002715 if (resolved_dies.find(die) == resolved_dies.end())
2716 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002717 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002718 resolved_dies.insert(die);
2719 }
Greg Claytonaa044962011-10-13 00:59:38 +00002720 }
Greg Clayton95d87902011-11-11 03:16:25 +00002721 else
2722 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002723 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2724 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002725 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002726 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002727 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002728
2729 if (name_type_mask & eFunctionNameTypeSelector)
2730 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002731 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00002732 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00002733
Greg Clayton43fe2172013-04-03 02:00:15 +00002734 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2735 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2736 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00002737
Greg Clayton43fe2172013-04-03 02:00:15 +00002738 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00002739 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002740 const dw_offset_t die_offset = die_offsets[i];
2741 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2742 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00002743 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002744 const char *die_name = die->GetName(this, dwarf_cu);
2745 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00002746 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002747 if (resolved_dies.find(die) == resolved_dies.end())
2748 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002749 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002750 resolved_dies.insert(die);
2751 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002752 }
2753 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002754 else
2755 {
2756 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2757 die_offset, name_cstr);
2758 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002759 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002760 die_offsets.clear();
2761 }
2762
Greg Clayton99558cc42015-08-24 23:46:31 +00002763 if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase)
Greg Clayton43fe2172013-04-03 02:00:15 +00002764 {
2765 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2766 // extract the base name, look that up, and if there is any other information in the name we were
2767 // passed in we have to post-filter based on that.
2768
2769 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2770 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2771
2772 for (uint32_t i = 0; i < num_matches; i++)
2773 {
2774 const dw_offset_t die_offset = die_offsets[i];
2775 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2776 if (die)
2777 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002778 if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die))
2779 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002780
Greg Clayton43fe2172013-04-03 02:00:15 +00002781
2782 // If we get to here, the die is good, and we should add it:
2783 if (resolved_dies.find(die) == resolved_dies.end())
Pavel Labatha73d6572015-03-13 10:22:00 +00002784 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002785 {
2786 bool keep_die = true;
2787 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
2788 {
2789 // We are looking for either basenames or methods, so we need to
2790 // trim out the ones we won't want by looking at the type
2791 SymbolContext sc;
2792 if (sc_list.GetLastContext(sc))
2793 {
2794 if (sc.block)
2795 {
2796 // We have an inlined function
2797 }
2798 else if (sc.function)
2799 {
2800 Type *type = sc.function->GetType();
2801
Sean Callananc370a8a2013-09-18 22:59:55 +00002802 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00002803 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002804 CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID());
2805 if (decl_ctx.IsStructUnionOrClass())
Greg Clayton43fe2172013-04-03 02:00:15 +00002806 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002807 if (name_type_mask & eFunctionNameTypeBase)
2808 {
2809 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2810 keep_die = false;
2811 }
2812 }
2813 else
2814 {
2815 if (name_type_mask & eFunctionNameTypeMethod)
2816 {
2817 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2818 keep_die = false;
2819 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002820 }
2821 }
2822 else
2823 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002824 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
2825 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00002826 }
2827 }
2828 }
2829 }
2830 if (keep_die)
2831 resolved_dies.insert(die);
2832 }
2833 }
2834 else
2835 {
2836 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2837 die_offset, name_cstr);
2838 }
2839 }
2840 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002841 }
2842 }
Greg Clayton7f995132011-10-04 22:41:51 +00002843 }
2844 else
2845 {
2846
2847 // Index the DWARF if we haven't already
2848 if (!m_indexed)
2849 Index ();
2850
Greg Clayton7f995132011-10-04 22:41:51 +00002851 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00002852 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002853 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002854
Ed Mastefc7baa02013-09-09 18:00:45 +00002855 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00002856 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00002857 // If we didn't find any functions in the global namespace try
2858 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00002859 // functions that have a namespace but keep functions which
2860 // have an anonymous namespace
2861 // TODO: The arch in the object file isn't correct for MSVC
2862 // binaries on windows, we should find a way to make it
2863 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00002864 if (sc_list.GetSize() == 0)
2865 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002866 ArchSpec arch;
Greg Clayton99558cc42015-08-24 23:46:31 +00002867 if (!parent_decl_ctx &&
Robert Flackeb83fab2015-05-15 18:59:59 +00002868 GetObjectFile()->GetArchitecture(arch) &&
2869 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
2870 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00002871 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002872 SymbolContextList temp_sc_list;
2873 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00002874 SymbolContext sc;
2875 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
2876 {
2877 if (temp_sc_list.GetContextAtIndex(i, sc))
2878 {
Matt Kopeca189d492013-05-10 22:55:24 +00002879 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
2880 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00002881 // Mangled names on Linux and FreeBSD are of the form:
2882 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00002883 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
2884 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00002885 {
2886 sc_list.Append(sc);
2887 }
2888 }
2889 }
2890 }
2891 }
Matt Kopecd6089962013-05-10 17:53:48 +00002892 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002893 DIEArray die_offsets;
2894 DWARFCompileUnit *dwarf_cu = NULL;
2895
Greg Clayton43fe2172013-04-03 02:00:15 +00002896 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002897 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002898 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002899 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002900 {
Greg Claytonaa044962011-10-13 00:59:38 +00002901 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2902 if (die)
2903 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002904 if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die))
2905 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002906
Greg Claytonaa044962011-10-13 00:59:38 +00002907 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00002908 if (resolved_dies.find(die) == resolved_dies.end())
2909 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002910 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002911 resolved_dies.insert(die);
2912 }
Greg Claytonaa044962011-10-13 00:59:38 +00002913 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002914 }
2915 die_offsets.clear();
2916 }
2917
Greg Clayton43fe2172013-04-03 02:00:15 +00002918 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002919 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002920 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Sean Callanan213fdb82011-10-13 01:49:10 +00002921 return 0; // no methods in namespaces
2922
Greg Clayton43fe2172013-04-03 02:00:15 +00002923 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002924 {
Greg Claytonaa044962011-10-13 00:59:38 +00002925 for (uint32_t i = 0; i < num_base; i++)
2926 {
2927 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
2928 if (die)
2929 {
Greg Claytonaa044962011-10-13 00:59:38 +00002930 // If we get to here, the die is good, and we should add it:
Greg Clayton43fe2172013-04-03 02:00:15 +00002931 if (resolved_dies.find(die) == resolved_dies.end())
2932 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002933 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002934 resolved_dies.insert(die);
2935 }
Greg Claytonaa044962011-10-13 00:59:38 +00002936 }
2937 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002938 }
2939 die_offsets.clear();
2940 }
Greg Clayton7f995132011-10-04 22:41:51 +00002941
Greg Clayton99558cc42015-08-24 23:46:31 +00002942 if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid()))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002943 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002944 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002945 }
2946
Greg Clayton4d01ace2011-09-29 16:58:15 +00002947 }
2948
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002949 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002950 const uint32_t num_matches = sc_list.GetSize() - original_size;
2951
2952 if (log && num_matches > 0)
2953 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002954 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00002955 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00002956 name.GetCString(),
2957 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00002958 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00002959 append,
2960 num_matches);
2961 }
2962 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002963}
2964
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002965uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00002966SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002967{
2968 Timer scoped_timer (__PRETTY_FUNCTION__,
2969 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2970 regex.GetText());
2971
Greg Clayton5160ce52013-03-27 23:08:40 +00002972 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002973
2974 if (log)
2975 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002976 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002977 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2978 regex.GetText(),
2979 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002980 }
2981
2982
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002983 // If we aren't appending the results to this list, then clear the list
2984 if (!append)
2985 sc_list.Clear();
2986
2987 // Remember how many sc_list are in the list before we search in case
2988 // we are appending the results to a variable list.
2989 uint32_t original_size = sc_list.GetSize();
2990
Greg Clayton97fbc342011-10-20 22:30:33 +00002991 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002992 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002993 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00002994 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002995 }
2996 else
2997 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002998 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002999 if (!m_indexed)
3000 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003001
Pavel Labatha73d6572015-03-13 10:22:00 +00003002 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003003
Pavel Labatha73d6572015-03-13 10:22:00 +00003004 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00003005 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003006
3007 // Return the number of variable that were appended to the list
3008 return sc_list.GetSize() - original_size;
3009}
Jim Ingham318c9f22011-08-26 19:44:13 +00003010
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003011uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00003012SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3013 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00003014 const CompilerDeclContext *parent_decl_ctx,
Greg Claytond1767f02011-12-08 02:13:16 +00003015 bool append,
3016 uint32_t max_matches,
3017 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003018{
Greg Claytonc685f8e2010-09-15 04:15:46 +00003019 DWARFDebugInfo* info = DebugInfo();
3020 if (info == NULL)
3021 return 0;
3022
Greg Clayton5160ce52013-03-27 23:08:40 +00003023 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003024
Greg Clayton21f2a492011-10-06 00:09:08 +00003025 if (log)
3026 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003027 if (parent_decl_ctx)
Greg Clayton5160ce52013-03-27 23:08:40 +00003028 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003029 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)",
Greg Clayton437a1352012-04-09 22:43:43 +00003030 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003031 static_cast<const void*>(parent_decl_ctx),
3032 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003033 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00003034 else
Greg Clayton5160ce52013-03-27 23:08:40 +00003035 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003036 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003037 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00003038 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00003039 }
3040
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003041 // If we aren't appending the results to this list, then clear the list
3042 if (!append)
3043 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003044
Greg Clayton99558cc42015-08-24 23:46:31 +00003045 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00003046 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003047
Greg Claytond4a2b372011-09-12 23:21:58 +00003048 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003049
Greg Clayton97fbc342011-10-20 22:30:33 +00003050 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003051 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003052 if (m_apple_types_ap.get())
3053 {
3054 const char *name_cstr = name.GetCString();
3055 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3056 }
Greg Clayton7f995132011-10-04 22:41:51 +00003057 }
3058 else
3059 {
3060 if (!m_indexed)
3061 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003062
Greg Clayton7f995132011-10-04 22:41:51 +00003063 m_type_index.Find (name, die_offsets);
3064 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003065
Greg Clayton437a1352012-04-09 22:43:43 +00003066 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00003067
Greg Clayton437a1352012-04-09 22:43:43 +00003068 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003069 {
Greg Clayton7f995132011-10-04 22:41:51 +00003070 const uint32_t initial_types_size = types.GetSize();
3071 DWARFCompileUnit* dwarf_cu = NULL;
3072 const DWARFDebugInfoEntry* die = NULL;
Greg Claytond4a2b372011-09-12 23:21:58 +00003073 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00003074 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003075 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003076 const dw_offset_t die_offset = die_offsets[i];
3077 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3078
Greg Clayton95d87902011-11-11 03:16:25 +00003079 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00003080 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003081 if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die))
3082 continue; // The containing decl contexts don't match
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003083
Greg Clayton95d87902011-11-11 03:16:25 +00003084 Type *matching_type = ResolveType (dwarf_cu, die);
3085 if (matching_type)
3086 {
3087 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003088 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00003089 if (types.GetSize() >= max_matches)
3090 break;
3091 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00003092 }
Greg Clayton95d87902011-11-11 03:16:25 +00003093 else
3094 {
3095 if (m_using_apple_tables)
3096 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003097 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3098 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003099 }
3100 }
3101
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003102 }
Greg Clayton437a1352012-04-09 22:43:43 +00003103 const uint32_t num_matches = types.GetSize() - initial_types_size;
3104 if (log && num_matches)
3105 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003106 if (parent_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00003107 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003108 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003109 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00003110 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003111 static_cast<const void*>(parent_decl_ctx),
3112 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003113 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003114 num_matches);
3115 }
3116 else
3117 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003118 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003119 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00003120 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00003121 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00003122 num_matches);
3123 }
3124 }
3125 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003126 }
Greg Clayton7f995132011-10-04 22:41:51 +00003127 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003128}
3129
3130
Greg Clayton99558cc42015-08-24 23:46:31 +00003131CompilerDeclContext
Greg Clayton96d7d742010-11-10 23:42:09 +00003132SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00003133 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00003134 const CompilerDeclContext *parent_decl_ctx)
Greg Clayton96d7d742010-11-10 23:42:09 +00003135{
Greg Clayton5160ce52013-03-27 23:08:40 +00003136 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00003137
3138 if (log)
3139 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003140 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00003141 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3142 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00003143 }
3144
Greg Clayton99558cc42015-08-24 23:46:31 +00003145 CompilerDeclContext namespace_decl_ctx;
3146
3147 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
3148 return namespace_decl_ctx;
3149
3150
Greg Clayton96d7d742010-11-10 23:42:09 +00003151 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00003152 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00003153 {
Greg Clayton7f995132011-10-04 22:41:51 +00003154 DIEArray die_offsets;
3155
Greg Clayton526e5af2010-11-13 03:52:47 +00003156 // Index if we already haven't to make sure the compile units
3157 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003158 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003159 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003160 if (m_apple_namespaces_ap.get())
3161 {
3162 const char *name_cstr = name.GetCString();
3163 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3164 }
Greg Clayton7f995132011-10-04 22:41:51 +00003165 }
3166 else
3167 {
3168 if (!m_indexed)
3169 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003170
Greg Clayton7f995132011-10-04 22:41:51 +00003171 m_namespace_index.Find (name, die_offsets);
3172 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003173
3174 DWARFCompileUnit* dwarf_cu = NULL;
Greg Clayton526e5af2010-11-13 03:52:47 +00003175 const DWARFDebugInfoEntry* die = NULL;
Greg Clayton7f995132011-10-04 22:41:51 +00003176 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003177 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003178 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003179 DWARFDebugInfo* debug_info = DebugInfo();
3180 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003181 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003182 const dw_offset_t die_offset = die_offsets[i];
3183 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
Sean Callanan213fdb82011-10-13 01:49:10 +00003184
Greg Clayton95d87902011-11-11 03:16:25 +00003185 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003186 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003187 if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die))
3188 continue; // The containing decl contexts don't match
Greg Clayton95d87902011-11-11 03:16:25 +00003189
Greg Clayton99558cc42015-08-24 23:46:31 +00003190 TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
Greg Clayton8b4edba2015-08-14 20:02:05 +00003191
3192 if (type_system)
3193 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003194 namespace_decl_ctx = type_system->GetDeclContextForUIDFromDWARF(this, dwarf_cu, die);
3195 if (namespace_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00003196 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003197 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003198 }
Greg Clayton95d87902011-11-11 03:16:25 +00003199 else
3200 {
3201 if (m_using_apple_tables)
3202 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003203 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3204 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003205 }
3206 }
3207
Greg Clayton526e5af2010-11-13 03:52:47 +00003208 }
3209 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003210 }
Greg Clayton99558cc42015-08-24 23:46:31 +00003211 if (log && namespace_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00003212 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003213 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003214 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"",
Greg Clayton437a1352012-04-09 22:43:43 +00003215 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003216 static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()),
3217 static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()),
3218 namespace_decl_ctx.GetName().AsCString("<NULL>"));
Greg Clayton437a1352012-04-09 22:43:43 +00003219 }
3220
Greg Clayton99558cc42015-08-24 23:46:31 +00003221 return namespace_decl_ctx;
Greg Clayton96d7d742010-11-10 23:42:09 +00003222}
3223
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003224uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003225SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003226{
3227 // Remember how many sc_list are in the list before we search in case
3228 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003229 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003230
3231 const uint32_t num_die_offsets = die_offsets.size();
3232 // Parse all of the types we found from the pubtypes matches
3233 uint32_t i;
3234 uint32_t num_matches = 0;
3235 for (i = 0; i < num_die_offsets; ++i)
3236 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003237 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3238 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003239 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003240 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003241 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003242 ++num_matches;
3243 if (num_matches >= max_matches)
3244 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003245 }
3246 }
3247
3248 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003249 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003250}
3251
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003253TypeSP
Greg Clayton53eb1c22012-04-02 22:59:12 +00003254SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003255{
3256 TypeSP type_sp;
3257 if (die != NULL)
3258 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003259 assert(dwarf_cu != NULL);
Greg Clayton594e5ed2010-09-27 21:07:38 +00003260 Type *type_ptr = m_die_to_type.lookup (die);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003261 if (type_ptr == NULL)
3262 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003263 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
Greg Claytonca512b32011-01-14 04:54:56 +00003264 assert (lldb_cu);
3265 SymbolContext sc(lldb_cu);
Greg Clayton53eb1c22012-04-02 22:59:12 +00003266 type_sp = ParseType(sc, dwarf_cu, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003267 }
3268 else if (type_ptr != DIE_IS_BEING_PARSED)
3269 {
3270 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003271 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003272 }
3273
3274 }
3275 return type_sp;
3276}
3277
Greg Clayton2bc22f82011-09-30 03:20:47 +00003278
3279const DWARFDebugInfoEntry *
Greg Clayton8b4edba2015-08-14 20:02:05 +00003280SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003281{
3282 if (cu && die)
3283 {
3284 const DWARFDebugInfoEntry * const decl_die = die;
3285
3286 while (die != NULL)
3287 {
3288 // If this is the original DIE that we are searching for a declaration
3289 // for, then don't look in the cache as we don't want our own decl
3290 // context to be our decl context...
3291 if (decl_die != die)
3292 {
3293 switch (die->Tag())
3294 {
3295 case DW_TAG_compile_unit:
3296 case DW_TAG_namespace:
3297 case DW_TAG_structure_type:
3298 case DW_TAG_union_type:
3299 case DW_TAG_class_type:
3300 return die;
3301
3302 default:
3303 break;
3304 }
3305 }
3306
3307 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
3308 if (die_offset != DW_INVALID_OFFSET)
3309 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00003310 DWARFCompileUnit *spec_cu = const_cast<DWARFCompileUnit *>(cu);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003311 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
3312 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
3313 if (spec_die_decl_ctx_die)
3314 return spec_die_decl_ctx_die;
3315 }
3316
3317 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
3318 if (die_offset != DW_INVALID_OFFSET)
3319 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00003320 DWARFCompileUnit *abs_cu = const_cast<DWARFCompileUnit *>(cu);
Greg Clayton2bc22f82011-09-30 03:20:47 +00003321 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
3322 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
3323 if (abs_die_decl_ctx_die)
3324 return abs_die_decl_ctx_die;
3325 }
3326
3327 die = die->GetParent();
3328 }
3329 }
3330 return NULL;
3331}
3332
3333
Greg Clayton901c5ca2011-12-03 04:40:03 +00003334Symbol *
3335SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3336{
3337 Symbol *objc_class_symbol = NULL;
3338 if (m_obj_file)
3339 {
Greg Clayton3046e662013-07-10 01:23:25 +00003340 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003341 if (symtab)
3342 {
3343 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3344 eSymbolTypeObjCClass,
3345 Symtab::eDebugNo,
3346 Symtab::eVisibilityAny);
3347 }
3348 }
3349 return objc_class_symbol;
3350}
3351
Greg Claytonc7f03b62012-01-12 04:33:28 +00003352// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3353// then we can end up looking through all class types for a complete type and never find
3354// the full definition. We need to know if this attribute is supported, so we determine
3355// this here and cache th result. We also need to worry about the debug map DWARF file
3356// if we are doing darwin DWARF in .o file debugging.
3357bool
3358SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
3359{
3360 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
3361 {
3362 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3363 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3364 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3365 else
3366 {
3367 DWARFDebugInfo* debug_info = DebugInfo();
3368 const uint32_t num_compile_units = GetNumCompileUnits();
3369 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3370 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003371 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3372 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003373 {
3374 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3375 break;
3376 }
3377 }
3378 }
Greg Clayton1f746072012-08-29 21:13:06 +00003379 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003380 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
3381 }
3382 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3383}
Greg Clayton901c5ca2011-12-03 04:40:03 +00003384
3385// This function can be used when a DIE is found that is a forward declaration
3386// DIE and we want to try and find a type that has the complete definition.
3387TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00003388SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
3389 const ConstString &type_name,
3390 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00003391{
3392
3393 TypeSP type_sp;
3394
Greg Claytonc7f03b62012-01-12 04:33:28 +00003395 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00003396 return type_sp;
3397
3398 DIEArray die_offsets;
3399
3400 if (m_using_apple_tables)
3401 {
3402 if (m_apple_types_ap.get())
3403 {
3404 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00003405 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003406 }
3407 }
3408 else
3409 {
3410 if (!m_indexed)
3411 Index ();
3412
3413 m_type_index.Find (type_name, die_offsets);
3414 }
3415
Greg Clayton901c5ca2011-12-03 04:40:03 +00003416 const size_t num_matches = die_offsets.size();
3417
Greg Clayton901c5ca2011-12-03 04:40:03 +00003418 DWARFCompileUnit* type_cu = NULL;
3419 const DWARFDebugInfoEntry* type_die = NULL;
3420 if (num_matches)
3421 {
3422 DWARFDebugInfo* debug_info = DebugInfo();
3423 for (size_t i=0; i<num_matches; ++i)
3424 {
3425 const dw_offset_t die_offset = die_offsets[i];
3426 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
3427
3428 if (type_die)
3429 {
3430 bool try_resolving_type = false;
3431
3432 // Don't try and resolve the DIE we are looking for with the DIE itself!
3433 if (type_die != die)
3434 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00003435 switch (type_die->Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00003436 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00003437 case DW_TAG_class_type:
3438 case DW_TAG_structure_type:
3439 try_resolving_type = true;
3440 break;
3441 default:
3442 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00003443 }
3444 }
3445
3446 if (try_resolving_type)
3447 {
Ed Maste4c24b122013-10-17 20:13:14 +00003448 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
3449 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003450
3451 if (try_resolving_type)
3452 {
3453 Type *resolved_type = ResolveType (type_cu, type_die, false);
3454 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3455 {
Ed Mastea0191d12013-10-17 20:42:56 +00003456 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton901c5ca2011-12-03 04:40:03 +00003457 MakeUserID(die->GetOffset()),
Jim Ingham4af59612014-12-19 19:20:44 +00003458 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton901c5ca2011-12-03 04:40:03 +00003459 MakeUserID(type_die->GetOffset()),
3460 MakeUserID(type_cu->GetOffset()));
3461
Greg Claytonc7f03b62012-01-12 04:33:28 +00003462 if (die)
3463 m_die_to_type[die] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00003464 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003465 break;
3466 }
3467 }
3468 }
3469 }
3470 else
3471 {
3472 if (m_using_apple_tables)
3473 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003474 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3475 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00003476 }
3477 }
3478
3479 }
3480 }
3481 return type_sp;
3482}
3483
Greg Claytona8022fa2012-04-24 21:22:41 +00003484
Greg Clayton80c26302012-02-05 06:12:47 +00003485//----------------------------------------------------------------------
3486// This function helps to ensure that the declaration contexts match for
3487// two different DIEs. Often times debug information will refer to a
3488// forward declaration of a type (the equivalent of "struct my_struct;".
3489// There will often be a declaration of that type elsewhere that has the
3490// full definition. When we go looking for the full type "my_struct", we
3491// will find one or more matches in the accelerator tables and we will
3492// then need to make sure the type was in the same declaration context
3493// as the original DIE. This function can efficiently compare two DIEs
3494// and will return true when the declaration context matches, and false
3495// when they don't.
3496//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00003497bool
3498SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
3499 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
3500{
Greg Claytona8022fa2012-04-24 21:22:41 +00003501 if (die1 == die2)
3502 return true;
3503
3504#if defined (LLDB_CONFIGURATION_DEBUG)
3505 // You can't and shouldn't call this function with a compile unit from
3506 // two different SymbolFileDWARF instances.
3507 assert (DebugInfo()->ContainsCompileUnit (cu1));
3508 assert (DebugInfo()->ContainsCompileUnit (cu2));
3509#endif
3510
Greg Clayton890ff562012-02-02 05:48:16 +00003511 DWARFDIECollection decl_ctx_1;
3512 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00003513 //The declaration DIE stack is a stack of the declaration context
3514 // DIEs all the way back to the compile unit. If a type "T" is
3515 // declared inside a class "B", and class "B" is declared inside
3516 // a class "A" and class "A" is in a namespace "lldb", and the
3517 // namespace is in a compile unit, there will be a stack of DIEs:
3518 //
3519 // [0] DW_TAG_class_type for "B"
3520 // [1] DW_TAG_class_type for "A"
3521 // [2] DW_TAG_namespace for "lldb"
3522 // [3] DW_TAG_compile_unit for the source file.
3523 //
3524 // We grab both contexts and make sure that everything matches
3525 // all the way back to the compiler unit.
3526
3527 // First lets grab the decl contexts for both DIEs
Greg Clayton890ff562012-02-02 05:48:16 +00003528 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
Sean Callanan5b26f272012-02-04 08:49:35 +00003529 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00003530 // Make sure the context arrays have the same size, otherwise
3531 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00003532 const size_t count1 = decl_ctx_1.Size();
3533 const size_t count2 = decl_ctx_2.Size();
3534 if (count1 != count2)
3535 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00003536
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003537 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00003538 // compile unit. If they don't, then we are done.
Greg Clayton890ff562012-02-02 05:48:16 +00003539 const DWARFDebugInfoEntry *decl_ctx_die1;
3540 const DWARFDebugInfoEntry *decl_ctx_die2;
3541 size_t i;
3542 for (i=0; i<count1; i++)
3543 {
3544 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
3545 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
3546 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
3547 return false;
3548 }
Greg Clayton890ff562012-02-02 05:48:16 +00003549#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00003550
3551 // Make sure the top item in the decl context die array is always
3552 // DW_TAG_compile_unit. If it isn't then something went wrong in
3553 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
Greg Clayton890ff562012-02-02 05:48:16 +00003554 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00003555
Greg Clayton890ff562012-02-02 05:48:16 +00003556#endif
3557 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00003558 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00003559 for (i=0; i<count1 - 1; i++)
3560 {
3561 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
3562 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
3563 const char *name1 = decl_ctx_die1->GetName(this, cu1);
Sean Callanan5b26f272012-02-04 08:49:35 +00003564 const char *name2 = decl_ctx_die2->GetName(this, cu2);
Greg Clayton890ff562012-02-02 05:48:16 +00003565 // If the string was from a DW_FORM_strp, then the pointer will often
3566 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00003567 if (name1 == name2)
3568 continue;
3569
3570 // Name pointers are not equal, so only compare the strings
3571 // if both are not NULL.
3572 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00003573 {
Greg Clayton5569e642012-02-06 01:44:54 +00003574 // If the strings don't compare, we are done...
3575 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00003576 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00003577 }
3578 else
3579 {
3580 // One name was NULL while the other wasn't
3581 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00003582 }
3583 }
Greg Clayton80c26302012-02-05 06:12:47 +00003584 // We made it through all of the checks and the declaration contexts
3585 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00003586 return true;
3587}
Greg Clayton220a0072011-12-09 08:48:30 +00003588
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003589
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003590TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00003591SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
3592{
3593 TypeSP type_sp;
3594
3595 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
3596 if (dwarf_decl_ctx_count > 0)
3597 {
3598 const ConstString type_name(dwarf_decl_ctx[0].name);
3599 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
3600
3601 if (type_name)
3602 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003603 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00003604 if (log)
3605 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003606 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003607 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
3608 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3609 dwarf_decl_ctx.GetQualifiedName());
3610 }
3611
3612 DIEArray die_offsets;
3613
3614 if (m_using_apple_tables)
3615 {
3616 if (m_apple_types_ap.get())
3617 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003618 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
3619 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
3620 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00003621 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003622 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
3623 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
3624 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003625 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003626 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
3627 }
3628 else if (has_tag)
3629 {
3630 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003631 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00003632 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
3633 }
3634 else
3635 {
3636 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
3637 }
3638 }
3639 }
3640 else
3641 {
3642 if (!m_indexed)
3643 Index ();
3644
3645 m_type_index.Find (type_name, die_offsets);
3646 }
3647
3648 const size_t num_matches = die_offsets.size();
3649
3650
3651 DWARFCompileUnit* type_cu = NULL;
3652 const DWARFDebugInfoEntry* type_die = NULL;
3653 if (num_matches)
3654 {
3655 DWARFDebugInfo* debug_info = DebugInfo();
3656 for (size_t i=0; i<num_matches; ++i)
3657 {
3658 const dw_offset_t die_offset = die_offsets[i];
3659 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
3660
3661 if (type_die)
3662 {
3663 bool try_resolving_type = false;
3664
3665 // Don't try and resolve the DIE we are looking for with the DIE itself!
3666 const dw_tag_t type_tag = type_die->Tag();
3667 // Make sure the tags match
3668 if (type_tag == tag)
3669 {
3670 // The tags match, lets try resolving this type
3671 try_resolving_type = true;
3672 }
3673 else
3674 {
3675 // The tags don't match, but we need to watch our for a
3676 // forward declaration for a struct and ("struct foo")
3677 // ends up being a class ("class foo { ... };") or
3678 // vice versa.
3679 switch (type_tag)
3680 {
3681 case DW_TAG_class_type:
3682 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3683 try_resolving_type = (tag == DW_TAG_structure_type);
3684 break;
3685 case DW_TAG_structure_type:
3686 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3687 try_resolving_type = (tag == DW_TAG_class_type);
3688 break;
3689 default:
3690 // Tags don't match, don't event try to resolve
3691 // using this type whose name matches....
3692 break;
3693 }
3694 }
3695
3696 if (try_resolving_type)
3697 {
3698 DWARFDeclContext type_dwarf_decl_ctx;
3699 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
3700
3701 if (log)
3702 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003703 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003704 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
3705 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3706 dwarf_decl_ctx.GetQualifiedName(),
3707 type_die->GetOffset(),
3708 type_dwarf_decl_ctx.GetQualifiedName());
3709 }
3710
3711 // Make sure the decl contexts match all the way up
3712 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
3713 {
3714 Type *resolved_type = ResolveType (type_cu, type_die, false);
3715 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3716 {
3717 type_sp = resolved_type->shared_from_this();
3718 break;
3719 }
3720 }
3721 }
3722 else
3723 {
3724 if (log)
3725 {
3726 std::string qualified_name;
3727 type_die->GetQualifiedName(this, type_cu, qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00003728 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003729 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
3730 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3731 dwarf_decl_ctx.GetQualifiedName(),
3732 type_die->GetOffset(),
3733 qualified_name.c_str());
3734 }
3735 }
3736 }
3737 else
3738 {
3739 if (m_using_apple_tables)
3740 {
3741 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3742 die_offset, type_name.GetCString());
3743 }
3744 }
3745
3746 }
3747 }
3748 }
3749 }
3750 return type_sp;
3751}
3752
Greg Claytona8022fa2012-04-24 21:22:41 +00003753TypeSP
Greg Clayton1be10fc2010-09-29 01:12:09 +00003754SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003755{
Greg Clayton196e8cd2015-08-17 20:31:46 +00003756 TypeSP type_sp;
3757
Greg Clayton8b4edba2015-08-14 20:02:05 +00003758 TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003759
Greg Clayton8b4edba2015-08-14 20:02:05 +00003760 if (type_system)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003761 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00003762 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
Greg Clayton196e8cd2015-08-17 20:31:46 +00003763 type_sp = type_system->ParseTypeFromDWARF (sc, this, dwarf_cu, die, log, type_is_new_ptr);
3764 if (type_sp)
3765 {
3766 TypeList* type_list = GetTypeList();
3767 if (type_list)
3768 type_list->Insert(type_sp);
3769 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003770 }
Greg Clayton196e8cd2015-08-17 20:31:46 +00003771
3772 return type_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003773}
3774
3775size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003776SymbolFileDWARF::ParseTypes
3777(
3778 const SymbolContext& sc,
3779 DWARFCompileUnit* dwarf_cu,
3780 const DWARFDebugInfoEntry *die,
3781 bool parse_siblings,
3782 bool parse_children
3783)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003784{
3785 size_t types_added = 0;
3786 while (die != NULL)
3787 {
3788 bool type_is_new = false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00003789 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003790 {
3791 if (type_is_new)
3792 ++types_added;
3793 }
3794
3795 if (parse_children && die->HasChildren())
3796 {
3797 if (die->Tag() == DW_TAG_subprogram)
3798 {
3799 SymbolContext child_sc(sc);
Greg Clayton81c22f62011-10-19 18:09:39 +00003800 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003801 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
3802 }
3803 else
3804 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
3805 }
3806
3807 if (parse_siblings)
3808 die = die->GetSibling();
3809 else
3810 die = NULL;
3811 }
3812 return types_added;
3813}
3814
3815
3816size_t
3817SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3818{
3819 assert(sc.comp_unit && sc.function);
3820 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003821 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003822 if (dwarf_cu)
3823 {
3824 dw_offset_t function_die_offset = sc.function->GetID();
3825 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
3826 if (function_die)
3827 {
Greg Claytondd7feaf2011-08-12 17:54:33 +00003828 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003829 }
3830 }
3831
3832 return functions_added;
3833}
3834
3835
3836size_t
3837SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3838{
3839 // At least a compile unit must be valid
3840 assert(sc.comp_unit);
3841 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003842 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003843 if (dwarf_cu)
3844 {
3845 if (sc.function)
3846 {
3847 dw_offset_t function_die_offset = sc.function->GetID();
3848 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
3849 if (func_die && func_die->HasChildren())
3850 {
3851 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
3852 }
3853 }
3854 else
3855 {
3856 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
3857 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
3858 {
3859 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
3860 }
3861 }
3862 }
3863
3864 return types_added;
3865}
3866
3867size_t
3868SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3869{
3870 if (sc.comp_unit != NULL)
3871 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00003872 DWARFDebugInfo* info = DebugInfo();
3873 if (info == NULL)
3874 return 0;
3875
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003876 if (sc.function)
3877 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003878 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
3879
3880 if (dwarf_cu == NULL)
3881 return 0;
3882
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
Greg Clayton016a95e2010-09-14 02:20:48 +00003884
Greg Claytonc7bece562013-01-25 18:06:21 +00003885 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
3886 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003887 {
3888 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00003889
Greg Claytone38a5ed2012-01-05 03:57:59 +00003890 // Let all blocks know they have parse all their variables
3891 sc.function->GetBlock (false).SetDidParseVariables (true, true);
3892 return num_variables;
3893 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003894 }
3895 else if (sc.comp_unit)
3896 {
Greg Clayton9422dd62013-03-04 21:46:16 +00003897 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
3898
3899 if (dwarf_cu == NULL)
3900 return 0;
3901
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003902 uint32_t vars_added = 0;
3903 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3904
3905 if (variables.get() == NULL)
3906 {
3907 variables.reset(new VariableList());
3908 sc.comp_unit->SetVariableList(variables);
3909
Greg Claytond4a2b372011-09-12 23:21:58 +00003910 DWARFCompileUnit* match_dwarf_cu = NULL;
3911 const DWARFDebugInfoEntry* die = NULL;
3912 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00003913 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003914 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003915 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003916 {
3917 DWARFMappedHash::DIEInfoArray hash_data_array;
3918 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
3919 dwarf_cu->GetNextCompileUnitOffset(),
3920 hash_data_array))
3921 {
3922 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3923 }
3924 }
Greg Clayton7f995132011-10-04 22:41:51 +00003925 }
3926 else
3927 {
3928 // Index if we already haven't to make sure the compile units
3929 // get indexed and make their global DIE index list
3930 if (!m_indexed)
3931 Index ();
3932
3933 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
3934 dwarf_cu->GetNextCompileUnitOffset(),
3935 die_offsets);
3936 }
3937
3938 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003939 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003940 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003941 DWARFDebugInfo* debug_info = DebugInfo();
3942 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003943 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003944 const dw_offset_t die_offset = die_offsets[i];
3945 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
Greg Clayton95d87902011-11-11 03:16:25 +00003946 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003947 {
Greg Clayton95d87902011-11-11 03:16:25 +00003948 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
3949 if (var_sp)
3950 {
3951 variables->AddVariableIfUnique (var_sp);
3952 ++vars_added;
3953 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003954 }
Greg Clayton95d87902011-11-11 03:16:25 +00003955 else
3956 {
3957 if (m_using_apple_tables)
3958 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003959 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00003960 }
3961 }
3962
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003963 }
3964 }
3965 }
3966 return vars_added;
3967 }
3968 }
3969 return 0;
3970}
3971
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003972VariableSP
3973SymbolFileDWARF::ParseVariableDIE
3974(
3975 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00003976 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00003977 const DWARFDebugInfoEntry *die,
3978 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003979)
3980{
Greg Clayton83c5cd92010-11-14 22:13:40 +00003981 VariableSP var_sp (m_die_to_variable_sp[die]);
3982 if (var_sp)
3983 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003984
3985 const dw_tag_t tag = die->Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00003986 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003987
3988 if ((tag == DW_TAG_variable) ||
3989 (tag == DW_TAG_constant) ||
3990 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003991 {
Greg Clayton7f995132011-10-04 22:41:51 +00003992 DWARFDebugInfoEntry::Attributes attributes;
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003993 const size_t num_attributes = die->GetAttributes(this,
3994 dwarf_cu,
3995 DWARFFormValue::FixedFormSizes(),
3996 attributes);
Greg Clayton7f995132011-10-04 22:41:51 +00003997 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003998 {
Greg Clayton7f995132011-10-04 22:41:51 +00003999 const char *name = NULL;
4000 const char *mangled = NULL;
4001 Declaration decl;
4002 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00004003 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton7f995132011-10-04 22:41:51 +00004004 DWARFExpression location;
4005 bool is_external = false;
4006 bool is_artificial = false;
4007 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004008 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00004009 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00004010 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00004011
4012 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004013 {
Greg Clayton7f995132011-10-04 22:41:51 +00004014 dw_attr_t attr = attributes.AttributeAtIndex(i);
4015 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00004016
Greg Clayton7f995132011-10-04 22:41:51 +00004017 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004018 {
Greg Clayton7f995132011-10-04 22:41:51 +00004019 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004020 {
Greg Clayton7f995132011-10-04 22:41:51 +00004021 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4022 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4023 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4024 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton71415542012-12-08 00:24:40 +00004025 case DW_AT_linkage_name:
Greg Clayton7f995132011-10-04 22:41:51 +00004026 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
Greg Clayton54166af2014-11-22 01:58:59 +00004027 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00004028 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00004029 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004030 // If we have already found a DW_AT_location attribute, ignore this attribute.
4031 if (!has_explicit_location)
4032 {
4033 location_is_const_value_data = true;
4034 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00004035 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004036 if (DWARFFormValue::IsBlockForm(form_value.Form()))
4037 {
4038 // Retrieve the value as a block expression.
4039 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4040 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00004041 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004042 }
4043 else if (DWARFFormValue::IsDataForm(form_value.Form()))
4044 {
4045 // Retrieve the value as a data expression.
Tamas Berghammerb7c64652015-08-25 11:45:46 +00004046 DWARFFormValue::FixedFormSizes fixed_form_sizes =
4047 DWARFFormValue::GetFixedFormSizesForAddressSize (
4048 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
4049 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004050 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00004051 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Enrico Granata4ec130d2014-08-11 19:16:35 +00004052 if (data_length == 0)
4053 {
4054 const uint8_t *data_pointer = form_value.BlockData();
4055 if (data_pointer)
4056 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00004057 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00004058 }
4059 else if (DWARFFormValue::IsDataForm(form_value.Form()))
4060 {
4061 // we need to get the byte size of the type later after we create the variable
4062 const_value = form_value;
4063 }
4064 }
4065 else
4066 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004067 }
4068 else
4069 {
4070 // Retrieve the value as a string expression.
4071 if (form_value.Form() == DW_FORM_strp)
4072 {
Tamas Berghammerb7c64652015-08-25 11:45:46 +00004073 DWARFFormValue::FixedFormSizes fixed_form_sizes =
4074 DWARFFormValue::GetFixedFormSizesForAddressSize (
4075 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
4076 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004077 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00004078 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Richard Mitton0a558352013-10-17 21:14:00 +00004079 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004080 }
4081 else
4082 {
4083 const char *str = form_value.AsCString(&debug_info_data);
4084 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
4085 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00004086 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004087 }
4088 }
4089 }
4090 break;
Greg Clayton7f995132011-10-04 22:41:51 +00004091 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004092 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00004093 location_is_const_value_data = false;
4094 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00004095 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004096 {
Ed Masteeeae7212013-10-24 20:43:47 +00004097 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00004098
4099 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4100 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00004101 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00004102 }
4103 else
4104 {
Ed Masteeeae7212013-10-24 20:43:47 +00004105 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00004106 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4107
4108 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
4109 if (loc_list_length > 0)
4110 {
Richard Mitton0a558352013-10-17 21:14:00 +00004111 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00004112 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00004113 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00004114 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004115 }
4116 }
Greg Clayton7f995132011-10-04 22:41:51 +00004117 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004118
Greg Clayton1c8ef472013-04-05 23:27:21 +00004119 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00004120 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00004121 case DW_AT_declaration:
4122 case DW_AT_description:
4123 case DW_AT_endianity:
4124 case DW_AT_segment:
4125 case DW_AT_start_scope:
4126 case DW_AT_visibility:
4127 default:
4128 case DW_AT_abstract_origin:
4129 case DW_AT_sibling:
4130 case DW_AT_specification:
4131 break;
4132 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004133 }
4134 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004135
Paul Herman10bc1a42015-08-18 22:46:57 +00004136 const DWARFDebugInfoEntry *parent_context_die = GetDeclContextDIEContainingDIE(dwarf_cu, die);
4137 bool is_static_member = die->GetParent()->Tag() == DW_TAG_compile_unit && (parent_context_die->Tag() == DW_TAG_class_type || parent_context_die->Tag() == DW_TAG_structure_type);
4138
Greg Clayton9e9f2192013-05-17 00:55:28 +00004139 ValueType scope = eValueTypeInvalid;
4140
4141 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
4142 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4143 SymbolContextScope * symbol_context_scope = NULL;
4144
Siva Chandra0783ab92015-03-24 18:32:27 +00004145 if (!mangled)
4146 {
4147 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
4148 // generate fully qualified names of global variables with commands like "frame var j".
4149 // For example, if j were an int variable holding a value 4 and declared in a namespace
4150 // B which in turn is contained in a namespace A, the command "frame var j" returns
4151 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
4152 // to generate a fully qualified name from the declaration context.
4153 if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
4154 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
4155 {
4156 DWARFDeclContext decl_ctx;
4157
4158 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
4159 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
4160 }
4161 }
4162
Greg Clayton9e9f2192013-05-17 00:55:28 +00004163 // DWARF doesn't specify if a DW_TAG_variable is a local, global
4164 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00004165 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00004166 // a DW_OP_addr opcode _somewhere_ in the definition. I say
4167 // somewhere because clang likes to combine small global variables
4168 // into the same symbol and have locations like:
4169 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
4170 // So if we don't have a DW_TAG_formal_parameter, we can look at
4171 // the location to see if it contains a DW_OP_addr opcode, and
4172 // then we can correctly classify our variables.
4173 if (tag == DW_TAG_formal_parameter)
4174 scope = eValueTypeVariableArgument;
4175 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004176 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004177 bool op_error = false;
4178 // Check if the location has a DW_OP_addr with any address value...
4179 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
4180 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004181 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004182 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
4183 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00004184 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004185 StreamString strm;
4186 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
4187 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str());
Greg Clayton96c09682012-01-04 22:56:43 +00004188 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004189 }
Greg Claytond1767f02011-12-08 02:13:16 +00004190
Greg Clayton9e9f2192013-05-17 00:55:28 +00004191 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
4192 {
4193 if (is_external)
4194 scope = eValueTypeVariableGlobal;
4195 else
4196 scope = eValueTypeVariableStatic;
4197
4198
4199 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
4200
4201 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004202 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004203 // When leaving the DWARF in the .o files on darwin,
4204 // when we have a global variable that wasn't initialized,
4205 // the .o file might not have allocated a virtual
4206 // address for the global variable. In this case it will
4207 // have created a symbol for the global variable
4208 // that is undefined/data and external and the value will
4209 // be the byte size of the variable. When we do the
4210 // address map in SymbolFileDWARFDebugMap we rely on
4211 // having an address, we need to do some magic here
4212 // so we can get the correct address for our global
4213 // variable. The address for all of these entries
4214 // will be zero, and there will be an undefined symbol
4215 // in this object file, and the executable will have
4216 // a matching symbol with a good address. So here we
4217 // dig up the correct address and replace it in the
4218 // location for the variable, and set the variable's
4219 // symbol context scope to be that of the main executable
4220 // so the file address will resolve correctly.
4221 bool linked_oso_file_addr = false;
4222 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00004223 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004224 // we have a possible uninitialized extern global
4225 ConstString const_name(mangled ? mangled : name);
4226 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
4227 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004228 {
Greg Clayton3046e662013-07-10 01:23:25 +00004229 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00004230 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004231 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004232 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
4233 eSymbolTypeData,
4234 Symtab::eDebugYes,
4235 Symtab::eVisibilityExtern);
4236 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004237 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004238 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004239 {
Greg Clayton358cf1e2015-06-25 21:46:34 +00004240 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
Greg Clayton9e9f2192013-05-17 00:55:28 +00004241 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004242 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004243 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004244 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004245 linked_oso_file_addr = true;
4246 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004247 }
4248 }
4249 }
4250 }
4251 }
4252 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004253 }
Greg Clayton9422dd62013-03-04 21:46:16 +00004254
Greg Clayton9e9f2192013-05-17 00:55:28 +00004255 if (!linked_oso_file_addr)
4256 {
4257 // The DW_OP_addr is not zero, but it contains a .o file address which
4258 // needs to be linked up correctly.
4259 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
4260 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00004261 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004262 // Update the file address for this variable
4263 location.Update_DW_OP_addr (exe_file_addr);
4264 }
4265 else
4266 {
4267 // Variable didn't make it into the final executable
4268 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00004269 }
Greg Claytond1767f02011-12-08 02:13:16 +00004270 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004271 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00004272 }
4273 else
4274 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004275 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00004276 }
Greg Clayton7f995132011-10-04 22:41:51 +00004277 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004278
4279 if (symbol_context_scope == NULL)
4280 {
4281 switch (parent_tag)
4282 {
4283 case DW_TAG_subprogram:
4284 case DW_TAG_inlined_subroutine:
4285 case DW_TAG_lexical_block:
4286 if (sc.function)
4287 {
4288 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
4289 if (symbol_context_scope == NULL)
4290 symbol_context_scope = sc.function;
4291 }
4292 break;
4293
4294 default:
4295 symbol_context_scope = sc.comp_unit;
4296 break;
4297 }
4298 }
4299
4300 if (symbol_context_scope)
4301 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00004302 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
4303
4304 if (const_value.Form() && type_sp && type_sp->GetType())
4305 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize());
4306
Greg Clayton9e9f2192013-05-17 00:55:28 +00004307 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
4308 name,
4309 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00004310 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00004311 scope,
4312 symbol_context_scope,
4313 &decl,
4314 location,
4315 is_external,
Paul Herman10bc1a42015-08-18 22:46:57 +00004316 is_artificial,
4317 is_static_member));
Greg Clayton9e9f2192013-05-17 00:55:28 +00004318
4319 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
4320 }
4321 else
4322 {
4323 // Not ready to parse this variable yet. It might be a global
4324 // or static variable that is in a function scope and the function
4325 // in the symbol context wasn't filled in yet
4326 return var_sp;
4327 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004328 }
Greg Clayton7f995132011-10-04 22:41:51 +00004329 // Cache var_sp even if NULL (the variable was just a specification or
4330 // was missing vital information to be able to be displayed in the debugger
4331 // (missing location due to optimization, etc)) so we don't re-parse
4332 // this DIE over and over later...
4333 m_die_to_variable_sp[die] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004334 }
4335 return var_sp;
4336}
4337
Greg Claytonc662ec82011-06-17 22:10:16 +00004338
4339const DWARFDebugInfoEntry *
4340SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
4341 dw_offset_t spec_block_die_offset,
4342 DWARFCompileUnit **result_die_cu_handle)
4343{
4344 // Give the concrete function die specified by "func_die_offset", find the
4345 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4346 // to "spec_block_die_offset"
4347 DWARFDebugInfo* info = DebugInfo();
4348
4349 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
4350 if (die)
4351 {
4352 assert (*result_die_cu_handle);
4353 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
4354 }
4355 return NULL;
4356}
4357
4358
4359const DWARFDebugInfoEntry *
4360SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
4361 const DWARFDebugInfoEntry *die,
4362 dw_offset_t spec_block_die_offset,
4363 DWARFCompileUnit **result_die_cu_handle)
4364{
4365 if (die)
4366 {
4367 switch (die->Tag())
4368 {
4369 case DW_TAG_subprogram:
4370 case DW_TAG_inlined_subroutine:
4371 case DW_TAG_lexical_block:
4372 {
4373 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4374 {
4375 *result_die_cu_handle = dwarf_cu;
4376 return die;
4377 }
4378
4379 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4380 {
4381 *result_die_cu_handle = dwarf_cu;
4382 return die;
4383 }
4384 }
4385 break;
4386 }
4387
4388 // Give the concrete function die specified by "func_die_offset", find the
4389 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4390 // to "spec_block_die_offset"
4391 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
4392 {
4393 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
4394 child_die,
4395 spec_block_die_offset,
4396 result_die_cu_handle);
4397 if (result_die)
4398 return result_die;
4399 }
4400 }
4401
4402 *result_die_cu_handle = NULL;
4403 return NULL;
4404}
4405
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004406size_t
4407SymbolFileDWARF::ParseVariables
4408(
4409 const SymbolContext& sc,
Greg Clayton0fffff52010-09-24 05:15:53 +00004410 DWARFCompileUnit* dwarf_cu,
Greg Clayton016a95e2010-09-14 02:20:48 +00004411 const lldb::addr_t func_low_pc,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004412 const DWARFDebugInfoEntry *orig_die,
4413 bool parse_siblings,
4414 bool parse_children,
4415 VariableList* cc_variable_list
4416)
4417{
4418 if (orig_die == NULL)
4419 return 0;
4420
Greg Claytonc662ec82011-06-17 22:10:16 +00004421 VariableListSP variable_list_sp;
4422
4423 size_t vars_added = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004424 const DWARFDebugInfoEntry *die = orig_die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004425 while (die != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004426 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004427 dw_tag_t tag = die->Tag();
4428
4429 // Check to see if we have already parsed this variable or constant?
4430 if (m_die_to_variable_sp[die])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004431 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004432 if (cc_variable_list)
4433 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004434 }
4435 else
4436 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004437 // We haven't already parsed it, lets do that now.
4438 if ((tag == DW_TAG_variable) ||
4439 (tag == DW_TAG_constant) ||
4440 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004441 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004442 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004443 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004444 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
4445 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
4446 switch (parent_tag)
4447 {
4448 case DW_TAG_compile_unit:
4449 if (sc.comp_unit != NULL)
4450 {
4451 variable_list_sp = sc.comp_unit->GetVariableList(false);
4452 if (variable_list_sp.get() == NULL)
4453 {
4454 variable_list_sp.reset(new VariableList());
4455 sc.comp_unit->SetVariableList(variable_list_sp);
4456 }
4457 }
4458 else
4459 {
Daniel Malead01b2952012-11-29 21:49:15 +00004460 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004461 MakeUserID(sc_parent_die->GetOffset()),
4462 DW_TAG_value_to_name (parent_tag),
4463 MakeUserID(orig_die->GetOffset()),
4464 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00004465 }
4466 break;
4467
4468 case DW_TAG_subprogram:
4469 case DW_TAG_inlined_subroutine:
4470 case DW_TAG_lexical_block:
4471 if (sc.function != NULL)
4472 {
4473 // Check to see if we already have parsed the variables for the given scope
4474
Greg Clayton81c22f62011-10-19 18:09:39 +00004475 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00004476 if (block == NULL)
4477 {
4478 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00004479 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00004480 // to find the concrete block so we can correctly add the
4481 // variable to it
4482 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
4483 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4484 sc_parent_die->GetOffset(),
4485 &concrete_block_die_cu);
4486 if (concrete_block_die)
Greg Clayton81c22f62011-10-19 18:09:39 +00004487 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
Greg Claytonc662ec82011-06-17 22:10:16 +00004488 }
4489
4490 if (block != NULL)
4491 {
4492 const bool can_create = false;
4493 variable_list_sp = block->GetBlockVariableList (can_create);
4494 if (variable_list_sp.get() == NULL)
4495 {
4496 variable_list_sp.reset(new VariableList());
4497 block->SetVariableList(variable_list_sp);
4498 }
4499 }
4500 }
4501 break;
4502
4503 default:
Daniel Malead01b2952012-11-29 21:49:15 +00004504 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +00004505 MakeUserID(orig_die->GetOffset()),
4506 DW_TAG_value_to_name (orig_die->Tag()));
Greg Claytonc662ec82011-06-17 22:10:16 +00004507 break;
4508 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004509 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004510
4511 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004512 {
Greg Clayton73bf5db2011-06-17 01:22:15 +00004513 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
4514 if (var_sp)
4515 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004516 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004517 if (cc_variable_list)
4518 cc_variable_list->AddVariableIfUnique (var_sp);
4519 ++vars_added;
4520 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004521 }
4522 }
4523 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004524
4525 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4526
4527 if (!skip_children && parse_children && die->HasChildren())
4528 {
4529 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
4530 }
4531
4532 if (parse_siblings)
4533 die = die->GetSibling();
4534 else
4535 die = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004536 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004537 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004538}
4539
4540//------------------------------------------------------------------
4541// PluginInterface protocol
4542//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00004543ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004544SymbolFileDWARF::GetPluginName()
4545{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004546 return GetPluginNameStatic();
4547}
4548
4549uint32_t
4550SymbolFileDWARF::GetPluginVersion()
4551{
4552 return 1;
4553}
4554
4555void
Sean Callanancc427fa2011-07-30 02:42:06 +00004556SymbolFileDWARF::DumpIndexes ()
4557{
4558 StreamFile s(stdout, false);
4559
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004560 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00004561 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004562 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00004563 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4564 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4565 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4566 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4567 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4568 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4569 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00004570 s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
Sean Callanancc427fa2011-07-30 02:42:06 +00004571}
4572
Greg Claytoncaab74e2012-01-28 00:48:57 +00004573
Greg Clayton1f746072012-08-29 21:13:06 +00004574SymbolFileDWARFDebugMap *
4575SymbolFileDWARF::GetDebugMapSymfile ()
4576{
4577 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
4578 {
4579 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
4580 if (module_sp)
4581 {
4582 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
4583 if (sym_vendor)
4584 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
4585 }
4586 }
4587 return m_debug_map_symfile;
4588}
4589
Greg Claytoncaab74e2012-01-28 00:48:57 +00004590