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