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 &&
485             m_compile_unit_infos[cu_idx].symbol_file_supported)
486         {
487             SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (cu_idx);
488             if (oso_dwarf)
489             {
490                 // There is only one compile unit for N_OSO entry right now, so
491                 // it will always exist at index zero.
492                 m_compile_unit_infos[cu_idx].oso_compile_unit_sp = m_compile_unit_infos[cu_idx].oso_symbol_vendor->GetCompileUnitAtIndex (0);
493             }
494 
495             if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL)
496             {
497                 // We weren't able to get the DWARF for this N_OSO entry (the
498                 // .o file may be missing or not at the specified path), make
499                 // one up as best we can from the debug map. We set the uid
500                 // of the compile unit to the symbol index with the MSBit set
501                 // so that it doesn't collide with any uid values from the DWARF
502                 Symbol *so_symbol = m_compile_unit_infos[cu_idx].so_symbol;
503                 if (so_symbol)
504                 {
505                     m_compile_unit_infos[cu_idx].oso_compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
506                                                                                             NULL,
507                                                                                             so_symbol->GetMangled().GetName().AsCString(),
508                                                                                             cu_idx,
509                                                                                             eLanguageTypeUnknown));
510 
511                     // Let our symbol vendor know about this compile unit
512                     m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex (cu_idx,
513                                                                                        m_compile_unit_infos[cu_idx].oso_compile_unit_sp);
514                 }
515             }
516         }
517         comp_unit_sp = m_compile_unit_infos[cu_idx].oso_compile_unit_sp;
518     }
519 
520     return comp_unit_sp;
521 }
522 
523 SymbolFileDWARFDebugMap::CompileUnitInfo *
524 SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc)
525 {
526     const uint32_t cu_count = GetNumCompileUnits();
527     for (uint32_t i=0; i<cu_count; ++i)
528     {
529         if (sc.comp_unit == m_compile_unit_infos[i].oso_compile_unit_sp.get())
530             return &m_compile_unit_infos[i];
531     }
532     return NULL;
533 }
534 
535 size_t
536 SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc)
537 {
538     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
539     if (oso_dwarf)
540         return oso_dwarf->ParseCompileUnitFunctions (sc);
541     return 0;
542 }
543 
544 bool
545 SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc)
546 {
547     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
548     if (oso_dwarf)
549         return oso_dwarf->ParseCompileUnitLineTable (sc);
550     return false;
551 }
552 
553 bool
554 SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files)
555 {
556     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
557     if (oso_dwarf)
558         return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files);
559     return false;
560 }
561 
562 
563 size_t
564 SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc)
565 {
566     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
567     if (oso_dwarf)
568         return oso_dwarf->ParseFunctionBlocks (sc);
569     return 0;
570 }
571 
572 
573 size_t
574 SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc)
575 {
576     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
577     if (oso_dwarf)
578         return oso_dwarf->ParseTypes (sc);
579     return 0;
580 }
581 
582 
583 size_t
584 SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc)
585 {
586     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
587     if (oso_dwarf)
588         return oso_dwarf->ParseTypes (sc);
589     return 0;
590 }
591 
592 
593 
594 Type*
595 SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid)
596 {
597     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
598     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
599     if (oso_dwarf)
600         oso_dwarf->ResolveTypeUID (type_uid);
601     return NULL;
602 }
603 
604 lldb::clang_type_t
605 SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
606 {
607     // We have a struct/union/class/enum that needs to be fully resolved.
608     return NULL;
609 }
610 
611 uint32_t
612 SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc)
613 {
614     uint32_t resolved_flags = 0;
615     Symtab* symtab = m_obj_file->GetSymtab();
616     if (symtab)
617     {
618         const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
619         sc.symbol = symtab->FindSymbolContainingFileAddress (exe_file_addr, &m_func_indexes[0], m_func_indexes.size());
620 
621         if (sc.symbol != NULL)
622         {
623             resolved_flags |= eSymbolContextSymbol;
624 
625             uint32_t oso_idx = 0;
626             CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx);
627             if (comp_unit_info)
628             {
629                 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
630                 ObjectFile *oso_objfile = GetObjectFileByOSOIndex (oso_idx);
631                 if (oso_dwarf && oso_objfile)
632                 {
633                     SectionList *oso_section_list = oso_objfile->GetSectionList();
634 
635                     SectionSP oso_symbol_section_sp (oso_section_list->FindSectionContainingLinkedFileAddress (exe_file_addr, UINT32_MAX));
636 
637                     if (oso_symbol_section_sp)
638                     {
639                         const addr_t linked_file_addr = oso_symbol_section_sp->GetLinkedFileAddress();
640                         Address oso_so_addr (oso_symbol_section_sp, exe_file_addr - linked_file_addr);
641                         if (oso_so_addr.IsSectionOffset())
642                             resolved_flags |= oso_dwarf->ResolveSymbolContext (oso_so_addr, resolve_scope, sc);
643                     }
644                 }
645             }
646         }
647     }
648     return resolved_flags;
649 }
650 
651 
652 uint32_t
653 SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
654 {
655     uint32_t initial = sc_list.GetSize();
656     const uint32_t cu_count = GetNumCompileUnits();
657 
658     FileSpec so_file_spec;
659     for (uint32_t i=0; i<cu_count; ++i)
660     {
661         if (GetFileSpecForSO (i, so_file_spec))
662         {
663             // By passing false to the comparison we will be able to match
664             // and files given a filename only. If both file_spec and
665             // so_file_spec have directories, we will still do a full match.
666             if (FileSpec::Compare (file_spec, so_file_spec, false) == 0)
667             {
668                 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i);
669                 if (oso_dwarf)
670                     oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
671             }
672         }
673     }
674     return sc_list.GetSize() - initial;
675 }
676 
677 uint32_t
678 SymbolFileDWARFDebugMap::PrivateFindGlobalVariables
679 (
680     const ConstString &name,
681     const ClangNamespaceDecl *namespace_decl,
682     const std::vector<uint32_t> &indexes,   // Indexes into the symbol table that match "name"
683     uint32_t max_matches,
684     VariableList& variables
685 )
686 {
687     const uint32_t original_size = variables.GetSize();
688     const size_t match_count = indexes.size();
689     for (size_t i=0; i<match_count; ++i)
690     {
691         uint32_t oso_idx;
692         CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx);
693         if (comp_unit_info)
694         {
695             SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
696             if (oso_dwarf)
697             {
698                 if (oso_dwarf->FindGlobalVariables(name, namespace_decl, true, max_matches, variables))
699                     if (variables.GetSize() > max_matches)
700                         break;
701             }
702         }
703     }
704     return variables.GetSize() - original_size;
705 }
706 
707 uint32_t
708 SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
709 {
710 
711     // If we aren't appending the results to this list, then clear the list
712     if (!append)
713         variables.Clear();
714 
715     // Remember how many variables are in the list before we search in case
716     // we are appending the results to a variable list.
717     const uint32_t original_size = variables.GetSize();
718 
719     uint32_t total_matches = 0;
720     SymbolFileDWARF *oso_dwarf;
721     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
722     {
723         const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name,
724                                                                      namespace_decl,
725                                                                      true,
726                                                                      max_matches,
727                                                                      variables);
728         if (oso_matches > 0)
729         {
730             total_matches += oso_matches;
731 
732             // Are we getting all matches?
733             if (max_matches == UINT32_MAX)
734                 continue;   // Yep, continue getting everything
735 
736             // If we have found enough matches, lets get out
737             if (max_matches >= total_matches)
738                 break;
739 
740             // Update the max matches for any subsequent calls to find globals
741             // in any other object files with DWARF
742             max_matches -= oso_matches;
743         }
744     }
745     // Return the number of variable that were appended to the list
746     return variables.GetSize() - original_size;
747 }
748 
749 
750 uint32_t
751 SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
752 {
753     // If we aren't appending the results to this list, then clear the list
754     if (!append)
755         variables.Clear();
756 
757     // Remember how many variables are in the list before we search in case
758     // we are appending the results to a variable list.
759     const uint32_t original_size = variables.GetSize();
760 
761     uint32_t total_matches = 0;
762     SymbolFileDWARF *oso_dwarf;
763     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
764     {
765         const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
766                                                                      true,
767                                                                      max_matches,
768                                                                      variables);
769         if (oso_matches > 0)
770         {
771             total_matches += oso_matches;
772 
773             // Are we getting all matches?
774             if (max_matches == UINT32_MAX)
775                 continue;   // Yep, continue getting everything
776 
777             // If we have found enough matches, lets get out
778             if (max_matches >= total_matches)
779                 break;
780 
781             // Update the max matches for any subsequent calls to find globals
782             // in any other object files with DWARF
783             max_matches -= oso_matches;
784         }
785     }
786     // Return the number of variable that were appended to the list
787     return variables.GetSize() - original_size;
788 }
789 
790 
791 int
792 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
793 {
794     const uint32_t symbol_idx = *symbol_idx_ptr;
795 
796     if (symbol_idx < comp_unit_info->first_symbol_index)
797         return -1;
798 
799     if (symbol_idx <= comp_unit_info->last_symbol_index)
800         return 0;
801 
802     return 1;
803 }
804 
805 
806 int
807 SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
808 {
809     const user_id_t symbol_id = *symbol_idx_ptr;
810 
811     if (symbol_id < comp_unit_info->so_symbol->GetID())
812         return -1;
813 
814     if (symbol_id <= comp_unit_info->last_symbol->GetID())
815         return 0;
816 
817     return 1;
818 }
819 
820 
821 SymbolFileDWARFDebugMap::CompileUnitInfo*
822 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr)
823 {
824     const uint32_t oso_index_count = m_compile_unit_infos.size();
825     CompileUnitInfo *comp_unit_info = NULL;
826     if (oso_index_count)
827     {
828         comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx,
829                                                    &m_compile_unit_infos[0],
830                                                    m_compile_unit_infos.size(),
831                                                    sizeof(CompileUnitInfo),
832                                                    (ComparisonFunction)SymbolContainsSymbolWithIndex);
833     }
834 
835     if (oso_idx_ptr)
836     {
837         if (comp_unit_info != NULL)
838             *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
839         else
840             *oso_idx_ptr = UINT32_MAX;
841     }
842     return comp_unit_info;
843 }
844 
845 SymbolFileDWARFDebugMap::CompileUnitInfo*
846 SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr)
847 {
848     const uint32_t oso_index_count = m_compile_unit_infos.size();
849     CompileUnitInfo *comp_unit_info = NULL;
850     if (oso_index_count)
851     {
852         comp_unit_info = (CompileUnitInfo*)::bsearch (&symbol_id,
853                                                       &m_compile_unit_infos[0],
854                                                       m_compile_unit_infos.size(),
855                                                       sizeof(CompileUnitInfo),
856                                                       (ComparisonFunction)SymbolContainsSymbolWithID);
857     }
858 
859     if (oso_idx_ptr)
860     {
861         if (comp_unit_info != NULL)
862             *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
863         else
864             *oso_idx_ptr = UINT32_MAX;
865     }
866     return comp_unit_info;
867 }
868 
869 
870 static void
871 RemoveFunctionsWithModuleNotEqualTo (const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx)
872 {
873     // We found functions in .o files. Not all functions in the .o files
874     // will have made it into the final output file. The ones that did
875     // make it into the final output file will have a section whose module
876     // matches the module from the ObjectFile for this SymbolFile. When
877     // the modules don't match, then we have something that was in a
878     // .o file, but doesn't map to anything in the final executable.
879     uint32_t i=start_idx;
880     while (i < sc_list.GetSize())
881     {
882         SymbolContext sc;
883         sc_list.GetContextAtIndex(i, sc);
884         if (sc.function)
885         {
886             const SectionSP section_sp (sc.function->GetAddressRange().GetBaseAddress().GetSection());
887             if (section_sp->GetModule() != module_sp)
888             {
889                 sc_list.RemoveContextAtIndex(i);
890                 continue;
891             }
892         }
893         ++i;
894     }
895 }
896 
897 uint32_t
898 SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
899 {
900     Timer scoped_timer (__PRETTY_FUNCTION__,
901                         "SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
902                         name.GetCString());
903 
904     uint32_t initial_size = 0;
905     if (append)
906         initial_size = sc_list.GetSize();
907     else
908         sc_list.Clear();
909 
910     uint32_t oso_idx = 0;
911     SymbolFileDWARF *oso_dwarf;
912     while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
913     {
914         uint32_t sc_idx = sc_list.GetSize();
915         if (oso_dwarf->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, true, sc_list))
916         {
917             RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
918         }
919     }
920 
921     return sc_list.GetSize() - initial_size;
922 }
923 
924 
925 uint32_t
926 SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
927 {
928     Timer scoped_timer (__PRETTY_FUNCTION__,
929                         "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
930                         regex.GetText());
931 
932     uint32_t initial_size = 0;
933     if (append)
934         initial_size = sc_list.GetSize();
935     else
936         sc_list.Clear();
937 
938     uint32_t oso_idx = 0;
939     SymbolFileDWARF *oso_dwarf;
940     while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
941     {
942         uint32_t sc_idx = sc_list.GetSize();
943 
944         if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list))
945         {
946             RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
947         }
948     }
949 
950     return sc_list.GetSize() - initial_size;
951 }
952 
953 TypeSP
954 SymbolFileDWARFDebugMap::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
955                                                    const DWARFDebugInfoEntry *die,
956                                                    const ConstString &type_name)
957 {
958     TypeSP type_sp;
959     SymbolFileDWARF *oso_dwarf;
960     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
961     {
962         type_sp = oso_dwarf->FindDefinitionTypeForDIE (cu, die, type_name);
963         if (type_sp)
964             break;
965     }
966     return type_sp;
967 }
968 
969 
970 
971 bool
972 SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso)
973 {
974     if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
975     {
976         m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
977         SymbolFileDWARF *oso_dwarf;
978         for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
979         {
980             if (skip_dwarf_oso != oso_dwarf && oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL))
981             {
982                 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
983                 break;
984             }
985         }
986     }
987     return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
988 }
989 
990 TypeSP
991 SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
992                                                                const ConstString &type_name,
993                                                                bool must_be_implementation)
994 {
995     TypeSP type_sp;
996     SymbolFileDWARF *oso_dwarf;
997     for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
998     {
999         type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation);
1000         if (type_sp)
1001             break;
1002     }
1003     return type_sp;
1004 }
1005 
1006 uint32_t
1007 SymbolFileDWARFDebugMap::FindTypes
1008 (
1009     const SymbolContext& sc,
1010     const ConstString &name,
1011     const ClangNamespaceDecl *namespace_decl,
1012     bool append,
1013     uint32_t max_matches,
1014     TypeList& types
1015 )
1016 {
1017     if (!append)
1018         types.Clear();
1019 
1020     const uint32_t initial_types_size = types.GetSize();
1021     SymbolFileDWARF *oso_dwarf;
1022 
1023     if (sc.comp_unit)
1024     {
1025         oso_dwarf = GetSymbolFile (sc);
1026         if (oso_dwarf)
1027             return oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
1028     }
1029     else
1030     {
1031         uint32_t oso_idx = 0;
1032         while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
1033             oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
1034     }
1035 
1036     return types.GetSize() - initial_types_size;
1037 }
1038 
1039 //
1040 //uint32_t
1041 //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)
1042 //{
1043 //  SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
1044 //  if (oso_dwarf)
1045 //      return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types);
1046 //  return 0;
1047 //}
1048 
1049 
1050 ClangNamespaceDecl
1051 SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc,
1052                                         const lldb_private::ConstString &name,
1053                                         const ClangNamespaceDecl *parent_namespace_decl)
1054 {
1055     ClangNamespaceDecl matching_namespace;
1056     SymbolFileDWARF *oso_dwarf;
1057 
1058     if (sc.comp_unit)
1059     {
1060         oso_dwarf = GetSymbolFile (sc);
1061         if (oso_dwarf)
1062             matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
1063     }
1064     else
1065     {
1066         for (uint32_t oso_idx = 0;
1067              ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL);
1068              ++oso_idx)
1069         {
1070             matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
1071 
1072             if (matching_namespace)
1073                 break;
1074         }
1075     }
1076 
1077     return matching_namespace;
1078 }
1079 
1080 //------------------------------------------------------------------
1081 // PluginInterface protocol
1082 //------------------------------------------------------------------
1083 const char *
1084 SymbolFileDWARFDebugMap::GetPluginName()
1085 {
1086     return "SymbolFileDWARFDebugMap";
1087 }
1088 
1089 const char *
1090 SymbolFileDWARFDebugMap::GetShortPluginName()
1091 {
1092     return GetPluginNameStatic();
1093 }
1094 
1095 uint32_t
1096 SymbolFileDWARFDebugMap::GetPluginVersion()
1097 {
1098     return 1;
1099 }
1100 
1101 void
1102 SymbolFileDWARFDebugMap::SetCompileUnit (SymbolFileDWARF *oso_dwarf, const CompUnitSP &cu_sp)
1103 {
1104     const uint32_t cu_count = GetNumCompileUnits();
1105     for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx)
1106     {
1107         if (m_compile_unit_infos[cu_idx].oso_symbol_vendor &&
1108             m_compile_unit_infos[cu_idx].oso_symbol_vendor->GetSymbolFile() == oso_dwarf)
1109         {
1110             if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp)
1111             {
1112                 assert (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == cu_sp.get());
1113             }
1114             else
1115             {
1116                 m_compile_unit_infos[cu_idx].oso_compile_unit_sp = cu_sp;
1117                 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1118             }
1119         }
1120     }
1121 }
1122 
1123 
1124 void
1125 SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl)
1126 {
1127     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1128     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1129     if (clang_type)
1130     {
1131         SymbolFileDWARF *oso_dwarf;
1132 
1133         for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1134         {
1135             if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1136             {
1137                 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1138                 return;
1139             }
1140         }
1141     }
1142 }
1143 
1144 void
1145 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
1146 {
1147     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1148     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1149     if (clang_type)
1150     {
1151         SymbolFileDWARF *oso_dwarf;
1152 
1153         for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1154         {
1155             if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1156             {
1157                 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1158                 return;
1159             }
1160         }
1161     }
1162 }
1163 
1164 bool
1165 SymbolFileDWARFDebugMap::LayoutRecordType (void *baton,
1166                                            const clang::RecordDecl *record_decl,
1167                                            uint64_t &size,
1168                                            uint64_t &alignment,
1169                                            llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
1170                                            llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
1171                                            llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
1172 {
1173     SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1174     SymbolFileDWARF *oso_dwarf;
1175     for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1176     {
1177         if (oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets))
1178             return true;
1179     }
1180     return false;
1181 }
1182 
1183 
1184 
1185 clang::DeclContext*
1186 SymbolFileDWARFDebugMap::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
1187 {
1188     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1189     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1190     if (oso_dwarf)
1191         return oso_dwarf->GetClangDeclContextContainingTypeUID (type_uid);
1192     return NULL;
1193 }
1194 
1195 clang::DeclContext*
1196 SymbolFileDWARFDebugMap::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1197 {
1198     const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1199     SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1200     if (oso_dwarf)
1201         return oso_dwarf->GetClangDeclContextForTypeUID (sc, type_uid);
1202     return NULL;
1203 }
1204 
1205 
1206