blob: 1c3f976cc644530b7fbeb81fc1f8f39419f6d7c3 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
Jim Inghame3ae82a2011-11-12 01:36:43 +000017#include "clang/AST/DeclObjC.h"
Greg Clayton3c2e3ae2012-02-06 06:42:51 +000018#include "clang/AST/DeclTemplate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "clang/Basic/Builtins.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Basic/SourceManager.h"
23#include "clang/Basic/TargetInfo.h"
24#include "clang/Basic/Specifiers.h"
Greg Clayton7fedea22010-11-16 02:10:54 +000025#include "clang/Sema/DeclSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Sean Callanancc427fa2011-07-30 02:42:06 +000027#include "llvm/Support/Casting.h"
28
Robert Flackeb83fab2015-05-15 18:59:59 +000029#include "lldb/Core/ArchSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/Module.h"
Sean Callananf0c5aeb2015-04-20 16:31:29 +000031#include "lldb/Core/ModuleList.h"
32#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/PluginManager.h"
34#include "lldb/Core/RegularExpression.h"
35#include "lldb/Core/Scalar.h"
36#include "lldb/Core/Section.h"
Greg Claytonc685f8e2010-09-15 04:15:46 +000037#include "lldb/Core/StreamFile.h"
Jim Ingham318c9f22011-08-26 19:44:13 +000038#include "lldb/Core/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Core/Timer.h"
40#include "lldb/Core/Value.h"
41
Sean Callananf0c5aeb2015-04-20 16:31:29 +000042#include "lldb/Expression/ClangModulesDeclVendor.h"
43
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +000044#include "lldb/Host/FileSystem.h"
Greg Clayton20568dd2011-10-13 23:13:20 +000045#include "lldb/Host/Host.h"
46
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +000047#include "lldb/Interpreter/OptionValueFileSpecList.h"
48#include "lldb/Interpreter/OptionValueProperties.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Symbol/Block.h"
51#include "lldb/Symbol/CompileUnit.h"
52#include "lldb/Symbol/LineTable.h"
53#include "lldb/Symbol/ObjectFile.h"
54#include "lldb/Symbol/SymbolVendor.h"
55#include "lldb/Symbol/VariableList.h"
56
Jim Inghamaa816b82015-09-02 01:59:14 +000057#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
58#include "Plugins/Language/ObjC/ObjCLanguage.h"
Jim Inghamb7f6b2f2011-09-08 22:13:49 +000059
Jim Ingham0e0984e2015-09-02 01:06:46 +000060#include "lldb/Target/Language.h"
61
Greg Clayton261ac3f2015-08-28 01:01:03 +000062#include "DWARFASTParser.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063#include "DWARFCompileUnit.h"
64#include "DWARFDebugAbbrev.h"
65#include "DWARFDebugAranges.h"
66#include "DWARFDebugInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067#include "DWARFDebugLine.h"
68#include "DWARFDebugPubnames.h"
69#include "DWARFDebugRanges.h"
Greg Claytona8022fa2012-04-24 21:22:41 +000070#include "DWARFDeclContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071#include "DWARFDIECollection.h"
72#include "DWARFFormValue.h"
73#include "DWARFLocationList.h"
74#include "LogChannelDWARF.h"
Greg Clayton450e3f32010-10-12 02:24:53 +000075#include "SymbolFileDWARFDebugMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
77#include <map>
78
Matthew Gardinere81df3b2014-08-26 06:57:23 +000079#include <ctype.h>
80#include <string.h>
81
Greg Clayton62742b12010-11-11 01:09:45 +000082//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
Greg Claytonc93237c2010-10-01 20:48:32 +000083
84#ifdef ENABLE_DEBUG_PRINTF
85#include <stdio.h>
Ed Mastea0191d12013-10-17 20:42:56 +000086#define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
Greg Claytonc93237c2010-10-01 20:48:32 +000087#else
88#define DEBUG_PRINTF(fmt, ...)
89#endif
90
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091using namespace lldb;
92using namespace lldb_private;
93
Greg Clayton219cf312012-03-30 00:51:13 +000094//static inline bool
95//child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
96//{
97// switch (tag)
98// {
99// default:
100// break;
101// case DW_TAG_subprogram:
102// case DW_TAG_inlined_subroutine:
103// case DW_TAG_class_type:
104// case DW_TAG_structure_type:
105// case DW_TAG_union_type:
106// return true;
107// }
108// return false;
109//}
110//
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000111
112namespace {
113
114 PropertyDefinition
115 g_properties[] =
116 {
117 { "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." },
118 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
119 };
120
121 enum
122 {
123 ePropertySymLinkPaths
124 };
125
126
127 class PluginProperties : public Properties
128 {
129 public:
130 static ConstString
131 GetSettingName()
132 {
133 return SymbolFileDWARF::GetPluginNameStatic();
134 }
135
136 PluginProperties()
137 {
138 m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
139 m_collection_sp->Initialize(g_properties);
140 }
141
142 FileSpecList&
143 GetSymLinkPaths()
144 {
145 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
146 assert(option_value);
147 return option_value->GetCurrentValue();
148 }
149
150 };
151
152 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
153
154 static const SymbolFileDWARFPropertiesSP&
155 GetGlobalPluginProperties()
156 {
157 static const auto g_settings_sp(std::make_shared<PluginProperties>());
158 return g_settings_sp;
159 }
160
161} // anonymous namespace end
162
163
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000164static const char*
165removeHostnameFromPathname(const char* path_from_dwarf)
166{
167 if (!path_from_dwarf || !path_from_dwarf[0])
168 {
169 return path_from_dwarf;
170 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000171
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000172 const char *colon_pos = strchr(path_from_dwarf, ':');
Enrico Granata99e5e222015-07-27 21:27:02 +0000173 if (nullptr == colon_pos)
174 {
175 return path_from_dwarf;
176 }
177
178 const char *slash_pos = strchr(path_from_dwarf, '/');
179 if (slash_pos && (slash_pos < colon_pos))
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000180 {
181 return path_from_dwarf;
182 }
183
184 // check whether we have a windows path, and so the first character
185 // is a drive-letter not a hostname.
186 if (
187 colon_pos == path_from_dwarf + 1 &&
188 isalpha(*path_from_dwarf) &&
189 strlen(path_from_dwarf) > 2 &&
190 '\\' == path_from_dwarf[2])
191 {
192 return path_from_dwarf;
193 }
Enrico Granata99e5e222015-07-27 21:27:02 +0000194
Matthew Gardinere81df3b2014-08-26 06:57:23 +0000195 return colon_pos + 1;
196}
197
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000198static const char*
199resolveCompDir(const char* path_from_dwarf)
200{
201 if (!path_from_dwarf)
202 return nullptr;
203
204 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
205 // Remove the host part if present.
206 const char* local_path = removeHostnameFromPathname(path_from_dwarf);
207 if (!local_path)
208 return nullptr;
209
210 bool is_symlink = false;
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000211 FileSpec local_path_spec(local_path, false);
212 const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
213 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
214 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000215
216 if (!is_symlink)
217 return local_path;
218
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000219 if (!local_path_spec.IsSymbolicLink())
220 return local_path;
221
222 FileSpec resolved_local_path_spec;
223 const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
224 if (error.Success())
225 return resolved_local_path_spec.GetCString();
226
227 return nullptr;
228}
229
230
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231void
232SymbolFileDWARF::Initialize()
233{
234 LogChannelDWARF::Initialize();
235 PluginManager::RegisterPlugin (GetPluginNameStatic(),
236 GetPluginDescriptionStatic(),
Oleksiy Vyalovabb5a352015-07-29 22:18:16 +0000237 CreateInstance,
238 DebuggerInitialize);
239}
240
241void
242SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
243{
244 if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
245 {
246 const bool is_global_setting = true;
247 PluginManager::CreateSettingForSymbolFilePlugin(debugger,
248 GetGlobalPluginProperties()->GetValueProperties(),
249 ConstString ("Properties for the dwarf symbol-file plug-in."),
250 is_global_setting);
251 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252}
253
254void
255SymbolFileDWARF::Terminate()
256{
257 PluginManager::UnregisterPlugin (CreateInstance);
258 LogChannelDWARF::Initialize();
259}
260
261
Greg Clayton57abc5d2013-05-10 21:47:16 +0000262lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263SymbolFileDWARF::GetPluginNameStatic()
264{
Greg Clayton57abc5d2013-05-10 21:47:16 +0000265 static ConstString g_name("dwarf");
266 return g_name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267}
268
269const char *
270SymbolFileDWARF::GetPluginDescriptionStatic()
271{
272 return "DWARF and DWARF3 debug symbol file reader.";
273}
274
275
276SymbolFile*
277SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
278{
279 return new SymbolFileDWARF(obj_file);
280}
281
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000282TypeList *
283SymbolFileDWARF::GetTypeList ()
284{
Greg Clayton1f746072012-08-29 21:13:06 +0000285 if (GetDebugMapSymfile ())
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000286 return m_debug_map_symfile->GetTypeList();
287 return m_obj_file->GetModule()->GetTypeList();
288
289}
Greg Claytonf02500c2013-06-18 22:51:05 +0000290void
Greg Clayton6071e6f2015-08-26 22:57:51 +0000291SymbolFileDWARF::GetTypes (const DWARFDIE &die,
Greg Claytonf02500c2013-06-18 22:51:05 +0000292 dw_offset_t min_die_offset,
293 dw_offset_t max_die_offset,
294 uint32_t type_mask,
295 TypeSet &type_set)
296{
Greg Clayton6071e6f2015-08-26 22:57:51 +0000297 if (die)
Greg Claytonf02500c2013-06-18 22:51:05 +0000298 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000299 const dw_offset_t die_offset = die.GetOffset();
300
301 if (die_offset >= max_die_offset)
302 return;
303
304 if (die_offset >= min_die_offset)
Greg Claytonf02500c2013-06-18 22:51:05 +0000305 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000306 const dw_tag_t tag = die.Tag();
Greg Claytonf02500c2013-06-18 22:51:05 +0000307
Greg Clayton6071e6f2015-08-26 22:57:51 +0000308 bool add_type = false;
309
310 switch (tag)
Greg Claytonf02500c2013-06-18 22:51:05 +0000311 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000312 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
313 case DW_TAG_unspecified_type:
314 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
315 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
316 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
317 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
318 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
319 case DW_TAG_subroutine_type:
320 case DW_TAG_subprogram:
321 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
322 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
323 case DW_TAG_rvalue_reference_type:
324 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
325 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
326 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
327 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000328
Greg Clayton6071e6f2015-08-26 22:57:51 +0000329 if (add_type)
330 {
331 const bool assert_not_being_parsed = true;
332 Type *type = ResolveTypeUID (die, assert_not_being_parsed);
333 if (type)
Greg Claytonf02500c2013-06-18 22:51:05 +0000334 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000335 if (type_set.find(type) == type_set.end())
336 type_set.insert(type);
Greg Claytonf02500c2013-06-18 22:51:05 +0000337 }
338 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000339 }
340
341 for (DWARFDIE child_die = die.GetFirstChild();
342 child_die.IsValid();
343 child_die = child_die.GetSibling())
344 {
345 GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set);
Greg Claytonf02500c2013-06-18 22:51:05 +0000346 }
347 }
348}
349
350size_t
351SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
352 uint32_t type_mask,
353 TypeList &type_list)
354
355{
356 TypeSet type_set;
357
358 CompileUnit *comp_unit = NULL;
359 DWARFCompileUnit* dwarf_cu = NULL;
360 if (sc_scope)
361 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
362
363 if (comp_unit)
364 {
365 dwarf_cu = GetDWARFCompileUnit(comp_unit);
366 if (dwarf_cu == 0)
367 return 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +0000368 GetTypes (dwarf_cu->DIE(),
Greg Claytonf02500c2013-06-18 22:51:05 +0000369 dwarf_cu->GetOffset(),
370 dwarf_cu->GetNextCompileUnitOffset(),
371 type_mask,
372 type_set);
373 }
374 else
375 {
376 DWARFDebugInfo* info = DebugInfo();
377 if (info)
378 {
379 const size_t num_cus = info->GetNumCompileUnits();
380 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
381 {
382 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
383 if (dwarf_cu)
384 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000385 GetTypes (dwarf_cu->DIE(),
Greg Claytonf02500c2013-06-18 22:51:05 +0000386 0,
387 UINT32_MAX,
388 type_mask,
389 type_set);
390 }
391 }
392 }
393 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000394
Greg Claytona1e5dc82015-08-11 22:53:00 +0000395 std::set<CompilerType> clang_type_set;
Greg Claytonf02500c2013-06-18 22:51:05 +0000396 size_t num_types_added = 0;
397 for (Type *type : type_set)
398 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000399 CompilerType clang_type = type->GetForwardCompilerType ();
Greg Clayton0fc4f312013-06-20 01:23:18 +0000400 if (clang_type_set.find(clang_type) == clang_type_set.end())
401 {
402 clang_type_set.insert(clang_type);
403 type_list.Insert (type->shared_from_this());
404 ++num_types_added;
405 }
Greg Claytonf02500c2013-06-18 22:51:05 +0000406 }
407 return num_types_added;
408}
409
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000410
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411//----------------------------------------------------------------------
412// Gets the first parent that is a lexical block, function or inlined
413// subroutine, or compile unit.
414//----------------------------------------------------------------------
Greg Clayton6071e6f2015-08-26 22:57:51 +0000415DWARFDIE
416SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417{
Greg Clayton6071e6f2015-08-26 22:57:51 +0000418 DWARFDIE die;
419 for (die = child_die.GetParent(); die; die = die.GetParent())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 {
Greg Clayton6071e6f2015-08-26 22:57:51 +0000421 dw_tag_t tag = die.Tag();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422
423 switch (tag)
424 {
425 case DW_TAG_compile_unit:
426 case DW_TAG_subprogram:
427 case DW_TAG_inlined_subroutine:
428 case DW_TAG_lexical_block:
429 return die;
430 }
431 }
Greg Clayton6071e6f2015-08-26 22:57:51 +0000432 return DWARFDIE();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433}
434
435
Greg Clayton450e3f32010-10-12 02:24:53 +0000436SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
437 SymbolFile (objfile),
Greg Clayton81c22f62011-10-19 18:09:39 +0000438 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 +0000439 m_debug_map_module_wp (),
Greg Clayton450e3f32010-10-12 02:24:53 +0000440 m_debug_map_symfile (NULL),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 m_flags(),
Greg Claytond4a2b372011-09-12 23:21:58 +0000442 m_data_debug_abbrev (),
443 m_data_debug_aranges (),
444 m_data_debug_frame (),
445 m_data_debug_info (),
446 m_data_debug_line (),
447 m_data_debug_loc (),
448 m_data_debug_ranges (),
449 m_data_debug_str (),
Greg Clayton17674402011-09-28 17:06:40 +0000450 m_data_apple_names (),
451 m_data_apple_types (),
Greg Clayton7f995132011-10-04 22:41:51 +0000452 m_data_apple_namespaces (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 m_abbr(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 m_info(),
455 m_line(),
Greg Clayton7f995132011-10-04 22:41:51 +0000456 m_apple_names_ap (),
457 m_apple_types_ap (),
458 m_apple_namespaces_ap (),
Greg Clayton5009f9d2011-10-27 17:55:14 +0000459 m_apple_objc_ap (),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000460 m_function_basename_index(),
461 m_function_fullname_index(),
462 m_function_method_index(),
463 m_function_selector_index(),
Greg Clayton450e3f32010-10-12 02:24:53 +0000464 m_objc_class_selectors_index(),
Greg Claytonc685f8e2010-09-15 04:15:46 +0000465 m_global_index(),
Greg Clayton69b04882010-10-15 02:03:22 +0000466 m_type_index(),
467 m_namespace_index(),
Greg Clayton6beaaa62011-01-17 03:46:26 +0000468 m_indexed (false),
Greg Clayton97fbc342011-10-20 22:30:33 +0000469 m_using_apple_tables (false),
Sean Callananf0c5aeb2015-04-20 16:31:29 +0000470 m_fetched_external_modules (false),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000471 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
Greg Clayton1c9e5ac2011-02-09 19:06:17 +0000472 m_ranges(),
473 m_unique_ast_type_map ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474{
475}
476
477SymbolFileDWARF::~SymbolFileDWARF()
478{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000479}
480
481static const ConstString &
482GetDWARFMachOSegmentName ()
483{
484 static ConstString g_dwarf_section_name ("__DWARF");
485 return g_dwarf_section_name;
486}
487
Greg Claytone576ab22011-02-15 00:19:15 +0000488UniqueDWARFASTTypeMap &
489SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
490{
Greg Clayton1f746072012-08-29 21:13:06 +0000491 if (GetDebugMapSymfile ())
Greg Claytone576ab22011-02-15 00:19:15 +0000492 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
493 return m_unique_ast_type_map;
494}
495
Greg Clayton8b4edba2015-08-14 20:02:05 +0000496ClangASTContext &
Greg Clayton6beaaa62011-01-17 03:46:26 +0000497SymbolFileDWARF::GetClangASTContext ()
498{
Greg Clayton1f746072012-08-29 21:13:06 +0000499 if (GetDebugMapSymfile ())
Greg Clayton6beaaa62011-01-17 03:46:26 +0000500 return m_debug_map_symfile->GetClangASTContext ();
Greg Clayton6dc8d582015-08-18 22:32:36 +0000501 else
502 return m_obj_file->GetModule()->GetClangASTContext();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000503}
504
Greg Clayton8b4edba2015-08-14 20:02:05 +0000505TypeSystem *
506SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language)
507{
508 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
509 if (debug_map_symfile)
510 return debug_map_symfile->GetTypeSystemForLanguage (language);
511 else
Greg Clayton6dc8d582015-08-18 22:32:36 +0000512 return m_obj_file->GetModule()->GetTypeSystemForLanguage (language);
Greg Clayton8b4edba2015-08-14 20:02:05 +0000513}
514
Greg Clayton6beaaa62011-01-17 03:46:26 +0000515void
516SymbolFileDWARF::InitializeObject()
517{
Greg Claytone72dfb32012-02-24 01:59:29 +0000518 ModuleSP module_sp (m_obj_file->GetModule());
519 if (module_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +0000520 {
Greg Clayton3046e662013-07-10 01:23:25 +0000521 const SectionList *section_list = module_sp->GetSectionList();
Greg Clayton6beaaa62011-01-17 03:46:26 +0000522
523 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
524
525 // Memory map the DWARF mach-o segment so we have everything mmap'ed
526 // to keep our heap memory usage down.
527 if (section)
Greg Claytonc9660542012-02-05 02:38:54 +0000528 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
Greg Clayton6beaaa62011-01-17 03:46:26 +0000529 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000530 get_apple_names_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000531 if (m_data_apple_names.GetByteSize() > 0)
532 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000533 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
534 if (m_apple_names_ap->IsValid())
535 m_using_apple_tables = true;
536 else
Greg Clayton7f995132011-10-04 22:41:51 +0000537 m_apple_names_ap.reset();
538 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000539 get_apple_types_data();
Greg Clayton7f995132011-10-04 22:41:51 +0000540 if (m_data_apple_types.GetByteSize() > 0)
541 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000542 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
543 if (m_apple_types_ap->IsValid())
544 m_using_apple_tables = true;
545 else
Greg Clayton7f995132011-10-04 22:41:51 +0000546 m_apple_types_ap.reset();
547 }
548
549 get_apple_namespaces_data();
550 if (m_data_apple_namespaces.GetByteSize() > 0)
551 {
Greg Clayton97fbc342011-10-20 22:30:33 +0000552 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
553 if (m_apple_namespaces_ap->IsValid())
554 m_using_apple_tables = true;
555 else
Greg Clayton7f995132011-10-04 22:41:51 +0000556 m_apple_namespaces_ap.reset();
557 }
Greg Clayton4d01ace2011-09-29 16:58:15 +0000558
Greg Clayton5009f9d2011-10-27 17:55:14 +0000559 get_apple_objc_data();
560 if (m_data_apple_objc.GetByteSize() > 0)
561 {
562 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
563 if (m_apple_objc_ap->IsValid())
564 m_using_apple_tables = true;
565 else
566 m_apple_objc_ap.reset();
567 }
Greg Clayton6dc8d582015-08-18 22:32:36 +0000568
569 // Set the symbol file to this file if we don't have a debug map symbol
570 // file as our main symbol file. This allows the clang ASTContext to complete
571 // types using this symbol file when it needs to complete classes and structures.
572 if (GetDebugMapSymfile () == nullptr)
573 GetClangASTContext().SetSymbolFile(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574}
575
576bool
577SymbolFileDWARF::SupportedVersion(uint16_t version)
578{
Greg Claytonabcbfe52013-04-04 00:00:36 +0000579 return version == 2 || version == 3 || version == 4;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580}
581
582uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000583SymbolFileDWARF::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584{
585 uint32_t abilities = 0;
586 if (m_obj_file != NULL)
587 {
588 const Section* section = NULL;
589 const SectionList *section_list = m_obj_file->GetSectionList();
590 if (section_list == NULL)
591 return 0;
592
593 uint64_t debug_abbrev_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594 uint64_t debug_info_file_size = 0;
595 uint64_t debug_line_file_size = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596
Greg Clayton6beaaa62011-01-17 03:46:26 +0000597 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598
599 if (section)
Greg Clayton4ceb9982010-07-21 22:54:26 +0000600 section_list = &section->GetChildren ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601
Greg Clayton4ceb9982010-07-21 22:54:26 +0000602 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 if (section != NULL)
604 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000605 debug_info_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606
Greg Clayton4ceb9982010-07-21 22:54:26 +0000607 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000609 debug_abbrev_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 else
611 m_flags.Set (flagsGotDebugAbbrevData);
612
Greg Clayton4ceb9982010-07-21 22:54:26 +0000613 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000614 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000615 m_flags.Set (flagsGotDebugArangesData);
616
Greg Clayton4ceb9982010-07-21 22:54:26 +0000617 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000618 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 m_flags.Set (flagsGotDebugFrameData);
620
Greg Clayton4ceb9982010-07-21 22:54:26 +0000621 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000622 if (section)
Greg Clayton47037bc2012-03-27 02:40:46 +0000623 debug_line_file_size = section->GetFileSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624 else
625 m_flags.Set (flagsGotDebugLineData);
626
Greg Clayton4ceb9982010-07-21 22:54:26 +0000627 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000628 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 m_flags.Set (flagsGotDebugLocData);
630
Greg Clayton4ceb9982010-07-21 22:54:26 +0000631 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000632 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 m_flags.Set (flagsGotDebugMacInfoData);
634
Greg Clayton4ceb9982010-07-21 22:54:26 +0000635 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000636 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 m_flags.Set (flagsGotDebugPubNamesData);
638
Greg Clayton4ceb9982010-07-21 22:54:26 +0000639 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000640 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 m_flags.Set (flagsGotDebugPubTypesData);
642
Greg Clayton4ceb9982010-07-21 22:54:26 +0000643 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000644 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645 m_flags.Set (flagsGotDebugRangesData);
646
Greg Clayton4ceb9982010-07-21 22:54:26 +0000647 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
Greg Clayton23f59502012-07-17 03:23:13 +0000648 if (!section)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 m_flags.Set (flagsGotDebugStrData);
650 }
Greg Clayton6c596612012-05-18 21:47:20 +0000651 else
652 {
653 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
654 if (symfile_dir_cstr)
655 {
656 if (strcasestr(symfile_dir_cstr, ".dsym"))
657 {
658 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
659 {
660 // We have a dSYM file that didn't have a any debug info.
661 // If the string table has a size of 1, then it was made from
662 // an executable with no debug info, or from an executable that
663 // was stripped.
664 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
665 if (section && section->GetFileSize() == 1)
666 {
667 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
668 }
669 }
670 }
671 }
672 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673
674 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
675 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
676
677 if (debug_line_file_size > 0)
678 abilities |= LineTables;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 }
680 return abilities;
681}
682
Ed Masteeeae7212013-10-24 20:43:47 +0000683const DWARFDataExtractor&
684SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685{
686 if (m_flags.IsClear (got_flag))
687 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000688 ModuleSP module_sp (m_obj_file->GetModule());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 m_flags.Set (got_flag);
Greg Clayton3046e662013-07-10 01:23:25 +0000690 const SectionList *section_list = module_sp->GetSectionList();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 if (section_list)
692 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000693 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
694 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 {
696 // See if we memory mapped the DWARF segment?
697 if (m_dwarf_data.GetByteSize())
698 {
Greg Clayton47037bc2012-03-27 02:40:46 +0000699 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700 }
701 else
702 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000703 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 data.Clear();
705 }
706 }
707 }
708 }
709 return data;
710}
711
Ed Masteeeae7212013-10-24 20:43:47 +0000712const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713SymbolFileDWARF::get_debug_abbrev_data()
714{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000715 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000716}
717
Ed Masteeeae7212013-10-24 20:43:47 +0000718const DWARFDataExtractor&
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000719SymbolFileDWARF::get_debug_addr_data()
720{
721 return GetCachedSectionData (flagsGotDebugAddrData, eSectionTypeDWARFDebugAddr, m_data_debug_addr);
722}
723
724const DWARFDataExtractor&
Greg Claytond4a2b372011-09-12 23:21:58 +0000725SymbolFileDWARF::get_debug_aranges_data()
726{
727 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
728}
729
Ed Masteeeae7212013-10-24 20:43:47 +0000730const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731SymbolFileDWARF::get_debug_frame_data()
732{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000733 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734}
735
Ed Masteeeae7212013-10-24 20:43:47 +0000736const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737SymbolFileDWARF::get_debug_info_data()
738{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000739 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740}
741
Ed Masteeeae7212013-10-24 20:43:47 +0000742const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743SymbolFileDWARF::get_debug_line_data()
744{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000745 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746}
747
Ed Masteeeae7212013-10-24 20:43:47 +0000748const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749SymbolFileDWARF::get_debug_loc_data()
750{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000751 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752}
753
Ed Masteeeae7212013-10-24 20:43:47 +0000754const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755SymbolFileDWARF::get_debug_ranges_data()
756{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000757 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000758}
759
Ed Masteeeae7212013-10-24 20:43:47 +0000760const DWARFDataExtractor&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761SymbolFileDWARF::get_debug_str_data()
762{
Greg Clayton4ceb9982010-07-21 22:54:26 +0000763 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764}
765
Ed Masteeeae7212013-10-24 20:43:47 +0000766const DWARFDataExtractor&
Tamas Berghammerc178d4c2015-08-25 11:45:58 +0000767SymbolFileDWARF::get_debug_str_offsets_data()
768{
769 return GetCachedSectionData (flagsGotDebugStrOffsetsData, eSectionTypeDWARFDebugStrOffsets, m_data_debug_str_offsets);
770}
771
772const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000773SymbolFileDWARF::get_apple_names_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000774{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000775 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
Greg Claytonf9eec202011-09-01 23:16:13 +0000776}
777
Ed Masteeeae7212013-10-24 20:43:47 +0000778const DWARFDataExtractor&
Greg Clayton17674402011-09-28 17:06:40 +0000779SymbolFileDWARF::get_apple_types_data()
Greg Claytonf9eec202011-09-01 23:16:13 +0000780{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000781 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
Greg Claytonf9eec202011-09-01 23:16:13 +0000782}
783
Ed Masteeeae7212013-10-24 20:43:47 +0000784const DWARFDataExtractor&
Greg Clayton7f995132011-10-04 22:41:51 +0000785SymbolFileDWARF::get_apple_namespaces_data()
786{
Greg Clayton5009f9d2011-10-27 17:55:14 +0000787 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
788}
789
Ed Masteeeae7212013-10-24 20:43:47 +0000790const DWARFDataExtractor&
Greg Clayton5009f9d2011-10-27 17:55:14 +0000791SymbolFileDWARF::get_apple_objc_data()
792{
793 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
Greg Clayton7f995132011-10-04 22:41:51 +0000794}
795
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796
797DWARFDebugAbbrev*
798SymbolFileDWARF::DebugAbbrev()
799{
800 if (m_abbr.get() == NULL)
801 {
Ed Masteeeae7212013-10-24 20:43:47 +0000802 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 if (debug_abbrev_data.GetByteSize() > 0)
804 {
805 m_abbr.reset(new DWARFDebugAbbrev());
806 if (m_abbr.get())
807 m_abbr->Parse(debug_abbrev_data);
808 }
809 }
810 return m_abbr.get();
811}
812
813const DWARFDebugAbbrev*
814SymbolFileDWARF::DebugAbbrev() const
815{
816 return m_abbr.get();
817}
818
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819
820DWARFDebugInfo*
821SymbolFileDWARF::DebugInfo()
822{
823 if (m_info.get() == NULL)
824 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000825 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
826 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000827 if (get_debug_info_data().GetByteSize() > 0)
828 {
829 m_info.reset(new DWARFDebugInfo());
830 if (m_info.get())
831 {
832 m_info->SetDwarfData(this);
833 }
834 }
835 }
836 return m_info.get();
837}
838
839const DWARFDebugInfo*
840SymbolFileDWARF::DebugInfo() const
841{
842 return m_info.get();
843}
844
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845DWARFCompileUnit*
Greg Clayton1f746072012-08-29 21:13:06 +0000846SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847{
Greg Claytonea4a5bb2015-09-04 22:29:46 +0000848 if (!comp_unit)
849 return nullptr;
850
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 DWARFDebugInfo* info = DebugInfo();
Greg Clayton1f746072012-08-29 21:13:06 +0000852 if (info)
853 {
854 if (GetDebugMapSymfile ())
855 {
856 // The debug map symbol file made the compile units for this DWARF
857 // file which is .o file with DWARF in it, and we should have
858 // only 1 compile unit which is at offset zero in the DWARF.
859 // TODO: modify to support LTO .o files where each .o file might
860 // have multiple DW_TAG_compile_unit tags.
Greg Clayton68c00bd2015-02-05 02:10:29 +0000861
Greg Clayton6071e6f2015-08-26 22:57:51 +0000862 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0);
Greg Clayton68c00bd2015-02-05 02:10:29 +0000863 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
864 dwarf_cu->SetUserData(comp_unit);
865 return dwarf_cu;
Greg Clayton1f746072012-08-29 21:13:06 +0000866 }
867 else
868 {
869 // Just a normal DWARF file whose user ID for the compile unit is
870 // the DWARF offset itself
Greg Clayton68c00bd2015-02-05 02:10:29 +0000871
Greg Clayton6071e6f2015-08-26 22:57:51 +0000872 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
Greg Clayton68c00bd2015-02-05 02:10:29 +0000873 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
874 dwarf_cu->SetUserData(comp_unit);
875 return dwarf_cu;
876
Greg Clayton1f746072012-08-29 21:13:06 +0000877 }
878 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879 return NULL;
880}
881
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882
883DWARFDebugRanges*
884SymbolFileDWARF::DebugRanges()
885{
886 if (m_ranges.get() == NULL)
887 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000888 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
889 __PRETTY_FUNCTION__, static_cast<void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000890 if (get_debug_ranges_data().GetByteSize() > 0)
891 {
892 m_ranges.reset(new DWARFDebugRanges());
893 if (m_ranges.get())
894 m_ranges->Extract(this);
895 }
896 }
897 return m_ranges.get();
898}
899
900const DWARFDebugRanges*
901SymbolFileDWARF::DebugRanges() const
902{
903 return m_ranges.get();
904}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905
Greg Clayton53eb1c22012-04-02 22:59:12 +0000906lldb::CompUnitSP
907SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908{
Greg Clayton53eb1c22012-04-02 22:59:12 +0000909 CompUnitSP cu_sp;
910 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000912 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
913 if (comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 {
Greg Clayton53eb1c22012-04-02 22:59:12 +0000915 // We already parsed this compile unit, had out a shared pointer to it
916 cu_sp = comp_unit->shared_from_this();
917 }
918 else
919 {
Greg Clayton1f746072012-08-29 21:13:06 +0000920 if (GetDebugMapSymfile ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921 {
Greg Clayton1f746072012-08-29 21:13:06 +0000922 // Let the debug map create the compile unit
923 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
924 dwarf_cu->SetUserData(cu_sp.get());
925 }
926 else
927 {
928 ModuleSP module_sp (m_obj_file->GetModule());
929 if (module_sp)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000930 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000931 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
Greg Clayton1f746072012-08-29 21:13:06 +0000932 if (cu_die)
Greg Clayton53eb1c22012-04-02 22:59:12 +0000933 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000934 FileSpec cu_file_spec{cu_die.GetName(), false};
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000935 if (cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000936 {
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000937 // If we have a full path to the compile unit, we don't need to resolve
938 // the file. This can be expensive e.g. when the source files are NFS mounted.
Chaoren Lin372e9062015-06-09 17:54:27 +0000939 if (cu_file_spec.IsRelative())
Greg Clayton53eb1c22012-04-02 22:59:12 +0000940 {
Greg Clayton5ce1a842015-08-27 18:09:44 +0000941 const char *cu_comp_dir{cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)};
Oleksiy Vyalov5d9c50b2015-07-21 02:09:42 +0000942 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
Greg Clayton1f746072012-08-29 21:13:06 +0000943 }
944
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000945 std::string remapped_file;
946 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
947 cu_file_spec.SetFile(remapped_file, false);
David Srbeckyd515e942015-07-08 14:00:04 +0000948 }
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000949
Greg Clayton5ce1a842015-08-27 18:09:44 +0000950 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
Chaoren Lin0c5a9c12015-06-05 00:28:06 +0000951
Jason Molendac7099582015-07-31 05:47:00 +0000952 bool is_optimized = dwarf_cu->GetIsOptimized ();
David Srbeckyd515e942015-07-08 14:00:04 +0000953 cu_sp.reset(new CompileUnit (module_sp,
954 dwarf_cu,
955 cu_file_spec,
Greg Clayton6071e6f2015-08-26 22:57:51 +0000956 dwarf_cu->GetID(),
Jason Molenda6ab659a2015-07-29 00:42:47 +0000957 cu_language,
958 is_optimized));
David Srbeckyd515e942015-07-08 14:00:04 +0000959 if (cu_sp)
960 {
961 // If we just created a compile unit with an invalid file spec, try and get the
962 // first entry in the supports files from the line table as that should be the
963 // compile unit.
964 if (!cu_file_spec)
Greg Clayton1f746072012-08-29 21:13:06 +0000965 {
David Srbeckyd515e942015-07-08 14:00:04 +0000966 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
967 if (cu_file_spec)
968 {
969 (FileSpec &)(*cu_sp) = cu_file_spec;
970 // Also fix the invalid file spec which was copied from the compile unit.
971 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
972 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000973 }
David Srbeckyd515e942015-07-08 14:00:04 +0000974
975 dwarf_cu->SetUserData(cu_sp.get());
976
977 // Figure out the compile unit index if we weren't given one
978 if (cu_idx == UINT32_MAX)
979 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
980
981 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
Greg Clayton53eb1c22012-04-02 22:59:12 +0000982 }
983 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000984 }
985 }
986 }
987 }
Greg Clayton53eb1c22012-04-02 22:59:12 +0000988 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989}
990
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991uint32_t
992SymbolFileDWARF::GetNumCompileUnits()
993{
994 DWARFDebugInfo* info = DebugInfo();
995 if (info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000996 return info->GetNumCompileUnits();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000997 return 0;
998}
999
1000CompUnitSP
1001SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
1002{
Greg Clayton53eb1c22012-04-02 22:59:12 +00001003 CompUnitSP cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001004 DWARFDebugInfo* info = DebugInfo();
1005 if (info)
1006 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001007 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
1008 if (dwarf_cu)
1009 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001011 return cu_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012}
1013
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014Function *
Greg Clayton6071e6f2015-08-26 22:57:51 +00001015SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016{
Greg Clayton6071e6f2015-08-26 22:57:51 +00001017 if (die.IsValid())
1018 {
1019 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020
Greg Clayton6071e6f2015-08-26 22:57:51 +00001021 if (type_system)
1022 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00001023 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
1024 if (dwarf_ast)
1025 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
Greg Clayton6071e6f2015-08-26 22:57:51 +00001026 }
1027 }
1028 return nullptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001029}
1030
Greg Clayton9422dd62013-03-04 21:46:16 +00001031bool
1032SymbolFileDWARF::FixupAddress (Address &addr)
1033{
1034 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1035 if (debug_map_symfile)
1036 {
1037 return debug_map_symfile->LinkOSOAddress(addr);
1038 }
1039 // This is a normal DWARF file, no address fixups need to happen
1040 return true;
1041}
Greg Clayton1f746072012-08-29 21:13:06 +00001042lldb::LanguageType
1043SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1044{
1045 assert (sc.comp_unit);
1046 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1047 if (dwarf_cu)
Greg Clayton5ce1a842015-08-27 18:09:44 +00001048 return dwarf_cu->GetLanguageType();
1049 else
1050 return eLanguageTypeUnknown;
Greg Clayton1f746072012-08-29 21:13:06 +00001051}
1052
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001053size_t
1054SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1055{
1056 assert (sc.comp_unit);
1057 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00001058 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 if (dwarf_cu)
1060 {
1061 DWARFDIECollection function_dies;
Greg Clayton1f746072012-08-29 21:13:06 +00001062 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 size_t func_idx;
Greg Clayton1f746072012-08-29 21:13:06 +00001064 for (func_idx = 0; func_idx < num_functions; ++func_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001065 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001066 DWARFDIE die = function_dies.GetDIEAtIndex(func_idx);
1067 if (sc.comp_unit->FindFunctionByUID (die.GetID()).get() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001069 if (ParseCompileUnitFunction(sc, die))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001070 ++functions_added;
1071 }
1072 }
1073 //FixupTypes();
1074 }
1075 return functions_added;
1076}
1077
1078bool
1079SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1080{
1081 assert (sc.comp_unit);
Greg Clayton1f746072012-08-29 21:13:06 +00001082 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Greg Claytonda2455b2012-11-01 17:28:37 +00001083 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001085 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001086
Greg Claytonda2455b2012-11-01 17:28:37 +00001087 if (cu_die)
1088 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001089 const char * cu_comp_dir = resolveCompDir(cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr));
Matthew Gardinere81df3b2014-08-26 06:57:23 +00001090
Greg Clayton5ce1a842015-08-27 18:09:44 +00001091 const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092
Greg Claytonda2455b2012-11-01 17:28:37 +00001093 // All file indexes in DWARF are one based and a file of index zero is
1094 // supposed to be the compile unit itself.
1095 support_files.Append (*sc.comp_unit);
1096
1097 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1098 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001099 }
1100 return false;
1101}
1102
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001103bool
1104SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1105{
1106 assert (sc.comp_unit);
1107 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1108 if (dwarf_cu)
1109 {
1110 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1111 {
1112 UpdateExternalModuleListIfNeeded();
1113 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules)
1114 {
1115 imported_modules.push_back(external_type_module.second.m_name);
1116 }
1117 }
1118 }
1119 return false;
1120}
1121
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122struct ParseDWARFLineTableCallbackInfo
1123{
1124 LineTable* line_table;
Greg Clayton7b0992d2013-04-18 22:45:39 +00001125 std::unique_ptr<LineSequence> sequence_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126};
1127
1128//----------------------------------------------------------------------
1129// ParseStatementTableCallback
1130//----------------------------------------------------------------------
1131static void
1132ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1133{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1135 {
1136 // Just started parsing the line table
1137 }
1138 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1139 {
1140 // Done parsing line table, nothing to do for the cleanup
1141 }
1142 else
1143 {
1144 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
Greg Clayton9422dd62013-03-04 21:46:16 +00001145 LineTable* line_table = info->line_table;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001146
Greg Clayton9422dd62013-03-04 21:46:16 +00001147 // If this is our first time here, we need to create a
1148 // sequence container.
1149 if (!info->sequence_ap.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001150 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001151 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1152 assert(info->sequence_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001153 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001154 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1155 state.address,
1156 state.line,
1157 state.column,
1158 state.file,
1159 state.is_stmt,
1160 state.basic_block,
1161 state.prologue_end,
1162 state.epilogue_begin,
1163 state.end_sequence);
1164 if (state.end_sequence)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001166 // First, put the current sequence into the line table.
1167 line_table->InsertSequence(info->sequence_ap.get());
1168 // Then, empty it to prepare for the next sequence.
1169 info->sequence_ap->Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 }
1172}
1173
1174bool
1175SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1176{
1177 assert (sc.comp_unit);
1178 if (sc.comp_unit->GetLineTable() != NULL)
1179 return true;
1180
Greg Clayton1f746072012-08-29 21:13:06 +00001181 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 if (dwarf_cu)
1183 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001184 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
Greg Clayton129d12c2011-11-28 03:29:03 +00001185 if (dwarf_cu_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001187 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 +00001188 if (cu_line_offset != DW_INVALID_OFFSET)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001190 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
Greg Clayton129d12c2011-11-28 03:29:03 +00001191 if (line_table_ap.get())
1192 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001193 ParseDWARFLineTableCallbackInfo info;
1194 info.line_table = line_table_ap.get();
Greg Claytonc7bece562013-01-25 18:06:21 +00001195 lldb::offset_t offset = cu_line_offset;
Greg Clayton129d12c2011-11-28 03:29:03 +00001196 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
Greg Clayton9422dd62013-03-04 21:46:16 +00001197 if (m_debug_map_symfile)
1198 {
1199 // We have an object file that has a line table with addresses
1200 // that are not linked. We need to link the line table and convert
1201 // the addresses that are relative to the .o file into addresses
1202 // for the main executable.
1203 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1204 }
1205 else
1206 {
1207 sc.comp_unit->SetLineTable(line_table_ap.release());
1208 return true;
1209 }
Greg Clayton129d12c2011-11-28 03:29:03 +00001210 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211 }
1212 }
1213 }
1214 return false;
1215}
1216
1217size_t
Greg Clayton6071e6f2015-08-26 22:57:51 +00001218SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext& sc,
1219 Block *parent_block,
1220 const DWARFDIE &orig_die,
1221 addr_t subprogram_low_pc,
1222 uint32_t depth)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223{
1224 size_t blocks_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001225 DWARFDIE die = orig_die;
1226 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001227 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001228 dw_tag_t tag = die.Tag();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229
1230 switch (tag)
1231 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 case DW_TAG_inlined_subroutine:
Greg Claytonb4d37332011-08-12 16:22:48 +00001233 case DW_TAG_subprogram:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 case DW_TAG_lexical_block:
1235 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001236 Block *block = NULL;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001237 if (tag == DW_TAG_subprogram)
1238 {
1239 // Skip any DW_TAG_subprogram DIEs that are inside
1240 // of a normal or inlined functions. These will be
1241 // parsed on their own as separate entities.
1242
1243 if (depth > 0)
1244 break;
1245
1246 block = parent_block;
1247 }
1248 else
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001249 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001250 BlockSP block_sp(new Block (die.GetID()));
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001251 parent_block->AddChild(block_sp);
1252 block = block_sp.get();
1253 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001254 DWARFRangeList ranges;
Greg Claytondd7feaf2011-08-12 17:54:33 +00001255 const char *name = NULL;
1256 const char *mangled_name = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 int decl_file = 0;
1259 int decl_line = 0;
1260 int decl_column = 0;
1261 int call_file = 0;
1262 int call_line = 0;
1263 int call_column = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001264 if (die.GetDIENamesAndRanges (name,
1265 mangled_name,
1266 ranges,
1267 decl_file, decl_line, decl_column,
1268 call_file, call_line, call_column, nullptr))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 {
1270 if (tag == DW_TAG_subprogram)
1271 {
1272 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
Greg Claytonea3e7d52011-10-08 00:49:15 +00001273 subprogram_low_pc = ranges.GetMinRangeBase(0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 }
Jim Inghamb0be4422010-08-12 01:20:14 +00001275 else if (tag == DW_TAG_inlined_subroutine)
1276 {
1277 // We get called here for inlined subroutines in two ways.
1278 // The first time is when we are making the Function object
1279 // for this inlined concrete instance. Since we're creating a top level block at
1280 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1281 // adjust the containing address.
1282 // The second time is when we are parsing the blocks inside the function that contains
1283 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1284 // function the offset will be for that function.
1285 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1286 {
Greg Claytonea3e7d52011-10-08 00:49:15 +00001287 subprogram_low_pc = ranges.GetMinRangeBase(0);
Jim Inghamb0be4422010-08-12 01:20:14 +00001288 }
1289 }
Greg Clayton103f3092015-01-15 03:04:37 +00001290
1291 const size_t num_ranges = ranges.GetSize();
1292 for (size_t i = 0; i<num_ranges; ++i)
1293 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001294 const DWARFRangeList::Entry &range = ranges.GetEntryRef (i);
Greg Clayton103f3092015-01-15 03:04:37 +00001295 const addr_t range_base = range.GetRangeBase();
1296 if (range_base >= subprogram_low_pc)
1297 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1298 else
1299 {
1300 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",
1301 block->GetID(),
1302 range_base,
1303 range.GetRangeEnd(),
1304 subprogram_low_pc);
1305 }
1306 }
1307 block->FinalizeRanges ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308
1309 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1310 {
Greg Clayton7b0992d2013-04-18 22:45:39 +00001311 std::unique_ptr<Declaration> decl_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001313 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1314 decl_line, decl_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315
Greg Clayton7b0992d2013-04-18 22:45:39 +00001316 std::unique_ptr<Declaration> call_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 if (call_file != 0 || call_line != 0 || call_column != 0)
Jim Inghamb0be4422010-08-12 01:20:14 +00001318 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1319 call_line, call_column));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001321 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001322 }
1323
1324 ++blocks_added;
1325
Greg Clayton6071e6f2015-08-26 22:57:51 +00001326 if (die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 {
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001328 blocks_added += ParseFunctionBlocks (sc,
1329 block,
Greg Clayton6071e6f2015-08-26 22:57:51 +00001330 die.GetFirstChild(),
Greg Clayton0b76a2c2010-08-21 02:22:51 +00001331 subprogram_low_pc,
Greg Claytondd7feaf2011-08-12 17:54:33 +00001332 depth + 1);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 }
1334 }
1335 }
1336 break;
1337 default:
1338 break;
1339 }
1340
Greg Claytondd7feaf2011-08-12 17:54:33 +00001341 // Only parse siblings of the block if we are not at depth zero. A depth
1342 // of zero indicates we are currently parsing the top level
1343 // DW_TAG_subprogram DIE
1344
1345 if (depth == 0)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001346 die.Clear();
Greg Claytondd7feaf2011-08-12 17:54:33 +00001347 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00001348 die = die.GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349 }
1350 return blocks_added;
1351}
1352
Greg Claytonf0705c82011-10-22 03:33:13 +00001353bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00001354SymbolFileDWARF::ClassOrStructIsVirtual (const DWARFDIE &parent_die)
Greg Claytonc4ffd662013-03-08 01:37:30 +00001355{
1356 if (parent_die)
1357 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001358 for (DWARFDIE die = parent_die.GetFirstChild(); die; die = die.GetSibling())
Greg Claytonc4ffd662013-03-08 01:37:30 +00001359 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001360 dw_tag_t tag = die.Tag();
Greg Claytonc4ffd662013-03-08 01:37:30 +00001361 bool check_virtuality = false;
1362 switch (tag)
1363 {
1364 case DW_TAG_inheritance:
1365 case DW_TAG_subprogram:
1366 check_virtuality = true;
1367 break;
1368 default:
1369 break;
1370 }
1371 if (check_virtuality)
1372 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001373 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
Greg Claytonc4ffd662013-03-08 01:37:30 +00001374 return true;
1375 }
1376 }
1377 }
1378 return false;
1379}
1380
Greg Clayton99558cc42015-08-24 23:46:31 +00001381CompilerDeclContext
1382SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001383{
Greg Clayton8b4edba2015-08-14 20:02:05 +00001384 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001385 {
Greg Clayton8b4edba2015-08-14 20:02:05 +00001386 DWARFDebugInfo* debug_info = DebugInfo();
1387 if (debug_info)
1388 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001389 DWARFDIE die = debug_info->GetDIE(type_uid);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001390 if (die)
1391 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00001392 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1393 if (dwarf_ast)
1394 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001395 }
1396 }
Sean Callanan72e49402011-08-05 23:43:37 +00001397 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001398 return CompilerDeclContext();
Sean Callanan72e49402011-08-05 23:43:37 +00001399}
1400
Greg Clayton99558cc42015-08-24 23:46:31 +00001401CompilerDeclContext
1402SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid)
Sean Callanan72e49402011-08-05 23:43:37 +00001403{
Greg Clayton81c22f62011-10-19 18:09:39 +00001404 if (UserIDMatches(type_uid))
Greg Clayton8b4edba2015-08-14 20:02:05 +00001405 {
1406 DWARFDebugInfo* debug_info = DebugInfo();
1407 if (debug_info)
1408 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001409 DWARFDIE die = debug_info->GetDIE(type_uid);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001410 if (die)
1411 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00001412 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1413 if (dwarf_ast)
1414 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
Greg Clayton8b4edba2015-08-14 20:02:05 +00001415 }
1416 }
1417 }
Greg Clayton99558cc42015-08-24 23:46:31 +00001418 return CompilerDeclContext();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419}
1420
Greg Clayton99558cc42015-08-24 23:46:31 +00001421
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001422Type*
Greg Claytonc685f8e2010-09-15 04:15:46 +00001423SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424{
Greg Clayton81c22f62011-10-19 18:09:39 +00001425 if (UserIDMatches(type_uid))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426 {
Greg Clayton81c22f62011-10-19 18:09:39 +00001427 DWARFDebugInfo* debug_info = DebugInfo();
1428 if (debug_info)
Greg Claytonca512b32011-01-14 04:54:56 +00001429 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001430 DWARFDIE type_die = debug_info->GetDIE (type_uid);
1431 if (type_die)
1432 {
1433 const bool assert_not_being_parsed = true;
1434 return ResolveTypeUID (type_die, assert_not_being_parsed);
1435 }
Greg Claytonca512b32011-01-14 04:54:56 +00001436 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437 }
1438 return NULL;
1439}
1440
Greg Claytoncab36a32011-12-08 05:16:30 +00001441Type*
Greg Clayton6071e6f2015-08-26 22:57:51 +00001442SymbolFileDWARF::ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed)
Sean Callanan5b26f272012-02-04 08:49:35 +00001443{
Greg Clayton6071e6f2015-08-26 22:57:51 +00001444 if (die)
Greg Claytoncab36a32011-12-08 05:16:30 +00001445 {
Greg Clayton5160ce52013-03-27 23:08:40 +00001446 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
Greg Clayton3bffb082011-12-10 02:15:28 +00001447 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001448 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00001449 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001450 die.GetOffset(),
1451 die.GetTagAsCString(),
1452 die.GetName());
Greg Clayton3bffb082011-12-10 02:15:28 +00001453
Greg Claytoncab36a32011-12-08 05:16:30 +00001454 // We might be coming in in the middle of a type tree (a class
1455 // withing a class, an enum within a class), so parse any needed
1456 // parent DIEs before we get to this one...
Greg Clayton6071e6f2015-08-26 22:57:51 +00001457 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE (die);
1458 if (decl_ctx_die)
Greg Claytoncab36a32011-12-08 05:16:30 +00001459 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001460 if (log)
Greg Claytoncab36a32011-12-08 05:16:30 +00001461 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001462 switch (decl_ctx_die.Tag())
1463 {
1464 case DW_TAG_structure_type:
1465 case DW_TAG_union_type:
1466 case DW_TAG_class_type:
1467 {
1468 // Get the type, which could be a forward declaration
1469 if (log)
1470 GetObjectFile()->GetModule()->LogMessage (log,
1471 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1472 die.GetOffset(),
1473 die.GetTagAsCString(),
1474 die.GetName(),
1475 decl_ctx_die.GetOffset());
1476 }
1477 break;
Greg Claytoncab36a32011-12-08 05:16:30 +00001478
Greg Clayton6071e6f2015-08-26 22:57:51 +00001479 default:
1480 break;
1481 }
1482 }
Greg Claytoncab36a32011-12-08 05:16:30 +00001483 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001484 return ResolveType (die);
Greg Claytoncab36a32011-12-08 05:16:30 +00001485 }
1486 return NULL;
1487}
1488
Greg Clayton6beaaa62011-01-17 03:46:26 +00001489// This function is used when SymbolFileDWARFDebugMap owns a bunch of
1490// SymbolFileDWARF objects to detect if this DWARF file is the one that
1491// can resolve a clang_type.
1492bool
Greg Claytona1e5dc82015-08-11 22:53:00 +00001493SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001494{
Greg Claytona1e5dc82015-08-11 22:53:00 +00001495 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton5ce1a842015-08-27 18:09:44 +00001496 return m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()) != nullptr;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001497}
1498
1499
Greg Clayton57ee3062013-07-11 22:46:58 +00001500bool
Greg Clayton6dc8d582015-08-18 22:32:36 +00001501SymbolFileDWARF::CompleteType (CompilerType &clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +00001502{
1503 // We have a struct/union/class/enum that needs to be fully resolved.
Greg Claytona1e5dc82015-08-11 22:53:00 +00001504 CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +00001505 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001506 if (die == NULL)
Greg Clayton73b472d2010-10-27 03:32:59 +00001507 {
1508 // We have already resolved this type...
Greg Clayton57ee3062013-07-11 22:46:58 +00001509 return true;
Greg Clayton73b472d2010-10-27 03:32:59 +00001510 }
1511 // Once we start resolving this type, remove it from the forward declaration
1512 // map in case anyone child members or other types require this type to get resolved.
1513 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1514 // are done.
Greg Clayton57ee3062013-07-11 22:46:58 +00001515 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001516
Greg Clayton450e3f32010-10-12 02:24:53 +00001517 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton6071e6f2015-08-26 22:57:51 +00001518 DWARFDIE dwarf_die (debug_info->GetCompileUnitContainingDIE (die->GetOffset()), die);
Greg Clayton1be10fc2010-09-29 01:12:09 +00001519 Type *type = m_die_to_type.lookup (die);
1520
Greg Clayton5160ce52013-03-27 23:08:40 +00001521 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
Greg Clayton3bffb082011-12-10 02:15:28 +00001522 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00001523 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
Daniel Malead01b2952012-11-29 21:49:15 +00001524 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001525 dwarf_die.GetID(),
1526 dwarf_die.GetTagAsCString(),
Greg Claytond61c0fc2012-04-23 22:55:20 +00001527 type->GetName().AsCString());
Greg Clayton1be10fc2010-09-29 01:12:09 +00001528 assert (clang_type);
Greg Clayton6071e6f2015-08-26 22:57:51 +00001529 DWARFAttributes attributes;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001530
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001531
Greg Clayton261ac3f2015-08-28 01:01:03 +00001532 DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser();
1533 if (dwarf_ast)
1534 return dwarf_ast->CompleteTypeFromDWARF (dwarf_die, type, clang_type);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001535
Ashok Thirumurthia4658a52013-07-30 14:58:39 +00001536 return false;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001537}
1538
Greg Clayton8b4edba2015-08-14 20:02:05 +00001539Type*
Greg Clayton6071e6f2015-08-26 22:57:51 +00001540SymbolFileDWARF::ResolveType (const DWARFDIE &die, bool assert_not_being_parsed)
Greg Clayton8b4edba2015-08-14 20:02:05 +00001541{
Greg Clayton6071e6f2015-08-26 22:57:51 +00001542 if (die)
Greg Clayton8b4edba2015-08-14 20:02:05 +00001543 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001544 Type *type = m_die_to_type.lookup (die.GetDIE());
Greg Claytoncab36a32011-12-08 05:16:30 +00001545
Greg Claytonc685f8e2010-09-15 04:15:46 +00001546 if (type == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001547 type = GetTypeForDIE (die).get();
Greg Claytoncab36a32011-12-08 05:16:30 +00001548
Greg Clayton24739922010-10-13 03:15:28 +00001549 if (assert_not_being_parsed)
Jim Inghamc3549282012-01-11 02:21:12 +00001550 {
1551 if (type != DIE_IS_BEING_PARSED)
1552 return type;
1553
1554 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
Greg Clayton6071e6f2015-08-26 22:57:51 +00001555 die.GetOffset(),
1556 die.GetTagAsCString(),
1557 die.GetName());
Jim Inghamc3549282012-01-11 02:21:12 +00001558
1559 }
1560 else
1561 return type;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001562 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00001563 return nullptr;
Greg Claytonc685f8e2010-09-15 04:15:46 +00001564}
1565
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001566CompileUnit*
Greg Clayton53eb1c22012-04-02 22:59:12 +00001567SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001568{
1569 // Check if the symbol vendor already knows about this compile unit?
Greg Clayton53eb1c22012-04-02 22:59:12 +00001570 if (dwarf_cu->GetUserData() == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571 {
1572 // The symbol vendor doesn't know about this compile unit, we
1573 // need to parse and add it to the symbol vendor object.
Greg Clayton53eb1c22012-04-02 22:59:12 +00001574 return ParseCompileUnit(dwarf_cu, cu_idx).get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575 }
Greg Clayton53eb1c22012-04-02 22:59:12 +00001576 return (CompileUnit*)dwarf_cu->GetUserData();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001577}
1578
Greg Clayton8b4edba2015-08-14 20:02:05 +00001579size_t
1580SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets)
1581{
1582 method_die_offsets.clear();
1583 if (m_using_apple_tables)
1584 {
1585 if (m_apple_objc_ap.get())
1586 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
1587 }
1588 else
1589 {
1590 if (!m_indexed)
1591 Index ();
1592
1593 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1594 }
1595 return method_die_offsets.size();
1596}
1597
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001598bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00001599SymbolFileDWARF::GetFunction (const DWARFDIE &die, SymbolContext& sc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001600{
Greg Clayton72310352013-02-23 04:12:47 +00001601 sc.Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001602
Greg Clayton6071e6f2015-08-26 22:57:51 +00001603 if (die)
1604 {
1605 // Check if the symbol vendor already knows about this compile unit?
1606 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
1607
1608 sc.function = sc.comp_unit->FindFunctionByUID (die.GetID()).get();
1609 if (sc.function == NULL)
1610 sc.function = ParseCompileUnitFunction(sc, die);
1611
1612 if (sc.function)
1613 {
1614 sc.module_sp = sc.function->CalculateSymbolContextModule();
1615 return true;
1616 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00001617 }
1618
1619 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001620}
1621
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001622void
1623SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
1624{
1625 if (m_fetched_external_modules)
1626 return;
1627 m_fetched_external_modules = true;
1628
1629 DWARFDebugInfo * debug_info = DebugInfo();
1630 debug_info->GetNumCompileUnits();
1631
1632 const uint32_t num_compile_units = GetNumCompileUnits();
1633 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1634 {
1635 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1636
Greg Clayton5ce1a842015-08-27 18:09:44 +00001637 const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly();
1638 if (die && die.HasChildren() == false)
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001639 {
Greg Clayton5ce1a842015-08-27 18:09:44 +00001640 const uint64_t name_strp = die.GetAttributeValueAsUnsigned (DW_AT_name, UINT64_MAX);
1641 const uint64_t dwo_path_strp = die.GetAttributeValueAsUnsigned (DW_AT_GNU_dwo_name, UINT64_MAX);
Sean Callananf0c5aeb2015-04-20 16:31:29 +00001642
1643 if (name_strp != UINT64_MAX)
1644 {
1645 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end())
1646 {
1647 const char *name = get_debug_str_data().PeekCStr(name_strp);
1648 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp);
1649 if (name || dwo_path)
1650 {
1651 ModuleSP module_sp;
1652 if (dwo_path)
1653 {
1654 ModuleSpec dwo_module_spec;
1655 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
1656 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
1657 //printf ("Loading dwo = '%s'\n", dwo_path);
1658 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
1659 }
1660
1661 if (dwo_path_strp != LLDB_INVALID_UID)
1662 {
1663 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp };
1664 }
1665 else
1666 {
1667 // This hack should be removed promptly once clang emits both.
1668 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp };
1669 }
1670 }
1671 }
1672 }
1673 }
1674 }
1675}
Greg Clayton2501e5e2015-01-15 02:59:20 +00001676
1677SymbolFileDWARF::GlobalVariableMap &
1678SymbolFileDWARF::GetGlobalAranges()
1679{
1680 if (!m_global_aranges_ap)
1681 {
1682 m_global_aranges_ap.reset (new GlobalVariableMap());
1683
1684 ModuleSP module_sp = GetObjectFile()->GetModule();
1685 if (module_sp)
1686 {
1687 const size_t num_cus = module_sp->GetNumCompileUnits();
1688 for (size_t i = 0; i < num_cus; ++i)
1689 {
1690 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1691 if (cu_sp)
1692 {
1693 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1694 if (globals_sp)
1695 {
1696 const size_t num_globals = globals_sp->GetSize();
1697 for (size_t g = 0; g < num_globals; ++g)
1698 {
1699 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1700 if (var_sp && !var_sp->GetLocationIsConstantValueData())
1701 {
1702 const DWARFExpression &location = var_sp->LocationExpression();
1703 Value location_result;
1704 Error error;
1705 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
1706 {
1707 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
1708 {
1709 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
1710 lldb::addr_t byte_size = 1;
1711 if (var_sp->GetType())
1712 byte_size = var_sp->GetType()->GetByteSize();
1713 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
1714 }
1715 }
1716 }
1717 }
1718 }
1719 }
1720 }
1721 }
1722 m_global_aranges_ap->Sort();
1723 }
1724 return *m_global_aranges_ap;
1725}
1726
1727
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728uint32_t
1729SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1730{
1731 Timer scoped_timer(__PRETTY_FUNCTION__,
Daniel Malead01b2952012-11-29 21:49:15 +00001732 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001733 static_cast<void*>(so_addr.GetSection().get()),
1734 so_addr.GetOffset(), resolve_scope);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 uint32_t resolved = 0;
Greg Clayton2501e5e2015-01-15 02:59:20 +00001736 if (resolve_scope & ( eSymbolContextCompUnit |
1737 eSymbolContextFunction |
1738 eSymbolContextBlock |
1739 eSymbolContextLineEntry |
1740 eSymbolContextVariable ))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 {
1742 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1743
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 DWARFDebugInfo* debug_info = DebugInfo();
Greg Claytond4a2b372011-09-12 23:21:58 +00001745 if (debug_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001747 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
Greg Clayton2501e5e2015-01-15 02:59:20 +00001748 if (cu_offset == DW_INVALID_OFFSET)
1749 {
1750 // Global variables are not in the compile unit address ranges. The only way to
1751 // currently find global variables is to iterate over the .debug_pubnames or the
1752 // __apple_names table and find all items in there that point to DW_TAG_variable
1753 // DIEs and then find the address that matches.
1754 if (resolve_scope & eSymbolContextVariable)
1755 {
1756 GlobalVariableMap &map = GetGlobalAranges();
1757 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
1758 if (entry && entry->data)
1759 {
1760 Variable *variable = entry->data;
1761 SymbolContextScope *scc = variable->GetSymbolContextScope();
1762 if (scc)
1763 {
1764 scc->CalculateSymbolContext(&sc);
1765 sc.variable = variable;
1766 }
1767 return sc.GetResolvedMask();
1768 }
1769 }
1770 }
1771 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001773 uint32_t cu_idx = DW_INVALID_INDEX;
Greg Clayton6071e6f2015-08-26 22:57:51 +00001774 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx);
Greg Clayton53eb1c22012-04-02 22:59:12 +00001775 if (dwarf_cu)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001777 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001778 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001779 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001780 resolved |= eSymbolContextCompUnit;
1781
Greg Clayton6ab80132012-12-12 17:30:52 +00001782 bool force_check_line_table = false;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001783 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1784 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001785 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1786 DWARFDIE block_die;
1787 if (function_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001788 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001789 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
Greg Clayton526a4ae2012-05-16 22:09:01 +00001790 if (sc.function == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001791 sc.function = ParseCompileUnitFunction(sc, function_die);
1792
1793 if (sc.function && (resolve_scope & eSymbolContextBlock))
1794 block_die = function_die.LookupDeepestBlock(file_vm_addr);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001795 }
1796 else
1797 {
1798 // We might have had a compile unit that had discontiguous
1799 // address ranges where the gaps are symbols that don't have
1800 // any debug info. Discontiguous compile unit address ranges
1801 // should only happen when there aren't other functions from
1802 // other compile units in these gaps. This helps keep the size
1803 // of the aranges down.
Greg Clayton6ab80132012-12-12 17:30:52 +00001804 force_check_line_table = true;
Greg Clayton526a4ae2012-05-16 22:09:01 +00001805 }
1806
1807 if (sc.function != NULL)
1808 {
1809 resolved |= eSymbolContextFunction;
1810
1811 if (resolve_scope & eSymbolContextBlock)
1812 {
1813 Block& block = sc.function->GetBlock (true);
1814
Greg Clayton6071e6f2015-08-26 22:57:51 +00001815 if (block_die)
1816 sc.block = block.FindBlockByID (block_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001817 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00001818 sc.block = block.FindBlockByID (function_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001819 if (sc.block)
1820 resolved |= eSymbolContextBlock;
1821 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001822 }
1823 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001824
1825 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
1826 {
1827 LineTable *line_table = sc.comp_unit->GetLineTable();
1828 if (line_table != NULL)
1829 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001830 // And address that makes it into this function should be in terms
1831 // of this debug file if there is no debug map, or it will be an
1832 // address in the .o file which needs to be fixed up to be in terms
1833 // of the debug map executable. Either way, calling FixupAddress()
1834 // will work for us.
1835 Address exe_so_addr (so_addr);
1836 if (FixupAddress(exe_so_addr))
Greg Clayton6ab80132012-12-12 17:30:52 +00001837 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001838 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
Greg Clayton6ab80132012-12-12 17:30:52 +00001839 {
1840 resolved |= eSymbolContextLineEntry;
1841 }
1842 }
Greg Clayton6ab80132012-12-12 17:30:52 +00001843 }
1844 }
1845
1846 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
1847 {
1848 // We might have had a compile unit that had discontiguous
1849 // address ranges where the gaps are symbols that don't have
1850 // any debug info. Discontiguous compile unit address ranges
1851 // should only happen when there aren't other functions from
1852 // other compile units in these gaps. This helps keep the size
1853 // of the aranges down.
1854 sc.comp_unit = NULL;
1855 resolved &= ~eSymbolContextCompUnit;
1856 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00001858 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001860 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
1861 cu_offset,
1862 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001863 }
1864 }
1865 }
1866 }
1867 }
1868 return resolved;
1869}
1870
1871
1872
1873uint32_t
1874SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1875{
1876 const uint32_t prev_size = sc_list.GetSize();
1877 if (resolve_scope & eSymbolContextCompUnit)
1878 {
1879 DWARFDebugInfo* debug_info = DebugInfo();
1880 if (debug_info)
1881 {
1882 uint32_t cu_idx;
Greg Clayton53eb1c22012-04-02 22:59:12 +00001883 DWARFCompileUnit* dwarf_cu = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884
Greg Clayton53eb1c22012-04-02 22:59:12 +00001885 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00001887 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Sean Callananddd7a2a2013-10-03 22:27:29 +00001888 const bool full_match = (bool)file_spec.GetDirectory();
Greg Clayton1f746072012-08-29 21:13:06 +00001889 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 +00001890 if (check_inlines || file_spec_matches_cu_file_spec)
1891 {
1892 SymbolContext sc (m_obj_file->GetModule());
Greg Clayton53eb1c22012-04-02 22:59:12 +00001893 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001894 if (sc.comp_unit)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001895 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001896 uint32_t file_idx = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897
Greg Clayton526a4ae2012-05-16 22:09:01 +00001898 // If we are looking for inline functions only and we don't
1899 // find it in the support files, we are done.
1900 if (check_inlines)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001902 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
1903 if (file_idx == UINT32_MAX)
1904 continue;
1905 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906
Greg Clayton526a4ae2012-05-16 22:09:01 +00001907 if (line != 0)
1908 {
1909 LineTable *line_table = sc.comp_unit->GetLineTable();
1910
1911 if (line_table != NULL && line != 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001912 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001913 // We will have already looked up the file index if
1914 // we are searching for inline entries.
1915 if (!check_inlines)
1916 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917
Greg Clayton526a4ae2012-05-16 22:09:01 +00001918 if (file_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001919 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001920 uint32_t found_line;
1921 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1922 found_line = sc.line_entry.line;
1923
1924 while (line_idx != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001926 sc.function = NULL;
1927 sc.block = NULL;
1928 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 {
Greg Clayton526a4ae2012-05-16 22:09:01 +00001930 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1931 if (file_vm_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001933 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1934 DWARFDIE block_die;
1935 if (function_die)
Greg Clayton526a4ae2012-05-16 22:09:01 +00001936 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00001937 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
Greg Clayton526a4ae2012-05-16 22:09:01 +00001938 if (sc.function == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00001939 sc.function = ParseCompileUnitFunction(sc, function_die);
1940
1941 if (sc.function && (resolve_scope & eSymbolContextBlock))
1942 block_die = function_die.LookupDeepestBlock(file_vm_addr);
Greg Clayton526a4ae2012-05-16 22:09:01 +00001943 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001944
Greg Clayton526a4ae2012-05-16 22:09:01 +00001945 if (sc.function != NULL)
1946 {
1947 Block& block = sc.function->GetBlock (true);
1948
Greg Clayton6071e6f2015-08-26 22:57:51 +00001949 if (block_die)
1950 sc.block = block.FindBlockByID (block_die.GetID());
1951 else if (function_die)
1952 sc.block = block.FindBlockByID (function_die.GetID());
Greg Clayton526a4ae2012-05-16 22:09:01 +00001953 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001954 }
1955 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956
Greg Clayton526a4ae2012-05-16 22:09:01 +00001957 sc_list.Append(sc);
1958 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1959 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001960 }
1961 }
Greg Clayton526a4ae2012-05-16 22:09:01 +00001962 else if (file_spec_matches_cu_file_spec && !check_inlines)
1963 {
1964 // only append the context if we aren't looking for inline call sites
1965 // by file and line and if the file spec matches that of the compile unit
1966 sc_list.Append(sc);
1967 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001968 }
1969 else if (file_spec_matches_cu_file_spec && !check_inlines)
1970 {
1971 // only append the context if we aren't looking for inline call sites
1972 // by file and line and if the file spec matches that of the compile unit
1973 sc_list.Append(sc);
1974 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975
Greg Clayton526a4ae2012-05-16 22:09:01 +00001976 if (!check_inlines)
1977 break;
1978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001979 }
1980 }
1981 }
1982 }
1983 return sc_list.GetSize() - prev_size;
1984}
1985
1986void
1987SymbolFileDWARF::Index ()
1988{
1989 if (m_indexed)
1990 return;
1991 m_indexed = true;
1992 Timer scoped_timer (__PRETTY_FUNCTION__,
1993 "SymbolFileDWARF::Index (%s)",
Jim Ingham4af59612014-12-19 19:20:44 +00001994 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995
1996 DWARFDebugInfo* debug_info = DebugInfo();
1997 if (debug_info)
1998 {
1999 uint32_t cu_idx = 0;
2000 const uint32_t num_compile_units = GetNumCompileUnits();
2001 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2002 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00002003 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004
Greg Clayton53eb1c22012-04-02 22:59:12 +00002005 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002006
Greg Clayton53eb1c22012-04-02 22:59:12 +00002007 dwarf_cu->Index (cu_idx,
2008 m_function_basename_index,
2009 m_function_fullname_index,
2010 m_function_method_index,
2011 m_function_selector_index,
2012 m_objc_class_selectors_index,
2013 m_global_index,
2014 m_type_index,
2015 m_namespace_index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016
2017 // Keep memory down by clearing DIEs if this generate function
2018 // caused them to be parsed
2019 if (clear_dies)
Greg Clayton53eb1c22012-04-02 22:59:12 +00002020 dwarf_cu->ClearDIEs (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021 }
2022
Greg Claytond4a2b372011-09-12 23:21:58 +00002023 m_function_basename_index.Finalize();
2024 m_function_fullname_index.Finalize();
2025 m_function_method_index.Finalize();
2026 m_function_selector_index.Finalize();
2027 m_objc_class_selectors_index.Finalize();
2028 m_global_index.Finalize();
2029 m_type_index.Finalize();
2030 m_namespace_index.Finalize();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002031
Greg Clayton24739922010-10-13 03:15:28 +00002032#if defined (ENABLE_DEBUG_PRINTF)
Greg Clayton7bd65b92011-02-09 23:39:34 +00002033 StreamFile s(stdout, false);
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00002034 s.Printf ("DWARF index for '%s':",
2035 GetObjectFile()->GetFileSpec().GetPath().c_str());
Greg Claytonba2d22d2010-11-13 22:57:37 +00002036 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2037 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2038 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2039 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2040 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2041 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
Greg Clayton69b04882010-10-15 02:03:22 +00002042 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00002043 s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s);
Greg Claytonc685f8e2010-09-15 04:15:46 +00002044#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045 }
2046}
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002047
2048bool
Greg Clayton99558cc42015-08-24 23:46:31 +00002049SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx)
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002050{
Greg Clayton99558cc42015-08-24 23:46:31 +00002051 if (decl_ctx == nullptr || !decl_ctx->IsValid())
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002052 {
2053 // Invalid namespace decl which means we aren't matching only things
2054 // in this symbol file, so return true to indicate it matches this
2055 // symbol file.
2056 return true;
2057 }
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002058
Greg Clayton99558cc42015-08-24 23:46:31 +00002059 if ((TypeSystem *)&GetClangASTContext() == decl_ctx->GetTypeSystem())
2060 return true; // The type systems match, return true
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002061
2062 // The namespace AST was valid, and it does not match...
Greg Clayton5160ce52013-03-27 23:08:40 +00002063 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Sean Callananc41e68b2011-10-13 21:08:11 +00002064
2065 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002066 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
Sean Callananc41e68b2011-10-13 21:08:11 +00002067
Greg Claytonbfe3dd42011-10-13 00:00:53 +00002068 return false;
2069}
2070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002072SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073{
Greg Clayton5160ce52013-03-27 23:08:40 +00002074 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002075
2076 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00002077 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002078 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)",
Greg Claytone38a5ed2012-01-05 03:57:59 +00002079 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002080 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002081 append, max_matches);
2082
Greg Clayton99558cc42015-08-24 23:46:31 +00002083 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002084 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002085
Greg Claytonc685f8e2010-09-15 04:15:46 +00002086 DWARFDebugInfo* info = DebugInfo();
2087 if (info == NULL)
2088 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089
2090 // If we aren't appending the results to this list, then clear the list
2091 if (!append)
2092 variables.Clear();
2093
2094 // Remember how many variables are in the list before we search in case
2095 // we are appending the results to a variable list.
2096 const uint32_t original_size = variables.GetSize();
2097
Greg Claytond4a2b372011-09-12 23:21:58 +00002098 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002099
Greg Clayton97fbc342011-10-20 22:30:33 +00002100 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002101 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002102 if (m_apple_names_ap.get())
2103 {
2104 const char *name_cstr = name.GetCString();
Jim Inghamfa39bb42014-10-25 00:33:55 +00002105 llvm::StringRef basename;
2106 llvm::StringRef context;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002107
Jim Inghamaa816b82015-09-02 01:59:14 +00002108 if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename))
Jim Inghamfa39bb42014-10-25 00:33:55 +00002109 basename = name_cstr;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002110
Jim Inghamfa39bb42014-10-25 00:33:55 +00002111 m_apple_names_ap->FindByName (basename.data(), die_offsets);
Greg Clayton97fbc342011-10-20 22:30:33 +00002112 }
Greg Clayton7f995132011-10-04 22:41:51 +00002113 }
2114 else
2115 {
2116 // Index the DWARF if we haven't already
2117 if (!m_indexed)
2118 Index ();
2119
2120 m_global_index.Find (name, die_offsets);
2121 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002122
Greg Clayton437a1352012-04-09 22:43:43 +00002123 const size_t num_die_matches = die_offsets.size();
2124 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002125 {
Greg Clayton7f995132011-10-04 22:41:51 +00002126 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002127 sc.module_sp = m_obj_file->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00002128 assert (sc.module_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002129
Greg Claytond4a2b372011-09-12 23:21:58 +00002130 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00002131 bool done = false;
2132 for (size_t i=0; i<num_die_matches && !done; ++i)
Greg Claytond4a2b372011-09-12 23:21:58 +00002133 {
2134 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002135 DWARFDIE die = debug_info->GetDIE (die_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002136
Greg Clayton95d87902011-11-11 03:16:25 +00002137 if (die)
2138 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002139 switch (die.Tag())
Greg Clayton437a1352012-04-09 22:43:43 +00002140 {
2141 default:
2142 case DW_TAG_subprogram:
2143 case DW_TAG_inlined_subroutine:
2144 case DW_TAG_try_block:
2145 case DW_TAG_catch_block:
2146 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002147
Greg Clayton437a1352012-04-09 22:43:43 +00002148 case DW_TAG_variable:
2149 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002150 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002151
Greg Clayton99558cc42015-08-24 23:46:31 +00002152 if (parent_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00002153 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002154 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2155 if (dwarf_ast)
Greg Clayton99558cc42015-08-24 23:46:31 +00002156 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002157 CompilerDeclContext actual_parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00002158 if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx)
2159 continue;
2160 }
Greg Clayton8b4edba2015-08-14 20:02:05 +00002161 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002162
Greg Clayton6071e6f2015-08-26 22:57:51 +00002163 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002164
Greg Clayton437a1352012-04-09 22:43:43 +00002165 if (variables.GetSize() - original_size >= max_matches)
2166 done = true;
2167 }
2168 break;
2169 }
Greg Clayton95d87902011-11-11 03:16:25 +00002170 }
2171 else
2172 {
2173 if (m_using_apple_tables)
2174 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002175 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2176 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002177 }
2178 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002179 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002180 }
2181
2182 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002183 const uint32_t num_matches = variables.GetSize() - original_size;
2184 if (log && num_matches > 0)
2185 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002186 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002187 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002188 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002189 static_cast<const void*>(parent_decl_ctx),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002190 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002191 num_matches);
2192 }
2193 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002194}
2195
2196uint32_t
2197SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2198{
Greg Clayton5160ce52013-03-27 23:08:40 +00002199 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002200
Greg Clayton21f2a492011-10-06 00:09:08 +00002201 if (log)
2202 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002203 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002204 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002205 regex.GetText(), append,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002206 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002207 }
2208
Greg Claytonc685f8e2010-09-15 04:15:46 +00002209 DWARFDebugInfo* info = DebugInfo();
2210 if (info == NULL)
2211 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002212
2213 // If we aren't appending the results to this list, then clear the list
2214 if (!append)
2215 variables.Clear();
2216
2217 // Remember how many variables are in the list before we search in case
2218 // we are appending the results to a variable list.
2219 const uint32_t original_size = variables.GetSize();
2220
Greg Clayton7f995132011-10-04 22:41:51 +00002221 DIEArray die_offsets;
2222
Greg Clayton97fbc342011-10-20 22:30:33 +00002223 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002224 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002225 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00002226 {
2227 DWARFMappedHash::DIEInfoArray hash_data_array;
2228 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2229 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2230 }
Greg Clayton7f995132011-10-04 22:41:51 +00002231 }
2232 else
2233 {
2234 // Index the DWARF if we haven't already
2235 if (!m_indexed)
2236 Index ();
2237
2238 m_global_index.Find (regex, die_offsets);
2239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002240
Greg Claytonc685f8e2010-09-15 04:15:46 +00002241 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +00002242 sc.module_sp = m_obj_file->GetModule();
Greg Claytonc685f8e2010-09-15 04:15:46 +00002243 assert (sc.module_sp);
2244
Greg Clayton7f995132011-10-04 22:41:51 +00002245 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002246 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002247 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002248 DWARFDebugInfo* debug_info = DebugInfo();
2249 for (size_t i=0; i<num_matches; ++i)
2250 {
2251 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002252 DWARFDIE die = debug_info->GetDIE (die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00002253
2254 if (die)
2255 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002256 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002257
Greg Clayton6071e6f2015-08-26 22:57:51 +00002258 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002259
Greg Clayton95d87902011-11-11 03:16:25 +00002260 if (variables.GetSize() - original_size >= max_matches)
2261 break;
2262 }
2263 else
2264 {
2265 if (m_using_apple_tables)
2266 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002267 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2268 die_offset, regex.GetText());
Greg Clayton95d87902011-11-11 03:16:25 +00002269 }
2270 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002271 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002272 }
2273
2274 // Return the number of variable that were appended to the list
2275 return variables.GetSize() - original_size;
2276}
2277
Greg Claytonaa044962011-10-13 00:59:38 +00002278
Jim Ingham4cda6e02011-10-07 22:23:45 +00002279bool
2280SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
Pavel Labatha73d6572015-03-13 10:22:00 +00002281 bool include_inlines,
Jim Ingham4cda6e02011-10-07 22:23:45 +00002282 SymbolContextList& sc_list)
Greg Clayton9e315582011-09-02 04:03:59 +00002283{
Greg Clayton6071e6f2015-08-26 22:57:51 +00002284 DWARFDIE die = DebugInfo()->GetDIE (die_offset);
2285 return ResolveFunction (die, include_inlines, sc_list);
Greg Claytonaa044962011-10-13 00:59:38 +00002286}
2287
2288
2289bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00002290SymbolFileDWARF::ResolveFunction (const DWARFDIE &orig_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002291 bool include_inlines,
Greg Claytonaa044962011-10-13 00:59:38 +00002292 SymbolContextList& sc_list)
2293{
Greg Clayton9e315582011-09-02 04:03:59 +00002294 SymbolContext sc;
Greg Claytonaa044962011-10-13 00:59:38 +00002295
Greg Clayton6071e6f2015-08-26 22:57:51 +00002296 if (!orig_die)
Greg Claytonaa044962011-10-13 00:59:38 +00002297 return false;
2298
Jim Ingham4cda6e02011-10-07 22:23:45 +00002299 // If we were passed a die that is not a function, just return false...
Greg Clayton6071e6f2015-08-26 22:57:51 +00002300 if (!(orig_die.Tag() == DW_TAG_subprogram || (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002301 return false;
Greg Clayton6071e6f2015-08-26 22:57:51 +00002302
2303 DWARFDIE die = orig_die;
2304 DWARFDIE inlined_die;
2305 if (die.Tag() == DW_TAG_inlined_subroutine)
Greg Clayton9e315582011-09-02 04:03:59 +00002306 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002307 inlined_die = die;
Greg Clayton9e315582011-09-02 04:03:59 +00002308
Greg Clayton6071e6f2015-08-26 22:57:51 +00002309 while (1)
Greg Clayton2bc22f82011-09-30 03:20:47 +00002310 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002311 die = die.GetParent();
2312
2313 if (die)
2314 {
2315 if (die.Tag() == DW_TAG_subprogram)
2316 break;
2317 }
2318 else
Jim Ingham4cda6e02011-10-07 22:23:45 +00002319 break;
Greg Clayton9e315582011-09-02 04:03:59 +00002320 }
2321 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00002322 assert (die && die.Tag() == DW_TAG_subprogram);
2323 if (GetFunction (die, sc))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002324 {
2325 Address addr;
2326 // Parse all blocks if needed
2327 if (inlined_die)
2328 {
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002329 Block &function_block = sc.function->GetBlock (true);
Greg Clayton6071e6f2015-08-26 22:57:51 +00002330 sc.block = function_block.FindBlockByID (inlined_die.GetID());
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002331 if (sc.block == NULL)
Greg Clayton6071e6f2015-08-26 22:57:51 +00002332 sc.block = function_block.FindBlockByID (inlined_die.GetOffset());
Greg Claytonf7bb1fb2015-01-15 03:13:44 +00002333 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002334 addr.Clear();
2335 }
2336 else
2337 {
2338 sc.block = NULL;
2339 addr = sc.function->GetAddressRange().GetBaseAddress();
2340 }
2341
2342 if (addr.IsValid())
2343 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002344 sc_list.Append(sc);
Greg Claytonaa044962011-10-13 00:59:38 +00002345 return true;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002346 }
2347 }
2348
Greg Claytonaa044962011-10-13 00:59:38 +00002349 return false;
Greg Clayton9e315582011-09-02 04:03:59 +00002350}
2351
Greg Clayton7f995132011-10-04 22:41:51 +00002352void
2353SymbolFileDWARF::FindFunctions (const ConstString &name,
2354 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002355 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002356 SymbolContextList& sc_list)
2357{
Greg Claytond4a2b372011-09-12 23:21:58 +00002358 DIEArray die_offsets;
Greg Clayton7f995132011-10-04 22:41:51 +00002359 if (name_to_die.Find (name, die_offsets))
2360 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002361 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002362 }
2363}
2364
2365
2366void
2367SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2368 const NameToDIE &name_to_die,
Pavel Labatha73d6572015-03-13 10:22:00 +00002369 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002370 SymbolContextList& sc_list)
2371{
2372 DIEArray die_offsets;
2373 if (name_to_die.Find (regex, die_offsets))
2374 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002375 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002376 }
2377}
2378
2379
2380void
2381SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2382 const DWARFMappedHash::MemoryTable &memory_table,
Pavel Labatha73d6572015-03-13 10:22:00 +00002383 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002384 SymbolContextList& sc_list)
2385{
2386 DIEArray die_offsets;
Greg Claytond1767f02011-12-08 02:13:16 +00002387 DWARFMappedHash::DIEInfoArray hash_data_array;
2388 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
Greg Clayton7f995132011-10-04 22:41:51 +00002389 {
Greg Claytond1767f02011-12-08 02:13:16 +00002390 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
Pavel Labatha73d6572015-03-13 10:22:00 +00002391 ParseFunctions (die_offsets, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002392 }
2393}
2394
2395void
2396SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
Pavel Labatha73d6572015-03-13 10:22:00 +00002397 bool include_inlines,
Greg Clayton7f995132011-10-04 22:41:51 +00002398 SymbolContextList& sc_list)
2399{
2400 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002401 if (num_matches)
Greg Claytonc685f8e2010-09-15 04:15:46 +00002402 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002403 for (size_t i=0; i<num_matches; ++i)
Greg Claytond7e05462010-11-14 00:22:48 +00002404 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002405 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002406 ResolveFunction (die_offset, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002407 }
2408 }
Greg Claytonc685f8e2010-09-15 04:15:46 +00002409}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002410
Jim Ingham4cda6e02011-10-07 22:23:45 +00002411bool
Greg Clayton99558cc42015-08-24 23:46:31 +00002412SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx,
Greg Clayton6071e6f2015-08-26 22:57:51 +00002413 const DWARFDIE &die)
Greg Clayton99558cc42015-08-24 23:46:31 +00002414{
2415 // If we have no parent decl context to match this DIE matches, and if the parent
2416 // decl context isn't valid, we aren't trying to look for any particular decl
2417 // context so any die matches.
2418 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2419 return true;
2420
Greg Clayton6071e6f2015-08-26 22:57:51 +00002421 if (die)
Greg Clayton99558cc42015-08-24 23:46:31 +00002422 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002423 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2424 if (dwarf_ast)
Greg Clayton99558cc42015-08-24 23:46:31 +00002425 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002426 CompilerDeclContext actual_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00002427 if (actual_decl_ctx)
2428 return actual_decl_ctx == *decl_ctx;
2429 }
2430 }
2431 return false;
2432}
2433
Greg Clayton0c5cd902010-06-28 21:30:43 +00002434uint32_t
Greg Clayton99558cc42015-08-24 23:46:31 +00002435SymbolFileDWARF::FindFunctions (const ConstString &name,
2436 const CompilerDeclContext *parent_decl_ctx,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002437 uint32_t name_type_mask,
2438 bool include_inlines,
Greg Clayton2bc22f82011-09-30 03:20:47 +00002439 bool append,
2440 SymbolContextList& sc_list)
Greg Clayton0c5cd902010-06-28 21:30:43 +00002441{
2442 Timer scoped_timer (__PRETTY_FUNCTION__,
2443 "SymbolFileDWARF::FindFunctions (name = '%s')",
2444 name.AsCString());
2445
Greg Clayton43fe2172013-04-03 02:00:15 +00002446 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
2447 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
2448
Greg Clayton5160ce52013-03-27 23:08:40 +00002449 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002450
2451 if (log)
2452 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002453 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002454 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2455 name.GetCString(),
2456 name_type_mask,
2457 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002458 }
2459
Greg Clayton0c5cd902010-06-28 21:30:43 +00002460 // If we aren't appending the results to this list, then clear the list
2461 if (!append)
2462 sc_list.Clear();
Sean Callanan213fdb82011-10-13 01:49:10 +00002463
Greg Clayton99558cc42015-08-24 23:46:31 +00002464 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002465 return 0;
Jim Ingham4cda6e02011-10-07 22:23:45 +00002466
2467 // If name is empty then we won't find anything.
2468 if (name.IsEmpty())
2469 return 0;
Greg Clayton0c5cd902010-06-28 21:30:43 +00002470
2471 // Remember how many sc_list are in the list before we search in case
2472 // we are appending the results to a variable list.
Greg Clayton9e315582011-09-02 04:03:59 +00002473
Jim Ingham4cda6e02011-10-07 22:23:45 +00002474 const char *name_cstr = name.GetCString();
Greg Clayton43fe2172013-04-03 02:00:15 +00002475
2476 const uint32_t original_size = sc_list.GetSize();
2477
Jim Ingham4cda6e02011-10-07 22:23:45 +00002478 DWARFDebugInfo* info = DebugInfo();
2479 if (info == NULL)
2480 return 0;
2481
Greg Clayton43fe2172013-04-03 02:00:15 +00002482 std::set<const DWARFDebugInfoEntry *> resolved_dies;
Greg Clayton97fbc342011-10-20 22:30:33 +00002483 if (m_using_apple_tables)
Greg Clayton4d01ace2011-09-29 16:58:15 +00002484 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002485 if (m_apple_names_ap.get())
Jim Ingham4cda6e02011-10-07 22:23:45 +00002486 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002487
2488 DIEArray die_offsets;
2489
2490 uint32_t num_matches = 0;
2491
Greg Clayton43fe2172013-04-03 02:00:15 +00002492 if (name_type_mask & eFunctionNameTypeFull)
Greg Claytonaa044962011-10-13 00:59:38 +00002493 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002494 // If they asked for the full name, match what they typed. At some point we may
2495 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2496 // dies that we find by exact match.
Jim Ingham4cda6e02011-10-07 22:23:45 +00002497 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002498 for (uint32_t i = 0; i < num_matches; i++)
2499 {
Greg Clayton95d87902011-11-11 03:16:25 +00002500 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002501 DWARFDIE die = info->GetDIE (die_offset);
Greg Claytonaa044962011-10-13 00:59:38 +00002502 if (die)
2503 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002504 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002505 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002506
Greg Clayton6071e6f2015-08-26 22:57:51 +00002507 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002508 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002509 if (ResolveFunction (die, include_inlines, sc_list))
2510 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002511 }
Greg Claytonaa044962011-10-13 00:59:38 +00002512 }
Greg Clayton95d87902011-11-11 03:16:25 +00002513 else
2514 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002515 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2516 die_offset, name_cstr);
Greg Clayton95d87902011-11-11 03:16:25 +00002517 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002518 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002519 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002520
2521 if (name_type_mask & eFunctionNameTypeSelector)
2522 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002523 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Greg Clayton43fe2172013-04-03 02:00:15 +00002524 return 0; // no selectors in namespaces
Greg Clayton97fbc342011-10-20 22:30:33 +00002525
Greg Clayton43fe2172013-04-03 02:00:15 +00002526 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2527 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2528 // and if it is an ObjC method name, we're good.
Greg Clayton97fbc342011-10-20 22:30:33 +00002529
Greg Clayton43fe2172013-04-03 02:00:15 +00002530 for (uint32_t i = 0; i < num_matches; i++)
Greg Clayton97fbc342011-10-20 22:30:33 +00002531 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002532 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002533 DWARFDIE die = info->GetDIE (die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00002534 if (die)
Greg Clayton97fbc342011-10-20 22:30:33 +00002535 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002536 const char *die_name = die.GetName();
Jim Inghamaa816b82015-09-02 01:59:14 +00002537 if (ObjCLanguage::IsPossibleObjCMethodName(die_name))
Greg Clayton97fbc342011-10-20 22:30:33 +00002538 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002539 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002540 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002541 if (ResolveFunction (die, include_inlines, sc_list))
2542 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002543 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002544 }
2545 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002546 else
2547 {
2548 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2549 die_offset, name_cstr);
2550 }
Greg Clayton97fbc342011-10-20 22:30:33 +00002551 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002552 die_offsets.clear();
2553 }
2554
Greg Clayton99558cc42015-08-24 23:46:31 +00002555 if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase)
Greg Clayton43fe2172013-04-03 02:00:15 +00002556 {
2557 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2558 // extract the base name, look that up, and if there is any other information in the name we were
2559 // passed in we have to post-filter based on that.
2560
2561 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2562 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2563
2564 for (uint32_t i = 0; i < num_matches; i++)
2565 {
2566 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002567 DWARFDIE die = info->GetDIE (die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00002568 if (die)
2569 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002570 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002571 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002572
Greg Clayton43fe2172013-04-03 02:00:15 +00002573
2574 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002575 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() && ResolveFunction (die, include_inlines, sc_list))
Greg Clayton43fe2172013-04-03 02:00:15 +00002576 {
2577 bool keep_die = true;
2578 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
2579 {
2580 // We are looking for either basenames or methods, so we need to
2581 // trim out the ones we won't want by looking at the type
2582 SymbolContext sc;
2583 if (sc_list.GetLastContext(sc))
2584 {
2585 if (sc.block)
2586 {
2587 // We have an inlined function
2588 }
2589 else if (sc.function)
2590 {
2591 Type *type = sc.function->GetType();
2592
Sean Callananc370a8a2013-09-18 22:59:55 +00002593 if (type)
Greg Clayton43fe2172013-04-03 02:00:15 +00002594 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002595 CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID());
2596 if (decl_ctx.IsStructUnionOrClass())
Greg Clayton43fe2172013-04-03 02:00:15 +00002597 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002598 if (name_type_mask & eFunctionNameTypeBase)
2599 {
2600 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2601 keep_die = false;
2602 }
2603 }
2604 else
2605 {
2606 if (name_type_mask & eFunctionNameTypeMethod)
2607 {
2608 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2609 keep_die = false;
2610 }
Greg Clayton43fe2172013-04-03 02:00:15 +00002611 }
2612 }
2613 else
2614 {
Sean Callananc370a8a2013-09-18 22:59:55 +00002615 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
2616 die_offset);
Greg Clayton43fe2172013-04-03 02:00:15 +00002617 }
2618 }
2619 }
2620 }
2621 if (keep_die)
Greg Clayton6071e6f2015-08-26 22:57:51 +00002622 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002623 }
2624 }
2625 else
2626 {
2627 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2628 die_offset, name_cstr);
2629 }
2630 }
2631 die_offsets.clear();
Jim Ingham4cda6e02011-10-07 22:23:45 +00002632 }
2633 }
Greg Clayton7f995132011-10-04 22:41:51 +00002634 }
2635 else
2636 {
2637
2638 // Index the DWARF if we haven't already
2639 if (!m_indexed)
2640 Index ();
2641
Greg Clayton7f995132011-10-04 22:41:51 +00002642 if (name_type_mask & eFunctionNameTypeFull)
Matt Kopecd6089962013-05-10 17:53:48 +00002643 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002644 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002645
Ed Mastefc7baa02013-09-09 18:00:45 +00002646 // FIXME Temporary workaround for global/anonymous namespace
Robert Flack5cbd3bf2015-05-13 18:20:02 +00002647 // functions debugging FreeBSD and Linux binaries.
Matt Kopecd6089962013-05-10 17:53:48 +00002648 // If we didn't find any functions in the global namespace try
2649 // looking in the basename index but ignore any returned
Robert Flackeb83fab2015-05-15 18:59:59 +00002650 // functions that have a namespace but keep functions which
2651 // have an anonymous namespace
2652 // TODO: The arch in the object file isn't correct for MSVC
2653 // binaries on windows, we should find a way to make it
2654 // correct and handle those symbols as well.
Matt Kopecd6089962013-05-10 17:53:48 +00002655 if (sc_list.GetSize() == 0)
2656 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002657 ArchSpec arch;
Greg Clayton99558cc42015-08-24 23:46:31 +00002658 if (!parent_decl_ctx &&
Robert Flackeb83fab2015-05-15 18:59:59 +00002659 GetObjectFile()->GetArchitecture(arch) &&
2660 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
2661 arch.GetMachine() == llvm::Triple::hexagon))
Matt Kopecd6089962013-05-10 17:53:48 +00002662 {
Robert Flackeb83fab2015-05-15 18:59:59 +00002663 SymbolContextList temp_sc_list;
2664 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
Matt Kopecd6089962013-05-10 17:53:48 +00002665 SymbolContext sc;
2666 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
2667 {
2668 if (temp_sc_list.GetContextAtIndex(i, sc))
2669 {
Matt Kopeca189d492013-05-10 22:55:24 +00002670 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
2671 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
Robert Flackeb83fab2015-05-15 18:59:59 +00002672 // Mangled names on Linux and FreeBSD are of the form:
2673 // _ZN18function_namespace13function_nameEv.
Matt Kopec04e5d582013-05-14 19:00:41 +00002674 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
2675 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
Matt Kopecd6089962013-05-10 17:53:48 +00002676 {
2677 sc_list.Append(sc);
2678 }
2679 }
2680 }
2681 }
2682 }
Matt Kopecd6089962013-05-10 17:53:48 +00002683 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002684 DIEArray die_offsets;
Greg Clayton43fe2172013-04-03 02:00:15 +00002685 if (name_type_mask & eFunctionNameTypeBase)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002686 {
Greg Clayton43fe2172013-04-03 02:00:15 +00002687 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
Greg Claytonaa044962011-10-13 00:59:38 +00002688 for (uint32_t i = 0; i < num_base; i++)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002689 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002690 DWARFDIE die = info->GetDIE (die_offsets[i]);
Greg Claytonaa044962011-10-13 00:59:38 +00002691 if (die)
2692 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002693 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002694 continue; // The containing decl contexts don't match
Greg Clayton8b4edba2015-08-14 20:02:05 +00002695
Greg Claytonaa044962011-10-13 00:59:38 +00002696 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002697 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002698 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002699 if (ResolveFunction (die, include_inlines, sc_list))
2700 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002701 }
Greg Claytonaa044962011-10-13 00:59:38 +00002702 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002703 }
2704 die_offsets.clear();
2705 }
2706
Greg Clayton43fe2172013-04-03 02:00:15 +00002707 if (name_type_mask & eFunctionNameTypeMethod)
Jim Ingham4cda6e02011-10-07 22:23:45 +00002708 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002709 if (parent_decl_ctx && parent_decl_ctx->IsValid())
Sean Callanan213fdb82011-10-13 01:49:10 +00002710 return 0; // no methods in namespaces
2711
Greg Clayton43fe2172013-04-03 02:00:15 +00002712 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002713 {
Greg Claytonaa044962011-10-13 00:59:38 +00002714 for (uint32_t i = 0; i < num_base; i++)
2715 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002716 DWARFDIE die = info->GetDIE (die_offsets[i]);
Greg Claytonaa044962011-10-13 00:59:38 +00002717 if (die)
2718 {
Greg Claytonaa044962011-10-13 00:59:38 +00002719 // If we get to here, the die is good, and we should add it:
Greg Clayton6071e6f2015-08-26 22:57:51 +00002720 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
Greg Clayton43fe2172013-04-03 02:00:15 +00002721 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002722 if (ResolveFunction (die, include_inlines, sc_list))
2723 resolved_dies.insert(die.GetDIE());
Greg Clayton43fe2172013-04-03 02:00:15 +00002724 }
Greg Claytonaa044962011-10-13 00:59:38 +00002725 }
2726 }
Jim Ingham4cda6e02011-10-07 22:23:45 +00002727 }
2728 die_offsets.clear();
2729 }
Greg Clayton7f995132011-10-04 22:41:51 +00002730
Greg Clayton99558cc42015-08-24 23:46:31 +00002731 if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid()))
Jim Ingham4cda6e02011-10-07 22:23:45 +00002732 {
Pavel Labatha73d6572015-03-13 10:22:00 +00002733 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
Jim Ingham4cda6e02011-10-07 22:23:45 +00002734 }
2735
Greg Clayton4d01ace2011-09-29 16:58:15 +00002736 }
2737
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002738 // Return the number of variable that were appended to the list
Greg Clayton437a1352012-04-09 22:43:43 +00002739 const uint32_t num_matches = sc_list.GetSize() - original_size;
2740
2741 if (log && num_matches > 0)
2742 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002743 GetObjectFile()->GetModule()->LogMessage (log,
Pavel Labatha73d6572015-03-13 10:22:00 +00002744 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00002745 name.GetCString(),
2746 name_type_mask,
Pavel Labatha73d6572015-03-13 10:22:00 +00002747 include_inlines,
Greg Clayton437a1352012-04-09 22:43:43 +00002748 append,
2749 num_matches);
2750 }
2751 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002752}
2753
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002754uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00002755SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002756{
2757 Timer scoped_timer (__PRETTY_FUNCTION__,
2758 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2759 regex.GetText());
2760
Greg Clayton5160ce52013-03-27 23:08:40 +00002761 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002762
2763 if (log)
2764 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002765 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002766 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2767 regex.GetText(),
2768 append);
Greg Clayton21f2a492011-10-06 00:09:08 +00002769 }
2770
2771
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002772 // If we aren't appending the results to this list, then clear the list
2773 if (!append)
2774 sc_list.Clear();
2775
2776 // Remember how many sc_list are in the list before we search in case
2777 // we are appending the results to a variable list.
2778 uint32_t original_size = sc_list.GetSize();
2779
Greg Clayton97fbc342011-10-20 22:30:33 +00002780 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002781 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002782 if (m_apple_names_ap.get())
Pavel Labatha73d6572015-03-13 10:22:00 +00002783 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002784 }
2785 else
2786 {
Jim Ingham4cda6e02011-10-07 22:23:45 +00002787 // Index the DWARF if we haven't already
Greg Clayton7f995132011-10-04 22:41:51 +00002788 if (!m_indexed)
2789 Index ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002790
Pavel Labatha73d6572015-03-13 10:22:00 +00002791 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002792
Pavel Labatha73d6572015-03-13 10:22:00 +00002793 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
Greg Clayton7f995132011-10-04 22:41:51 +00002794 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002795
2796 // Return the number of variable that were appended to the list
2797 return sc_list.GetSize() - original_size;
2798}
Jim Ingham318c9f22011-08-26 19:44:13 +00002799
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002800uint32_t
Greg Claytond1767f02011-12-08 02:13:16 +00002801SymbolFileDWARF::FindTypes (const SymbolContext& sc,
2802 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00002803 const CompilerDeclContext *parent_decl_ctx,
Greg Claytond1767f02011-12-08 02:13:16 +00002804 bool append,
2805 uint32_t max_matches,
2806 TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002807{
Greg Claytonc685f8e2010-09-15 04:15:46 +00002808 DWARFDebugInfo* info = DebugInfo();
2809 if (info == NULL)
2810 return 0;
2811
Greg Clayton5160ce52013-03-27 23:08:40 +00002812 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002813
Greg Clayton21f2a492011-10-06 00:09:08 +00002814 if (log)
2815 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002816 if (parent_decl_ctx)
Greg Clayton5160ce52013-03-27 23:08:40 +00002817 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002818 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)",
Greg Clayton437a1352012-04-09 22:43:43 +00002819 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002820 static_cast<const void*>(parent_decl_ctx),
2821 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002822 append, max_matches);
Greg Clayton437a1352012-04-09 22:43:43 +00002823 else
Greg Clayton5160ce52013-03-27 23:08:40 +00002824 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002825 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002826 name.GetCString(), append,
Greg Clayton437a1352012-04-09 22:43:43 +00002827 max_matches);
Greg Clayton21f2a492011-10-06 00:09:08 +00002828 }
2829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002830 // If we aren't appending the results to this list, then clear the list
2831 if (!append)
2832 types.Clear();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002833
Greg Clayton99558cc42015-08-24 23:46:31 +00002834 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
Ed Maste4c24b122013-10-17 20:13:14 +00002835 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002836
Greg Claytond4a2b372011-09-12 23:21:58 +00002837 DIEArray die_offsets;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002838
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_types_ap.get())
2842 {
2843 const char *name_cstr = name.GetCString();
2844 m_apple_types_ap->FindByName (name_cstr, die_offsets);
2845 }
Greg Clayton7f995132011-10-04 22:41:51 +00002846 }
2847 else
2848 {
2849 if (!m_indexed)
2850 Index ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002851
Greg Clayton7f995132011-10-04 22:41:51 +00002852 m_type_index.Find (name, die_offsets);
2853 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002854
Greg Clayton437a1352012-04-09 22:43:43 +00002855 const size_t num_die_matches = die_offsets.size();
Greg Clayton7f995132011-10-04 22:41:51 +00002856
Greg Clayton437a1352012-04-09 22:43:43 +00002857 if (num_die_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002858 {
Greg Clayton7f995132011-10-04 22:41:51 +00002859 const uint32_t initial_types_size = types.GetSize();
Greg Claytond4a2b372011-09-12 23:21:58 +00002860 DWARFDebugInfo* debug_info = DebugInfo();
Greg Clayton437a1352012-04-09 22:43:43 +00002861 for (size_t i=0; i<num_die_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002862 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002863 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002864 DWARFDIE die = debug_info->GetDIE (die_offset);
Greg Claytond4a2b372011-09-12 23:21:58 +00002865
Greg Clayton95d87902011-11-11 03:16:25 +00002866 if (die)
Greg Clayton73bf5db2011-06-17 01:22:15 +00002867 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002868 if (!DIEInDeclContext(parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002869 continue; // The containing decl contexts don't match
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002870
Greg Clayton6071e6f2015-08-26 22:57:51 +00002871 Type *matching_type = ResolveType (die);
Greg Clayton95d87902011-11-11 03:16:25 +00002872 if (matching_type)
2873 {
2874 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00002875 types.InsertUnique (matching_type->shared_from_this());
Greg Clayton95d87902011-11-11 03:16:25 +00002876 if (types.GetSize() >= max_matches)
2877 break;
2878 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00002879 }
Greg Clayton95d87902011-11-11 03:16:25 +00002880 else
2881 {
2882 if (m_using_apple_tables)
2883 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002884 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
2885 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002886 }
2887 }
2888
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002889 }
Greg Clayton437a1352012-04-09 22:43:43 +00002890 const uint32_t num_matches = types.GetSize() - initial_types_size;
2891 if (log && num_matches)
2892 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002893 if (parent_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00002894 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002895 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002896 "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 +00002897 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00002898 static_cast<const void*>(parent_decl_ctx),
2899 parent_decl_ctx->GetName().AsCString("<NULL>"),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002900 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002901 num_matches);
2902 }
2903 else
2904 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002905 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002906 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u",
Greg Clayton437a1352012-04-09 22:43:43 +00002907 name.GetCString(),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002908 append, max_matches,
Greg Clayton437a1352012-04-09 22:43:43 +00002909 num_matches);
2910 }
2911 }
2912 return num_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002913 }
Greg Clayton7f995132011-10-04 22:41:51 +00002914 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002915}
2916
2917
Greg Clayton99558cc42015-08-24 23:46:31 +00002918CompilerDeclContext
Greg Clayton96d7d742010-11-10 23:42:09 +00002919SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00002920 const ConstString &name,
Greg Clayton99558cc42015-08-24 23:46:31 +00002921 const CompilerDeclContext *parent_decl_ctx)
Greg Clayton96d7d742010-11-10 23:42:09 +00002922{
Greg Clayton5160ce52013-03-27 23:08:40 +00002923 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
Greg Clayton21f2a492011-10-06 00:09:08 +00002924
2925 if (log)
2926 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002927 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytone38a5ed2012-01-05 03:57:59 +00002928 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
2929 name.GetCString());
Greg Clayton21f2a492011-10-06 00:09:08 +00002930 }
2931
Greg Clayton99558cc42015-08-24 23:46:31 +00002932 CompilerDeclContext namespace_decl_ctx;
2933
2934 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2935 return namespace_decl_ctx;
2936
2937
Greg Clayton96d7d742010-11-10 23:42:09 +00002938 DWARFDebugInfo* info = DebugInfo();
Greg Clayton526e5af2010-11-13 03:52:47 +00002939 if (info)
Greg Clayton96d7d742010-11-10 23:42:09 +00002940 {
Greg Clayton7f995132011-10-04 22:41:51 +00002941 DIEArray die_offsets;
2942
Greg Clayton526e5af2010-11-13 03:52:47 +00002943 // Index if we already haven't to make sure the compile units
2944 // get indexed and make their global DIE index list
Greg Clayton97fbc342011-10-20 22:30:33 +00002945 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00002946 {
Greg Clayton97fbc342011-10-20 22:30:33 +00002947 if (m_apple_namespaces_ap.get())
2948 {
2949 const char *name_cstr = name.GetCString();
2950 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
2951 }
Greg Clayton7f995132011-10-04 22:41:51 +00002952 }
2953 else
2954 {
2955 if (!m_indexed)
2956 Index ();
Greg Clayton96d7d742010-11-10 23:42:09 +00002957
Greg Clayton7f995132011-10-04 22:41:51 +00002958 m_namespace_index.Find (name, die_offsets);
2959 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002960
Greg Clayton7f995132011-10-04 22:41:51 +00002961 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00002962 if (num_matches)
Greg Clayton526e5af2010-11-13 03:52:47 +00002963 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002964 DWARFDebugInfo* debug_info = DebugInfo();
2965 for (size_t i=0; i<num_matches; ++i)
Greg Clayton526e5af2010-11-13 03:52:47 +00002966 {
Greg Claytond4a2b372011-09-12 23:21:58 +00002967 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00002968 DWARFDIE die = debug_info->GetDIE (die_offset);
2969
Greg Clayton95d87902011-11-11 03:16:25 +00002970 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00002971 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00002972 if (!DIEInDeclContext (parent_decl_ctx, die))
Greg Clayton99558cc42015-08-24 23:46:31 +00002973 continue; // The containing decl contexts don't match
Greg Clayton95d87902011-11-11 03:16:25 +00002974
Greg Clayton261ac3f2015-08-28 01:01:03 +00002975 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2976 if (dwarf_ast)
Greg Clayton8b4edba2015-08-14 20:02:05 +00002977 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00002978 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF (die);
Greg Clayton99558cc42015-08-24 23:46:31 +00002979 if (namespace_decl_ctx)
Greg Clayton8b4edba2015-08-14 20:02:05 +00002980 break;
Greg Clayton95d87902011-11-11 03:16:25 +00002981 }
Greg Claytond4a2b372011-09-12 23:21:58 +00002982 }
Greg Clayton95d87902011-11-11 03:16:25 +00002983 else
2984 {
2985 if (m_using_apple_tables)
2986 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00002987 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
2988 die_offset, name.GetCString());
Greg Clayton95d87902011-11-11 03:16:25 +00002989 }
2990 }
2991
Greg Clayton526e5af2010-11-13 03:52:47 +00002992 }
2993 }
Greg Clayton96d7d742010-11-10 23:42:09 +00002994 }
Greg Clayton99558cc42015-08-24 23:46:31 +00002995 if (log && namespace_decl_ctx)
Greg Clayton437a1352012-04-09 22:43:43 +00002996 {
Greg Clayton5160ce52013-03-27 23:08:40 +00002997 GetObjectFile()->GetModule()->LogMessage (log,
Greg Clayton99558cc42015-08-24 23:46:31 +00002998 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"",
Greg Clayton437a1352012-04-09 22:43:43 +00002999 name.GetCString(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003000 static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()),
3001 static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()),
3002 namespace_decl_ctx.GetName().AsCString("<NULL>"));
Greg Clayton437a1352012-04-09 22:43:43 +00003003 }
3004
Greg Clayton99558cc42015-08-24 23:46:31 +00003005 return namespace_decl_ctx;
Greg Clayton96d7d742010-11-10 23:42:09 +00003006}
3007
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003008uint32_t
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003009SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003010{
3011 // Remember how many sc_list are in the list before we search in case
3012 // we are appending the results to a variable list.
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003013 uint32_t original_size = types.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003014
3015 const uint32_t num_die_offsets = die_offsets.size();
3016 // Parse all of the types we found from the pubtypes matches
3017 uint32_t i;
3018 uint32_t num_matches = 0;
3019 for (i = 0; i < num_die_offsets; ++i)
3020 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003021 Type *matching_type = ResolveTypeUID (die_offsets[i]);
3022 if (matching_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003023 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003024 // We found a type pointer, now find the shared pointer form our type list
Greg Claytone1cd1be2012-01-29 20:56:30 +00003025 types.InsertUnique (matching_type->shared_from_this());
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003026 ++num_matches;
3027 if (num_matches >= max_matches)
3028 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003029 }
3030 }
3031
3032 // Return the number of variable that were appended to the list
Greg Claytonb0b9fe62010-08-03 00:35:52 +00003033 return types.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003034}
3035
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003036
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003037TypeSP
Greg Clayton6071e6f2015-08-26 22:57:51 +00003038SymbolFileDWARF::GetTypeForDIE (const DWARFDIE &die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003039{
3040 TypeSP type_sp;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003041 if (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003042 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003043 Type *type_ptr = m_die_to_type.lookup (die.GetDIE());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003044 if (type_ptr == NULL)
3045 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003046 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU());
Greg Claytonca512b32011-01-14 04:54:56 +00003047 assert (lldb_cu);
3048 SymbolContext sc(lldb_cu);
Greg Clayton6071e6f2015-08-26 22:57:51 +00003049 type_sp = ParseType(sc, die, NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003050 }
3051 else if (type_ptr != DIE_IS_BEING_PARSED)
3052 {
3053 // Grab the existing type from the master types lists
Greg Claytone1cd1be2012-01-29 20:56:30 +00003054 type_sp = type_ptr->shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003055 }
3056
3057 }
3058 return type_sp;
3059}
3060
Greg Clayton2bc22f82011-09-30 03:20:47 +00003061
Greg Clayton6071e6f2015-08-26 22:57:51 +00003062DWARFDIE
3063SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFDIE &orig_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003064{
Greg Clayton6071e6f2015-08-26 22:57:51 +00003065 if (orig_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003066 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003067 DWARFDIE die = orig_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003068
Greg Clayton6071e6f2015-08-26 22:57:51 +00003069 while (die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003070 {
3071 // If this is the original DIE that we are searching for a declaration
3072 // for, then don't look in the cache as we don't want our own decl
3073 // context to be our decl context...
Greg Clayton6071e6f2015-08-26 22:57:51 +00003074 if (orig_die != die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003075 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003076 switch (die.Tag())
Greg Clayton2bc22f82011-09-30 03:20:47 +00003077 {
3078 case DW_TAG_compile_unit:
3079 case DW_TAG_namespace:
3080 case DW_TAG_structure_type:
3081 case DW_TAG_union_type:
3082 case DW_TAG_class_type:
3083 return die;
3084
3085 default:
3086 break;
3087 }
3088 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003089
3090 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
3091 if (spec_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003092 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003093 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
3094 if (decl_ctx_die)
3095 return decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003096 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003097
3098 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3099 if (abs_die)
Greg Clayton2bc22f82011-09-30 03:20:47 +00003100 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003101 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
3102 if (decl_ctx_die)
3103 return decl_ctx_die;
Greg Clayton2bc22f82011-09-30 03:20:47 +00003104 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003105
3106 die = die.GetParent();
Greg Clayton2bc22f82011-09-30 03:20:47 +00003107 }
3108 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003109 return DWARFDIE();
Greg Clayton2bc22f82011-09-30 03:20:47 +00003110}
3111
3112
Greg Clayton901c5ca2011-12-03 04:40:03 +00003113Symbol *
3114SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3115{
3116 Symbol *objc_class_symbol = NULL;
3117 if (m_obj_file)
3118 {
Greg Clayton3046e662013-07-10 01:23:25 +00003119 Symtab *symtab = m_obj_file->GetSymtab ();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003120 if (symtab)
3121 {
3122 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3123 eSymbolTypeObjCClass,
3124 Symtab::eDebugNo,
3125 Symtab::eVisibilityAny);
3126 }
3127 }
3128 return objc_class_symbol;
3129}
3130
Greg Claytonc7f03b62012-01-12 04:33:28 +00003131// Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3132// then we can end up looking through all class types for a complete type and never find
3133// the full definition. We need to know if this attribute is supported, so we determine
3134// this here and cache th result. We also need to worry about the debug map DWARF file
3135// if we are doing darwin DWARF in .o file debugging.
3136bool
3137SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
3138{
3139 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
3140 {
3141 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3142 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3143 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3144 else
3145 {
3146 DWARFDebugInfo* debug_info = DebugInfo();
3147 const uint32_t num_compile_units = GetNumCompileUnits();
3148 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3149 {
Greg Clayton53eb1c22012-04-02 22:59:12 +00003150 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3151 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003152 {
3153 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3154 break;
3155 }
3156 }
3157 }
Greg Clayton1f746072012-08-29 21:13:06 +00003158 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
Greg Claytonc7f03b62012-01-12 04:33:28 +00003159 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
3160 }
3161 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3162}
Greg Clayton901c5ca2011-12-03 04:40:03 +00003163
3164// This function can be used when a DIE is found that is a forward declaration
3165// DIE and we want to try and find a type that has the complete definition.
3166TypeSP
Greg Clayton6071e6f2015-08-26 22:57:51 +00003167SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
Greg Claytonc7f03b62012-01-12 04:33:28 +00003168 const ConstString &type_name,
3169 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00003170{
3171
3172 TypeSP type_sp;
3173
Greg Claytonc7f03b62012-01-12 04:33:28 +00003174 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
Greg Clayton901c5ca2011-12-03 04:40:03 +00003175 return type_sp;
3176
3177 DIEArray die_offsets;
3178
3179 if (m_using_apple_tables)
3180 {
3181 if (m_apple_types_ap.get())
3182 {
3183 const char *name_cstr = type_name.GetCString();
Greg Clayton68221ec2012-01-18 20:58:12 +00003184 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003185 }
3186 }
3187 else
3188 {
3189 if (!m_indexed)
3190 Index ();
3191
3192 m_type_index.Find (type_name, die_offsets);
3193 }
3194
Greg Clayton901c5ca2011-12-03 04:40:03 +00003195 const size_t num_matches = die_offsets.size();
3196
Greg Clayton901c5ca2011-12-03 04:40:03 +00003197 if (num_matches)
3198 {
3199 DWARFDebugInfo* debug_info = DebugInfo();
3200 for (size_t i=0; i<num_matches; ++i)
3201 {
3202 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00003203 DWARFDIE type_die = debug_info->GetDIE (die_offset);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003204
3205 if (type_die)
3206 {
3207 bool try_resolving_type = false;
3208
3209 // Don't try and resolve the DIE we are looking for with the DIE itself!
3210 if (type_die != die)
3211 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003212 switch (type_die.Tag())
Greg Clayton901c5ca2011-12-03 04:40:03 +00003213 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00003214 case DW_TAG_class_type:
3215 case DW_TAG_structure_type:
3216 try_resolving_type = true;
3217 break;
3218 default:
3219 break;
Greg Clayton901c5ca2011-12-03 04:40:03 +00003220 }
3221 }
3222
3223 if (try_resolving_type)
3224 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003225 if (must_be_implementation && type_die.Supports_DW_AT_APPLE_objc_complete_type())
3226 try_resolving_type = type_die.GetAttributeValueAsUnsigned (DW_AT_APPLE_objc_complete_type, 0);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003227
3228 if (try_resolving_type)
3229 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003230 Type *resolved_type = ResolveType (type_die, false);
Greg Clayton901c5ca2011-12-03 04:40:03 +00003231 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3232 {
Ed Mastea0191d12013-10-17 20:42:56 +00003233 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 +00003234 die.GetID(),
Jim Ingham4af59612014-12-19 19:20:44 +00003235 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003236 type_die.GetID(),
3237 type_cu->GetID());
Greg Clayton901c5ca2011-12-03 04:40:03 +00003238
Greg Claytonc7f03b62012-01-12 04:33:28 +00003239 if (die)
Greg Clayton6071e6f2015-08-26 22:57:51 +00003240 m_die_to_type[die.GetDIE()] = resolved_type;
Greg Claytone1cd1be2012-01-29 20:56:30 +00003241 type_sp = resolved_type->shared_from_this();
Greg Clayton901c5ca2011-12-03 04:40:03 +00003242 break;
3243 }
3244 }
3245 }
3246 }
3247 else
3248 {
3249 if (m_using_apple_tables)
3250 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003251 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3252 die_offset, type_name.GetCString());
Greg Clayton901c5ca2011-12-03 04:40:03 +00003253 }
3254 }
3255
3256 }
3257 }
3258 return type_sp;
3259}
3260
Greg Claytona8022fa2012-04-24 21:22:41 +00003261
Greg Clayton80c26302012-02-05 06:12:47 +00003262//----------------------------------------------------------------------
3263// This function helps to ensure that the declaration contexts match for
3264// two different DIEs. Often times debug information will refer to a
3265// forward declaration of a type (the equivalent of "struct my_struct;".
3266// There will often be a declaration of that type elsewhere that has the
3267// full definition. When we go looking for the full type "my_struct", we
3268// will find one or more matches in the accelerator tables and we will
3269// then need to make sure the type was in the same declaration context
3270// as the original DIE. This function can efficiently compare two DIEs
3271// and will return true when the declaration context matches, and false
3272// when they don't.
3273//----------------------------------------------------------------------
Greg Clayton890ff562012-02-02 05:48:16 +00003274bool
Greg Clayton6071e6f2015-08-26 22:57:51 +00003275SymbolFileDWARF::DIEDeclContextsMatch (const DWARFDIE &die1,
3276 const DWARFDIE &die2)
Greg Clayton890ff562012-02-02 05:48:16 +00003277{
Greg Claytona8022fa2012-04-24 21:22:41 +00003278 if (die1 == die2)
3279 return true;
3280
Greg Clayton890ff562012-02-02 05:48:16 +00003281 DWARFDIECollection decl_ctx_1;
3282 DWARFDIECollection decl_ctx_2;
Greg Clayton80c26302012-02-05 06:12:47 +00003283 //The declaration DIE stack is a stack of the declaration context
3284 // DIEs all the way back to the compile unit. If a type "T" is
3285 // declared inside a class "B", and class "B" is declared inside
3286 // a class "A" and class "A" is in a namespace "lldb", and the
3287 // namespace is in a compile unit, there will be a stack of DIEs:
3288 //
3289 // [0] DW_TAG_class_type for "B"
3290 // [1] DW_TAG_class_type for "A"
3291 // [2] DW_TAG_namespace for "lldb"
3292 // [3] DW_TAG_compile_unit for the source file.
3293 //
3294 // We grab both contexts and make sure that everything matches
3295 // all the way back to the compiler unit.
3296
3297 // First lets grab the decl contexts for both DIEs
Greg Clayton6071e6f2015-08-26 22:57:51 +00003298 die1.GetDeclContextDIEs (decl_ctx_1);
3299 die2.GetDeclContextDIEs (decl_ctx_2);
Greg Clayton80c26302012-02-05 06:12:47 +00003300 // Make sure the context arrays have the same size, otherwise
3301 // we are done
Greg Clayton890ff562012-02-02 05:48:16 +00003302 const size_t count1 = decl_ctx_1.Size();
3303 const size_t count2 = decl_ctx_2.Size();
3304 if (count1 != count2)
3305 return false;
Greg Clayton80c26302012-02-05 06:12:47 +00003306
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003307 // Make sure the DW_TAG values match all the way back up the
Greg Clayton80c26302012-02-05 06:12:47 +00003308 // compile unit. If they don't, then we are done.
Greg Clayton6071e6f2015-08-26 22:57:51 +00003309 DWARFDIE decl_ctx_die1;
3310 DWARFDIE decl_ctx_die2;
Greg Clayton890ff562012-02-02 05:48:16 +00003311 size_t i;
3312 for (i=0; i<count1; i++)
3313 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003314 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3315 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3316 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
Greg Clayton890ff562012-02-02 05:48:16 +00003317 return false;
3318 }
Greg Clayton890ff562012-02-02 05:48:16 +00003319#if defined LLDB_CONFIGURATION_DEBUG
Greg Clayton80c26302012-02-05 06:12:47 +00003320
3321 // Make sure the top item in the decl context die array is always
3322 // DW_TAG_compile_unit. If it isn't then something went wrong in
Greg Clayton5ce1a842015-08-27 18:09:44 +00003323 // the DWARFDIE::GetDeclContextDIEs() function...
Greg Clayton6071e6f2015-08-26 22:57:51 +00003324 assert (decl_ctx_1.GetDIEAtIndex (count1 - 1).Tag() == DW_TAG_compile_unit);
Greg Clayton80c26302012-02-05 06:12:47 +00003325
Greg Clayton890ff562012-02-02 05:48:16 +00003326#endif
3327 // Always skip the compile unit when comparing by only iterating up to
Greg Clayton80c26302012-02-05 06:12:47 +00003328 // "count - 1". Here we compare the names as we go.
Greg Clayton890ff562012-02-02 05:48:16 +00003329 for (i=0; i<count1 - 1; i++)
3330 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003331 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3332 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3333 const char *name1 = decl_ctx_die1.GetName();
3334 const char *name2 = decl_ctx_die2.GetName();
Greg Clayton890ff562012-02-02 05:48:16 +00003335 // If the string was from a DW_FORM_strp, then the pointer will often
3336 // be the same!
Greg Clayton5569e642012-02-06 01:44:54 +00003337 if (name1 == name2)
3338 continue;
3339
3340 // Name pointers are not equal, so only compare the strings
3341 // if both are not NULL.
3342 if (name1 && name2)
Greg Clayton890ff562012-02-02 05:48:16 +00003343 {
Greg Clayton5569e642012-02-06 01:44:54 +00003344 // If the strings don't compare, we are done...
3345 if (strcmp(name1, name2) != 0)
Greg Clayton890ff562012-02-02 05:48:16 +00003346 return false;
Greg Clayton5569e642012-02-06 01:44:54 +00003347 }
3348 else
3349 {
3350 // One name was NULL while the other wasn't
3351 return false;
Greg Clayton890ff562012-02-02 05:48:16 +00003352 }
3353 }
Greg Clayton80c26302012-02-05 06:12:47 +00003354 // We made it through all of the checks and the declaration contexts
3355 // are equal.
Greg Clayton890ff562012-02-02 05:48:16 +00003356 return true;
3357}
Greg Clayton220a0072011-12-09 08:48:30 +00003358
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00003359
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003360TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00003361SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
3362{
3363 TypeSP type_sp;
3364
3365 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
3366 if (dwarf_decl_ctx_count > 0)
3367 {
3368 const ConstString type_name(dwarf_decl_ctx[0].name);
3369 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
3370
3371 if (type_name)
3372 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003373 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
Greg Claytona8022fa2012-04-24 21:22:41 +00003374 if (log)
3375 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003376 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003377 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
3378 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3379 dwarf_decl_ctx.GetQualifiedName());
3380 }
3381
3382 DIEArray die_offsets;
3383
3384 if (m_using_apple_tables)
3385 {
3386 if (m_apple_types_ap.get())
3387 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003388 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
3389 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
3390 if (has_tag && has_qualified_name_hash)
Greg Claytona8022fa2012-04-24 21:22:41 +00003391 {
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003392 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
3393 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
3394 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003395 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
Greg Claytoncb9c8cf2013-02-06 23:56:13 +00003396 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
3397 }
3398 else if (has_tag)
3399 {
3400 if (log)
Greg Clayton5160ce52013-03-27 23:08:40 +00003401 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
Greg Claytona8022fa2012-04-24 21:22:41 +00003402 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
3403 }
3404 else
3405 {
3406 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
3407 }
3408 }
3409 }
3410 else
3411 {
3412 if (!m_indexed)
3413 Index ();
3414
3415 m_type_index.Find (type_name, die_offsets);
3416 }
3417
3418 const size_t num_matches = die_offsets.size();
3419
3420
Greg Claytona8022fa2012-04-24 21:22:41 +00003421 if (num_matches)
3422 {
3423 DWARFDebugInfo* debug_info = DebugInfo();
3424 for (size_t i=0; i<num_matches; ++i)
3425 {
3426 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00003427 DWARFDIE type_die = debug_info->GetDIE (die_offset);
Greg Claytona8022fa2012-04-24 21:22:41 +00003428
3429 if (type_die)
3430 {
3431 bool try_resolving_type = false;
3432
3433 // Don't try and resolve the DIE we are looking for with the DIE itself!
Greg Clayton6071e6f2015-08-26 22:57:51 +00003434 const dw_tag_t type_tag = type_die.Tag();
Greg Claytona8022fa2012-04-24 21:22:41 +00003435 // Make sure the tags match
3436 if (type_tag == tag)
3437 {
3438 // The tags match, lets try resolving this type
3439 try_resolving_type = true;
3440 }
3441 else
3442 {
3443 // The tags don't match, but we need to watch our for a
3444 // forward declaration for a struct and ("struct foo")
3445 // ends up being a class ("class foo { ... };") or
3446 // vice versa.
3447 switch (type_tag)
3448 {
3449 case DW_TAG_class_type:
3450 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3451 try_resolving_type = (tag == DW_TAG_structure_type);
3452 break;
3453 case DW_TAG_structure_type:
3454 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3455 try_resolving_type = (tag == DW_TAG_class_type);
3456 break;
3457 default:
3458 // Tags don't match, don't event try to resolve
3459 // using this type whose name matches....
3460 break;
3461 }
3462 }
3463
3464 if (try_resolving_type)
3465 {
3466 DWARFDeclContext type_dwarf_decl_ctx;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003467 type_die.GetDWARFDeclContext (type_dwarf_decl_ctx);
Greg Claytona8022fa2012-04-24 21:22:41 +00003468
3469 if (log)
3470 {
Greg Clayton5160ce52013-03-27 23:08:40 +00003471 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003472 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
3473 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3474 dwarf_decl_ctx.GetQualifiedName(),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003475 type_die.GetOffset(),
Greg Claytona8022fa2012-04-24 21:22:41 +00003476 type_dwarf_decl_ctx.GetQualifiedName());
3477 }
3478
3479 // Make sure the decl contexts match all the way up
3480 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
3481 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003482 Type *resolved_type = ResolveType (type_die, false);
Greg Claytona8022fa2012-04-24 21:22:41 +00003483 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3484 {
3485 type_sp = resolved_type->shared_from_this();
3486 break;
3487 }
3488 }
3489 }
3490 else
3491 {
3492 if (log)
3493 {
3494 std::string qualified_name;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003495 type_die.GetQualifiedName(qualified_name);
Greg Clayton5160ce52013-03-27 23:08:40 +00003496 GetObjectFile()->GetModule()->LogMessage (log,
Greg Claytona8022fa2012-04-24 21:22:41 +00003497 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
3498 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3499 dwarf_decl_ctx.GetQualifiedName(),
Greg Clayton6071e6f2015-08-26 22:57:51 +00003500 type_die.GetOffset(),
Greg Claytona8022fa2012-04-24 21:22:41 +00003501 qualified_name.c_str());
3502 }
3503 }
3504 }
3505 else
3506 {
3507 if (m_using_apple_tables)
3508 {
3509 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3510 die_offset, type_name.GetCString());
3511 }
3512 }
3513
3514 }
3515 }
3516 }
3517 }
3518 return type_sp;
3519}
3520
Greg Claytona8022fa2012-04-24 21:22:41 +00003521TypeSP
Greg Clayton6071e6f2015-08-26 22:57:51 +00003522SymbolFileDWARF::ParseType (const SymbolContext& sc, const DWARFDIE &die, bool *type_is_new_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003523{
Greg Clayton196e8cd2015-08-17 20:31:46 +00003524 TypeSP type_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003525
Greg Clayton6071e6f2015-08-26 22:57:51 +00003526 if (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003527 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003528 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
3529
3530 if (type_system)
Greg Clayton196e8cd2015-08-17 20:31:46 +00003531 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00003532 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
3533 if (dwarf_ast)
Greg Clayton6071e6f2015-08-26 22:57:51 +00003534 {
Greg Clayton261ac3f2015-08-28 01:01:03 +00003535 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3536 type_sp = dwarf_ast->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr);
3537 if (type_sp)
3538 {
3539 TypeList* type_list = GetTypeList();
3540 if (type_list)
3541 type_list->Insert(type_sp);
3542 }
Greg Clayton6071e6f2015-08-26 22:57:51 +00003543 }
Greg Clayton196e8cd2015-08-17 20:31:46 +00003544 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003545 }
Greg Clayton196e8cd2015-08-17 20:31:46 +00003546
3547 return type_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003548}
3549
3550size_t
Greg Clayton1be10fc2010-09-29 01:12:09 +00003551SymbolFileDWARF::ParseTypes
3552(
3553 const SymbolContext& sc,
Greg Clayton6071e6f2015-08-26 22:57:51 +00003554 const DWARFDIE &orig_die,
Greg Clayton1be10fc2010-09-29 01:12:09 +00003555 bool parse_siblings,
3556 bool parse_children
3557)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003558{
3559 size_t types_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003560 DWARFDIE die = orig_die;
3561 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003562 {
3563 bool type_is_new = false;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003564 if (ParseType(sc, die, &type_is_new).get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003565 {
3566 if (type_is_new)
3567 ++types_added;
3568 }
3569
Greg Clayton6071e6f2015-08-26 22:57:51 +00003570 if (parse_children && die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003571 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003572 if (die.Tag() == DW_TAG_subprogram)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003573 {
3574 SymbolContext child_sc(sc);
Greg Clayton6071e6f2015-08-26 22:57:51 +00003575 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3576 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003577 }
3578 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00003579 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003580 }
3581
3582 if (parse_siblings)
Greg Clayton6071e6f2015-08-26 22:57:51 +00003583 die = die.GetSibling();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003584 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00003585 die.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003586 }
3587 return types_added;
3588}
3589
3590
3591size_t
3592SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3593{
3594 assert(sc.comp_unit && sc.function);
3595 size_t functions_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003596 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003597 if (dwarf_cu)
3598 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003599 const dw_offset_t function_die_offset = sc.function->GetID();
3600 DWARFDIE function_die = dwarf_cu->GetDIE (function_die_offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003601 if (function_die)
3602 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003603 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), function_die, LLDB_INVALID_ADDRESS, 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003604 }
3605 }
3606
3607 return functions_added;
3608}
3609
3610
3611size_t
3612SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3613{
3614 // At least a compile unit must be valid
3615 assert(sc.comp_unit);
3616 size_t types_added = 0;
Greg Clayton1f746072012-08-29 21:13:06 +00003617 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003618 if (dwarf_cu)
3619 {
3620 if (sc.function)
3621 {
3622 dw_offset_t function_die_offset = sc.function->GetID();
Greg Clayton6071e6f2015-08-26 22:57:51 +00003623 DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset);
3624 if (func_die && func_die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003625 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003626 types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003627 }
3628 }
3629 else
3630 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003631 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3632 if (dwarf_cu_die && dwarf_cu_die.HasChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003633 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003634 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003635 }
3636 }
3637 }
3638
3639 return types_added;
3640}
3641
3642size_t
3643SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3644{
3645 if (sc.comp_unit != NULL)
3646 {
Greg Clayton4b3dc102010-11-01 20:32:12 +00003647 DWARFDebugInfo* info = DebugInfo();
3648 if (info == NULL)
3649 return 0;
3650
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003651 if (sc.function)
3652 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003653 DWARFDIE function_die = info->GetDIE(sc.function->GetID());
Greg Clayton9422dd62013-03-04 21:46:16 +00003654
Greg Clayton6071e6f2015-08-26 22:57:51 +00003655 const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsUnsigned (DW_AT_low_pc, LLDB_INVALID_ADDRESS);
Greg Claytonc7bece562013-01-25 18:06:21 +00003656 if (func_lo_pc != LLDB_INVALID_ADDRESS)
Greg Claytone38a5ed2012-01-05 03:57:59 +00003657 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003658 const size_t num_variables = ParseVariables(sc, function_die.GetFirstChild(), func_lo_pc, true, true);
Greg Claytonc662ec82011-06-17 22:10:16 +00003659
Greg Claytone38a5ed2012-01-05 03:57:59 +00003660 // Let all blocks know they have parse all their variables
3661 sc.function->GetBlock (false).SetDidParseVariables (true, true);
3662 return num_variables;
3663 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003664 }
3665 else if (sc.comp_unit)
3666 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003667 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID());
Greg Clayton9422dd62013-03-04 21:46:16 +00003668
3669 if (dwarf_cu == NULL)
3670 return 0;
3671
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003672 uint32_t vars_added = 0;
3673 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3674
3675 if (variables.get() == NULL)
3676 {
3677 variables.reset(new VariableList());
3678 sc.comp_unit->SetVariableList(variables);
3679
Greg Claytond4a2b372011-09-12 23:21:58 +00003680 DIEArray die_offsets;
Greg Clayton97fbc342011-10-20 22:30:33 +00003681 if (m_using_apple_tables)
Greg Clayton7f995132011-10-04 22:41:51 +00003682 {
Greg Clayton97fbc342011-10-20 22:30:33 +00003683 if (m_apple_names_ap.get())
Greg Claytond1767f02011-12-08 02:13:16 +00003684 {
3685 DWARFMappedHash::DIEInfoArray hash_data_array;
3686 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
3687 dwarf_cu->GetNextCompileUnitOffset(),
3688 hash_data_array))
3689 {
3690 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3691 }
3692 }
Greg Clayton7f995132011-10-04 22:41:51 +00003693 }
3694 else
3695 {
3696 // Index if we already haven't to make sure the compile units
3697 // get indexed and make their global DIE index list
3698 if (!m_indexed)
3699 Index ();
3700
3701 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
3702 dwarf_cu->GetNextCompileUnitOffset(),
3703 die_offsets);
3704 }
3705
3706 const size_t num_matches = die_offsets.size();
Greg Claytond4a2b372011-09-12 23:21:58 +00003707 if (num_matches)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003708 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003709 DWARFDebugInfo* debug_info = DebugInfo();
3710 for (size_t i=0; i<num_matches; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003711 {
Greg Claytond4a2b372011-09-12 23:21:58 +00003712 const dw_offset_t die_offset = die_offsets[i];
Greg Clayton6071e6f2015-08-26 22:57:51 +00003713 DWARFDIE die = debug_info->GetDIE (die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00003714 if (die)
Greg Claytond4a2b372011-09-12 23:21:58 +00003715 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003716 VariableSP var_sp (ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
Greg Clayton95d87902011-11-11 03:16:25 +00003717 if (var_sp)
3718 {
3719 variables->AddVariableIfUnique (var_sp);
3720 ++vars_added;
3721 }
Greg Claytond4a2b372011-09-12 23:21:58 +00003722 }
Greg Clayton95d87902011-11-11 03:16:25 +00003723 else
3724 {
3725 if (m_using_apple_tables)
3726 {
Greg Claytone38a5ed2012-01-05 03:57:59 +00003727 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset);
Greg Clayton95d87902011-11-11 03:16:25 +00003728 }
3729 }
3730
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003731 }
3732 }
3733 }
3734 return vars_added;
3735 }
3736 }
3737 return 0;
3738}
3739
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003740VariableSP
3741SymbolFileDWARF::ParseVariableDIE
3742(
3743 const SymbolContext& sc,
Greg Clayton6071e6f2015-08-26 22:57:51 +00003744 const DWARFDIE &die,
Greg Clayton016a95e2010-09-14 02:20:48 +00003745 const lldb::addr_t func_low_pc
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003746)
3747{
Greg Clayton6071e6f2015-08-26 22:57:51 +00003748 VariableSP var_sp;
3749 if (!die)
3750 return var_sp;
3751
3752 var_sp = m_die_to_variable_sp[die.GetDIE()];
Greg Clayton83c5cd92010-11-14 22:13:40 +00003753 if (var_sp)
3754 return var_sp; // Already been parsed!
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003755
Greg Clayton6071e6f2015-08-26 22:57:51 +00003756 const dw_tag_t tag = die.Tag();
Richard Mitton0a558352013-10-17 21:14:00 +00003757 ModuleSP module = GetObjectFile()->GetModule();
Greg Clayton7f995132011-10-04 22:41:51 +00003758
3759 if ((tag == DW_TAG_variable) ||
3760 (tag == DW_TAG_constant) ||
3761 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003762 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003763 DWARFAttributes attributes;
3764 const size_t num_attributes = die.GetAttributes(attributes);
Greg Clayton7f995132011-10-04 22:41:51 +00003765 if (num_attributes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003766 {
Greg Clayton7f995132011-10-04 22:41:51 +00003767 const char *name = NULL;
3768 const char *mangled = NULL;
3769 Declaration decl;
3770 uint32_t i;
Greg Claytond1767f02011-12-08 02:13:16 +00003771 lldb::user_id_t type_uid = LLDB_INVALID_UID;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003772 DWARFExpression location(die.GetCU());
Greg Clayton7f995132011-10-04 22:41:51 +00003773 bool is_external = false;
3774 bool is_artificial = false;
3775 bool location_is_const_value_data = false;
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003776 bool has_explicit_location = false;
Enrico Granata4ec130d2014-08-11 19:16:35 +00003777 DWARFFormValue const_value;
Greg Clayton23f59502012-07-17 03:23:13 +00003778 //AccessType accessibility = eAccessNone;
Greg Clayton7f995132011-10-04 22:41:51 +00003779
3780 for (i=0; i<num_attributes; ++i)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003781 {
Greg Clayton7f995132011-10-04 22:41:51 +00003782 dw_attr_t attr = attributes.AttributeAtIndex(i);
3783 DWARFFormValue form_value;
Greg Clayton54166af2014-11-22 01:58:59 +00003784
Greg Clayton6071e6f2015-08-26 22:57:51 +00003785 if (attributes.ExtractFormValueAtIndex(i, form_value))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003786 {
Greg Clayton7f995132011-10-04 22:41:51 +00003787 switch (attr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003788 {
Greg Clayton7f995132011-10-04 22:41:51 +00003789 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3790 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3791 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
Greg Clayton6071e6f2015-08-26 22:57:51 +00003792 case DW_AT_name: name = form_value.AsCString(); break;
Greg Clayton71415542012-12-08 00:24:40 +00003793 case DW_AT_linkage_name:
Greg Clayton6071e6f2015-08-26 22:57:51 +00003794 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(); break;
Greg Clayton54166af2014-11-22 01:58:59 +00003795 case DW_AT_type: type_uid = form_value.Reference(); break;
Greg Clayton1c8ef472013-04-05 23:27:21 +00003796 case DW_AT_external: is_external = form_value.Boolean(); break;
Greg Clayton7f995132011-10-04 22:41:51 +00003797 case DW_AT_const_value:
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003798 // If we have already found a DW_AT_location attribute, ignore this attribute.
3799 if (!has_explicit_location)
3800 {
3801 location_is_const_value_data = true;
3802 // The constant value will be either a block, a data value or a string.
Ed Masteeeae7212013-10-24 20:43:47 +00003803 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003804 if (DWARFFormValue::IsBlockForm(form_value.Form()))
3805 {
3806 // Retrieve the value as a block expression.
3807 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3808 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00003809 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003810 }
3811 else if (DWARFFormValue::IsDataForm(form_value.Form()))
3812 {
3813 // Retrieve the value as a data expression.
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003814 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3815 DWARFFormValue::GetFixedFormSizesForAddressSize (
3816 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
3817 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003818 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003819 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Enrico Granata4ec130d2014-08-11 19:16:35 +00003820 if (data_length == 0)
3821 {
3822 const uint8_t *data_pointer = form_value.BlockData();
3823 if (data_pointer)
3824 {
Jason Molenda18f5fd32014-10-16 07:52:17 +00003825 form_value.Unsigned();
Enrico Granata4ec130d2014-08-11 19:16:35 +00003826 }
3827 else if (DWARFFormValue::IsDataForm(form_value.Form()))
3828 {
3829 // we need to get the byte size of the type later after we create the variable
3830 const_value = form_value;
3831 }
3832 }
3833 else
3834 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003835 }
3836 else
3837 {
3838 // Retrieve the value as a string expression.
3839 if (form_value.Form() == DW_FORM_strp)
3840 {
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003841 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3842 DWARFFormValue::GetFixedFormSizesForAddressSize (
3843 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
3844 attributes.CompileUnitAtIndex(i)->IsDWARF64());
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003845 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
Tamas Berghammerb7c64652015-08-25 11:45:46 +00003846 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
Richard Mitton0a558352013-10-17 21:14:00 +00003847 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003848 }
3849 else
3850 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00003851 const char *str = form_value.AsCString();
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003852 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
3853 uint32_t string_length = strlen(str) + 1;
Richard Mitton0a558352013-10-17 21:14:00 +00003854 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003855 }
3856 }
3857 }
3858 break;
Greg Clayton7f995132011-10-04 22:41:51 +00003859 case DW_AT_location:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003860 {
Andrew Kaylorb32581f2013-02-13 19:57:06 +00003861 location_is_const_value_data = false;
3862 has_explicit_location = true;
Greg Clayton7f995132011-10-04 22:41:51 +00003863 if (form_value.BlockData())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003864 {
Ed Masteeeae7212013-10-24 20:43:47 +00003865 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
Greg Clayton7f995132011-10-04 22:41:51 +00003866
3867 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3868 uint32_t block_length = form_value.Unsigned();
Richard Mitton0a558352013-10-17 21:14:00 +00003869 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
Greg Clayton7f995132011-10-04 22:41:51 +00003870 }
3871 else
3872 {
Ed Masteeeae7212013-10-24 20:43:47 +00003873 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
Greg Clayton7f995132011-10-04 22:41:51 +00003874 const dw_offset_t debug_loc_offset = form_value.Unsigned();
3875
3876 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
3877 if (loc_list_length > 0)
3878 {
Richard Mitton0a558352013-10-17 21:14:00 +00003879 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
Greg Clayton7f995132011-10-04 22:41:51 +00003880 assert (func_low_pc != LLDB_INVALID_ADDRESS);
Greg Clayton54166af2014-11-22 01:58:59 +00003881 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
Greg Clayton7f995132011-10-04 22:41:51 +00003882 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003883 }
3884 }
Greg Clayton7f995132011-10-04 22:41:51 +00003885 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003886
Greg Clayton1c8ef472013-04-05 23:27:21 +00003887 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
Greg Clayton23f59502012-07-17 03:23:13 +00003888 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
Greg Clayton7f995132011-10-04 22:41:51 +00003889 case DW_AT_declaration:
3890 case DW_AT_description:
3891 case DW_AT_endianity:
3892 case DW_AT_segment:
3893 case DW_AT_start_scope:
3894 case DW_AT_visibility:
3895 default:
3896 case DW_AT_abstract_origin:
3897 case DW_AT_sibling:
3898 case DW_AT_specification:
3899 break;
3900 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003901 }
3902 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003903
Greg Clayton6071e6f2015-08-26 22:57:51 +00003904 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3905 const dw_tag_t parent_tag = die.GetParent().Tag();
3906 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 +00003907
Greg Clayton9e9f2192013-05-17 00:55:28 +00003908 ValueType scope = eValueTypeInvalid;
3909
Greg Clayton6071e6f2015-08-26 22:57:51 +00003910 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
Greg Clayton9e9f2192013-05-17 00:55:28 +00003911 SymbolContextScope * symbol_context_scope = NULL;
3912
Siva Chandra0783ab92015-03-24 18:32:27 +00003913 if (!mangled)
3914 {
3915 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
3916 // generate fully qualified names of global variables with commands like "frame var j".
3917 // For example, if j were an int variable holding a value 4 and declared in a namespace
3918 // B which in turn is contained in a namespace A, the command "frame var j" returns
3919 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
3920 // to generate a fully qualified name from the declaration context.
Greg Clayton6071e6f2015-08-26 22:57:51 +00003921 if (parent_tag == DW_TAG_compile_unit &&
Jim Ingham0e0984e2015-09-02 01:06:46 +00003922 Language::LanguageIsCPlusPlus(die.GetLanguage()))
Siva Chandra0783ab92015-03-24 18:32:27 +00003923 {
3924 DWARFDeclContext decl_ctx;
3925
Greg Clayton6071e6f2015-08-26 22:57:51 +00003926 die.GetDWARFDeclContext(decl_ctx);
Siva Chandra0783ab92015-03-24 18:32:27 +00003927 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
3928 }
3929 }
3930
Greg Clayton9e9f2192013-05-17 00:55:28 +00003931 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3932 // or static variable, so we have to do a little digging by
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00003933 // looking at the location of a variable to see if it contains
Greg Clayton9e9f2192013-05-17 00:55:28 +00003934 // a DW_OP_addr opcode _somewhere_ in the definition. I say
3935 // somewhere because clang likes to combine small global variables
3936 // into the same symbol and have locations like:
3937 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3938 // So if we don't have a DW_TAG_formal_parameter, we can look at
3939 // the location to see if it contains a DW_OP_addr opcode, and
3940 // then we can correctly classify our variables.
3941 if (tag == DW_TAG_formal_parameter)
3942 scope = eValueTypeVariableArgument;
3943 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00003944 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003945 bool op_error = false;
3946 // Check if the location has a DW_OP_addr with any address value...
3947 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3948 if (!location_is_const_value_data)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00003949 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003950 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
3951 if (op_error)
Greg Clayton96c09682012-01-04 22:56:43 +00003952 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003953 StreamString strm;
3954 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
Greg Clayton6071e6f2015-08-26 22:57:51 +00003955 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 +00003956 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00003957 }
Greg Claytond1767f02011-12-08 02:13:16 +00003958
Greg Clayton9e9f2192013-05-17 00:55:28 +00003959 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
3960 {
3961 if (is_external)
3962 scope = eValueTypeVariableGlobal;
3963 else
3964 scope = eValueTypeVariableStatic;
3965
3966
3967 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
3968
3969 if (debug_map_symfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00003970 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003971 // When leaving the DWARF in the .o files on darwin,
3972 // when we have a global variable that wasn't initialized,
3973 // the .o file might not have allocated a virtual
3974 // address for the global variable. In this case it will
3975 // have created a symbol for the global variable
3976 // that is undefined/data and external and the value will
3977 // be the byte size of the variable. When we do the
3978 // address map in SymbolFileDWARFDebugMap we rely on
3979 // having an address, we need to do some magic here
3980 // so we can get the correct address for our global
3981 // variable. The address for all of these entries
3982 // will be zero, and there will be an undefined symbol
3983 // in this object file, and the executable will have
3984 // a matching symbol with a good address. So here we
3985 // dig up the correct address and replace it in the
3986 // location for the variable, and set the variable's
3987 // symbol context scope to be that of the main executable
3988 // so the file address will resolve correctly.
3989 bool linked_oso_file_addr = false;
3990 if (is_external && location_DW_OP_addr == 0)
Greg Clayton9422dd62013-03-04 21:46:16 +00003991 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00003992 // we have a possible uninitialized extern global
3993 ConstString const_name(mangled ? mangled : name);
3994 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
3995 if (debug_map_objfile)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00003996 {
Greg Clayton3046e662013-07-10 01:23:25 +00003997 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
Greg Clayton9e9f2192013-05-17 00:55:28 +00003998 if (debug_map_symtab)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00003999 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004000 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
4001 eSymbolTypeData,
4002 Symtab::eDebugYes,
4003 Symtab::eVisibilityExtern);
4004 if (exe_symbol)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004005 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004006 if (exe_symbol->ValueIsAddress())
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004007 {
Greg Clayton358cf1e2015-06-25 21:46:34 +00004008 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
Greg Clayton9e9f2192013-05-17 00:55:28 +00004009 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004010 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004011 if (location.Update_DW_OP_addr (exe_file_addr))
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004012 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004013 linked_oso_file_addr = true;
4014 symbol_context_scope = exe_symbol;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004015 }
4016 }
4017 }
4018 }
4019 }
4020 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004021 }
Greg Clayton9422dd62013-03-04 21:46:16 +00004022
Greg Clayton9e9f2192013-05-17 00:55:28 +00004023 if (!linked_oso_file_addr)
4024 {
4025 // The DW_OP_addr is not zero, but it contains a .o file address which
4026 // needs to be linked up correctly.
4027 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
4028 if (exe_file_addr != LLDB_INVALID_ADDRESS)
Greg Clayton9422dd62013-03-04 21:46:16 +00004029 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004030 // Update the file address for this variable
4031 location.Update_DW_OP_addr (exe_file_addr);
4032 }
4033 else
4034 {
4035 // Variable didn't make it into the final executable
4036 return var_sp;
Greg Clayton9422dd62013-03-04 21:46:16 +00004037 }
Greg Claytond1767f02011-12-08 02:13:16 +00004038 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00004039 }
Greg Clayton5cf58b92011-10-05 22:22:08 +00004040 }
4041 else
4042 {
Greg Clayton9e9f2192013-05-17 00:55:28 +00004043 scope = eValueTypeVariableLocal;
Greg Clayton5cf58b92011-10-05 22:22:08 +00004044 }
Greg Clayton7f995132011-10-04 22:41:51 +00004045 }
Greg Clayton9e9f2192013-05-17 00:55:28 +00004046
4047 if (symbol_context_scope == NULL)
4048 {
4049 switch (parent_tag)
4050 {
4051 case DW_TAG_subprogram:
4052 case DW_TAG_inlined_subroutine:
4053 case DW_TAG_lexical_block:
4054 if (sc.function)
4055 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004056 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
Greg Clayton9e9f2192013-05-17 00:55:28 +00004057 if (symbol_context_scope == NULL)
4058 symbol_context_scope = sc.function;
4059 }
4060 break;
4061
4062 default:
4063 symbol_context_scope = sc.comp_unit;
4064 break;
4065 }
4066 }
4067
4068 if (symbol_context_scope)
4069 {
Enrico Granata4ec130d2014-08-11 19:16:35 +00004070 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid));
4071
4072 if (const_value.Form() && type_sp && type_sp->GetType())
Greg Clayton6071e6f2015-08-26 22:57:51 +00004073 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), die.GetCU()->GetAddressByteSize());
Enrico Granata4ec130d2014-08-11 19:16:35 +00004074
Greg Clayton6071e6f2015-08-26 22:57:51 +00004075 var_sp.reset (new Variable (die.GetID(),
Greg Clayton9e9f2192013-05-17 00:55:28 +00004076 name,
4077 mangled,
Enrico Granata4ec130d2014-08-11 19:16:35 +00004078 type_sp,
Greg Clayton9e9f2192013-05-17 00:55:28 +00004079 scope,
4080 symbol_context_scope,
4081 &decl,
4082 location,
4083 is_external,
Paul Herman10bc1a42015-08-18 22:46:57 +00004084 is_artificial,
4085 is_static_member));
Greg Clayton9e9f2192013-05-17 00:55:28 +00004086
4087 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
4088 }
4089 else
4090 {
4091 // Not ready to parse this variable yet. It might be a global
4092 // or static variable that is in a function scope and the function
4093 // in the symbol context wasn't filled in yet
4094 return var_sp;
4095 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004096 }
Greg Clayton7f995132011-10-04 22:41:51 +00004097 // Cache var_sp even if NULL (the variable was just a specification or
4098 // was missing vital information to be able to be displayed in the debugger
4099 // (missing location due to optimization, etc)) so we don't re-parse
4100 // this DIE over and over later...
Greg Clayton6071e6f2015-08-26 22:57:51 +00004101 m_die_to_variable_sp[die.GetDIE()] = var_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004102 }
4103 return var_sp;
4104}
4105
Greg Claytonc662ec82011-06-17 22:10:16 +00004106
Greg Clayton6071e6f2015-08-26 22:57:51 +00004107DWARFDIE
Greg Claytonc662ec82011-06-17 22:10:16 +00004108SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
Greg Clayton6071e6f2015-08-26 22:57:51 +00004109 dw_offset_t spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004110{
4111 // Give the concrete function die specified by "func_die_offset", find the
4112 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4113 // to "spec_block_die_offset"
Greg Clayton6071e6f2015-08-26 22:57:51 +00004114 return FindBlockContainingSpecification (DebugInfo()->GetDIE (func_die_offset), spec_block_die_offset);
Greg Claytonc662ec82011-06-17 22:10:16 +00004115}
4116
4117
Greg Clayton6071e6f2015-08-26 22:57:51 +00004118DWARFDIE
4119SymbolFileDWARF::FindBlockContainingSpecification(const DWARFDIE &die,
4120 dw_offset_t spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004121{
4122 if (die)
4123 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004124 switch (die.Tag())
Greg Claytonc662ec82011-06-17 22:10:16 +00004125 {
4126 case DW_TAG_subprogram:
4127 case DW_TAG_inlined_subroutine:
4128 case DW_TAG_lexical_block:
4129 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004130 if (die.GetAttributeValueAsReference (DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004131 return die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004132
Greg Clayton6071e6f2015-08-26 22:57:51 +00004133 if (die.GetAttributeValueAsReference (DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
Greg Claytonc662ec82011-06-17 22:10:16 +00004134 return die;
Greg Claytonc662ec82011-06-17 22:10:16 +00004135 }
4136 break;
4137 }
4138
4139 // Give the concrete function die specified by "func_die_offset", find the
4140 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4141 // to "spec_block_die_offset"
Greg Clayton6071e6f2015-08-26 22:57:51 +00004142 for (DWARFDIE child_die = die.GetFirstChild(); child_die; child_die = child_die.GetSibling())
Greg Claytonc662ec82011-06-17 22:10:16 +00004143 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004144 DWARFDIE result_die = FindBlockContainingSpecification (child_die, spec_block_die_offset);
Greg Claytonc662ec82011-06-17 22:10:16 +00004145 if (result_die)
4146 return result_die;
4147 }
4148 }
4149
Greg Clayton6071e6f2015-08-26 22:57:51 +00004150 return DWARFDIE();
Greg Claytonc662ec82011-06-17 22:10:16 +00004151}
4152
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004153size_t
Greg Clayton6071e6f2015-08-26 22:57:51 +00004154SymbolFileDWARF::ParseVariables (const SymbolContext& sc,
4155 const DWARFDIE &orig_die,
4156 const lldb::addr_t func_low_pc,
4157 bool parse_siblings,
4158 bool parse_children,
4159 VariableList* cc_variable_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004160{
Greg Clayton6071e6f2015-08-26 22:57:51 +00004161 if (!orig_die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004162 return 0;
4163
Greg Claytonc662ec82011-06-17 22:10:16 +00004164 VariableListSP variable_list_sp;
4165
4166 size_t vars_added = 0;
Greg Clayton6071e6f2015-08-26 22:57:51 +00004167 DWARFDIE die = orig_die;
4168 while (die)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004169 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004170 dw_tag_t tag = die.Tag();
Greg Claytonc662ec82011-06-17 22:10:16 +00004171
4172 // Check to see if we have already parsed this variable or constant?
Greg Clayton6071e6f2015-08-26 22:57:51 +00004173 VariableSP var_sp = m_die_to_variable_sp[die.GetDIE()];
4174 if (var_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004175 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004176 if (cc_variable_list)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004177 cc_variable_list->AddVariableIfUnique (var_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004178 }
4179 else
4180 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004181 // We haven't already parsed it, lets do that now.
4182 if ((tag == DW_TAG_variable) ||
4183 (tag == DW_TAG_constant) ||
4184 (tag == DW_TAG_formal_parameter && sc.function))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004185 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004186 if (variable_list_sp.get() == NULL)
Greg Clayton73bf5db2011-06-17 01:22:15 +00004187 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004188 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die);
4189 dw_tag_t parent_tag = sc_parent_die.Tag();
Greg Claytonc662ec82011-06-17 22:10:16 +00004190 switch (parent_tag)
4191 {
4192 case DW_TAG_compile_unit:
4193 if (sc.comp_unit != NULL)
4194 {
4195 variable_list_sp = sc.comp_unit->GetVariableList(false);
4196 if (variable_list_sp.get() == NULL)
4197 {
4198 variable_list_sp.reset(new VariableList());
4199 sc.comp_unit->SetVariableList(variable_list_sp);
4200 }
4201 }
4202 else
4203 {
Daniel Malead01b2952012-11-29 21:49:15 +00004204 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 +00004205 sc_parent_die.GetID(),
4206 sc_parent_die.GetTagAsCString(),
4207 orig_die.GetID(),
4208 orig_die.GetTagAsCString());
Greg Claytonc662ec82011-06-17 22:10:16 +00004209 }
4210 break;
4211
4212 case DW_TAG_subprogram:
4213 case DW_TAG_inlined_subroutine:
4214 case DW_TAG_lexical_block:
4215 if (sc.function != NULL)
4216 {
4217 // Check to see if we already have parsed the variables for the given scope
4218
Greg Clayton6071e6f2015-08-26 22:57:51 +00004219 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
Greg Claytonc662ec82011-06-17 22:10:16 +00004220 if (block == NULL)
4221 {
4222 // This must be a specification or abstract origin with
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +00004223 // a concrete block counterpart in the current function. We need
Greg Claytonc662ec82011-06-17 22:10:16 +00004224 // to find the concrete block so we can correctly add the
4225 // variable to it
Greg Clayton6071e6f2015-08-26 22:57:51 +00004226 const DWARFDIE concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
4227 sc_parent_die.GetOffset());
Greg Claytonc662ec82011-06-17 22:10:16 +00004228 if (concrete_block_die)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004229 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die.GetID());
Greg Claytonc662ec82011-06-17 22:10:16 +00004230 }
4231
4232 if (block != NULL)
4233 {
4234 const bool can_create = false;
4235 variable_list_sp = block->GetBlockVariableList (can_create);
4236 if (variable_list_sp.get() == NULL)
4237 {
4238 variable_list_sp.reset(new VariableList());
4239 block->SetVariableList(variable_list_sp);
4240 }
4241 }
4242 }
4243 break;
4244
4245 default:
Daniel Malead01b2952012-11-29 21:49:15 +00004246 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 +00004247 orig_die.GetID(),
4248 orig_die.GetTagAsCString());
Greg Claytonc662ec82011-06-17 22:10:16 +00004249 break;
4250 }
Greg Clayton73bf5db2011-06-17 01:22:15 +00004251 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004252
4253 if (variable_list_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004254 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004255 VariableSP var_sp (ParseVariableDIE(sc, die, func_low_pc));
Greg Clayton73bf5db2011-06-17 01:22:15 +00004256 if (var_sp)
4257 {
Greg Claytonc662ec82011-06-17 22:10:16 +00004258 variable_list_sp->AddVariableIfUnique (var_sp);
Greg Clayton73bf5db2011-06-17 01:22:15 +00004259 if (cc_variable_list)
4260 cc_variable_list->AddVariableIfUnique (var_sp);
4261 ++vars_added;
4262 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004263 }
4264 }
4265 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004266
4267 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4268
Greg Clayton6071e6f2015-08-26 22:57:51 +00004269 if (!skip_children && parse_children && die.HasChildren())
Greg Claytonc662ec82011-06-17 22:10:16 +00004270 {
Greg Clayton6071e6f2015-08-26 22:57:51 +00004271 vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, true, cc_variable_list);
Greg Claytonc662ec82011-06-17 22:10:16 +00004272 }
4273
4274 if (parse_siblings)
Greg Clayton6071e6f2015-08-26 22:57:51 +00004275 die = die.GetSibling();
Greg Claytonc662ec82011-06-17 22:10:16 +00004276 else
Greg Clayton6071e6f2015-08-26 22:57:51 +00004277 die.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004278 }
Greg Claytonc662ec82011-06-17 22:10:16 +00004279 return vars_added;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004280}
4281
4282//------------------------------------------------------------------
4283// PluginInterface protocol
4284//------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +00004285ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004286SymbolFileDWARF::GetPluginName()
4287{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00004288 return GetPluginNameStatic();
4289}
4290
4291uint32_t
4292SymbolFileDWARF::GetPluginVersion()
4293{
4294 return 1;
4295}
4296
4297void
Sean Callanancc427fa2011-07-30 02:42:06 +00004298SymbolFileDWARF::DumpIndexes ()
4299{
4300 StreamFile s(stdout, false);
4301
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004302 s.Printf ("DWARF index for (%s) '%s':",
Sean Callanancc427fa2011-07-30 02:42:06 +00004303 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00004304 GetObjectFile()->GetFileSpec().GetPath().c_str());
Sean Callanancc427fa2011-07-30 02:42:06 +00004305 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4306 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4307 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4308 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4309 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4310 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4311 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
Bruce Mitchenere171da52015-07-22 00:16:02 +00004312 s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
Sean Callanancc427fa2011-07-30 02:42:06 +00004313}
4314
Greg Claytoncaab74e2012-01-28 00:48:57 +00004315
Greg Clayton1f746072012-08-29 21:13:06 +00004316SymbolFileDWARFDebugMap *
4317SymbolFileDWARF::GetDebugMapSymfile ()
4318{
4319 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
4320 {
4321 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
4322 if (module_sp)
4323 {
4324 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
4325 if (sym_vendor)
4326 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
4327 }
4328 }
4329 return m_debug_map_symfile;
4330}
4331
Greg Claytoncaab74e2012-01-28 00:48:57 +00004332