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