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