| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #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 Clayton | 7fedea2 | 2010-11-16 02:10:54 +0000 | [diff] [blame] | 25 | #include "clang/Sema/DeclSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Casting.h" |
| 28 | |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 29 | #include "lldb/Core/ArchSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/Module.h" |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ModuleList.h" |
| 32 | #include "lldb/Core/ModuleSpec.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Core/PluginManager.h" |
| 34 | #include "lldb/Core/RegularExpression.h" |
| 35 | #include "lldb/Core/Scalar.h" |
| 36 | #include "lldb/Core/Section.h" |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 37 | #include "lldb/Core/StreamFile.h" |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 38 | #include "lldb/Core/StreamString.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Core/Timer.h" |
| 40 | #include "lldb/Core/Value.h" |
| 41 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 42 | #include "lldb/Expression/ClangModulesDeclVendor.h" |
| 43 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 44 | #include "lldb/Host/FileSystem.h" |
| Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 45 | #include "lldb/Host/Host.h" |
| 46 | |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 47 | #include "lldb/Interpreter/OptionValueFileSpecList.h" |
| 48 | #include "lldb/Interpreter/OptionValueProperties.h" |
| 49 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #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 Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 57 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 58 | #include "lldb/Target/CPPLanguageRuntime.h" |
| Jim Ingham | b7f6b2f | 2011-09-08 22:13:49 +0000 | [diff] [blame] | 59 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | #include "DWARFCompileUnit.h" |
| 61 | #include "DWARFDebugAbbrev.h" |
| 62 | #include "DWARFDebugAranges.h" |
| 63 | #include "DWARFDebugInfo.h" |
| 64 | #include "DWARFDebugInfoEntry.h" |
| 65 | #include "DWARFDebugLine.h" |
| 66 | #include "DWARFDebugPubnames.h" |
| 67 | #include "DWARFDebugRanges.h" |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 68 | #include "DWARFDeclContext.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | #include "DWARFDIECollection.h" |
| 70 | #include "DWARFFormValue.h" |
| 71 | #include "DWARFLocationList.h" |
| 72 | #include "LogChannelDWARF.h" |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 73 | #include "SymbolFileDWARFDebugMap.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | |
| 75 | #include <map> |
| 76 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 77 | #include <ctype.h> |
| 78 | #include <string.h> |
| 79 | |
| Greg Clayton | 62742b1 | 2010-11-11 01:09:45 +0000 | [diff] [blame] | 80 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 81 | |
| 82 | #ifdef ENABLE_DEBUG_PRINTF |
| 83 | #include <stdio.h> |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 84 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) |
| Greg Clayton | c93237c | 2010-10-01 20:48:32 +0000 | [diff] [blame] | 85 | #else |
| 86 | #define DEBUG_PRINTF(fmt, ...) |
| 87 | #endif |
| 88 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | using namespace lldb; |
| 90 | using namespace lldb_private; |
| 91 | |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 92 | //static inline bool |
| 93 | //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) |
| 94 | //{ |
| 95 | // switch (tag) |
| 96 | // { |
| 97 | // default: |
| 98 | // break; |
| 99 | // case DW_TAG_subprogram: |
| 100 | // case DW_TAG_inlined_subroutine: |
| 101 | // case DW_TAG_class_type: |
| 102 | // case DW_TAG_structure_type: |
| 103 | // case DW_TAG_union_type: |
| 104 | // return true; |
| 105 | // } |
| 106 | // return false; |
| 107 | //} |
| 108 | // |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 109 | |
| 110 | namespace { |
| 111 | |
| 112 | PropertyDefinition |
| 113 | g_properties[] = |
| 114 | { |
| 115 | { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." }, |
| 116 | { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr } |
| 117 | }; |
| 118 | |
| 119 | enum |
| 120 | { |
| 121 | ePropertySymLinkPaths |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | class PluginProperties : public Properties |
| 126 | { |
| 127 | public: |
| 128 | static ConstString |
| 129 | GetSettingName() |
| 130 | { |
| 131 | return SymbolFileDWARF::GetPluginNameStatic(); |
| 132 | } |
| 133 | |
| 134 | PluginProperties() |
| 135 | { |
| 136 | m_collection_sp.reset (new OptionValueProperties(GetSettingName())); |
| 137 | m_collection_sp->Initialize(g_properties); |
| 138 | } |
| 139 | |
| 140 | FileSpecList& |
| 141 | GetSymLinkPaths() |
| 142 | { |
| 143 | OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths); |
| 144 | assert(option_value); |
| 145 | return option_value->GetCurrentValue(); |
| 146 | } |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP; |
| 151 | |
| 152 | static const SymbolFileDWARFPropertiesSP& |
| 153 | GetGlobalPluginProperties() |
| 154 | { |
| 155 | static const auto g_settings_sp(std::make_shared<PluginProperties>()); |
| 156 | return g_settings_sp; |
| 157 | } |
| 158 | |
| 159 | } // anonymous namespace end |
| 160 | |
| 161 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 162 | static const char* |
| 163 | removeHostnameFromPathname(const char* path_from_dwarf) |
| 164 | { |
| 165 | if (!path_from_dwarf || !path_from_dwarf[0]) |
| 166 | { |
| 167 | return path_from_dwarf; |
| 168 | } |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 169 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 170 | const char *colon_pos = strchr(path_from_dwarf, ':'); |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 171 | if (nullptr == colon_pos) |
| 172 | { |
| 173 | return path_from_dwarf; |
| 174 | } |
| 175 | |
| 176 | const char *slash_pos = strchr(path_from_dwarf, '/'); |
| 177 | if (slash_pos && (slash_pos < colon_pos)) |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 178 | { |
| 179 | return path_from_dwarf; |
| 180 | } |
| 181 | |
| 182 | // check whether we have a windows path, and so the first character |
| 183 | // is a drive-letter not a hostname. |
| 184 | if ( |
| 185 | colon_pos == path_from_dwarf + 1 && |
| 186 | isalpha(*path_from_dwarf) && |
| 187 | strlen(path_from_dwarf) > 2 && |
| 188 | '\\' == path_from_dwarf[2]) |
| 189 | { |
| 190 | return path_from_dwarf; |
| 191 | } |
| Enrico Granata | 99e5e22 | 2015-07-27 21:27:02 +0000 | [diff] [blame] | 192 | |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 193 | return colon_pos + 1; |
| 194 | } |
| 195 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 196 | static const char* |
| 197 | resolveCompDir(const char* path_from_dwarf) |
| 198 | { |
| 199 | if (!path_from_dwarf) |
| 200 | return nullptr; |
| 201 | |
| 202 | // DWARF2/3 suggests the form hostname:pathname for compilation directory. |
| 203 | // Remove the host part if present. |
| 204 | const char* local_path = removeHostnameFromPathname(path_from_dwarf); |
| 205 | if (!local_path) |
| 206 | return nullptr; |
| 207 | |
| 208 | bool is_symlink = false; |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 209 | FileSpec local_path_spec(local_path, false); |
| 210 | const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths(); |
| 211 | for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i) |
| 212 | is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true); |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 213 | |
| 214 | if (!is_symlink) |
| 215 | return local_path; |
| 216 | |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 217 | if (!local_path_spec.IsSymbolicLink()) |
| 218 | return local_path; |
| 219 | |
| 220 | FileSpec resolved_local_path_spec; |
| 221 | const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec); |
| 222 | if (error.Success()) |
| 223 | return resolved_local_path_spec.GetCString(); |
| 224 | |
| 225 | return nullptr; |
| 226 | } |
| 227 | |
| 228 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | void |
| 230 | SymbolFileDWARF::Initialize() |
| 231 | { |
| 232 | LogChannelDWARF::Initialize(); |
| 233 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 234 | GetPluginDescriptionStatic(), |
| Oleksiy Vyalov | abb5a35 | 2015-07-29 22:18:16 +0000 | [diff] [blame] | 235 | CreateInstance, |
| 236 | DebuggerInitialize); |
| 237 | } |
| 238 | |
| 239 | void |
| 240 | SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) |
| 241 | { |
| 242 | if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName())) |
| 243 | { |
| 244 | const bool is_global_setting = true; |
| 245 | PluginManager::CreateSettingForSymbolFilePlugin(debugger, |
| 246 | GetGlobalPluginProperties()->GetValueProperties(), |
| 247 | ConstString ("Properties for the dwarf symbol-file plug-in."), |
| 248 | is_global_setting); |
| 249 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void |
| 253 | SymbolFileDWARF::Terminate() |
| 254 | { |
| 255 | PluginManager::UnregisterPlugin (CreateInstance); |
| 256 | LogChannelDWARF::Initialize(); |
| 257 | } |
| 258 | |
| 259 | |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 260 | lldb_private::ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | SymbolFileDWARF::GetPluginNameStatic() |
| 262 | { |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 263 | static ConstString g_name("dwarf"); |
| 264 | return g_name; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | const char * |
| 268 | SymbolFileDWARF::GetPluginDescriptionStatic() |
| 269 | { |
| 270 | return "DWARF and DWARF3 debug symbol file reader."; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | SymbolFile* |
| 275 | SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) |
| 276 | { |
| 277 | return new SymbolFileDWARF(obj_file); |
| 278 | } |
| 279 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 280 | TypeList * |
| 281 | SymbolFileDWARF::GetTypeList () |
| 282 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 283 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 284 | return m_debug_map_symfile->GetTypeList(); |
| 285 | return m_obj_file->GetModule()->GetTypeList(); |
| 286 | |
| 287 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 288 | void |
| 289 | SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, |
| 290 | const DWARFDebugInfoEntry *die, |
| 291 | dw_offset_t min_die_offset, |
| 292 | dw_offset_t max_die_offset, |
| 293 | uint32_t type_mask, |
| 294 | TypeSet &type_set) |
| 295 | { |
| 296 | if (cu) |
| 297 | { |
| 298 | if (die) |
| 299 | { |
| 300 | const dw_offset_t die_offset = die->GetOffset(); |
| 301 | |
| 302 | if (die_offset >= max_die_offset) |
| 303 | return; |
| 304 | |
| 305 | if (die_offset >= min_die_offset) |
| 306 | { |
| 307 | const dw_tag_t tag = die->Tag(); |
| 308 | |
| 309 | bool add_type = false; |
| 310 | |
| 311 | switch (tag) |
| 312 | { |
| 313 | case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; |
| 314 | case DW_TAG_unspecified_type: |
| 315 | case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; |
| 316 | case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; |
| 317 | case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; |
| 318 | case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; |
| 319 | case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; |
| 320 | case DW_TAG_subroutine_type: |
| 321 | case DW_TAG_subprogram: |
| 322 | case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; |
| 323 | case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; |
| 324 | case DW_TAG_rvalue_reference_type: |
| 325 | case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; |
| 326 | case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; |
| 327 | case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; |
| 328 | } |
| 329 | |
| 330 | if (add_type) |
| 331 | { |
| 332 | const bool assert_not_being_parsed = true; |
| 333 | Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); |
| 334 | if (type) |
| 335 | { |
| 336 | if (type_set.find(type) == type_set.end()) |
| 337 | type_set.insert(type); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); |
| 343 | child_die != NULL; |
| 344 | child_die = child_die->GetSibling()) |
| 345 | { |
| 346 | GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | size_t |
| 353 | SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, |
| 354 | uint32_t type_mask, |
| 355 | TypeList &type_list) |
| 356 | |
| 357 | { |
| 358 | TypeSet type_set; |
| 359 | |
| 360 | CompileUnit *comp_unit = NULL; |
| 361 | DWARFCompileUnit* dwarf_cu = NULL; |
| 362 | if (sc_scope) |
| 363 | comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); |
| 364 | |
| 365 | if (comp_unit) |
| 366 | { |
| 367 | dwarf_cu = GetDWARFCompileUnit(comp_unit); |
| 368 | if (dwarf_cu == 0) |
| 369 | return 0; |
| 370 | GetTypes (dwarf_cu, |
| 371 | dwarf_cu->DIE(), |
| 372 | dwarf_cu->GetOffset(), |
| 373 | dwarf_cu->GetNextCompileUnitOffset(), |
| 374 | type_mask, |
| 375 | type_set); |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | DWARFDebugInfo* info = DebugInfo(); |
| 380 | if (info) |
| 381 | { |
| 382 | const size_t num_cus = info->GetNumCompileUnits(); |
| 383 | for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) |
| 384 | { |
| 385 | dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 386 | if (dwarf_cu) |
| 387 | { |
| 388 | GetTypes (dwarf_cu, |
| 389 | dwarf_cu->DIE(), |
| 390 | 0, |
| 391 | UINT32_MAX, |
| 392 | type_mask, |
| 393 | type_set); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | // if (m_using_apple_tables) |
| 399 | // { |
| 400 | // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); |
| 401 | // if (apple_types) |
| 402 | // { |
| 403 | // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { |
| 404 | // |
| 405 | // for (auto die_info: die_info_array) |
| 406 | // { |
| 407 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 408 | // if (!add_type) |
| 409 | // { |
| 410 | // dw_tag_t tag = die_info.tag; |
| 411 | // if (tag == 0) |
| 412 | // { |
| 413 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); |
| 414 | // tag = die->Tag(); |
| 415 | // } |
| 416 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 417 | // } |
| 418 | // if (add_type) |
| 419 | // { |
| 420 | // Type *type = ResolveTypeUID(die_info.offset); |
| 421 | // |
| 422 | // if (type_set.find(type) == type_set.end()) |
| 423 | // type_set.insert(type); |
| 424 | // } |
| 425 | // } |
| 426 | // return true; // Keep iterating |
| 427 | // }); |
| 428 | // } |
| 429 | // } |
| 430 | // else |
| 431 | // { |
| 432 | // if (!m_indexed) |
| 433 | // Index (); |
| 434 | // |
| 435 | // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { |
| 436 | // |
| 437 | // bool add_type = TagMatchesTypeMask (type_mask, 0); |
| 438 | // |
| 439 | // if (!add_type) |
| 440 | // { |
| 441 | // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); |
| 442 | // if (die) |
| 443 | // { |
| 444 | // const dw_tag_t tag = die->Tag(); |
| 445 | // add_type = TagMatchesTypeMask (type_mask, tag); |
| 446 | // } |
| 447 | // } |
| 448 | // |
| 449 | // if (add_type) |
| 450 | // { |
| 451 | // Type *type = ResolveTypeUID(die_offset); |
| 452 | // |
| 453 | // if (type_set.find(type) == type_set.end()) |
| 454 | // type_set.insert(type); |
| 455 | // } |
| 456 | // return true; // Keep iterating |
| 457 | // }); |
| 458 | // } |
| 459 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 460 | std::set<CompilerType> clang_type_set; |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 461 | size_t num_types_added = 0; |
| 462 | for (Type *type : type_set) |
| 463 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 464 | CompilerType clang_type = type->GetForwardCompilerType (); |
| Greg Clayton | 0fc4f31 | 2013-06-20 01:23:18 +0000 | [diff] [blame] | 465 | if (clang_type_set.find(clang_type) == clang_type_set.end()) |
| 466 | { |
| 467 | clang_type_set.insert(clang_type); |
| 468 | type_list.Insert (type->shared_from_this()); |
| 469 | ++num_types_added; |
| 470 | } |
| Greg Clayton | f02500c | 2013-06-18 22:51:05 +0000 | [diff] [blame] | 471 | } |
| 472 | return num_types_added; |
| 473 | } |
| 474 | |
| Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 475 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | //---------------------------------------------------------------------- |
| 477 | // Gets the first parent that is a lexical block, function or inlined |
| 478 | // subroutine, or compile unit. |
| 479 | //---------------------------------------------------------------------- |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 480 | const DWARFDebugInfoEntry * |
| 481 | SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 482 | { |
| 483 | const DWARFDebugInfoEntry *die; |
| 484 | for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) |
| 485 | { |
| 486 | dw_tag_t tag = die->Tag(); |
| 487 | |
| 488 | switch (tag) |
| 489 | { |
| 490 | case DW_TAG_compile_unit: |
| 491 | case DW_TAG_subprogram: |
| 492 | case DW_TAG_inlined_subroutine: |
| 493 | case DW_TAG_lexical_block: |
| 494 | return die; |
| 495 | } |
| 496 | } |
| 497 | return NULL; |
| 498 | } |
| 499 | |
| 500 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 501 | SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : |
| 502 | SymbolFile (objfile), |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 503 | UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 504 | m_debug_map_module_wp (), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 505 | m_debug_map_symfile (NULL), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | m_flags(), |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 507 | m_data_debug_abbrev (), |
| 508 | m_data_debug_aranges (), |
| 509 | m_data_debug_frame (), |
| 510 | m_data_debug_info (), |
| 511 | m_data_debug_line (), |
| 512 | m_data_debug_loc (), |
| 513 | m_data_debug_ranges (), |
| 514 | m_data_debug_str (), |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 515 | m_data_apple_names (), |
| 516 | m_data_apple_types (), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 517 | m_data_apple_namespaces (), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 518 | m_abbr(), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 519 | m_info(), |
| 520 | m_line(), |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 521 | m_apple_names_ap (), |
| 522 | m_apple_types_ap (), |
| 523 | m_apple_namespaces_ap (), |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 524 | m_apple_objc_ap (), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 525 | m_function_basename_index(), |
| 526 | m_function_fullname_index(), |
| 527 | m_function_method_index(), |
| 528 | m_function_selector_index(), |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 529 | m_objc_class_selectors_index(), |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 530 | m_global_index(), |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 531 | m_type_index(), |
| 532 | m_namespace_index(), |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 533 | m_indexed (false), |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 534 | m_using_apple_tables (false), |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 535 | m_fetched_external_modules (false), |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 536 | m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), |
| Greg Clayton | 1c9e5ac | 2011-02-09 19:06:17 +0000 | [diff] [blame] | 537 | m_ranges(), |
| 538 | m_unique_ast_type_map () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 539 | { |
| 540 | } |
| 541 | |
| 542 | SymbolFileDWARF::~SymbolFileDWARF() |
| 543 | { |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static const ConstString & |
| 547 | GetDWARFMachOSegmentName () |
| 548 | { |
| 549 | static ConstString g_dwarf_section_name ("__DWARF"); |
| 550 | return g_dwarf_section_name; |
| 551 | } |
| 552 | |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 553 | UniqueDWARFASTTypeMap & |
| 554 | SymbolFileDWARF::GetUniqueDWARFASTTypeMap () |
| 555 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 556 | if (GetDebugMapSymfile ()) |
| Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 557 | return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); |
| 558 | return m_unique_ast_type_map; |
| 559 | } |
| 560 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 561 | ClangASTContext & |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 562 | SymbolFileDWARF::GetClangASTContext () |
| 563 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 564 | if (GetDebugMapSymfile ()) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 565 | return m_debug_map_symfile->GetClangASTContext (); |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 566 | else |
| 567 | return m_obj_file->GetModule()->GetClangASTContext(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 570 | TypeSystem * |
| 571 | SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language) |
| 572 | { |
| 573 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 574 | if (debug_map_symfile) |
| 575 | return debug_map_symfile->GetTypeSystemForLanguage (language); |
| 576 | else |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 577 | return m_obj_file->GetModule()->GetTypeSystemForLanguage (language); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 580 | void |
| 581 | SymbolFileDWARF::InitializeObject() |
| 582 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 583 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 584 | if (module_sp) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 585 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 586 | const SectionList *section_list = module_sp->GetSectionList(); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 587 | |
| 588 | const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| 589 | |
| 590 | // Memory map the DWARF mach-o segment so we have everything mmap'ed |
| 591 | // to keep our heap memory usage down. |
| 592 | if (section) |
| Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 593 | m_obj_file->MemoryMapSectionData(section, m_dwarf_data); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 594 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 595 | get_apple_names_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 596 | if (m_data_apple_names.GetByteSize() > 0) |
| 597 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 598 | m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); |
| 599 | if (m_apple_names_ap->IsValid()) |
| 600 | m_using_apple_tables = true; |
| 601 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 602 | m_apple_names_ap.reset(); |
| 603 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 604 | get_apple_types_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 605 | if (m_data_apple_types.GetByteSize() > 0) |
| 606 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 607 | m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); |
| 608 | if (m_apple_types_ap->IsValid()) |
| 609 | m_using_apple_tables = true; |
| 610 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 611 | m_apple_types_ap.reset(); |
| 612 | } |
| 613 | |
| 614 | get_apple_namespaces_data(); |
| 615 | if (m_data_apple_namespaces.GetByteSize() > 0) |
| 616 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 617 | m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); |
| 618 | if (m_apple_namespaces_ap->IsValid()) |
| 619 | m_using_apple_tables = true; |
| 620 | else |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 621 | m_apple_namespaces_ap.reset(); |
| 622 | } |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 623 | |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 624 | get_apple_objc_data(); |
| 625 | if (m_data_apple_objc.GetByteSize() > 0) |
| 626 | { |
| 627 | m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); |
| 628 | if (m_apple_objc_ap->IsValid()) |
| 629 | m_using_apple_tables = true; |
| 630 | else |
| 631 | m_apple_objc_ap.reset(); |
| 632 | } |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 633 | |
| 634 | // Set the symbol file to this file if we don't have a debug map symbol |
| 635 | // file as our main symbol file. This allows the clang ASTContext to complete |
| 636 | // types using this symbol file when it needs to complete classes and structures. |
| 637 | if (GetDebugMapSymfile () == nullptr) |
| 638 | GetClangASTContext().SetSymbolFile(this); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | bool |
| 642 | SymbolFileDWARF::SupportedVersion(uint16_t version) |
| 643 | { |
| Greg Clayton | abcbfe5 | 2013-04-04 00:00:36 +0000 | [diff] [blame] | 644 | return version == 2 || version == 3 || version == 4; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | uint32_t |
| Sean Callanan | bfaf54d | 2011-12-03 04:38:43 +0000 | [diff] [blame] | 648 | SymbolFileDWARF::CalculateAbilities () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | { |
| 650 | uint32_t abilities = 0; |
| 651 | if (m_obj_file != NULL) |
| 652 | { |
| 653 | const Section* section = NULL; |
| 654 | const SectionList *section_list = m_obj_file->GetSectionList(); |
| 655 | if (section_list == NULL) |
| 656 | return 0; |
| 657 | |
| 658 | uint64_t debug_abbrev_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | uint64_t debug_info_file_size = 0; |
| 660 | uint64_t debug_line_file_size = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 661 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 662 | section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | |
| 664 | if (section) |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 665 | section_list = §ion->GetChildren (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 667 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 668 | if (section != NULL) |
| 669 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 670 | debug_info_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 672 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 673 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 674 | debug_abbrev_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | else |
| 676 | m_flags.Set (flagsGotDebugAbbrevData); |
| 677 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 678 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 679 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | m_flags.Set (flagsGotDebugArangesData); |
| 681 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 682 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 683 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 684 | m_flags.Set (flagsGotDebugFrameData); |
| 685 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 686 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | if (section) |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 688 | debug_line_file_size = section->GetFileSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 689 | else |
| 690 | m_flags.Set (flagsGotDebugLineData); |
| 691 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 692 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 693 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | m_flags.Set (flagsGotDebugLocData); |
| 695 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 696 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 697 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | m_flags.Set (flagsGotDebugMacInfoData); |
| 699 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 700 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 701 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 702 | m_flags.Set (flagsGotDebugPubNamesData); |
| 703 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 704 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 705 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 706 | m_flags.Set (flagsGotDebugPubTypesData); |
| 707 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 708 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 709 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | m_flags.Set (flagsGotDebugRangesData); |
| 711 | |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 712 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 713 | if (!section) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | m_flags.Set (flagsGotDebugStrData); |
| 715 | } |
| Greg Clayton | 6c59661 | 2012-05-18 21:47:20 +0000 | [diff] [blame] | 716 | else |
| 717 | { |
| 718 | const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); |
| 719 | if (symfile_dir_cstr) |
| 720 | { |
| 721 | if (strcasestr(symfile_dir_cstr, ".dsym")) |
| 722 | { |
| 723 | if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) |
| 724 | { |
| 725 | // We have a dSYM file that didn't have a any debug info. |
| 726 | // If the string table has a size of 1, then it was made from |
| 727 | // an executable with no debug info, or from an executable that |
| 728 | // was stripped. |
| 729 | section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); |
| 730 | if (section && section->GetFileSize() == 1) |
| 731 | { |
| 732 | m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | |
| 739 | if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) |
| 740 | abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; |
| 741 | |
| 742 | if (debug_line_file_size > 0) |
| 743 | abilities |= LineTables; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | } |
| 745 | return abilities; |
| 746 | } |
| 747 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 748 | const DWARFDataExtractor& |
| 749 | SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | { |
| 751 | if (m_flags.IsClear (got_flag)) |
| 752 | { |
| Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 753 | ModuleSP module_sp (m_obj_file->GetModule()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | m_flags.Set (got_flag); |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 755 | const SectionList *section_list = module_sp->GetSectionList(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 756 | if (section_list) |
| 757 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 758 | SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); |
| 759 | if (section_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 760 | { |
| 761 | // See if we memory mapped the DWARF segment? |
| 762 | if (m_dwarf_data.GetByteSize()) |
| 763 | { |
| Greg Clayton | 47037bc | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 764 | data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | } |
| 766 | else |
| 767 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 768 | if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | data.Clear(); |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | return data; |
| 775 | } |
| 776 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 777 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | SymbolFileDWARF::get_debug_abbrev_data() |
| 779 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 780 | return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 783 | const DWARFDataExtractor& |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 784 | SymbolFileDWARF::get_debug_aranges_data() |
| 785 | { |
| 786 | return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); |
| 787 | } |
| 788 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 789 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | SymbolFileDWARF::get_debug_frame_data() |
| 791 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 792 | return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 795 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | SymbolFileDWARF::get_debug_info_data() |
| 797 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 798 | return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 801 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 802 | SymbolFileDWARF::get_debug_line_data() |
| 803 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 804 | return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 807 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 808 | SymbolFileDWARF::get_debug_loc_data() |
| 809 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 810 | return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 813 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | SymbolFileDWARF::get_debug_ranges_data() |
| 815 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 816 | return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 819 | const DWARFDataExtractor& |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 820 | SymbolFileDWARF::get_debug_str_data() |
| 821 | { |
| Greg Clayton | 4ceb998 | 2010-07-21 22:54:26 +0000 | [diff] [blame] | 822 | return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 825 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 826 | SymbolFileDWARF::get_apple_names_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 827 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 828 | return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 831 | const DWARFDataExtractor& |
| Greg Clayton | 1767440 | 2011-09-28 17:06:40 +0000 | [diff] [blame] | 832 | SymbolFileDWARF::get_apple_types_data() |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 833 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 834 | return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); |
| Greg Clayton | f9eec20 | 2011-09-01 23:16:13 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 837 | const DWARFDataExtractor& |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 838 | SymbolFileDWARF::get_apple_namespaces_data() |
| 839 | { |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 840 | return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); |
| 841 | } |
| 842 | |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 843 | const DWARFDataExtractor& |
| Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 844 | SymbolFileDWARF::get_apple_objc_data() |
| 845 | { |
| 846 | return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 849 | |
| 850 | DWARFDebugAbbrev* |
| 851 | SymbolFileDWARF::DebugAbbrev() |
| 852 | { |
| 853 | if (m_abbr.get() == NULL) |
| 854 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 855 | const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 856 | if (debug_abbrev_data.GetByteSize() > 0) |
| 857 | { |
| 858 | m_abbr.reset(new DWARFDebugAbbrev()); |
| 859 | if (m_abbr.get()) |
| 860 | m_abbr->Parse(debug_abbrev_data); |
| 861 | } |
| 862 | } |
| 863 | return m_abbr.get(); |
| 864 | } |
| 865 | |
| 866 | const DWARFDebugAbbrev* |
| 867 | SymbolFileDWARF::DebugAbbrev() const |
| 868 | { |
| 869 | return m_abbr.get(); |
| 870 | } |
| 871 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 | |
| 873 | DWARFDebugInfo* |
| 874 | SymbolFileDWARF::DebugInfo() |
| 875 | { |
| 876 | if (m_info.get() == NULL) |
| 877 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 878 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 879 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | if (get_debug_info_data().GetByteSize() > 0) |
| 881 | { |
| 882 | m_info.reset(new DWARFDebugInfo()); |
| 883 | if (m_info.get()) |
| 884 | { |
| 885 | m_info->SetDwarfData(this); |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | return m_info.get(); |
| 890 | } |
| 891 | |
| 892 | const DWARFDebugInfo* |
| 893 | SymbolFileDWARF::DebugInfo() const |
| 894 | { |
| 895 | return m_info.get(); |
| 896 | } |
| 897 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 898 | DWARFCompileUnit* |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 899 | SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | { |
| 901 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 902 | if (info) |
| 903 | { |
| 904 | if (GetDebugMapSymfile ()) |
| 905 | { |
| 906 | // The debug map symbol file made the compile units for this DWARF |
| 907 | // file which is .o file with DWARF in it, and we should have |
| 908 | // only 1 compile unit which is at offset zero in the DWARF. |
| 909 | // TODO: modify to support LTO .o files where each .o file might |
| 910 | // have multiple DW_TAG_compile_unit tags. |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 911 | |
| 912 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get(); |
| 913 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 914 | dwarf_cu->SetUserData(comp_unit); |
| 915 | return dwarf_cu; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 916 | } |
| 917 | else |
| 918 | { |
| 919 | // Just a normal DWARF file whose user ID for the compile unit is |
| 920 | // the DWARF offset itself |
| Greg Clayton | 68c00bd | 2015-02-05 02:10:29 +0000 | [diff] [blame] | 921 | |
| 922 | DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); |
| 923 | if (dwarf_cu && dwarf_cu->GetUserData() == NULL) |
| 924 | dwarf_cu->SetUserData(comp_unit); |
| 925 | return dwarf_cu; |
| 926 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 927 | } |
| 928 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 929 | return NULL; |
| 930 | } |
| 931 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 932 | |
| 933 | DWARFDebugRanges* |
| 934 | SymbolFileDWARF::DebugRanges() |
| 935 | { |
| 936 | if (m_ranges.get() == NULL) |
| 937 | { |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 938 | Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", |
| 939 | __PRETTY_FUNCTION__, static_cast<void*>(this)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | if (get_debug_ranges_data().GetByteSize() > 0) |
| 941 | { |
| 942 | m_ranges.reset(new DWARFDebugRanges()); |
| 943 | if (m_ranges.get()) |
| 944 | m_ranges->Extract(this); |
| 945 | } |
| 946 | } |
| 947 | return m_ranges.get(); |
| 948 | } |
| 949 | |
| 950 | const DWARFDebugRanges* |
| 951 | SymbolFileDWARF::DebugRanges() const |
| 952 | { |
| 953 | return m_ranges.get(); |
| 954 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 955 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 956 | lldb::CompUnitSP |
| 957 | SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 958 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 959 | CompUnitSP cu_sp; |
| 960 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 961 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 962 | CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); |
| 963 | if (comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 964 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 965 | // We already parsed this compile unit, had out a shared pointer to it |
| 966 | cu_sp = comp_unit->shared_from_this(); |
| 967 | } |
| 968 | else |
| 969 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 970 | if (GetDebugMapSymfile ()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 971 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 972 | // Let the debug map create the compile unit |
| 973 | cu_sp = m_debug_map_symfile->GetCompileUnit(this); |
| 974 | dwarf_cu->SetUserData(cu_sp.get()); |
| 975 | } |
| 976 | else |
| 977 | { |
| 978 | ModuleSP module_sp (m_obj_file->GetModule()); |
| 979 | if (module_sp) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 980 | { |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 981 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); |
| 982 | if (cu_die) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 983 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 984 | FileSpec cu_file_spec{cu_die->GetName(this, dwarf_cu), false}; |
| 985 | if (cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 986 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 987 | // If we have a full path to the compile unit, we don't need to resolve |
| 988 | // the file. This can be expensive e.g. when the source files are NFS mounted. |
| Chaoren Lin | 372e906 | 2015-06-09 17:54:27 +0000 | [diff] [blame] | 989 | if (cu_file_spec.IsRelative()) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 990 | { |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 991 | const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)}; |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 992 | cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir)); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 995 | std::string remapped_file; |
| 996 | if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file)) |
| 997 | cu_file_spec.SetFile(remapped_file, false); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 998 | } |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 999 | |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1000 | LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0)); |
| Chaoren Lin | 0c5a9c1 | 2015-06-05 00:28:06 +0000 | [diff] [blame] | 1001 | |
| Jason Molenda | c709958 | 2015-07-31 05:47:00 +0000 | [diff] [blame] | 1002 | bool is_optimized = dwarf_cu->GetIsOptimized (); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1003 | cu_sp.reset(new CompileUnit (module_sp, |
| 1004 | dwarf_cu, |
| 1005 | cu_file_spec, |
| 1006 | MakeUserID(dwarf_cu->GetOffset()), |
| Jason Molenda | 6ab659a | 2015-07-29 00:42:47 +0000 | [diff] [blame] | 1007 | cu_language, |
| 1008 | is_optimized)); |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1009 | if (cu_sp) |
| 1010 | { |
| 1011 | // If we just created a compile unit with an invalid file spec, try and get the |
| 1012 | // first entry in the supports files from the line table as that should be the |
| 1013 | // compile unit. |
| 1014 | if (!cu_file_spec) |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1015 | { |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1016 | cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1); |
| 1017 | if (cu_file_spec) |
| 1018 | { |
| 1019 | (FileSpec &)(*cu_sp) = cu_file_spec; |
| 1020 | // Also fix the invalid file spec which was copied from the compile unit. |
| 1021 | cu_sp->GetSupportFiles().Replace(0, cu_file_spec); |
| 1022 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1023 | } |
| David Srbecky | d515e94 | 2015-07-08 14:00:04 +0000 | [diff] [blame] | 1024 | |
| 1025 | dwarf_cu->SetUserData(cu_sp.get()); |
| 1026 | |
| 1027 | // Figure out the compile unit index if we weren't given one |
| 1028 | if (cu_idx == UINT32_MAX) |
| 1029 | DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); |
| 1030 | |
| 1031 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1032 | } |
| 1033 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1038 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | uint32_t |
| 1042 | SymbolFileDWARF::GetNumCompileUnits() |
| 1043 | { |
| 1044 | DWARFDebugInfo* info = DebugInfo(); |
| 1045 | if (info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1046 | return info->GetNumCompileUnits(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | CompUnitSP |
| 1051 | SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 1052 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1053 | CompUnitSP cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1054 | DWARFDebugInfo* info = DebugInfo(); |
| 1055 | if (info) |
| 1056 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1057 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); |
| 1058 | if (dwarf_cu) |
| 1059 | cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1060 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1061 | return cu_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1064 | Function * |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1065 | SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1066 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1067 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1068 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1069 | if (type_system) |
| 1070 | return type_system->ParseFunctionFromDWARF(sc, this, dwarf_cu, die); |
| 1071 | else |
| 1072 | return nullptr; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1075 | bool |
| 1076 | SymbolFileDWARF::FixupAddress (Address &addr) |
| 1077 | { |
| 1078 | SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); |
| 1079 | if (debug_map_symfile) |
| 1080 | { |
| 1081 | return debug_map_symfile->LinkOSOAddress(addr); |
| 1082 | } |
| 1083 | // This is a normal DWARF file, no address fixups need to happen |
| 1084 | return true; |
| 1085 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1086 | lldb::LanguageType |
| 1087 | SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) |
| 1088 | { |
| 1089 | assert (sc.comp_unit); |
| 1090 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1091 | if (dwarf_cu) |
| 1092 | { |
| 1093 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1094 | if (die) |
| Dawn Perchik | d0e87eb | 2015-06-17 22:30:24 +0000 | [diff] [blame] | 1095 | return DWARFCompileUnit::LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0)); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1096 | } |
| 1097 | return eLanguageTypeUnknown; |
| 1098 | } |
| 1099 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1100 | size_t |
| 1101 | SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) |
| 1102 | { |
| 1103 | assert (sc.comp_unit); |
| 1104 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1105 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | if (dwarf_cu) |
| 1107 | { |
| 1108 | DWARFDIECollection function_dies; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1109 | const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 | size_t func_idx; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1111 | for (func_idx = 0; func_idx < num_functions; ++func_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | { |
| 1113 | const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1114 | if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1115 | { |
| 1116 | if (ParseCompileUnitFunction(sc, dwarf_cu, die)) |
| 1117 | ++functions_added; |
| 1118 | } |
| 1119 | } |
| 1120 | //FixupTypes(); |
| 1121 | } |
| 1122 | return functions_added; |
| 1123 | } |
| 1124 | |
| 1125 | bool |
| 1126 | SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) |
| 1127 | { |
| 1128 | assert (sc.comp_unit); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1129 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1130 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1131 | { |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1132 | const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1133 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1134 | if (cu_die) |
| 1135 | { |
| Oleksiy Vyalov | 5d9c50b | 2015-07-21 02:09:42 +0000 | [diff] [blame] | 1136 | const char * cu_comp_dir = resolveCompDir(cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)); |
| Matthew Gardiner | e81df3b | 2014-08-26 06:57:23 +0000 | [diff] [blame] | 1137 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1138 | dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1139 | |
| Greg Clayton | da2455b | 2012-11-01 17:28:37 +0000 | [diff] [blame] | 1140 | // All file indexes in DWARF are one based and a file of index zero is |
| 1141 | // supposed to be the compile unit itself. |
| 1142 | support_files.Append (*sc.comp_unit); |
| 1143 | |
| 1144 | return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); |
| 1145 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1146 | } |
| 1147 | return false; |
| 1148 | } |
| 1149 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1150 | bool |
| 1151 | SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) |
| 1152 | { |
| 1153 | assert (sc.comp_unit); |
| 1154 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| 1155 | if (dwarf_cu) |
| 1156 | { |
| 1157 | if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage())) |
| 1158 | { |
| 1159 | UpdateExternalModuleListIfNeeded(); |
| 1160 | for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules) |
| 1161 | { |
| 1162 | imported_modules.push_back(external_type_module.second.m_name); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | struct ParseDWARFLineTableCallbackInfo |
| 1170 | { |
| 1171 | LineTable* line_table; |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1172 | std::unique_ptr<LineSequence> sequence_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1173 | }; |
| 1174 | |
| 1175 | //---------------------------------------------------------------------- |
| 1176 | // ParseStatementTableCallback |
| 1177 | //---------------------------------------------------------------------- |
| 1178 | static void |
| 1179 | ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) |
| 1180 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1181 | if (state.row == DWARFDebugLine::State::StartParsingLineTable) |
| 1182 | { |
| 1183 | // Just started parsing the line table |
| 1184 | } |
| 1185 | else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) |
| 1186 | { |
| 1187 | // Done parsing line table, nothing to do for the cleanup |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1192 | LineTable* line_table = info->line_table; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1193 | |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1194 | // If this is our first time here, we need to create a |
| 1195 | // sequence container. |
| 1196 | if (!info->sequence_ap.get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1198 | info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); |
| 1199 | assert(info->sequence_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1201 | line_table->AppendLineEntryToSequence (info->sequence_ap.get(), |
| 1202 | state.address, |
| 1203 | state.line, |
| 1204 | state.column, |
| 1205 | state.file, |
| 1206 | state.is_stmt, |
| 1207 | state.basic_block, |
| 1208 | state.prologue_end, |
| 1209 | state.epilogue_begin, |
| 1210 | state.end_sequence); |
| 1211 | if (state.end_sequence) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1213 | // First, put the current sequence into the line table. |
| 1214 | line_table->InsertSequence(info->sequence_ap.get()); |
| 1215 | // Then, empty it to prepare for the next sequence. |
| 1216 | info->sequence_ap->Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1217 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | bool |
| 1222 | SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) |
| 1223 | { |
| 1224 | assert (sc.comp_unit); |
| 1225 | if (sc.comp_unit->GetLineTable() != NULL) |
| 1226 | return true; |
| 1227 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1228 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | if (dwarf_cu) |
| 1230 | { |
| 1231 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1232 | if (dwarf_cu_die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | { |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1234 | const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); |
| 1235 | if (cu_line_offset != DW_INVALID_OFFSET) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1236 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1237 | std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1238 | if (line_table_ap.get()) |
| 1239 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1240 | ParseDWARFLineTableCallbackInfo info; |
| 1241 | info.line_table = line_table_ap.get(); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1242 | lldb::offset_t offset = cu_line_offset; |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1243 | DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1244 | if (m_debug_map_symfile) |
| 1245 | { |
| 1246 | // We have an object file that has a line table with addresses |
| 1247 | // that are not linked. We need to link the line table and convert |
| 1248 | // the addresses that are relative to the .o file into addresses |
| 1249 | // for the main executable. |
| 1250 | sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); |
| 1251 | } |
| 1252 | else |
| 1253 | { |
| 1254 | sc.comp_unit->SetLineTable(line_table_ap.release()); |
| 1255 | return true; |
| 1256 | } |
| Greg Clayton | 129d12c | 2011-11-28 03:29:03 +0000 | [diff] [blame] | 1257 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
| 1264 | size_t |
| 1265 | SymbolFileDWARF::ParseFunctionBlocks |
| 1266 | ( |
| 1267 | const SymbolContext& sc, |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1268 | Block *parent_block, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1269 | DWARFCompileUnit* dwarf_cu, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1270 | const DWARFDebugInfoEntry *die, |
| 1271 | addr_t subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1272 | uint32_t depth |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1273 | ) |
| 1274 | { |
| 1275 | size_t blocks_added = 0; |
| 1276 | while (die != NULL) |
| 1277 | { |
| 1278 | dw_tag_t tag = die->Tag(); |
| 1279 | |
| 1280 | switch (tag) |
| 1281 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1282 | case DW_TAG_inlined_subroutine: |
| Greg Clayton | b4d3733 | 2011-08-12 16:22:48 +0000 | [diff] [blame] | 1283 | case DW_TAG_subprogram: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1284 | case DW_TAG_lexical_block: |
| 1285 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1286 | Block *block = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1287 | if (tag == DW_TAG_subprogram) |
| 1288 | { |
| 1289 | // Skip any DW_TAG_subprogram DIEs that are inside |
| 1290 | // of a normal or inlined functions. These will be |
| 1291 | // parsed on their own as separate entities. |
| 1292 | |
| 1293 | if (depth > 0) |
| 1294 | break; |
| 1295 | |
| 1296 | block = parent_block; |
| 1297 | } |
| 1298 | else |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1299 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1300 | BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1301 | parent_block->AddChild(block_sp); |
| 1302 | block = block_sp.get(); |
| 1303 | } |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1304 | DWARFDebugRanges::RangeList ranges; |
| 1305 | const char *name = NULL; |
| 1306 | const char *mangled_name = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1307 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1308 | int decl_file = 0; |
| 1309 | int decl_line = 0; |
| 1310 | int decl_column = 0; |
| 1311 | int call_file = 0; |
| 1312 | int call_line = 0; |
| 1313 | int call_column = 0; |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1314 | if (die->GetDIENamesAndRanges (this, |
| 1315 | dwarf_cu, |
| 1316 | name, |
| 1317 | mangled_name, |
| 1318 | ranges, |
| 1319 | decl_file, decl_line, decl_column, |
| 1320 | call_file, call_line, call_column)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | { |
| 1322 | if (tag == DW_TAG_subprogram) |
| 1323 | { |
| 1324 | assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1325 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1326 | } |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1327 | else if (tag == DW_TAG_inlined_subroutine) |
| 1328 | { |
| 1329 | // We get called here for inlined subroutines in two ways. |
| 1330 | // The first time is when we are making the Function object |
| 1331 | // for this inlined concrete instance. Since we're creating a top level block at |
| 1332 | // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to |
| 1333 | // adjust the containing address. |
| 1334 | // The second time is when we are parsing the blocks inside the function that contains |
| 1335 | // the inlined concrete instance. Since these will be blocks inside the containing "real" |
| 1336 | // function the offset will be for that function. |
| 1337 | if (subprogram_low_pc == LLDB_INVALID_ADDRESS) |
| 1338 | { |
| Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 1339 | subprogram_low_pc = ranges.GetMinRangeBase(0); |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1340 | } |
| 1341 | } |
| Greg Clayton | 103f309 | 2015-01-15 03:04:37 +0000 | [diff] [blame] | 1342 | |
| 1343 | const size_t num_ranges = ranges.GetSize(); |
| 1344 | for (size_t i = 0; i<num_ranges; ++i) |
| 1345 | { |
| 1346 | const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); |
| 1347 | const addr_t range_base = range.GetRangeBase(); |
| 1348 | if (range_base >= subprogram_low_pc) |
| 1349 | block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); |
| 1350 | else |
| 1351 | { |
| 1352 | GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message", |
| 1353 | block->GetID(), |
| 1354 | range_base, |
| 1355 | range.GetRangeEnd(), |
| 1356 | subprogram_low_pc); |
| 1357 | } |
| 1358 | } |
| 1359 | block->FinalizeRanges (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1360 | |
| 1361 | if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) |
| 1362 | { |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1363 | std::unique_ptr<Declaration> decl_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1364 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1365 | decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), |
| 1366 | decl_line, decl_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1367 | |
| Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 1368 | std::unique_ptr<Declaration> call_ap; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1369 | if (call_file != 0 || call_line != 0 || call_column != 0) |
| Jim Ingham | b0be442 | 2010-08-12 01:20:14 +0000 | [diff] [blame] | 1370 | call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), |
| 1371 | call_line, call_column)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1373 | block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | ++blocks_added; |
| 1377 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1378 | if (die->HasChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1379 | { |
| Greg Clayton | 0b76a2c | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 1380 | blocks_added += ParseFunctionBlocks (sc, |
| 1381 | block, |
| 1382 | dwarf_cu, |
| 1383 | die->GetFirstChild(), |
| 1384 | subprogram_low_pc, |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1385 | depth + 1); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | break; |
| 1390 | default: |
| 1391 | break; |
| 1392 | } |
| 1393 | |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1394 | // Only parse siblings of the block if we are not at depth zero. A depth |
| 1395 | // of zero indicates we are currently parsing the top level |
| 1396 | // DW_TAG_subprogram DIE |
| 1397 | |
| 1398 | if (depth == 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1399 | die = NULL; |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 1400 | else |
| 1401 | die = die->GetSibling(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1402 | } |
| 1403 | return blocks_added; |
| 1404 | } |
| 1405 | |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1406 | bool |
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1407 | SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, |
| 1408 | const DWARFDebugInfoEntry *parent_die) |
| 1409 | { |
| 1410 | if (parent_die) |
| 1411 | { |
| 1412 | for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) |
| 1413 | { |
| 1414 | dw_tag_t tag = die->Tag(); |
| 1415 | bool check_virtuality = false; |
| 1416 | switch (tag) |
| 1417 | { |
| 1418 | case DW_TAG_inheritance: |
| 1419 | case DW_TAG_subprogram: |
| 1420 | check_virtuality = true; |
| 1421 | break; |
| 1422 | default: |
| 1423 | break; |
| 1424 | } |
| 1425 | if (check_virtuality) |
| 1426 | { |
| 1427 | if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) |
| 1428 | return true; |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | return false; |
| 1433 | } |
| 1434 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1435 | CompilerDeclContext |
| 1436 | SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1437 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1438 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1439 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1440 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1441 | if (debug_info) |
| 1442 | { |
| 1443 | DWARFCompileUnitSP cu_sp; |
| 1444 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1445 | if (die) |
| 1446 | { |
| 1447 | TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType()); |
| 1448 | if (type_system) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1449 | return type_system->GetDeclContextForUIDFromDWARF(this, cu_sp.get(), die); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1450 | } |
| 1451 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1452 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1453 | return CompilerDeclContext(); |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1456 | CompilerDeclContext |
| 1457 | SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid) |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1458 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1459 | if (UserIDMatches(type_uid)) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1460 | { |
| 1461 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1462 | if (debug_info) |
| 1463 | { |
| 1464 | DWARFCompileUnitSP cu_sp; |
| 1465 | const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| 1466 | if (die) |
| 1467 | { |
| 1468 | TypeSystem *type_system = GetTypeSystemForLanguage(cu_sp->GetLanguageType()); |
| 1469 | if (type_system) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1470 | return type_system->GetDeclContextContainingUIDFromDWARF(this, cu_sp.get(), die); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1474 | return CompilerDeclContext(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1477 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1478 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1479 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1481 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1482 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1483 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1484 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1485 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1486 | DWARFCompileUnitSP cu_sp; |
| 1487 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1488 | const bool assert_not_being_parsed = true; |
| 1489 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1490 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1491 | } |
| 1492 | return NULL; |
| 1493 | } |
| 1494 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1495 | Type* |
| 1496 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1497 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1498 | if (die != NULL) |
| 1499 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1500 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1501 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1502 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1503 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1504 | die->GetOffset(), |
| 1505 | DW_TAG_value_to_name(die->Tag()), |
| 1506 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1507 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1508 | // We might be coming in in the middle of a type tree (a class |
| 1509 | // withing a class, an enum within a class), so parse any needed |
| 1510 | // parent DIEs before we get to this one... |
| 1511 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1512 | switch (decl_ctx_die->Tag()) |
| 1513 | { |
| 1514 | case DW_TAG_structure_type: |
| 1515 | case DW_TAG_union_type: |
| 1516 | case DW_TAG_class_type: |
| 1517 | { |
| 1518 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1519 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1520 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1521 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1522 | die->GetOffset(), |
| 1523 | DW_TAG_value_to_name(die->Tag()), |
| 1524 | die->GetName(this, cu), |
| 1525 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1526 | // |
| 1527 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 1528 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 1529 | // { |
| 1530 | // if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1531 | // GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1532 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 1533 | // die->GetOffset(), |
| 1534 | // DW_TAG_value_to_name(die->Tag()), |
| 1535 | // die->GetName(this, cu), |
| 1536 | // decl_ctx_die->GetOffset()); |
| 1537 | // // Ask the type to complete itself if it already hasn't since if we |
| 1538 | // // want a function (method or static) from a class, the class must |
| 1539 | // // create itself and add it's own methods and class functions. |
| 1540 | // if (parent_type) |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1541 | // parent_type->GetFullCompilerType (); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1542 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1543 | } |
| 1544 | break; |
| 1545 | |
| 1546 | default: |
| 1547 | break; |
| 1548 | } |
| 1549 | return ResolveType (cu, die); |
| 1550 | } |
| 1551 | return NULL; |
| 1552 | } |
| 1553 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1554 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1555 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1556 | // can resolve a clang_type. |
| 1557 | bool |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1558 | SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1559 | { |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1560 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1561 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1562 | return die != NULL; |
| 1563 | } |
| 1564 | |
| 1565 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1566 | bool |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 1567 | SymbolFileDWARF::CompleteType (CompilerType &clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1568 | { |
| 1569 | // We have a struct/union/class/enum that needs to be fully resolved. |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1570 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1571 | const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1572 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1573 | { |
| 1574 | // We have already resolved this type... |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1575 | return true; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1576 | } |
| 1577 | // Once we start resolving this type, remove it from the forward declaration |
| 1578 | // map in case anyone child members or other types require this type to get resolved. |
| 1579 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1580 | // are done. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1581 | m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1582 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1583 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1584 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1585 | Type *type = m_die_to_type.lookup (die); |
| 1586 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1587 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1588 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1589 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1590 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1591 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1592 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1593 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1594 | assert (clang_type); |
| 1595 | DWARFDebugInfoEntry::Attributes attributes; |
| 1596 | |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1597 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1598 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1599 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1600 | if (type_system) |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 1601 | return type_system->CompleteTypeFromDWARF (this, dwarf_cu, die, type, clang_type); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1602 | |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1603 | return false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1606 | void |
| 1607 | SymbolFileDWARF::ClearDIEBeingParsed (const DWARFDebugInfoEntry* type_die) |
| 1608 | { |
| 1609 | if (type_die) |
| 1610 | { |
| 1611 | if (m_die_to_type.lookup (type_die) == DIE_IS_BEING_PARSED) |
| 1612 | m_die_to_type[type_die] = nullptr; |
| 1613 | } |
| 1614 | } |
| 1615 | Type* |
| 1616 | SymbolFileDWARF::GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const |
| 1617 | { |
| 1618 | if (type_die) |
| 1619 | { |
| 1620 | Type *type = m_die_to_type.lookup (type_die); |
| 1621 | if (type != DIE_IS_BEING_PARSED) |
| 1622 | return type; |
| 1623 | } |
| 1624 | return nullptr; |
| 1625 | } |
| 1626 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1627 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1628 | SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1629 | { |
| 1630 | if (type_die != NULL) |
| 1631 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1632 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1633 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1634 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1635 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1636 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1637 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1638 | { |
| 1639 | if (type != DIE_IS_BEING_PARSED) |
| 1640 | return type; |
| 1641 | |
| 1642 | GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1643 | type_die->GetOffset(), |
| 1644 | DW_TAG_value_to_name(type_die->Tag()), |
| 1645 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1646 | |
| 1647 | } |
| 1648 | else |
| 1649 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1650 | } |
| 1651 | return NULL; |
| 1652 | } |
| 1653 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1654 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1655 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1656 | { |
| 1657 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1658 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1659 | { |
| 1660 | // The symbol vendor doesn't know about this compile unit, we |
| 1661 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1662 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1663 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1664 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1667 | size_t |
| 1668 | SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets) |
| 1669 | { |
| 1670 | method_die_offsets.clear(); |
| 1671 | if (m_using_apple_tables) |
| 1672 | { |
| 1673 | if (m_apple_objc_ap.get()) |
| 1674 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); |
| 1675 | } |
| 1676 | else |
| 1677 | { |
| 1678 | if (!m_indexed) |
| 1679 | Index (); |
| 1680 | |
| 1681 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 1682 | } |
| 1683 | return method_die_offsets.size(); |
| 1684 | } |
| 1685 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1686 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1687 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1688 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 1689 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1690 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1691 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1692 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1693 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1694 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1695 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 1696 | |
| 1697 | if (sc.function) |
| 1698 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1699 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 1700 | return true; |
| 1701 | } |
| 1702 | |
| 1703 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1706 | void |
| 1707 | SymbolFileDWARF::UpdateExternalModuleListIfNeeded() |
| 1708 | { |
| 1709 | if (m_fetched_external_modules) |
| 1710 | return; |
| 1711 | m_fetched_external_modules = true; |
| 1712 | |
| 1713 | DWARFDebugInfo * debug_info = DebugInfo(); |
| 1714 | debug_info->GetNumCompileUnits(); |
| 1715 | |
| 1716 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 1717 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 1718 | { |
| 1719 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 1720 | |
| 1721 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| 1722 | if (die && die->HasChildren() == false) |
| 1723 | { |
| 1724 | const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX); |
| 1725 | const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX); |
| 1726 | |
| 1727 | if (name_strp != UINT64_MAX) |
| 1728 | { |
| 1729 | if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end()) |
| 1730 | { |
| 1731 | const char *name = get_debug_str_data().PeekCStr(name_strp); |
| 1732 | const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp); |
| 1733 | if (name || dwo_path) |
| 1734 | { |
| 1735 | ModuleSP module_sp; |
| 1736 | if (dwo_path) |
| 1737 | { |
| 1738 | ModuleSpec dwo_module_spec; |
| 1739 | dwo_module_spec.GetFileSpec().SetFile(dwo_path, false); |
| 1740 | dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture(); |
| 1741 | //printf ("Loading dwo = '%s'\n", dwo_path); |
| 1742 | Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL); |
| 1743 | } |
| 1744 | |
| 1745 | if (dwo_path_strp != LLDB_INVALID_UID) |
| 1746 | { |
| 1747 | m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1748 | } |
| 1749 | else |
| 1750 | { |
| 1751 | // This hack should be removed promptly once clang emits both. |
| 1752 | m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1760 | |
| 1761 | SymbolFileDWARF::GlobalVariableMap & |
| 1762 | SymbolFileDWARF::GetGlobalAranges() |
| 1763 | { |
| 1764 | if (!m_global_aranges_ap) |
| 1765 | { |
| 1766 | m_global_aranges_ap.reset (new GlobalVariableMap()); |
| 1767 | |
| 1768 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 1769 | if (module_sp) |
| 1770 | { |
| 1771 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 1772 | for (size_t i = 0; i < num_cus; ++i) |
| 1773 | { |
| 1774 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 1775 | if (cu_sp) |
| 1776 | { |
| 1777 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 1778 | if (globals_sp) |
| 1779 | { |
| 1780 | const size_t num_globals = globals_sp->GetSize(); |
| 1781 | for (size_t g = 0; g < num_globals; ++g) |
| 1782 | { |
| 1783 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 1784 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) |
| 1785 | { |
| 1786 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 1787 | Value location_result; |
| 1788 | Error error; |
| 1789 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) |
| 1790 | { |
| 1791 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) |
| 1792 | { |
| 1793 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); |
| 1794 | lldb::addr_t byte_size = 1; |
| 1795 | if (var_sp->GetType()) |
| 1796 | byte_size = var_sp->GetType()->GetByteSize(); |
| 1797 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | m_global_aranges_ap->Sort(); |
| 1807 | } |
| 1808 | return *m_global_aranges_ap; |
| 1809 | } |
| 1810 | |
| 1811 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1812 | uint32_t |
| 1813 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 1814 | { |
| 1815 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1816 | "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1817 | static_cast<void*>(so_addr.GetSection().get()), |
| 1818 | so_addr.GetOffset(), resolve_scope); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1819 | uint32_t resolved = 0; |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1820 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 1821 | eSymbolContextFunction | |
| 1822 | eSymbolContextBlock | |
| 1823 | eSymbolContextLineEntry | |
| 1824 | eSymbolContextVariable )) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1825 | { |
| 1826 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 1827 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1828 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1829 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1830 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1831 | const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1832 | if (cu_offset == DW_INVALID_OFFSET) |
| 1833 | { |
| 1834 | // Global variables are not in the compile unit address ranges. The only way to |
| 1835 | // currently find global variables is to iterate over the .debug_pubnames or the |
| 1836 | // __apple_names table and find all items in there that point to DW_TAG_variable |
| 1837 | // DIEs and then find the address that matches. |
| 1838 | if (resolve_scope & eSymbolContextVariable) |
| 1839 | { |
| 1840 | GlobalVariableMap &map = GetGlobalAranges(); |
| 1841 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); |
| 1842 | if (entry && entry->data) |
| 1843 | { |
| 1844 | Variable *variable = entry->data; |
| 1845 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 1846 | if (scc) |
| 1847 | { |
| 1848 | scc->CalculateSymbolContext(&sc); |
| 1849 | sc.variable = variable; |
| 1850 | } |
| 1851 | return sc.GetResolvedMask(); |
| 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1856 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1857 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1858 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 1859 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1860 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1861 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1862 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1863 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1864 | resolved |= eSymbolContextCompUnit; |
| 1865 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1866 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1867 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 1868 | { |
| 1869 | DWARFDebugInfoEntry *function_die = NULL; |
| 1870 | DWARFDebugInfoEntry *block_die = NULL; |
| 1871 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1872 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1873 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 1878 | } |
| 1879 | |
| 1880 | if (function_die != NULL) |
| 1881 | { |
| 1882 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 1883 | if (sc.function == NULL) |
| 1884 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 1885 | } |
| 1886 | else |
| 1887 | { |
| 1888 | // We might have had a compile unit that had discontiguous |
| 1889 | // address ranges where the gaps are symbols that don't have |
| 1890 | // any debug info. Discontiguous compile unit address ranges |
| 1891 | // should only happen when there aren't other functions from |
| 1892 | // other compile units in these gaps. This helps keep the size |
| 1893 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1894 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | if (sc.function != NULL) |
| 1898 | { |
| 1899 | resolved |= eSymbolContextFunction; |
| 1900 | |
| 1901 | if (resolve_scope & eSymbolContextBlock) |
| 1902 | { |
| 1903 | Block& block = sc.function->GetBlock (true); |
| 1904 | |
| 1905 | if (block_die != NULL) |
| 1906 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 1907 | else |
| 1908 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 1909 | if (sc.block) |
| 1910 | resolved |= eSymbolContextBlock; |
| 1911 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1912 | } |
| 1913 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1914 | |
| 1915 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 1916 | { |
| 1917 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1918 | if (line_table != NULL) |
| 1919 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1920 | // And address that makes it into this function should be in terms |
| 1921 | // of this debug file if there is no debug map, or it will be an |
| 1922 | // address in the .o file which needs to be fixed up to be in terms |
| 1923 | // of the debug map executable. Either way, calling FixupAddress() |
| 1924 | // will work for us. |
| 1925 | Address exe_so_addr (so_addr); |
| 1926 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1927 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1928 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1929 | { |
| 1930 | resolved |= eSymbolContextLineEntry; |
| 1931 | } |
| 1932 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 1937 | { |
| 1938 | // We might have had a compile unit that had discontiguous |
| 1939 | // address ranges where the gaps are symbols that don't have |
| 1940 | // any debug info. Discontiguous compile unit address ranges |
| 1941 | // should only happen when there aren't other functions from |
| 1942 | // other compile units in these gaps. This helps keep the size |
| 1943 | // of the aranges down. |
| 1944 | sc.comp_unit = NULL; |
| 1945 | resolved &= ~eSymbolContextCompUnit; |
| 1946 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1947 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1948 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1949 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1950 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 1951 | cu_offset, |
| 1952 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | } |
| 1958 | return resolved; |
| 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | uint32_t |
| 1964 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 1965 | { |
| 1966 | const uint32_t prev_size = sc_list.GetSize(); |
| 1967 | if (resolve_scope & eSymbolContextCompUnit) |
| 1968 | { |
| 1969 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1970 | if (debug_info) |
| 1971 | { |
| 1972 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1973 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1974 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1975 | for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1976 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1977 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 1978 | const bool full_match = (bool)file_spec.GetDirectory(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1979 | bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1980 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 1981 | { |
| 1982 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1983 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1984 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1985 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1986 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1987 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1988 | // If we are looking for inline functions only and we don't |
| 1989 | // find it in the support files, we are done. |
| 1990 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1991 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1992 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 1993 | if (file_idx == UINT32_MAX) |
| 1994 | continue; |
| 1995 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1996 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1997 | if (line != 0) |
| 1998 | { |
| 1999 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 2000 | |
| 2001 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2002 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2003 | // We will have already looked up the file index if |
| 2004 | // we are searching for inline entries. |
| 2005 | if (!check_inlines) |
| 2006 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2007 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2008 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2009 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2010 | uint32_t found_line; |
| 2011 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2012 | found_line = sc.line_entry.line; |
| 2013 | |
| 2014 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2015 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2016 | sc.function = NULL; |
| 2017 | sc.block = NULL; |
| 2018 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2019 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2020 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2021 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2022 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2023 | DWARFDebugInfoEntry *function_die = NULL; |
| 2024 | DWARFDebugInfoEntry *block_die = NULL; |
| 2025 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2026 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2027 | if (function_die != NULL) |
| 2028 | { |
| 2029 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2030 | if (sc.function == NULL) |
| 2031 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2032 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2033 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2034 | if (sc.function != NULL) |
| 2035 | { |
| 2036 | Block& block = sc.function->GetBlock (true); |
| 2037 | |
| 2038 | if (block_die != NULL) |
| 2039 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 2040 | else if (function_die != NULL) |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2041 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2042 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2043 | } |
| 2044 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2045 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2046 | sc_list.Append(sc); |
| 2047 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2048 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2049 | } |
| 2050 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2051 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2052 | { |
| 2053 | // only append the context if we aren't looking for inline call sites |
| 2054 | // by file and line and if the file spec matches that of the compile unit |
| 2055 | sc_list.Append(sc); |
| 2056 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2057 | } |
| 2058 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2059 | { |
| 2060 | // only append the context if we aren't looking for inline call sites |
| 2061 | // by file and line and if the file spec matches that of the compile unit |
| 2062 | sc_list.Append(sc); |
| 2063 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2064 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2065 | if (!check_inlines) |
| 2066 | break; |
| 2067 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | } |
| 2072 | return sc_list.GetSize() - prev_size; |
| 2073 | } |
| 2074 | |
| 2075 | void |
| 2076 | SymbolFileDWARF::Index () |
| 2077 | { |
| 2078 | if (m_indexed) |
| 2079 | return; |
| 2080 | m_indexed = true; |
| 2081 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2082 | "SymbolFileDWARF::Index (%s)", |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 2083 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2084 | |
| 2085 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2086 | if (debug_info) |
| 2087 | { |
| 2088 | uint32_t cu_idx = 0; |
| 2089 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2090 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2091 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2092 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2093 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2094 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2095 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2096 | dwarf_cu->Index (cu_idx, |
| 2097 | m_function_basename_index, |
| 2098 | m_function_fullname_index, |
| 2099 | m_function_method_index, |
| 2100 | m_function_selector_index, |
| 2101 | m_objc_class_selectors_index, |
| 2102 | m_global_index, |
| 2103 | m_type_index, |
| 2104 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2105 | |
| 2106 | // Keep memory down by clearing DIEs if this generate function |
| 2107 | // caused them to be parsed |
| 2108 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2109 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2112 | m_function_basename_index.Finalize(); |
| 2113 | m_function_fullname_index.Finalize(); |
| 2114 | m_function_method_index.Finalize(); |
| 2115 | m_function_selector_index.Finalize(); |
| 2116 | m_objc_class_selectors_index.Finalize(); |
| 2117 | m_global_index.Finalize(); |
| 2118 | m_type_index.Finalize(); |
| 2119 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2120 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2121 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2122 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2123 | s.Printf ("DWARF index for '%s':", |
| 2124 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2125 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2126 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2127 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2128 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2129 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2130 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2131 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 2132 | s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2133 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2134 | } |
| 2135 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2136 | |
| 2137 | bool |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2138 | SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx) |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2139 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2140 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2141 | { |
| 2142 | // Invalid namespace decl which means we aren't matching only things |
| 2143 | // in this symbol file, so return true to indicate it matches this |
| 2144 | // symbol file. |
| 2145 | return true; |
| 2146 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2147 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2148 | if ((TypeSystem *)&GetClangASTContext() == decl_ctx->GetTypeSystem()) |
| 2149 | return true; // The type systems match, return true |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2150 | |
| 2151 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2152 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2153 | |
| 2154 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2155 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2156 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2157 | return false; |
| 2158 | } |
| 2159 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2160 | uint32_t |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2161 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2162 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2163 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2164 | |
| 2165 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2166 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2167 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2168 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2169 | static_cast<const void*>(parent_decl_ctx), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2170 | append, max_matches); |
| 2171 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2172 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2173 | return 0; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2174 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2175 | DWARFDebugInfo* info = DebugInfo(); |
| 2176 | if (info == NULL) |
| 2177 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2178 | |
| 2179 | // If we aren't appending the results to this list, then clear the list |
| 2180 | if (!append) |
| 2181 | variables.Clear(); |
| 2182 | |
| 2183 | // Remember how many variables are in the list before we search in case |
| 2184 | // we are appending the results to a variable list. |
| 2185 | const uint32_t original_size = variables.GetSize(); |
| 2186 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2187 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2188 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2189 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2190 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2191 | if (m_apple_names_ap.get()) |
| 2192 | { |
| 2193 | const char *name_cstr = name.GetCString(); |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2194 | llvm::StringRef basename; |
| 2195 | llvm::StringRef context; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2196 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2197 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) |
| 2198 | basename = name_cstr; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2199 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2200 | m_apple_names_ap->FindByName (basename.data(), die_offsets); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2201 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2202 | } |
| 2203 | else |
| 2204 | { |
| 2205 | // Index the DWARF if we haven't already |
| 2206 | if (!m_indexed) |
| 2207 | Index (); |
| 2208 | |
| 2209 | m_global_index.Find (name, die_offsets); |
| 2210 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2211 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2212 | const size_t num_die_matches = die_offsets.size(); |
| 2213 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2214 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2215 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2216 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2217 | assert (sc.module_sp); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2218 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2219 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2220 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2221 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2222 | bool done = false; |
| 2223 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2224 | { |
| 2225 | const dw_offset_t die_offset = die_offsets[i]; |
| 2226 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2227 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2228 | if (die) |
| 2229 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2230 | switch (die->Tag()) |
| 2231 | { |
| 2232 | default: |
| 2233 | case DW_TAG_subprogram: |
| 2234 | case DW_TAG_inlined_subroutine: |
| 2235 | case DW_TAG_try_block: |
| 2236 | case DW_TAG_catch_block: |
| 2237 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2238 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2239 | case DW_TAG_variable: |
| 2240 | { |
| 2241 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2242 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2243 | if (parent_decl_ctx) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2244 | { |
| 2245 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 2246 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2247 | if (type_system) |
| 2248 | { |
| 2249 | CompilerDeclContext actual_parent_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, dwarf_cu, die); |
| 2250 | if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx) |
| 2251 | continue; |
| 2252 | } |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2253 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2254 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2255 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2256 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2257 | if (variables.GetSize() - original_size >= max_matches) |
| 2258 | done = true; |
| 2259 | } |
| 2260 | break; |
| 2261 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2262 | } |
| 2263 | else |
| 2264 | { |
| 2265 | if (m_using_apple_tables) |
| 2266 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2267 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2268 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2269 | } |
| 2270 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2271 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2275 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2276 | if (log && num_matches > 0) |
| 2277 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2278 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2279 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2280 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2281 | static_cast<const void*>(parent_decl_ctx), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2282 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2283 | num_matches); |
| 2284 | } |
| 2285 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | uint32_t |
| 2289 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2290 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2291 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2292 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2293 | if (log) |
| 2294 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2295 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2296 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2297 | regex.GetText(), append, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2298 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2301 | DWARFDebugInfo* info = DebugInfo(); |
| 2302 | if (info == NULL) |
| 2303 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2304 | |
| 2305 | // If we aren't appending the results to this list, then clear the list |
| 2306 | if (!append) |
| 2307 | variables.Clear(); |
| 2308 | |
| 2309 | // Remember how many variables are in the list before we search in case |
| 2310 | // we are appending the results to a variable list. |
| 2311 | const uint32_t original_size = variables.GetSize(); |
| 2312 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2313 | DIEArray die_offsets; |
| 2314 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2315 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2316 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2317 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2318 | { |
| 2319 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2320 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2321 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2322 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2323 | } |
| 2324 | else |
| 2325 | { |
| 2326 | // Index the DWARF if we haven't already |
| 2327 | if (!m_indexed) |
| 2328 | Index (); |
| 2329 | |
| 2330 | m_global_index.Find (regex, die_offsets); |
| 2331 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2332 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2333 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2334 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2335 | assert (sc.module_sp); |
| 2336 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2337 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2338 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2339 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2340 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2341 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2342 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2343 | for (size_t i=0; i<num_matches; ++i) |
| 2344 | { |
| 2345 | const dw_offset_t die_offset = die_offsets[i]; |
| 2346 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2347 | |
| 2348 | if (die) |
| 2349 | { |
| 2350 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2351 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2352 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2353 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2354 | if (variables.GetSize() - original_size >= max_matches) |
| 2355 | break; |
| 2356 | } |
| 2357 | else |
| 2358 | { |
| 2359 | if (m_using_apple_tables) |
| 2360 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2361 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2362 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2363 | } |
| 2364 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2365 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | // Return the number of variable that were appended to the list |
| 2369 | return variables.GetSize() - original_size; |
| 2370 | } |
| 2371 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2372 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2373 | bool |
| 2374 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2375 | DWARFCompileUnit *&dwarf_cu, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2376 | bool include_inlines, |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2377 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2378 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2379 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2380 | return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
| 2384 | bool |
| 2385 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2386 | const DWARFDebugInfoEntry *die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2387 | bool include_inlines, |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2388 | SymbolContextList& sc_list) |
| 2389 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2390 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2391 | |
| 2392 | if (die == NULL) |
| 2393 | return false; |
| 2394 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2395 | // If we were passed a die that is not a function, just return false... |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2396 | if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine))) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2397 | return false; |
| 2398 | |
| 2399 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2400 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2401 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2402 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2403 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2404 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2405 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2406 | if (die->Tag() == DW_TAG_subprogram) |
| 2407 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2408 | } |
| 2409 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 2410 | assert (die && die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2411 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2412 | { |
| 2413 | Address addr; |
| 2414 | // Parse all blocks if needed |
| 2415 | if (inlined_die) |
| 2416 | { |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 2417 | Block &function_block = sc.function->GetBlock (true); |
| 2418 | sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| 2419 | if (sc.block == NULL) |
| 2420 | sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); |
| 2421 | if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2422 | addr.Clear(); |
| 2423 | } |
| 2424 | else |
| 2425 | { |
| 2426 | sc.block = NULL; |
| 2427 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2428 | } |
| 2429 | |
| 2430 | if (addr.IsValid()) |
| 2431 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2432 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2433 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2437 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2440 | void |
| 2441 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2442 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2443 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2444 | SymbolContextList& sc_list) |
| 2445 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2446 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2447 | if (name_to_die.Find (name, die_offsets)) |
| 2448 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2449 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | |
| 2454 | void |
| 2455 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2456 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2457 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2458 | SymbolContextList& sc_list) |
| 2459 | { |
| 2460 | DIEArray die_offsets; |
| 2461 | if (name_to_die.Find (regex, die_offsets)) |
| 2462 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2463 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | |
| 2468 | void |
| 2469 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2470 | const DWARFMappedHash::MemoryTable &memory_table, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2471 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2472 | SymbolContextList& sc_list) |
| 2473 | { |
| 2474 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2475 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2476 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2477 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2478 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2479 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | void |
| 2484 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2485 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2486 | SymbolContextList& sc_list) |
| 2487 | { |
| 2488 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2489 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2490 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2491 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2492 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2493 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2494 | const dw_offset_t die_offset = die_offsets[i]; |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2495 | ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2496 | } |
| 2497 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2498 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2499 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2500 | bool |
| 2501 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 2502 | const DWARFCompileUnit *dwarf_cu, |
| 2503 | uint32_t name_type_mask, |
| 2504 | const char *partial_name, |
| 2505 | const char *base_name_start, |
| 2506 | const char *base_name_end) |
| 2507 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2508 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: |
| 2509 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2510 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2511 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (dwarf_cu, die); |
| 2512 | |
| 2513 | if (decl_ctx_die == nullptr) |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2514 | return false; |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2515 | |
| 2516 | const dw_tag_t decl_ctx_tag = decl_ctx_die->Tag(); |
| 2517 | |
| 2518 | bool is_cxx_method = (decl_ctx_tag == DW_TAG_structure_type) || (decl_ctx_tag == DW_TAG_class_type); |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2519 | |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2520 | if (name_type_mask == eFunctionNameTypeMethod) |
| 2521 | { |
| 2522 | if (is_cxx_method == false) |
| 2523 | return false; |
| 2524 | } |
| 2525 | |
| 2526 | if (name_type_mask == eFunctionNameTypeBase) |
| 2527 | { |
| 2528 | if (is_cxx_method == true) |
| 2529 | return false; |
| 2530 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 2534 | // that were in the name we're looking up: |
| 2535 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 2536 | { |
| 2537 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 2538 | // we can pull out the mips linkage name attribute: |
| 2539 | |
| 2540 | Mangled best_name; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2541 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2542 | DWARFFormValue form_value; |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 2543 | die->GetAttributes(this, dwarf_cu, DWARFFormValue::FixedFormSizes(), attributes); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2544 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 2545 | if (idx == UINT32_MAX) |
| 2546 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2547 | if (idx != UINT32_MAX) |
| 2548 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2549 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2550 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2551 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); |
| 2552 | if (mangled_name) |
| 2553 | best_name.SetValue (ConstString(mangled_name), true); |
| 2554 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2555 | } |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2556 | |
| 2557 | if (!best_name) |
| 2558 | { |
| 2559 | idx = attributes.FindAttributeIndex(DW_AT_name); |
| 2560 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2561 | { |
| 2562 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 2563 | best_name.SetValue (ConstString(name), false); |
| 2564 | } |
| 2565 | } |
| 2566 | |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 2567 | const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType(); |
| 2568 | if (best_name.GetDemangledName(cu_language)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2569 | { |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 2570 | const char *demangled = best_name.GetDemangledName(cu_language).GetCString(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2571 | if (demangled) |
| 2572 | { |
| 2573 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 2574 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 2575 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2576 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 2577 | else |
| 2578 | { |
| 2579 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 2580 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 2581 | // namespace boundaries... |
| 2582 | |
| 2583 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 2584 | { |
| 2585 | // The partial name was already on a namespace boundary so all matches are good. |
| 2586 | return true; |
| 2587 | } |
| 2588 | else if (partial_in_demangled == demangled) |
| 2589 | { |
| 2590 | // They both start the same, so this is an good match. |
| 2591 | return true; |
| 2592 | } |
| 2593 | else |
| 2594 | { |
| 2595 | if (partial_in_demangled - demangled == 1) |
| 2596 | { |
| 2597 | // Only one character difference, can't be a namespace boundary... |
| 2598 | return false; |
| 2599 | } |
| 2600 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 2601 | { |
| 2602 | // We are on a namespace boundary, so this is also good. |
| 2603 | return true; |
| 2604 | } |
| 2605 | else |
| 2606 | return false; |
| 2607 | } |
| 2608 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | return true; |
| 2614 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2615 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2616 | bool |
| 2617 | SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx, |
| 2618 | DWARFCompileUnit *cu, |
| 2619 | const DWARFDebugInfoEntry *die) |
| 2620 | { |
| 2621 | // If we have no parent decl context to match this DIE matches, and if the parent |
| 2622 | // decl context isn't valid, we aren't trying to look for any particular decl |
| 2623 | // context so any die matches. |
| 2624 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) |
| 2625 | return true; |
| 2626 | |
| 2627 | if (cu && die) |
| 2628 | { |
| 2629 | TypeSystem *type_system = GetTypeSystemForLanguage(cu->GetLanguageType()); |
| 2630 | |
| 2631 | if (type_system) |
| 2632 | { |
| 2633 | CompilerDeclContext actual_decl_ctx = type_system->GetDeclContextContainingUIDFromDWARF (this, cu, die); |
| 2634 | if (actual_decl_ctx) |
| 2635 | return actual_decl_ctx == *decl_ctx; |
| 2636 | } |
| 2637 | } |
| 2638 | return false; |
| 2639 | } |
| 2640 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2641 | uint32_t |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2642 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2643 | const CompilerDeclContext *parent_decl_ctx, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2644 | uint32_t name_type_mask, |
| 2645 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2646 | bool append, |
| 2647 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2648 | { |
| 2649 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2650 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2651 | name.AsCString()); |
| 2652 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2653 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 2654 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 2655 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2656 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2657 | |
| 2658 | if (log) |
| 2659 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2660 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2661 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2662 | name.GetCString(), |
| 2663 | name_type_mask, |
| 2664 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2667 | // If we aren't appending the results to this list, then clear the list |
| 2668 | if (!append) |
| 2669 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2670 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2671 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2672 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2673 | |
| 2674 | // If name is empty then we won't find anything. |
| 2675 | if (name.IsEmpty()) |
| 2676 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2677 | |
| 2678 | // Remember how many sc_list are in the list before we search in case |
| 2679 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2680 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2681 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2682 | |
| 2683 | const uint32_t original_size = sc_list.GetSize(); |
| 2684 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2685 | DWARFDebugInfo* info = DebugInfo(); |
| 2686 | if (info == NULL) |
| 2687 | return 0; |
| 2688 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2689 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2690 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2691 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2692 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2693 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2694 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2695 | |
| 2696 | DIEArray die_offsets; |
| 2697 | |
| 2698 | uint32_t num_matches = 0; |
| 2699 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2700 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2701 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2702 | // If they asked for the full name, match what they typed. At some point we may |
| 2703 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 2704 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2705 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2706 | for (uint32_t i = 0; i < num_matches; i++) |
| 2707 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2708 | const dw_offset_t die_offset = die_offsets[i]; |
| 2709 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2710 | if (die) |
| 2711 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2712 | if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) |
| 2713 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2714 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2715 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2716 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2717 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2718 | resolved_dies.insert(die); |
| 2719 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2720 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2721 | else |
| 2722 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2723 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2724 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2725 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2726 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2727 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2728 | |
| 2729 | if (name_type_mask & eFunctionNameTypeSelector) |
| 2730 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2731 | if (parent_decl_ctx && parent_decl_ctx->IsValid()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2732 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2733 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2734 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2735 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 2736 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2737 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2738 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2739 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2740 | const dw_offset_t die_offset = die_offsets[i]; |
| 2741 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2742 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2743 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2744 | const char *die_name = die->GetName(this, dwarf_cu); |
| 2745 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2746 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2747 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2748 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2749 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2750 | resolved_dies.insert(die); |
| 2751 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2752 | } |
| 2753 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2754 | else |
| 2755 | { |
| 2756 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2757 | die_offset, name_cstr); |
| 2758 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2759 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2760 | die_offsets.clear(); |
| 2761 | } |
| 2762 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2763 | if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2764 | { |
| 2765 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 2766 | // extract the base name, look that up, and if there is any other information in the name we were |
| 2767 | // passed in we have to post-filter based on that. |
| 2768 | |
| 2769 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 2770 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2771 | |
| 2772 | for (uint32_t i = 0; i < num_matches; i++) |
| 2773 | { |
| 2774 | const dw_offset_t die_offset = die_offsets[i]; |
| 2775 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2776 | if (die) |
| 2777 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2778 | if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) |
| 2779 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2780 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2781 | |
| 2782 | // If we get to here, the die is good, and we should add it: |
| 2783 | if (resolved_dies.find(die) == resolved_dies.end()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2784 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2785 | { |
| 2786 | bool keep_die = true; |
| 2787 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 2788 | { |
| 2789 | // We are looking for either basenames or methods, so we need to |
| 2790 | // trim out the ones we won't want by looking at the type |
| 2791 | SymbolContext sc; |
| 2792 | if (sc_list.GetLastContext(sc)) |
| 2793 | { |
| 2794 | if (sc.block) |
| 2795 | { |
| 2796 | // We have an inlined function |
| 2797 | } |
| 2798 | else if (sc.function) |
| 2799 | { |
| 2800 | Type *type = sc.function->GetType(); |
| 2801 | |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2802 | if (type) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2803 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2804 | CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID()); |
| 2805 | if (decl_ctx.IsStructUnionOrClass()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2806 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2807 | if (name_type_mask & eFunctionNameTypeBase) |
| 2808 | { |
| 2809 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2810 | keep_die = false; |
| 2811 | } |
| 2812 | } |
| 2813 | else |
| 2814 | { |
| 2815 | if (name_type_mask & eFunctionNameTypeMethod) |
| 2816 | { |
| 2817 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2818 | keep_die = false; |
| 2819 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | else |
| 2823 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2824 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", |
| 2825 | die_offset); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | } |
| 2829 | } |
| 2830 | if (keep_die) |
| 2831 | resolved_dies.insert(die); |
| 2832 | } |
| 2833 | } |
| 2834 | else |
| 2835 | { |
| 2836 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2837 | die_offset, name_cstr); |
| 2838 | } |
| 2839 | } |
| 2840 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2841 | } |
| 2842 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2843 | } |
| 2844 | else |
| 2845 | { |
| 2846 | |
| 2847 | // Index the DWARF if we haven't already |
| 2848 | if (!m_indexed) |
| 2849 | Index (); |
| 2850 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2851 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2852 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2853 | FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2854 | |
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 2855 | // FIXME Temporary workaround for global/anonymous namespace |
| Robert Flack | 5cbd3bf | 2015-05-13 18:20:02 +0000 | [diff] [blame] | 2856 | // functions debugging FreeBSD and Linux binaries. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2857 | // If we didn't find any functions in the global namespace try |
| 2858 | // looking in the basename index but ignore any returned |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2859 | // functions that have a namespace but keep functions which |
| 2860 | // have an anonymous namespace |
| 2861 | // TODO: The arch in the object file isn't correct for MSVC |
| 2862 | // binaries on windows, we should find a way to make it |
| 2863 | // correct and handle those symbols as well. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2864 | if (sc_list.GetSize() == 0) |
| 2865 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2866 | ArchSpec arch; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2867 | if (!parent_decl_ctx && |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2868 | GetObjectFile()->GetArchitecture(arch) && |
| 2869 | (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() || |
| 2870 | arch.GetMachine() == llvm::Triple::hexagon)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2871 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2872 | SymbolContextList temp_sc_list; |
| 2873 | FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2874 | SymbolContext sc; |
| 2875 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 2876 | { |
| 2877 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 2878 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 2879 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 2880 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2881 | // Mangled names on Linux and FreeBSD are of the form: |
| 2882 | // _ZN18function_namespace13function_nameEv. |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 2883 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 2884 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2885 | { |
| 2886 | sc_list.Append(sc); |
| 2887 | } |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | } |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2892 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2893 | DIEArray die_offsets; |
| 2894 | DWARFCompileUnit *dwarf_cu = NULL; |
| 2895 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2896 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2897 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2898 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2899 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2900 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2901 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 2902 | if (die) |
| 2903 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2904 | if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) |
| 2905 | continue; // The containing decl contexts don't match |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2906 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2907 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2908 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2909 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2910 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2911 | resolved_dies.insert(die); |
| 2912 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2913 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2914 | } |
| 2915 | die_offsets.clear(); |
| 2916 | } |
| 2917 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2918 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2919 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2920 | if (parent_decl_ctx && parent_decl_ctx->IsValid()) |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2921 | return 0; // no methods in namespaces |
| 2922 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2923 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2924 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2925 | for (uint32_t i = 0; i < num_base; i++) |
| 2926 | { |
| 2927 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 2928 | if (die) |
| 2929 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2930 | // If we get to here, the die is good, and we should add it: |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2931 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2932 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2933 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2934 | resolved_dies.insert(die); |
| 2935 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2936 | } |
| 2937 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2938 | } |
| 2939 | die_offsets.clear(); |
| 2940 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2941 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2942 | if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid())) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2943 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2944 | FindFunctions (name, m_function_selector_index, include_inlines, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2949 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2950 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 2951 | |
| 2952 | if (log && num_matches > 0) |
| 2953 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2954 | GetObjectFile()->GetModule()->LogMessage (log, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2955 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2956 | name.GetCString(), |
| 2957 | name_type_mask, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2958 | include_inlines, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2959 | append, |
| 2960 | num_matches); |
| 2961 | } |
| 2962 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2965 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2966 | SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2967 | { |
| 2968 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2969 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 2970 | regex.GetText()); |
| 2971 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2972 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2973 | |
| 2974 | if (log) |
| 2975 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2976 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2977 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 2978 | regex.GetText(), |
| 2979 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2983 | // If we aren't appending the results to this list, then clear the list |
| 2984 | if (!append) |
| 2985 | sc_list.Clear(); |
| 2986 | |
| 2987 | // Remember how many sc_list are in the list before we search in case |
| 2988 | // we are appending the results to a variable list. |
| 2989 | uint32_t original_size = sc_list.GetSize(); |
| 2990 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2991 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2992 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2993 | if (m_apple_names_ap.get()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2994 | FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2995 | } |
| 2996 | else |
| 2997 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2998 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2999 | if (!m_indexed) |
| 3000 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3001 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3002 | FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3003 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 3004 | FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3005 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3006 | |
| 3007 | // Return the number of variable that were appended to the list |
| 3008 | return sc_list.GetSize() - original_size; |
| 3009 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3010 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3011 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3012 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3013 | const ConstString &name, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3014 | const CompilerDeclContext *parent_decl_ctx, |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3015 | bool append, |
| 3016 | uint32_t max_matches, |
| 3017 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3018 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3019 | DWARFDebugInfo* info = DebugInfo(); |
| 3020 | if (info == NULL) |
| 3021 | return 0; |
| 3022 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3023 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3024 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3025 | if (log) |
| 3026 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3027 | if (parent_decl_ctx) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3028 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3029 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3030 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3031 | static_cast<const void*>(parent_decl_ctx), |
| 3032 | parent_decl_ctx->GetName().AsCString("<NULL>"), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3033 | append, max_matches); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3034 | else |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3035 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3036 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3037 | name.GetCString(), append, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3038 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3041 | // If we aren't appending the results to this list, then clear the list |
| 3042 | if (!append) |
| 3043 | types.Clear(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3044 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3045 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3046 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3047 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3048 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3049 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3050 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3051 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3052 | if (m_apple_types_ap.get()) |
| 3053 | { |
| 3054 | const char *name_cstr = name.GetCString(); |
| 3055 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3056 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3057 | } |
| 3058 | else |
| 3059 | { |
| 3060 | if (!m_indexed) |
| 3061 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3062 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3063 | m_type_index.Find (name, die_offsets); |
| 3064 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3065 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3066 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3067 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3068 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3069 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3070 | const uint32_t initial_types_size = types.GetSize(); |
| 3071 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3072 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3073 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3074 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3075 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3076 | const dw_offset_t die_offset = die_offsets[i]; |
| 3077 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3078 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3079 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3080 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3081 | if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) |
| 3082 | continue; // The containing decl contexts don't match |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3083 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3084 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3085 | if (matching_type) |
| 3086 | { |
| 3087 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3088 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3089 | if (types.GetSize() >= max_matches) |
| 3090 | break; |
| 3091 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3092 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3093 | else |
| 3094 | { |
| 3095 | if (m_using_apple_tables) |
| 3096 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3097 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3098 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3102 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3103 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3104 | if (log && num_matches) |
| 3105 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3106 | if (parent_decl_ctx) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3107 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3108 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3109 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3110 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3111 | static_cast<const void*>(parent_decl_ctx), |
| 3112 | parent_decl_ctx->GetName().AsCString("<NULL>"), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3113 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3114 | num_matches); |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3118 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3119 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3120 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3121 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3122 | num_matches); |
| 3123 | } |
| 3124 | } |
| 3125 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3126 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3127 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3131 | CompilerDeclContext |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3132 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3133 | const ConstString &name, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3134 | const CompilerDeclContext *parent_decl_ctx) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3135 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3136 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3137 | |
| 3138 | if (log) |
| 3139 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3140 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3141 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3142 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3145 | CompilerDeclContext namespace_decl_ctx; |
| 3146 | |
| 3147 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) |
| 3148 | return namespace_decl_ctx; |
| 3149 | |
| 3150 | |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3151 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3152 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3153 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3154 | DIEArray die_offsets; |
| 3155 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3156 | // Index if we already haven't to make sure the compile units |
| 3157 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3158 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3159 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3160 | if (m_apple_namespaces_ap.get()) |
| 3161 | { |
| 3162 | const char *name_cstr = name.GetCString(); |
| 3163 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3164 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3165 | } |
| 3166 | else |
| 3167 | { |
| 3168 | if (!m_indexed) |
| 3169 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3170 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3171 | m_namespace_index.Find (name, die_offsets); |
| 3172 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3173 | |
| 3174 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3175 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3176 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3177 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3178 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3179 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3180 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3181 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3182 | const dw_offset_t die_offset = die_offsets[i]; |
| 3183 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3184 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3185 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3186 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3187 | if (!DIEInDeclContext(parent_decl_ctx, dwarf_cu, die)) |
| 3188 | continue; // The containing decl contexts don't match |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3189 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3190 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3191 | |
| 3192 | if (type_system) |
| 3193 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3194 | namespace_decl_ctx = type_system->GetDeclContextForUIDFromDWARF(this, dwarf_cu, die); |
| 3195 | if (namespace_decl_ctx) |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3196 | break; |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3197 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3198 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3199 | else |
| 3200 | { |
| 3201 | if (m_using_apple_tables) |
| 3202 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3203 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3204 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3208 | } |
| 3209 | } |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3210 | } |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3211 | if (log && namespace_decl_ctx) |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3212 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3213 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3214 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"", |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3215 | name.GetCString(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3216 | static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()), |
| 3217 | static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()), |
| 3218 | namespace_decl_ctx.GetName().AsCString("<NULL>")); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3221 | return namespace_decl_ctx; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3224 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3225 | SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3226 | { |
| 3227 | // Remember how many sc_list are in the list before we search in case |
| 3228 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3229 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3230 | |
| 3231 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3232 | // Parse all of the types we found from the pubtypes matches |
| 3233 | uint32_t i; |
| 3234 | uint32_t num_matches = 0; |
| 3235 | for (i = 0; i < num_die_offsets; ++i) |
| 3236 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3237 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3238 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3239 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3240 | // We found a type pointer, now find the shared pointer form our type list |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3241 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3242 | ++num_matches; |
| 3243 | if (num_matches >= max_matches) |
| 3244 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3249 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3252 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3253 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3254 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3255 | { |
| 3256 | TypeSP type_sp; |
| 3257 | if (die != NULL) |
| 3258 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3259 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3260 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3261 | if (type_ptr == NULL) |
| 3262 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3263 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3264 | assert (lldb_cu); |
| 3265 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3266 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3267 | } |
| 3268 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3269 | { |
| 3270 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3271 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | } |
| 3275 | return type_sp; |
| 3276 | } |
| 3277 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3278 | |
| 3279 | const DWARFDebugInfoEntry * |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3280 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3281 | { |
| 3282 | if (cu && die) |
| 3283 | { |
| 3284 | const DWARFDebugInfoEntry * const decl_die = die; |
| 3285 | |
| 3286 | while (die != NULL) |
| 3287 | { |
| 3288 | // If this is the original DIE that we are searching for a declaration |
| 3289 | // for, then don't look in the cache as we don't want our own decl |
| 3290 | // context to be our decl context... |
| 3291 | if (decl_die != die) |
| 3292 | { |
| 3293 | switch (die->Tag()) |
| 3294 | { |
| 3295 | case DW_TAG_compile_unit: |
| 3296 | case DW_TAG_namespace: |
| 3297 | case DW_TAG_structure_type: |
| 3298 | case DW_TAG_union_type: |
| 3299 | case DW_TAG_class_type: |
| 3300 | return die; |
| 3301 | |
| 3302 | default: |
| 3303 | break; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 3308 | if (die_offset != DW_INVALID_OFFSET) |
| 3309 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3310 | DWARFCompileUnit *spec_cu = const_cast<DWARFCompileUnit *>(cu); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3311 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 3312 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 3313 | if (spec_die_decl_ctx_die) |
| 3314 | return spec_die_decl_ctx_die; |
| 3315 | } |
| 3316 | |
| 3317 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 3318 | if (die_offset != DW_INVALID_OFFSET) |
| 3319 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3320 | DWARFCompileUnit *abs_cu = const_cast<DWARFCompileUnit *>(cu); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3321 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 3322 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 3323 | if (abs_die_decl_ctx_die) |
| 3324 | return abs_die_decl_ctx_die; |
| 3325 | } |
| 3326 | |
| 3327 | die = die->GetParent(); |
| 3328 | } |
| 3329 | } |
| 3330 | return NULL; |
| 3331 | } |
| 3332 | |
| 3333 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3334 | Symbol * |
| 3335 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 3336 | { |
| 3337 | Symbol *objc_class_symbol = NULL; |
| 3338 | if (m_obj_file) |
| 3339 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 3340 | Symtab *symtab = m_obj_file->GetSymtab (); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3341 | if (symtab) |
| 3342 | { |
| 3343 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 3344 | eSymbolTypeObjCClass, |
| 3345 | Symtab::eDebugNo, |
| 3346 | Symtab::eVisibilityAny); |
| 3347 | } |
| 3348 | } |
| 3349 | return objc_class_symbol; |
| 3350 | } |
| 3351 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3352 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 3353 | // then we can end up looking through all class types for a complete type and never find |
| 3354 | // the full definition. We need to know if this attribute is supported, so we determine |
| 3355 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 3356 | // if we are doing darwin DWARF in .o file debugging. |
| 3357 | bool |
| 3358 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 3359 | { |
| 3360 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 3361 | { |
| 3362 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 3363 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3364 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3365 | else |
| 3366 | { |
| 3367 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3368 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3369 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3370 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3371 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 3372 | if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3373 | { |
| 3374 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3375 | break; |
| 3376 | } |
| 3377 | } |
| 3378 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3379 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3380 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 3381 | } |
| 3382 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 3383 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3384 | |
| 3385 | // This function can be used when a DIE is found that is a forward declaration |
| 3386 | // DIE and we want to try and find a type that has the complete definition. |
| 3387 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3388 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 3389 | const ConstString &type_name, |
| 3390 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3391 | { |
| 3392 | |
| 3393 | TypeSP type_sp; |
| 3394 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3395 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3396 | return type_sp; |
| 3397 | |
| 3398 | DIEArray die_offsets; |
| 3399 | |
| 3400 | if (m_using_apple_tables) |
| 3401 | { |
| 3402 | if (m_apple_types_ap.get()) |
| 3403 | { |
| 3404 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 3405 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | else |
| 3409 | { |
| 3410 | if (!m_indexed) |
| 3411 | Index (); |
| 3412 | |
| 3413 | m_type_index.Find (type_name, die_offsets); |
| 3414 | } |
| 3415 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3416 | const size_t num_matches = die_offsets.size(); |
| 3417 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3418 | DWARFCompileUnit* type_cu = NULL; |
| 3419 | const DWARFDebugInfoEntry* type_die = NULL; |
| 3420 | if (num_matches) |
| 3421 | { |
| 3422 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3423 | for (size_t i=0; i<num_matches; ++i) |
| 3424 | { |
| 3425 | const dw_offset_t die_offset = die_offsets[i]; |
| 3426 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 3427 | |
| 3428 | if (type_die) |
| 3429 | { |
| 3430 | bool try_resolving_type = false; |
| 3431 | |
| 3432 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 3433 | if (type_die != die) |
| 3434 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3435 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3436 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3437 | case DW_TAG_class_type: |
| 3438 | case DW_TAG_structure_type: |
| 3439 | try_resolving_type = true; |
| 3440 | break; |
| 3441 | default: |
| 3442 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | if (try_resolving_type) |
| 3447 | { |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3448 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3449 | try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3450 | |
| 3451 | if (try_resolving_type) |
| 3452 | { |
| 3453 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 3454 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3455 | { |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 3456 | DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3457 | MakeUserID(die->GetOffset()), |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3458 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3459 | MakeUserID(type_die->GetOffset()), |
| 3460 | MakeUserID(type_cu->GetOffset())); |
| 3461 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3462 | if (die) |
| 3463 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3464 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3465 | break; |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | else |
| 3471 | { |
| 3472 | if (m_using_apple_tables) |
| 3473 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3474 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3475 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | } |
| 3480 | } |
| 3481 | return type_sp; |
| 3482 | } |
| 3483 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3484 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3485 | //---------------------------------------------------------------------- |
| 3486 | // This function helps to ensure that the declaration contexts match for |
| 3487 | // two different DIEs. Often times debug information will refer to a |
| 3488 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 3489 | // There will often be a declaration of that type elsewhere that has the |
| 3490 | // full definition. When we go looking for the full type "my_struct", we |
| 3491 | // will find one or more matches in the accelerator tables and we will |
| 3492 | // then need to make sure the type was in the same declaration context |
| 3493 | // as the original DIE. This function can efficiently compare two DIEs |
| 3494 | // and will return true when the declaration context matches, and false |
| 3495 | // when they don't. |
| 3496 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3497 | bool |
| 3498 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 3499 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 3500 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3501 | if (die1 == die2) |
| 3502 | return true; |
| 3503 | |
| 3504 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 3505 | // You can't and shouldn't call this function with a compile unit from |
| 3506 | // two different SymbolFileDWARF instances. |
| 3507 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 3508 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 3509 | #endif |
| 3510 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3511 | DWARFDIECollection decl_ctx_1; |
| 3512 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3513 | //The declaration DIE stack is a stack of the declaration context |
| 3514 | // DIEs all the way back to the compile unit. If a type "T" is |
| 3515 | // declared inside a class "B", and class "B" is declared inside |
| 3516 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 3517 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 3518 | // |
| 3519 | // [0] DW_TAG_class_type for "B" |
| 3520 | // [1] DW_TAG_class_type for "A" |
| 3521 | // [2] DW_TAG_namespace for "lldb" |
| 3522 | // [3] DW_TAG_compile_unit for the source file. |
| 3523 | // |
| 3524 | // We grab both contexts and make sure that everything matches |
| 3525 | // all the way back to the compiler unit. |
| 3526 | |
| 3527 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3528 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 3529 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3530 | // Make sure the context arrays have the same size, otherwise |
| 3531 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3532 | const size_t count1 = decl_ctx_1.Size(); |
| 3533 | const size_t count2 = decl_ctx_2.Size(); |
| 3534 | if (count1 != count2) |
| 3535 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3536 | |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3537 | // Make sure the DW_TAG values match all the way back up the |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3538 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3539 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 3540 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 3541 | size_t i; |
| 3542 | for (i=0; i<count1; i++) |
| 3543 | { |
| 3544 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 3545 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 3546 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 3547 | return false; |
| 3548 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3549 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3550 | |
| 3551 | // Make sure the top item in the decl context die array is always |
| 3552 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 3553 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3554 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3555 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3556 | #endif |
| 3557 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3558 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3559 | for (i=0; i<count1 - 1; i++) |
| 3560 | { |
| 3561 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 3562 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 3563 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 3564 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3565 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 3566 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3567 | if (name1 == name2) |
| 3568 | continue; |
| 3569 | |
| 3570 | // Name pointers are not equal, so only compare the strings |
| 3571 | // if both are not NULL. |
| 3572 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3573 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3574 | // If the strings don't compare, we are done... |
| 3575 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3576 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3577 | } |
| 3578 | else |
| 3579 | { |
| 3580 | // One name was NULL while the other wasn't |
| 3581 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3582 | } |
| 3583 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3584 | // We made it through all of the checks and the declaration contexts |
| 3585 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3586 | return true; |
| 3587 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 3588 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3589 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3590 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3591 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 3592 | { |
| 3593 | TypeSP type_sp; |
| 3594 | |
| 3595 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 3596 | if (dwarf_decl_ctx_count > 0) |
| 3597 | { |
| 3598 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 3599 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 3600 | |
| 3601 | if (type_name) |
| 3602 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3603 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3604 | if (log) |
| 3605 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3606 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3607 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 3608 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3609 | dwarf_decl_ctx.GetQualifiedName()); |
| 3610 | } |
| 3611 | |
| 3612 | DIEArray die_offsets; |
| 3613 | |
| 3614 | if (m_using_apple_tables) |
| 3615 | { |
| 3616 | if (m_apple_types_ap.get()) |
| 3617 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3618 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 3619 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 3620 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3621 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3622 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 3623 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 3624 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3625 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3626 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 3627 | } |
| 3628 | else if (has_tag) |
| 3629 | { |
| 3630 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3631 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3632 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 3633 | } |
| 3634 | else |
| 3635 | { |
| 3636 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 3637 | } |
| 3638 | } |
| 3639 | } |
| 3640 | else |
| 3641 | { |
| 3642 | if (!m_indexed) |
| 3643 | Index (); |
| 3644 | |
| 3645 | m_type_index.Find (type_name, die_offsets); |
| 3646 | } |
| 3647 | |
| 3648 | const size_t num_matches = die_offsets.size(); |
| 3649 | |
| 3650 | |
| 3651 | DWARFCompileUnit* type_cu = NULL; |
| 3652 | const DWARFDebugInfoEntry* type_die = NULL; |
| 3653 | if (num_matches) |
| 3654 | { |
| 3655 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3656 | for (size_t i=0; i<num_matches; ++i) |
| 3657 | { |
| 3658 | const dw_offset_t die_offset = die_offsets[i]; |
| 3659 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 3660 | |
| 3661 | if (type_die) |
| 3662 | { |
| 3663 | bool try_resolving_type = false; |
| 3664 | |
| 3665 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 3666 | const dw_tag_t type_tag = type_die->Tag(); |
| 3667 | // Make sure the tags match |
| 3668 | if (type_tag == tag) |
| 3669 | { |
| 3670 | // The tags match, lets try resolving this type |
| 3671 | try_resolving_type = true; |
| 3672 | } |
| 3673 | else |
| 3674 | { |
| 3675 | // The tags don't match, but we need to watch our for a |
| 3676 | // forward declaration for a struct and ("struct foo") |
| 3677 | // ends up being a class ("class foo { ... };") or |
| 3678 | // vice versa. |
| 3679 | switch (type_tag) |
| 3680 | { |
| 3681 | case DW_TAG_class_type: |
| 3682 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 3683 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 3684 | break; |
| 3685 | case DW_TAG_structure_type: |
| 3686 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 3687 | try_resolving_type = (tag == DW_TAG_class_type); |
| 3688 | break; |
| 3689 | default: |
| 3690 | // Tags don't match, don't event try to resolve |
| 3691 | // using this type whose name matches.... |
| 3692 | break; |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | if (try_resolving_type) |
| 3697 | { |
| 3698 | DWARFDeclContext type_dwarf_decl_ctx; |
| 3699 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 3700 | |
| 3701 | if (log) |
| 3702 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3703 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3704 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 3705 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3706 | dwarf_decl_ctx.GetQualifiedName(), |
| 3707 | type_die->GetOffset(), |
| 3708 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 3709 | } |
| 3710 | |
| 3711 | // Make sure the decl contexts match all the way up |
| 3712 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 3713 | { |
| 3714 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 3715 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3716 | { |
| 3717 | type_sp = resolved_type->shared_from_this(); |
| 3718 | break; |
| 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | else |
| 3723 | { |
| 3724 | if (log) |
| 3725 | { |
| 3726 | std::string qualified_name; |
| 3727 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3728 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3729 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 3730 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3731 | dwarf_decl_ctx.GetQualifiedName(), |
| 3732 | type_die->GetOffset(), |
| 3733 | qualified_name.c_str()); |
| 3734 | } |
| 3735 | } |
| 3736 | } |
| 3737 | else |
| 3738 | { |
| 3739 | if (m_using_apple_tables) |
| 3740 | { |
| 3741 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3742 | die_offset, type_name.GetCString()); |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | } |
| 3747 | } |
| 3748 | } |
| 3749 | } |
| 3750 | return type_sp; |
| 3751 | } |
| 3752 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3753 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3754 | SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3755 | { |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3756 | TypeSP type_sp; |
| 3757 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3758 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3759 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3760 | if (type_system) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3761 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3762 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3763 | type_sp = type_system->ParseTypeFromDWARF (sc, this, dwarf_cu, die, log, type_is_new_ptr); |
| 3764 | if (type_sp) |
| 3765 | { |
| 3766 | TypeList* type_list = GetTypeList(); |
| 3767 | if (type_list) |
| 3768 | type_list->Insert(type_sp); |
| 3769 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3770 | } |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3771 | |
| 3772 | return type_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3776 | SymbolFileDWARF::ParseTypes |
| 3777 | ( |
| 3778 | const SymbolContext& sc, |
| 3779 | DWARFCompileUnit* dwarf_cu, |
| 3780 | const DWARFDebugInfoEntry *die, |
| 3781 | bool parse_siblings, |
| 3782 | bool parse_children |
| 3783 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3784 | { |
| 3785 | size_t types_added = 0; |
| 3786 | while (die != NULL) |
| 3787 | { |
| 3788 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3789 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3790 | { |
| 3791 | if (type_is_new) |
| 3792 | ++types_added; |
| 3793 | } |
| 3794 | |
| 3795 | if (parse_children && die->HasChildren()) |
| 3796 | { |
| 3797 | if (die->Tag() == DW_TAG_subprogram) |
| 3798 | { |
| 3799 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3800 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3801 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 3802 | } |
| 3803 | else |
| 3804 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 3805 | } |
| 3806 | |
| 3807 | if (parse_siblings) |
| 3808 | die = die->GetSibling(); |
| 3809 | else |
| 3810 | die = NULL; |
| 3811 | } |
| 3812 | return types_added; |
| 3813 | } |
| 3814 | |
| 3815 | |
| 3816 | size_t |
| 3817 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 3818 | { |
| 3819 | assert(sc.comp_unit && sc.function); |
| 3820 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3821 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3822 | if (dwarf_cu) |
| 3823 | { |
| 3824 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 3825 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 3826 | if (function_die) |
| 3827 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 3828 | ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3829 | } |
| 3830 | } |
| 3831 | |
| 3832 | return functions_added; |
| 3833 | } |
| 3834 | |
| 3835 | |
| 3836 | size_t |
| 3837 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 3838 | { |
| 3839 | // At least a compile unit must be valid |
| 3840 | assert(sc.comp_unit); |
| 3841 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3842 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3843 | if (dwarf_cu) |
| 3844 | { |
| 3845 | if (sc.function) |
| 3846 | { |
| 3847 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 3848 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 3849 | if (func_die && func_die->HasChildren()) |
| 3850 | { |
| 3851 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 3852 | } |
| 3853 | } |
| 3854 | else |
| 3855 | { |
| 3856 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 3857 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 3858 | { |
| 3859 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 3860 | } |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | return types_added; |
| 3865 | } |
| 3866 | |
| 3867 | size_t |
| 3868 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 3869 | { |
| 3870 | if (sc.comp_unit != NULL) |
| 3871 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 3872 | DWARFDebugInfo* info = DebugInfo(); |
| 3873 | if (info == NULL) |
| 3874 | return 0; |
| 3875 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3876 | if (sc.function) |
| 3877 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3878 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 3879 | |
| 3880 | if (dwarf_cu == NULL) |
| 3881 | return 0; |
| 3882 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3883 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 3884 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3885 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 3886 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3887 | { |
| 3888 | const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 3889 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3890 | // Let all blocks know they have parse all their variables |
| 3891 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 3892 | return num_variables; |
| 3893 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3894 | } |
| 3895 | else if (sc.comp_unit) |
| 3896 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3897 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 3898 | |
| 3899 | if (dwarf_cu == NULL) |
| 3900 | return 0; |
| 3901 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3902 | uint32_t vars_added = 0; |
| 3903 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 3904 | |
| 3905 | if (variables.get() == NULL) |
| 3906 | { |
| 3907 | variables.reset(new VariableList()); |
| 3908 | sc.comp_unit->SetVariableList(variables); |
| 3909 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3910 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 3911 | const DWARFDebugInfoEntry* die = NULL; |
| 3912 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3913 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3914 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3915 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3916 | { |
| 3917 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3918 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 3919 | dwarf_cu->GetNextCompileUnitOffset(), |
| 3920 | hash_data_array)) |
| 3921 | { |
| 3922 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3923 | } |
| 3924 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3925 | } |
| 3926 | else |
| 3927 | { |
| 3928 | // Index if we already haven't to make sure the compile units |
| 3929 | // get indexed and make their global DIE index list |
| 3930 | if (!m_indexed) |
| 3931 | Index (); |
| 3932 | |
| 3933 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 3934 | dwarf_cu->GetNextCompileUnitOffset(), |
| 3935 | die_offsets); |
| 3936 | } |
| 3937 | |
| 3938 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3939 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3940 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3941 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3942 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3943 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3944 | const dw_offset_t die_offset = die_offsets[i]; |
| 3945 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3946 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3947 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3948 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 3949 | if (var_sp) |
| 3950 | { |
| 3951 | variables->AddVariableIfUnique (var_sp); |
| 3952 | ++vars_added; |
| 3953 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3954 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3955 | else |
| 3956 | { |
| 3957 | if (m_using_apple_tables) |
| 3958 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3959 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | } |
| 3966 | return vars_added; |
| 3967 | } |
| 3968 | } |
| 3969 | return 0; |
| 3970 | } |
| 3971 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3972 | VariableSP |
| 3973 | SymbolFileDWARF::ParseVariableDIE |
| 3974 | ( |
| 3975 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 3976 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 3977 | const DWARFDebugInfoEntry *die, |
| 3978 | const lldb::addr_t func_low_pc |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3979 | ) |
| 3980 | { |
| Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 3981 | VariableSP var_sp (m_die_to_variable_sp[die]); |
| 3982 | if (var_sp) |
| 3983 | return var_sp; // Already been parsed! |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3984 | |
| 3985 | const dw_tag_t tag = die->Tag(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 3986 | ModuleSP module = GetObjectFile()->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3987 | |
| 3988 | if ((tag == DW_TAG_variable) || |
| 3989 | (tag == DW_TAG_constant) || |
| 3990 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3991 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3992 | DWARFDebugInfoEntry::Attributes attributes; |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 3993 | const size_t num_attributes = die->GetAttributes(this, |
| 3994 | dwarf_cu, |
| 3995 | DWARFFormValue::FixedFormSizes(), |
| 3996 | attributes); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3997 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3998 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3999 | const char *name = NULL; |
| 4000 | const char *mangled = NULL; |
| 4001 | Declaration decl; |
| 4002 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4003 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4004 | DWARFExpression location; |
| 4005 | bool is_external = false; |
| 4006 | bool is_artificial = false; |
| 4007 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4008 | bool has_explicit_location = false; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4009 | DWARFFormValue const_value; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 4010 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4011 | |
| 4012 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4013 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4014 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4015 | DWARFFormValue form_value; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4016 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4017 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4018 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4019 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4020 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4021 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4022 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4023 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4024 | case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 4025 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4026 | case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4027 | case DW_AT_type: type_uid = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4028 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4029 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4030 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 4031 | if (!has_explicit_location) |
| 4032 | { |
| 4033 | location_is_const_value_data = true; |
| 4034 | // The constant value will be either a block, a data value or a string. |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4035 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4036 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 4037 | { |
| 4038 | // Retrieve the value as a block expression. |
| 4039 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 4040 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4041 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4042 | } |
| 4043 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 4044 | { |
| 4045 | // Retrieve the value as a data expression. |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 4046 | DWARFFormValue::FixedFormSizes fixed_form_sizes = |
| 4047 | DWARFFormValue::GetFixedFormSizesForAddressSize ( |
| 4048 | attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), |
| 4049 | attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4050 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 4051 | uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4052 | if (data_length == 0) |
| 4053 | { |
| 4054 | const uint8_t *data_pointer = form_value.BlockData(); |
| 4055 | if (data_pointer) |
| 4056 | { |
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 4057 | form_value.Unsigned(); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4058 | } |
| 4059 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 4060 | { |
| 4061 | // we need to get the byte size of the type later after we create the variable |
| 4062 | const_value = form_value; |
| 4063 | } |
| 4064 | } |
| 4065 | else |
| 4066 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4067 | } |
| 4068 | else |
| 4069 | { |
| 4070 | // Retrieve the value as a string expression. |
| 4071 | if (form_value.Form() == DW_FORM_strp) |
| 4072 | { |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 4073 | DWARFFormValue::FixedFormSizes fixed_form_sizes = |
| 4074 | DWARFFormValue::GetFixedFormSizesForAddressSize ( |
| 4075 | attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), |
| 4076 | attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4077 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| Tamas Berghammer | b7c6465 | 2015-08-25 11:45:46 +0000 | [diff] [blame^] | 4078 | uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4079 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4080 | } |
| 4081 | else |
| 4082 | { |
| 4083 | const char *str = form_value.AsCString(&debug_info_data); |
| 4084 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 4085 | uint32_t string_length = strlen(str) + 1; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4086 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4091 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4092 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4093 | location_is_const_value_data = false; |
| 4094 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4095 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4096 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4097 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4098 | |
| 4099 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 4100 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4101 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4102 | } |
| 4103 | else |
| 4104 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4105 | const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4106 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 4107 | |
| 4108 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 4109 | if (loc_list_length > 0) |
| 4110 | { |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4111 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4112 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4113 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4114 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4115 | } |
| 4116 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4117 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4118 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4119 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 4120 | case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4121 | case DW_AT_declaration: |
| 4122 | case DW_AT_description: |
| 4123 | case DW_AT_endianity: |
| 4124 | case DW_AT_segment: |
| 4125 | case DW_AT_start_scope: |
| 4126 | case DW_AT_visibility: |
| 4127 | default: |
| 4128 | case DW_AT_abstract_origin: |
| 4129 | case DW_AT_sibling: |
| 4130 | case DW_AT_specification: |
| 4131 | break; |
| 4132 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4133 | } |
| 4134 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4135 | |
| Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 4136 | const DWARFDebugInfoEntry *parent_context_die = GetDeclContextDIEContainingDIE(dwarf_cu, die); |
| 4137 | bool is_static_member = die->GetParent()->Tag() == DW_TAG_compile_unit && (parent_context_die->Tag() == DW_TAG_class_type || parent_context_die->Tag() == DW_TAG_structure_type); |
| 4138 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4139 | ValueType scope = eValueTypeInvalid; |
| 4140 | |
| 4141 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 4142 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4143 | SymbolContextScope * symbol_context_scope = NULL; |
| 4144 | |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 4145 | if (!mangled) |
| 4146 | { |
| 4147 | // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to |
| 4148 | // generate fully qualified names of global variables with commands like "frame var j". |
| 4149 | // For example, if j were an int variable holding a value 4 and declared in a namespace |
| 4150 | // B which in turn is contained in a namespace A, the command "frame var j" returns |
| 4151 | // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able |
| 4152 | // to generate a fully qualified name from the declaration context. |
| 4153 | if (die->GetParent()->Tag() == DW_TAG_compile_unit && |
| 4154 | LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) |
| 4155 | { |
| 4156 | DWARFDeclContext decl_ctx; |
| 4157 | |
| 4158 | die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); |
| 4159 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); |
| 4160 | } |
| 4161 | } |
| 4162 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4163 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 4164 | // or static variable, so we have to do a little digging by |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4165 | // looking at the location of a variable to see if it contains |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4166 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 4167 | // somewhere because clang likes to combine small global variables |
| 4168 | // into the same symbol and have locations like: |
| 4169 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 4170 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 4171 | // the location to see if it contains a DW_OP_addr opcode, and |
| 4172 | // then we can correctly classify our variables. |
| 4173 | if (tag == DW_TAG_formal_parameter) |
| 4174 | scope = eValueTypeVariableArgument; |
| 4175 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4176 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4177 | bool op_error = false; |
| 4178 | // Check if the location has a DW_OP_addr with any address value... |
| 4179 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 4180 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4181 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4182 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 4183 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 4184 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4185 | StreamString strm; |
| 4186 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| 4187 | GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 4188 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4189 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4190 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4191 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 4192 | { |
| 4193 | if (is_external) |
| 4194 | scope = eValueTypeVariableGlobal; |
| 4195 | else |
| 4196 | scope = eValueTypeVariableStatic; |
| 4197 | |
| 4198 | |
| 4199 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 4200 | |
| 4201 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4202 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4203 | // When leaving the DWARF in the .o files on darwin, |
| 4204 | // when we have a global variable that wasn't initialized, |
| 4205 | // the .o file might not have allocated a virtual |
| 4206 | // address for the global variable. In this case it will |
| 4207 | // have created a symbol for the global variable |
| 4208 | // that is undefined/data and external and the value will |
| 4209 | // be the byte size of the variable. When we do the |
| 4210 | // address map in SymbolFileDWARFDebugMap we rely on |
| 4211 | // having an address, we need to do some magic here |
| 4212 | // so we can get the correct address for our global |
| 4213 | // variable. The address for all of these entries |
| 4214 | // will be zero, and there will be an undefined symbol |
| 4215 | // in this object file, and the executable will have |
| 4216 | // a matching symbol with a good address. So here we |
| 4217 | // dig up the correct address and replace it in the |
| 4218 | // location for the variable, and set the variable's |
| 4219 | // symbol context scope to be that of the main executable |
| 4220 | // so the file address will resolve correctly. |
| 4221 | bool linked_oso_file_addr = false; |
| 4222 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4223 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4224 | // we have a possible uninitialized extern global |
| 4225 | ConstString const_name(mangled ? mangled : name); |
| 4226 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 4227 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4228 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4229 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4230 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4231 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4232 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 4233 | eSymbolTypeData, |
| 4234 | Symtab::eDebugYes, |
| 4235 | Symtab::eVisibilityExtern); |
| 4236 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4237 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4238 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4239 | { |
| Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 4240 | const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4241 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4242 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4243 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4244 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4245 | linked_oso_file_addr = true; |
| 4246 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4247 | } |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4253 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4254 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4255 | if (!linked_oso_file_addr) |
| 4256 | { |
| 4257 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 4258 | // needs to be linked up correctly. |
| 4259 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 4260 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4261 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4262 | // Update the file address for this variable |
| 4263 | location.Update_DW_OP_addr (exe_file_addr); |
| 4264 | } |
| 4265 | else |
| 4266 | { |
| 4267 | // Variable didn't make it into the final executable |
| 4268 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4269 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4270 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4271 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4272 | } |
| 4273 | else |
| 4274 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4275 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4276 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4277 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4278 | |
| 4279 | if (symbol_context_scope == NULL) |
| 4280 | { |
| 4281 | switch (parent_tag) |
| 4282 | { |
| 4283 | case DW_TAG_subprogram: |
| 4284 | case DW_TAG_inlined_subroutine: |
| 4285 | case DW_TAG_lexical_block: |
| 4286 | if (sc.function) |
| 4287 | { |
| 4288 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 4289 | if (symbol_context_scope == NULL) |
| 4290 | symbol_context_scope = sc.function; |
| 4291 | } |
| 4292 | break; |
| 4293 | |
| 4294 | default: |
| 4295 | symbol_context_scope = sc.comp_unit; |
| 4296 | break; |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | if (symbol_context_scope) |
| 4301 | { |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4302 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); |
| 4303 | |
| 4304 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| 4305 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); |
| 4306 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4307 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 4308 | name, |
| 4309 | mangled, |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4310 | type_sp, |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4311 | scope, |
| 4312 | symbol_context_scope, |
| 4313 | &decl, |
| 4314 | location, |
| 4315 | is_external, |
| Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 4316 | is_artificial, |
| 4317 | is_static_member)); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4318 | |
| 4319 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 4320 | } |
| 4321 | else |
| 4322 | { |
| 4323 | // Not ready to parse this variable yet. It might be a global |
| 4324 | // or static variable that is in a function scope and the function |
| 4325 | // in the symbol context wasn't filled in yet |
| 4326 | return var_sp; |
| 4327 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4328 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4329 | // Cache var_sp even if NULL (the variable was just a specification or |
| 4330 | // was missing vital information to be able to be displayed in the debugger |
| 4331 | // (missing location due to optimization, etc)) so we don't re-parse |
| 4332 | // this DIE over and over later... |
| 4333 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4334 | } |
| 4335 | return var_sp; |
| 4336 | } |
| 4337 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4338 | |
| 4339 | const DWARFDebugInfoEntry * |
| 4340 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 4341 | dw_offset_t spec_block_die_offset, |
| 4342 | DWARFCompileUnit **result_die_cu_handle) |
| 4343 | { |
| 4344 | // Give the concrete function die specified by "func_die_offset", find the |
| 4345 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4346 | // to "spec_block_die_offset" |
| 4347 | DWARFDebugInfo* info = DebugInfo(); |
| 4348 | |
| 4349 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 4350 | if (die) |
| 4351 | { |
| 4352 | assert (*result_die_cu_handle); |
| 4353 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 4354 | } |
| 4355 | return NULL; |
| 4356 | } |
| 4357 | |
| 4358 | |
| 4359 | const DWARFDebugInfoEntry * |
| 4360 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 4361 | const DWARFDebugInfoEntry *die, |
| 4362 | dw_offset_t spec_block_die_offset, |
| 4363 | DWARFCompileUnit **result_die_cu_handle) |
| 4364 | { |
| 4365 | if (die) |
| 4366 | { |
| 4367 | switch (die->Tag()) |
| 4368 | { |
| 4369 | case DW_TAG_subprogram: |
| 4370 | case DW_TAG_inlined_subroutine: |
| 4371 | case DW_TAG_lexical_block: |
| 4372 | { |
| 4373 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4374 | { |
| 4375 | *result_die_cu_handle = dwarf_cu; |
| 4376 | return die; |
| 4377 | } |
| 4378 | |
| 4379 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4380 | { |
| 4381 | *result_die_cu_handle = dwarf_cu; |
| 4382 | return die; |
| 4383 | } |
| 4384 | } |
| 4385 | break; |
| 4386 | } |
| 4387 | |
| 4388 | // Give the concrete function die specified by "func_die_offset", find the |
| 4389 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4390 | // to "spec_block_die_offset" |
| 4391 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 4392 | { |
| 4393 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 4394 | child_die, |
| 4395 | spec_block_die_offset, |
| 4396 | result_die_cu_handle); |
| 4397 | if (result_die) |
| 4398 | return result_die; |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | *result_die_cu_handle = NULL; |
| 4403 | return NULL; |
| 4404 | } |
| 4405 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4406 | size_t |
| 4407 | SymbolFileDWARF::ParseVariables |
| 4408 | ( |
| 4409 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4410 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4411 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4412 | const DWARFDebugInfoEntry *orig_die, |
| 4413 | bool parse_siblings, |
| 4414 | bool parse_children, |
| 4415 | VariableList* cc_variable_list |
| 4416 | ) |
| 4417 | { |
| 4418 | if (orig_die == NULL) |
| 4419 | return 0; |
| 4420 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4421 | VariableListSP variable_list_sp; |
| 4422 | |
| 4423 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4424 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4425 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4426 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4427 | dw_tag_t tag = die->Tag(); |
| 4428 | |
| 4429 | // Check to see if we have already parsed this variable or constant? |
| 4430 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4431 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4432 | if (cc_variable_list) |
| 4433 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4434 | } |
| 4435 | else |
| 4436 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4437 | // We haven't already parsed it, lets do that now. |
| 4438 | if ((tag == DW_TAG_variable) || |
| 4439 | (tag == DW_TAG_constant) || |
| 4440 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4441 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4442 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4443 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4444 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 4445 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4446 | switch (parent_tag) |
| 4447 | { |
| 4448 | case DW_TAG_compile_unit: |
| 4449 | if (sc.comp_unit != NULL) |
| 4450 | { |
| 4451 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 4452 | if (variable_list_sp.get() == NULL) |
| 4453 | { |
| 4454 | variable_list_sp.reset(new VariableList()); |
| 4455 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 4456 | } |
| 4457 | } |
| 4458 | else |
| 4459 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4460 | 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 Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4461 | MakeUserID(sc_parent_die->GetOffset()), |
| 4462 | DW_TAG_value_to_name (parent_tag), |
| 4463 | MakeUserID(orig_die->GetOffset()), |
| 4464 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4465 | } |
| 4466 | break; |
| 4467 | |
| 4468 | case DW_TAG_subprogram: |
| 4469 | case DW_TAG_inlined_subroutine: |
| 4470 | case DW_TAG_lexical_block: |
| 4471 | if (sc.function != NULL) |
| 4472 | { |
| 4473 | // Check to see if we already have parsed the variables for the given scope |
| 4474 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4475 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4476 | if (block == NULL) |
| 4477 | { |
| 4478 | // This must be a specification or abstract origin with |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4479 | // a concrete block counterpart in the current function. We need |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4480 | // to find the concrete block so we can correctly add the |
| 4481 | // variable to it |
| 4482 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 4483 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 4484 | sc_parent_die->GetOffset(), |
| 4485 | &concrete_block_die_cu); |
| 4486 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4487 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | if (block != NULL) |
| 4491 | { |
| 4492 | const bool can_create = false; |
| 4493 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 4494 | if (variable_list_sp.get() == NULL) |
| 4495 | { |
| 4496 | variable_list_sp.reset(new VariableList()); |
| 4497 | block->SetVariableList(variable_list_sp); |
| 4498 | } |
| 4499 | } |
| 4500 | } |
| 4501 | break; |
| 4502 | |
| 4503 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4504 | GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n", |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 4505 | MakeUserID(orig_die->GetOffset()), |
| 4506 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4507 | break; |
| 4508 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4509 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4510 | |
| 4511 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4512 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4513 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 4514 | if (var_sp) |
| 4515 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4516 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4517 | if (cc_variable_list) |
| 4518 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 4519 | ++vars_added; |
| 4520 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4521 | } |
| 4522 | } |
| 4523 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4524 | |
| 4525 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 4526 | |
| 4527 | if (!skip_children && parse_children && die->HasChildren()) |
| 4528 | { |
| 4529 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 4530 | } |
| 4531 | |
| 4532 | if (parse_siblings) |
| 4533 | die = die->GetSibling(); |
| 4534 | else |
| 4535 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4536 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4537 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | //------------------------------------------------------------------ |
| 4541 | // PluginInterface protocol |
| 4542 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 4543 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4544 | SymbolFileDWARF::GetPluginName() |
| 4545 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4546 | return GetPluginNameStatic(); |
| 4547 | } |
| 4548 | |
| 4549 | uint32_t |
| 4550 | SymbolFileDWARF::GetPluginVersion() |
| 4551 | { |
| 4552 | return 1; |
| 4553 | } |
| 4554 | |
| 4555 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4556 | SymbolFileDWARF::DumpIndexes () |
| 4557 | { |
| 4558 | StreamFile s(stdout, false); |
| 4559 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4560 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4561 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4562 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4563 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 4564 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 4565 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 4566 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 4567 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 4568 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 4569 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 4570 | s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 4573 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4574 | SymbolFileDWARFDebugMap * |
| 4575 | SymbolFileDWARF::GetDebugMapSymfile () |
| 4576 | { |
| 4577 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 4578 | { |
| 4579 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 4580 | if (module_sp) |
| 4581 | { |
| 4582 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 4583 | if (sym_vendor) |
| 4584 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 4585 | } |
| 4586 | } |
| 4587 | return m_debug_map_symfile; |
| 4588 | } |
| 4589 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 4590 | |