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 
19 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Symbol/SymbolVendor.h"
22 #include "lldb/Symbol/VariableList.h"
23 
24 #include "SymbolFileDWARF.h"
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 
29 void
30 SymbolFileDWARFDebugMap::Initialize()
31 {
32     PluginManager::RegisterPlugin (GetPluginNameStatic(),
33                                    GetPluginDescriptionStatic(),
34                                    CreateInstance);
35 }
36 
37 void
38 SymbolFileDWARFDebugMap::Terminate()
39 {
40     PluginManager::UnregisterPlugin (CreateInstance);
41 }
42 
43 
44 const char *
45 SymbolFileDWARFDebugMap::GetPluginNameStatic()
46 {
47     return "dwarf-debugmap";
48 }
49 
50 const char *
51 SymbolFileDWARFDebugMap::GetPluginDescriptionStatic()
52 {
53     return "DWARF and DWARF3 debug symbol file reader (debug map).";
54 }
55 
56 SymbolFile*
57 SymbolFileDWARFDebugMap::CreateInstance (ObjectFile* obj_file)
58 {
59     return new SymbolFileDWARFDebugMap (obj_file);
60 }
61 
62 
63 SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap (ObjectFile* ofile) :
64     SymbolFile(ofile),
65     m_flags(),
66     m_compile_unit_infos(),
67     m_func_indexes(),
68     m_glob_indexes(),
69     m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate)
70 {
71 }
72 
73 
74 SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap()
75 {
76 }
77 
78 void
79 SymbolFileDWARFDebugMap::InitializeObject()
80 {
81     // Install our external AST source callbacks so we can complete Clang types.
82     llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
83         new ClangExternalASTSourceCallbacks (SymbolFileDWARFDebugMap::CompleteTagDecl,
84                                              SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl,
85                                              NULL,
86                                              SymbolFileDWARFDebugMap::LayoutRecordType,
87                                              this));
88 
89     GetClangASTContext().SetExternalSource (ast_source_ap);
90 }
91 
92 
93 
94 void
95 SymbolFileDWARFDebugMap::InitOSO ()
96 {
97     if (m_flags.test(kHaveInitializedOSOs))
98         return;
99 
100     m_flags.set(kHaveInitializedOSOs);
101     // In order to get the abilities of this plug-in, we look at the list of
102     // N_OSO entries (object files) from the symbol table and make sure that
103     // these files exist and also contain valid DWARF. If we get any of that
104     // then we return the abilities of the first N_OSO's DWARF.
105 
106     Symtab* symtab = m_obj_file->GetSymtab();
107     if (symtab)
108     {
109         std::vector<uint32_t> oso_indexes;
110 //      StreamFile s(stdout);
111 //      symtab->Dump(&s, NULL, eSortOrderNone);
112 
113         // When a mach-o symbol is encoded, the n_type field is encoded in bits
114         // 23:16, and the n_desc field is encoded in bits 15:0.
115         //
116         // To find all N_OSO entries that are part of the DWARF + debug map
117         // we find only object file symbols with the flags value as follows:
118         // bits 23:16 == 0x66 (N_OSO)
119         // bits 15: 0 == 0x0001 (specifies this is a debug map object file)
120         const uint32_t k_oso_symbol_flags_value = 0x660001u;
121 
122         const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithTypeAndFlagsValue(eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
123 
124         if (oso_index_count > 0)
125         {
126             symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes);
127             symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes);
128 
129             symtab->SortSymbolIndexesByValue(m_func_indexes, true);
130             symtab->SortSymbolIndexesByValue(m_glob_indexes, true);
131 
132             m_compile_unit_infos.resize(oso_index_count);
133 //          s.Printf("%s N_OSO symbols:\n", __PRETTY_FUNCTION__);
134 //          symtab->Dump(&s, oso_indexes);
135 
136             for (uint32_t i=0; i<oso_index_count; ++i)
137             {
138                 m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 1);
139                 if (m_compile_unit_infos[i].so_symbol->GetSiblingIndex() == 0)
140                     m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 2);
141                 m_compile_unit_infos[i].oso_symbol = symtab->SymbolAtIndex(oso_indexes[i]);
142                 uint32_t sibling_idx = m_compile_unit_infos[i].so_symbol->GetSiblingIndex();
143                 assert (sibling_idx != 0);
144                 assert (sibling_idx > i + 1);
145                 m_compile_unit_infos[i].last_symbol = symtab->SymbolAtIndex (sibling_idx - 1);
146                 m_compile_unit_infos[i].first_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].so_symbol);
147                 m_compile_unit_infos[i].last_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].last_symbol);
148             }
149         }
150     }
151 }
152 
153 Module *
154 SymbolFileDWARFDebugMap::GetModuleByOSOIndex (uint32_t oso_idx)
155 {
156     const uint32_t cu_count = GetNumCompileUnits();
157     if (oso_idx < cu_count)
158         return GetModuleByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
159     return NULL;
160 }
161 
162 Module *
163 SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info)
164 {
165     if (comp_unit_info->oso_module_sp.get() == NULL && comp_unit_info->symbol_file_supported)
166     {
167         Symbol *oso_symbol = comp_unit_info->oso_symbol;
168         if (oso_symbol)
169         {
170             FileSpec oso_file_spec(oso_symbol->GetMangled().GetName().AsCString(), true);
171             // Always create a new module for .o files. Why? Because we
172             // use the debug map, to add new sections to each .o file and
173             // even though a .o file might not have changed, the sections
174             // that get added to the .o file can change.
175             comp_unit_info->oso_module_sp.reset (new Module (oso_file_spec,
176                                                              m_obj_file->GetModule()->GetArchitecture(),
177                                                              NULL,
178                                                              0));
179         }
180     }
181     return comp_unit_info->oso_module_sp.get();
182 }
183 
184 
185 bool
186 SymbolFileDWARFDebugMap::GetFileSpecForSO (uint32_t oso_idx, FileSpec &file_spec)
187 {
188     if (oso_idx < m_compile_unit_infos.size())
189     {
190         if (!m_compile_unit_infos[oso_idx].so_file)
191         {
192 
193             if (m_compile_unit_infos[oso_idx].so_symbol == NULL)
194                 return false;
195 
196             std::string so_path (m_compile_unit_infos[oso_idx].so_symbol->GetMangled().GetName().AsCString());
197             if (m_compile_unit_infos[oso_idx].so_symbol[1].GetType() == eSymbolTypeSourceFile)
198                 so_path += m_compile_unit_infos[oso_idx].so_symbol[1].GetMangled().GetName().AsCString();
199             m_compile_unit_infos[oso_idx].so_file.SetFile(so_path.c_str(), true);
200         }
201         file_spec = m_compile_unit_infos[oso_idx].so_file;
202         return true;
203     }
204     return false;
205 }
206 
207 
208 
209 ObjectFile *
210 SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex (uint32_t oso_idx)
211 {
212     Module *oso_module = GetModuleByOSOIndex (oso_idx);
213     if (oso_module)
214         return oso_module->GetObjectFile();
215     return NULL;
216 }
217 
218 SymbolFileDWARF *
219 SymbolFileDWARFDebugMap::GetSymbolFile (const SymbolContext& sc)
220 {
221     CompileUnitInfo *comp_unit_info = GetCompUnitInfo (sc);
222     if (comp_unit_info)
223         return GetSymbolFileByCompUnitInfo (comp_unit_info);
224     return NULL;
225 }
226 
227 ObjectFile *
228 SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
229 {
230     Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info);
231     if (oso_module)
232         return oso_module->GetObjectFile();
233     return NULL;
234 }
235 
236 
237 uint32_t
238 SymbolFileDWARFDebugMap::GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info)
239 {
240     if (!m_compile_unit_infos.empty())
241     {
242         const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
243         const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
244         if (first_comp_unit_info <= comp_unit_info && comp_unit_info <= last_comp_unit_info)
245             return comp_unit_info - first_comp_unit_info;
246     }
247     return UINT32_MAX;
248 }
249 
250 SymbolFileDWARF *
251 SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex (uint32_t oso_idx)
252 {
253     if (oso_idx < m_compile_unit_infos.size())
254         return GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
255     return NULL;
256 }
257 
258 SymbolFileDWARF *
259 SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
260 {
261     if (comp_unit_info->oso_symbol_vendor == NULL && comp_unit_info->symbol_file_supported)
262     {
263         ObjectFile *oso_objfile = GetObjectFileByCompUnitInfo (comp_unit_info);
264 
265         if (oso_objfile)
266         {
267             comp_unit_info->oso_symbol_vendor = oso_objfile->GetModule()->GetSymbolVendor();
268 //          SymbolFileDWARF *oso_dwarf = new SymbolFileDWARF(oso_objfile);
269 //          comp_unit_info->oso_dwarf_sp.reset (oso_dwarf);
270             if (comp_unit_info->oso_symbol_vendor)
271             {
272                 // Set a a pointer to this class to set our OSO DWARF file know
273                 // that the DWARF is being used along with a debug map and that
274                 // it will have the remapped sections that we do below.
275                 SymbolFileDWARF *oso_symfile = (SymbolFileDWARF *)comp_unit_info->oso_symbol_vendor->GetSymbolFile();
276 
277                 if (oso_symfile->GetNumCompileUnits() != 1)
278                 {
279                     oso_symfile->GetObjectFile()->GetModule()->ReportError ("DWARF for object file '%s' contains multiple translation units!",
280                                                                             oso_symfile->GetObjectFile()->GetFileSpec().GetFilename().AsCString());
281                     comp_unit_info->symbol_file_supported = false;
282                     comp_unit_info->oso_module_sp.reset();
283                     comp_unit_info->oso_compile_unit_sp.reset();
284                     comp_unit_info->oso_symbol_vendor = NULL;
285                     return NULL;
286                 }
287 
288                 oso_symfile->SetDebugMapSymfile(this);
289                 // Set the ID of the symbol file DWARF to the index of the OSO
290                 // shifted left by 32 bits to provide a unique prefix for any
291                 // UserID's that get created in the symbol file.
292                 oso_symfile->SetID (((uint64_t)GetCompUnitInfoIndex(comp_unit_info) + 1ull) << 32ull);
293                 comp_unit_info->debug_map_sections_sp.reset(new SectionList);
294 
295                 Symtab *exe_symtab = m_obj_file->GetSymtab();
296                 ModuleSP oso_module_sp (oso_objfile->GetModule());
297                 Symtab *oso_symtab = oso_objfile->GetSymtab();
298 //#define DEBUG_OSO_DMAP    // Do not check in with this defined...
299 #if defined(DEBUG_OSO_DMAP)
300                 StreamFile s(stdout);
301                 s << "OSO symtab:\n";
302                 oso_symtab->Dump(&s, NULL);
303                 s << "OSO sections before:\n";
304                 oso_objfile->GetSectionList()->Dump(&s, NULL, true);
305 #endif
306 
307                 ///const uint32_t fun_resolve_flags = SymbolContext::Module | eSymbolContextCompUnit | eSymbolContextFunction;
308                 //SectionList *oso_sections = oso_objfile->Sections();
309                 // Now we need to make sections that map from zero based object
310                 // file addresses to where things eneded up in the main executable.
311                 uint32_t oso_start_idx = exe_symtab->GetIndexForSymbol (comp_unit_info->oso_symbol);
312                 assert (oso_start_idx != UINT32_MAX);
313                 oso_start_idx += 1;
314                 const uint32_t oso_end_idx = comp_unit_info->so_symbol->GetSiblingIndex();
315                 uint32_t sect_id = 0x10000;
316                 for (uint32_t idx = oso_start_idx; idx < oso_end_idx; ++idx)
317                 {
318                     Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx);
319                     if (exe_symbol)
320                     {
321                         if (exe_symbol->IsDebug() == false)
322                             continue;
323 
324                         switch (exe_symbol->GetType())
325                         {
326                         default:
327                             break;
328 
329                         case eSymbolTypeCode:
330                             {
331                                 // For each N_FUN, or function that we run into in the debug map
332                                 // we make a new section that we add to the sections found in the
333                                 // .o file. This new section has the file address set to what the
334                                 // addresses are in the .o file, and the load address is adjusted
335                                 // to match where it ended up in the final executable! We do this
336                                 // before we parse any dwarf info so that when it goes get parsed
337                                 // all section/offset addresses that get registered will resolve
338                                 // correctly to the new addresses in the main executable.
339 
340                                 // First we find the original symbol in the .o file's symbol table
341                                 Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny);
342                                 if (oso_fun_symbol)
343                                 {
344                                     // If we found the symbol, then we
345                                     SectionSP exe_fun_section (exe_symbol->GetAddress().GetSection());
346                                     SectionSP oso_fun_section (oso_fun_symbol->GetAddress().GetSection());
347                                     if (oso_fun_section)
348                                     {
349                                         // Now we create a section that we will add as a child of the
350                                         // section in which the .o symbol (the N_FUN) exists.
351 
352                                         // We use the exe_symbol size because the one in the .o file
353                                         // will just be a symbol with no size, and the exe_symbol
354                                         // size will reflect any size changes (ppc has been known to
355                                         // shrink function sizes when it gets rid of jump islands that
356                                         // aren't needed anymore).
357                                         SectionSP oso_fun_section_sp (new Section (oso_fun_symbol->GetAddress().GetSection(),
358                                                                                         oso_module_sp,                         // Module (the .o file)
359                                                                                         sect_id++,                          // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs
360                                                                                         exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated!
361                                                                                         eSectionTypeDebug,
362                                                                                         oso_fun_symbol->GetAddress().GetOffset(),  // File VM address offset in the current section
363                                                                                         exe_symbol->GetByteSize(),          // File size (we need the size from the executable)
364                                                                                         0, 0, 0));
365 
366                                         oso_fun_section_sp->SetLinkedLocation (exe_fun_section,
367                                                                                exe_symbol->GetAddress().GetFileAddress() - exe_fun_section->GetFileAddress());
368                                         oso_fun_section->GetChildren().AddSection(oso_fun_section_sp);
369                                         comp_unit_info->debug_map_sections_sp->AddSection(oso_fun_section_sp);
370                                     }
371                                 }
372                             }
373                             break;
374 
375                         case eSymbolTypeData:
376                             {
377                                 // For each N_GSYM we remap the address for the global by making
378                                 // a new section that we add to the sections found in the .o file.
379                                 // This new section has the file address set to what the
380                                 // addresses are in the .o file, and the load address is adjusted
381                                 // to match where it ended up in the final executable! We do this
382                                 // before we parse any dwarf info so that when it goes get parsed
383                                 // all section/offset addresses that get registered will resolve
384                                 // correctly to the new addresses in the main executable. We
385                                 // initially set the section size to be 1 byte, but will need to
386                                 // fix up these addresses further after all globals have been
387                                 // parsed to span the gaps, or we can find the global variable
388                                 // sizes from the DWARF info as we are parsing.
389 
390                                 // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file
391                                 Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(),
392                                                                                                       eSymbolTypeData,
393                                                                                                       Symtab::eDebugNo,
394                                                                                                       Symtab::eVisibilityAny);
395 
396                                 if (exe_symbol && oso_gsym_symbol && exe_symbol->ValueIsAddress() && oso_gsym_symbol->ValueIsAddress())
397                                 {
398                                     // If we found the symbol, then we
399                                     SectionSP exe_gsym_section (exe_symbol->GetAddress().GetSection());
400                                     SectionSP oso_gsym_section (oso_gsym_symbol->GetAddress().GetSection());
401                                     if (oso_gsym_section)
402                                     {
403                                         SectionSP oso_gsym_section_sp (new Section (oso_gsym_symbol->GetAddress().GetSection(),
404                                                                                     oso_module_sp,                         // Module (the .o file)
405                                                                                     sect_id++,                          // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs
406                                                                                     exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated!
407                                                                                     eSectionTypeDebug,
408                                                                                     oso_gsym_symbol->GetAddress().GetOffset(),  // File VM address offset in the current section
409                                                                                     1,                                   // We don't know the size of the global, just do the main address for now.
410                                                                                     0, 0, 0));
411 
412                                         oso_gsym_section_sp->SetLinkedLocation (exe_gsym_section,
413                                                                                 exe_symbol->GetAddress().GetFileAddress() - exe_gsym_section->GetFileAddress());
414                                         oso_gsym_section->GetChildren().AddSection(oso_gsym_section_sp);
415                                         comp_unit_info->debug_map_sections_sp->AddSection(oso_gsym_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::CalculateAbilities ()
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 && m_compile_unit_infos[cu_idx].symbol_file_supported)
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,
508                                                                                             eLanguageTypeUnknown));
509 
510                     // Let our symbol vendor know about this compile unit
511                     m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex (m_compile_unit_infos[cu_idx].oso_compile_unit_sp,
512                                                                                        cu_idx);
513                 }
514             }
515         }
516         comp_unit_sp = m_compile_unit_infos[cu_idx].oso_compile_unit_sp;
517     }
518 
519     return comp_unit_sp;
520 }
521 
522 SymbolFileDWARFDebugMap::CompileUnitInfo *
523 SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc)
524 {
525     const uint32_t cu_count = GetNumCompileUnits();
526     for (uint32_t i=0; i<cu_count; ++i)
527     {
528         if (sc.comp_unit == m_compile_unit_infos[i].oso_compile_unit_sp.get())
529             return &m_compile_unit_infos[i];
530     }
531     return NULL;
532 }
533 
534 size_t
535 SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc)
536 {
537     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
538     if (oso_dwarf)
539         return oso_dwarf->ParseCompileUnitFunctions (sc);
540     return 0;
541 }
542 
543 bool
544 SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc)
545 {
546     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
547     if (oso_dwarf)
548         return oso_dwarf->ParseCompileUnitLineTable (sc);
549     return false;
550 }
551 
552 bool
553 SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files)
554 {
555     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
556     if (oso_dwarf)
557         return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files);
558     return false;
559 }
560 
561 
562 size_t
563 SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc)
564 {
565     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
566     if (oso_dwarf)
567         return oso_dwarf->ParseFunctionBlocks (sc);
568     return 0;
569 }
570 
571 
572 size_t
573 SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc)
574 {
575     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
576     if (oso_dwarf)
577         return oso_dwarf->ParseTypes (sc);
578     return 0;
579 }
580 
581 
582 size_t
583 SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc)
584 {
585     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
586     if (oso_dwarf)
587         return oso_dwarf->ParseTypes (sc);
588     return 0;
589 }
590 
591 
592 
593 Type*
594 SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid)
595 {
596     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
597     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
598     if (oso_dwarf)
599         oso_dwarf->ResolveTypeUID (type_uid);
600     return NULL;
601 }
602 
603 lldb::clang_type_t
604 SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
605 {
606     // We have a struct/union/class/enum that needs to be fully resolved.
607     return NULL;
608 }
609 
610 uint32_t
611 SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc)
612 {
613     uint32_t resolved_flags = 0;
614     Symtab* symtab = m_obj_file->GetSymtab();
615     if (symtab)
616     {
617         const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
618         sc.symbol = symtab->FindSymbolContainingFileAddress (exe_file_addr, &m_func_indexes[0], m_func_indexes.size());
619 
620         if (sc.symbol != NULL)
621         {
622             resolved_flags |= eSymbolContextSymbol;
623 
624             uint32_t oso_idx = 0;
625             CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx);
626             if (comp_unit_info)
627             {
628                 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
629                 ObjectFile *oso_objfile = GetObjectFileByOSOIndex (oso_idx);
630                 if (oso_dwarf && oso_objfile)
631                 {
632                     SectionList *oso_section_list = oso_objfile->GetSectionList();
633 
634                     SectionSP oso_symbol_section_sp (oso_section_list->FindSectionContainingLinkedFileAddress (exe_file_addr, UINT32_MAX));
635 
636                     if (oso_symbol_section_sp)
637                     {
638                         const addr_t linked_file_addr = oso_symbol_section_sp->GetLinkedFileAddress();
639                         Address oso_so_addr (oso_symbol_section_sp, exe_file_addr - linked_file_addr);
640                         if (oso_so_addr.IsSectionOffset())
641                             resolved_flags |= oso_dwarf->ResolveSymbolContext (oso_so_addr, resolve_scope, sc);
642                     }
643                 }
644             }
645         }
646     }
647     return resolved_flags;
648 }
649 
650 
651 uint32_t
652 SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
653 {
654     uint32_t initial = sc_list.GetSize();
655     const uint32_t cu_count = GetNumCompileUnits();
656 
657     FileSpec so_file_spec;
658     for (uint32_t i=0; i<cu_count; ++i)
659     {
660         if (GetFileSpecForSO (i, so_file_spec))
661         {
662             // By passing false to the comparison we will be able to match
663             // and files given a filename only. If both file_spec and
664             // so_file_spec have directories, we will still do a full match.
665             if (FileSpec::Compare (file_spec, so_file_spec, false) == 0)
666             {
667                 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i);
668                 if (oso_dwarf)
669                     oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
670             }
671         }
672     }
673     return sc_list.GetSize() - initial;
674 }
675 
676 uint32_t
677 SymbolFileDWARFDebugMap::PrivateFindGlobalVariables
678 (
679     const ConstString &name,
680     const ClangNamespaceDecl *namespace_decl,
681     const std::vector<uint32_t> &indexes,   // Indexes into the symbol table that match "name"
682     uint32_t max_matches,
683     VariableList& variables
684 )
685 {
686     const uint32_t original_size = variables.GetSize();
687     const size_t match_count = indexes.size();
688     for (size_t i=0; i<match_count; ++i)
689     {
690         uint32_t oso_idx;
691         CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx);
692         if (comp_unit_info)
693         {
694             SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
695             if (oso_dwarf)
696             {
697                 if (oso_dwarf->FindGlobalVariables(name, namespace_decl, true, max_matches, variables))
698                     if (variables.GetSize() > max_matches)
699                         break;
700             }
701         }
702     }
703     return variables.GetSize() - original_size;
704 }
705 
706 uint32_t
707 SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
708 {
709 
710     // If we aren't appending the results to this list, then clear the list
711     if (!append)
712         variables.Clear();
713 
714     // Remember how many variables are in the list before we search in case
715     // we are appending the results to a variable list.
716     const uint32_t original_size = variables.GetSize();
717 
718     uint32_t total_matches = 0;
719     SymbolFileDWARF *oso_dwarf;
720     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
721     {
722         const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name,
723                                                                      namespace_decl,
724                                                                      true,
725                                                                      max_matches,
726                                                                      variables);
727         if (oso_matches > 0)
728         {
729             total_matches += oso_matches;
730 
731             // Are we getting all matches?
732             if (max_matches == UINT32_MAX)
733                 continue;   // Yep, continue getting everything
734 
735             // If we have found enough matches, lets get out
736             if (max_matches >= total_matches)
737                 break;
738 
739             // Update the max matches for any subsequent calls to find globals
740             // in any other object files with DWARF
741             max_matches -= oso_matches;
742         }
743     }
744     // Return the number of variable that were appended to the list
745     return variables.GetSize() - original_size;
746 }
747 
748 
749 uint32_t
750 SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
751 {
752     // If we aren't appending the results to this list, then clear the list
753     if (!append)
754         variables.Clear();
755 
756     // Remember how many variables are in the list before we search in case
757     // we are appending the results to a variable list.
758     const uint32_t original_size = variables.GetSize();
759 
760     uint32_t total_matches = 0;
761     SymbolFileDWARF *oso_dwarf;
762     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
763     {
764         const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
765                                                                      true,
766                                                                      max_matches,
767                                                                      variables);
768         if (oso_matches > 0)
769         {
770             total_matches += oso_matches;
771 
772             // Are we getting all matches?
773             if (max_matches == UINT32_MAX)
774                 continue;   // Yep, continue getting everything
775 
776             // If we have found enough matches, lets get out
777             if (max_matches >= total_matches)
778                 break;
779 
780             // Update the max matches for any subsequent calls to find globals
781             // in any other object files with DWARF
782             max_matches -= oso_matches;
783         }
784     }
785     // Return the number of variable that were appended to the list
786     return variables.GetSize() - original_size;
787 }
788 
789 
790 int
791 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
792 {
793     const uint32_t symbol_idx = *symbol_idx_ptr;
794 
795     if (symbol_idx < comp_unit_info->first_symbol_index)
796         return -1;
797 
798     if (symbol_idx <= comp_unit_info->last_symbol_index)
799         return 0;
800 
801     return 1;
802 }
803 
804 
805 int
806 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
807 {
808     const user_id_t symbol_id = *symbol_idx_ptr;
809 
810     if (symbol_id < comp_unit_info->so_symbol->GetID())
811         return -1;
812 
813     if (symbol_id <= comp_unit_info->last_symbol->GetID())
814         return 0;
815 
816     return 1;
817 }
818 
819 
820 SymbolFileDWARFDebugMap::CompileUnitInfo*
821 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr)
822 {
823     const uint32_t oso_index_count = m_compile_unit_infos.size();
824     CompileUnitInfo *comp_unit_info = NULL;
825     if (oso_index_count)
826     {
827         comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx,
828                                                    &m_compile_unit_infos[0],
829                                                    m_compile_unit_infos.size(),
830                                                    sizeof(CompileUnitInfo),
831                                                    (ComparisonFunction)SymbolContainsSymbolWithIndex);
832     }
833 
834     if (oso_idx_ptr)
835     {
836         if (comp_unit_info != NULL)
837             *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
838         else
839             *oso_idx_ptr = UINT32_MAX;
840     }
841     return comp_unit_info;
842 }
843 
844 SymbolFileDWARFDebugMap::CompileUnitInfo*
845 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr)
846 {
847     const uint32_t oso_index_count = m_compile_unit_infos.size();
848     CompileUnitInfo *comp_unit_info = NULL;
849     if (oso_index_count)
850     {
851         comp_unit_info = (CompileUnitInfo*)::bsearch (&symbol_id,
852                                                       &m_compile_unit_infos[0],
853                                                       m_compile_unit_infos.size(),
854                                                       sizeof(CompileUnitInfo),
855                                                       (ComparisonFunction)SymbolContainsSymbolWithID);
856     }
857 
858     if (oso_idx_ptr)
859     {
860         if (comp_unit_info != NULL)
861             *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
862         else
863             *oso_idx_ptr = UINT32_MAX;
864     }
865     return comp_unit_info;
866 }
867 
868 
869 static void
870 RemoveFunctionsWithModuleNotEqualTo (const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx)
871 {
872     // We found functions in .o files. Not all functions in the .o files
873     // will have made it into the final output file. The ones that did
874     // make it into the final output file will have a section whose module
875     // matches the module from the ObjectFile for this SymbolFile. When
876     // the modules don't match, then we have something that was in a
877     // .o file, but doesn't map to anything in the final executable.
878     uint32_t i=start_idx;
879     while (i < sc_list.GetSize())
880     {
881         SymbolContext sc;
882         sc_list.GetContextAtIndex(i, sc);
883         if (sc.function)
884         {
885             const SectionSP section_sp (sc.function->GetAddressRange().GetBaseAddress().GetSection());
886             if (section_sp->GetModule() != module_sp)
887             {
888                 sc_list.RemoveContextAtIndex(i);
889                 continue;
890             }
891         }
892         ++i;
893     }
894 }
895 
896 uint32_t
897 SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
898 {
899     Timer scoped_timer (__PRETTY_FUNCTION__,
900                         "SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
901                         name.GetCString());
902 
903     uint32_t initial_size = 0;
904     if (append)
905         initial_size = sc_list.GetSize();
906     else
907         sc_list.Clear();
908 
909     uint32_t oso_idx = 0;
910     SymbolFileDWARF *oso_dwarf;
911     while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
912     {
913         uint32_t sc_idx = sc_list.GetSize();
914         if (oso_dwarf->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, true, sc_list))
915         {
916             RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
917         }
918     }
919 
920     return sc_list.GetSize() - initial_size;
921 }
922 
923 
924 uint32_t
925 SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
926 {
927     Timer scoped_timer (__PRETTY_FUNCTION__,
928                         "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
929                         regex.GetText());
930 
931     uint32_t initial_size = 0;
932     if (append)
933         initial_size = sc_list.GetSize();
934     else
935         sc_list.Clear();
936 
937     uint32_t oso_idx = 0;
938     SymbolFileDWARF *oso_dwarf;
939     while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
940     {
941         uint32_t sc_idx = sc_list.GetSize();
942 
943         if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list))
944         {
945             RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
946         }
947     }
948 
949     return sc_list.GetSize() - initial_size;
950 }
951 
952 TypeSP
953 SymbolFileDWARFDebugMap::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
954                                                    const DWARFDebugInfoEntry *die,
955                                                    const ConstString &type_name)
956 {
957     TypeSP type_sp;
958     SymbolFileDWARF *oso_dwarf;
959     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
960     {
961         type_sp = oso_dwarf->FindDefinitionTypeForDIE (cu, die, type_name);
962         if (type_sp)
963             break;
964     }
965     return type_sp;
966 }
967 
968 
969 
970 bool
971 SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso)
972 {
973     if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
974     {
975         m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
976         SymbolFileDWARF *oso_dwarf;
977         for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
978         {
979             if (skip_dwarf_oso != oso_dwarf && oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL))
980             {
981                 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
982                 break;
983             }
984         }
985     }
986     return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
987 }
988 
989 TypeSP
990 SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
991                                                                const ConstString &type_name,
992                                                                bool must_be_implementation)
993 {
994     TypeSP type_sp;
995     SymbolFileDWARF *oso_dwarf;
996     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
997     {
998         type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation);
999         if (type_sp)
1000             break;
1001     }
1002     return type_sp;
1003 }
1004 
1005 uint32_t
1006 SymbolFileDWARFDebugMap::FindTypes
1007 (
1008     const SymbolContext& sc,
1009     const ConstString &name,
1010     const ClangNamespaceDecl *namespace_decl,
1011     bool append,
1012     uint32_t max_matches,
1013     TypeList& types
1014 )
1015 {
1016     if (!append)
1017         types.Clear();
1018 
1019     const uint32_t initial_types_size = types.GetSize();
1020     SymbolFileDWARF *oso_dwarf;
1021 
1022     if (sc.comp_unit)
1023     {
1024         oso_dwarf = GetSymbolFile (sc);
1025         if (oso_dwarf)
1026             return oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
1027     }
1028     else
1029     {
1030         uint32_t oso_idx = 0;
1031         while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
1032             oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
1033     }
1034 
1035     return types.GetSize() - initial_types_size;
1036 }
1037 
1038 //
1039 //uint32_t
1040 //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)
1041 //{
1042 //  SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
1043 //  if (oso_dwarf)
1044 //      return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types);
1045 //  return 0;
1046 //}
1047 
1048 
1049 ClangNamespaceDecl
1050 SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc,
1051                                         const lldb_private::ConstString &name,
1052                                         const ClangNamespaceDecl *parent_namespace_decl)
1053 {
1054     ClangNamespaceDecl matching_namespace;
1055     SymbolFileDWARF *oso_dwarf;
1056 
1057     if (sc.comp_unit)
1058     {
1059         oso_dwarf = GetSymbolFile (sc);
1060         if (oso_dwarf)
1061             matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
1062     }
1063     else
1064     {
1065         for (uint32_t oso_idx = 0;
1066              ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL);
1067              ++oso_idx)
1068         {
1069             matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
1070 
1071             if (matching_namespace)
1072                 break;
1073         }
1074     }
1075 
1076     return matching_namespace;
1077 }
1078 
1079 //------------------------------------------------------------------
1080 // PluginInterface protocol
1081 //------------------------------------------------------------------
1082 const char *
1083 SymbolFileDWARFDebugMap::GetPluginName()
1084 {
1085     return "SymbolFileDWARFDebugMap";
1086 }
1087 
1088 const char *
1089 SymbolFileDWARFDebugMap::GetShortPluginName()
1090 {
1091     return GetPluginNameStatic();
1092 }
1093 
1094 uint32_t
1095 SymbolFileDWARFDebugMap::GetPluginVersion()
1096 {
1097     return 1;
1098 }
1099 
1100 void
1101 SymbolFileDWARFDebugMap::SetCompileUnit (SymbolFileDWARF *oso_dwarf, const CompUnitSP &cu_sp)
1102 {
1103     const uint32_t cu_count = GetNumCompileUnits();
1104     for (uint32_t i=0; i<cu_count; ++i)
1105     {
1106         if (m_compile_unit_infos[i].oso_symbol_vendor &&
1107             m_compile_unit_infos[i].oso_symbol_vendor->GetSymbolFile() == oso_dwarf)
1108         {
1109             if (m_compile_unit_infos[i].oso_compile_unit_sp)
1110             {
1111                 assert (m_compile_unit_infos[i].oso_compile_unit_sp.get() == cu_sp.get());
1112             }
1113             else
1114             {
1115                 m_compile_unit_infos[i].oso_compile_unit_sp = cu_sp;
1116             }
1117         }
1118     }
1119 }
1120 
1121 
1122 void
1123 SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl)
1124 {
1125     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1126     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1127     if (clang_type)
1128     {
1129         SymbolFileDWARF *oso_dwarf;
1130 
1131         for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1132         {
1133             if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1134             {
1135                 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1136                 return;
1137             }
1138         }
1139     }
1140 }
1141 
1142 void
1143 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
1144 {
1145     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1146     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1147     if (clang_type)
1148     {
1149         SymbolFileDWARF *oso_dwarf;
1150 
1151         for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1152         {
1153             if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1154             {
1155                 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1156                 return;
1157             }
1158         }
1159     }
1160 }
1161 
1162 bool
1163 SymbolFileDWARFDebugMap::LayoutRecordType (void *baton,
1164                                            const clang::RecordDecl *record_decl,
1165                                            uint64_t &size,
1166                                            uint64_t &alignment,
1167                                            llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
1168                                            llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
1169                                            llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
1170 {
1171     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1172     SymbolFileDWARF *oso_dwarf;
1173     for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1174     {
1175         if (oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets))
1176             return true;
1177     }
1178     return false;
1179 }
1180 
1181 
1182 
1183 clang::DeclContext*
1184 SymbolFileDWARFDebugMap::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
1185 {
1186     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1187     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1188     if (oso_dwarf)
1189         return oso_dwarf->GetClangDeclContextContainingTypeUID (type_uid);
1190     return NULL;
1191 }
1192 
1193 clang::DeclContext*
1194 SymbolFileDWARFDebugMap::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1195 {
1196     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1197     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1198     if (oso_dwarf)
1199         return oso_dwarf->GetClangDeclContextForTypeUID (sc, type_uid);
1200     return NULL;
1201 }
1202 
1203 
1204