blob: 1186fed2b92fea3476cad63df16373e877fc4b76 [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
Sean Callanancc427fa2011-07-30 02:42:06 +000013#include "llvm/Support/Casting.h"
14
Robert Flackeb83fab2015-05-15 18:59:59 +000015#include "lldb/Core/ArchSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000017#include "lldb/Core/ModuleList.h"
18#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/PluginManager.h"
20#include "lldb/Core/RegularExpression.h"
21#include "lldb/Core/Scalar.h"
22#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000023#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000024#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/Timer.h"
26#include "lldb/Core/Value.h"
27
Sean Callanan4dbb2712015-09-25 20:35:58 +000028#include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000029
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +000030#include "lldb/Host/FileSystem.h"
Greg Clayton20568dd2011-10-13 23:13:20 +000031#include "lldb/Host/Host.h"
32
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +000033#include "lldb/Interpreter/OptionValueFileSpecList.h"
34#include "lldb/Interpreter/OptionValueProperties.h"
35
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Symbol/Block.h"
Bruce Mitchener937e3962015-09-21 16:56:08 +000037#include "lldb/Symbol/ClangASTContext.h"
Paul Hermand628cbb2015-09-15 23:44:17 +000038#include "lldb/Symbol/CompilerDecl.h"
39#include "lldb/Symbol/CompilerDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Symbol/CompileUnit.h"
41#include "lldb/Symbol/LineTable.h"
42#include "lldb/Symbol/ObjectFile.h"
43#include "lldb/Symbol/SymbolVendor.h"
Bruce Mitchener937e3962015-09-21 16:56:08 +000044#include "lldb/Symbol/TypeSystem.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Symbol/VariableList.h"
Ravitheja Addepally40697302015-10-08 09:45:41 +000046#include "lldb/Symbol/TypeMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Jim Inghamaa816b82015-09-02 01:59:14 +000048#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
49#include "Plugins/Language/ObjC/ObjCLanguage.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000050
Jim Ingham0e0984e2015-09-02 01:06:46 +000051#include "lldb/Target/Language.h"
52
Tamas Berghammer2ff88702015-10-23 10:34:49 +000053#include "lldb/Utility/TaskPool.h"
54
Greg Clayton261ac3f2015-08-28 01:01:03 +000055#include "DWARFASTParser.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "DWARFCompileUnit.h"
57#include "DWARFDebugAbbrev.h"
58#include "DWARFDebugAranges.h"
59#include "DWARFDebugInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "DWARFDebugLine.h"
61#include "DWARFDebugPubnames.h"
62#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000063#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064#include "DWARFDIECollection.h"
65#include "DWARFFormValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066#include "LogChannelDWARF.h"
Tamas Berghammereb882fc2015-09-09 10:20:48 +000067#include "SymbolFileDWARFDwo.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000068#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069
70#include <map>
71
Matthew Gardinere81df3b2014-08-26 06:57:23 +000072#include <ctype.h>
73#include <string.h>
74
Greg Clayton62742b12010-11-11 01:09:45 +000075//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000076
77#ifdef ENABLE_DEBUG_PRINTF
78#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000079#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000080#else
81#define DEBUG_PRINTF(fmt, ...)
82#endif
83
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084using namespace lldb;
85using namespace lldb_private;
86
Greg Clayton219cf312012-03-30 00:51:13 +000087//static inline bool
88//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
89//{
90// switch (tag)
91// {
92// default:
93// break;
94// case DW_TAG_subprogram:
95// case DW_TAG_inlined_subroutine:
96// case DW_TAG_class_type:
97// case DW_TAG_structure_type:
98// case DW_TAG_union_type:
99// return true;
100// }
101// return false;
102//}
103//
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000104
105namespace {
106
107 PropertyDefinition
108 g_properties[] =
109 {
110 { "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." },
111 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
112 };
113
114 enum
115 {
116 ePropertySymLinkPaths
117 };
118
119
120 class PluginProperties : public Properties
121 {
122 public:
123 static ConstString
124 GetSettingName()
125 {
126 return SymbolFileDWARF::GetPluginNameStatic();
127 }
128
129 PluginProperties()
130 {
131 m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
132 m_collection_sp->Initialize(g_properties);
133 }
134
135 FileSpecList&
136 GetSymLinkPaths()
137 {
138 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
139 assert(option_value);
140 return option_value->GetCurrentValue();
141 }
142
143 };
144
145 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
146
147 static const SymbolFileDWARFPropertiesSP&
148 GetGlobalPluginProperties()
149 {
150 static const auto g_settings_sp(std::make_shared<PluginProperties>());
151 return g_settings_sp;
152 }
153
154} // anonymous namespace end
155
156
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000157static const char*
158removeHostnameFromPathname(const char* path_from_dwarf)
159{
160 if (!path_from_dwarf || !path_from_dwarf[0])
161 {
162 return path_from_dwarf;
163 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000164
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000165 const char *colon_pos = strchr(path_from_dwarf, ':');
Enrico Granata99e5e222015-07-27 21:27:02 +0000166 if (nullptr == colon_pos)
167 {
168 return path_from_dwarf;
169 }
170
171 const char *slash_pos = strchr(path_from_dwarf, '/');
172 if (slash_pos && (slash_pos < colon_pos))
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000173 {
174 return path_from_dwarf;
175 }
176
177 // check whether we have a windows path, and so the first character
178 // is a drive-letter not a hostname.
179 if (
180 colon_pos == path_from_dwarf + 1 &&
181 isalpha(*path_from_dwarf) &&
182 strlen(path_from_dwarf) > 2 &&
183 '\\' == path_from_dwarf[2])
184 {
185 return path_from_dwarf;
186 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000187
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000188 return colon_pos + 1;
189}
190
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000191static const char*
192resolveCompDir(const char* path_from_dwarf)
193{
194 if (!path_from_dwarf)
195 return nullptr;
196
197 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
198 // Remove the host part if present.
199 const char* local_path = removeHostnameFromPathname(path_from_dwarf);
200 if (!local_path)
201 return nullptr;
202
203 bool is_symlink = false;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000204 FileSpec local_path_spec(local_path, false);
205 const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
206 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
207 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000208
209 if (!is_symlink)
210 return local_path;
211
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000212 if (!local_path_spec.IsSymbolicLink())
213 return local_path;
214
215 FileSpec resolved_local_path_spec;
216 const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
217 if (error.Success())
218 return resolved_local_path_spec.GetCString();
219
220 return nullptr;
221}
222
223
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224void
225SymbolFileDWARF::Initialize()
226{
227 LogChannelDWARF::Initialize();
228 PluginManager::RegisterPlugin (GetPluginNameStatic(),
229 GetPluginDescriptionStatic(),
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000230 CreateInstance,
231 DebuggerInitialize);
232}
233
234void
235SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
236{
237 if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
238 {
239 const bool is_global_setting = true;
240 PluginManager::CreateSettingForSymbolFilePlugin(debugger,
241 GetGlobalPluginProperties()->GetValueProperties(),
242 ConstString ("Properties for the dwarf symbol-file plug-in."),
243 is_global_setting);
244 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245}
246
247void
248SymbolFileDWARF::Terminate()
249{
250 PluginManager::UnregisterPlugin (CreateInstance);
251 LogChannelDWARF::Initialize();
252}
253
254
Greg Clayton57abc5d2013-05-10 21:47:16 +0000255lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000256SymbolFileDWARF::GetPluginNameStatic()
257{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000258 static ConstString g_name("dwarf");
259 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000260}
261
262const char *
263SymbolFileDWARF::GetPluginDescriptionStatic()
264{
265 return "DWARF and DWARF3 debug symbol file reader.";
266}
267
268
269SymbolFile*
270SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
271{
272 return new SymbolFileDWARF(obj_file);
273}
274
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000275TypeList *
276SymbolFileDWARF::GetTypeList ()
277{
Greg Clayton1f746072012-08-29 21:13:06 +0000278 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000279 return m_debug_map_symfile->GetTypeList();
280 return m_obj_file->GetModule()->GetTypeList();
281
282}
Greg Claytonf02500c2013-06-18 22:51:05 +0000283void
Greg Clayton6071e6f2015-08-26 22:57:51 +0000284SymbolFileDWARF::GetTypes (const DWARFDIE &die,
Greg Claytonf02500c2013-06-18 22:51:05 +0000285 dw_offset_t min_die_offset,
286 dw_offset_t max_die_offset,
287 uint32_t type_mask,
288 TypeSet &type_set)
289{
Greg Clayton6071e6f2015-08-26 22:57:51 +0000290 if (die)
Greg Claytonf02500c2013-06-18 22:51:05 +0000291 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000292 const dw_offset_t die_offset = die.GetOffset();
293
294 if (die_offset >= max_die_offset)
295 return;
296
297 if (die_offset >= min_die_offset)
Greg Claytonf02500c2013-06-18 22:51:05 +0000298 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000299 const dw_tag_t tag = die.Tag();
Greg Claytonf02500c2013-06-18 22:51:05 +0000300
Greg Clayton6071e6f2015-08-26 22:57:51 +0000301 bool add_type = false;
302
303 switch (tag)
Greg Claytonf02500c2013-06-18 22:51:05 +0000304 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000305 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
306 case DW_TAG_unspecified_type:
307 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
308 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
309 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
310 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
311 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
312 case DW_TAG_subroutine_type:
313 case DW_TAG_subprogram:
314 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
315 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
316 case DW_TAG_rvalue_reference_type:
317 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
318 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
319 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
320 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000321
Greg Clayton6071e6f2015-08-26 22:57:51 +0000322 if (add_type)
323 {
324 const bool assert_not_being_parsed = true;
325 Type *type = ResolveTypeUID (die, assert_not_being_parsed);
326 if (type)
Greg Claytonf02500c2013-06-18 22:51:05 +0000327 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000328 if (type_set.find(type) == type_set.end())
329 type_set.insert(type);
Greg Claytonf02500c2013-06-18 22:51:05 +0000330 }
331 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000332 }
333
334 for (DWARFDIE child_die = die.GetFirstChild();
335 child_die.IsValid();
336 child_die = child_die.GetSibling())
337 {
338 GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set);
Greg Claytonf02500c2013-06-18 22:51:05 +0000339 }
340 }
341}
342
343size_t
344SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
345 uint32_t type_mask,
346 TypeList &type_list)
347
348{
349 TypeSet type_set;
350
351 CompileUnit *comp_unit = NULL;
352 DWARFCompileUnit* dwarf_cu = NULL;
353 if (sc_scope)
354 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
355
356 if (comp_unit)
357 {
358 dwarf_cu = GetDWARFCompileUnit(comp_unit);
359 if (dwarf_cu == 0)
360 return 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +0000361 GetTypes (dwarf_cu->DIE(),
Greg Claytonf02500c2013-06-18 22:51:05 +0000362 dwarf_cu->GetOffset(),
363 dwarf_cu->GetNextCompileUnitOffset(),
364 type_mask,
365 type_set);
366 }
367 else
368 {
369 DWARFDebugInfo* info = DebugInfo();
370 if (info)
371 {
372 const size_t num_cus = info->GetNumCompileUnits();
373 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
374 {
375 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
376 if (dwarf_cu)
377 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000378 GetTypes (dwarf_cu->DIE(),
Greg Claytonf02500c2013-06-18 22:51:05 +0000379 0,
380 UINT32_MAX,
381 type_mask,
382 type_set);
383 }
384 }
385 }
386 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000387
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000388 std::set<CompilerType> compiler_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000389 size_t num_types_added = 0;
390 for (Type *type : type_set)
391 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000392 CompilerType compiler_type = type->GetForwardCompilerType ();
393 if (compiler_type_set.find(compiler_type) == compiler_type_set.end())
Greg Clayton0fc4f312013-06-20 01:23:18 +0000394 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000395 compiler_type_set.insert(compiler_type);
Greg Clayton0fc4f312013-06-20 01:23:18 +0000396 type_list.Insert (type->shared_from_this());
397 ++num_types_added;
398 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000399 }
400 return num_types_added;
401}
402
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000403
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404//----------------------------------------------------------------------
405// Gets the first parent that is a lexical block, function or inlined
406// subroutine, or compile unit.
407//----------------------------------------------------------------------
Greg Clayton6071e6f2015-08-26 22:57:51 +0000408DWARFDIE
409SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410{
Greg Clayton6071e6f2015-08-26 22:57:51 +0000411 DWARFDIE die;
412 for (die = child_die.GetParent(); die; die = die.GetParent())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000414 dw_tag_t tag = die.Tag();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415
416 switch (tag)
417 {
418 case DW_TAG_compile_unit:
419 case DW_TAG_subprogram:
420 case DW_TAG_inlined_subroutine:
421 case DW_TAG_lexical_block:
422 return die;
423 }
424 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000425 return DWARFDIE();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426}
427
428
Greg Clayton450e3f32010-10-12 02:24:53 +0000429SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
430 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000431 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 +0000432 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000433 m_debug_map_symfile (NULL),
Greg Claytond4a2b372011-09-12 23:21:58 +0000434 m_data_debug_abbrev (),
435 m_data_debug_aranges (),
436 m_data_debug_frame (),
437 m_data_debug_info (),
438 m_data_debug_line (),
439 m_data_debug_loc (),
440 m_data_debug_ranges (),
441 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000442 m_data_apple_names (),
443 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000444 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 m_info(),
447 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000448 m_apple_names_ap (),
449 m_apple_types_ap (),
450 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000451 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000452 m_function_basename_index(),
453 m_function_fullname_index(),
454 m_function_method_index(),
455 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000456 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000457 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000458 m_type_index(),
459 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000460 m_indexed (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000461 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000462 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000463 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000464 m_ranges(),
465 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466{
467}
468
469SymbolFileDWARF::~SymbolFileDWARF()
470{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000471}
472
473static const ConstString &
474GetDWARFMachOSegmentName ()
475{
476 static ConstString g_dwarf_section_name ("__DWARF");
477 return g_dwarf_section_name;
478}
479
Greg Claytone576ab22011-02-15 00:19:15 +0000480UniqueDWARFASTTypeMap &
481SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
482{
Greg Clayton1f746072012-08-29 21:13:06 +0000483 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000484 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
485 return m_unique_ast_type_map;
486}
487
Greg Clayton8b4edba2015-08-14 20:02:05 +0000488TypeSystem *
489SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language)
490{
491 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
Ryan Brown57bee1e2015-09-14 22:45:11 +0000492 TypeSystem *type_system;
Greg Clayton8b4edba2015-08-14 20:02:05 +0000493 if (debug_map_symfile)
Ryan Brown57bee1e2015-09-14 22:45:11 +0000494 {
495 type_system = debug_map_symfile->GetTypeSystemForLanguage(language);
496 }
Greg Clayton8b4edba2015-08-14 20:02:05 +0000497 else
Ryan Brown57bee1e2015-09-14 22:45:11 +0000498 {
499 type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
500 if (type_system)
501 type_system->SetSymbolFile(this);
502 }
503 return type_system;
Greg Clayton8b4edba2015-08-14 20:02:05 +0000504}
505
Greg Clayton6beaaa62011-01-17 03:46:26 +0000506void
507SymbolFileDWARF::InitializeObject()
508{
Greg Claytone72dfb32012-02-24 01:59:29 +0000509 ModuleSP module_sp (m_obj_file->GetModule());
510 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000511 {
Greg Clayton3046e662013-07-10 01:23:25 +0000512 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000513 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
514
515 // Memory map the DWARF mach-o segment so we have everything mmap'ed
516 // to keep our heap memory usage down.
517 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000518 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000519 }
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000520
Greg Clayton4d01ace2011-09-29 16:58:15 +0000521 get_apple_names_data();
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000522 if (m_data_apple_names.m_data.GetByteSize() > 0)
Greg Clayton7f995132011-10-04 22:41:51 +0000523 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000524 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names.m_data,
525 get_debug_str_data(),
526 ".apple_names"));
Greg Clayton97fbc342011-10-20 22:30:33 +0000527 if (m_apple_names_ap->IsValid())
528 m_using_apple_tables = true;
529 else
Greg Clayton7f995132011-10-04 22:41:51 +0000530 m_apple_names_ap.reset();
531 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000532 get_apple_types_data();
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000533 if (m_data_apple_types.m_data.GetByteSize() > 0)
Greg Clayton7f995132011-10-04 22:41:51 +0000534 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000535 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types.m_data,
536 get_debug_str_data(),
537 ".apple_types"));
Greg Clayton97fbc342011-10-20 22:30:33 +0000538 if (m_apple_types_ap->IsValid())
539 m_using_apple_tables = true;
540 else
Greg Clayton7f995132011-10-04 22:41:51 +0000541 m_apple_types_ap.reset();
542 }
543
544 get_apple_namespaces_data();
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000545 if (m_data_apple_namespaces.m_data.GetByteSize() > 0)
Greg Clayton7f995132011-10-04 22:41:51 +0000546 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000547 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces.m_data,
548 get_debug_str_data(),
549 ".apple_namespaces"));
Greg Clayton97fbc342011-10-20 22:30:33 +0000550 if (m_apple_namespaces_ap->IsValid())
551 m_using_apple_tables = true;
552 else
Greg Clayton7f995132011-10-04 22:41:51 +0000553 m_apple_namespaces_ap.reset();
554 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000555
Greg Clayton5009f9d2011-10-27 17:55:14 +0000556 get_apple_objc_data();
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000557 if (m_data_apple_objc.m_data.GetByteSize() > 0)
Greg Clayton5009f9d2011-10-27 17:55:14 +0000558 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000559 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc.m_data,
560 get_debug_str_data(),
561 ".apple_objc"));
Greg Clayton5009f9d2011-10-27 17:55:14 +0000562 if (m_apple_objc_ap->IsValid())
563 m_using_apple_tables = true;
564 else
565 m_apple_objc_ap.reset();
566 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567}
568
569bool
570SymbolFileDWARF::SupportedVersion(uint16_t version)
571{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000572 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574
575uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000576SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577{
578 uint32_t abilities = 0;
579 if (m_obj_file != NULL)
580 {
581 const Section* section = NULL;
582 const SectionList *section_list = m_obj_file->GetSectionList();
583 if (section_list == NULL)
584 return 0;
585
586 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 uint64_t debug_info_file_size = 0;
588 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589
Greg Clayton6beaaa62011-01-17 03:46:26 +0000590 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591
592 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000593 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594
Greg Clayton4ceb9982010-07-21 22:54:26 +0000595 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 if (section != NULL)
597 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000598 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599
Greg Clayton4ceb9982010-07-21 22:54:26 +0000600 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000602 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603
Greg Clayton4ceb9982010-07-21 22:54:26 +0000604 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000606 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 }
Greg Clayton6c596612012-05-18 21:47:20 +0000608 else
609 {
610 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
611 if (symfile_dir_cstr)
612 {
613 if (strcasestr(symfile_dir_cstr, ".dsym"))
614 {
615 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
616 {
617 // We have a dSYM file that didn't have a any debug info.
618 // If the string table has a size of 1, then it was made from
619 // an executable with no debug info, or from an executable that
620 // was stripped.
621 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
622 if (section && section->GetFileSize() == 1)
623 {
624 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
625 }
626 }
627 }
628 }
629 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630
631 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
632 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
633
634 if (debug_line_file_size > 0)
635 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 }
637 return abilities;
638}
639
Ed Masteeeae7212013-10-24 20:43:47 +0000640const DWARFDataExtractor&
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000641SymbolFileDWARF::GetCachedSectionData (lldb::SectionType sect_type, DWARFDataSegment& data_segment)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000643 std::call_once(data_segment.m_flag,
644 &SymbolFileDWARF::LoadSectionData,
645 this,
646 sect_type,
647 std::ref(data_segment.m_data));
648 return data_segment.m_data;
649}
650
651void
652SymbolFileDWARF::LoadSectionData (lldb::SectionType sect_type, DWARFDataExtractor& data)
653{
654 ModuleSP module_sp (m_obj_file->GetModule());
655 const SectionList *section_list = module_sp->GetSectionList();
656 if (section_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000658 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
659 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000661 // See if we memory mapped the DWARF segment?
662 if (m_dwarf_data.GetByteSize())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 {
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000664 data.SetData(m_dwarf_data, section_sp->GetOffset(), section_sp->GetFileSize());
665 }
666 else
667 {
668 if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
669 data.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 }
671 }
672 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673}
674
Ed Masteeeae7212013-10-24 20:43:47 +0000675const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676SymbolFileDWARF::get_debug_abbrev_data()
677{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000678 return GetCachedSectionData (eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679}
680
Ed Masteeeae7212013-10-24 20:43:47 +0000681const DWARFDataExtractor&
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000682SymbolFileDWARF::get_debug_addr_data()
683{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000684 return GetCachedSectionData (eSectionTypeDWARFDebugAddr, m_data_debug_addr);
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000685}
686
687const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000688SymbolFileDWARF::get_debug_aranges_data()
689{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000690 return GetCachedSectionData (eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
Greg Claytond4a2b372011-09-12 23:21:58 +0000691}
692
Ed Masteeeae7212013-10-24 20:43:47 +0000693const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694SymbolFileDWARF::get_debug_frame_data()
695{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000696 return GetCachedSectionData (eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697}
698
Ed Masteeeae7212013-10-24 20:43:47 +0000699const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700SymbolFileDWARF::get_debug_info_data()
701{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000702 return GetCachedSectionData (eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703}
704
Ed Masteeeae7212013-10-24 20:43:47 +0000705const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706SymbolFileDWARF::get_debug_line_data()
707{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000708 return GetCachedSectionData (eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709}
710
Ed Masteeeae7212013-10-24 20:43:47 +0000711const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000712SymbolFileDWARF::get_debug_loc_data()
713{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000714 return GetCachedSectionData (eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715}
716
Ed Masteeeae7212013-10-24 20:43:47 +0000717const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718SymbolFileDWARF::get_debug_ranges_data()
719{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000720 return GetCachedSectionData (eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000721}
722
Ed Masteeeae7212013-10-24 20:43:47 +0000723const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724SymbolFileDWARF::get_debug_str_data()
725{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000726 return GetCachedSectionData (eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727}
728
Ed Masteeeae7212013-10-24 20:43:47 +0000729const DWARFDataExtractor&
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000730SymbolFileDWARF::get_debug_str_offsets_data()
731{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000732 return GetCachedSectionData (eSectionTypeDWARFDebugStrOffsets, m_data_debug_str_offsets);
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000733}
734
735const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000736SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000737{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000738 return GetCachedSectionData (eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000739}
740
Ed Masteeeae7212013-10-24 20:43:47 +0000741const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000742SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000743{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000744 return GetCachedSectionData (eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000745}
746
Ed Masteeeae7212013-10-24 20:43:47 +0000747const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000748SymbolFileDWARF::get_apple_namespaces_data()
749{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000750 return GetCachedSectionData (eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
Greg Clayton5009f9d2011-10-27 17:55:14 +0000751}
752
Ed Masteeeae7212013-10-24 20:43:47 +0000753const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000754SymbolFileDWARF::get_apple_objc_data()
755{
Tamas Berghammer90b4dce2015-10-22 11:14:37 +0000756 return GetCachedSectionData (eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000757}
758
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759
760DWARFDebugAbbrev*
761SymbolFileDWARF::DebugAbbrev()
762{
763 if (m_abbr.get() == NULL)
764 {
Ed Masteeeae7212013-10-24 20:43:47 +0000765 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766 if (debug_abbrev_data.GetByteSize() > 0)
767 {
768 m_abbr.reset(new DWARFDebugAbbrev());
769 if (m_abbr.get())
770 m_abbr->Parse(debug_abbrev_data);
771 }
772 }
773 return m_abbr.get();
774}
775
776const DWARFDebugAbbrev*
777SymbolFileDWARF::DebugAbbrev() const
778{
779 return m_abbr.get();
780}
781
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782
783DWARFDebugInfo*
784SymbolFileDWARF::DebugInfo()
785{
786 if (m_info.get() == NULL)
787 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000788 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
789 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 if (get_debug_info_data().GetByteSize() > 0)
791 {
792 m_info.reset(new DWARFDebugInfo());
793 if (m_info.get())
794 {
795 m_info->SetDwarfData(this);
796 }
797 }
798 }
799 return m_info.get();
800}
801
802const DWARFDebugInfo*
803SymbolFileDWARF::DebugInfo() const
804{
805 return m_info.get();
806}
807
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000809SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810{
Greg Claytonea4a5bb2015-09-04 22:29:46 +0000811 if (!comp_unit)
812 return nullptr;
813
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000815 if (info)
816 {
817 if (GetDebugMapSymfile ())
818 {
819 // The debug map symbol file made the compile units for this DWARF
820 // file which is .o file with DWARF in it, and we should have
821 // only 1 compile unit which is at offset zero in the DWARF.
822 // TODO: modify to support LTO .o files where each .o file might
823 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000824
Greg Clayton6071e6f2015-08-26 22:57:51 +0000825 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0);
Greg Clayton68c00bd2015-02-05 02:10:29 +0000826 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
827 dwarf_cu->SetUserData(comp_unit);
828 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000829 }
830 else
831 {
832 // Just a normal DWARF file whose user ID for the compile unit is
833 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000834
Greg Clayton6071e6f2015-08-26 22:57:51 +0000835 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
Greg Clayton68c00bd2015-02-05 02:10:29 +0000836 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
837 dwarf_cu->SetUserData(comp_unit);
838 return dwarf_cu;
839
Greg Clayton1f746072012-08-29 21:13:06 +0000840 }
841 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000842 return NULL;
843}
844
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845
846DWARFDebugRanges*
847SymbolFileDWARF::DebugRanges()
848{
849 if (m_ranges.get() == NULL)
850 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000851 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
852 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853 if (get_debug_ranges_data().GetByteSize() > 0)
854 {
855 m_ranges.reset(new DWARFDebugRanges());
856 if (m_ranges.get())
857 m_ranges->Extract(this);
858 }
859 }
860 return m_ranges.get();
861}
862
863const DWARFDebugRanges*
864SymbolFileDWARF::DebugRanges() const
865{
866 return m_ranges.get();
867}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868
Greg Clayton53eb1c22012-04-02 22:59:12 +0000869lldb::CompUnitSP
870SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000872 CompUnitSP cu_sp;
873 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000875 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
876 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000878 // We already parsed this compile unit, had out a shared pointer to it
879 cu_sp = comp_unit->shared_from_this();
880 }
881 else
882 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +0000883 if (dwarf_cu->GetSymbolFileDWARF() != this)
884 {
885 return dwarf_cu->GetSymbolFileDWARF()->ParseCompileUnit(dwarf_cu, cu_idx);
886 }
887 else if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888 {
Greg Clayton1f746072012-08-29 21:13:06 +0000889 // Let the debug map create the compile unit
890 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
891 dwarf_cu->SetUserData(cu_sp.get());
892 }
893 else
894 {
895 ModuleSP module_sp (m_obj_file->GetModule());
896 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000897 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000898 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
Greg Clayton1f746072012-08-29 21:13:06 +0000899 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000900 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000901 FileSpec cu_file_spec{cu_die.GetName(), false};
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000902 if (cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000903 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000904 // If we have a full path to the compile unit, we don't need to resolve
905 // the file. This can be expensive e.g. when the source files are NFS mounted.
Chaoren Lin372e9062015-06-09 17:54:27 +0000906 if (cu_file_spec.IsRelative())
Greg Clayton53eb1c22012-04-02 22:59:12 +0000907 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000908 const char *cu_comp_dir{cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)};
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000909 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
Greg Clayton1f746072012-08-29 21:13:06 +0000910 }
911
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000912 std::string remapped_file;
913 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
914 cu_file_spec.SetFile(remapped_file, false);
David Srbeckyd515e942015-07-08 14:00:04 +0000915 }
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000916
Greg Clayton5ce1a842015-08-27 18:09:44 +0000917 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000918
Jason Molendac7099582015-07-31 05:47:00 +0000919 bool is_optimized = dwarf_cu->GetIsOptimized ();
David Srbeckyd515e942015-07-08 14:00:04 +0000920 cu_sp.reset(new CompileUnit (module_sp,
921 dwarf_cu,
922 cu_file_spec,
Greg Clayton6071e6f2015-08-26 22:57:51 +0000923 dwarf_cu->GetID(),
Jason Molenda6ab659a2015-07-29 00:42:47 +0000924 cu_language,
925 is_optimized));
David Srbeckyd515e942015-07-08 14:00:04 +0000926 if (cu_sp)
927 {
928 // If we just created a compile unit with an invalid file spec, try and get the
929 // first entry in the supports files from the line table as that should be the
930 // compile unit.
931 if (!cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000932 {
David Srbeckyd515e942015-07-08 14:00:04 +0000933 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
934 if (cu_file_spec)
935 {
936 (FileSpec &)(*cu_sp) = cu_file_spec;
937 // Also fix the invalid file spec which was copied from the compile unit.
938 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
939 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000940 }
David Srbeckyd515e942015-07-08 14:00:04 +0000941
942 dwarf_cu->SetUserData(cu_sp.get());
943
944 // Figure out the compile unit index if we weren't given one
945 if (cu_idx == UINT32_MAX)
946 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
947
948 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000949 }
950 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000951 }
952 }
953 }
954 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000955 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956}
957
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958uint32_t
959SymbolFileDWARF::GetNumCompileUnits()
960{
961 DWARFDebugInfo* info = DebugInfo();
962 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000963 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000964 return 0;
965}
966
967CompUnitSP
968SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
969{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000970 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000971 DWARFDebugInfo* info = DebugInfo();
972 if (info)
973 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000974 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
975 if (dwarf_cu)
976 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000978 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979}
980
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981Function *
Greg Clayton6071e6f2015-08-26 22:57:51 +0000982SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000983{
Greg Clayton6071e6f2015-08-26 22:57:51 +0000984 if (die.IsValid())
985 {
986 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000987
Greg Clayton6071e6f2015-08-26 22:57:51 +0000988 if (type_system)
989 {
Greg Clayton261ac3f2015-08-28 01:01:03 +0000990 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
991 if (dwarf_ast)
992 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
Greg Clayton6071e6f2015-08-26 22:57:51 +0000993 }
994 }
995 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000996}
997
Greg Clayton9422dd62013-03-04 21:46:16 +0000998bool
999SymbolFileDWARF::FixupAddress (Address &addr)
1000{
1001 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1002 if (debug_map_symfile)
1003 {
1004 return debug_map_symfile->LinkOSOAddress(addr);
1005 }
1006 // This is a normal DWARF file, no address fixups need to happen
1007 return true;
1008}
Greg Clayton1f746072012-08-29 21:13:06 +00001009lldb::LanguageType
1010SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1011{
1012 assert (sc.comp_unit);
1013 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1014 if (dwarf_cu)
Greg Clayton5ce1a842015-08-27 18:09:44 +00001015 return dwarf_cu->GetLanguageType();
1016 else
1017 return eLanguageTypeUnknown;
Greg Clayton1f746072012-08-29 21:13:06 +00001018}
1019
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020size_t
1021SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1022{
1023 assert (sc.comp_unit);
1024 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001025 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 if (dwarf_cu)
1027 {
1028 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001029 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001031 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001033 DWARFDIE die = function_dies.GetDIEAtIndex(func_idx);
1034 if (sc.comp_unit->FindFunctionByUID (die.GetID()).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001035 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001036 if (ParseCompileUnitFunction(sc, die))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 ++functions_added;
1038 }
1039 }
1040 //FixupTypes();
1041 }
1042 return functions_added;
1043}
1044
1045bool
1046SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1047{
1048 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001049 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001050 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001052 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053
Greg Claytonda2455b2012-11-01 17:28:37 +00001054 if (cu_die)
1055 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001056 const char * cu_comp_dir = resolveCompDir(cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr));
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001057
Greg Clayton5ce1a842015-08-27 18:09:44 +00001058 const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059
Greg Claytonda2455b2012-11-01 17:28:37 +00001060 // All file indexes in DWARF are one based and a file of index zero is
1061 // supposed to be the compile unit itself.
1062 support_files.Append (*sc.comp_unit);
1063
1064 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1065 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066 }
1067 return false;
1068}
1069
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001070bool
1071SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1072{
1073 assert (sc.comp_unit);
1074 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1075 if (dwarf_cu)
1076 {
1077 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1078 {
1079 UpdateExternalModuleListIfNeeded();
1080 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1081 {
1082 imported_modules.push_back(external_type_module.second.m_name);
1083 }
1084 }
1085 }
1086 return false;
1087}
1088
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089struct ParseDWARFLineTableCallbackInfo
1090{
1091 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001092 std::unique_ptr<LineSequence> sequence_ap;
Jaydeep Patil44d07fc2015-09-22 06:36:56 +00001093 lldb::addr_t addr_mask;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094};
1095
1096//----------------------------------------------------------------------
1097// ParseStatementTableCallback
1098//----------------------------------------------------------------------
1099static void
1100ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1101{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001102 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1103 {
1104 // Just started parsing the line table
1105 }
1106 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1107 {
1108 // Done parsing line table, nothing to do for the cleanup
1109 }
1110 else
1111 {
1112 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001113 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001114
Greg Clayton9422dd62013-03-04 21:46:16 +00001115 // If this is our first time here, we need to create a
1116 // sequence container.
1117 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001118 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001119 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1120 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001121 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001122 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
Jaydeep Patil44d07fc2015-09-22 06:36:56 +00001123 state.address & info->addr_mask,
Greg Clayton9422dd62013-03-04 21:46:16 +00001124 state.line,
1125 state.column,
1126 state.file,
1127 state.is_stmt,
1128 state.basic_block,
1129 state.prologue_end,
1130 state.epilogue_begin,
1131 state.end_sequence);
1132 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001133 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001134 // First, put the current sequence into the line table.
1135 line_table->InsertSequence(info->sequence_ap.get());
1136 // Then, empty it to prepare for the next sequence.
1137 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139 }
1140}
1141
1142bool
1143SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1144{
1145 assert (sc.comp_unit);
1146 if (sc.comp_unit->GetLineTable() != NULL)
1147 return true;
1148
Greg Clayton1f746072012-08-29 21:13:06 +00001149 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001150 if (dwarf_cu)
1151 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001152 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001153 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001155 const dw_offset_t cu_line_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
Greg Clayton129d12c2011-11-28 03:29:03 +00001156 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001158 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001159 if (line_table_ap.get())
1160 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001161 ParseDWARFLineTableCallbackInfo info;
1162 info.line_table = line_table_ap.get();
Jaydeep Patil44d07fc2015-09-22 06:36:56 +00001163
1164 /*
1165 * MIPS:
1166 * The SymbolContext may not have a valid target, thus we may not be able
1167 * to call Address::GetOpcodeLoadAddress() which would clear the bit #0
1168 * for MIPS. Use ArchSpec to clear the bit #0.
1169 */
1170 ArchSpec arch;
1171 GetObjectFile()->GetArchitecture(arch);
1172 switch (arch.GetMachine())
1173 {
1174 case llvm::Triple::mips:
1175 case llvm::Triple::mipsel:
1176 case llvm::Triple::mips64:
1177 case llvm::Triple::mips64el:
1178 info.addr_mask = ~((lldb::addr_t)1);
1179 break;
1180 default:
1181 info.addr_mask = ~((lldb::addr_t)0);
1182 break;
1183 }
1184
Greg Claytonc7bece562013-01-25 18:06:21 +00001185 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001186 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001187 if (m_debug_map_symfile)
1188 {
1189 // We have an object file that has a line table with addresses
1190 // that are not linked. We need to link the line table and convert
1191 // the addresses that are relative to the .o file into addresses
1192 // for the main executable.
1193 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1194 }
1195 else
1196 {
1197 sc.comp_unit->SetLineTable(line_table_ap.release());
1198 return true;
1199 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201 }
1202 }
1203 }
1204 return false;
1205}
1206
1207size_t
Greg Clayton6071e6f2015-08-26 22:57:51 +00001208SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext& sc,
1209 Block *parent_block,
1210 const DWARFDIE &orig_die,
1211 addr_t subprogram_low_pc,
1212 uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213{
1214 size_t blocks_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001215 DWARFDIE die = orig_die;
1216 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001218 dw_tag_t tag = die.Tag();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219
1220 switch (tag)
1221 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001223 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 case DW_TAG_lexical_block:
1225 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001226 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001227 if (tag == DW_TAG_subprogram)
1228 {
1229 // Skip any DW_TAG_subprogram DIEs that are inside
1230 // of a normal or inlined functions. These will be
1231 // parsed on their own as separate entities.
1232
1233 if (depth > 0)
1234 break;
1235
1236 block = parent_block;
1237 }
1238 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001239 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001240 BlockSP block_sp(new Block (die.GetID()));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001241 parent_block->AddChild(block_sp);
1242 block = block_sp.get();
1243 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001244 DWARFRangeList ranges;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001245 const char *name = NULL;
1246 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 int decl_file = 0;
1249 int decl_line = 0;
1250 int decl_column = 0;
1251 int call_file = 0;
1252 int call_line = 0;
1253 int call_column = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001254 if (die.GetDIENamesAndRanges (name,
1255 mangled_name,
1256 ranges,
1257 decl_file, decl_line, decl_column,
1258 call_file, call_line, call_column, nullptr))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001259 {
1260 if (tag == DW_TAG_subprogram)
1261 {
1262 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001263 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001265 else if (tag == DW_TAG_inlined_subroutine)
1266 {
1267 // We get called here for inlined subroutines in two ways.
1268 // The first time is when we are making the Function object
1269 // for this inlined concrete instance. Since we're creating a top level block at
1270 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1271 // adjust the containing address.
1272 // The second time is when we are parsing the blocks inside the function that contains
1273 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1274 // function the offset will be for that function.
1275 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1276 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001277 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001278 }
1279 }
Greg Clayton103f3092015-01-15 03:04:37 +00001280
1281 const size_t num_ranges = ranges.GetSize();
1282 for (size_t i = 0; i<num_ranges; ++i)
1283 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001284 const DWARFRangeList::Entry &range = ranges.GetEntryRef (i);
Greg Clayton103f3092015-01-15 03:04:37 +00001285 const addr_t range_base = range.GetRangeBase();
1286 if (range_base >= subprogram_low_pc)
1287 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1288 else
1289 {
1290 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",
1291 block->GetID(),
1292 range_base,
1293 range.GetRangeEnd(),
1294 subprogram_low_pc);
1295 }
1296 }
1297 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298
1299 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1300 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001301 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001303 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1304 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001305
Greg Clayton7b0992d2013-04-18 22:45:39 +00001306 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001308 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1309 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001311 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312 }
1313
1314 ++blocks_added;
1315
Greg Clayton6071e6f2015-08-26 22:57:51 +00001316 if (die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001318 blocks_added += ParseFunctionBlocks (sc,
1319 block,
Greg Clayton6071e6f2015-08-26 22:57:51 +00001320 die.GetFirstChild(),
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001321 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001322 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323 }
1324 }
1325 }
1326 break;
1327 default:
1328 break;
1329 }
1330
Greg Claytondd7feaf2011-08-12 17:54:33 +00001331 // Only parse siblings of the block if we are not at depth zero. A depth
1332 // of zero indicates we are currently parsing the top level
1333 // DW_TAG_subprogram DIE
1334
1335 if (depth == 0)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001336 die.Clear();
Greg Claytondd7feaf2011-08-12 17:54:33 +00001337 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00001338 die = die.GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 }
1340 return blocks_added;
1341}
1342
Greg Claytonf0705c82011-10-22 03:33:13 +00001343bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00001344SymbolFileDWARF::ClassOrStructIsVirtual (const DWARFDIE &parent_die)
Greg Claytonc4ffd662013-03-08 01:37:30 +00001345{
1346 if (parent_die)
1347 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001348 for (DWARFDIE die = parent_die.GetFirstChild(); die; die = die.GetSibling())
Greg Claytonc4ffd662013-03-08 01:37:30 +00001349 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001350 dw_tag_t tag = die.Tag();
Greg Claytonc4ffd662013-03-08 01:37:30 +00001351 bool check_virtuality = false;
1352 switch (tag)
1353 {
1354 case DW_TAG_inheritance:
1355 case DW_TAG_subprogram:
1356 check_virtuality = true;
1357 break;
1358 default:
1359 break;
1360 }
1361 if (check_virtuality)
1362 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001363 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
Greg Claytonc4ffd662013-03-08 01:37:30 +00001364 return true;
1365 }
1366 }
1367 }
1368 return false;
1369}
1370
Paul Hermanea188fc2015-09-16 18:48:30 +00001371void
1372SymbolFileDWARF::ParseDeclsForContext (CompilerDeclContext decl_ctx)
1373{
1374 TypeSystem *type_system = decl_ctx.GetTypeSystem();
1375 DWARFASTParser *ast_parser = type_system->GetDWARFParser();
1376 std::vector<DWARFDIE> decl_ctx_die_list = ast_parser->GetDIEForDeclContext(decl_ctx);
1377
1378 for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
1379 for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; decl = decl.GetSibling())
1380 ast_parser->GetDeclForUIDFromDWARF(decl);
1381}
1382
Paul Hermand628cbb2015-09-15 23:44:17 +00001383CompilerDecl
1384SymbolFileDWARF::GetDeclForUID (lldb::user_id_t type_uid)
1385{
1386 if (UserIDMatches(type_uid))
1387 {
1388 DWARFDebugInfo* debug_info = DebugInfo();
1389 if (debug_info)
1390 {
1391 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
1392 if (die)
1393 {
1394 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1395 if (dwarf_ast)
1396 return dwarf_ast->GetDeclForUIDFromDWARF(die);
1397 }
1398 }
1399 }
1400 return CompilerDecl();
1401}
1402
Greg Clayton99558cc42015-08-24 23:46:31 +00001403CompilerDeclContext
1404SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405{
Greg Clayton8b4edba2015-08-14 20:02:05 +00001406 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001407 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00001408 DWARFDebugInfo* debug_info = DebugInfo();
1409 if (debug_info)
1410 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001411 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
Greg Clayton8b4edba2015-08-14 20:02:05 +00001412 if (die)
1413 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00001414 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1415 if (dwarf_ast)
1416 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001417 }
1418 }
Sean Callanan72e49402011-08-05 23:43:37 +00001419 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001420 return CompilerDeclContext();
Sean Callanan72e49402011-08-05 23:43:37 +00001421}
1422
Greg Clayton99558cc42015-08-24 23:46:31 +00001423CompilerDeclContext
1424SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid)
Sean Callanan72e49402011-08-05 23:43:37 +00001425{
Greg Clayton81c22f62011-10-19 18:09:39 +00001426 if (UserIDMatches(type_uid))
Greg Clayton8b4edba2015-08-14 20:02:05 +00001427 {
1428 DWARFDebugInfo* debug_info = DebugInfo();
1429 if (debug_info)
1430 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001431 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
Greg Clayton8b4edba2015-08-14 20:02:05 +00001432 if (die)
1433 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00001434 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1435 if (dwarf_ast)
1436 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001437 }
1438 }
1439 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001440 return CompilerDeclContext();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441}
1442
Greg Clayton99558cc42015-08-24 23:46:31 +00001443
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001445SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446{
Greg Clayton81c22f62011-10-19 18:09:39 +00001447 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001449 DWARFDebugInfo* debug_info = DebugInfo();
1450 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001451 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001452 DWARFDIE type_die = debug_info->GetDIE (DIERef(type_uid));
Greg Clayton6071e6f2015-08-26 22:57:51 +00001453 if (type_die)
1454 {
1455 const bool assert_not_being_parsed = true;
1456 return ResolveTypeUID (type_die, assert_not_being_parsed);
1457 }
Greg Claytonca512b32011-01-14 04:54:56 +00001458 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001459 }
1460 return NULL;
1461}
1462
Greg Claytoncab36a32011-12-08 05:16:30 +00001463Type*
Greg Clayton6071e6f2015-08-26 22:57:51 +00001464SymbolFileDWARF::ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001465{
Greg Clayton6071e6f2015-08-26 22:57:51 +00001466 if (die)
Greg Claytoncab36a32011-12-08 05:16:30 +00001467 {
Greg Clayton5160ce52013-03-27 23:08:40 +00001468 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00001469 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001470 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00001471 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001472 die.GetOffset(),
1473 die.GetTagAsCString(),
1474 die.GetName());
Greg Clayton3bffb082011-12-10 02:15:28 +00001475
Greg Claytoncab36a32011-12-08 05:16:30 +00001476 // We might be coming in in the middle of a type tree (a class
1477 // withing a class, an enum within a class), so parse any needed
1478 // parent DIEs before we get to this one...
Greg Clayton6071e6f2015-08-26 22:57:51 +00001479 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE (die);
1480 if (decl_ctx_die)
Greg Claytoncab36a32011-12-08 05:16:30 +00001481 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001482 if (log)
Greg Claytoncab36a32011-12-08 05:16:30 +00001483 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001484 switch (decl_ctx_die.Tag())
1485 {
1486 case DW_TAG_structure_type:
1487 case DW_TAG_union_type:
1488 case DW_TAG_class_type:
1489 {
1490 // Get the type, which could be a forward declaration
1491 if (log)
1492 GetObjectFile()->GetModule()->LogMessage (log,
1493 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1494 die.GetOffset(),
1495 die.GetTagAsCString(),
1496 die.GetName(),
1497 decl_ctx_die.GetOffset());
1498 }
1499 break;
Greg Claytoncab36a32011-12-08 05:16:30 +00001500
Greg Clayton6071e6f2015-08-26 22:57:51 +00001501 default:
1502 break;
1503 }
1504 }
Greg Claytoncab36a32011-12-08 05:16:30 +00001505 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001506 return ResolveType (die);
Greg Claytoncab36a32011-12-08 05:16:30 +00001507 }
1508 return NULL;
1509}
1510
Greg Clayton6beaaa62011-01-17 03:46:26 +00001511// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1512// SymbolFileDWARF objects to detect if this DWARF file is the one that
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001513// can resolve a compiler_type.
Greg Clayton6beaaa62011-01-17 03:46:26 +00001514bool
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001515SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &compiler_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001516{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001517 CompilerType compiler_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(compiler_type);
1518 return GetForwardDeclClangTypeToDie().count (compiler_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton6beaaa62011-01-17 03:46:26 +00001519}
1520
1521
Greg Clayton57ee3062013-07-11 22:46:58 +00001522bool
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001523SymbolFileDWARF::CompleteType (CompilerType &compiler_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001524{
1525 // We have a struct/union/class/enum that needs to be fully resolved.
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001526 CompilerType compiler_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(compiler_type);
1527 auto die_it = GetForwardDeclClangTypeToDie().find (compiler_type_no_qualifiers.GetOpaqueQualType());
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001528 if (die_it == GetForwardDeclClangTypeToDie().end())
Greg Clayton73b472d2010-10-27 03:32:59 +00001529 {
1530 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00001531 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00001532 }
Tamas Berghammerf8fd9b52015-09-14 15:44:29 +00001533
1534 DWARFDebugInfo* debug_info = DebugInfo();
1535 DWARFDIE dwarf_die = debug_info->GetDIE(die_it->getSecond());
1536
Tamas Berghammer69d0b332015-10-09 12:43:08 +00001537 assert(UserIDMatches(die_it->getSecond().GetUID()) && "CompleteType called on the wrong SymbolFile");
1538
Greg Clayton73b472d2010-10-27 03:32:59 +00001539 // Once we start resolving this type, remove it from the forward declaration
1540 // map in case anyone child members or other types require this type to get resolved.
1541 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1542 // are done.
Tamas Berghammerf8fd9b52015-09-14 15:44:29 +00001543 GetForwardDeclClangTypeToDie().erase (die_it);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001544
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001545 Type *type = GetDIEToType().lookup (dwarf_die.GetDIE());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001546
Greg Clayton5160ce52013-03-27 23:08:40 +00001547 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001548 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001549 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00001550 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001551 dwarf_die.GetID(),
1552 dwarf_die.GetTagAsCString(),
Greg Claytond61c0fc2012-04-23 22:55:20 +00001553 type->GetName().AsCString());
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001554 assert (compiler_type);
Greg Clayton261ac3f2015-08-28 01:01:03 +00001555 DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser();
1556 if (dwarf_ast)
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001557 return dwarf_ast->CompleteTypeFromDWARF (dwarf_die, type, compiler_type);
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001558 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001559}
1560
Greg Clayton8b4edba2015-08-14 20:02:05 +00001561Type*
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00001562SymbolFileDWARF::ResolveType (const DWARFDIE &die, bool assert_not_being_parsed, bool resolve_function_context)
Greg Clayton8b4edba2015-08-14 20:02:05 +00001563{
Greg Clayton6071e6f2015-08-26 22:57:51 +00001564 if (die)
Greg Clayton8b4edba2015-08-14 20:02:05 +00001565 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001566 Type *type = GetDIEToType().lookup (die.GetDIE());
Greg Claytoncab36a32011-12-08 05:16:30 +00001567
Greg Claytonc685f8e2010-09-15 04:15:46 +00001568 if (type == NULL)
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00001569 type = GetTypeForDIE (die, resolve_function_context).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00001570
Greg Clayton24739922010-10-13 03:15:28 +00001571 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00001572 {
1573 if (type != DIE_IS_BEING_PARSED)
1574 return type;
1575
1576 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001577 die.GetOffset(),
1578 die.GetTagAsCString(),
1579 die.GetName());
Jim Inghamc3549282012-01-11 02:21:12 +00001580
1581 }
1582 else
1583 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001584 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001585 return nullptr;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001586}
1587
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001588CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00001589SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001590{
1591 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00001592 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001593 {
1594 // The symbol vendor doesn't know about this compile unit, we
1595 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00001596 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001598 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599}
1600
Greg Clayton8b4edba2015-08-14 20:02:05 +00001601size_t
1602SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets)
1603{
1604 method_die_offsets.clear();
1605 if (m_using_apple_tables)
1606 {
1607 if (m_apple_objc_ap.get())
1608 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
1609 }
1610 else
1611 {
1612 if (!m_indexed)
1613 Index ();
1614
1615 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1616 }
1617 return method_die_offsets.size();
1618}
1619
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001620bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00001621SymbolFileDWARF::GetFunction (const DWARFDIE &die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001622{
Greg Clayton72310352013-02-23 04:12:47 +00001623 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001624
Greg Clayton6071e6f2015-08-26 22:57:51 +00001625 if (die)
1626 {
1627 // Check if the symbol vendor already knows about this compile unit?
1628 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
1629
1630 sc.function = sc.comp_unit->FindFunctionByUID (die.GetID()).get();
1631 if (sc.function == NULL)
1632 sc.function = ParseCompileUnitFunction(sc, die);
1633
1634 if (sc.function)
1635 {
1636 sc.module_sp = sc.function->CalculateSymbolContextModule();
1637 return true;
1638 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00001639 }
1640
1641 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642}
1643
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001644void
1645SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
1646{
1647 if (m_fetched_external_modules)
1648 return;
1649 m_fetched_external_modules = true;
1650
1651 DWARFDebugInfo * debug_info = DebugInfo();
Tamas Berghammereb882fc2015-09-09 10:20:48 +00001652
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001653 const uint32_t num_compile_units = GetNumCompileUnits();
1654 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1655 {
1656 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1657
Greg Clayton5ce1a842015-08-27 18:09:44 +00001658 const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly();
1659 if (die && die.HasChildren() == false)
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001660 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001661 const uint64_t name_strp = die.GetAttributeValueAsUnsigned (DW_AT_name, UINT64_MAX);
1662 const uint64_t dwo_path_strp = die.GetAttributeValueAsUnsigned (DW_AT_GNU_dwo_name, UINT64_MAX);
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001663
1664 if (name_strp != UINT64_MAX)
1665 {
1666 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
1667 {
1668 const char *name = get_debug_str_data().PeekCStr(name_strp);
1669 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
1670 if (name || dwo_path)
1671 {
1672 ModuleSP module_sp;
1673 if (dwo_path)
1674 {
1675 ModuleSpec dwo_module_spec;
1676 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
1677 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
1678 //printf ("Loading dwo = '%s'\n", dwo_path);
1679 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
1680 }
1681
1682 if (dwo_path_strp != LLDB_INVALID_UID)
1683 {
1684 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
1685 }
1686 else
1687 {
1688 // This hack should be removed promptly once clang emits both.
1689 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
1690 }
1691 }
1692 }
1693 }
1694 }
1695 }
1696}
Greg Clayton2501e5e2015-01-15 02:59:20 +00001697
1698SymbolFileDWARF::GlobalVariableMap &
1699SymbolFileDWARF::GetGlobalAranges()
1700{
1701 if (!m_global_aranges_ap)
1702 {
1703 m_global_aranges_ap.reset (new GlobalVariableMap());
1704
1705 ModuleSP module_sp = GetObjectFile()->GetModule();
1706 if (module_sp)
1707 {
1708 const size_t num_cus = module_sp->GetNumCompileUnits();
1709 for (size_t i = 0; i < num_cus; ++i)
1710 {
1711 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1712 if (cu_sp)
1713 {
1714 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1715 if (globals_sp)
1716 {
1717 const size_t num_globals = globals_sp->GetSize();
1718 for (size_t g = 0; g < num_globals; ++g)
1719 {
1720 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1721 if (var_sp && !var_sp->GetLocationIsConstantValueData())
1722 {
1723 const DWARFExpression &location = var_sp->LocationExpression();
1724 Value location_result;
1725 Error error;
1726 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
1727 {
1728 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
1729 {
1730 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
1731 lldb::addr_t byte_size = 1;
1732 if (var_sp->GetType())
1733 byte_size = var_sp->GetType()->GetByteSize();
1734 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
1735 }
1736 }
1737 }
1738 }
1739 }
1740 }
1741 }
1742 }
1743 m_global_aranges_ap->Sort();
1744 }
1745 return *m_global_aranges_ap;
1746}
1747
1748
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749uint32_t
1750SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1751{
1752 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00001753 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001754 static_cast<void*>(so_addr.GetSection().get()),
1755 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001756 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00001757 if (resolve_scope & ( eSymbolContextCompUnit |
1758 eSymbolContextFunction |
1759 eSymbolContextBlock |
1760 eSymbolContextLineEntry |
1761 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762 {
1763 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1764
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001765 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001766 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001767 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001768 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00001769 if (cu_offset == DW_INVALID_OFFSET)
1770 {
1771 // Global variables are not in the compile unit address ranges. The only way to
1772 // currently find global variables is to iterate over the .debug_pubnames or the
1773 // __apple_names table and find all items in there that point to DW_TAG_variable
1774 // DIEs and then find the address that matches.
1775 if (resolve_scope & eSymbolContextVariable)
1776 {
1777 GlobalVariableMap &map = GetGlobalAranges();
1778 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
1779 if (entry && entry->data)
1780 {
1781 Variable *variable = entry->data;
1782 SymbolContextScope *scc = variable->GetSymbolContextScope();
1783 if (scc)
1784 {
1785 scc->CalculateSymbolContext(&sc);
1786 sc.variable = variable;
1787 }
1788 return sc.GetResolvedMask();
1789 }
1790 }
1791 }
1792 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001793 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001794 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001795 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx);
Greg Clayton53eb1c22012-04-02 22:59:12 +00001796 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001797 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001798 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001799 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001801 resolved |= eSymbolContextCompUnit;
1802
Greg Clayton6ab80132012-12-12 17:30:52 +00001803 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001804 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1805 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001806 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1807 DWARFDIE block_die;
1808 if (function_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001810 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
Greg Clayton526a4ae2012-05-16 22:09:01 +00001811 if (sc.function == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001812 sc.function = ParseCompileUnitFunction(sc, function_die);
1813
1814 if (sc.function && (resolve_scope & eSymbolContextBlock))
1815 block_die = function_die.LookupDeepestBlock(file_vm_addr);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001816 }
1817 else
1818 {
1819 // We might have had a compile unit that had discontiguous
1820 // address ranges where the gaps are symbols that don't have
1821 // any debug info. Discontiguous compile unit address ranges
1822 // should only happen when there aren't other functions from
1823 // other compile units in these gaps. This helps keep the size
1824 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00001825 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001826 }
1827
1828 if (sc.function != NULL)
1829 {
1830 resolved |= eSymbolContextFunction;
1831
1832 if (resolve_scope & eSymbolContextBlock)
1833 {
1834 Block& block = sc.function->GetBlock (true);
1835
Greg Clayton6071e6f2015-08-26 22:57:51 +00001836 if (block_die)
1837 sc.block = block.FindBlockByID (block_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001838 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00001839 sc.block = block.FindBlockByID (function_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001840 if (sc.block)
1841 resolved |= eSymbolContextBlock;
1842 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843 }
1844 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001845
1846 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
1847 {
1848 LineTable *line_table = sc.comp_unit->GetLineTable();
1849 if (line_table != NULL)
1850 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001851 // And address that makes it into this function should be in terms
1852 // of this debug file if there is no debug map, or it will be an
1853 // address in the .o file which needs to be fixed up to be in terms
1854 // of the debug map executable. Either way, calling FixupAddress()
1855 // will work for us.
1856 Address exe_so_addr (so_addr);
1857 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00001858 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001859 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00001860 {
1861 resolved |= eSymbolContextLineEntry;
1862 }
1863 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001864 }
1865 }
1866
1867 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
1868 {
1869 // We might have had a compile unit that had discontiguous
1870 // address ranges where the gaps are symbols that don't have
1871 // any debug info. Discontiguous compile unit address ranges
1872 // should only happen when there aren't other functions from
1873 // other compile units in these gaps. This helps keep the size
1874 // of the aranges down.
1875 sc.comp_unit = NULL;
1876 resolved &= ~eSymbolContextCompUnit;
1877 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001878 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00001879 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001881 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
1882 cu_offset,
1883 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884 }
1885 }
1886 }
1887 }
1888 }
1889 return resolved;
1890}
1891
1892
1893
1894uint32_t
1895SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1896{
1897 const uint32_t prev_size = sc_list.GetSize();
1898 if (resolve_scope & eSymbolContextCompUnit)
1899 {
1900 DWARFDebugInfo* debug_info = DebugInfo();
1901 if (debug_info)
1902 {
1903 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00001904 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001905
Greg Clayton53eb1c22012-04-02 22:59:12 +00001906 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001908 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00001909 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00001910 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 +00001911 if (check_inlines || file_spec_matches_cu_file_spec)
1912 {
1913 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00001914 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001915 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001916 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001917 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918
Greg Clayton526a4ae2012-05-16 22:09:01 +00001919 // If we are looking for inline functions only and we don't
1920 // find it in the support files, we are done.
1921 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001923 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
1924 if (file_idx == UINT32_MAX)
1925 continue;
1926 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927
Greg Clayton526a4ae2012-05-16 22:09:01 +00001928 if (line != 0)
1929 {
1930 LineTable *line_table = sc.comp_unit->GetLineTable();
1931
1932 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001934 // We will have already looked up the file index if
1935 // we are searching for inline entries.
1936 if (!check_inlines)
1937 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001938
Greg Clayton526a4ae2012-05-16 22:09:01 +00001939 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001941 uint32_t found_line;
1942 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1943 found_line = sc.line_entry.line;
1944
1945 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001947 sc.function = NULL;
1948 sc.block = NULL;
1949 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001951 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1952 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001954 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1955 DWARFDIE block_die;
1956 if (function_die)
Greg Clayton526a4ae2012-05-16 22:09:01 +00001957 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001958 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
Greg Clayton526a4ae2012-05-16 22:09:01 +00001959 if (sc.function == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001960 sc.function = ParseCompileUnitFunction(sc, function_die);
1961
1962 if (sc.function && (resolve_scope & eSymbolContextBlock))
1963 block_die = function_die.LookupDeepestBlock(file_vm_addr);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001964 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965
Greg Clayton526a4ae2012-05-16 22:09:01 +00001966 if (sc.function != NULL)
1967 {
1968 Block& block = sc.function->GetBlock (true);
1969
Greg Clayton6071e6f2015-08-26 22:57:51 +00001970 if (block_die)
1971 sc.block = block.FindBlockByID (block_die.GetID());
1972 else if (function_die)
1973 sc.block = block.FindBlockByID (function_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001974 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975 }
1976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977
Greg Clayton526a4ae2012-05-16 22:09:01 +00001978 sc_list.Append(sc);
1979 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001981 }
1982 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00001983 else if (file_spec_matches_cu_file_spec && !check_inlines)
1984 {
1985 // only append the context if we aren't looking for inline call sites
1986 // by file and line and if the file spec matches that of the compile unit
1987 sc_list.Append(sc);
1988 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001989 }
1990 else if (file_spec_matches_cu_file_spec && !check_inlines)
1991 {
1992 // only append the context if we aren't looking for inline call sites
1993 // by file and line and if the file spec matches that of the compile unit
1994 sc_list.Append(sc);
1995 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996
Greg Clayton526a4ae2012-05-16 22:09:01 +00001997 if (!check_inlines)
1998 break;
1999 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002000 }
2001 }
2002 }
2003 }
2004 return sc_list.GetSize() - prev_size;
2005}
2006
2007void
2008SymbolFileDWARF::Index ()
2009{
2010 if (m_indexed)
2011 return;
2012 m_indexed = true;
2013 Timer scoped_timer (__PRETTY_FUNCTION__,
2014 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00002015 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016
2017 DWARFDebugInfo* debug_info = DebugInfo();
2018 if (debug_info)
2019 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020 const uint32_t num_compile_units = GetNumCompileUnits();
Tamas Berghammer2ff88702015-10-23 10:34:49 +00002021 std::vector<NameToDIE> function_basename_index(num_compile_units);
2022 std::vector<NameToDIE> function_fullname_index(num_compile_units);
2023 std::vector<NameToDIE> function_method_index(num_compile_units);
2024 std::vector<NameToDIE> function_selector_index(num_compile_units);
2025 std::vector<NameToDIE> objc_class_selectors_index(num_compile_units);
2026 std::vector<NameToDIE> global_index(num_compile_units);
2027 std::vector<NameToDIE> type_index(num_compile_units);
2028 std::vector<NameToDIE> namespace_index(num_compile_units);
2029
2030 auto parser_fn = [this,
2031 debug_info,
2032 &function_basename_index,
2033 &function_fullname_index,
2034 &function_method_index,
2035 &function_selector_index,
2036 &objc_class_selectors_index,
2037 &global_index,
2038 &type_index,
2039 &namespace_index](uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002041 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Tamas Berghammer2ff88702015-10-23 10:34:49 +00002042 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded(false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002043
Tamas Berghammer2ff88702015-10-23 10:34:49 +00002044 dwarf_cu->Index(function_basename_index[cu_idx],
2045 function_fullname_index[cu_idx],
2046 function_method_index[cu_idx],
2047 function_selector_index[cu_idx],
2048 objc_class_selectors_index[cu_idx],
2049 global_index[cu_idx],
2050 type_index[cu_idx],
2051 namespace_index[cu_idx]);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002052
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002053 // Keep memory down by clearing DIEs if this generate function
2054 // caused them to be parsed
2055 if (clear_dies)
Tamas Berghammer2ff88702015-10-23 10:34:49 +00002056 dwarf_cu->ClearDIEs(true);
2057
2058 return cu_idx;
2059 };
2060
2061 TaskRunner<uint32_t> task_runner;
2062 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2063 task_runner.AddTask(parser_fn, cu_idx);
2064
2065 while (true)
2066 {
2067 std::future<uint32_t> f = task_runner.WaitForNextCompletedTask();
2068 if (!f.valid())
2069 break;
2070 uint32_t cu_idx = f.get();
2071
2072 m_function_basename_index.Append(function_basename_index[cu_idx]);
2073 m_function_fullname_index.Append(function_fullname_index[cu_idx]);
2074 m_function_method_index.Append(function_method_index[cu_idx]);
2075 m_function_selector_index.Append(function_selector_index[cu_idx]);
2076 m_objc_class_selectors_index.Append(objc_class_selectors_index[cu_idx]);
2077 m_global_index.Append(global_index[cu_idx]);
2078 m_type_index.Append(type_index[cu_idx]);
2079 m_namespace_index.Append(namespace_index[cu_idx]);
Tamas Berghammerda4e8ed2015-10-20 15:43:40 +00002080 }
Tamas Berghammer2ff88702015-10-23 10:34:49 +00002081
2082 TaskPool::RunTasks(
2083 [&]() { m_function_basename_index.Finalize(); },
2084 [&]() { m_function_fullname_index.Finalize(); },
2085 [&]() { m_function_method_index.Finalize(); },
2086 [&]() { m_function_selector_index.Finalize(); },
2087 [&]() { m_objc_class_selectors_index.Finalize(); },
2088 [&]() { m_global_index.Finalize(); },
2089 [&]() { m_type_index.Finalize(); },
2090 [&]() { m_namespace_index.Finalize(); });
Greg Claytonc685f8e2010-09-15 04:15:46 +00002091
Greg Clayton24739922010-10-13 03:15:28 +00002092#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002093 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002094 s.Printf ("DWARF index for '%s':",
2095 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002096 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2097 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2098 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2099 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2100 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2101 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002102 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00002103 s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002104#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002105 }
2106}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002107
2108bool
Greg Clayton99558cc42015-08-24 23:46:31 +00002109SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx)
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002110{
Greg Clayton99558cc42015-08-24 23:46:31 +00002111 if (decl_ctx == nullptr || !decl_ctx->IsValid())
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002112 {
2113 // Invalid namespace decl which means we aren't matching only things
2114 // in this symbol file, so return true to indicate it matches this
2115 // symbol file.
2116 return true;
2117 }
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002118
Greg Clayton56939cb2015-09-17 22:23:34 +00002119 TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem();
2120 TypeSystem *type_system = GetTypeSystemForLanguage(decl_ctx_type_system->GetMinimumLanguage(nullptr));
2121 if (decl_ctx_type_system == type_system)
Greg Clayton99558cc42015-08-24 23:46:31 +00002122 return true; // The type systems match, return true
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002123
2124 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002125 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002126
2127 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002128 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002129
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002130 return false;
2131}
2132
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002133uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002134SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002135{
Greg Clayton5160ce52013-03-27 23:08:40 +00002136 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002137
2138 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002139 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002140 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00002141 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002142 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002143 append, max_matches);
2144
Greg Clayton99558cc42015-08-24 23:46:31 +00002145 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002146 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002147
Greg Claytonc685f8e2010-09-15 04:15:46 +00002148 DWARFDebugInfo* info = DebugInfo();
2149 if (info == NULL)
2150 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002151
2152 // If we aren't appending the results to this list, then clear the list
2153 if (!append)
2154 variables.Clear();
2155
2156 // Remember how many variables are in the list before we search in case
2157 // we are appending the results to a variable list.
2158 const uint32_t original_size = variables.GetSize();
2159
Greg Claytond4a2b372011-09-12 23:21:58 +00002160 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002161
Greg Clayton97fbc342011-10-20 22:30:33 +00002162 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002163 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002164 if (m_apple_names_ap.get())
2165 {
2166 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00002167 llvm::StringRef basename;
2168 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002169
Jim Inghamaa816b82015-09-02 01:59:14 +00002170 if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename))
Jim Inghamfa39bb42014-10-25 00:33:55 +00002171 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002172
Jim Inghamfa39bb42014-10-25 00:33:55 +00002173 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00002174 }
Greg Clayton7f995132011-10-04 22:41:51 +00002175 }
2176 else
2177 {
2178 // Index the DWARF if we haven't already
2179 if (!m_indexed)
2180 Index ();
2181
2182 m_global_index.Find (name, die_offsets);
2183 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002184
Greg Clayton437a1352012-04-09 22:43:43 +00002185 const size_t num_die_matches = die_offsets.size();
2186 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002187 {
Greg Clayton7f995132011-10-04 22:41:51 +00002188 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002189 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002190 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002191
Greg Claytond4a2b372011-09-12 23:21:58 +00002192 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00002193 bool done = false;
2194 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002195 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002196 const DIERef& die_ref = die_offsets[i];
2197 DWARFDIE die = debug_info->GetDIE (die_ref);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002198
Greg Clayton95d87902011-11-11 03:16:25 +00002199 if (die)
2200 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002201 switch (die.Tag())
Greg Clayton437a1352012-04-09 22:43:43 +00002202 {
2203 default:
2204 case DW_TAG_subprogram:
2205 case DW_TAG_inlined_subroutine:
2206 case DW_TAG_try_block:
2207 case DW_TAG_catch_block:
2208 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002209
Greg Clayton437a1352012-04-09 22:43:43 +00002210 case DW_TAG_variable:
2211 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002212 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002213
Greg Clayton99558cc42015-08-24 23:46:31 +00002214 if (parent_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00002215 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002216 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2217 if (dwarf_ast)
Greg Clayton99558cc42015-08-24 23:46:31 +00002218 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002219 CompilerDeclContext actual_parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00002220 if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx)
2221 continue;
2222 }
Greg Clayton8b4edba2015-08-14 20:02:05 +00002223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002224
Greg Clayton6071e6f2015-08-26 22:57:51 +00002225 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002226
Greg Clayton437a1352012-04-09 22:43:43 +00002227 if (variables.GetSize() - original_size >= max_matches)
2228 done = true;
2229 }
2230 break;
2231 }
Greg Clayton95d87902011-11-11 03:16:25 +00002232 }
2233 else
2234 {
2235 if (m_using_apple_tables)
2236 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002237 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002238 die_ref.die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002239 }
2240 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002242 }
2243
2244 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002245 const uint32_t num_matches = variables.GetSize() - original_size;
2246 if (log && num_matches > 0)
2247 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002248 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002249 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002250 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002251 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002252 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002253 num_matches);
2254 }
2255 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002256}
2257
2258uint32_t
2259SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2260{
Greg Clayton5160ce52013-03-27 23:08:40 +00002261 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002262
Greg Clayton21f2a492011-10-06 00:09:08 +00002263 if (log)
2264 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002265 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002266 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002267 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002268 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002269 }
2270
Greg Claytonc685f8e2010-09-15 04:15:46 +00002271 DWARFDebugInfo* info = DebugInfo();
2272 if (info == NULL)
2273 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002274
2275 // If we aren't appending the results to this list, then clear the list
2276 if (!append)
2277 variables.Clear();
2278
2279 // Remember how many variables are in the list before we search in case
2280 // we are appending the results to a variable list.
2281 const uint32_t original_size = variables.GetSize();
2282
Greg Clayton7f995132011-10-04 22:41:51 +00002283 DIEArray die_offsets;
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002284
Greg Clayton97fbc342011-10-20 22:30:33 +00002285 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002286 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002287 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002288 {
2289 DWARFMappedHash::DIEInfoArray hash_data_array;
2290 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2291 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2292 }
Greg Clayton7f995132011-10-04 22:41:51 +00002293 }
2294 else
2295 {
2296 // Index the DWARF if we haven't already
2297 if (!m_indexed)
2298 Index ();
2299
2300 m_global_index.Find (regex, die_offsets);
2301 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002302
Greg Claytonc685f8e2010-09-15 04:15:46 +00002303 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002304 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002305 assert (sc.module_sp);
2306
Greg Clayton7f995132011-10-04 22:41:51 +00002307 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002308 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002309 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002310 DWARFDebugInfo* debug_info = DebugInfo();
2311 for (size_t i=0; i<num_matches; ++i)
2312 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002313 const DIERef& die_ref = die_offsets[i];
2314 DWARFDIE die = debug_info->GetDIE (die_ref);
Greg Clayton95d87902011-11-11 03:16:25 +00002315
2316 if (die)
2317 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002318 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002319
Greg Clayton6071e6f2015-08-26 22:57:51 +00002320 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002321
Greg Clayton95d87902011-11-11 03:16:25 +00002322 if (variables.GetSize() - original_size >= max_matches)
2323 break;
2324 }
2325 else
2326 {
2327 if (m_using_apple_tables)
2328 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002329 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002330 die_ref.die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002331 }
2332 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002333 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002334 }
2335
2336 // Return the number of variable that were appended to the list
2337 return variables.GetSize() - original_size;
2338}
2339
Greg Claytonaa044962011-10-13 00:59:38 +00002340
Jim Ingham4cda6e02011-10-07 22:23:45 +00002341bool
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002342SymbolFileDWARF::ResolveFunction (const DIERef& die_ref,
Pavel Labatha73d6572015-03-13 10:22:00 +00002343 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00002344 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002345{
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002346 DWARFDIE die = DebugInfo()->GetDIE (die_ref);
Greg Clayton6071e6f2015-08-26 22:57:51 +00002347 return ResolveFunction (die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00002348}
2349
2350
2351bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00002352SymbolFileDWARF::ResolveFunction (const DWARFDIE &orig_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002353 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00002354 SymbolContextList& sc_list)
2355{
Greg Clayton9e315582011-09-02 04:03:59 +00002356 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002357
Greg Clayton6071e6f2015-08-26 22:57:51 +00002358 if (!orig_die)
Greg Claytonaa044962011-10-13 00:59:38 +00002359 return false;
2360
Jim Ingham4cda6e02011-10-07 22:23:45 +00002361 // If we were passed a die that is not a function, just return false...
Greg Clayton6071e6f2015-08-26 22:57:51 +00002362 if (!(orig_die.Tag() == DW_TAG_subprogram || (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002363 return false;
Greg Clayton6071e6f2015-08-26 22:57:51 +00002364
2365 DWARFDIE die = orig_die;
2366 DWARFDIE inlined_die;
2367 if (die.Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002368 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002369 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002370
Greg Clayton6071e6f2015-08-26 22:57:51 +00002371 while (1)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002372 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002373 die = die.GetParent();
2374
2375 if (die)
2376 {
2377 if (die.Tag() == DW_TAG_subprogram)
2378 break;
2379 }
2380 else
Jim Ingham4cda6e02011-10-07 22:23:45 +00002381 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002382 }
2383 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00002384 assert (die && die.Tag() == DW_TAG_subprogram);
2385 if (GetFunction (die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002386 {
2387 Address addr;
2388 // Parse all blocks if needed
2389 if (inlined_die)
2390 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002391 Block &function_block = sc.function->GetBlock (true);
Greg Clayton6071e6f2015-08-26 22:57:51 +00002392 sc.block = function_block.FindBlockByID (inlined_die.GetID());
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002393 if (sc.block == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00002394 sc.block = function_block.FindBlockByID (inlined_die.GetOffset());
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002395 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002396 addr.Clear();
2397 }
2398 else
2399 {
2400 sc.block = NULL;
2401 addr = sc.function->GetAddressRange().GetBaseAddress();
2402 }
2403
2404 if (addr.IsValid())
2405 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002406 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002407 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002408 }
2409 }
2410
Greg Claytonaa044962011-10-13 00:59:38 +00002411 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002412}
2413
Greg Clayton7f995132011-10-04 22:41:51 +00002414void
2415SymbolFileDWARF::FindFunctions (const ConstString &name,
2416 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002417 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002418 SymbolContextList& sc_list)
2419{
Greg Claytond4a2b372011-09-12 23:21:58 +00002420 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002421 if (name_to_die.Find (name, die_offsets))
2422 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002423 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002424 }
2425}
2426
2427
2428void
2429SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2430 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002431 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002432 SymbolContextList& sc_list)
2433{
2434 DIEArray die_offsets;
2435 if (name_to_die.Find (regex, die_offsets))
2436 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002437 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002438 }
2439}
2440
2441
2442void
2443SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2444 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00002445 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002446 SymbolContextList& sc_list)
2447{
2448 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002449 DWARFMappedHash::DIEInfoArray hash_data_array;
2450 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002451 {
Greg Claytond1767f02011-12-08 02:13:16 +00002452 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00002453 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002454 }
2455}
2456
2457void
2458SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00002459 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002460 SymbolContextList& sc_list)
2461{
2462 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002463 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002464 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002465 for (size_t i=0; i<num_matches; ++i)
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002466 ResolveFunction (die_offsets[i], include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002467 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002468}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002469
Jim Ingham4cda6e02011-10-07 22:23:45 +00002470bool
Greg Clayton99558cc42015-08-24 23:46:31 +00002471SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx,
Greg Clayton6071e6f2015-08-26 22:57:51 +00002472 const DWARFDIE &die)
Greg Clayton99558cc42015-08-24 23:46:31 +00002473{
2474 // If we have no parent decl context to match this DIE matches, and if the parent
2475 // decl context isn't valid, we aren't trying to look for any particular decl
2476 // context so any die matches.
2477 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2478 return true;
2479
Greg Clayton6071e6f2015-08-26 22:57:51 +00002480 if (die)
Greg Clayton99558cc42015-08-24 23:46:31 +00002481 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002482 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2483 if (dwarf_ast)
Greg Clayton99558cc42015-08-24 23:46:31 +00002484 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002485 CompilerDeclContext actual_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00002486 if (actual_decl_ctx)
2487 return actual_decl_ctx == *decl_ctx;
2488 }
2489 }
2490 return false;
2491}
2492
Greg Clayton0c5cd902010-06-28 21:30:43 +00002493uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002494SymbolFileDWARF::FindFunctions (const ConstString &name,
2495 const CompilerDeclContext *parent_decl_ctx,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002496 uint32_t name_type_mask,
2497 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002498 bool append,
2499 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002500{
2501 Timer scoped_timer (__PRETTY_FUNCTION__,
2502 "SymbolFileDWARF::FindFunctions (name = '%s')",
2503 name.AsCString());
2504
Greg Clayton43fe2172013-04-03 02:00:15 +00002505 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
2506 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
2507
Greg Clayton5160ce52013-03-27 23:08:40 +00002508 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002509
2510 if (log)
2511 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002512 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002513 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2514 name.GetCString(),
2515 name_type_mask,
2516 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002517 }
2518
Greg Clayton0c5cd902010-06-28 21:30:43 +00002519 // If we aren't appending the results to this list, then clear the list
2520 if (!append)
2521 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002522
Greg Clayton99558cc42015-08-24 23:46:31 +00002523 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002524 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002525
2526 // If name is empty then we won't find anything.
2527 if (name.IsEmpty())
2528 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002529
2530 // Remember how many sc_list are in the list before we search in case
2531 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002532
Jim Ingham4cda6e02011-10-07 22:23:45 +00002533 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00002534
2535 const uint32_t original_size = sc_list.GetSize();
2536
Jim Ingham4cda6e02011-10-07 22:23:45 +00002537 DWARFDebugInfo* info = DebugInfo();
2538 if (info == NULL)
2539 return 0;
2540
Greg Clayton43fe2172013-04-03 02:00:15 +00002541 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00002542 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002543 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002544 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002545 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002546
2547 DIEArray die_offsets;
2548
2549 uint32_t num_matches = 0;
2550
Greg Clayton43fe2172013-04-03 02:00:15 +00002551 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002552 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002553 // If they asked for the full name, match what they typed. At some point we may
2554 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2555 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002556 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002557 for (uint32_t i = 0; i < num_matches; i++)
2558 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002559 const DIERef& die_ref = die_offsets[i];
2560 DWARFDIE die = info->GetDIE (die_ref);
Greg Claytonaa044962011-10-13 00:59:38 +00002561 if (die)
2562 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002563 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002564 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002565
Greg Clayton6071e6f2015-08-26 22:57:51 +00002566 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002567 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002568 if (ResolveFunction (die, include_inlines, sc_list))
2569 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002570 }
Greg Claytonaa044962011-10-13 00:59:38 +00002571 }
Greg Clayton95d87902011-11-11 03:16:25 +00002572 else
2573 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002574 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002575 die_ref.die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002576 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002577 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002578 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002579
2580 if (name_type_mask & eFunctionNameTypeSelector)
2581 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002582 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00002583 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00002584
Greg Clayton43fe2172013-04-03 02:00:15 +00002585 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2586 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2587 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00002588
Greg Clayton43fe2172013-04-03 02:00:15 +00002589 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00002590 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002591 const DIERef& die_ref = die_offsets[i];
2592 DWARFDIE die = info->GetDIE (die_ref);
Greg Clayton43fe2172013-04-03 02:00:15 +00002593 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00002594 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002595 const char *die_name = die.GetName();
Jim Inghamaa816b82015-09-02 01:59:14 +00002596 if (ObjCLanguage::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00002597 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002598 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002599 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002600 if (ResolveFunction (die, include_inlines, sc_list))
2601 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002602 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002603 }
2604 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002605 else
2606 {
2607 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002608 die_ref.die_offset, name_cstr);
Greg Clayton43fe2172013-04-03 02:00:15 +00002609 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002610 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002611 die_offsets.clear();
2612 }
2613
Greg Clayton99558cc42015-08-24 23:46:31 +00002614 if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase)
Greg Clayton43fe2172013-04-03 02:00:15 +00002615 {
2616 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2617 // extract the base name, look that up, and if there is any other information in the name we were
2618 // passed in we have to post-filter based on that.
2619
2620 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2621 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2622
2623 for (uint32_t i = 0; i < num_matches; i++)
2624 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002625 const DIERef& die_ref = die_offsets[i];
2626 DWARFDIE die = info->GetDIE (die_ref);
Greg Clayton43fe2172013-04-03 02:00:15 +00002627 if (die)
2628 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002629 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002630 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002631
Greg Clayton43fe2172013-04-03 02:00:15 +00002632
2633 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002634 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() && ResolveFunction (die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002635 {
2636 bool keep_die = true;
2637 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
2638 {
2639 // We are looking for either basenames or methods, so we need to
2640 // trim out the ones we won't want by looking at the type
2641 SymbolContext sc;
2642 if (sc_list.GetLastContext(sc))
2643 {
2644 if (sc.block)
2645 {
2646 // We have an inlined function
2647 }
2648 else if (sc.function)
2649 {
2650 Type *type = sc.function->GetType();
2651
Sean Callananc370a8a2013-09-18 22:59:55 +00002652 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00002653 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002654 CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID());
2655 if (decl_ctx.IsStructUnionOrClass())
Greg Clayton43fe2172013-04-03 02:00:15 +00002656 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002657 if (name_type_mask & eFunctionNameTypeBase)
2658 {
2659 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2660 keep_die = false;
2661 }
2662 }
2663 else
2664 {
2665 if (name_type_mask & eFunctionNameTypeMethod)
2666 {
2667 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2668 keep_die = false;
2669 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002670 }
2671 }
2672 else
2673 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002674 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002675 die_ref.die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00002676 }
2677 }
2678 }
2679 }
2680 if (keep_die)
Greg Clayton6071e6f2015-08-26 22:57:51 +00002681 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002682 }
2683 }
2684 else
2685 {
2686 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002687 die_ref.die_offset, name_cstr);
Greg Clayton43fe2172013-04-03 02:00:15 +00002688 }
2689 }
2690 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002691 }
2692 }
Greg Clayton7f995132011-10-04 22:41:51 +00002693 }
2694 else
2695 {
2696
2697 // Index the DWARF if we haven't already
2698 if (!m_indexed)
2699 Index ();
2700
Greg Clayton7f995132011-10-04 22:41:51 +00002701 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00002702 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002703 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002704
Ed Mastefc7baa02013-09-09 18:00:45 +00002705 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00002706 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00002707 // If we didn't find any functions in the global namespace try
2708 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00002709 // functions that have a namespace but keep functions which
2710 // have an anonymous namespace
2711 // TODO: The arch in the object file isn't correct for MSVC
2712 // binaries on windows, we should find a way to make it
2713 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00002714 if (sc_list.GetSize() == 0)
2715 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002716 ArchSpec arch;
Greg Clayton99558cc42015-08-24 23:46:31 +00002717 if (!parent_decl_ctx &&
Robert Flackeb83fab2015-05-15 18:59:59 +00002718 GetObjectFile()->GetArchitecture(arch) &&
2719 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
2720 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00002721 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002722 SymbolContextList temp_sc_list;
2723 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00002724 SymbolContext sc;
2725 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
2726 {
2727 if (temp_sc_list.GetContextAtIndex(i, sc))
2728 {
Matt Kopeca189d492013-05-10 22:55:24 +00002729 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
2730 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00002731 // Mangled names on Linux and FreeBSD are of the form:
2732 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00002733 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
2734 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00002735 {
2736 sc_list.Append(sc);
2737 }
2738 }
2739 }
2740 }
2741 }
Matt Kopecd6089962013-05-10 17:53:48 +00002742 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002743 DIEArray die_offsets;
Greg Clayton43fe2172013-04-03 02:00:15 +00002744 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002745 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002746 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002747 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002748 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002749 DWARFDIE die = info->GetDIE (die_offsets[i]);
Greg Claytonaa044962011-10-13 00:59:38 +00002750 if (die)
2751 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002752 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002753 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002754
Greg Claytonaa044962011-10-13 00:59:38 +00002755 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002756 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002757 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002758 if (ResolveFunction (die, include_inlines, sc_list))
2759 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002760 }
Greg Claytonaa044962011-10-13 00:59:38 +00002761 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002762 }
2763 die_offsets.clear();
2764 }
2765
Greg Clayton43fe2172013-04-03 02:00:15 +00002766 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002767 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002768 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Sean Callanan213fdb82011-10-13 01:49:10 +00002769 return 0; // no methods in namespaces
2770
Greg Clayton43fe2172013-04-03 02:00:15 +00002771 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002772 {
Greg Claytonaa044962011-10-13 00:59:38 +00002773 for (uint32_t i = 0; i < num_base; i++)
2774 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002775 DWARFDIE die = info->GetDIE (die_offsets[i]);
Greg Claytonaa044962011-10-13 00:59:38 +00002776 if (die)
2777 {
Greg Claytonaa044962011-10-13 00:59:38 +00002778 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002779 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002780 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002781 if (ResolveFunction (die, include_inlines, sc_list))
2782 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002783 }
Greg Claytonaa044962011-10-13 00:59:38 +00002784 }
2785 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002786 }
2787 die_offsets.clear();
2788 }
Greg Clayton7f995132011-10-04 22:41:51 +00002789
Greg Clayton99558cc42015-08-24 23:46:31 +00002790 if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid()))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002791 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002792 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002793 }
2794
Greg Clayton4d01ace2011-09-29 16:58:15 +00002795 }
2796
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002797 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002798 const uint32_t num_matches = sc_list.GetSize() - original_size;
2799
2800 if (log && num_matches > 0)
2801 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002802 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00002803 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00002804 name.GetCString(),
2805 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00002806 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00002807 append,
2808 num_matches);
2809 }
2810 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002811}
2812
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002813uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00002814SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002815{
2816 Timer scoped_timer (__PRETTY_FUNCTION__,
2817 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2818 regex.GetText());
2819
Greg Clayton5160ce52013-03-27 23:08:40 +00002820 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002821
2822 if (log)
2823 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002824 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002825 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2826 regex.GetText(),
2827 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002828 }
2829
2830
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002831 // If we aren't appending the results to this list, then clear the list
2832 if (!append)
2833 sc_list.Clear();
2834
2835 // Remember how many sc_list are in the list before we search in case
2836 // we are appending the results to a variable list.
2837 uint32_t original_size = sc_list.GetSize();
2838
Greg Clayton97fbc342011-10-20 22:30:33 +00002839 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002840 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002841 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00002842 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002843 }
2844 else
2845 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002846 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002847 if (!m_indexed)
2848 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002849
Pavel Labatha73d6572015-03-13 10:22:00 +00002850 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002851
Pavel Labatha73d6572015-03-13 10:22:00 +00002852 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002853 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002854
2855 // Return the number of variable that were appended to the list
2856 return sc_list.GetSize() - original_size;
2857}
Jim Ingham318c9f22011-08-26 19:44:13 +00002858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002859uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00002860SymbolFileDWARF::FindTypes (const SymbolContext& sc,
2861 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00002862 const CompilerDeclContext *parent_decl_ctx,
Greg Claytond1767f02011-12-08 02:13:16 +00002863 bool append,
2864 uint32_t max_matches,
Ravitheja Addepally40697302015-10-08 09:45:41 +00002865 TypeMap& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002866{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002867 DWARFDebugInfo* info = DebugInfo();
2868 if (info == NULL)
2869 return 0;
2870
Greg Clayton5160ce52013-03-27 23:08:40 +00002871 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002872
Greg Clayton21f2a492011-10-06 00:09:08 +00002873 if (log)
2874 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002875 if (parent_decl_ctx)
Greg Clayton5160ce52013-03-27 23:08:40 +00002876 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002877 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)",
Greg Clayton437a1352012-04-09 22:43:43 +00002878 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002879 static_cast<const void*>(parent_decl_ctx),
2880 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002881 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00002882 else
Greg Clayton5160ce52013-03-27 23:08:40 +00002883 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002884 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002885 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00002886 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002887 }
2888
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002889 // If we aren't appending the results to this list, then clear the list
2890 if (!append)
2891 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002892
Greg Clayton99558cc42015-08-24 23:46:31 +00002893 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002894 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002895
Greg Claytond4a2b372011-09-12 23:21:58 +00002896 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002897
Greg Clayton97fbc342011-10-20 22:30:33 +00002898 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002899 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002900 if (m_apple_types_ap.get())
2901 {
2902 const char *name_cstr = name.GetCString();
2903 m_apple_types_ap->FindByName (name_cstr, die_offsets);
2904 }
Greg Clayton7f995132011-10-04 22:41:51 +00002905 }
2906 else
2907 {
2908 if (!m_indexed)
2909 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002910
Greg Clayton7f995132011-10-04 22:41:51 +00002911 m_type_index.Find (name, die_offsets);
2912 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002913
Greg Clayton437a1352012-04-09 22:43:43 +00002914 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00002915
Greg Clayton437a1352012-04-09 22:43:43 +00002916 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002917 {
Greg Clayton7f995132011-10-04 22:41:51 +00002918 const uint32_t initial_types_size = types.GetSize();
Greg Claytond4a2b372011-09-12 23:21:58 +00002919 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00002920 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002921 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002922 const DIERef& die_ref = die_offsets[i];
2923 DWARFDIE die = debug_info->GetDIE (die_ref);
Greg Claytond4a2b372011-09-12 23:21:58 +00002924
Greg Clayton95d87902011-11-11 03:16:25 +00002925 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002926 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002927 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002928 continue; // The containing decl contexts don't match
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002929
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00002930 Type *matching_type = ResolveType (die, true, true);
Greg Clayton95d87902011-11-11 03:16:25 +00002931 if (matching_type)
2932 {
2933 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00002934 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00002935 if (types.GetSize() >= max_matches)
2936 break;
2937 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00002938 }
Greg Clayton95d87902011-11-11 03:16:25 +00002939 else
2940 {
2941 if (m_using_apple_tables)
2942 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002943 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00002944 die_ref.die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002945 }
2946 }
2947
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002948 }
Greg Clayton437a1352012-04-09 22:43:43 +00002949 const uint32_t num_matches = types.GetSize() - initial_types_size;
2950 if (log && num_matches)
2951 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002952 if (parent_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00002953 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002954 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002955 "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 +00002956 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002957 static_cast<const void*>(parent_decl_ctx),
2958 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002959 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002960 num_matches);
2961 }
2962 else
2963 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002964 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002965 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00002966 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002967 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002968 num_matches);
2969 }
2970 }
2971 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002972 }
Greg Clayton7f995132011-10-04 22:41:51 +00002973 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002974}
2975
2976
Greg Clayton99558cc42015-08-24 23:46:31 +00002977CompilerDeclContext
Greg Clayton96d7d742010-11-10 23:42:09 +00002978SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00002979 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00002980 const CompilerDeclContext *parent_decl_ctx)
Greg Clayton96d7d742010-11-10 23:42:09 +00002981{
Greg Clayton5160ce52013-03-27 23:08:40 +00002982 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002983
2984 if (log)
2985 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002986 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002987 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
2988 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00002989 }
2990
Greg Clayton99558cc42015-08-24 23:46:31 +00002991 CompilerDeclContext namespace_decl_ctx;
2992
2993 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2994 return namespace_decl_ctx;
2995
2996
Greg Clayton96d7d742010-11-10 23:42:09 +00002997 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002998 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002999 {
Greg Clayton7f995132011-10-04 22:41:51 +00003000 DIEArray die_offsets;
3001
Greg Clayton526e5af2010-11-13 03:52:47 +00003002 // Index if we already haven't to make sure the compile units
3003 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00003004 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003005 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003006 if (m_apple_namespaces_ap.get())
3007 {
3008 const char *name_cstr = name.GetCString();
3009 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3010 }
Greg Clayton7f995132011-10-04 22:41:51 +00003011 }
3012 else
3013 {
3014 if (!m_indexed)
3015 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00003016
Greg Clayton7f995132011-10-04 22:41:51 +00003017 m_namespace_index.Find (name, die_offsets);
3018 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003019
Greg Clayton7f995132011-10-04 22:41:51 +00003020 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003021 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00003022 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003023 DWARFDebugInfo* debug_info = DebugInfo();
3024 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00003025 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003026 const DIERef& die_ref = die_offsets[i];
3027 DWARFDIE die = debug_info->GetDIE (die_ref);
Greg Clayton6071e6f2015-08-26 22:57:51 +00003028
Greg Clayton95d87902011-11-11 03:16:25 +00003029 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003030 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003031 if (!DIEInDeclContext (parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00003032 continue; // The containing decl contexts don't match
Greg Clayton95d87902011-11-11 03:16:25 +00003033
Greg Clayton261ac3f2015-08-28 01:01:03 +00003034 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
3035 if (dwarf_ast)
Greg Clayton8b4edba2015-08-14 20:02:05 +00003036 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00003037 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00003038 if (namespace_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00003039 break;
Greg Clayton95d87902011-11-11 03:16:25 +00003040 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003041 }
Greg Clayton95d87902011-11-11 03:16:25 +00003042 else
3043 {
3044 if (m_using_apple_tables)
3045 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003046 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003047 die_ref.die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00003048 }
3049 }
3050
Greg Clayton526e5af2010-11-13 03:52:47 +00003051 }
3052 }
Greg Clayton96d7d742010-11-10 23:42:09 +00003053 }
Greg Clayton99558cc42015-08-24 23:46:31 +00003054 if (log && namespace_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00003055 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003056 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00003057 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"",
Greg Clayton437a1352012-04-09 22:43:43 +00003058 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003059 static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()),
3060 static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()),
3061 namespace_decl_ctx.GetName().AsCString("<NULL>"));
Greg Clayton437a1352012-04-09 22:43:43 +00003062 }
3063
Greg Clayton99558cc42015-08-24 23:46:31 +00003064 return namespace_decl_ctx;
Greg Clayton96d7d742010-11-10 23:42:09 +00003065}
3066
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003067TypeSP
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00003068SymbolFileDWARF::GetTypeForDIE (const DWARFDIE &die, bool resolve_function_context)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003069{
3070 TypeSP type_sp;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003071 if (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003072 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003073 Type *type_ptr = GetDIEToType().lookup (die.GetDIE());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003074 if (type_ptr == NULL)
3075 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003076 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU());
Greg Claytonca512b32011-01-14 04:54:56 +00003077 assert (lldb_cu);
3078 SymbolContext sc(lldb_cu);
Ravitheja Addepally40697302015-10-08 09:45:41 +00003079 const DWARFDebugInfoEntry* parent_die = die.GetParent().GetDIE();
3080 while (parent_die != nullptr)
3081 {
3082 if (parent_die->Tag() == DW_TAG_subprogram)
3083 break;
3084 parent_die = parent_die->GetParent();
3085 }
3086 SymbolContext sc_backup = sc;
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00003087 if (resolve_function_context && parent_die != nullptr && !GetFunction(DWARFDIE(die.GetCU(),parent_die), sc))
Ravitheja Addepally40697302015-10-08 09:45:41 +00003088 sc = sc_backup;
3089
Greg Clayton6071e6f2015-08-26 22:57:51 +00003090 type_sp = ParseType(sc, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003091 }
3092 else if (type_ptr != DIE_IS_BEING_PARSED)
3093 {
3094 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003095 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003096 }
3097
3098 }
3099 return type_sp;
3100}
3101
Greg Clayton2bc22f82011-09-30 03:20:47 +00003102
Greg Clayton6071e6f2015-08-26 22:57:51 +00003103DWARFDIE
3104SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFDIE &orig_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003105{
Greg Clayton6071e6f2015-08-26 22:57:51 +00003106 if (orig_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003107 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003108 DWARFDIE die = orig_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003109
Greg Clayton6071e6f2015-08-26 22:57:51 +00003110 while (die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003111 {
3112 // If this is the original DIE that we are searching for a declaration
3113 // for, then don't look in the cache as we don't want our own decl
3114 // context to be our decl context...
Greg Clayton6071e6f2015-08-26 22:57:51 +00003115 if (orig_die != die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003116 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003117 switch (die.Tag())
Greg Clayton2bc22f82011-09-30 03:20:47 +00003118 {
3119 case DW_TAG_compile_unit:
3120 case DW_TAG_namespace:
3121 case DW_TAG_structure_type:
3122 case DW_TAG_union_type:
3123 case DW_TAG_class_type:
Paul Hermand628cbb2015-09-15 23:44:17 +00003124 case DW_TAG_lexical_block:
3125 case DW_TAG_subprogram:
Greg Clayton2bc22f82011-09-30 03:20:47 +00003126 return die;
3127
3128 default:
3129 break;
3130 }
3131 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003132
3133 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
3134 if (spec_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003135 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003136 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
3137 if (decl_ctx_die)
3138 return decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003139 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003140
3141 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3142 if (abs_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003143 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003144 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
3145 if (decl_ctx_die)
3146 return decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003147 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003148
3149 die = die.GetParent();
Greg Clayton2bc22f82011-09-30 03:20:47 +00003150 }
3151 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003152 return DWARFDIE();
Greg Clayton2bc22f82011-09-30 03:20:47 +00003153}
3154
3155
Greg Clayton901c5ca2011-12-03 04:40:03 +00003156Symbol *
3157SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3158{
3159 Symbol *objc_class_symbol = NULL;
3160 if (m_obj_file)
3161 {
Greg Clayton3046e662013-07-10 01:23:25 +00003162 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003163 if (symtab)
3164 {
3165 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3166 eSymbolTypeObjCClass,
3167 Symtab::eDebugNo,
3168 Symtab::eVisibilityAny);
3169 }
3170 }
3171 return objc_class_symbol;
3172}
3173
Greg Claytonc7f03b62012-01-12 04:33:28 +00003174// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3175// then we can end up looking through all class types for a complete type and never find
3176// the full definition. We need to know if this attribute is supported, so we determine
3177// this here and cache th result. We also need to worry about the debug map DWARF file
3178// if we are doing darwin DWARF in .o file debugging.
3179bool
3180SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
3181{
3182 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
3183 {
3184 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3185 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3186 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3187 else
3188 {
3189 DWARFDebugInfo* debug_info = DebugInfo();
3190 const uint32_t num_compile_units = GetNumCompileUnits();
3191 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3192 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003193 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3194 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003195 {
3196 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3197 break;
3198 }
3199 }
3200 }
Greg Clayton1f746072012-08-29 21:13:06 +00003201 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003202 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
3203 }
3204 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3205}
Greg Clayton901c5ca2011-12-03 04:40:03 +00003206
3207// This function can be used when a DIE is found that is a forward declaration
3208// DIE and we want to try and find a type that has the complete definition.
3209TypeSP
Greg Clayton6071e6f2015-08-26 22:57:51 +00003210SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
Greg Claytonc7f03b62012-01-12 04:33:28 +00003211 const ConstString &type_name,
3212 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00003213{
3214
3215 TypeSP type_sp;
3216
Greg Claytonc7f03b62012-01-12 04:33:28 +00003217 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00003218 return type_sp;
3219
3220 DIEArray die_offsets;
3221
3222 if (m_using_apple_tables)
3223 {
3224 if (m_apple_types_ap.get())
3225 {
3226 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00003227 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003228 }
3229 }
3230 else
3231 {
3232 if (!m_indexed)
3233 Index ();
3234
3235 m_type_index.Find (type_name, die_offsets);
3236 }
3237
Greg Clayton901c5ca2011-12-03 04:40:03 +00003238 const size_t num_matches = die_offsets.size();
3239
Greg Clayton901c5ca2011-12-03 04:40:03 +00003240 if (num_matches)
3241 {
3242 DWARFDebugInfo* debug_info = DebugInfo();
3243 for (size_t i=0; i<num_matches; ++i)
3244 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003245 const DIERef& die_ref = die_offsets[i];
3246 DWARFDIE type_die = debug_info->GetDIE (die_ref);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003247
3248 if (type_die)
3249 {
3250 bool try_resolving_type = false;
3251
3252 // Don't try and resolve the DIE we are looking for with the DIE itself!
3253 if (type_die != die)
3254 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003255 switch (type_die.Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00003256 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00003257 case DW_TAG_class_type:
3258 case DW_TAG_structure_type:
3259 try_resolving_type = true;
3260 break;
3261 default:
3262 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00003263 }
3264 }
3265
3266 if (try_resolving_type)
3267 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003268 if (must_be_implementation && type_die.Supports_DW_AT_APPLE_objc_complete_type())
3269 try_resolving_type = type_die.GetAttributeValueAsUnsigned (DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003270
3271 if (try_resolving_type)
3272 {
Ravitheja Addepally46bcbaa2015-11-03 14:24:24 +00003273 Type *resolved_type = ResolveType (type_die, false, true);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003274 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3275 {
Ed Mastea0191d12013-10-17 20:42:56 +00003276 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
Greg Clayton6071e6f2015-08-26 22:57:51 +00003277 die.GetID(),
Jim Ingham4af59612014-12-19 19:20:44 +00003278 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003279 type_die.GetID(),
3280 type_cu->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00003281
Greg Claytonc7f03b62012-01-12 04:33:28 +00003282 if (die)
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003283 GetDIEToType()[die.GetDIE()] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00003284 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003285 break;
3286 }
3287 }
3288 }
3289 }
3290 else
3291 {
3292 if (m_using_apple_tables)
3293 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003294 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003295 die_ref.die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00003296 }
3297 }
3298
3299 }
3300 }
3301 return type_sp;
3302}
3303
Greg Claytona8022fa2012-04-24 21:22:41 +00003304
Greg Clayton80c26302012-02-05 06:12:47 +00003305//----------------------------------------------------------------------
3306// This function helps to ensure that the declaration contexts match for
3307// two different DIEs. Often times debug information will refer to a
3308// forward declaration of a type (the equivalent of "struct my_struct;".
3309// There will often be a declaration of that type elsewhere that has the
3310// full definition. When we go looking for the full type "my_struct", we
3311// will find one or more matches in the accelerator tables and we will
3312// then need to make sure the type was in the same declaration context
3313// as the original DIE. This function can efficiently compare two DIEs
3314// and will return true when the declaration context matches, and false
3315// when they don't.
3316//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00003317bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00003318SymbolFileDWARF::DIEDeclContextsMatch (const DWARFDIE &die1,
3319 const DWARFDIE &die2)
Greg Clayton890ff562012-02-02 05:48:16 +00003320{
Greg Claytona8022fa2012-04-24 21:22:41 +00003321 if (die1 == die2)
3322 return true;
3323
Greg Clayton890ff562012-02-02 05:48:16 +00003324 DWARFDIECollection decl_ctx_1;
3325 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00003326 //The declaration DIE stack is a stack of the declaration context
3327 // DIEs all the way back to the compile unit. If a type "T" is
3328 // declared inside a class "B", and class "B" is declared inside
3329 // a class "A" and class "A" is in a namespace "lldb", and the
3330 // namespace is in a compile unit, there will be a stack of DIEs:
3331 //
3332 // [0] DW_TAG_class_type for "B"
3333 // [1] DW_TAG_class_type for "A"
3334 // [2] DW_TAG_namespace for "lldb"
3335 // [3] DW_TAG_compile_unit for the source file.
3336 //
3337 // We grab both contexts and make sure that everything matches
3338 // all the way back to the compiler unit.
3339
3340 // First lets grab the decl contexts for both DIEs
Greg Clayton6071e6f2015-08-26 22:57:51 +00003341 die1.GetDeclContextDIEs (decl_ctx_1);
3342 die2.GetDeclContextDIEs (decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00003343 // Make sure the context arrays have the same size, otherwise
3344 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00003345 const size_t count1 = decl_ctx_1.Size();
3346 const size_t count2 = decl_ctx_2.Size();
3347 if (count1 != count2)
3348 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00003349
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003350 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00003351 // compile unit. If they don't, then we are done.
Greg Clayton6071e6f2015-08-26 22:57:51 +00003352 DWARFDIE decl_ctx_die1;
3353 DWARFDIE decl_ctx_die2;
Greg Clayton890ff562012-02-02 05:48:16 +00003354 size_t i;
3355 for (i=0; i<count1; i++)
3356 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003357 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3358 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3359 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
Greg Clayton890ff562012-02-02 05:48:16 +00003360 return false;
3361 }
Greg Clayton890ff562012-02-02 05:48:16 +00003362#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00003363
3364 // Make sure the top item in the decl context die array is always
3365 // DW_TAG_compile_unit. If it isn't then something went wrong in
Greg Clayton5ce1a842015-08-27 18:09:44 +00003366 // the DWARFDIE::GetDeclContextDIEs() function...
Greg Clayton6071e6f2015-08-26 22:57:51 +00003367 assert (decl_ctx_1.GetDIEAtIndex (count1 - 1).Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00003368
Greg Clayton890ff562012-02-02 05:48:16 +00003369#endif
3370 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00003371 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00003372 for (i=0; i<count1 - 1; i++)
3373 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003374 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3375 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3376 const char *name1 = decl_ctx_die1.GetName();
3377 const char *name2 = decl_ctx_die2.GetName();
Greg Clayton890ff562012-02-02 05:48:16 +00003378 // If the string was from a DW_FORM_strp, then the pointer will often
3379 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00003380 if (name1 == name2)
3381 continue;
3382
3383 // Name pointers are not equal, so only compare the strings
3384 // if both are not NULL.
3385 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00003386 {
Greg Clayton5569e642012-02-06 01:44:54 +00003387 // If the strings don't compare, we are done...
3388 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00003389 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00003390 }
3391 else
3392 {
3393 // One name was NULL while the other wasn't
3394 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00003395 }
3396 }
Greg Clayton80c26302012-02-05 06:12:47 +00003397 // We made it through all of the checks and the declaration contexts
3398 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00003399 return true;
3400}
Greg Clayton220a0072011-12-09 08:48:30 +00003401
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003402
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003403TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00003404SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
3405{
3406 TypeSP type_sp;
3407
3408 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
3409 if (dwarf_decl_ctx_count > 0)
3410 {
3411 const ConstString type_name(dwarf_decl_ctx[0].name);
3412 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
3413
3414 if (type_name)
3415 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003416 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00003417 if (log)
3418 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003419 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003420 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
3421 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3422 dwarf_decl_ctx.GetQualifiedName());
3423 }
3424
3425 DIEArray die_offsets;
3426
3427 if (m_using_apple_tables)
3428 {
3429 if (m_apple_types_ap.get())
3430 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003431 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
3432 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
3433 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00003434 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003435 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
3436 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
3437 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003438 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003439 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
3440 }
3441 else if (has_tag)
3442 {
3443 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003444 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00003445 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
3446 }
3447 else
3448 {
3449 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
3450 }
3451 }
3452 }
3453 else
3454 {
3455 if (!m_indexed)
3456 Index ();
3457
3458 m_type_index.Find (type_name, die_offsets);
3459 }
3460
3461 const size_t num_matches = die_offsets.size();
3462
3463
Greg Claytona8022fa2012-04-24 21:22:41 +00003464 if (num_matches)
3465 {
3466 DWARFDebugInfo* debug_info = DebugInfo();
3467 for (size_t i=0; i<num_matches; ++i)
3468 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003469 const DIERef& die_ref = die_offsets[i];
3470 DWARFDIE type_die = debug_info->GetDIE (die_ref);
Greg Claytona8022fa2012-04-24 21:22:41 +00003471
3472 if (type_die)
3473 {
3474 bool try_resolving_type = false;
3475
3476 // Don't try and resolve the DIE we are looking for with the DIE itself!
Greg Clayton6071e6f2015-08-26 22:57:51 +00003477 const dw_tag_t type_tag = type_die.Tag();
Greg Claytona8022fa2012-04-24 21:22:41 +00003478 // Make sure the tags match
3479 if (type_tag == tag)
3480 {
3481 // The tags match, lets try resolving this type
3482 try_resolving_type = true;
3483 }
3484 else
3485 {
3486 // The tags don't match, but we need to watch our for a
3487 // forward declaration for a struct and ("struct foo")
3488 // ends up being a class ("class foo { ... };") or
3489 // vice versa.
3490 switch (type_tag)
3491 {
3492 case DW_TAG_class_type:
3493 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3494 try_resolving_type = (tag == DW_TAG_structure_type);
3495 break;
3496 case DW_TAG_structure_type:
3497 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3498 try_resolving_type = (tag == DW_TAG_class_type);
3499 break;
3500 default:
3501 // Tags don't match, don't event try to resolve
3502 // using this type whose name matches....
3503 break;
3504 }
3505 }
3506
3507 if (try_resolving_type)
3508 {
3509 DWARFDeclContext type_dwarf_decl_ctx;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003510 type_die.GetDWARFDeclContext (type_dwarf_decl_ctx);
Greg Claytona8022fa2012-04-24 21:22:41 +00003511
3512 if (log)
3513 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003514 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003515 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
3516 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3517 dwarf_decl_ctx.GetQualifiedName(),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003518 type_die.GetOffset(),
Greg Claytona8022fa2012-04-24 21:22:41 +00003519 type_dwarf_decl_ctx.GetQualifiedName());
3520 }
3521
3522 // Make sure the decl contexts match all the way up
3523 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
3524 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003525 Type *resolved_type = ResolveType (type_die, false);
Greg Claytona8022fa2012-04-24 21:22:41 +00003526 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3527 {
3528 type_sp = resolved_type->shared_from_this();
3529 break;
3530 }
3531 }
3532 }
3533 else
3534 {
3535 if (log)
3536 {
3537 std::string qualified_name;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003538 type_die.GetQualifiedName(qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00003539 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003540 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
3541 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3542 dwarf_decl_ctx.GetQualifiedName(),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003543 type_die.GetOffset(),
Greg Claytona8022fa2012-04-24 21:22:41 +00003544 qualified_name.c_str());
3545 }
3546 }
3547 }
3548 else
3549 {
3550 if (m_using_apple_tables)
3551 {
3552 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003553 die_ref.die_offset, type_name.GetCString());
Greg Claytona8022fa2012-04-24 21:22:41 +00003554 }
3555 }
3556
3557 }
3558 }
3559 }
3560 }
3561 return type_sp;
3562}
3563
Greg Claytona8022fa2012-04-24 21:22:41 +00003564TypeSP
Greg Clayton6071e6f2015-08-26 22:57:51 +00003565SymbolFileDWARF::ParseType (const SymbolContext& sc, const DWARFDIE &die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003566{
Greg Clayton196e8cd2015-08-17 20:31:46 +00003567 TypeSP type_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003568
Greg Clayton6071e6f2015-08-26 22:57:51 +00003569 if (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003570 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003571 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
3572
3573 if (type_system)
Greg Clayton196e8cd2015-08-17 20:31:46 +00003574 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00003575 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
3576 if (dwarf_ast)
Greg Clayton6071e6f2015-08-26 22:57:51 +00003577 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00003578 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3579 type_sp = dwarf_ast->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr);
3580 if (type_sp)
3581 {
3582 TypeList* type_list = GetTypeList();
3583 if (type_list)
3584 type_list->Insert(type_sp);
3585 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003586 }
Greg Clayton196e8cd2015-08-17 20:31:46 +00003587 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003588 }
Greg Clayton196e8cd2015-08-17 20:31:46 +00003589
3590 return type_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003591}
3592
3593size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003594SymbolFileDWARF::ParseTypes
3595(
3596 const SymbolContext& sc,
Greg Clayton6071e6f2015-08-26 22:57:51 +00003597 const DWARFDIE &orig_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003598 bool parse_siblings,
3599 bool parse_children
3600)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601{
3602 size_t types_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003603 DWARFDIE die = orig_die;
3604 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003605 {
3606 bool type_is_new = false;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003607 if (ParseType(sc, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003608 {
3609 if (type_is_new)
3610 ++types_added;
3611 }
3612
Greg Clayton6071e6f2015-08-26 22:57:51 +00003613 if (parse_children && die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003614 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003615 if (die.Tag() == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003616 {
3617 SymbolContext child_sc(sc);
Greg Clayton6071e6f2015-08-26 22:57:51 +00003618 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3619 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003620 }
3621 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00003622 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003623 }
3624
3625 if (parse_siblings)
Greg Clayton6071e6f2015-08-26 22:57:51 +00003626 die = die.GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003627 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00003628 die.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003629 }
3630 return types_added;
3631}
3632
3633
3634size_t
3635SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3636{
3637 assert(sc.comp_unit && sc.function);
3638 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003639 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003640 if (dwarf_cu)
3641 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003642 const dw_offset_t function_die_offset = sc.function->GetID();
3643 DWARFDIE function_die = dwarf_cu->GetDIE (function_die_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003644 if (function_die)
3645 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003646 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003647 }
3648 }
3649
3650 return functions_added;
3651}
3652
3653
3654size_t
3655SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3656{
3657 // At least a compile unit must be valid
3658 assert(sc.comp_unit);
3659 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003660 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003661 if (dwarf_cu)
3662 {
3663 if (sc.function)
3664 {
3665 dw_offset_t function_die_offset = sc.function->GetID();
Greg Clayton6071e6f2015-08-26 22:57:51 +00003666 DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset);
3667 if (func_die && func_die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003668 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003669 types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003670 }
3671 }
3672 else
3673 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003674 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3675 if (dwarf_cu_die && dwarf_cu_die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003676 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003677 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003678 }
3679 }
3680 }
3681
3682 return types_added;
3683}
3684
3685size_t
3686SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3687{
3688 if (sc.comp_unit != NULL)
3689 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00003690 DWARFDebugInfo* info = DebugInfo();
3691 if (info == NULL)
3692 return 0;
3693
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003694 if (sc.function)
3695 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003696 DWARFDIE function_die = info->GetDIE(DIERef(sc.function->GetID()));
Greg Clayton9422dd62013-03-04 21:46:16 +00003697
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003698 const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress (DW_AT_low_pc, LLDB_INVALID_ADDRESS);
Greg Claytonc7bece562013-01-25 18:06:21 +00003699 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003700 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003701 const size_t num_variables = ParseVariables(sc, function_die.GetFirstChild(), func_lo_pc, true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00003702
Greg Claytone38a5ed2012-01-05 03:57:59 +00003703 // Let all blocks know they have parse all their variables
3704 sc.function->GetBlock (false).SetDidParseVariables (true, true);
3705 return num_variables;
3706 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003707 }
3708 else if (sc.comp_unit)
3709 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003710 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID());
Greg Clayton9422dd62013-03-04 21:46:16 +00003711
3712 if (dwarf_cu == NULL)
3713 return 0;
3714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003715 uint32_t vars_added = 0;
3716 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3717
3718 if (variables.get() == NULL)
3719 {
3720 variables.reset(new VariableList());
3721 sc.comp_unit->SetVariableList(variables);
3722
Greg Claytond4a2b372011-09-12 23:21:58 +00003723 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00003724 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003725 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003726 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003727 {
3728 DWARFMappedHash::DIEInfoArray hash_data_array;
3729 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
3730 dwarf_cu->GetNextCompileUnitOffset(),
3731 hash_data_array))
3732 {
3733 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3734 }
3735 }
Greg Clayton7f995132011-10-04 22:41:51 +00003736 }
3737 else
3738 {
3739 // Index if we already haven't to make sure the compile units
3740 // get indexed and make their global DIE index list
3741 if (!m_indexed)
3742 Index ();
3743
3744 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
Greg Clayton7f995132011-10-04 22:41:51 +00003745 die_offsets);
3746 }
3747
3748 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003749 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003750 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003751 DWARFDebugInfo* debug_info = DebugInfo();
3752 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003753 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003754 const DIERef& die_ref = die_offsets[i];
3755 DWARFDIE die = debug_info->GetDIE (die_ref);
Greg Clayton95d87902011-11-11 03:16:25 +00003756 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003757 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003758 VariableSP var_sp (ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
Greg Clayton95d87902011-11-11 03:16:25 +00003759 if (var_sp)
3760 {
3761 variables->AddVariableIfUnique (var_sp);
3762 ++vars_added;
3763 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003764 }
Greg Clayton95d87902011-11-11 03:16:25 +00003765 else
3766 {
3767 if (m_using_apple_tables)
3768 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003769 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_ref.die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00003770 }
3771 }
3772
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003773 }
3774 }
3775 }
3776 return vars_added;
3777 }
3778 }
3779 return 0;
3780}
3781
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003782VariableSP
3783SymbolFileDWARF::ParseVariableDIE
3784(
3785 const SymbolContext& sc,
Greg Clayton6071e6f2015-08-26 22:57:51 +00003786 const DWARFDIE &die,
Greg Clayton016a95e2010-09-14 02:20:48 +00003787 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003788)
3789{
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003790 if (die.GetDWARF() != this)
3791 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
3792
Greg Clayton6071e6f2015-08-26 22:57:51 +00003793 VariableSP var_sp;
3794 if (!die)
3795 return var_sp;
3796
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003797 var_sp = GetDIEToVariable()[die.GetDIE()];
Greg Clayton83c5cd92010-11-14 22:13:40 +00003798 if (var_sp)
3799 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003800
Greg Clayton6071e6f2015-08-26 22:57:51 +00003801 const dw_tag_t tag = die.Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00003802 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003803
3804 if ((tag == DW_TAG_variable) ||
3805 (tag == DW_TAG_constant) ||
3806 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003807 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003808 DWARFAttributes attributes;
3809 const size_t num_attributes = die.GetAttributes(attributes);
Paul Hermand628cbb2015-09-15 23:44:17 +00003810 DWARFDIE spec_die;
Greg Clayton7f995132011-10-04 22:41:51 +00003811 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003812 {
Greg Clayton7f995132011-10-04 22:41:51 +00003813 const char *name = NULL;
3814 const char *mangled = NULL;
3815 Declaration decl;
3816 uint32_t i;
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003817 DWARFFormValue type_die_form;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003818 DWARFExpression location(die.GetCU());
Greg Clayton7f995132011-10-04 22:41:51 +00003819 bool is_external = false;
3820 bool is_artificial = false;
3821 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003822 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00003823 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00003824 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00003825
3826 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003827 {
Greg Clayton7f995132011-10-04 22:41:51 +00003828 dw_attr_t attr = attributes.AttributeAtIndex(i);
3829 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00003830
Greg Clayton6071e6f2015-08-26 22:57:51 +00003831 if (attributes.ExtractFormValueAtIndex(i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003832 {
Greg Clayton7f995132011-10-04 22:41:51 +00003833 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003834 {
Greg Clayton7f995132011-10-04 22:41:51 +00003835 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3836 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3837 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003838 case DW_AT_name: name = form_value.AsCString(); break;
Greg Clayton71415542012-12-08 00:24:40 +00003839 case DW_AT_linkage_name:
Greg Clayton6071e6f2015-08-26 22:57:51 +00003840 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(); break;
Tamas Berghammereb882fc2015-09-09 10:20:48 +00003841 case DW_AT_type: type_die_form = form_value; break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00003842 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00003843 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003844 // If we have already found a DW_AT_location attribute, ignore this attribute.
3845 if (!has_explicit_location)
3846 {
3847 location_is_const_value_data = true;
3848 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00003849 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003850 if (DWARFFormValue::IsBlockForm(form_value.Form()))
3851 {
3852 // Retrieve the value as a block expression.
3853 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3854 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00003855 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003856 }
3857 else if (DWARFFormValue::IsDataForm(form_value.Form()))
3858 {
3859 // Retrieve the value as a data expression.
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003860 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3861 DWARFFormValue::GetFixedFormSizesForAddressSize (
3862 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
3863 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003864 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003865 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Enrico Granata4ec130d2014-08-11 19:16:35 +00003866 if (data_length == 0)
3867 {
3868 const uint8_t *data_pointer = form_value.BlockData();
3869 if (data_pointer)
3870 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00003871 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00003872 }
3873 else if (DWARFFormValue::IsDataForm(form_value.Form()))
3874 {
3875 // we need to get the byte size of the type later after we create the variable
3876 const_value = form_value;
3877 }
3878 }
3879 else
3880 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003881 }
3882 else
3883 {
3884 // Retrieve the value as a string expression.
3885 if (form_value.Form() == DW_FORM_strp)
3886 {
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003887 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3888 DWARFFormValue::GetFixedFormSizesForAddressSize (
3889 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
3890 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003891 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003892 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Richard Mitton0a558352013-10-17 21:14:00 +00003893 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003894 }
3895 else
3896 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003897 const char *str = form_value.AsCString();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003898 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
3899 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00003900 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003901 }
3902 }
3903 }
3904 break;
Greg Clayton7f995132011-10-04 22:41:51 +00003905 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003906 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003907 location_is_const_value_data = false;
3908 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00003909 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003910 {
Ed Masteeeae7212013-10-24 20:43:47 +00003911 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00003912
3913 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3914 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00003915 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00003916 }
3917 else
3918 {
Tamas Berghammer1f5e4482015-09-16 12:37:06 +00003919 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00003920 const dw_offset_t debug_loc_offset = form_value.Unsigned();
3921
Tamas Berghammer1f5e4482015-09-16 12:37:06 +00003922 size_t loc_list_length = DWARFExpression::LocationListSize(die.GetCU(), debug_loc_data, debug_loc_offset);
Greg Clayton7f995132011-10-04 22:41:51 +00003923 if (loc_list_length > 0)
3924 {
Richard Mitton0a558352013-10-17 21:14:00 +00003925 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00003926 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00003927 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00003928 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003929 }
3930 }
Greg Clayton7f995132011-10-04 22:41:51 +00003931 break;
Paul Hermand628cbb2015-09-15 23:44:17 +00003932 case DW_AT_specification:
3933 {
3934 DWARFDebugInfo* debug_info = DebugInfo();
3935 if (debug_info)
3936 spec_die = debug_info->GetDIE(DIERef(form_value));
3937 break;
3938 }
Greg Clayton1c8ef472013-04-05 23:27:21 +00003939 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00003940 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00003941 case DW_AT_declaration:
3942 case DW_AT_description:
3943 case DW_AT_endianity:
3944 case DW_AT_segment:
3945 case DW_AT_start_scope:
3946 case DW_AT_visibility:
3947 default:
3948 case DW_AT_abstract_origin:
3949 case DW_AT_sibling:
Greg Clayton7f995132011-10-04 22:41:51 +00003950 break;
3951 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003952 }
3953 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003954
Greg Clayton6071e6f2015-08-26 22:57:51 +00003955 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3956 const dw_tag_t parent_tag = die.GetParent().Tag();
3957 bool is_static_member = parent_tag == DW_TAG_compile_unit && (parent_context_die.Tag() == DW_TAG_class_type || parent_context_die.Tag() == DW_TAG_structure_type);
Paul Herman10bc1a42015-08-18 22:46:57 +00003958
Greg Clayton9e9f2192013-05-17 00:55:28 +00003959 ValueType scope = eValueTypeInvalid;
3960
Greg Clayton6071e6f2015-08-26 22:57:51 +00003961 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
Greg Clayton9e9f2192013-05-17 00:55:28 +00003962 SymbolContextScope * symbol_context_scope = NULL;
3963
Siva Chandra0783ab92015-03-24 18:32:27 +00003964 if (!mangled)
3965 {
3966 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
3967 // generate fully qualified names of global variables with commands like "frame var j".
3968 // For example, if j were an int variable holding a value 4 and declared in a namespace
3969 // B which in turn is contained in a namespace A, the command "frame var j" returns
3970 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
3971 // to generate a fully qualified name from the declaration context.
Greg Clayton6071e6f2015-08-26 22:57:51 +00003972 if (parent_tag == DW_TAG_compile_unit &&
Jim Ingham0e0984e2015-09-02 01:06:46 +00003973 Language::LanguageIsCPlusPlus(die.GetLanguage()))
Siva Chandra0783ab92015-03-24 18:32:27 +00003974 {
3975 DWARFDeclContext decl_ctx;
3976
Greg Clayton6071e6f2015-08-26 22:57:51 +00003977 die.GetDWARFDeclContext(decl_ctx);
Siva Chandra0783ab92015-03-24 18:32:27 +00003978 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
3979 }
3980 }
3981
Greg Clayton9e9f2192013-05-17 00:55:28 +00003982 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3983 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003984 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00003985 // a DW_OP_addr opcode _somewhere_ in the definition. I say
3986 // somewhere because clang likes to combine small global variables
3987 // into the same symbol and have locations like:
3988 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3989 // So if we don't have a DW_TAG_formal_parameter, we can look at
3990 // the location to see if it contains a DW_OP_addr opcode, and
3991 // then we can correctly classify our variables.
3992 if (tag == DW_TAG_formal_parameter)
3993 scope = eValueTypeVariableArgument;
3994 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003995 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003996 bool op_error = false;
3997 // Check if the location has a DW_OP_addr with any address value...
3998 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3999 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004000 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004001 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
4002 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00004003 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004004 StreamString strm;
4005 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Clayton6071e6f2015-08-26 22:57:51 +00004006 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die.GetOffset(), die.GetTagAsCString(), strm.GetString().c_str());
Greg Clayton96c09682012-01-04 22:56:43 +00004007 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004008 }
Greg Claytond1767f02011-12-08 02:13:16 +00004009
Greg Clayton9e9f2192013-05-17 00:55:28 +00004010 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
4011 {
4012 if (is_external)
4013 scope = eValueTypeVariableGlobal;
4014 else
4015 scope = eValueTypeVariableStatic;
4016
4017
4018 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
4019
4020 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004021 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004022 // When leaving the DWARF in the .o files on darwin,
4023 // when we have a global variable that wasn't initialized,
4024 // the .o file might not have allocated a virtual
4025 // address for the global variable. In this case it will
4026 // have created a symbol for the global variable
4027 // that is undefined/data and external and the value will
4028 // be the byte size of the variable. When we do the
4029 // address map in SymbolFileDWARFDebugMap we rely on
4030 // having an address, we need to do some magic here
4031 // so we can get the correct address for our global
4032 // variable. The address for all of these entries
4033 // will be zero, and there will be an undefined symbol
4034 // in this object file, and the executable will have
4035 // a matching symbol with a good address. So here we
4036 // dig up the correct address and replace it in the
4037 // location for the variable, and set the variable's
4038 // symbol context scope to be that of the main executable
4039 // so the file address will resolve correctly.
4040 bool linked_oso_file_addr = false;
4041 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00004042 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004043 // we have a possible uninitialized extern global
4044 ConstString const_name(mangled ? mangled : name);
4045 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
4046 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004047 {
Greg Clayton3046e662013-07-10 01:23:25 +00004048 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00004049 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004050 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004051 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
4052 eSymbolTypeData,
4053 Symtab::eDebugYes,
4054 Symtab::eVisibilityExtern);
4055 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004056 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004057 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004058 {
Greg Clayton358cf1e2015-06-25 21:46:34 +00004059 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
Greg Clayton9e9f2192013-05-17 00:55:28 +00004060 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004061 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004062 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004063 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004064 linked_oso_file_addr = true;
4065 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004066 }
4067 }
4068 }
4069 }
4070 }
4071 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004072 }
Greg Clayton9422dd62013-03-04 21:46:16 +00004073
Greg Clayton9e9f2192013-05-17 00:55:28 +00004074 if (!linked_oso_file_addr)
4075 {
4076 // The DW_OP_addr is not zero, but it contains a .o file address which
4077 // needs to be linked up correctly.
4078 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
4079 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00004080 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004081 // Update the file address for this variable
4082 location.Update_DW_OP_addr (exe_file_addr);
4083 }
4084 else
4085 {
4086 // Variable didn't make it into the final executable
4087 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00004088 }
Greg Claytond1767f02011-12-08 02:13:16 +00004089 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004090 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00004091 }
4092 else
4093 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004094 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00004095 }
Greg Clayton7f995132011-10-04 22:41:51 +00004096 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004097
4098 if (symbol_context_scope == NULL)
4099 {
4100 switch (parent_tag)
4101 {
4102 case DW_TAG_subprogram:
4103 case DW_TAG_inlined_subroutine:
4104 case DW_TAG_lexical_block:
4105 if (sc.function)
4106 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004107 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
Greg Clayton9e9f2192013-05-17 00:55:28 +00004108 if (symbol_context_scope == NULL)
4109 symbol_context_scope = sc.function;
4110 }
4111 break;
4112
4113 default:
4114 symbol_context_scope = sc.comp_unit;
4115 break;
4116 }
4117 }
4118
4119 if (symbol_context_scope)
4120 {
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004121 SymbolFileTypeSP type_sp(new SymbolFileType(*this, DIERef(type_die_form).GetUID()));
Enrico Granata4ec130d2014-08-11 19:16:35 +00004122
4123 if (const_value.Form() && type_sp && type_sp->GetType())
Greg Clayton6071e6f2015-08-26 22:57:51 +00004124 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), die.GetCU()->GetAddressByteSize());
Enrico Granata4ec130d2014-08-11 19:16:35 +00004125
Greg Clayton6071e6f2015-08-26 22:57:51 +00004126 var_sp.reset (new Variable (die.GetID(),
Greg Clayton9e9f2192013-05-17 00:55:28 +00004127 name,
4128 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00004129 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00004130 scope,
4131 symbol_context_scope,
4132 &decl,
4133 location,
4134 is_external,
Paul Herman10bc1a42015-08-18 22:46:57 +00004135 is_artificial,
4136 is_static_member));
Greg Clayton9e9f2192013-05-17 00:55:28 +00004137
4138 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
4139 }
4140 else
4141 {
4142 // Not ready to parse this variable yet. It might be a global
4143 // or static variable that is in a function scope and the function
4144 // in the symbol context wasn't filled in yet
4145 return var_sp;
4146 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004147 }
Greg Clayton7f995132011-10-04 22:41:51 +00004148 // Cache var_sp even if NULL (the variable was just a specification or
4149 // was missing vital information to be able to be displayed in the debugger
4150 // (missing location due to optimization, etc)) so we don't re-parse
4151 // this DIE over and over later...
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004152 GetDIEToVariable()[die.GetDIE()] = var_sp;
Paul Hermand628cbb2015-09-15 23:44:17 +00004153 if (spec_die)
4154 GetDIEToVariable()[spec_die.GetDIE()] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004155 }
4156 return var_sp;
4157}
4158
Greg Claytonc662ec82011-06-17 22:10:16 +00004159
Greg Clayton6071e6f2015-08-26 22:57:51 +00004160DWARFDIE
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004161SymbolFileDWARF::FindBlockContainingSpecification (const DIERef& func_die_ref,
Greg Clayton6071e6f2015-08-26 22:57:51 +00004162 dw_offset_t spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004163{
4164 // Give the concrete function die specified by "func_die_offset", find the
4165 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4166 // to "spec_block_die_offset"
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004167 return FindBlockContainingSpecification (DebugInfo()->GetDIE (func_die_ref), spec_block_die_offset);
Greg Claytonc662ec82011-06-17 22:10:16 +00004168}
4169
4170
Greg Clayton6071e6f2015-08-26 22:57:51 +00004171DWARFDIE
4172SymbolFileDWARF::FindBlockContainingSpecification(const DWARFDIE &die,
4173 dw_offset_t spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004174{
4175 if (die)
4176 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004177 switch (die.Tag())
Greg Claytonc662ec82011-06-17 22:10:16 +00004178 {
4179 case DW_TAG_subprogram:
4180 case DW_TAG_inlined_subroutine:
4181 case DW_TAG_lexical_block:
4182 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004183 if (die.GetAttributeValueAsReference (DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004184 return die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004185
Greg Clayton6071e6f2015-08-26 22:57:51 +00004186 if (die.GetAttributeValueAsReference (DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004187 return die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004188 }
4189 break;
4190 }
4191
4192 // Give the concrete function die specified by "func_die_offset", find the
4193 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4194 // to "spec_block_die_offset"
Greg Clayton6071e6f2015-08-26 22:57:51 +00004195 for (DWARFDIE child_die = die.GetFirstChild(); child_die; child_die = child_die.GetSibling())
Greg Claytonc662ec82011-06-17 22:10:16 +00004196 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004197 DWARFDIE result_die = FindBlockContainingSpecification (child_die, spec_block_die_offset);
Greg Claytonc662ec82011-06-17 22:10:16 +00004198 if (result_die)
4199 return result_die;
4200 }
4201 }
4202
Greg Clayton6071e6f2015-08-26 22:57:51 +00004203 return DWARFDIE();
Greg Claytonc662ec82011-06-17 22:10:16 +00004204}
4205
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004206size_t
Greg Clayton6071e6f2015-08-26 22:57:51 +00004207SymbolFileDWARF::ParseVariables (const SymbolContext& sc,
4208 const DWARFDIE &orig_die,
4209 const lldb::addr_t func_low_pc,
4210 bool parse_siblings,
4211 bool parse_children,
4212 VariableList* cc_variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004213{
Greg Clayton6071e6f2015-08-26 22:57:51 +00004214 if (!orig_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004215 return 0;
4216
Greg Claytonc662ec82011-06-17 22:10:16 +00004217 VariableListSP variable_list_sp;
4218
4219 size_t vars_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00004220 DWARFDIE die = orig_die;
4221 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004222 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004223 dw_tag_t tag = die.Tag();
Greg Claytonc662ec82011-06-17 22:10:16 +00004224
4225 // Check to see if we have already parsed this variable or constant?
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004226 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
Greg Clayton6071e6f2015-08-26 22:57:51 +00004227 if (var_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004228 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004229 if (cc_variable_list)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004230 cc_variable_list->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004231 }
4232 else
4233 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004234 // We haven't already parsed it, lets do that now.
4235 if ((tag == DW_TAG_variable) ||
4236 (tag == DW_TAG_constant) ||
4237 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004238 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004239 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004240 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004241 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die);
4242 dw_tag_t parent_tag = sc_parent_die.Tag();
Greg Claytonc662ec82011-06-17 22:10:16 +00004243 switch (parent_tag)
4244 {
4245 case DW_TAG_compile_unit:
4246 if (sc.comp_unit != NULL)
4247 {
4248 variable_list_sp = sc.comp_unit->GetVariableList(false);
4249 if (variable_list_sp.get() == NULL)
4250 {
4251 variable_list_sp.reset(new VariableList());
4252 sc.comp_unit->SetVariableList(variable_list_sp);
4253 }
4254 }
4255 else
4256 {
Daniel Malead01b2952012-11-29 21:49:15 +00004257 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 Clayton6071e6f2015-08-26 22:57:51 +00004258 sc_parent_die.GetID(),
4259 sc_parent_die.GetTagAsCString(),
4260 orig_die.GetID(),
4261 orig_die.GetTagAsCString());
Greg Claytonc662ec82011-06-17 22:10:16 +00004262 }
4263 break;
4264
4265 case DW_TAG_subprogram:
4266 case DW_TAG_inlined_subroutine:
4267 case DW_TAG_lexical_block:
4268 if (sc.function != NULL)
4269 {
4270 // Check to see if we already have parsed the variables for the given scope
4271
Greg Clayton6071e6f2015-08-26 22:57:51 +00004272 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
Greg Claytonc662ec82011-06-17 22:10:16 +00004273 if (block == NULL)
4274 {
4275 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00004276 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00004277 // to find the concrete block so we can correctly add the
4278 // variable to it
Tamas Berghammereb882fc2015-09-09 10:20:48 +00004279 const DWARFDIE concrete_block_die = FindBlockContainingSpecification (DIERef(sc.function->GetID()),
Greg Clayton6071e6f2015-08-26 22:57:51 +00004280 sc_parent_die.GetOffset());
Greg Claytonc662ec82011-06-17 22:10:16 +00004281 if (concrete_block_die)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004282 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die.GetID());
Greg Claytonc662ec82011-06-17 22:10:16 +00004283 }
4284
4285 if (block != NULL)
4286 {
4287 const bool can_create = false;
4288 variable_list_sp = block->GetBlockVariableList (can_create);
4289 if (variable_list_sp.get() == NULL)
4290 {
4291 variable_list_sp.reset(new VariableList());
4292 block->SetVariableList(variable_list_sp);
4293 }
4294 }
4295 }
4296 break;
4297
4298 default:
Daniel Malead01b2952012-11-29 21:49:15 +00004299 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
Greg Clayton6071e6f2015-08-26 22:57:51 +00004300 orig_die.GetID(),
4301 orig_die.GetTagAsCString());
Greg Claytonc662ec82011-06-17 22:10:16 +00004302 break;
4303 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004304 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004305
4306 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004307 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004308 VariableSP var_sp (ParseVariableDIE(sc, die, func_low_pc));
Greg Clayton73bf5db2011-06-17 01:22:15 +00004309 if (var_sp)
4310 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004311 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004312 if (cc_variable_list)
4313 cc_variable_list->AddVariableIfUnique (var_sp);
4314 ++vars_added;
4315 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004316 }
4317 }
4318 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004319
4320 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4321
Greg Clayton6071e6f2015-08-26 22:57:51 +00004322 if (!skip_children && parse_children && die.HasChildren())
Greg Claytonc662ec82011-06-17 22:10:16 +00004323 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004324 vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, true, cc_variable_list);
Greg Claytonc662ec82011-06-17 22:10:16 +00004325 }
4326
4327 if (parse_siblings)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004328 die = die.GetSibling();
Greg Claytonc662ec82011-06-17 22:10:16 +00004329 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00004330 die.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004331 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004332 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004333}
4334
4335//------------------------------------------------------------------
4336// PluginInterface protocol
4337//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00004338ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004339SymbolFileDWARF::GetPluginName()
4340{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004341 return GetPluginNameStatic();
4342}
4343
4344uint32_t
4345SymbolFileDWARF::GetPluginVersion()
4346{
4347 return 1;
4348}
4349
4350void
Sean Callanancc427fa2011-07-30 02:42:06 +00004351SymbolFileDWARF::DumpIndexes ()
4352{
4353 StreamFile s(stdout, false);
4354
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004355 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00004356 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004357 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00004358 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4359 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4360 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4361 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4362 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4363 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4364 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00004365 s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
Sean Callanancc427fa2011-07-30 02:42:06 +00004366}
4367
Greg Claytoncaab74e2012-01-28 00:48:57 +00004368
Greg Clayton1f746072012-08-29 21:13:06 +00004369SymbolFileDWARFDebugMap *
4370SymbolFileDWARF::GetDebugMapSymfile ()
4371{
4372 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
4373 {
4374 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
4375 if (module_sp)
4376 {
4377 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
4378 if (sym_vendor)
4379 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
4380 }
4381 }
4382 return m_debug_map_symfile;
4383}
Tamas Berghammer1f5e4482015-09-16 12:37:06 +00004384
4385DWARFExpression::LocationListFormat
4386SymbolFileDWARF::GetLocationListFormat() const
4387{
4388 return DWARFExpression::RegularLocationList;
4389}