| 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 | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 464 | CompilerType clang_type = type->GetClangForwardType(); |
| 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 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1435 | clang::DeclContext* |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1436 | SymbolFileDWARF::GetClangDeclContextContainingTypeUID (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) |
| 1449 | return type_system->GetClangDeclContextContainingTypeUID(this, type_uid); |
| 1450 | } |
| 1451 | } |
| Sean Callanan | 72e4940 | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 1452 | } |
| 1453 | return NULL; |
| 1454 | } |
| 1455 | |
| 1456 | clang::DeclContext* |
| 1457 | SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) |
| 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) |
| 1470 | return type_system->GetClangDeclContextForTypeUID(this, sc, type_uid); |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1474 | return NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | Type* |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1478 | SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1479 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1480 | if (UserIDMatches(type_uid)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1481 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1482 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1483 | if (debug_info) |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1484 | { |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1485 | DWARFCompileUnitSP cu_sp; |
| 1486 | const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1487 | const bool assert_not_being_parsed = true; |
| 1488 | return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1489 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1490 | } |
| 1491 | return NULL; |
| 1492 | } |
| 1493 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1494 | Type* |
| 1495 | SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1496 | { |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1497 | if (die != NULL) |
| 1498 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1499 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1500 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1501 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1502 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", |
| 1503 | die->GetOffset(), |
| 1504 | DW_TAG_value_to_name(die->Tag()), |
| 1505 | die->GetName(this, cu)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1506 | |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1507 | // We might be coming in in the middle of a type tree (a class |
| 1508 | // withing a class, an enum within a class), so parse any needed |
| 1509 | // parent DIEs before we get to this one... |
| 1510 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); |
| 1511 | switch (decl_ctx_die->Tag()) |
| 1512 | { |
| 1513 | case DW_TAG_structure_type: |
| 1514 | case DW_TAG_union_type: |
| 1515 | case DW_TAG_class_type: |
| 1516 | { |
| 1517 | // Get the type, which could be a forward declaration |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1518 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1519 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1520 | "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", |
| 1521 | die->GetOffset(), |
| 1522 | DW_TAG_value_to_name(die->Tag()), |
| 1523 | die->GetName(this, cu), |
| 1524 | decl_ctx_die->GetOffset()); |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1525 | // |
| 1526 | // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); |
| 1527 | // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) |
| 1528 | // { |
| 1529 | // if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1530 | // GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 1531 | // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", |
| 1532 | // die->GetOffset(), |
| 1533 | // DW_TAG_value_to_name(die->Tag()), |
| 1534 | // die->GetName(this, cu), |
| 1535 | // decl_ctx_die->GetOffset()); |
| 1536 | // // Ask the type to complete itself if it already hasn't since if we |
| 1537 | // // want a function (method or static) from a class, the class must |
| 1538 | // // create itself and add it's own methods and class functions. |
| 1539 | // if (parent_type) |
| 1540 | // parent_type->GetClangFullType(); |
| 1541 | // } |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1542 | } |
| 1543 | break; |
| 1544 | |
| 1545 | default: |
| 1546 | break; |
| 1547 | } |
| 1548 | return ResolveType (cu, die); |
| 1549 | } |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1553 | // This function is used when SymbolFileDWARFDebugMap owns a bunch of |
| 1554 | // SymbolFileDWARF objects to detect if this DWARF file is the one that |
| 1555 | // can resolve a clang_type. |
| 1556 | bool |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1557 | SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &clang_type) |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1558 | { |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1559 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1560 | 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] | 1561 | return die != NULL; |
| 1562 | } |
| 1563 | |
| 1564 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1565 | bool |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame^] | 1566 | SymbolFileDWARF::CompleteType (CompilerType &clang_type) |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1567 | { |
| 1568 | // 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] | 1569 | CompilerType clang_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(clang_type); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1570 | 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] | 1571 | if (die == NULL) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1572 | { |
| 1573 | // We have already resolved this type... |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1574 | return true; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1575 | } |
| 1576 | // Once we start resolving this type, remove it from the forward declaration |
| 1577 | // map in case anyone child members or other types require this type to get resolved. |
| 1578 | // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition |
| 1579 | // are done. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1580 | 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] | 1581 | |
| Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 1582 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1583 | DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1584 | Type *type = m_die_to_type.lookup (die); |
| 1585 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1586 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); |
| Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 1587 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1588 | GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1589 | "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1590 | MakeUserID(die->GetOffset()), |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1591 | DW_TAG_value_to_name(die->Tag()), |
| Greg Clayton | d61c0fc | 2012-04-23 22:55:20 +0000 | [diff] [blame] | 1592 | type->GetName().AsCString()); |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1593 | assert (clang_type); |
| 1594 | DWARFDebugInfoEntry::Attributes attributes; |
| 1595 | |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1596 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1597 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1598 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1599 | if (type_system) |
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame^] | 1600 | return type_system->CompleteTypeFromDWARF (this, dwarf_cu, die, type, clang_type); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1601 | |
| Ashok Thirumurthi | a4658a5 | 2013-07-30 14:58:39 +0000 | [diff] [blame] | 1602 | return false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1605 | void |
| 1606 | SymbolFileDWARF::ClearDIEBeingParsed (const DWARFDebugInfoEntry* type_die) |
| 1607 | { |
| 1608 | if (type_die) |
| 1609 | { |
| 1610 | if (m_die_to_type.lookup (type_die) == DIE_IS_BEING_PARSED) |
| 1611 | m_die_to_type[type_die] = nullptr; |
| 1612 | } |
| 1613 | } |
| 1614 | Type* |
| 1615 | SymbolFileDWARF::GetCachedTypeForDIE (const DWARFDebugInfoEntry* type_die) const |
| 1616 | { |
| 1617 | if (type_die) |
| 1618 | { |
| 1619 | Type *type = m_die_to_type.lookup (type_die); |
| 1620 | if (type != DIE_IS_BEING_PARSED) |
| 1621 | return type; |
| 1622 | } |
| 1623 | return nullptr; |
| 1624 | } |
| 1625 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1626 | Type* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1627 | 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] | 1628 | { |
| 1629 | if (type_die != NULL) |
| 1630 | { |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 1631 | Type *type = m_die_to_type.lookup (type_die); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1632 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1633 | if (type == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1634 | type = GetTypeForDIE (dwarf_cu, type_die).get(); |
| Greg Clayton | cab36a3 | 2011-12-08 05:16:30 +0000 | [diff] [blame] | 1635 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 1636 | if (assert_not_being_parsed) |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1637 | { |
| 1638 | if (type != DIE_IS_BEING_PARSED) |
| 1639 | return type; |
| 1640 | |
| 1641 | 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] | 1642 | type_die->GetOffset(), |
| 1643 | DW_TAG_value_to_name(type_die->Tag()), |
| 1644 | type_die->GetName(this, dwarf_cu)); |
| Jim Ingham | c354928 | 2012-01-11 02:21:12 +0000 | [diff] [blame] | 1645 | |
| 1646 | } |
| 1647 | else |
| 1648 | return type; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 1649 | } |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1653 | CompileUnit* |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1654 | SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1655 | { |
| 1656 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1657 | if (dwarf_cu->GetUserData() == NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1658 | { |
| 1659 | // The symbol vendor doesn't know about this compile unit, we |
| 1660 | // need to parse and add it to the symbol vendor object. |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1661 | return ParseCompileUnit(dwarf_cu, cu_idx).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1662 | } |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1663 | return (CompileUnit*)dwarf_cu->GetUserData(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 1666 | size_t |
| 1667 | SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets) |
| 1668 | { |
| 1669 | method_die_offsets.clear(); |
| 1670 | if (m_using_apple_tables) |
| 1671 | { |
| 1672 | if (m_apple_objc_ap.get()) |
| 1673 | m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); |
| 1674 | } |
| 1675 | else |
| 1676 | { |
| 1677 | if (!m_indexed) |
| 1678 | Index (); |
| 1679 | |
| 1680 | m_objc_class_selectors_index.Find (class_name, method_die_offsets); |
| 1681 | } |
| 1682 | return method_die_offsets.size(); |
| 1683 | } |
| 1684 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1685 | bool |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1686 | SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1687 | { |
| Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 1688 | sc.Clear(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1689 | // Check if the symbol vendor already knows about this compile unit? |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1690 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1691 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1692 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1693 | if (sc.function == NULL) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1694 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 1695 | |
| 1696 | if (sc.function) |
| 1697 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1698 | sc.module_sp = sc.function->CalculateSymbolContextModule(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 1699 | return true; |
| 1700 | } |
| 1701 | |
| 1702 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 1705 | void |
| 1706 | SymbolFileDWARF::UpdateExternalModuleListIfNeeded() |
| 1707 | { |
| 1708 | if (m_fetched_external_modules) |
| 1709 | return; |
| 1710 | m_fetched_external_modules = true; |
| 1711 | |
| 1712 | DWARFDebugInfo * debug_info = DebugInfo(); |
| 1713 | debug_info->GetNumCompileUnits(); |
| 1714 | |
| 1715 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 1716 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 1717 | { |
| 1718 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 1719 | |
| 1720 | const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); |
| 1721 | if (die && die->HasChildren() == false) |
| 1722 | { |
| 1723 | const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX); |
| 1724 | const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX); |
| 1725 | |
| 1726 | if (name_strp != UINT64_MAX) |
| 1727 | { |
| 1728 | if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end()) |
| 1729 | { |
| 1730 | const char *name = get_debug_str_data().PeekCStr(name_strp); |
| 1731 | const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp); |
| 1732 | if (name || dwo_path) |
| 1733 | { |
| 1734 | ModuleSP module_sp; |
| 1735 | if (dwo_path) |
| 1736 | { |
| 1737 | ModuleSpec dwo_module_spec; |
| 1738 | dwo_module_spec.GetFileSpec().SetFile(dwo_path, false); |
| 1739 | dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture(); |
| 1740 | //printf ("Loading dwo = '%s'\n", dwo_path); |
| 1741 | Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL); |
| 1742 | } |
| 1743 | |
| 1744 | if (dwo_path_strp != LLDB_INVALID_UID) |
| 1745 | { |
| 1746 | m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1747 | } |
| 1748 | else |
| 1749 | { |
| 1750 | // This hack should be removed promptly once clang emits both. |
| 1751 | m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp }; |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1759 | |
| 1760 | SymbolFileDWARF::GlobalVariableMap & |
| 1761 | SymbolFileDWARF::GetGlobalAranges() |
| 1762 | { |
| 1763 | if (!m_global_aranges_ap) |
| 1764 | { |
| 1765 | m_global_aranges_ap.reset (new GlobalVariableMap()); |
| 1766 | |
| 1767 | ModuleSP module_sp = GetObjectFile()->GetModule(); |
| 1768 | if (module_sp) |
| 1769 | { |
| 1770 | const size_t num_cus = module_sp->GetNumCompileUnits(); |
| 1771 | for (size_t i = 0; i < num_cus; ++i) |
| 1772 | { |
| 1773 | CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); |
| 1774 | if (cu_sp) |
| 1775 | { |
| 1776 | VariableListSP globals_sp = cu_sp->GetVariableList(true); |
| 1777 | if (globals_sp) |
| 1778 | { |
| 1779 | const size_t num_globals = globals_sp->GetSize(); |
| 1780 | for (size_t g = 0; g < num_globals; ++g) |
| 1781 | { |
| 1782 | VariableSP var_sp = globals_sp->GetVariableAtIndex(g); |
| 1783 | if (var_sp && !var_sp->GetLocationIsConstantValueData()) |
| 1784 | { |
| 1785 | const DWARFExpression &location = var_sp->LocationExpression(); |
| 1786 | Value location_result; |
| 1787 | Error error; |
| 1788 | if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) |
| 1789 | { |
| 1790 | if (location_result.GetValueType() == Value::eValueTypeFileAddress) |
| 1791 | { |
| 1792 | lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); |
| 1793 | lldb::addr_t byte_size = 1; |
| 1794 | if (var_sp->GetType()) |
| 1795 | byte_size = var_sp->GetType()->GetByteSize(); |
| 1796 | m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | m_global_aranges_ap->Sort(); |
| 1806 | } |
| 1807 | return *m_global_aranges_ap; |
| 1808 | } |
| 1809 | |
| 1810 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1811 | uint32_t |
| 1812 | SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 1813 | { |
| 1814 | Timer scoped_timer(__PRETTY_FUNCTION__, |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1815 | "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] | 1816 | static_cast<void*>(so_addr.GetSection().get()), |
| 1817 | so_addr.GetOffset(), resolve_scope); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1818 | uint32_t resolved = 0; |
| Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 1819 | if (resolve_scope & ( eSymbolContextCompUnit | |
| 1820 | eSymbolContextFunction | |
| 1821 | eSymbolContextBlock | |
| 1822 | eSymbolContextLineEntry | |
| 1823 | eSymbolContextVariable )) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1824 | { |
| 1825 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); |
| 1826 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1827 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 1828 | if (debug_info) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1829 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1830 | 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] | 1831 | if (cu_offset == DW_INVALID_OFFSET) |
| 1832 | { |
| 1833 | // Global variables are not in the compile unit address ranges. The only way to |
| 1834 | // currently find global variables is to iterate over the .debug_pubnames or the |
| 1835 | // __apple_names table and find all items in there that point to DW_TAG_variable |
| 1836 | // DIEs and then find the address that matches. |
| 1837 | if (resolve_scope & eSymbolContextVariable) |
| 1838 | { |
| 1839 | GlobalVariableMap &map = GetGlobalAranges(); |
| 1840 | const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); |
| 1841 | if (entry && entry->data) |
| 1842 | { |
| 1843 | Variable *variable = entry->data; |
| 1844 | SymbolContextScope *scc = variable->GetSymbolContextScope(); |
| 1845 | if (scc) |
| 1846 | { |
| 1847 | scc->CalculateSymbolContext(&sc); |
| 1848 | sc.variable = variable; |
| 1849 | } |
| 1850 | return sc.GetResolvedMask(); |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1855 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1856 | uint32_t cu_idx = DW_INVALID_INDEX; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1857 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); |
| 1858 | if (dwarf_cu) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1859 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1860 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1861 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1862 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1863 | resolved |= eSymbolContextCompUnit; |
| 1864 | |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1865 | bool force_check_line_table = false; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1866 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| 1867 | { |
| 1868 | DWARFDebugInfoEntry *function_die = NULL; |
| 1869 | DWARFDebugInfoEntry *block_die = NULL; |
| 1870 | if (resolve_scope & eSymbolContextBlock) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1871 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1872 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); |
| 1873 | } |
| 1874 | else |
| 1875 | { |
| 1876 | dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); |
| 1877 | } |
| 1878 | |
| 1879 | if (function_die != NULL) |
| 1880 | { |
| 1881 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 1882 | if (sc.function == NULL) |
| 1883 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 1884 | } |
| 1885 | else |
| 1886 | { |
| 1887 | // We might have had a compile unit that had discontiguous |
| 1888 | // address ranges where the gaps are symbols that don't have |
| 1889 | // any debug info. Discontiguous compile unit address ranges |
| 1890 | // should only happen when there aren't other functions from |
| 1891 | // other compile units in these gaps. This helps keep the size |
| 1892 | // of the aranges down. |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1893 | force_check_line_table = true; |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | if (sc.function != NULL) |
| 1897 | { |
| 1898 | resolved |= eSymbolContextFunction; |
| 1899 | |
| 1900 | if (resolve_scope & eSymbolContextBlock) |
| 1901 | { |
| 1902 | Block& block = sc.function->GetBlock (true); |
| 1903 | |
| 1904 | if (block_die != NULL) |
| 1905 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| 1906 | else |
| 1907 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 1908 | if (sc.block) |
| 1909 | resolved |= eSymbolContextBlock; |
| 1910 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1911 | } |
| 1912 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1913 | |
| 1914 | if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) |
| 1915 | { |
| 1916 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1917 | if (line_table != NULL) |
| 1918 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1919 | // And address that makes it into this function should be in terms |
| 1920 | // of this debug file if there is no debug map, or it will be an |
| 1921 | // address in the .o file which needs to be fixed up to be in terms |
| 1922 | // of the debug map executable. Either way, calling FixupAddress() |
| 1923 | // will work for us. |
| 1924 | Address exe_so_addr (so_addr); |
| 1925 | if (FixupAddress(exe_so_addr)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1926 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 1927 | if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1928 | { |
| 1929 | resolved |= eSymbolContextLineEntry; |
| 1930 | } |
| 1931 | } |
| Greg Clayton | 6ab8013 | 2012-12-12 17:30:52 +0000 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) |
| 1936 | { |
| 1937 | // We might have had a compile unit that had discontiguous |
| 1938 | // address ranges where the gaps are symbols that don't have |
| 1939 | // any debug info. Discontiguous compile unit address ranges |
| 1940 | // should only happen when there aren't other functions from |
| 1941 | // other compile units in these gaps. This helps keep the size |
| 1942 | // of the aranges down. |
| 1943 | sc.comp_unit = NULL; |
| 1944 | resolved &= ~eSymbolContextCompUnit; |
| 1945 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1946 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1947 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1948 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1949 | GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", |
| 1950 | cu_offset, |
| 1951 | cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | return resolved; |
| 1958 | } |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | uint32_t |
| 1963 | SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 1964 | { |
| 1965 | const uint32_t prev_size = sc_list.GetSize(); |
| 1966 | if (resolve_scope & eSymbolContextCompUnit) |
| 1967 | { |
| 1968 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 1969 | if (debug_info) |
| 1970 | { |
| 1971 | uint32_t cu_idx; |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1972 | DWARFCompileUnit* dwarf_cu = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1973 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1974 | 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] | 1975 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1976 | CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Sean Callanan | ddd7a2a | 2013-10-03 22:27:29 +0000 | [diff] [blame] | 1977 | const bool full_match = (bool)file_spec.GetDirectory(); |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1978 | 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] | 1979 | if (check_inlines || file_spec_matches_cu_file_spec) |
| 1980 | { |
| 1981 | SymbolContext sc (m_obj_file->GetModule()); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 1982 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1983 | if (sc.comp_unit) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1984 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1985 | uint32_t file_idx = UINT32_MAX; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1986 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1987 | // If we are looking for inline functions only and we don't |
| 1988 | // find it in the support files, we are done. |
| 1989 | if (check_inlines) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1990 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1991 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| 1992 | if (file_idx == UINT32_MAX) |
| 1993 | continue; |
| 1994 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1995 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 1996 | if (line != 0) |
| 1997 | { |
| 1998 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 1999 | |
| 2000 | if (line_table != NULL && line != 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2001 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2002 | // We will have already looked up the file index if |
| 2003 | // we are searching for inline entries. |
| 2004 | if (!check_inlines) |
| 2005 | file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2006 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2007 | if (file_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2008 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2009 | uint32_t found_line; |
| 2010 | uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); |
| 2011 | found_line = sc.line_entry.line; |
| 2012 | |
| 2013 | while (line_idx != UINT32_MAX) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2014 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2015 | sc.function = NULL; |
| 2016 | sc.block = NULL; |
| 2017 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2018 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2019 | const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); |
| 2020 | if (file_vm_addr != LLDB_INVALID_ADDRESS) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2021 | { |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2022 | DWARFDebugInfoEntry *function_die = NULL; |
| 2023 | DWARFDebugInfoEntry *block_die = NULL; |
| 2024 | 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] | 2025 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2026 | if (function_die != NULL) |
| 2027 | { |
| 2028 | sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); |
| 2029 | if (sc.function == NULL) |
| 2030 | sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); |
| 2031 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2032 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2033 | if (sc.function != NULL) |
| 2034 | { |
| 2035 | Block& block = sc.function->GetBlock (true); |
| 2036 | |
| 2037 | if (block_die != NULL) |
| 2038 | sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 2039 | else if (function_die != NULL) |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2040 | sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); |
| 2041 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2042 | } |
| 2043 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2044 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2045 | sc_list.Append(sc); |
| 2046 | line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); |
| 2047 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2048 | } |
| 2049 | } |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2050 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2051 | { |
| 2052 | // only append the context if we aren't looking for inline call sites |
| 2053 | // by file and line and if the file spec matches that of the compile unit |
| 2054 | sc_list.Append(sc); |
| 2055 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2056 | } |
| 2057 | else if (file_spec_matches_cu_file_spec && !check_inlines) |
| 2058 | { |
| 2059 | // only append the context if we aren't looking for inline call sites |
| 2060 | // by file and line and if the file spec matches that of the compile unit |
| 2061 | sc_list.Append(sc); |
| 2062 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2063 | |
| Greg Clayton | 526a4ae | 2012-05-16 22:09:01 +0000 | [diff] [blame] | 2064 | if (!check_inlines) |
| 2065 | break; |
| 2066 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | return sc_list.GetSize() - prev_size; |
| 2072 | } |
| 2073 | |
| 2074 | void |
| 2075 | SymbolFileDWARF::Index () |
| 2076 | { |
| 2077 | if (m_indexed) |
| 2078 | return; |
| 2079 | m_indexed = true; |
| 2080 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2081 | "SymbolFileDWARF::Index (%s)", |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 2082 | GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2083 | |
| 2084 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2085 | if (debug_info) |
| 2086 | { |
| 2087 | uint32_t cu_idx = 0; |
| 2088 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 2089 | for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 2090 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2091 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2092 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2093 | bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2094 | |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2095 | dwarf_cu->Index (cu_idx, |
| 2096 | m_function_basename_index, |
| 2097 | m_function_fullname_index, |
| 2098 | m_function_method_index, |
| 2099 | m_function_selector_index, |
| 2100 | m_objc_class_selectors_index, |
| 2101 | m_global_index, |
| 2102 | m_type_index, |
| 2103 | m_namespace_index); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2104 | |
| 2105 | // Keep memory down by clearing DIEs if this generate function |
| 2106 | // caused them to be parsed |
| 2107 | if (clear_dies) |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 2108 | dwarf_cu->ClearDIEs (true); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2111 | m_function_basename_index.Finalize(); |
| 2112 | m_function_fullname_index.Finalize(); |
| 2113 | m_function_method_index.Finalize(); |
| 2114 | m_function_selector_index.Finalize(); |
| 2115 | m_objc_class_selectors_index.Finalize(); |
| 2116 | m_global_index.Finalize(); |
| 2117 | m_type_index.Finalize(); |
| 2118 | m_namespace_index.Finalize(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2119 | |
| Greg Clayton | 2473992 | 2010-10-13 03:15:28 +0000 | [diff] [blame] | 2120 | #if defined (ENABLE_DEBUG_PRINTF) |
| Greg Clayton | 7bd65b9 | 2011-02-09 23:39:34 +0000 | [diff] [blame] | 2121 | StreamFile s(stdout, false); |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 2122 | s.Printf ("DWARF index for '%s':", |
| 2123 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Greg Clayton | ba2d22d | 2010-11-13 22:57:37 +0000 | [diff] [blame] | 2124 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 2125 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 2126 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 2127 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 2128 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 2129 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| Greg Clayton | 69b0488 | 2010-10-15 02:03:22 +0000 | [diff] [blame] | 2130 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 2131 | s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2132 | #endif |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2133 | } |
| 2134 | } |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2135 | |
| 2136 | bool |
| 2137 | SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) |
| 2138 | { |
| 2139 | if (namespace_decl == NULL) |
| 2140 | { |
| 2141 | // Invalid namespace decl which means we aren't matching only things |
| 2142 | // in this symbol file, so return true to indicate it matches this |
| 2143 | // symbol file. |
| 2144 | return true; |
| 2145 | } |
| 2146 | |
| 2147 | clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); |
| 2148 | |
| 2149 | if (namespace_ast == NULL) |
| 2150 | return true; // No AST in the "namespace_decl", return true since it |
| 2151 | // could then match any symbol file, including this one |
| 2152 | |
| 2153 | if (namespace_ast == GetClangASTContext().getASTContext()) |
| 2154 | return true; // The ASTs match, return true |
| 2155 | |
| 2156 | // The namespace AST was valid, and it does not match... |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2157 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2158 | |
| 2159 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2160 | GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); |
| Sean Callanan | c41e68b | 2011-10-13 21:08:11 +0000 | [diff] [blame] | 2161 | |
| Greg Clayton | bfe3dd4 | 2011-10-13 00:00:53 +0000 | [diff] [blame] | 2162 | return false; |
| 2163 | } |
| 2164 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2165 | uint32_t |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2166 | SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2167 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2168 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2169 | |
| 2170 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2171 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2172 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", |
| 2173 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2174 | static_cast<const void*>(namespace_decl), |
| 2175 | append, max_matches); |
| 2176 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2177 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2178 | return 0; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2179 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2180 | DWARFDebugInfo* info = DebugInfo(); |
| 2181 | if (info == NULL) |
| 2182 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2183 | |
| 2184 | // If we aren't appending the results to this list, then clear the list |
| 2185 | if (!append) |
| 2186 | variables.Clear(); |
| 2187 | |
| 2188 | // Remember how many variables are in the list before we search in case |
| 2189 | // we are appending the results to a variable list. |
| 2190 | const uint32_t original_size = variables.GetSize(); |
| 2191 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2192 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2193 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2194 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2195 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2196 | if (m_apple_names_ap.get()) |
| 2197 | { |
| 2198 | const char *name_cstr = name.GetCString(); |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2199 | llvm::StringRef basename; |
| 2200 | llvm::StringRef context; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2201 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2202 | if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) |
| 2203 | basename = name_cstr; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2204 | |
| Jim Ingham | fa39bb4 | 2014-10-25 00:33:55 +0000 | [diff] [blame] | 2205 | m_apple_names_ap->FindByName (basename.data(), die_offsets); |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2206 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2207 | } |
| 2208 | else |
| 2209 | { |
| 2210 | // Index the DWARF if we haven't already |
| 2211 | if (!m_indexed) |
| 2212 | Index (); |
| 2213 | |
| 2214 | m_global_index.Find (name, die_offsets); |
| 2215 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2216 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2217 | const size_t num_die_matches = die_offsets.size(); |
| 2218 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2219 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2220 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2221 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2222 | assert (sc.module_sp); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2223 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2224 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2225 | DWARFCompileUnit* dwarf_cu = NULL; |
| 2226 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2227 | bool done = false; |
| 2228 | for (size_t i=0; i<num_die_matches && !done; ++i) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2229 | { |
| 2230 | const dw_offset_t die_offset = die_offsets[i]; |
| 2231 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2232 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2233 | if (die) |
| 2234 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2235 | switch (die->Tag()) |
| 2236 | { |
| 2237 | default: |
| 2238 | case DW_TAG_subprogram: |
| 2239 | case DW_TAG_inlined_subroutine: |
| 2240 | case DW_TAG_try_block: |
| 2241 | case DW_TAG_catch_block: |
| 2242 | break; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2243 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2244 | case DW_TAG_variable: |
| 2245 | { |
| 2246 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2247 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2248 | if (namespace_decl) |
| 2249 | { |
| 2250 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 2251 | |
| 2252 | if (!type_system->DIEIsInNamespace (namespace_decl, this, dwarf_cu, die)) |
| 2253 | continue; |
| 2254 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2255 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2256 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2257 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2258 | if (variables.GetSize() - original_size >= max_matches) |
| 2259 | done = true; |
| 2260 | } |
| 2261 | break; |
| 2262 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2263 | } |
| 2264 | else |
| 2265 | { |
| 2266 | if (m_using_apple_tables) |
| 2267 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2268 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", |
| 2269 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2270 | } |
| 2271 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2272 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2276 | const uint32_t num_matches = variables.GetSize() - original_size; |
| 2277 | if (log && num_matches > 0) |
| 2278 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2279 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2280 | "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2281 | name.GetCString(), |
| 2282 | static_cast<const void*>(namespace_decl), |
| 2283 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2284 | num_matches); |
| 2285 | } |
| 2286 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | uint32_t |
| 2290 | SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 2291 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2292 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2293 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2294 | if (log) |
| 2295 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2296 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2297 | "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2298 | regex.GetText(), append, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2299 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2302 | DWARFDebugInfo* info = DebugInfo(); |
| 2303 | if (info == NULL) |
| 2304 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2305 | |
| 2306 | // If we aren't appending the results to this list, then clear the list |
| 2307 | if (!append) |
| 2308 | variables.Clear(); |
| 2309 | |
| 2310 | // Remember how many variables are in the list before we search in case |
| 2311 | // we are appending the results to a variable list. |
| 2312 | const uint32_t original_size = variables.GetSize(); |
| 2313 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2314 | DIEArray die_offsets; |
| 2315 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2316 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2317 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2318 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2319 | { |
| 2320 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2321 | if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| 2322 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 2323 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2324 | } |
| 2325 | else |
| 2326 | { |
| 2327 | // Index the DWARF if we haven't already |
| 2328 | if (!m_indexed) |
| 2329 | Index (); |
| 2330 | |
| 2331 | m_global_index.Find (regex, die_offsets); |
| 2332 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2333 | |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2334 | SymbolContext sc; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 2335 | sc.module_sp = m_obj_file->GetModule(); |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2336 | assert (sc.module_sp); |
| 2337 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2338 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2339 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2340 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2341 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2342 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2343 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 2344 | for (size_t i=0; i<num_matches; ++i) |
| 2345 | { |
| 2346 | const dw_offset_t die_offset = die_offsets[i]; |
| 2347 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2348 | |
| 2349 | if (die) |
| 2350 | { |
| 2351 | sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2352 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2353 | ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2354 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2355 | if (variables.GetSize() - original_size >= max_matches) |
| 2356 | break; |
| 2357 | } |
| 2358 | else |
| 2359 | { |
| 2360 | if (m_using_apple_tables) |
| 2361 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2362 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", |
| 2363 | die_offset, regex.GetText()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2364 | } |
| 2365 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2366 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | // Return the number of variable that were appended to the list |
| 2370 | return variables.GetSize() - original_size; |
| 2371 | } |
| 2372 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2373 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2374 | bool |
| 2375 | SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, |
| 2376 | DWARFCompileUnit *&dwarf_cu, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2377 | bool include_inlines, |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2378 | SymbolContextList& sc_list) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2379 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2380 | const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2381 | return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | |
| 2385 | bool |
| 2386 | SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, |
| 2387 | const DWARFDebugInfoEntry *die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2388 | bool include_inlines, |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2389 | SymbolContextList& sc_list) |
| 2390 | { |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2391 | SymbolContext sc; |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2392 | |
| 2393 | if (die == NULL) |
| 2394 | return false; |
| 2395 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2396 | // 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] | 2397 | 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] | 2398 | return false; |
| 2399 | |
| 2400 | const DWARFDebugInfoEntry* inlined_die = NULL; |
| 2401 | if (die->Tag() == DW_TAG_inlined_subroutine) |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2402 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2403 | inlined_die = die; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2404 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2405 | while ((die = die->GetParent()) != NULL) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2406 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2407 | if (die->Tag() == DW_TAG_subprogram) |
| 2408 | break; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2409 | } |
| 2410 | } |
| Jason Molenda | 60db6e4 | 2014-10-16 01:40:16 +0000 | [diff] [blame] | 2411 | assert (die && die->Tag() == DW_TAG_subprogram); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2412 | if (GetFunction (cu, die, sc)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2413 | { |
| 2414 | Address addr; |
| 2415 | // Parse all blocks if needed |
| 2416 | if (inlined_die) |
| 2417 | { |
| Greg Clayton | f7bb1fb | 2015-01-15 03:13:44 +0000 | [diff] [blame] | 2418 | Block &function_block = sc.function->GetBlock (true); |
| 2419 | sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); |
| 2420 | if (sc.block == NULL) |
| 2421 | sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); |
| 2422 | if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2423 | addr.Clear(); |
| 2424 | } |
| 2425 | else |
| 2426 | { |
| 2427 | sc.block = NULL; |
| 2428 | addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 2429 | } |
| 2430 | |
| 2431 | if (addr.IsValid()) |
| 2432 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2433 | sc_list.Append(sc); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2434 | return true; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2438 | return false; |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2441 | void |
| 2442 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| 2443 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2444 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2445 | SymbolContextList& sc_list) |
| 2446 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2447 | DIEArray die_offsets; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2448 | if (name_to_die.Find (name, die_offsets)) |
| 2449 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2450 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | |
| 2455 | void |
| 2456 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2457 | const NameToDIE &name_to_die, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2458 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2459 | SymbolContextList& sc_list) |
| 2460 | { |
| 2461 | DIEArray die_offsets; |
| 2462 | if (name_to_die.Find (regex, die_offsets)) |
| 2463 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2464 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | void |
| 2470 | SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, |
| 2471 | const DWARFMappedHash::MemoryTable &memory_table, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2472 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2473 | SymbolContextList& sc_list) |
| 2474 | { |
| 2475 | DIEArray die_offsets; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2476 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 2477 | if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2478 | { |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 2479 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2480 | ParseFunctions (die_offsets, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | void |
| 2485 | SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2486 | bool include_inlines, |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2487 | SymbolContextList& sc_list) |
| 2488 | { |
| 2489 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2490 | if (num_matches) |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2491 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2492 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2493 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | d7e0546 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 2494 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 2495 | const dw_offset_t die_offset = die_offsets[i]; |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2496 | ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2497 | } |
| 2498 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2499 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2500 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2501 | bool |
| 2502 | SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, |
| 2503 | const DWARFCompileUnit *dwarf_cu, |
| 2504 | uint32_t name_type_mask, |
| 2505 | const char *partial_name, |
| 2506 | const char *base_name_start, |
| 2507 | const char *base_name_end) |
| 2508 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2509 | // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: |
| 2510 | if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2511 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2512 | const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (dwarf_cu, die); |
| 2513 | |
| 2514 | if (decl_ctx_die == nullptr) |
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 2515 | return false; |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2516 | |
| 2517 | const dw_tag_t decl_ctx_tag = decl_ctx_die->Tag(); |
| 2518 | |
| 2519 | 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] | 2520 | |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2521 | if (name_type_mask == eFunctionNameTypeMethod) |
| 2522 | { |
| 2523 | if (is_cxx_method == false) |
| 2524 | return false; |
| 2525 | } |
| 2526 | |
| 2527 | if (name_type_mask == eFunctionNameTypeBase) |
| 2528 | { |
| 2529 | if (is_cxx_method == true) |
| 2530 | return false; |
| 2531 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | // Now we need to check whether the name we got back for this type matches the extra specifications |
| 2535 | // that were in the name we're looking up: |
| 2536 | if (base_name_start != partial_name || *base_name_end != '\0') |
| 2537 | { |
| 2538 | // First see if the stuff to the left matches the full name. To do that let's see if |
| 2539 | // we can pull out the mips linkage name attribute: |
| 2540 | |
| 2541 | Mangled best_name; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2542 | DWARFDebugInfoEntry::Attributes attributes; |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2543 | DWARFFormValue form_value; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2544 | die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 2545 | uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); |
| Greg Clayton | 7141554 | 2012-12-08 00:24:40 +0000 | [diff] [blame] | 2546 | if (idx == UINT32_MAX) |
| 2547 | idx = attributes.FindAttributeIndex(DW_AT_linkage_name); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2548 | if (idx != UINT32_MAX) |
| 2549 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2550 | if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2551 | { |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2552 | const char *mangled_name = form_value.AsCString(&get_debug_str_data()); |
| 2553 | if (mangled_name) |
| 2554 | best_name.SetValue (ConstString(mangled_name), true); |
| 2555 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2556 | } |
| Greg Clayton | fbea0f6 | 2012-11-15 18:05:43 +0000 | [diff] [blame] | 2557 | |
| 2558 | if (!best_name) |
| 2559 | { |
| 2560 | idx = attributes.FindAttributeIndex(DW_AT_name); |
| 2561 | if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) |
| 2562 | { |
| 2563 | const char *name = form_value.AsCString(&get_debug_str_data()); |
| 2564 | best_name.SetValue (ConstString(name), false); |
| 2565 | } |
| 2566 | } |
| 2567 | |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 2568 | const LanguageType cu_language = const_cast<DWARFCompileUnit *>(dwarf_cu)->GetLanguageType(); |
| 2569 | if (best_name.GetDemangledName(cu_language)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2570 | { |
| Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 2571 | const char *demangled = best_name.GetDemangledName(cu_language).GetCString(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2572 | if (demangled) |
| 2573 | { |
| 2574 | std::string name_no_parens(partial_name, base_name_end - partial_name); |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 2575 | const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); |
| 2576 | if (partial_in_demangled == NULL) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2577 | return false; |
| Jim Ingham | 85c13d7 | 2012-03-02 02:24:42 +0000 | [diff] [blame] | 2578 | else |
| 2579 | { |
| 2580 | // Sort out the case where our name is something like "Process::Destroy" and the match is |
| 2581 | // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on |
| 2582 | // namespace boundaries... |
| 2583 | |
| 2584 | if (partial_name[0] == ':' && partial_name[1] == ':') |
| 2585 | { |
| 2586 | // The partial name was already on a namespace boundary so all matches are good. |
| 2587 | return true; |
| 2588 | } |
| 2589 | else if (partial_in_demangled == demangled) |
| 2590 | { |
| 2591 | // They both start the same, so this is an good match. |
| 2592 | return true; |
| 2593 | } |
| 2594 | else |
| 2595 | { |
| 2596 | if (partial_in_demangled - demangled == 1) |
| 2597 | { |
| 2598 | // Only one character difference, can't be a namespace boundary... |
| 2599 | return false; |
| 2600 | } |
| 2601 | else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') |
| 2602 | { |
| 2603 | // We are on a namespace boundary, so this is also good. |
| 2604 | return true; |
| 2605 | } |
| 2606 | else |
| 2607 | return false; |
| 2608 | } |
| 2609 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | return true; |
| 2615 | } |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 2616 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2617 | uint32_t |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2618 | SymbolFileDWARF::FindFunctions (const ConstString &name, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2619 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2620 | uint32_t name_type_mask, |
| 2621 | bool include_inlines, |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 2622 | bool append, |
| 2623 | SymbolContextList& sc_list) |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2624 | { |
| 2625 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2626 | "SymbolFileDWARF::FindFunctions (name = '%s')", |
| 2627 | name.AsCString()); |
| 2628 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2629 | // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() |
| 2630 | assert ((name_type_mask & eFunctionNameTypeAuto) == 0); |
| 2631 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2632 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2633 | |
| 2634 | if (log) |
| 2635 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2636 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2637 | "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", |
| 2638 | name.GetCString(), |
| 2639 | name_type_mask, |
| 2640 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2643 | // If we aren't appending the results to this list, then clear the list |
| 2644 | if (!append) |
| 2645 | sc_list.Clear(); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2646 | |
| 2647 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 2648 | return 0; |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2649 | |
| 2650 | // If name is empty then we won't find anything. |
| 2651 | if (name.IsEmpty()) |
| 2652 | return 0; |
| Greg Clayton | 0c5cd90 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 2653 | |
| 2654 | // Remember how many sc_list are in the list before we search in case |
| 2655 | // we are appending the results to a variable list. |
| Greg Clayton | 9e31558 | 2011-09-02 04:03:59 +0000 | [diff] [blame] | 2656 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2657 | const char *name_cstr = name.GetCString(); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2658 | |
| 2659 | const uint32_t original_size = sc_list.GetSize(); |
| 2660 | |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2661 | DWARFDebugInfo* info = DebugInfo(); |
| 2662 | if (info == NULL) |
| 2663 | return 0; |
| 2664 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2665 | DWARFCompileUnit *dwarf_cu = NULL; |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2666 | std::set<const DWARFDebugInfoEntry *> resolved_dies; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2667 | if (m_using_apple_tables) |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2668 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2669 | if (m_apple_names_ap.get()) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2670 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2671 | |
| 2672 | DIEArray die_offsets; |
| 2673 | |
| 2674 | uint32_t num_matches = 0; |
| 2675 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2676 | if (name_type_mask & eFunctionNameTypeFull) |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2677 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2678 | // If they asked for the full name, match what they typed. At some point we may |
| 2679 | // want to canonicalize this (strip double spaces, etc. For now, we just add all the |
| 2680 | // dies that we find by exact match. |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2681 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2682 | for (uint32_t i = 0; i < num_matches; i++) |
| 2683 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2684 | const dw_offset_t die_offset = die_offsets[i]; |
| 2685 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2686 | if (die) |
| 2687 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2688 | if (namespace_decl) |
| 2689 | { |
| 2690 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 2691 | |
| 2692 | if (!type_system->DIEIsInNamespace (namespace_decl, this, dwarf_cu, die)) |
| 2693 | continue; |
| 2694 | } |
| 2695 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2696 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2697 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2698 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2699 | resolved_dies.insert(die); |
| 2700 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2701 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2702 | else |
| 2703 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2704 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2705 | die_offset, name_cstr); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 2706 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2707 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2708 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2709 | |
| 2710 | if (name_type_mask & eFunctionNameTypeSelector) |
| 2711 | { |
| 2712 | if (namespace_decl && *namespace_decl) |
| 2713 | return 0; // no selectors in namespaces |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2714 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2715 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2716 | // Now make sure these are actually ObjC methods. In this case we can simply look up the name, |
| 2717 | // and if it is an ObjC method name, we're good. |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2718 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2719 | for (uint32_t i = 0; i < num_matches; i++) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2720 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2721 | const dw_offset_t die_offset = die_offsets[i]; |
| 2722 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2723 | if (die) |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2724 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2725 | const char *die_name = die->GetName(this, dwarf_cu); |
| 2726 | if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) |
| 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 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2729 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2730 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2731 | resolved_dies.insert(die); |
| 2732 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2733 | } |
| 2734 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2735 | else |
| 2736 | { |
| 2737 | GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2738 | die_offset, name_cstr); |
| 2739 | } |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2740 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2741 | die_offsets.clear(); |
| 2742 | } |
| 2743 | |
| 2744 | if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) |
| 2745 | { |
| 2746 | // The apple_names table stores just the "base name" of C++ methods in the table. So we have to |
| 2747 | // extract the base name, look that up, and if there is any other information in the name we were |
| 2748 | // passed in we have to post-filter based on that. |
| 2749 | |
| 2750 | // FIXME: Arrange the logic above so that we don't calculate the base name twice: |
| 2751 | num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); |
| 2752 | |
| 2753 | for (uint32_t i = 0; i < num_matches; i++) |
| 2754 | { |
| 2755 | const dw_offset_t die_offset = die_offsets[i]; |
| 2756 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 2757 | if (die) |
| 2758 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2759 | if (namespace_decl) |
| 2760 | { |
| 2761 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 2762 | |
| 2763 | if (!type_system->DIEIsInNamespace (namespace_decl, this, dwarf_cu, die)) |
| 2764 | continue; |
| 2765 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2766 | |
| 2767 | // If we get to here, the die is good, and we should add it: |
| 2768 | if (resolved_dies.find(die) == resolved_dies.end()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2769 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2770 | { |
| 2771 | bool keep_die = true; |
| 2772 | if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) |
| 2773 | { |
| 2774 | // We are looking for either basenames or methods, so we need to |
| 2775 | // trim out the ones we won't want by looking at the type |
| 2776 | SymbolContext sc; |
| 2777 | if (sc_list.GetLastContext(sc)) |
| 2778 | { |
| 2779 | if (sc.block) |
| 2780 | { |
| 2781 | // We have an inlined function |
| 2782 | } |
| 2783 | else if (sc.function) |
| 2784 | { |
| 2785 | Type *type = sc.function->GetType(); |
| 2786 | |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2787 | if (type) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2788 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2789 | clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); |
| 2790 | if (decl_ctx->isRecord()) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2791 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2792 | if (name_type_mask & eFunctionNameTypeBase) |
| 2793 | { |
| 2794 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2795 | keep_die = false; |
| 2796 | } |
| 2797 | } |
| 2798 | else |
| 2799 | { |
| 2800 | if (name_type_mask & eFunctionNameTypeMethod) |
| 2801 | { |
| 2802 | sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); |
| 2803 | keep_die = false; |
| 2804 | } |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | else |
| 2808 | { |
| Sean Callanan | c370a8a | 2013-09-18 22:59:55 +0000 | [diff] [blame] | 2809 | GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", |
| 2810 | die_offset); |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | } |
| 2815 | if (keep_die) |
| 2816 | resolved_dies.insert(die); |
| 2817 | } |
| 2818 | } |
| 2819 | else |
| 2820 | { |
| 2821 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", |
| 2822 | die_offset, name_cstr); |
| 2823 | } |
| 2824 | } |
| 2825 | die_offsets.clear(); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2826 | } |
| 2827 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2828 | } |
| 2829 | else |
| 2830 | { |
| 2831 | |
| 2832 | // Index the DWARF if we haven't already |
| 2833 | if (!m_indexed) |
| 2834 | Index (); |
| 2835 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2836 | if (name_type_mask & eFunctionNameTypeFull) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2837 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2838 | FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2839 | |
| Ed Maste | fc7baa0 | 2013-09-09 18:00:45 +0000 | [diff] [blame] | 2840 | // FIXME Temporary workaround for global/anonymous namespace |
| Robert Flack | 5cbd3bf | 2015-05-13 18:20:02 +0000 | [diff] [blame] | 2841 | // functions debugging FreeBSD and Linux binaries. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2842 | // If we didn't find any functions in the global namespace try |
| 2843 | // looking in the basename index but ignore any returned |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2844 | // functions that have a namespace but keep functions which |
| 2845 | // have an anonymous namespace |
| 2846 | // TODO: The arch in the object file isn't correct for MSVC |
| 2847 | // binaries on windows, we should find a way to make it |
| 2848 | // correct and handle those symbols as well. |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2849 | if (sc_list.GetSize() == 0) |
| 2850 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2851 | ArchSpec arch; |
| 2852 | if (!namespace_decl && |
| 2853 | GetObjectFile()->GetArchitecture(arch) && |
| 2854 | (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() || |
| 2855 | arch.GetMachine() == llvm::Triple::hexagon)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2856 | { |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2857 | SymbolContextList temp_sc_list; |
| 2858 | FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2859 | SymbolContext sc; |
| 2860 | for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) |
| 2861 | { |
| 2862 | if (temp_sc_list.GetContextAtIndex(i, sc)) |
| 2863 | { |
| Matt Kopec | a189d49 | 2013-05-10 22:55:24 +0000 | [diff] [blame] | 2864 | ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); |
| 2865 | ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); |
| Robert Flack | eb83fab | 2015-05-15 18:59:59 +0000 | [diff] [blame] | 2866 | // Mangled names on Linux and FreeBSD are of the form: |
| 2867 | // _ZN18function_namespace13function_nameEv. |
| Matt Kopec | 04e5d58 | 2013-05-14 19:00:41 +0000 | [diff] [blame] | 2868 | if (strncmp(mangled_name.GetCString(), "_ZN", 3) || |
| 2869 | !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2870 | { |
| 2871 | sc_list.Append(sc); |
| 2872 | } |
| 2873 | } |
| 2874 | } |
| 2875 | } |
| 2876 | } |
| Matt Kopec | d608996 | 2013-05-10 17:53:48 +0000 | [diff] [blame] | 2877 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2878 | DIEArray die_offsets; |
| 2879 | DWARFCompileUnit *dwarf_cu = NULL; |
| 2880 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2881 | if (name_type_mask & eFunctionNameTypeBase) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2882 | { |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2883 | uint32_t num_base = m_function_basename_index.Find(name, die_offsets); |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2884 | for (uint32_t i = 0; i < num_base; i++) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2885 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2886 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 2887 | if (die) |
| 2888 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 2889 | if (namespace_decl) |
| 2890 | { |
| 2891 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 2892 | |
| 2893 | if (!type_system->DIEIsInNamespace (namespace_decl, this, dwarf_cu, die)) |
| 2894 | continue; |
| 2895 | } |
| 2896 | |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2897 | // 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] | 2898 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2899 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2900 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2901 | resolved_dies.insert(die); |
| 2902 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2903 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2904 | } |
| 2905 | die_offsets.clear(); |
| 2906 | } |
| 2907 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2908 | if (name_type_mask & eFunctionNameTypeMethod) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2909 | { |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 2910 | if (namespace_decl && *namespace_decl) |
| 2911 | return 0; // no methods in namespaces |
| 2912 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2913 | uint32_t num_base = m_function_method_index.Find(name, die_offsets); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2914 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2915 | for (uint32_t i = 0; i < num_base; i++) |
| 2916 | { |
| 2917 | const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); |
| 2918 | if (die) |
| 2919 | { |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2920 | // 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] | 2921 | if (resolved_dies.find(die) == resolved_dies.end()) |
| 2922 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2923 | if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2924 | resolved_dies.insert(die); |
| 2925 | } |
| Greg Clayton | aa04496 | 2011-10-13 00:59:38 +0000 | [diff] [blame] | 2926 | } |
| 2927 | } |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2928 | } |
| 2929 | die_offsets.clear(); |
| 2930 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2931 | |
| Greg Clayton | 43fe217 | 2013-04-03 02:00:15 +0000 | [diff] [blame] | 2932 | if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2933 | { |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2934 | FindFunctions (name, m_function_selector_index, include_inlines, sc_list); |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
| Greg Clayton | 4d01ace | 2011-09-29 16:58:15 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2939 | // Return the number of variable that were appended to the list |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2940 | const uint32_t num_matches = sc_list.GetSize() - original_size; |
| 2941 | |
| 2942 | if (log && num_matches > 0) |
| 2943 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2944 | GetObjectFile()->GetModule()->LogMessage (log, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2945 | "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] | 2946 | name.GetCString(), |
| 2947 | name_type_mask, |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2948 | include_inlines, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 2949 | append, |
| 2950 | num_matches); |
| 2951 | } |
| 2952 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2955 | uint32_t |
| Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2956 | 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] | 2957 | { |
| 2958 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 2959 | "SymbolFileDWARF::FindFunctions (regex = '%s')", |
| 2960 | regex.GetText()); |
| 2961 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2962 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2963 | |
| 2964 | if (log) |
| 2965 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2966 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 2967 | "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", |
| 2968 | regex.GetText(), |
| 2969 | append); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2973 | // If we aren't appending the results to this list, then clear the list |
| 2974 | if (!append) |
| 2975 | sc_list.Clear(); |
| 2976 | |
| 2977 | // Remember how many sc_list are in the list before we search in case |
| 2978 | // we are appending the results to a variable list. |
| 2979 | uint32_t original_size = sc_list.GetSize(); |
| 2980 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2981 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2982 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 2983 | if (m_apple_names_ap.get()) |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2984 | FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2985 | } |
| 2986 | else |
| 2987 | { |
| Jim Ingham | 4cda6e0 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 2988 | // Index the DWARF if we haven't already |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2989 | if (!m_indexed) |
| 2990 | Index (); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2991 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2992 | FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2993 | |
| Pavel Labath | a73d657 | 2015-03-13 10:22:00 +0000 | [diff] [blame] | 2994 | FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 2995 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2996 | |
| 2997 | // Return the number of variable that were appended to the list |
| 2998 | return sc_list.GetSize() - original_size; |
| 2999 | } |
| Jim Ingham | 318c9f2 | 2011-08-26 19:44:13 +0000 | [diff] [blame] | 3000 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3001 | uint32_t |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3002 | SymbolFileDWARF::FindTypes (const SymbolContext& sc, |
| 3003 | const ConstString &name, |
| 3004 | const lldb_private::ClangNamespaceDecl *namespace_decl, |
| 3005 | bool append, |
| 3006 | uint32_t max_matches, |
| 3007 | TypeList& types) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3008 | { |
| Greg Clayton | c685f8e | 2010-09-15 04:15:46 +0000 | [diff] [blame] | 3009 | DWARFDebugInfo* info = DebugInfo(); |
| 3010 | if (info == NULL) |
| 3011 | return 0; |
| 3012 | |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3013 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3014 | |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3015 | if (log) |
| 3016 | { |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3017 | if (namespace_decl) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3018 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3019 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", |
| 3020 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3021 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3022 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3023 | append, max_matches); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3024 | else |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3025 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3026 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3027 | name.GetCString(), append, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3028 | max_matches); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3031 | // If we aren't appending the results to this list, then clear the list |
| 3032 | if (!append) |
| 3033 | types.Clear(); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3034 | |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3035 | if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3036 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3037 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3038 | DIEArray die_offsets; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3039 | |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3040 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3041 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3042 | if (m_apple_types_ap.get()) |
| 3043 | { |
| 3044 | const char *name_cstr = name.GetCString(); |
| 3045 | m_apple_types_ap->FindByName (name_cstr, die_offsets); |
| 3046 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3047 | } |
| 3048 | else |
| 3049 | { |
| 3050 | if (!m_indexed) |
| 3051 | Index (); |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3052 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3053 | m_type_index.Find (name, die_offsets); |
| 3054 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3055 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3056 | const size_t num_die_matches = die_offsets.size(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3057 | |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3058 | if (num_die_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3059 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3060 | const uint32_t initial_types_size = types.GetSize(); |
| 3061 | DWARFCompileUnit* dwarf_cu = NULL; |
| 3062 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3063 | DWARFDebugInfo* debug_info = DebugInfo(); |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3064 | for (size_t i=0; i<num_die_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3065 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3066 | const dw_offset_t die_offset = die_offsets[i]; |
| 3067 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| 3068 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3069 | if (die) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3070 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3071 | if (namespace_decl) |
| 3072 | { |
| 3073 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| 3074 | |
| 3075 | if (!type_system->DIEIsInNamespace (namespace_decl, this, dwarf_cu, die)) |
| 3076 | continue; |
| 3077 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3078 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3079 | Type *matching_type = ResolveType (dwarf_cu, die); |
| 3080 | if (matching_type) |
| 3081 | { |
| 3082 | // 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] | 3083 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3084 | if (types.GetSize() >= max_matches) |
| 3085 | break; |
| 3086 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 3087 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3088 | else |
| 3089 | { |
| 3090 | if (m_using_apple_tables) |
| 3091 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3092 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3093 | die_offset, name.GetCString()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3094 | } |
| 3095 | } |
| 3096 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3097 | } |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3098 | const uint32_t num_matches = types.GetSize() - initial_types_size; |
| 3099 | if (log && num_matches) |
| 3100 | { |
| 3101 | if (namespace_decl) |
| 3102 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3103 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3104 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", |
| 3105 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3106 | static_cast<void*>(namespace_decl->GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3107 | namespace_decl->GetQualifiedName().c_str(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3108 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3109 | num_matches); |
| 3110 | } |
| 3111 | else |
| 3112 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3113 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3114 | "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", |
| 3115 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3116 | append, max_matches, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3117 | num_matches); |
| 3118 | } |
| 3119 | } |
| 3120 | return num_matches; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3121 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3122 | return 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3126 | ClangNamespaceDecl |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3127 | SymbolFileDWARF::FindNamespace (const SymbolContext& sc, |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3128 | const ConstString &name, |
| 3129 | const lldb_private::ClangNamespaceDecl *parent_namespace_decl) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3130 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3131 | Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3132 | |
| 3133 | if (log) |
| 3134 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3135 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3136 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", |
| 3137 | name.GetCString()); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3138 | } |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3139 | |
| 3140 | if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3141 | return ClangNamespaceDecl(); |
| Greg Clayton | 21f2a49 | 2011-10-06 00:09:08 +0000 | [diff] [blame] | 3142 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3143 | ClangNamespaceDecl namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3144 | DWARFDebugInfo* info = DebugInfo(); |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3145 | if (info) |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3146 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3147 | DIEArray die_offsets; |
| 3148 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3149 | // Index if we already haven't to make sure the compile units |
| 3150 | // get indexed and make their global DIE index list |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3151 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3152 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3153 | if (m_apple_namespaces_ap.get()) |
| 3154 | { |
| 3155 | const char *name_cstr = name.GetCString(); |
| 3156 | m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); |
| 3157 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3158 | } |
| 3159 | else |
| 3160 | { |
| 3161 | if (!m_indexed) |
| 3162 | Index (); |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3163 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3164 | m_namespace_index.Find (name, die_offsets); |
| 3165 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3166 | |
| 3167 | DWARFCompileUnit* dwarf_cu = NULL; |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3168 | const DWARFDebugInfoEntry* die = NULL; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3169 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3170 | if (num_matches) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3171 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3172 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3173 | for (size_t i=0; i<num_matches; ++i) |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3174 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3175 | const dw_offset_t die_offset = die_offsets[i]; |
| 3176 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); |
| Sean Callanan | 213fdb8 | 2011-10-13 01:49:10 +0000 | [diff] [blame] | 3177 | |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3178 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3179 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3180 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3181 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3182 | if (parent_namespace_decl) |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3183 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3184 | if (type_system && !type_system->DIEIsInNamespace (parent_namespace_decl, this, dwarf_cu, die)) |
| 3185 | continue; |
| 3186 | } |
| 3187 | |
| 3188 | if (type_system) |
| 3189 | { |
| 3190 | clang::NamespaceDecl *clang_namespace_decl = type_system->ResolveNamespaceDIE (this, dwarf_cu, die); |
| 3191 | if (clang_namespace_decl) |
| 3192 | { |
| 3193 | namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); |
| 3194 | namespace_decl.SetNamespaceDecl (clang_namespace_decl); |
| 3195 | break; |
| 3196 | } |
| 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 | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3211 | if (log && namespace_decl.GetNamespaceDecl()) |
| 3212 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3213 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3214 | "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", |
| 3215 | name.GetCString(), |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3216 | static_cast<const void*>(namespace_decl.GetNamespaceDecl()), |
| Greg Clayton | 437a135 | 2012-04-09 22:43:43 +0000 | [diff] [blame] | 3217 | namespace_decl.GetQualifiedName().c_str()); |
| 3218 | } |
| 3219 | |
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 3220 | return namespace_decl; |
| Greg Clayton | 96d7d74 | 2010-11-10 23:42:09 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3223 | uint32_t |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3224 | 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] | 3225 | { |
| 3226 | // Remember how many sc_list are in the list before we search in case |
| 3227 | // we are appending the results to a variable list. |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3228 | uint32_t original_size = types.GetSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3229 | |
| 3230 | const uint32_t num_die_offsets = die_offsets.size(); |
| 3231 | // Parse all of the types we found from the pubtypes matches |
| 3232 | uint32_t i; |
| 3233 | uint32_t num_matches = 0; |
| 3234 | for (i = 0; i < num_die_offsets; ++i) |
| 3235 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3236 | Type *matching_type = ResolveTypeUID (die_offsets[i]); |
| 3237 | if (matching_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3238 | { |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3239 | // 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] | 3240 | types.InsertUnique (matching_type->shared_from_this()); |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3241 | ++num_matches; |
| 3242 | if (num_matches >= max_matches) |
| 3243 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | // Return the number of variable that were appended to the list |
| Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3248 | return types.GetSize() - original_size; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3251 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3252 | TypeSP |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3253 | SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3254 | { |
| 3255 | TypeSP type_sp; |
| 3256 | if (die != NULL) |
| 3257 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3258 | assert(dwarf_cu != NULL); |
| Greg Clayton | 594e5ed | 2010-09-27 21:07:38 +0000 | [diff] [blame] | 3259 | Type *type_ptr = m_die_to_type.lookup (die); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3260 | if (type_ptr == NULL) |
| 3261 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3262 | CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); |
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 3263 | assert (lldb_cu); |
| 3264 | SymbolContext sc(lldb_cu); |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3265 | type_sp = ParseType(sc, dwarf_cu, die, NULL); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3266 | } |
| 3267 | else if (type_ptr != DIE_IS_BEING_PARSED) |
| 3268 | { |
| 3269 | // Grab the existing type from the master types lists |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3270 | type_sp = type_ptr->shared_from_this(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | } |
| 3274 | return type_sp; |
| 3275 | } |
| 3276 | |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3277 | |
| 3278 | const DWARFDebugInfoEntry * |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3279 | SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3280 | { |
| 3281 | if (cu && die) |
| 3282 | { |
| 3283 | const DWARFDebugInfoEntry * const decl_die = die; |
| 3284 | |
| 3285 | while (die != NULL) |
| 3286 | { |
| 3287 | // If this is the original DIE that we are searching for a declaration |
| 3288 | // for, then don't look in the cache as we don't want our own decl |
| 3289 | // context to be our decl context... |
| 3290 | if (decl_die != die) |
| 3291 | { |
| 3292 | switch (die->Tag()) |
| 3293 | { |
| 3294 | case DW_TAG_compile_unit: |
| 3295 | case DW_TAG_namespace: |
| 3296 | case DW_TAG_structure_type: |
| 3297 | case DW_TAG_union_type: |
| 3298 | case DW_TAG_class_type: |
| 3299 | return die; |
| 3300 | |
| 3301 | default: |
| 3302 | break; |
| 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); |
| 3307 | if (die_offset != DW_INVALID_OFFSET) |
| 3308 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3309 | DWARFCompileUnit *spec_cu = const_cast<DWARFCompileUnit *>(cu); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3310 | const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); |
| 3311 | const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); |
| 3312 | if (spec_die_decl_ctx_die) |
| 3313 | return spec_die_decl_ctx_die; |
| 3314 | } |
| 3315 | |
| 3316 | die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); |
| 3317 | if (die_offset != DW_INVALID_OFFSET) |
| 3318 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3319 | DWARFCompileUnit *abs_cu = const_cast<DWARFCompileUnit *>(cu); |
| Greg Clayton | 2bc22f8 | 2011-09-30 03:20:47 +0000 | [diff] [blame] | 3320 | const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); |
| 3321 | const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); |
| 3322 | if (abs_die_decl_ctx_die) |
| 3323 | return abs_die_decl_ctx_die; |
| 3324 | } |
| 3325 | |
| 3326 | die = die->GetParent(); |
| 3327 | } |
| 3328 | } |
| 3329 | return NULL; |
| 3330 | } |
| 3331 | |
| 3332 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3333 | Symbol * |
| 3334 | SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) |
| 3335 | { |
| 3336 | Symbol *objc_class_symbol = NULL; |
| 3337 | if (m_obj_file) |
| 3338 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 3339 | Symtab *symtab = m_obj_file->GetSymtab (); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3340 | if (symtab) |
| 3341 | { |
| 3342 | objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, |
| 3343 | eSymbolTypeObjCClass, |
| 3344 | Symtab::eDebugNo, |
| 3345 | Symtab::eVisibilityAny); |
| 3346 | } |
| 3347 | } |
| 3348 | return objc_class_symbol; |
| 3349 | } |
| 3350 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3351 | // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't |
| 3352 | // then we can end up looking through all class types for a complete type and never find |
| 3353 | // the full definition. We need to know if this attribute is supported, so we determine |
| 3354 | // this here and cache th result. We also need to worry about the debug map DWARF file |
| 3355 | // if we are doing darwin DWARF in .o file debugging. |
| 3356 | bool |
| 3357 | SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) |
| 3358 | { |
| 3359 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) |
| 3360 | { |
| 3361 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; |
| 3362 | if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3363 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3364 | else |
| 3365 | { |
| 3366 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3367 | const uint32_t num_compile_units = GetNumCompileUnits(); |
| 3368 | for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) |
| 3369 | { |
| Greg Clayton | 53eb1c2 | 2012-04-02 22:59:12 +0000 | [diff] [blame] | 3370 | DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); |
| 3371 | 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] | 3372 | { |
| 3373 | m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; |
| 3374 | break; |
| 3375 | } |
| 3376 | } |
| 3377 | } |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3378 | if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3379 | return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); |
| 3380 | } |
| 3381 | return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; |
| 3382 | } |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3383 | |
| 3384 | // This function can be used when a DIE is found that is a forward declaration |
| 3385 | // DIE and we want to try and find a type that has the complete definition. |
| 3386 | TypeSP |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3387 | SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, |
| 3388 | const ConstString &type_name, |
| 3389 | bool must_be_implementation) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3390 | { |
| 3391 | |
| 3392 | TypeSP type_sp; |
| 3393 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3394 | if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3395 | return type_sp; |
| 3396 | |
| 3397 | DIEArray die_offsets; |
| 3398 | |
| 3399 | if (m_using_apple_tables) |
| 3400 | { |
| 3401 | if (m_apple_types_ap.get()) |
| 3402 | { |
| 3403 | const char *name_cstr = type_name.GetCString(); |
| Greg Clayton | 68221ec | 2012-01-18 20:58:12 +0000 | [diff] [blame] | 3404 | m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3405 | } |
| 3406 | } |
| 3407 | else |
| 3408 | { |
| 3409 | if (!m_indexed) |
| 3410 | Index (); |
| 3411 | |
| 3412 | m_type_index.Find (type_name, die_offsets); |
| 3413 | } |
| 3414 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3415 | const size_t num_matches = die_offsets.size(); |
| 3416 | |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3417 | DWARFCompileUnit* type_cu = NULL; |
| 3418 | const DWARFDebugInfoEntry* type_die = NULL; |
| 3419 | if (num_matches) |
| 3420 | { |
| 3421 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3422 | for (size_t i=0; i<num_matches; ++i) |
| 3423 | { |
| 3424 | const dw_offset_t die_offset = die_offsets[i]; |
| 3425 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 3426 | |
| 3427 | if (type_die) |
| 3428 | { |
| 3429 | bool try_resolving_type = false; |
| 3430 | |
| 3431 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 3432 | if (type_die != die) |
| 3433 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3434 | switch (type_die->Tag()) |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3435 | { |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3436 | case DW_TAG_class_type: |
| 3437 | case DW_TAG_structure_type: |
| 3438 | try_resolving_type = true; |
| 3439 | break; |
| 3440 | default: |
| 3441 | break; |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | if (try_resolving_type) |
| 3446 | { |
| Ed Maste | 4c24b12 | 2013-10-17 20:13:14 +0000 | [diff] [blame] | 3447 | if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) |
| 3448 | 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] | 3449 | |
| 3450 | if (try_resolving_type) |
| 3451 | { |
| 3452 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 3453 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3454 | { |
| Ed Maste | a0191d1 | 2013-10-17 20:42:56 +0000 | [diff] [blame] | 3455 | 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] | 3456 | MakeUserID(die->GetOffset()), |
| Jim Ingham | 4af5961 | 2014-12-19 19:20:44 +0000 | [diff] [blame] | 3457 | m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3458 | MakeUserID(type_die->GetOffset()), |
| 3459 | MakeUserID(type_cu->GetOffset())); |
| 3460 | |
| Greg Clayton | c7f03b6 | 2012-01-12 04:33:28 +0000 | [diff] [blame] | 3461 | if (die) |
| 3462 | m_die_to_type[die] = resolved_type; |
| Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3463 | type_sp = resolved_type->shared_from_this(); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3464 | break; |
| 3465 | } |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | else |
| 3470 | { |
| 3471 | if (m_using_apple_tables) |
| 3472 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3473 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3474 | die_offset, type_name.GetCString()); |
| Greg Clayton | 901c5ca | 2011-12-03 04:40:03 +0000 | [diff] [blame] | 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | } |
| 3479 | } |
| 3480 | return type_sp; |
| 3481 | } |
| 3482 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3483 | |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3484 | //---------------------------------------------------------------------- |
| 3485 | // This function helps to ensure that the declaration contexts match for |
| 3486 | // two different DIEs. Often times debug information will refer to a |
| 3487 | // forward declaration of a type (the equivalent of "struct my_struct;". |
| 3488 | // There will often be a declaration of that type elsewhere that has the |
| 3489 | // full definition. When we go looking for the full type "my_struct", we |
| 3490 | // will find one or more matches in the accelerator tables and we will |
| 3491 | // then need to make sure the type was in the same declaration context |
| 3492 | // as the original DIE. This function can efficiently compare two DIEs |
| 3493 | // and will return true when the declaration context matches, and false |
| 3494 | // when they don't. |
| 3495 | //---------------------------------------------------------------------- |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3496 | bool |
| 3497 | SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, |
| 3498 | DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) |
| 3499 | { |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3500 | if (die1 == die2) |
| 3501 | return true; |
| 3502 | |
| 3503 | #if defined (LLDB_CONFIGURATION_DEBUG) |
| 3504 | // You can't and shouldn't call this function with a compile unit from |
| 3505 | // two different SymbolFileDWARF instances. |
| 3506 | assert (DebugInfo()->ContainsCompileUnit (cu1)); |
| 3507 | assert (DebugInfo()->ContainsCompileUnit (cu2)); |
| 3508 | #endif |
| 3509 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3510 | DWARFDIECollection decl_ctx_1; |
| 3511 | DWARFDIECollection decl_ctx_2; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3512 | //The declaration DIE stack is a stack of the declaration context |
| 3513 | // DIEs all the way back to the compile unit. If a type "T" is |
| 3514 | // declared inside a class "B", and class "B" is declared inside |
| 3515 | // a class "A" and class "A" is in a namespace "lldb", and the |
| 3516 | // namespace is in a compile unit, there will be a stack of DIEs: |
| 3517 | // |
| 3518 | // [0] DW_TAG_class_type for "B" |
| 3519 | // [1] DW_TAG_class_type for "A" |
| 3520 | // [2] DW_TAG_namespace for "lldb" |
| 3521 | // [3] DW_TAG_compile_unit for the source file. |
| 3522 | // |
| 3523 | // We grab both contexts and make sure that everything matches |
| 3524 | // all the way back to the compiler unit. |
| 3525 | |
| 3526 | // First lets grab the decl contexts for both DIEs |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3527 | die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 3528 | die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3529 | // Make sure the context arrays have the same size, otherwise |
| 3530 | // we are done |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3531 | const size_t count1 = decl_ctx_1.Size(); |
| 3532 | const size_t count2 = decl_ctx_2.Size(); |
| 3533 | if (count1 != count2) |
| 3534 | return false; |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3535 | |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3536 | // 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] | 3537 | // compile unit. If they don't, then we are done. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3538 | const DWARFDebugInfoEntry *decl_ctx_die1; |
| 3539 | const DWARFDebugInfoEntry *decl_ctx_die2; |
| 3540 | size_t i; |
| 3541 | for (i=0; i<count1; i++) |
| 3542 | { |
| 3543 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 3544 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 3545 | if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) |
| 3546 | return false; |
| 3547 | } |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3548 | #if defined LLDB_CONFIGURATION_DEBUG |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3549 | |
| 3550 | // Make sure the top item in the decl context die array is always |
| 3551 | // DW_TAG_compile_unit. If it isn't then something went wrong in |
| 3552 | // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3553 | assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3554 | |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3555 | #endif |
| 3556 | // Always skip the compile unit when comparing by only iterating up to |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3557 | // "count - 1". Here we compare the names as we go. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3558 | for (i=0; i<count1 - 1; i++) |
| 3559 | { |
| 3560 | decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); |
| 3561 | decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); |
| 3562 | const char *name1 = decl_ctx_die1->GetName(this, cu1); |
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 3563 | const char *name2 = decl_ctx_die2->GetName(this, cu2); |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3564 | // If the string was from a DW_FORM_strp, then the pointer will often |
| 3565 | // be the same! |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3566 | if (name1 == name2) |
| 3567 | continue; |
| 3568 | |
| 3569 | // Name pointers are not equal, so only compare the strings |
| 3570 | // if both are not NULL. |
| 3571 | if (name1 && name2) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3572 | { |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3573 | // If the strings don't compare, we are done... |
| 3574 | if (strcmp(name1, name2) != 0) |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3575 | return false; |
| Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 3576 | } |
| 3577 | else |
| 3578 | { |
| 3579 | // One name was NULL while the other wasn't |
| 3580 | return false; |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3581 | } |
| 3582 | } |
| Greg Clayton | 80c2630 | 2012-02-05 06:12:47 +0000 | [diff] [blame] | 3583 | // We made it through all of the checks and the declaration contexts |
| 3584 | // are equal. |
| Greg Clayton | 890ff56 | 2012-02-02 05:48:16 +0000 | [diff] [blame] | 3585 | return true; |
| 3586 | } |
| Greg Clayton | 220a007 | 2011-12-09 08:48:30 +0000 | [diff] [blame] | 3587 | |
| Greg Clayton | 2ccf8cf | 2010-11-07 21:02:03 +0000 | [diff] [blame] | 3588 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3589 | TypeSP |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3590 | SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) |
| 3591 | { |
| 3592 | TypeSP type_sp; |
| 3593 | |
| 3594 | const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); |
| 3595 | if (dwarf_decl_ctx_count > 0) |
| 3596 | { |
| 3597 | const ConstString type_name(dwarf_decl_ctx[0].name); |
| 3598 | const dw_tag_t tag = dwarf_decl_ctx[0].tag; |
| 3599 | |
| 3600 | if (type_name) |
| 3601 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3602 | Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3603 | if (log) |
| 3604 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3605 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3606 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", |
| 3607 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3608 | dwarf_decl_ctx.GetQualifiedName()); |
| 3609 | } |
| 3610 | |
| 3611 | DIEArray die_offsets; |
| 3612 | |
| 3613 | if (m_using_apple_tables) |
| 3614 | { |
| 3615 | if (m_apple_types_ap.get()) |
| 3616 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3617 | const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); |
| 3618 | const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); |
| 3619 | if (has_tag && has_qualified_name_hash) |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3620 | { |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3621 | const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); |
| 3622 | const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); |
| 3623 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3624 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); |
| Greg Clayton | cb9c8cf | 2013-02-06 23:56:13 +0000 | [diff] [blame] | 3625 | m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); |
| 3626 | } |
| 3627 | else if (has_tag) |
| 3628 | { |
| 3629 | if (log) |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3630 | GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3631 | m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); |
| 3632 | } |
| 3633 | else |
| 3634 | { |
| 3635 | m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); |
| 3636 | } |
| 3637 | } |
| 3638 | } |
| 3639 | else |
| 3640 | { |
| 3641 | if (!m_indexed) |
| 3642 | Index (); |
| 3643 | |
| 3644 | m_type_index.Find (type_name, die_offsets); |
| 3645 | } |
| 3646 | |
| 3647 | const size_t num_matches = die_offsets.size(); |
| 3648 | |
| 3649 | |
| 3650 | DWARFCompileUnit* type_cu = NULL; |
| 3651 | const DWARFDebugInfoEntry* type_die = NULL; |
| 3652 | if (num_matches) |
| 3653 | { |
| 3654 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3655 | for (size_t i=0; i<num_matches; ++i) |
| 3656 | { |
| 3657 | const dw_offset_t die_offset = die_offsets[i]; |
| 3658 | type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); |
| 3659 | |
| 3660 | if (type_die) |
| 3661 | { |
| 3662 | bool try_resolving_type = false; |
| 3663 | |
| 3664 | // Don't try and resolve the DIE we are looking for with the DIE itself! |
| 3665 | const dw_tag_t type_tag = type_die->Tag(); |
| 3666 | // Make sure the tags match |
| 3667 | if (type_tag == tag) |
| 3668 | { |
| 3669 | // The tags match, lets try resolving this type |
| 3670 | try_resolving_type = true; |
| 3671 | } |
| 3672 | else |
| 3673 | { |
| 3674 | // The tags don't match, but we need to watch our for a |
| 3675 | // forward declaration for a struct and ("struct foo") |
| 3676 | // ends up being a class ("class foo { ... };") or |
| 3677 | // vice versa. |
| 3678 | switch (type_tag) |
| 3679 | { |
| 3680 | case DW_TAG_class_type: |
| 3681 | // We had a "class foo", see if we ended up with a "struct foo { ... };" |
| 3682 | try_resolving_type = (tag == DW_TAG_structure_type); |
| 3683 | break; |
| 3684 | case DW_TAG_structure_type: |
| 3685 | // We had a "struct foo", see if we ended up with a "class foo { ... };" |
| 3686 | try_resolving_type = (tag == DW_TAG_class_type); |
| 3687 | break; |
| 3688 | default: |
| 3689 | // Tags don't match, don't event try to resolve |
| 3690 | // using this type whose name matches.... |
| 3691 | break; |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | if (try_resolving_type) |
| 3696 | { |
| 3697 | DWARFDeclContext type_dwarf_decl_ctx; |
| 3698 | type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); |
| 3699 | |
| 3700 | if (log) |
| 3701 | { |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3702 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3703 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", |
| 3704 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3705 | dwarf_decl_ctx.GetQualifiedName(), |
| 3706 | type_die->GetOffset(), |
| 3707 | type_dwarf_decl_ctx.GetQualifiedName()); |
| 3708 | } |
| 3709 | |
| 3710 | // Make sure the decl contexts match all the way up |
| 3711 | if (dwarf_decl_ctx == type_dwarf_decl_ctx) |
| 3712 | { |
| 3713 | Type *resolved_type = ResolveType (type_cu, type_die, false); |
| 3714 | if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) |
| 3715 | { |
| 3716 | type_sp = resolved_type->shared_from_this(); |
| 3717 | break; |
| 3718 | } |
| 3719 | } |
| 3720 | } |
| 3721 | else |
| 3722 | { |
| 3723 | if (log) |
| 3724 | { |
| 3725 | std::string qualified_name; |
| 3726 | type_die->GetQualifiedName(this, type_cu, qualified_name); |
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3727 | GetObjectFile()->GetModule()->LogMessage (log, |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3728 | "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", |
| 3729 | DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), |
| 3730 | dwarf_decl_ctx.GetQualifiedName(), |
| 3731 | type_die->GetOffset(), |
| 3732 | qualified_name.c_str()); |
| 3733 | } |
| 3734 | } |
| 3735 | } |
| 3736 | else |
| 3737 | { |
| 3738 | if (m_using_apple_tables) |
| 3739 | { |
| 3740 | GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", |
| 3741 | die_offset, type_name.GetCString()); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | } |
| 3746 | } |
| 3747 | } |
| 3748 | } |
| 3749 | return type_sp; |
| 3750 | } |
| 3751 | |
| Greg Clayton | a8022fa | 2012-04-24 21:22:41 +0000 | [diff] [blame] | 3752 | TypeSP |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3753 | 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] | 3754 | { |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3755 | TypeSP type_sp; |
| 3756 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3757 | TypeSystem *type_system = GetTypeSystemForLanguage(dwarf_cu->GetLanguageType()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3758 | |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3759 | if (type_system) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3760 | { |
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 3761 | Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO); |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3762 | type_sp = type_system->ParseTypeFromDWARF (sc, this, dwarf_cu, die, log, type_is_new_ptr); |
| 3763 | if (type_sp) |
| 3764 | { |
| 3765 | TypeList* type_list = GetTypeList(); |
| 3766 | if (type_list) |
| 3767 | type_list->Insert(type_sp); |
| 3768 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3769 | } |
| Greg Clayton | 196e8cd | 2015-08-17 20:31:46 +0000 | [diff] [blame] | 3770 | |
| 3771 | return type_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | size_t |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3775 | SymbolFileDWARF::ParseTypes |
| 3776 | ( |
| 3777 | const SymbolContext& sc, |
| 3778 | DWARFCompileUnit* dwarf_cu, |
| 3779 | const DWARFDebugInfoEntry *die, |
| 3780 | bool parse_siblings, |
| 3781 | bool parse_children |
| 3782 | ) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3783 | { |
| 3784 | size_t types_added = 0; |
| 3785 | while (die != NULL) |
| 3786 | { |
| 3787 | bool type_is_new = false; |
| Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3788 | if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3789 | { |
| 3790 | if (type_is_new) |
| 3791 | ++types_added; |
| 3792 | } |
| 3793 | |
| 3794 | if (parse_children && die->HasChildren()) |
| 3795 | { |
| 3796 | if (die->Tag() == DW_TAG_subprogram) |
| 3797 | { |
| 3798 | SymbolContext child_sc(sc); |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3799 | child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3800 | types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 3801 | } |
| 3802 | else |
| 3803 | types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); |
| 3804 | } |
| 3805 | |
| 3806 | if (parse_siblings) |
| 3807 | die = die->GetSibling(); |
| 3808 | else |
| 3809 | die = NULL; |
| 3810 | } |
| 3811 | return types_added; |
| 3812 | } |
| 3813 | |
| 3814 | |
| 3815 | size_t |
| 3816 | SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) |
| 3817 | { |
| 3818 | assert(sc.comp_unit && sc.function); |
| 3819 | size_t functions_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3820 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3821 | if (dwarf_cu) |
| 3822 | { |
| 3823 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 3824 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 3825 | if (function_die) |
| 3826 | { |
| Greg Clayton | dd7feaf | 2011-08-12 17:54:33 +0000 | [diff] [blame] | 3827 | 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] | 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | return functions_added; |
| 3832 | } |
| 3833 | |
| 3834 | |
| 3835 | size_t |
| 3836 | SymbolFileDWARF::ParseTypes (const SymbolContext &sc) |
| 3837 | { |
| 3838 | // At least a compile unit must be valid |
| 3839 | assert(sc.comp_unit); |
| 3840 | size_t types_added = 0; |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3841 | DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3842 | if (dwarf_cu) |
| 3843 | { |
| 3844 | if (sc.function) |
| 3845 | { |
| 3846 | dw_offset_t function_die_offset = sc.function->GetID(); |
| 3847 | const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); |
| 3848 | if (func_die && func_die->HasChildren()) |
| 3849 | { |
| 3850 | types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); |
| 3851 | } |
| 3852 | } |
| 3853 | else |
| 3854 | { |
| 3855 | const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); |
| 3856 | if (dwarf_cu_die && dwarf_cu_die->HasChildren()) |
| 3857 | { |
| 3858 | types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); |
| 3859 | } |
| 3860 | } |
| 3861 | } |
| 3862 | |
| 3863 | return types_added; |
| 3864 | } |
| 3865 | |
| 3866 | size_t |
| 3867 | SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) |
| 3868 | { |
| 3869 | if (sc.comp_unit != NULL) |
| 3870 | { |
| Greg Clayton | 4b3dc10 | 2010-11-01 20:32:12 +0000 | [diff] [blame] | 3871 | DWARFDebugInfo* info = DebugInfo(); |
| 3872 | if (info == NULL) |
| 3873 | return 0; |
| 3874 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3875 | if (sc.function) |
| 3876 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3877 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); |
| 3878 | |
| 3879 | if (dwarf_cu == NULL) |
| 3880 | return 0; |
| 3881 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3882 | const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 3883 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3884 | dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); |
| 3885 | if (func_lo_pc != LLDB_INVALID_ADDRESS) |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3886 | { |
| 3887 | 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] | 3888 | |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3889 | // Let all blocks know they have parse all their variables |
| 3890 | sc.function->GetBlock (false).SetDidParseVariables (true, true); |
| 3891 | return num_variables; |
| 3892 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3893 | } |
| 3894 | else if (sc.comp_unit) |
| 3895 | { |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 3896 | DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); |
| 3897 | |
| 3898 | if (dwarf_cu == NULL) |
| 3899 | return 0; |
| 3900 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3901 | uint32_t vars_added = 0; |
| 3902 | VariableListSP variables (sc.comp_unit->GetVariableList(false)); |
| 3903 | |
| 3904 | if (variables.get() == NULL) |
| 3905 | { |
| 3906 | variables.reset(new VariableList()); |
| 3907 | sc.comp_unit->SetVariableList(variables); |
| 3908 | |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3909 | DWARFCompileUnit* match_dwarf_cu = NULL; |
| 3910 | const DWARFDebugInfoEntry* die = NULL; |
| 3911 | DIEArray die_offsets; |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3912 | if (m_using_apple_tables) |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3913 | { |
| Greg Clayton | 97fbc34 | 2011-10-20 22:30:33 +0000 | [diff] [blame] | 3914 | if (m_apple_names_ap.get()) |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 3915 | { |
| 3916 | DWARFMappedHash::DIEInfoArray hash_data_array; |
| 3917 | if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), |
| 3918 | dwarf_cu->GetNextCompileUnitOffset(), |
| 3919 | hash_data_array)) |
| 3920 | { |
| 3921 | DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); |
| 3922 | } |
| 3923 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3924 | } |
| 3925 | else |
| 3926 | { |
| 3927 | // Index if we already haven't to make sure the compile units |
| 3928 | // get indexed and make their global DIE index list |
| 3929 | if (!m_indexed) |
| 3930 | Index (); |
| 3931 | |
| 3932 | m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), |
| 3933 | dwarf_cu->GetNextCompileUnitOffset(), |
| 3934 | die_offsets); |
| 3935 | } |
| 3936 | |
| 3937 | const size_t num_matches = die_offsets.size(); |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3938 | if (num_matches) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3939 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3940 | DWARFDebugInfo* debug_info = DebugInfo(); |
| 3941 | for (size_t i=0; i<num_matches; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3942 | { |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3943 | const dw_offset_t die_offset = die_offsets[i]; |
| 3944 | die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3945 | if (die) |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3946 | { |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3947 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); |
| 3948 | if (var_sp) |
| 3949 | { |
| 3950 | variables->AddVariableIfUnique (var_sp); |
| 3951 | ++vars_added; |
| 3952 | } |
| Greg Clayton | d4a2b37 | 2011-09-12 23:21:58 +0000 | [diff] [blame] | 3953 | } |
| Greg Clayton | 95d8790 | 2011-11-11 03:16:25 +0000 | [diff] [blame] | 3954 | else |
| 3955 | { |
| 3956 | if (m_using_apple_tables) |
| 3957 | { |
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 3958 | 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] | 3959 | } |
| 3960 | } |
| 3961 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3962 | } |
| 3963 | } |
| 3964 | } |
| 3965 | return vars_added; |
| 3966 | } |
| 3967 | } |
| 3968 | return 0; |
| 3969 | } |
| 3970 | |
| 3971 | |
| 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; |
| 3993 | const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); |
| 3994 | if (num_attributes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3995 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 3996 | const char *name = NULL; |
| 3997 | const char *mangled = NULL; |
| 3998 | Declaration decl; |
| 3999 | uint32_t i; |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4000 | lldb::user_id_t type_uid = LLDB_INVALID_UID; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4001 | DWARFExpression location; |
| 4002 | bool is_external = false; |
| 4003 | bool is_artificial = false; |
| 4004 | bool location_is_const_value_data = false; |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4005 | bool has_explicit_location = false; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4006 | DWARFFormValue const_value; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 4007 | //AccessType accessibility = eAccessNone; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4008 | |
| 4009 | for (i=0; i<num_attributes; ++i) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4010 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4011 | dw_attr_t attr = attributes.AttributeAtIndex(i); |
| 4012 | DWARFFormValue form_value; |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4013 | |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4014 | if (attributes.ExtractFormValueAtIndex(this, i, form_value)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4015 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4016 | switch (attr) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4017 | { |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4018 | case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; |
| 4019 | case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; |
| 4020 | case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; |
| 4021 | 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] | 4022 | case DW_AT_linkage_name: |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4023 | 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] | 4024 | case DW_AT_type: type_uid = form_value.Reference(); break; |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4025 | case DW_AT_external: is_external = form_value.Boolean(); break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4026 | case DW_AT_const_value: |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4027 | // If we have already found a DW_AT_location attribute, ignore this attribute. |
| 4028 | if (!has_explicit_location) |
| 4029 | { |
| 4030 | location_is_const_value_data = true; |
| 4031 | // 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] | 4032 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4033 | if (DWARFFormValue::IsBlockForm(form_value.Form())) |
| 4034 | { |
| 4035 | // Retrieve the value as a block expression. |
| 4036 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 4037 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4038 | location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4039 | } |
| 4040 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 4041 | { |
| 4042 | // Retrieve the value as a data expression. |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4043 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4044 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 4045 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4046 | if (data_length == 0) |
| 4047 | { |
| 4048 | const uint8_t *data_pointer = form_value.BlockData(); |
| 4049 | if (data_pointer) |
| 4050 | { |
| Jason Molenda | 18f5fd3 | 2014-10-16 07:52:17 +0000 | [diff] [blame] | 4051 | form_value.Unsigned(); |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4052 | } |
| 4053 | else if (DWARFFormValue::IsDataForm(form_value.Form())) |
| 4054 | { |
| 4055 | // we need to get the byte size of the type later after we create the variable |
| 4056 | const_value = form_value; |
| 4057 | } |
| 4058 | } |
| 4059 | else |
| 4060 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4061 | } |
| 4062 | else |
| 4063 | { |
| 4064 | // Retrieve the value as a string expression. |
| 4065 | if (form_value.Form() == DW_FORM_strp) |
| 4066 | { |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4067 | const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4068 | uint32_t data_offset = attributes.DIEOffsetAtIndex(i); |
| 4069 | uint32_t data_length = fixed_form_sizes[form_value.Form()]; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4070 | location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4071 | } |
| 4072 | else |
| 4073 | { |
| 4074 | const char *str = form_value.AsCString(&debug_info_data); |
| 4075 | uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); |
| 4076 | uint32_t string_length = strlen(str) + 1; |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4077 | location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4078 | } |
| 4079 | } |
| 4080 | } |
| 4081 | break; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4082 | case DW_AT_location: |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4083 | { |
| Andrew Kaylor | b32581f | 2013-02-13 19:57:06 +0000 | [diff] [blame] | 4084 | location_is_const_value_data = false; |
| 4085 | has_explicit_location = true; |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4086 | if (form_value.BlockData()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4087 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4088 | const DWARFDataExtractor& debug_info_data = get_debug_info_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4089 | |
| 4090 | uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); |
| 4091 | uint32_t block_length = form_value.Unsigned(); |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4092 | location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4093 | } |
| 4094 | else |
| 4095 | { |
| Ed Maste | eeae721 | 2013-10-24 20:43:47 +0000 | [diff] [blame] | 4096 | const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4097 | const dw_offset_t debug_loc_offset = form_value.Unsigned(); |
| 4098 | |
| 4099 | size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); |
| 4100 | if (loc_list_length > 0) |
| 4101 | { |
| Richard Mitton | 0a55835 | 2013-10-17 21:14:00 +0000 | [diff] [blame] | 4102 | location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4103 | assert (func_low_pc != LLDB_INVALID_ADDRESS); |
| Greg Clayton | 54166af | 2014-11-22 01:58:59 +0000 | [diff] [blame] | 4104 | location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4105 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4106 | } |
| 4107 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4108 | break; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4109 | |
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 4110 | case DW_AT_artificial: is_artificial = form_value.Boolean(); break; |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 4111 | 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] | 4112 | case DW_AT_declaration: |
| 4113 | case DW_AT_description: |
| 4114 | case DW_AT_endianity: |
| 4115 | case DW_AT_segment: |
| 4116 | case DW_AT_start_scope: |
| 4117 | case DW_AT_visibility: |
| 4118 | default: |
| 4119 | case DW_AT_abstract_origin: |
| 4120 | case DW_AT_sibling: |
| 4121 | case DW_AT_specification: |
| 4122 | break; |
| 4123 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4124 | } |
| 4125 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4126 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4127 | ValueType scope = eValueTypeInvalid; |
| 4128 | |
| 4129 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); |
| 4130 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4131 | SymbolContextScope * symbol_context_scope = NULL; |
| 4132 | |
| Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 4133 | if (!mangled) |
| 4134 | { |
| 4135 | // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to |
| 4136 | // generate fully qualified names of global variables with commands like "frame var j". |
| 4137 | // For example, if j were an int variable holding a value 4 and declared in a namespace |
| 4138 | // B which in turn is contained in a namespace A, the command "frame var j" returns |
| 4139 | // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able |
| 4140 | // to generate a fully qualified name from the declaration context. |
| 4141 | if (die->GetParent()->Tag() == DW_TAG_compile_unit && |
| 4142 | LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) |
| 4143 | { |
| 4144 | DWARFDeclContext decl_ctx; |
| 4145 | |
| 4146 | die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); |
| 4147 | mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); |
| 4148 | } |
| 4149 | } |
| 4150 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4151 | // DWARF doesn't specify if a DW_TAG_variable is a local, global |
| 4152 | // or static variable, so we have to do a little digging by |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4153 | // looking at the location of a variable to see if it contains |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4154 | // a DW_OP_addr opcode _somewhere_ in the definition. I say |
| 4155 | // somewhere because clang likes to combine small global variables |
| 4156 | // into the same symbol and have locations like: |
| 4157 | // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus |
| 4158 | // So if we don't have a DW_TAG_formal_parameter, we can look at |
| 4159 | // the location to see if it contains a DW_OP_addr opcode, and |
| 4160 | // then we can correctly classify our variables. |
| 4161 | if (tag == DW_TAG_formal_parameter) |
| 4162 | scope = eValueTypeVariableArgument; |
| 4163 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4164 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4165 | bool op_error = false; |
| 4166 | // Check if the location has a DW_OP_addr with any address value... |
| 4167 | lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; |
| 4168 | if (!location_is_const_value_data) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4169 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4170 | location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); |
| 4171 | if (op_error) |
| Greg Clayton | 96c0968 | 2012-01-04 22:56:43 +0000 | [diff] [blame] | 4172 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4173 | StreamString strm; |
| 4174 | location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); |
| 4175 | 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] | 4176 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4177 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4178 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4179 | if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) |
| 4180 | { |
| 4181 | if (is_external) |
| 4182 | scope = eValueTypeVariableGlobal; |
| 4183 | else |
| 4184 | scope = eValueTypeVariableStatic; |
| 4185 | |
| 4186 | |
| 4187 | SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); |
| 4188 | |
| 4189 | if (debug_map_symfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4190 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4191 | // When leaving the DWARF in the .o files on darwin, |
| 4192 | // when we have a global variable that wasn't initialized, |
| 4193 | // the .o file might not have allocated a virtual |
| 4194 | // address for the global variable. In this case it will |
| 4195 | // have created a symbol for the global variable |
| 4196 | // that is undefined/data and external and the value will |
| 4197 | // be the byte size of the variable. When we do the |
| 4198 | // address map in SymbolFileDWARFDebugMap we rely on |
| 4199 | // having an address, we need to do some magic here |
| 4200 | // so we can get the correct address for our global |
| 4201 | // variable. The address for all of these entries |
| 4202 | // will be zero, and there will be an undefined symbol |
| 4203 | // in this object file, and the executable will have |
| 4204 | // a matching symbol with a good address. So here we |
| 4205 | // dig up the correct address and replace it in the |
| 4206 | // location for the variable, and set the variable's |
| 4207 | // symbol context scope to be that of the main executable |
| 4208 | // so the file address will resolve correctly. |
| 4209 | bool linked_oso_file_addr = false; |
| 4210 | if (is_external && location_DW_OP_addr == 0) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4211 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4212 | // we have a possible uninitialized extern global |
| 4213 | ConstString const_name(mangled ? mangled : name); |
| 4214 | ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); |
| 4215 | if (debug_map_objfile) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4216 | { |
| Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 4217 | Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4218 | if (debug_map_symtab) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4219 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4220 | Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, |
| 4221 | eSymbolTypeData, |
| 4222 | Symtab::eDebugYes, |
| 4223 | Symtab::eVisibilityExtern); |
| 4224 | if (exe_symbol) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4225 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4226 | if (exe_symbol->ValueIsAddress()) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4227 | { |
| Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 4228 | const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress(); |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4229 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4230 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4231 | if (location.Update_DW_OP_addr (exe_file_addr)) |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4232 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4233 | linked_oso_file_addr = true; |
| 4234 | symbol_context_scope = exe_symbol; |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | } |
| 4238 | } |
| 4239 | } |
| 4240 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4241 | } |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4242 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4243 | if (!linked_oso_file_addr) |
| 4244 | { |
| 4245 | // The DW_OP_addr is not zero, but it contains a .o file address which |
| 4246 | // needs to be linked up correctly. |
| 4247 | const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); |
| 4248 | if (exe_file_addr != LLDB_INVALID_ADDRESS) |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4249 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4250 | // Update the file address for this variable |
| 4251 | location.Update_DW_OP_addr (exe_file_addr); |
| 4252 | } |
| 4253 | else |
| 4254 | { |
| 4255 | // Variable didn't make it into the final executable |
| 4256 | return var_sp; |
| Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 4257 | } |
| Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 4258 | } |
| Greg Clayton | 2fc93ea | 2011-11-13 04:15:56 +0000 | [diff] [blame] | 4259 | } |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4260 | } |
| 4261 | else |
| 4262 | { |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4263 | scope = eValueTypeVariableLocal; |
| Greg Clayton | 5cf58b9 | 2011-10-05 22:22:08 +0000 | [diff] [blame] | 4264 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4265 | } |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4266 | |
| 4267 | if (symbol_context_scope == NULL) |
| 4268 | { |
| 4269 | switch (parent_tag) |
| 4270 | { |
| 4271 | case DW_TAG_subprogram: |
| 4272 | case DW_TAG_inlined_subroutine: |
| 4273 | case DW_TAG_lexical_block: |
| 4274 | if (sc.function) |
| 4275 | { |
| 4276 | symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| 4277 | if (symbol_context_scope == NULL) |
| 4278 | symbol_context_scope = sc.function; |
| 4279 | } |
| 4280 | break; |
| 4281 | |
| 4282 | default: |
| 4283 | symbol_context_scope = sc.comp_unit; |
| 4284 | break; |
| 4285 | } |
| 4286 | } |
| 4287 | |
| 4288 | if (symbol_context_scope) |
| 4289 | { |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4290 | SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); |
| 4291 | |
| 4292 | if (const_value.Form() && type_sp && type_sp->GetType()) |
| 4293 | location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); |
| 4294 | |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4295 | var_sp.reset (new Variable (MakeUserID(die->GetOffset()), |
| 4296 | name, |
| 4297 | mangled, |
| Enrico Granata | 4ec130d | 2014-08-11 19:16:35 +0000 | [diff] [blame] | 4298 | type_sp, |
| Greg Clayton | 9e9f219 | 2013-05-17 00:55:28 +0000 | [diff] [blame] | 4299 | scope, |
| 4300 | symbol_context_scope, |
| 4301 | &decl, |
| 4302 | location, |
| 4303 | is_external, |
| 4304 | is_artificial)); |
| 4305 | |
| 4306 | var_sp->SetLocationIsConstantValueData (location_is_const_value_data); |
| 4307 | } |
| 4308 | else |
| 4309 | { |
| 4310 | // Not ready to parse this variable yet. It might be a global |
| 4311 | // or static variable that is in a function scope and the function |
| 4312 | // in the symbol context wasn't filled in yet |
| 4313 | return var_sp; |
| 4314 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4315 | } |
| Greg Clayton | 7f99513 | 2011-10-04 22:41:51 +0000 | [diff] [blame] | 4316 | // Cache var_sp even if NULL (the variable was just a specification or |
| 4317 | // was missing vital information to be able to be displayed in the debugger |
| 4318 | // (missing location due to optimization, etc)) so we don't re-parse |
| 4319 | // this DIE over and over later... |
| 4320 | m_die_to_variable_sp[die] = var_sp; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4321 | } |
| 4322 | return var_sp; |
| 4323 | } |
| 4324 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4325 | |
| 4326 | const DWARFDebugInfoEntry * |
| 4327 | SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, |
| 4328 | dw_offset_t spec_block_die_offset, |
| 4329 | DWARFCompileUnit **result_die_cu_handle) |
| 4330 | { |
| 4331 | // Give the concrete function die specified by "func_die_offset", find the |
| 4332 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4333 | // to "spec_block_die_offset" |
| 4334 | DWARFDebugInfo* info = DebugInfo(); |
| 4335 | |
| 4336 | const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); |
| 4337 | if (die) |
| 4338 | { |
| 4339 | assert (*result_die_cu_handle); |
| 4340 | return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); |
| 4341 | } |
| 4342 | return NULL; |
| 4343 | } |
| 4344 | |
| 4345 | |
| 4346 | const DWARFDebugInfoEntry * |
| 4347 | SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, |
| 4348 | const DWARFDebugInfoEntry *die, |
| 4349 | dw_offset_t spec_block_die_offset, |
| 4350 | DWARFCompileUnit **result_die_cu_handle) |
| 4351 | { |
| 4352 | if (die) |
| 4353 | { |
| 4354 | switch (die->Tag()) |
| 4355 | { |
| 4356 | case DW_TAG_subprogram: |
| 4357 | case DW_TAG_inlined_subroutine: |
| 4358 | case DW_TAG_lexical_block: |
| 4359 | { |
| 4360 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4361 | { |
| 4362 | *result_die_cu_handle = dwarf_cu; |
| 4363 | return die; |
| 4364 | } |
| 4365 | |
| 4366 | if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) |
| 4367 | { |
| 4368 | *result_die_cu_handle = dwarf_cu; |
| 4369 | return die; |
| 4370 | } |
| 4371 | } |
| 4372 | break; |
| 4373 | } |
| 4374 | |
| 4375 | // Give the concrete function die specified by "func_die_offset", find the |
| 4376 | // concrete block whose DW_AT_specification or DW_AT_abstract_origin points |
| 4377 | // to "spec_block_die_offset" |
| 4378 | for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) |
| 4379 | { |
| 4380 | const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, |
| 4381 | child_die, |
| 4382 | spec_block_die_offset, |
| 4383 | result_die_cu_handle); |
| 4384 | if (result_die) |
| 4385 | return result_die; |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | *result_die_cu_handle = NULL; |
| 4390 | return NULL; |
| 4391 | } |
| 4392 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4393 | size_t |
| 4394 | SymbolFileDWARF::ParseVariables |
| 4395 | ( |
| 4396 | const SymbolContext& sc, |
| Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 4397 | DWARFCompileUnit* dwarf_cu, |
| Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 4398 | const lldb::addr_t func_low_pc, |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4399 | const DWARFDebugInfoEntry *orig_die, |
| 4400 | bool parse_siblings, |
| 4401 | bool parse_children, |
| 4402 | VariableList* cc_variable_list |
| 4403 | ) |
| 4404 | { |
| 4405 | if (orig_die == NULL) |
| 4406 | return 0; |
| 4407 | |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4408 | VariableListSP variable_list_sp; |
| 4409 | |
| 4410 | size_t vars_added = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4411 | const DWARFDebugInfoEntry *die = orig_die; |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4412 | while (die != NULL) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4413 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4414 | dw_tag_t tag = die->Tag(); |
| 4415 | |
| 4416 | // Check to see if we have already parsed this variable or constant? |
| 4417 | if (m_die_to_variable_sp[die]) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4418 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4419 | if (cc_variable_list) |
| 4420 | cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4421 | } |
| 4422 | else |
| 4423 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4424 | // We haven't already parsed it, lets do that now. |
| 4425 | if ((tag == DW_TAG_variable) || |
| 4426 | (tag == DW_TAG_constant) || |
| 4427 | (tag == DW_TAG_formal_parameter && sc.function)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4428 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4429 | if (variable_list_sp.get() == NULL) |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4430 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4431 | const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); |
| 4432 | dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; |
| 4433 | switch (parent_tag) |
| 4434 | { |
| 4435 | case DW_TAG_compile_unit: |
| 4436 | if (sc.comp_unit != NULL) |
| 4437 | { |
| 4438 | variable_list_sp = sc.comp_unit->GetVariableList(false); |
| 4439 | if (variable_list_sp.get() == NULL) |
| 4440 | { |
| 4441 | variable_list_sp.reset(new VariableList()); |
| 4442 | sc.comp_unit->SetVariableList(variable_list_sp); |
| 4443 | } |
| 4444 | } |
| 4445 | else |
| 4446 | { |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4447 | 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] | 4448 | MakeUserID(sc_parent_die->GetOffset()), |
| 4449 | DW_TAG_value_to_name (parent_tag), |
| 4450 | MakeUserID(orig_die->GetOffset()), |
| 4451 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4452 | } |
| 4453 | break; |
| 4454 | |
| 4455 | case DW_TAG_subprogram: |
| 4456 | case DW_TAG_inlined_subroutine: |
| 4457 | case DW_TAG_lexical_block: |
| 4458 | if (sc.function != NULL) |
| 4459 | { |
| 4460 | // Check to see if we already have parsed the variables for the given scope |
| 4461 | |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4462 | Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4463 | if (block == NULL) |
| 4464 | { |
| 4465 | // This must be a specification or abstract origin with |
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4466 | // a concrete block counterpart in the current function. We need |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4467 | // to find the concrete block so we can correctly add the |
| 4468 | // variable to it |
| 4469 | DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; |
| 4470 | const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), |
| 4471 | sc_parent_die->GetOffset(), |
| 4472 | &concrete_block_die_cu); |
| 4473 | if (concrete_block_die) |
| Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4474 | block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | if (block != NULL) |
| 4478 | { |
| 4479 | const bool can_create = false; |
| 4480 | variable_list_sp = block->GetBlockVariableList (can_create); |
| 4481 | if (variable_list_sp.get() == NULL) |
| 4482 | { |
| 4483 | variable_list_sp.reset(new VariableList()); |
| 4484 | block->SetVariableList(variable_list_sp); |
| 4485 | } |
| 4486 | } |
| 4487 | } |
| 4488 | break; |
| 4489 | |
| 4490 | default: |
| Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4491 | 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] | 4492 | MakeUserID(orig_die->GetOffset()), |
| 4493 | DW_TAG_value_to_name (orig_die->Tag())); |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4494 | break; |
| 4495 | } |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4496 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4497 | |
| 4498 | if (variable_list_sp) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4499 | { |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4500 | VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); |
| 4501 | if (var_sp) |
| 4502 | { |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4503 | variable_list_sp->AddVariableIfUnique (var_sp); |
| Greg Clayton | 73bf5db | 2011-06-17 01:22:15 +0000 | [diff] [blame] | 4504 | if (cc_variable_list) |
| 4505 | cc_variable_list->AddVariableIfUnique (var_sp); |
| 4506 | ++vars_added; |
| 4507 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4508 | } |
| 4509 | } |
| 4510 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4511 | |
| 4512 | bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); |
| 4513 | |
| 4514 | if (!skip_children && parse_children && die->HasChildren()) |
| 4515 | { |
| 4516 | vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); |
| 4517 | } |
| 4518 | |
| 4519 | if (parse_siblings) |
| 4520 | die = die->GetSibling(); |
| 4521 | else |
| 4522 | die = NULL; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4523 | } |
| Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 4524 | return vars_added; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | //------------------------------------------------------------------ |
| 4528 | // PluginInterface protocol |
| 4529 | //------------------------------------------------------------------ |
| Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 4530 | ConstString |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4531 | SymbolFileDWARF::GetPluginName() |
| 4532 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4533 | return GetPluginNameStatic(); |
| 4534 | } |
| 4535 | |
| 4536 | uint32_t |
| 4537 | SymbolFileDWARF::GetPluginVersion() |
| 4538 | { |
| 4539 | return 1; |
| 4540 | } |
| 4541 | |
| 4542 | void |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4543 | SymbolFileDWARF::DumpIndexes () |
| 4544 | { |
| 4545 | StreamFile s(stdout, false); |
| 4546 | |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4547 | s.Printf ("DWARF index for (%s) '%s':", |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4548 | GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), |
| Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 4549 | GetObjectFile()->GetFileSpec().GetPath().c_str()); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4550 | s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); |
| 4551 | s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); |
| 4552 | s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); |
| 4553 | s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); |
| 4554 | s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); |
| 4555 | s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); |
| 4556 | s.Printf("\nTypes:\n"); m_type_index.Dump (&s); |
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 4557 | s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s); |
| Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4558 | } |
| 4559 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 4560 | |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 4561 | SymbolFileDWARFDebugMap * |
| 4562 | SymbolFileDWARF::GetDebugMapSymfile () |
| 4563 | { |
| 4564 | if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) |
| 4565 | { |
| 4566 | lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); |
| 4567 | if (module_sp) |
| 4568 | { |
| 4569 | SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); |
| 4570 | if (sym_vendor) |
| 4571 | m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); |
| 4572 | } |
| 4573 | } |
| 4574 | return m_debug_map_symfile; |
| 4575 | } |
| 4576 | |
| Greg Clayton | caab74e | 2012-01-28 00:48:57 +0000 | [diff] [blame] | 4577 | |