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