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