Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolFileDWARFDebugMap.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 "SymbolFileDWARFDebugMap.h" |
| 11 | |
| 12 | #include "lldb/Core/Module.h" |
| 13 | #include "lldb/Core/ModuleList.h" |
| 14 | #include "lldb/Core/PluginManager.h" |
| 15 | #include "lldb/Core/RegularExpression.h" |
| 16 | #include "lldb/Core/StreamFile.h" |
| 17 | #include "lldb/Core/Timer.h" |
| 18 | #include "lldb/Symbol/ObjectFile.h" |
| 19 | #include "lldb/Symbol/SymbolVendor.h" |
| 20 | #include "lldb/Symbol/VariableList.h" |
| 21 | |
| 22 | #include "SymbolFileDWARF.h" |
| 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
| 27 | void |
| 28 | SymbolFileDWARFDebugMap::Initialize() |
| 29 | { |
| 30 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 31 | GetPluginDescriptionStatic(), |
| 32 | CreateInstance); |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | SymbolFileDWARFDebugMap::Terminate() |
| 37 | { |
| 38 | PluginManager::UnregisterPlugin (CreateInstance); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | const char * |
| 43 | SymbolFileDWARFDebugMap::GetPluginNameStatic() |
| 44 | { |
| 45 | return "symbol-file.dwarf2-debugmap"; |
| 46 | } |
| 47 | |
| 48 | const char * |
| 49 | SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() |
| 50 | { |
| 51 | return "DWARF and DWARF3 debug symbol file reader (debug map)."; |
| 52 | } |
| 53 | |
| 54 | SymbolFile* |
| 55 | SymbolFileDWARFDebugMap::CreateInstance (ObjectFile* obj_file) |
| 56 | { |
| 57 | return new SymbolFileDWARFDebugMap (obj_file); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap (ObjectFile* ofile) : |
| 62 | SymbolFile(ofile), |
| 63 | m_flags(), |
| 64 | m_compile_unit_infos(), |
| 65 | m_func_indexes(), |
| 66 | m_glob_indexes() |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | |
| 71 | SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | SymbolFileDWARFDebugMap::InitOSO () |
| 77 | { |
| 78 | if (m_flags.test(kHaveInitializedOSOs)) |
| 79 | return; |
| 80 | |
| 81 | m_flags.set(kHaveInitializedOSOs); |
| 82 | // In order to get the abilities of this plug-in, we look at the list of |
| 83 | // N_OSO entries (object files) from the symbol table and make sure that |
| 84 | // these files exist and also contain valid DWARF. If we get any of that |
| 85 | // then we return the abilities of the first N_OSO's DWARF. |
| 86 | |
| 87 | Symtab* symtab = m_obj_file->GetSymtab(); |
| 88 | if (symtab) |
| 89 | { |
| 90 | //StreamFile s(0, 4, eByteOrderHost, stdout); |
| 91 | std::vector<uint32_t> oso_indexes; |
| 92 | const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithType(eSymbolTypeObjectFile, oso_indexes); |
| 93 | |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 94 | symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes); |
| 95 | symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | |
| 97 | symtab->SortSymbolIndexesByValue(m_func_indexes, true); |
| 98 | symtab->SortSymbolIndexesByValue(m_glob_indexes, true); |
| 99 | |
| 100 | if (oso_index_count > 0) |
| 101 | { |
| 102 | m_compile_unit_infos.resize(oso_index_count); |
| 103 | // s.Printf("%s N_OSO symbols:\n", __PRETTY_FUNCTION__); |
| 104 | // symtab->Dump(&s, oso_indexes); |
| 105 | |
| 106 | for (uint32_t i=0; i<oso_index_count; ++i) |
| 107 | { |
| 108 | m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 1); |
| 109 | if (m_compile_unit_infos[i].so_symbol->GetSiblingIndex() == 0) |
| 110 | m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 2); |
| 111 | m_compile_unit_infos[i].oso_symbol = symtab->SymbolAtIndex(oso_indexes[i]); |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 112 | uint32_t sibling_idx = m_compile_unit_infos[i].so_symbol->GetSiblingIndex(); |
| 113 | assert (sibling_idx != 0); |
| 114 | assert (sibling_idx > i + 1); |
| 115 | m_compile_unit_infos[i].last_symbol = symtab->SymbolAtIndex (sibling_idx - 1); |
| 116 | m_compile_unit_infos[i].first_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].so_symbol); |
| 117 | m_compile_unit_infos[i].last_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].last_symbol); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | Module * |
| 124 | SymbolFileDWARFDebugMap::GetModuleByOSOIndex (uint32_t oso_idx) |
| 125 | { |
| 126 | const uint32_t cu_count = GetNumCompileUnits(); |
| 127 | if (oso_idx < cu_count) |
| 128 | return GetModuleByCompUnitInfo (&m_compile_unit_infos[oso_idx]); |
| 129 | return NULL; |
| 130 | } |
| 131 | |
| 132 | Module * |
| 133 | SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info) |
| 134 | { |
| 135 | if (comp_unit_info->oso_module_sp.get() == NULL) |
| 136 | { |
| 137 | Symbol *oso_symbol = comp_unit_info->oso_symbol; |
| 138 | if (oso_symbol) |
| 139 | { |
| 140 | FileSpec oso_file_spec(oso_symbol->GetMangled().GetName().AsCString()); |
| 141 | |
| 142 | ModuleList::GetSharedModule (oso_file_spec, |
| 143 | m_obj_file->GetModule()->GetArchitecture(), |
| 144 | NULL, // UUID pointer |
| 145 | NULL, // object name |
| 146 | 0, // object offset |
| 147 | comp_unit_info->oso_module_sp, |
| 148 | NULL, |
| 149 | NULL); |
| 150 | //comp_unit_info->oso_module_sp.reset(new Module (oso_file_spec, m_obj_file->GetModule()->GetArchitecture())); |
| 151 | } |
| 152 | } |
| 153 | return comp_unit_info->oso_module_sp.get(); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | bool |
| 158 | SymbolFileDWARFDebugMap::GetFileSpecForSO (uint32_t oso_idx, FileSpec &file_spec) |
| 159 | { |
| 160 | if (oso_idx < m_compile_unit_infos.size()) |
| 161 | { |
| 162 | if (!m_compile_unit_infos[oso_idx].so_file) |
| 163 | { |
| 164 | |
| 165 | if (m_compile_unit_infos[oso_idx].so_symbol == NULL) |
| 166 | return false; |
| 167 | |
| 168 | std::string so_path (m_compile_unit_infos[oso_idx].so_symbol->GetMangled().GetName().AsCString()); |
| 169 | if (m_compile_unit_infos[oso_idx].so_symbol[1].GetType() == eSymbolTypeSourceFile) |
| 170 | so_path += m_compile_unit_infos[oso_idx].so_symbol[1].GetMangled().GetName().AsCString(); |
| 171 | m_compile_unit_infos[oso_idx].so_file.SetFile(so_path.c_str()); |
| 172 | } |
| 173 | file_spec = m_compile_unit_infos[oso_idx].so_file; |
| 174 | return true; |
| 175 | } |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | ObjectFile * |
| 182 | SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex (uint32_t oso_idx) |
| 183 | { |
| 184 | Module *oso_module = GetModuleByOSOIndex (oso_idx); |
| 185 | if (oso_module) |
| 186 | return oso_module->GetObjectFile(); |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | SymbolFileDWARF * |
| 191 | SymbolFileDWARFDebugMap::GetSymbolFile (const SymbolContext& sc) |
| 192 | { |
| 193 | CompileUnitInfo *comp_unit_info = GetCompUnitInfo (sc); |
| 194 | if (comp_unit_info) |
| 195 | return GetSymbolFileByCompUnitInfo (comp_unit_info); |
| 196 | return NULL; |
| 197 | } |
| 198 | |
| 199 | ObjectFile * |
| 200 | SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info) |
| 201 | { |
| 202 | Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info); |
| 203 | if (oso_module) |
| 204 | return oso_module->GetObjectFile(); |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | SymbolFileDWARF * |
| 209 | SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex (uint32_t oso_idx) |
| 210 | { |
| 211 | if (oso_idx < m_compile_unit_infos.size()) |
| 212 | return GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[oso_idx]); |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | SymbolFileDWARF * |
| 217 | SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info) |
| 218 | { |
| 219 | if (comp_unit_info->oso_symbol_vendor == NULL) |
| 220 | { |
| 221 | ObjectFile *oso_objfile = GetObjectFileByCompUnitInfo (comp_unit_info); |
| 222 | |
| 223 | if (oso_objfile) |
| 224 | { |
| 225 | comp_unit_info->oso_symbol_vendor = oso_objfile->GetModule()->GetSymbolVendor(); |
| 226 | // SymbolFileDWARF *oso_dwarf = new SymbolFileDWARF(oso_objfile); |
| 227 | // comp_unit_info->oso_dwarf_sp.reset (oso_dwarf); |
| 228 | if (comp_unit_info->oso_symbol_vendor) |
| 229 | { |
| 230 | // Set a bit that lets this DWARF file know that it is being |
| 231 | // used along with a debug map and that it will have the |
| 232 | // remapped sections that we do below. |
| 233 | ((SymbolFileDWARF *)comp_unit_info->oso_symbol_vendor->GetSymbolFile())->GetFlags().Set(SymbolFileDWARF::flagsDWARFIsOSOForDebugMap); |
| 234 | comp_unit_info->debug_map_sections_sp.reset(new SectionList); |
| 235 | |
| 236 | Symtab *exe_symtab = m_obj_file->GetSymtab(); |
| 237 | Module *oso_module = oso_objfile->GetModule(); |
| 238 | Symtab *oso_symtab = oso_objfile->GetSymtab(); |
| 239 | //#define DEBUG_OSO_DMAP // Do not check in with this defined... |
| 240 | #if defined(DEBUG_OSO_DMAP) |
| 241 | StreamFile s(stdout); |
| 242 | s << "OSO symtab:\n"; |
| 243 | oso_symtab->Dump(&s, NULL); |
| 244 | s << "OSO sections before:\n"; |
| 245 | oso_objfile->GetSectionList()->Dump(&s, NULL, true); |
| 246 | #endif |
| 247 | |
| 248 | ///const uint32_t fun_resolve_flags = SymbolContext::Module | eSymbolContextCompUnit | eSymbolContextFunction; |
| 249 | //SectionList *oso_sections = oso_objfile->Sections(); |
| 250 | // Now we need to make sections that map from zero based object |
| 251 | // file addresses to where things eneded up in the main executable. |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 252 | uint32_t oso_start_idx = exe_symtab->GetIndexForSymbol (comp_unit_info->oso_symbol); |
| 253 | assert (oso_start_idx != UINT32_MAX); |
| 254 | oso_start_idx += 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 255 | const uint32_t oso_end_idx = comp_unit_info->so_symbol->GetSiblingIndex(); |
| 256 | uint32_t sect_id = 0x10000; |
| 257 | for (uint32_t idx = oso_start_idx; idx < oso_end_idx; ++idx) |
| 258 | { |
| 259 | Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx); |
| 260 | if (exe_symbol) |
| 261 | { |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 262 | if (exe_symbol->IsDebug() == false) |
| 263 | continue; |
| 264 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | switch (exe_symbol->GetType()) |
| 266 | { |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 267 | case eSymbolTypeCode: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | { |
| 269 | // For each N_FUN, or function that we run into in the debug map |
| 270 | // we make a new section that we add to the sections found in the |
| 271 | // .o file. This new section has the file address set to what the |
| 272 | // addresses are in the .o file, and the load address is adjusted |
| 273 | // to match where it ended up in the final executable! We do this |
| 274 | // before we parse any dwarf info so that when it goes get parsed |
| 275 | // all section/offset addresses that get registered will resolve |
| 276 | // correctly to the new addresses in the main executable. |
| 277 | |
| 278 | // First we find the original symbol in the .o file's symbol table |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 279 | Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | if (oso_fun_symbol) |
| 281 | { |
| 282 | // If we found the symbol, then we |
| 283 | Section* exe_fun_section = const_cast<Section *>(exe_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 284 | Section* oso_fun_section = const_cast<Section *>(oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 285 | if (oso_fun_section) |
| 286 | { |
| 287 | // Now we create a section that we will add as a child of the |
| 288 | // section in which the .o symbol (the N_FUN) exists. |
| 289 | |
| 290 | // We use the exe_symbol size because the one in the .o file |
| 291 | // will just be a symbol with no size, and the exe_symbol |
| 292 | // size will reflect any size changes (ppc has been known to |
| 293 | // shrink function sizes when it gets rid of jump islands that |
| 294 | // aren't needed anymore). |
| 295 | SectionSP oso_fun_section_sp (new Section (const_cast<Section *>(oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()), |
| 296 | oso_module, // Module (the .o file) |
| 297 | sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs |
| 298 | exe_symbol->GetMangled().GetName(), // Name the section the same as the symbol for which is was generated! |
| 299 | eSectionTypeDebug, |
| 300 | oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), // File VM address offset in the current section |
| 301 | exe_symbol->GetByteSize(), // File size (we need the size from the executable) |
| 302 | 0, 0, 0)); |
| 303 | |
| 304 | oso_fun_section_sp->SetLinkedLocation (exe_fun_section, |
| 305 | exe_symbol->GetValue().GetFileAddress() - exe_fun_section->GetFileAddress()); |
| 306 | oso_fun_section->GetChildren().AddSection(oso_fun_section_sp); |
| 307 | comp_unit_info->debug_map_sections_sp->AddSection(oso_fun_section_sp); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | break; |
| 312 | |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 313 | case eSymbolTypeData: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 314 | { |
| 315 | // For each N_GSYM we remap the address for the global by making |
| 316 | // a new section that we add to the sections found in the .o file. |
| 317 | // This new section has the file address set to what the |
| 318 | // addresses are in the .o file, and the load address is adjusted |
| 319 | // to match where it ended up in the final executable! We do this |
| 320 | // before we parse any dwarf info so that when it goes get parsed |
| 321 | // all section/offset addresses that get registered will resolve |
| 322 | // correctly to the new addresses in the main executable. We |
| 323 | // initially set the section size to be 1 byte, but will need to |
| 324 | // fix up these addresses further after all globals have been |
| 325 | // parsed to span the gaps, or we can find the global variable |
| 326 | // sizes from the DWARF info as we are parsing. |
| 327 | |
| 328 | #if 0 |
| 329 | // First we find the non-stab entry that corresponds to the N_GSYM in the executable |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 330 | Symbol *exe_gsym_symbol = exe_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 331 | #else |
| 332 | // The mach-o object file parser already matches up the N_GSYM with with the non-stab |
| 333 | // entry, so we shouldn't have to do that. If this ever changes, enable the code above |
| 334 | // in the "#if 0" block. STSYM's always match the symbol as found below. |
| 335 | Symbol *exe_gsym_symbol = exe_symbol; |
| 336 | #endif |
| 337 | // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 338 | Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | if (exe_gsym_symbol && oso_gsym_symbol) |
| 340 | { |
| 341 | // If we found the symbol, then we |
| 342 | Section* exe_gsym_section = const_cast<Section *>(exe_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 343 | Section* oso_gsym_section = const_cast<Section *>(oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 344 | if (oso_gsym_section) |
| 345 | { |
| 346 | SectionSP oso_gsym_section_sp (new Section (const_cast<Section *>(oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()), |
| 347 | oso_module, // Module (the .o file) |
| 348 | sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs |
| 349 | exe_symbol->GetMangled().GetName(), // Name the section the same as the symbol for which is was generated! |
| 350 | eSectionTypeDebug, |
| 351 | oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), // File VM address offset in the current section |
| 352 | 1, // We don't know the size of the global, just do the main address for now. |
| 353 | 0, 0, 0)); |
| 354 | |
| 355 | oso_gsym_section_sp->SetLinkedLocation (exe_gsym_section, |
| 356 | exe_gsym_symbol->GetValue().GetFileAddress() - exe_gsym_section->GetFileAddress()); |
| 357 | oso_gsym_section->GetChildren().AddSection(oso_gsym_section_sp); |
| 358 | comp_unit_info->debug_map_sections_sp->AddSection(oso_gsym_section_sp); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | break; |
| 363 | |
| 364 | // case eSymbolTypeStatic: |
| 365 | // { |
| 366 | // // For each N_STSYM we remap the address for the global by making |
| 367 | // // a new section that we add to the sections found in the .o file. |
| 368 | // // This new section has the file address set to what the |
| 369 | // // addresses are in the .o file, and the load address is adjusted |
| 370 | // // to match where it ended up in the final executable! We do this |
| 371 | // // before we parse any dwarf info so that when it goes get parsed |
| 372 | // // all section/offset addresses that get registered will resolve |
| 373 | // // correctly to the new addresses in the main executable. We |
| 374 | // // initially set the section size to be 1 byte, but will need to |
| 375 | // // fix up these addresses further after all globals have been |
| 376 | // // parsed to span the gaps, or we can find the global variable |
| 377 | // // sizes from the DWARF info as we are parsing. |
| 378 | // |
| 379 | // |
| 380 | // Symbol *exe_stsym_symbol = exe_symbol; |
| 381 | // // First we find the non-stab entry that corresponds to the N_STSYM in the .o file |
| 382 | // Symbol *oso_stsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeData); |
| 383 | // if (exe_stsym_symbol && oso_stsym_symbol) |
| 384 | // { |
| 385 | // // If we found the symbol, then we |
| 386 | // Section* exe_stsym_section = const_cast<Section *>(exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 387 | // Section* oso_stsym_section = const_cast<Section *>(oso_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()); |
| 388 | // if (oso_stsym_section) |
| 389 | // { |
| 390 | // // The load address of the symbol will use the section in the |
| 391 | // // executable that contains the debug map that corresponds to |
| 392 | // // the N_FUN symbol. We set the offset to reflect the offset |
| 393 | // // into that section since we are creating a new section. |
| 394 | // AddressRange stsym_load_range(exe_stsym_section, exe_stsym_symbol->GetValue().GetFileAddress() - exe_stsym_section->GetFileAddress(), 1); |
| 395 | // // We need the symbol's section offset address from the .o file, but |
| 396 | // // we need a non-zero size. |
| 397 | // AddressRange stsym_file_range(exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection(), exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), 1); |
| 398 | // |
| 399 | // // Now we create a section that we will add as a child of the |
| 400 | // // section in which the .o symbol (the N_FUN) exists. |
| 401 | // |
| 402 | //// TODO: mimic what I did for N_FUN if that works... |
| 403 | //// // We use the 1 byte for the size because we don't know the |
| 404 | //// // size of the global symbol without seeing the DWARF. |
| 405 | //// SectionSP oso_fun_section_sp (new Section ( NULL, oso_module, // Module (the .o file) |
| 406 | //// sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs |
| 407 | //// exe_symbol->GetMangled().GetName(),// Name the section the same as the symbol for which is was generated! |
| 408 | //// // &stsym_load_range, // Load offset is the offset into the executable section for the N_FUN from the debug map |
| 409 | //// &stsym_file_range, // File section/offset is just the same os the symbol on the .o file |
| 410 | //// 0, 0, 0)); |
| 411 | //// |
| 412 | //// // Now we add the new section to the .o file's sections as a child |
| 413 | //// // of the section in which the N_SECT symbol exists. |
| 414 | //// oso_stsym_section->GetChildren().AddSection(oso_fun_section_sp); |
| 415 | //// comp_unit_info->debug_map_sections_sp->AddSection(oso_fun_section_sp); |
| 416 | // } |
| 417 | // } |
| 418 | // } |
| 419 | // break; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | #if defined(DEBUG_OSO_DMAP) |
| 424 | s << "OSO sections after:\n"; |
| 425 | oso_objfile->GetSectionList()->Dump(&s, NULL, true); |
| 426 | #endif |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | if (comp_unit_info->oso_symbol_vendor) |
| 431 | return (SymbolFileDWARF *)comp_unit_info->oso_symbol_vendor->GetSymbolFile(); |
| 432 | return NULL; |
| 433 | } |
| 434 | |
| 435 | uint32_t |
| 436 | SymbolFileDWARFDebugMap::GetAbilities () |
| 437 | { |
| 438 | // In order to get the abilities of this plug-in, we look at the list of |
| 439 | // N_OSO entries (object files) from the symbol table and make sure that |
| 440 | // these files exist and also contain valid DWARF. If we get any of that |
| 441 | // then we return the abilities of the first N_OSO's DWARF. |
| 442 | |
| 443 | const uint32_t oso_index_count = GetNumCompileUnits(); |
| 444 | if (oso_index_count > 0) |
| 445 | { |
| 446 | const uint32_t dwarf_abilities = SymbolFile::CompileUnits | |
| 447 | SymbolFile::Functions | |
| 448 | SymbolFile::Blocks | |
| 449 | SymbolFile::GlobalVariables | |
| 450 | SymbolFile::LocalVariables | |
| 451 | SymbolFile::VariableTypes | |
| 452 | SymbolFile::LineTables; |
| 453 | |
| 454 | for (uint32_t oso_idx=0; oso_idx<oso_index_count; ++oso_idx) |
| 455 | { |
| 456 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); |
| 457 | if (oso_dwarf) |
| 458 | { |
| 459 | uint32_t oso_abilities = oso_dwarf->GetAbilities(); |
| 460 | if ((oso_abilities & dwarf_abilities) == dwarf_abilities) |
| 461 | return oso_abilities; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | uint32_t |
| 469 | SymbolFileDWARFDebugMap::GetNumCompileUnits() |
| 470 | { |
| 471 | InitOSO (); |
| 472 | return m_compile_unit_infos.size(); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | CompUnitSP |
| 477 | SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx) |
| 478 | { |
| 479 | CompUnitSP comp_unit_sp; |
| 480 | const uint32_t cu_count = GetNumCompileUnits(); |
| 481 | |
| 482 | if (cu_idx < cu_count) |
| 483 | { |
| 484 | if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL) |
| 485 | { |
| 486 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (cu_idx); |
| 487 | if (oso_dwarf) |
| 488 | { |
| 489 | // There is only one compile unit for N_OSO entry right now, so |
| 490 | // it will always exist at index zero. |
| 491 | m_compile_unit_infos[cu_idx].oso_compile_unit_sp = m_compile_unit_infos[cu_idx].oso_symbol_vendor->GetCompileUnitAtIndex (0); |
| 492 | } |
| 493 | |
| 494 | if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL) |
| 495 | { |
| 496 | // We weren't able to get the DWARF for this N_OSO entry (the |
| 497 | // .o file may be missing or not at the specified path), make |
| 498 | // one up as best we can from the debug map. We set the uid |
| 499 | // of the compile unit to the symbol index with the MSBit set |
| 500 | // so that it doesn't collide with any uid values from the DWARF |
| 501 | Symbol *so_symbol = m_compile_unit_infos[cu_idx].so_symbol; |
| 502 | if (so_symbol) |
| 503 | { |
| 504 | m_compile_unit_infos[cu_idx].oso_compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(), |
| 505 | NULL, |
| 506 | so_symbol->GetMangled().GetName().AsCString(), |
| 507 | cu_idx, |
Greg Clayton | 9488b74 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 508 | eLanguageTypeUnknown)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } |
| 512 | comp_unit_sp = m_compile_unit_infos[cu_idx].oso_compile_unit_sp; |
| 513 | } |
| 514 | |
| 515 | return comp_unit_sp; |
| 516 | } |
| 517 | |
| 518 | SymbolFileDWARFDebugMap::CompileUnitInfo * |
| 519 | SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc) |
| 520 | { |
| 521 | const uint32_t cu_count = GetNumCompileUnits(); |
| 522 | for (uint32_t i=0; i<cu_count; ++i) |
| 523 | { |
| 524 | if (sc.comp_unit == m_compile_unit_infos[i].oso_compile_unit_sp.get()) |
| 525 | return &m_compile_unit_infos[i]; |
| 526 | } |
| 527 | return NULL; |
| 528 | } |
| 529 | |
| 530 | size_t |
| 531 | SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc) |
| 532 | { |
| 533 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 534 | if (oso_dwarf) |
| 535 | return oso_dwarf->ParseCompileUnitFunctions (sc); |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | bool |
| 540 | SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc) |
| 541 | { |
| 542 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 543 | if (oso_dwarf) |
| 544 | return oso_dwarf->ParseCompileUnitLineTable (sc); |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | bool |
| 549 | SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files) |
| 550 | { |
| 551 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 552 | if (oso_dwarf) |
| 553 | return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files); |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | size_t |
| 559 | SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc) |
| 560 | { |
| 561 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 562 | if (oso_dwarf) |
| 563 | return oso_dwarf->ParseFunctionBlocks (sc); |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | |
| 568 | size_t |
| 569 | SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc) |
| 570 | { |
| 571 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 572 | if (oso_dwarf) |
| 573 | return oso_dwarf->ParseTypes (sc); |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | |
| 578 | size_t |
| 579 | SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc) |
| 580 | { |
| 581 | SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 582 | if (oso_dwarf) |
| 583 | return oso_dwarf->ParseTypes (sc); |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | |
| 589 | Type* |
| 590 | SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid) |
| 591 | { |
| 592 | return NULL; |
| 593 | } |
| 594 | |
| 595 | |
| 596 | uint32_t |
| 597 | SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc) |
| 598 | { |
| 599 | uint32_t resolved_flags = 0; |
| 600 | Symtab* symtab = m_obj_file->GetSymtab(); |
| 601 | if (symtab) |
| 602 | { |
| 603 | const addr_t exe_file_addr = exe_so_addr.GetFileAddress(); |
| 604 | sc.symbol = symtab->FindSymbolContainingFileAddress (exe_file_addr, &m_func_indexes[0], m_func_indexes.size()); |
| 605 | |
| 606 | if (sc.symbol != NULL) |
| 607 | { |
| 608 | resolved_flags |= eSymbolContextSymbol; |
| 609 | |
| 610 | uint32_t oso_idx = 0; |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 611 | CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | if (comp_unit_info) |
| 613 | { |
| 614 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); |
| 615 | ObjectFile *oso_objfile = GetObjectFileByOSOIndex (oso_idx); |
| 616 | if (oso_dwarf && oso_objfile) |
| 617 | { |
| 618 | SectionList *oso_section_list = oso_objfile->GetSectionList(); |
| 619 | |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 620 | SectionSP oso_symbol_section_sp (oso_section_list->FindSectionContainingLinkedFileAddress (exe_file_addr, UINT32_MAX)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 622 | if (oso_symbol_section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | { |
Greg Clayton | 178710c | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 624 | const addr_t linked_file_addr = oso_symbol_section_sp->GetLinkedFileAddress(); |
| 625 | Address oso_so_addr (oso_symbol_section_sp.get(), exe_file_addr - linked_file_addr); |
| 626 | if (oso_so_addr.IsSectionOffset()) |
| 627 | resolved_flags |= oso_dwarf->ResolveSymbolContext (oso_so_addr, resolve_scope, sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 628 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | return resolved_flags; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | uint32_t |
| 638 | SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) |
| 639 | { |
| 640 | uint32_t initial = sc_list.GetSize(); |
| 641 | const uint32_t cu_count = GetNumCompileUnits(); |
| 642 | |
| 643 | FileSpec so_file_spec; |
| 644 | for (uint32_t i=0; i<cu_count; ++i) |
| 645 | { |
| 646 | if (GetFileSpecForSO (i, so_file_spec)) |
| 647 | { |
| 648 | // By passing false to the comparison we will be able to match |
| 649 | // and files given a filename only. If both file_spec and |
| 650 | // so_file_spec have directories, we will still do a full match. |
| 651 | if (FileSpec::Compare (file_spec, so_file_spec, false) == 0) |
| 652 | { |
| 653 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i); |
| 654 | |
| 655 | oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | return sc_list.GetSize() - initial; |
| 660 | } |
| 661 | |
| 662 | uint32_t |
| 663 | SymbolFileDWARFDebugMap::PrivateFindGlobalVariables |
| 664 | ( |
| 665 | const ConstString &name, |
| 666 | const std::vector<uint32_t> &indexes, // Indexes into the symbol table that match "name" |
| 667 | uint32_t max_matches, |
| 668 | VariableList& variables |
| 669 | ) |
| 670 | { |
| 671 | const uint32_t original_size = variables.GetSize(); |
| 672 | const size_t match_count = indexes.size(); |
| 673 | for (size_t i=0; i<match_count; ++i) |
| 674 | { |
| 675 | uint32_t oso_idx; |
| 676 | CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx); |
| 677 | if (comp_unit_info) |
| 678 | { |
| 679 | SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx); |
| 680 | if (oso_dwarf) |
| 681 | { |
| 682 | if (oso_dwarf->FindGlobalVariables(name, true, max_matches, variables)) |
| 683 | if (variables.GetSize() > max_matches) |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | return variables.GetSize() - original_size; |
| 689 | } |
| 690 | |
| 691 | uint32_t |
| 692 | SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables) |
| 693 | { |
| 694 | |
| 695 | // If we aren't appending the results to this list, then clear the list |
| 696 | if (!append) |
| 697 | variables.Clear(); |
| 698 | |
| 699 | // Remember how many variables are in the list before we search in case |
| 700 | // we are appending the results to a variable list. |
| 701 | const uint32_t original_size = variables.GetSize(); |
| 702 | |
| 703 | Symtab* symtab = m_obj_file->GetSymtab(); |
| 704 | if (symtab) |
| 705 | { |
| 706 | std::vector<uint32_t> indexes; |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 707 | const size_t match_count = m_obj_file->GetSymtab()->FindAllSymbolsWithNameAndType (name, eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, indexes); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 708 | if (match_count) |
| 709 | { |
| 710 | PrivateFindGlobalVariables (name, indexes, max_matches, variables); |
| 711 | } |
| 712 | } |
| 713 | // Return the number of variable that were appended to the list |
| 714 | return variables.GetSize() - original_size; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | uint32_t |
| 719 | SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 720 | { |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | |
| 725 | int |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 726 | SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 727 | { |
| 728 | const uint32_t symbol_idx = *symbol_idx_ptr; |
| 729 | |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 730 | if (symbol_idx < comp_unit_info->first_symbol_index) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 731 | return -1; |
| 732 | |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 733 | if (symbol_idx <= comp_unit_info->last_symbol_index) |
| 734 | return 0; |
| 735 | |
| 736 | return 1; |
| 737 | } |
| 738 | |
| 739 | |
| 740 | int |
| 741 | SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info) |
| 742 | { |
| 743 | const user_id_t symbol_id = *symbol_idx_ptr; |
| 744 | |
| 745 | if (symbol_id < comp_unit_info->so_symbol->GetID()) |
| 746 | return -1; |
| 747 | |
| 748 | if (symbol_id <= comp_unit_info->last_symbol->GetID()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | return 0; |
| 750 | |
| 751 | return 1; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | SymbolFileDWARFDebugMap::CompileUnitInfo* |
| 756 | SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr) |
| 757 | { |
| 758 | const uint32_t oso_index_count = m_compile_unit_infos.size(); |
| 759 | CompileUnitInfo *comp_unit_info = NULL; |
| 760 | if (oso_index_count) |
| 761 | { |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 762 | comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(), sizeof(CompileUnitInfo), (comparison_function)SymbolContainsSymbolWithIndex); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | if (oso_idx_ptr) |
| 766 | { |
| 767 | if (comp_unit_info != NULL) |
| 768 | *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; |
| 769 | else |
| 770 | *oso_idx_ptr = UINT32_MAX; |
| 771 | } |
| 772 | return comp_unit_info; |
| 773 | } |
| 774 | |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 775 | SymbolFileDWARFDebugMap::CompileUnitInfo* |
| 776 | SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr) |
| 777 | { |
| 778 | const uint32_t oso_index_count = m_compile_unit_infos.size(); |
| 779 | CompileUnitInfo *comp_unit_info = NULL; |
| 780 | if (oso_index_count) |
| 781 | { |
| 782 | comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(), sizeof(CompileUnitInfo), (comparison_function)SymbolContainsSymbolWithID); |
| 783 | } |
| 784 | |
| 785 | if (oso_idx_ptr) |
| 786 | { |
| 787 | if (comp_unit_info != NULL) |
| 788 | *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0]; |
| 789 | else |
| 790 | *oso_idx_ptr = UINT32_MAX; |
| 791 | } |
| 792 | return comp_unit_info; |
| 793 | } |
| 794 | |
| 795 | |
Greg Clayton | 88957ff | 2010-08-17 23:16:15 +0000 | [diff] [blame] | 796 | static void |
| 797 | RemoveFunctionsWithModuleNotEqualTo (Module *module, SymbolContextList &sc_list, uint32_t start_idx) |
| 798 | { |
| 799 | // We found functions in .o files. Not all functions in the .o files |
| 800 | // will have made it into the final output file. The ones that did |
| 801 | // make it into the final output file will have a section whose module |
| 802 | // matches the module from the ObjectFile for this SymbolFile. When |
| 803 | // the modules don't match, then we have something that was in a |
| 804 | // .o file, but doesn't map to anything in the final executable. |
| 805 | uint32_t i=start_idx; |
| 806 | while (i < sc_list.GetSize()) |
| 807 | { |
| 808 | SymbolContext sc; |
| 809 | sc_list.GetContextAtIndex(i, sc); |
| 810 | if (sc.function) |
| 811 | { |
| 812 | const Section *section = sc.function->GetAddressRange().GetBaseAddress().GetSection(); |
| 813 | if (section->GetModule() != module) |
| 814 | { |
| 815 | sc_list.RemoveContextAtIndex(i); |
| 816 | continue; |
| 817 | } |
| 818 | } |
| 819 | ++i; |
| 820 | } |
| 821 | } |
| 822 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | uint32_t |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 824 | SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | { |
| 826 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 827 | "SymbolFileDWARFDebugMap::FindFunctions (name = %s)", |
| 828 | name.GetCString()); |
| 829 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 830 | uint32_t initial_size = 0; |
| 831 | if (append) |
| 832 | initial_size = sc_list.GetSize(); |
| 833 | else |
| 834 | sc_list.Clear(); |
| 835 | |
Greg Clayton | 7241ba7 | 2010-08-17 00:35:34 +0000 | [diff] [blame] | 836 | uint32_t oso_idx = 0; |
| 837 | SymbolFileDWARF *oso_dwarf; |
| 838 | while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 839 | { |
Greg Clayton | 88957ff | 2010-08-17 23:16:15 +0000 | [diff] [blame] | 840 | uint32_t sc_idx = sc_list.GetSize(); |
| 841 | if (oso_dwarf->FindFunctions(name, name_type_mask, true, sc_list)) |
| 842 | { |
| 843 | RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx); |
| 844 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | return sc_list.GetSize() - initial_size; |
| 848 | } |
| 849 | |
| 850 | |
| 851 | uint32_t |
| 852 | SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool append, SymbolContextList& sc_list) |
| 853 | { |
| 854 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 855 | "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')", |
| 856 | regex.GetText()); |
| 857 | |
Greg Clayton | 7241ba7 | 2010-08-17 00:35:34 +0000 | [diff] [blame] | 858 | uint32_t initial_size = 0; |
| 859 | if (append) |
| 860 | initial_size = sc_list.GetSize(); |
| 861 | else |
| 862 | sc_list.Clear(); |
| 863 | |
| 864 | uint32_t oso_idx = 0; |
| 865 | SymbolFileDWARF *oso_dwarf; |
| 866 | while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) |
| 867 | { |
Greg Clayton | 88957ff | 2010-08-17 23:16:15 +0000 | [diff] [blame] | 868 | uint32_t sc_idx = sc_list.GetSize(); |
| 869 | |
| 870 | if (oso_dwarf->FindFunctions(regex, true, sc_list)) |
| 871 | { |
| 872 | RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx); |
| 873 | } |
Greg Clayton | 7241ba7 | 2010-08-17 00:35:34 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | return sc_list.GetSize() - initial_size; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 879 | |
| 880 | uint32_t |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 881 | SymbolFileDWARFDebugMap::FindTypes |
| 882 | ( |
| 883 | const SymbolContext& sc, |
| 884 | const ConstString &name, |
| 885 | bool append, |
| 886 | uint32_t max_matches, |
| 887 | TypeList& types |
| 888 | ) |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 889 | { |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 890 | if (!append) |
| 891 | types.Clear(); |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 892 | |
| 893 | const uint32_t initial_types_size = types.GetSize(); |
| 894 | SymbolFileDWARF *oso_dwarf; |
| 895 | |
| 896 | if (sc.comp_unit) |
| 897 | { |
| 898 | oso_dwarf = GetSymbolFile (sc); |
| 899 | if (oso_dwarf) |
| 900 | return oso_dwarf->FindTypes (sc, name, append, max_matches, types); |
| 901 | } |
| 902 | else |
| 903 | { |
| 904 | uint32_t oso_idx = 0; |
| 905 | while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL) |
| 906 | oso_dwarf->FindTypes (sc, name, append, max_matches, types); |
| 907 | } |
| 908 | |
| 909 | return types.GetSize() - initial_types_size; |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | // |
| 913 | //uint32_t |
| 914 | //SymbolFileDWARFDebugMap::FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types) |
| 915 | //{ |
| 916 | // SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc); |
| 917 | // if (oso_dwarf) |
| 918 | // return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types); |
| 919 | // return 0; |
| 920 | //} |
| 921 | |
| 922 | //------------------------------------------------------------------ |
| 923 | // PluginInterface protocol |
| 924 | //------------------------------------------------------------------ |
| 925 | const char * |
| 926 | SymbolFileDWARFDebugMap::GetPluginName() |
| 927 | { |
| 928 | return "SymbolFileDWARFDebugMap"; |
| 929 | } |
| 930 | |
| 931 | const char * |
| 932 | SymbolFileDWARFDebugMap::GetShortPluginName() |
| 933 | { |
| 934 | return GetPluginNameStatic(); |
| 935 | } |
| 936 | |
| 937 | uint32_t |
| 938 | SymbolFileDWARFDebugMap::GetPluginVersion() |
| 939 | { |
| 940 | return 1; |
| 941 | } |
| 942 | |
| 943 | void |
| 944 | SymbolFileDWARFDebugMap::GetPluginCommandHelp (const char *command, Stream *strm) |
| 945 | { |
| 946 | } |
| 947 | |
| 948 | Error |
| 949 | SymbolFileDWARFDebugMap::ExecutePluginCommand (Args &command, Stream *strm) |
| 950 | { |
| 951 | Error error; |
| 952 | error.SetErrorString("No plug-in command are currently supported."); |
| 953 | return error; |
| 954 | } |
| 955 | |
| 956 | Log * |
| 957 | SymbolFileDWARFDebugMap::EnablePluginLogging (Stream *strm, Args &command) |
| 958 | { |
| 959 | return NULL; |
| 960 | } |
| 961 | |
| 962 | |