blob: 880d826bcd3764ce7a318a6dd9f1ce520481efa4 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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"
Greg Clayton6beaaa62011-01-17 03:46:26 +000018
19#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Symbol/ObjectFile.h"
21#include "lldb/Symbol/SymbolVendor.h"
22#include "lldb/Symbol/VariableList.h"
23
24#include "SymbolFileDWARF.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29void
30SymbolFileDWARFDebugMap::Initialize()
31{
32 PluginManager::RegisterPlugin (GetPluginNameStatic(),
33 GetPluginDescriptionStatic(),
34 CreateInstance);
35}
36
37void
38SymbolFileDWARFDebugMap::Terminate()
39{
40 PluginManager::UnregisterPlugin (CreateInstance);
41}
42
43
44const char *
45SymbolFileDWARFDebugMap::GetPluginNameStatic()
46{
47 return "symbol-file.dwarf2-debugmap";
48}
49
50const char *
51SymbolFileDWARFDebugMap::GetPluginDescriptionStatic()
52{
53 return "DWARF and DWARF3 debug symbol file reader (debug map).";
54}
55
56SymbolFile*
57SymbolFileDWARFDebugMap::CreateInstance (ObjectFile* obj_file)
58{
59 return new SymbolFileDWARFDebugMap (obj_file);
60}
61
62
63SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap (ObjectFile* ofile) :
64 SymbolFile(ofile),
65 m_flags(),
66 m_compile_unit_infos(),
67 m_func_indexes(),
68 m_glob_indexes()
69{
70}
71
72
73SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap()
74{
75}
76
Greg Clayton6beaaa62011-01-17 03:46:26 +000077void
78SymbolFileDWARFDebugMap::InitializeObject()
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000079{
Greg Clayton6beaaa62011-01-17 03:46:26 +000080 // Install our external AST source callbacks so we can complete Clang types.
81 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
82 new ClangExternalASTSourceCallbacks (SymbolFileDWARFDebugMap::CompleteTagDecl,
83 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl,
84 this));
85
86 GetClangASTContext().SetExternalSource (ast_source_ap);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000087}
88
Greg Clayton6beaaa62011-01-17 03:46:26 +000089
90
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091void
92SymbolFileDWARFDebugMap::InitOSO ()
93{
94 if (m_flags.test(kHaveInitializedOSOs))
95 return;
96
97 m_flags.set(kHaveInitializedOSOs);
98 // In order to get the abilities of this plug-in, we look at the list of
99 // N_OSO entries (object files) from the symbol table and make sure that
100 // these files exist and also contain valid DWARF. If we get any of that
101 // then we return the abilities of the first N_OSO's DWARF.
102
103 Symtab* symtab = m_obj_file->GetSymtab();
104 if (symtab)
105 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106 std::vector<uint32_t> oso_indexes;
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000107// StreamFile s(stdout);
108// symtab->Dump(&s, NULL, eSortOrderNone);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000110 // When a mach-o symbol is encoded, the n_type field is encoded in bits
111 // 23:16, and the n_desc field is encoded in bits 15:0.
112 //
113 // To find all N_OSO entries that are part of the DWARF + debug map
114 // we find only object file symbols with the flags value as follows:
115 // bits 23:16 == 0x66 (N_OSO)
116 // bits 15: 0 == 0x0001 (specifies this is a debug map object file)
117 const uint32_t k_oso_symbol_flags_value = 0x660001u;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000119 const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithTypeAndFlagsValue(eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120
121 if (oso_index_count > 0)
122 {
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000123 symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes);
124 symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes);
125
126 symtab->SortSymbolIndexesByValue(m_func_indexes, true);
127 symtab->SortSymbolIndexesByValue(m_glob_indexes, true);
128
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129 m_compile_unit_infos.resize(oso_index_count);
130// s.Printf("%s N_OSO symbols:\n", __PRETTY_FUNCTION__);
131// symtab->Dump(&s, oso_indexes);
132
133 for (uint32_t i=0; i<oso_index_count; ++i)
134 {
135 m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 1);
136 if (m_compile_unit_infos[i].so_symbol->GetSiblingIndex() == 0)
137 m_compile_unit_infos[i].so_symbol = symtab->SymbolAtIndex(oso_indexes[i] - 2);
138 m_compile_unit_infos[i].oso_symbol = symtab->SymbolAtIndex(oso_indexes[i]);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000139 uint32_t sibling_idx = m_compile_unit_infos[i].so_symbol->GetSiblingIndex();
140 assert (sibling_idx != 0);
141 assert (sibling_idx > i + 1);
142 m_compile_unit_infos[i].last_symbol = symtab->SymbolAtIndex (sibling_idx - 1);
143 m_compile_unit_infos[i].first_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].so_symbol);
144 m_compile_unit_infos[i].last_symbol_index = symtab->GetIndexForSymbol(m_compile_unit_infos[i].last_symbol);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 }
146 }
147 }
148}
149
150Module *
151SymbolFileDWARFDebugMap::GetModuleByOSOIndex (uint32_t oso_idx)
152{
153 const uint32_t cu_count = GetNumCompileUnits();
154 if (oso_idx < cu_count)
155 return GetModuleByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
156 return NULL;
157}
158
159Module *
160SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info)
161{
162 if (comp_unit_info->oso_module_sp.get() == NULL)
163 {
164 Symbol *oso_symbol = comp_unit_info->oso_symbol;
165 if (oso_symbol)
166 {
Greg Clayton274060b2010-10-20 20:54:39 +0000167 FileSpec oso_file_spec(oso_symbol->GetMangled().GetName().AsCString(), true);
Greg Clayton616f4902011-03-15 03:56:33 +0000168 // Don't allow cached .o files since we dress up each .o file with
169 // new sections. We want them to be in the module list so we can
170 // always find a shared pointer to the module (in Module::GetSP()),
171 // but just don't share them.
172 const bool always_create = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 ModuleList::GetSharedModule (oso_file_spec,
174 m_obj_file->GetModule()->GetArchitecture(),
Greg Clayton60830262011-02-04 18:53:10 +0000175 NULL, // lldb_private::UUID pointer
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176 NULL, // object name
177 0, // object offset
178 comp_unit_info->oso_module_sp,
179 NULL,
Greg Clayton616f4902011-03-15 03:56:33 +0000180 NULL,
181 always_create);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 }
183 }
184 return comp_unit_info->oso_module_sp.get();
185}
186
187
188bool
189SymbolFileDWARFDebugMap::GetFileSpecForSO (uint32_t oso_idx, FileSpec &file_spec)
190{
191 if (oso_idx < m_compile_unit_infos.size())
192 {
193 if (!m_compile_unit_infos[oso_idx].so_file)
194 {
195
196 if (m_compile_unit_infos[oso_idx].so_symbol == NULL)
197 return false;
198
199 std::string so_path (m_compile_unit_infos[oso_idx].so_symbol->GetMangled().GetName().AsCString());
200 if (m_compile_unit_infos[oso_idx].so_symbol[1].GetType() == eSymbolTypeSourceFile)
201 so_path += m_compile_unit_infos[oso_idx].so_symbol[1].GetMangled().GetName().AsCString();
Greg Clayton274060b2010-10-20 20:54:39 +0000202 m_compile_unit_infos[oso_idx].so_file.SetFile(so_path.c_str(), true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203 }
204 file_spec = m_compile_unit_infos[oso_idx].so_file;
205 return true;
206 }
207 return false;
208}
209
210
211
212ObjectFile *
213SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex (uint32_t oso_idx)
214{
215 Module *oso_module = GetModuleByOSOIndex (oso_idx);
216 if (oso_module)
217 return oso_module->GetObjectFile();
218 return NULL;
219}
220
221SymbolFileDWARF *
222SymbolFileDWARFDebugMap::GetSymbolFile (const SymbolContext& sc)
223{
224 CompileUnitInfo *comp_unit_info = GetCompUnitInfo (sc);
225 if (comp_unit_info)
226 return GetSymbolFileByCompUnitInfo (comp_unit_info);
227 return NULL;
228}
229
230ObjectFile *
231SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
232{
233 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info);
234 if (oso_module)
235 return oso_module->GetObjectFile();
236 return NULL;
237}
238
239SymbolFileDWARF *
240SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex (uint32_t oso_idx)
241{
242 if (oso_idx < m_compile_unit_infos.size())
243 return GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
244 return NULL;
245}
246
247SymbolFileDWARF *
248SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
249{
250 if (comp_unit_info->oso_symbol_vendor == NULL)
251 {
252 ObjectFile *oso_objfile = GetObjectFileByCompUnitInfo (comp_unit_info);
253
254 if (oso_objfile)
255 {
256 comp_unit_info->oso_symbol_vendor = oso_objfile->GetModule()->GetSymbolVendor();
257// SymbolFileDWARF *oso_dwarf = new SymbolFileDWARF(oso_objfile);
258// comp_unit_info->oso_dwarf_sp.reset (oso_dwarf);
259 if (comp_unit_info->oso_symbol_vendor)
260 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000261 // Set a a pointer to this class to set our OSO DWARF file know
262 // that the DWARF is being used along with a debug map and that
263 // it will have the remapped sections that we do below.
264 ((SymbolFileDWARF *)comp_unit_info->oso_symbol_vendor->GetSymbolFile())->SetDebugMapSymfile(this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 comp_unit_info->debug_map_sections_sp.reset(new SectionList);
266
267 Symtab *exe_symtab = m_obj_file->GetSymtab();
268 Module *oso_module = oso_objfile->GetModule();
269 Symtab *oso_symtab = oso_objfile->GetSymtab();
270//#define DEBUG_OSO_DMAP // Do not check in with this defined...
271#if defined(DEBUG_OSO_DMAP)
272 StreamFile s(stdout);
273 s << "OSO symtab:\n";
274 oso_symtab->Dump(&s, NULL);
275 s << "OSO sections before:\n";
276 oso_objfile->GetSectionList()->Dump(&s, NULL, true);
277#endif
278
279 ///const uint32_t fun_resolve_flags = SymbolContext::Module | eSymbolContextCompUnit | eSymbolContextFunction;
280 //SectionList *oso_sections = oso_objfile->Sections();
281 // Now we need to make sections that map from zero based object
282 // file addresses to where things eneded up in the main executable.
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000283 uint32_t oso_start_idx = exe_symtab->GetIndexForSymbol (comp_unit_info->oso_symbol);
284 assert (oso_start_idx != UINT32_MAX);
285 oso_start_idx += 1;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286 const uint32_t oso_end_idx = comp_unit_info->so_symbol->GetSiblingIndex();
287 uint32_t sect_id = 0x10000;
288 for (uint32_t idx = oso_start_idx; idx < oso_end_idx; ++idx)
289 {
290 Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx);
291 if (exe_symbol)
292 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000293 if (exe_symbol->IsDebug() == false)
294 continue;
295
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296 switch (exe_symbol->GetType())
297 {
Greg Clayton7a5388b2011-03-20 04:57:14 +0000298 default:
299 break;
300
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000301 case eSymbolTypeCode:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000302 {
303 // For each N_FUN, or function that we run into in the debug map
304 // we make a new section that we add to the sections found in the
305 // .o file. This new section has the file address set to what the
306 // addresses are in the .o file, and the load address is adjusted
307 // to match where it ended up in the final executable! We do this
308 // before we parse any dwarf info so that when it goes get parsed
309 // all section/offset addresses that get registered will resolve
310 // correctly to the new addresses in the main executable.
311
312 // First we find the original symbol in the .o file's symbol table
Greg Clayton65e364e2010-12-07 07:37:38 +0000313 Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), eSymbolTypeCode, Symtab::eDebugNo, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314 if (oso_fun_symbol)
315 {
316 // If we found the symbol, then we
317 Section* exe_fun_section = const_cast<Section *>(exe_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
318 Section* oso_fun_section = const_cast<Section *>(oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
319 if (oso_fun_section)
320 {
321 // Now we create a section that we will add as a child of the
322 // section in which the .o symbol (the N_FUN) exists.
323
324 // We use the exe_symbol size because the one in the .o file
325 // will just be a symbol with no size, and the exe_symbol
326 // size will reflect any size changes (ppc has been known to
327 // shrink function sizes when it gets rid of jump islands that
328 // aren't needed anymore).
329 SectionSP oso_fun_section_sp (new Section (const_cast<Section *>(oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()),
330 oso_module, // Module (the .o file)
331 sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs
Greg Clayton65e364e2010-12-07 07:37:38 +0000332 exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated!
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 eSectionTypeDebug,
334 oso_fun_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), // File VM address offset in the current section
335 exe_symbol->GetByteSize(), // File size (we need the size from the executable)
336 0, 0, 0));
337
338 oso_fun_section_sp->SetLinkedLocation (exe_fun_section,
339 exe_symbol->GetValue().GetFileAddress() - exe_fun_section->GetFileAddress());
340 oso_fun_section->GetChildren().AddSection(oso_fun_section_sp);
341 comp_unit_info->debug_map_sections_sp->AddSection(oso_fun_section_sp);
342 }
343 }
344 }
345 break;
346
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000347 case eSymbolTypeData:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000348 {
349 // For each N_GSYM we remap the address for the global by making
350 // a new section that we add to the sections found in the .o file.
351 // This new section has the file address set to what the
352 // addresses are in the .o file, and the load address is adjusted
353 // to match where it ended up in the final executable! We do this
354 // before we parse any dwarf info so that when it goes get parsed
355 // all section/offset addresses that get registered will resolve
356 // correctly to the new addresses in the main executable. We
357 // initially set the section size to be 1 byte, but will need to
358 // fix up these addresses further after all globals have been
359 // parsed to span the gaps, or we can find the global variable
360 // sizes from the DWARF info as we are parsing.
361
362#if 0
363 // First we find the non-stab entry that corresponds to the N_GSYM in the executable
Greg Clayton65e364e2010-12-07 07:37:38 +0000364 Symbol *exe_gsym_symbol = exe_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365#else
366 // The mach-o object file parser already matches up the N_GSYM with with the non-stab
367 // entry, so we shouldn't have to do that. If this ever changes, enable the code above
368 // in the "#if 0" block. STSYM's always match the symbol as found below.
369 Symbol *exe_gsym_symbol = exe_symbol;
370#endif
371 // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000372 Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeData, Symtab::eDebugNo, Symtab::eVisibilityAny);
Greg Clayton70120492011-02-08 02:40:32 +0000373 if (exe_gsym_symbol && oso_gsym_symbol && exe_gsym_symbol->GetAddressRangePtr() && oso_gsym_symbol->GetAddressRangePtr())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 {
375 // If we found the symbol, then we
376 Section* exe_gsym_section = const_cast<Section *>(exe_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
377 Section* oso_gsym_section = const_cast<Section *>(oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
378 if (oso_gsym_section)
379 {
380 SectionSP oso_gsym_section_sp (new Section (const_cast<Section *>(oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection()),
381 oso_module, // Module (the .o file)
382 sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs
Greg Clayton65e364e2010-12-07 07:37:38 +0000383 exe_symbol->GetMangled().GetName(Mangled::ePreferMangled), // Name the section the same as the symbol for which is was generated!
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 eSectionTypeDebug,
385 oso_gsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), // File VM address offset in the current section
386 1, // We don't know the size of the global, just do the main address for now.
387 0, 0, 0));
388
389 oso_gsym_section_sp->SetLinkedLocation (exe_gsym_section,
390 exe_gsym_symbol->GetValue().GetFileAddress() - exe_gsym_section->GetFileAddress());
391 oso_gsym_section->GetChildren().AddSection(oso_gsym_section_sp);
392 comp_unit_info->debug_map_sections_sp->AddSection(oso_gsym_section_sp);
393 }
394 }
395 }
396 break;
397
398// case eSymbolTypeStatic:
399// {
400// // For each N_STSYM we remap the address for the global by making
401// // a new section that we add to the sections found in the .o file.
402// // This new section has the file address set to what the
403// // addresses are in the .o file, and the load address is adjusted
404// // to match where it ended up in the final executable! We do this
405// // before we parse any dwarf info so that when it goes get parsed
406// // all section/offset addresses that get registered will resolve
407// // correctly to the new addresses in the main executable. We
408// // initially set the section size to be 1 byte, but will need to
409// // fix up these addresses further after all globals have been
410// // parsed to span the gaps, or we can find the global variable
411// // sizes from the DWARF info as we are parsing.
412//
413//
414// Symbol *exe_stsym_symbol = exe_symbol;
415// // First we find the non-stab entry that corresponds to the N_STSYM in the .o file
416// Symbol *oso_stsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType(exe_symbol->GetMangled().GetName(), eSymbolTypeData);
417// if (exe_stsym_symbol && oso_stsym_symbol)
418// {
419// // If we found the symbol, then we
420// Section* exe_stsym_section = const_cast<Section *>(exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
421// Section* oso_stsym_section = const_cast<Section *>(oso_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection());
422// if (oso_stsym_section)
423// {
424// // The load address of the symbol will use the section in the
425// // executable that contains the debug map that corresponds to
426// // the N_FUN symbol. We set the offset to reflect the offset
427// // into that section since we are creating a new section.
428// AddressRange stsym_load_range(exe_stsym_section, exe_stsym_symbol->GetValue().GetFileAddress() - exe_stsym_section->GetFileAddress(), 1);
429// // We need the symbol's section offset address from the .o file, but
430// // we need a non-zero size.
431// AddressRange stsym_file_range(exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetSection(), exe_stsym_symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(), 1);
432//
433// // Now we create a section that we will add as a child of the
434// // section in which the .o symbol (the N_FUN) exists.
435//
436//// TODO: mimic what I did for N_FUN if that works...
437//// // We use the 1 byte for the size because we don't know the
438//// // size of the global symbol without seeing the DWARF.
439//// SectionSP oso_fun_section_sp (new Section ( NULL, oso_module, // Module (the .o file)
440//// sect_id++, // Section ID starts at 0x10000 and increments so the section IDs don't overlap with the standard mach IDs
441//// exe_symbol->GetMangled().GetName(),// Name the section the same as the symbol for which is was generated!
442//// // &stsym_load_range, // Load offset is the offset into the executable section for the N_FUN from the debug map
443//// &stsym_file_range, // File section/offset is just the same os the symbol on the .o file
444//// 0, 0, 0));
445////
446//// // Now we add the new section to the .o file's sections as a child
447//// // of the section in which the N_SECT symbol exists.
448//// oso_stsym_section->GetChildren().AddSection(oso_fun_section_sp);
449//// comp_unit_info->debug_map_sections_sp->AddSection(oso_fun_section_sp);
450// }
451// }
452// }
453// break;
454 }
455 }
456 }
457#if defined(DEBUG_OSO_DMAP)
458 s << "OSO sections after:\n";
459 oso_objfile->GetSectionList()->Dump(&s, NULL, true);
460#endif
461 }
462 }
463 }
464 if (comp_unit_info->oso_symbol_vendor)
465 return (SymbolFileDWARF *)comp_unit_info->oso_symbol_vendor->GetSymbolFile();
466 return NULL;
467}
468
469uint32_t
470SymbolFileDWARFDebugMap::GetAbilities ()
471{
472 // In order to get the abilities of this plug-in, we look at the list of
473 // N_OSO entries (object files) from the symbol table and make sure that
474 // these files exist and also contain valid DWARF. If we get any of that
475 // then we return the abilities of the first N_OSO's DWARF.
476
477 const uint32_t oso_index_count = GetNumCompileUnits();
478 if (oso_index_count > 0)
479 {
480 const uint32_t dwarf_abilities = SymbolFile::CompileUnits |
481 SymbolFile::Functions |
482 SymbolFile::Blocks |
483 SymbolFile::GlobalVariables |
484 SymbolFile::LocalVariables |
485 SymbolFile::VariableTypes |
486 SymbolFile::LineTables;
487
488 for (uint32_t oso_idx=0; oso_idx<oso_index_count; ++oso_idx)
489 {
490 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
491 if (oso_dwarf)
492 {
493 uint32_t oso_abilities = oso_dwarf->GetAbilities();
494 if ((oso_abilities & dwarf_abilities) == dwarf_abilities)
495 return oso_abilities;
496 }
497 }
498 }
499 return 0;
500}
501
502uint32_t
503SymbolFileDWARFDebugMap::GetNumCompileUnits()
504{
505 InitOSO ();
506 return m_compile_unit_infos.size();
507}
508
509
510CompUnitSP
511SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx)
512{
513 CompUnitSP comp_unit_sp;
514 const uint32_t cu_count = GetNumCompileUnits();
515
516 if (cu_idx < cu_count)
517 {
518 if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL)
519 {
520 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (cu_idx);
521 if (oso_dwarf)
522 {
523 // There is only one compile unit for N_OSO entry right now, so
524 // it will always exist at index zero.
525 m_compile_unit_infos[cu_idx].oso_compile_unit_sp = m_compile_unit_infos[cu_idx].oso_symbol_vendor->GetCompileUnitAtIndex (0);
526 }
527
528 if (m_compile_unit_infos[cu_idx].oso_compile_unit_sp.get() == NULL)
529 {
530 // We weren't able to get the DWARF for this N_OSO entry (the
531 // .o file may be missing or not at the specified path), make
532 // one up as best we can from the debug map. We set the uid
533 // of the compile unit to the symbol index with the MSBit set
534 // so that it doesn't collide with any uid values from the DWARF
535 Symbol *so_symbol = m_compile_unit_infos[cu_idx].so_symbol;
536 if (so_symbol)
537 {
538 m_compile_unit_infos[cu_idx].oso_compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
539 NULL,
540 so_symbol->GetMangled().GetName().AsCString(),
541 cu_idx,
Greg Clayton9e409562010-07-28 02:04:09 +0000542 eLanguageTypeUnknown));
Greg Clayton450e3f32010-10-12 02:24:53 +0000543
544 // Let our symbol vendor know about this compile unit
545 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex (m_compile_unit_infos[cu_idx].oso_compile_unit_sp,
546 cu_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547 }
548 }
549 }
550 comp_unit_sp = m_compile_unit_infos[cu_idx].oso_compile_unit_sp;
551 }
552
553 return comp_unit_sp;
554}
555
556SymbolFileDWARFDebugMap::CompileUnitInfo *
557SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc)
558{
559 const uint32_t cu_count = GetNumCompileUnits();
560 for (uint32_t i=0; i<cu_count; ++i)
561 {
562 if (sc.comp_unit == m_compile_unit_infos[i].oso_compile_unit_sp.get())
563 return &m_compile_unit_infos[i];
564 }
565 return NULL;
566}
567
568size_t
569SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc)
570{
571 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
572 if (oso_dwarf)
573 return oso_dwarf->ParseCompileUnitFunctions (sc);
574 return 0;
575}
576
577bool
578SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc)
579{
580 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
581 if (oso_dwarf)
582 return oso_dwarf->ParseCompileUnitLineTable (sc);
583 return false;
584}
585
586bool
587SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files)
588{
589 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
590 if (oso_dwarf)
591 return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files);
592 return false;
593}
594
595
596size_t
597SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc)
598{
599 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
600 if (oso_dwarf)
601 return oso_dwarf->ParseFunctionBlocks (sc);
602 return 0;
603}
604
605
606size_t
607SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc)
608{
609 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
610 if (oso_dwarf)
611 return oso_dwarf->ParseTypes (sc);
612 return 0;
613}
614
615
616size_t
617SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc)
618{
619 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
620 if (oso_dwarf)
621 return oso_dwarf->ParseTypes (sc);
622 return 0;
623}
624
625
626
627Type*
628SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid)
629{
630 return NULL;
631}
632
Greg Clayton1be10fc2010-09-29 01:12:09 +0000633lldb::clang_type_t
634SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_Type)
635{
636 // We have a struct/union/class/enum that needs to be fully resolved.
637 return NULL;
638}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639
640uint32_t
641SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc)
642{
643 uint32_t resolved_flags = 0;
644 Symtab* symtab = m_obj_file->GetSymtab();
645 if (symtab)
646 {
647 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
648 sc.symbol = symtab->FindSymbolContainingFileAddress (exe_file_addr, &m_func_indexes[0], m_func_indexes.size());
649
650 if (sc.symbol != NULL)
651 {
652 resolved_flags |= eSymbolContextSymbol;
653
654 uint32_t oso_idx = 0;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000655 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 if (comp_unit_info)
657 {
658 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
659 ObjectFile *oso_objfile = GetObjectFileByOSOIndex (oso_idx);
660 if (oso_dwarf && oso_objfile)
661 {
662 SectionList *oso_section_list = oso_objfile->GetSectionList();
663
Greg Clayton016a95e2010-09-14 02:20:48 +0000664 SectionSP oso_symbol_section_sp (oso_section_list->FindSectionContainingLinkedFileAddress (exe_file_addr, UINT32_MAX));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665
Greg Clayton016a95e2010-09-14 02:20:48 +0000666 if (oso_symbol_section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 {
Greg Clayton016a95e2010-09-14 02:20:48 +0000668 const addr_t linked_file_addr = oso_symbol_section_sp->GetLinkedFileAddress();
669 Address oso_so_addr (oso_symbol_section_sp.get(), exe_file_addr - linked_file_addr);
670 if (oso_so_addr.IsSectionOffset())
671 resolved_flags |= oso_dwarf->ResolveSymbolContext (oso_so_addr, resolve_scope, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673 }
674 }
675 }
676 }
677 return resolved_flags;
678}
679
680
681uint32_t
682SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
683{
684 uint32_t initial = sc_list.GetSize();
685 const uint32_t cu_count = GetNumCompileUnits();
686
687 FileSpec so_file_spec;
688 for (uint32_t i=0; i<cu_count; ++i)
689 {
690 if (GetFileSpecForSO (i, so_file_spec))
691 {
692 // By passing false to the comparison we will be able to match
693 // and files given a filename only. If both file_spec and
694 // so_file_spec have directories, we will still do a full match.
695 if (FileSpec::Compare (file_spec, so_file_spec, false) == 0)
696 {
697 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i);
698
699 oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
700 }
701 }
702 }
703 return sc_list.GetSize() - initial;
704}
705
706uint32_t
707SymbolFileDWARFDebugMap::PrivateFindGlobalVariables
708(
709 const ConstString &name,
710 const std::vector<uint32_t> &indexes, // Indexes into the symbol table that match "name"
711 uint32_t max_matches,
712 VariableList& variables
713)
714{
715 const uint32_t original_size = variables.GetSize();
716 const size_t match_count = indexes.size();
717 for (size_t i=0; i<match_count; ++i)
718 {
719 uint32_t oso_idx;
720 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx);
721 if (comp_unit_info)
722 {
723 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
724 if (oso_dwarf)
725 {
726 if (oso_dwarf->FindGlobalVariables(name, true, max_matches, variables))
727 if (variables.GetSize() > max_matches)
728 break;
729 }
730 }
731 }
732 return variables.GetSize() - original_size;
733}
734
735uint32_t
736SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
737{
738
739 // If we aren't appending the results to this list, then clear the list
740 if (!append)
741 variables.Clear();
742
743 // Remember how many variables are in the list before we search in case
744 // we are appending the results to a variable list.
745 const uint32_t original_size = variables.GetSize();
746
Greg Claytonba2d22d2010-11-13 22:57:37 +0000747 uint32_t total_matches = 0;
748 SymbolFileDWARF *oso_dwarf;
749 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 {
Greg Claytonba2d22d2010-11-13 22:57:37 +0000751 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name,
752 true,
753 max_matches,
754 variables);
755 if (oso_matches > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 {
Greg Claytonba2d22d2010-11-13 22:57:37 +0000757 total_matches += oso_matches;
758
759 // Are we getting all matches?
760 if (max_matches == UINT32_MAX)
761 continue; // Yep, continue getting everything
762
763 // If we have found enough matches, lets get out
764 if (max_matches >= total_matches)
765 break;
766
767 // Update the max matches for any subsequent calls to find globals
768 // in any other object files with DWARF
769 max_matches -= oso_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771 }
772 // Return the number of variable that were appended to the list
773 return variables.GetSize() - original_size;
774}
775
776
777uint32_t
778SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
779{
Greg Claytonba2d22d2010-11-13 22:57:37 +0000780 // If we aren't appending the results to this list, then clear the list
781 if (!append)
782 variables.Clear();
783
784 // Remember how many variables are in the list before we search in case
785 // we are appending the results to a variable list.
786 const uint32_t original_size = variables.GetSize();
787
788 uint32_t total_matches = 0;
789 SymbolFileDWARF *oso_dwarf;
790 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
791 {
792 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
793 true,
794 max_matches,
795 variables);
796 if (oso_matches > 0)
797 {
798 total_matches += oso_matches;
799
800 // Are we getting all matches?
801 if (max_matches == UINT32_MAX)
802 continue; // Yep, continue getting everything
803
804 // If we have found enough matches, lets get out
805 if (max_matches >= total_matches)
806 break;
807
808 // Update the max matches for any subsequent calls to find globals
809 // in any other object files with DWARF
810 max_matches -= oso_matches;
811 }
812 }
813 // Return the number of variable that were appended to the list
814 return variables.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815}
816
817
818int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000819SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820{
821 const uint32_t symbol_idx = *symbol_idx_ptr;
822
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000823 if (symbol_idx < comp_unit_info->first_symbol_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 return -1;
825
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000826 if (symbol_idx <= comp_unit_info->last_symbol_index)
827 return 0;
828
829 return 1;
830}
831
832
833int
834SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
835{
836 const user_id_t symbol_id = *symbol_idx_ptr;
837
838 if (symbol_id < comp_unit_info->so_symbol->GetID())
839 return -1;
840
841 if (symbol_id <= comp_unit_info->last_symbol->GetID())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000842 return 0;
843
844 return 1;
845}
846
847
848SymbolFileDWARFDebugMap::CompileUnitInfo*
849SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr)
850{
851 const uint32_t oso_index_count = m_compile_unit_infos.size();
852 CompileUnitInfo *comp_unit_info = NULL;
853 if (oso_index_count)
854 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000855 comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx, &m_compile_unit_infos[0], m_compile_unit_infos.size(), sizeof(CompileUnitInfo), (comparison_function)SymbolContainsSymbolWithIndex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000856 }
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
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000868SymbolFileDWARFDebugMap::CompileUnitInfo*
869SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr)
870{
871 const uint32_t oso_index_count = m_compile_unit_infos.size();
872 CompileUnitInfo *comp_unit_info = NULL;
873 if (oso_index_count)
874 {
875 comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_id, &m_compile_unit_infos[0], m_compile_unit_infos.size(), sizeof(CompileUnitInfo), (comparison_function)SymbolContainsSymbolWithID);
876 }
877
878 if (oso_idx_ptr)
879 {
880 if (comp_unit_info != NULL)
881 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
882 else
883 *oso_idx_ptr = UINT32_MAX;
884 }
885 return comp_unit_info;
886}
887
888
Greg Clayton3ef3fc62010-08-17 23:16:15 +0000889static void
890RemoveFunctionsWithModuleNotEqualTo (Module *module, SymbolContextList &sc_list, uint32_t start_idx)
891{
892 // We found functions in .o files. Not all functions in the .o files
893 // will have made it into the final output file. The ones that did
894 // make it into the final output file will have a section whose module
895 // matches the module from the ObjectFile for this SymbolFile. When
896 // the modules don't match, then we have something that was in a
897 // .o file, but doesn't map to anything in the final executable.
898 uint32_t i=start_idx;
899 while (i < sc_list.GetSize())
900 {
901 SymbolContext sc;
902 sc_list.GetContextAtIndex(i, sc);
903 if (sc.function)
904 {
905 const Section *section = sc.function->GetAddressRange().GetBaseAddress().GetSection();
906 if (section->GetModule() != module)
907 {
908 sc_list.RemoveContextAtIndex(i);
909 continue;
910 }
911 }
912 ++i;
913 }
914}
915
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916uint32_t
Greg Clayton0c5cd902010-06-28 21:30:43 +0000917SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, uint32_t name_type_mask, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000918{
919 Timer scoped_timer (__PRETTY_FUNCTION__,
920 "SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
921 name.GetCString());
922
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000923 uint32_t initial_size = 0;
924 if (append)
925 initial_size = sc_list.GetSize();
926 else
927 sc_list.Clear();
928
Greg Clayton57a6b992010-08-17 00:35:34 +0000929 uint32_t oso_idx = 0;
930 SymbolFileDWARF *oso_dwarf;
931 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932 {
Greg Clayton3ef3fc62010-08-17 23:16:15 +0000933 uint32_t sc_idx = sc_list.GetSize();
934 if (oso_dwarf->FindFunctions(name, name_type_mask, true, sc_list))
935 {
936 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
937 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938 }
939
940 return sc_list.GetSize() - initial_size;
941}
942
943
944uint32_t
945SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool append, SymbolContextList& sc_list)
946{
947 Timer scoped_timer (__PRETTY_FUNCTION__,
948 "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
949 regex.GetText());
950
Greg Clayton57a6b992010-08-17 00:35:34 +0000951 uint32_t initial_size = 0;
952 if (append)
953 initial_size = sc_list.GetSize();
954 else
955 sc_list.Clear();
956
957 uint32_t oso_idx = 0;
958 SymbolFileDWARF *oso_dwarf;
959 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
960 {
Greg Clayton3ef3fc62010-08-17 23:16:15 +0000961 uint32_t sc_idx = sc_list.GetSize();
962
963 if (oso_dwarf->FindFunctions(regex, true, sc_list))
964 {
965 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
966 }
Greg Clayton57a6b992010-08-17 00:35:34 +0000967 }
968
969 return sc_list.GetSize() - initial_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000970}
971
Greg Clayton2ccf8cf2010-11-07 21:02:03 +0000972TypeSP
973SymbolFileDWARFDebugMap::FindDefinitionTypeForDIE (
974 DWARFCompileUnit* cu,
975 const DWARFDebugInfoEntry *die,
976 const ConstString &type_name
977)
978{
979 TypeSP type_sp;
980 SymbolFileDWARF *oso_dwarf;
981 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
982 {
983 type_sp = oso_dwarf->FindDefinitionTypeForDIE (cu, die, type_name);
984 if (type_sp)
985 break;
986 }
987 return type_sp;
988}
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000989
990uint32_t
Greg Clayton6dbd3982010-09-15 05:51:24 +0000991SymbolFileDWARFDebugMap::FindTypes
992(
993 const SymbolContext& sc,
994 const ConstString &name,
995 bool append,
996 uint32_t max_matches,
997 TypeList& types
998)
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000999{
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001000 if (!append)
1001 types.Clear();
Greg Clayton6dbd3982010-09-15 05:51:24 +00001002
1003 const uint32_t initial_types_size = types.GetSize();
1004 SymbolFileDWARF *oso_dwarf;
1005
1006 if (sc.comp_unit)
1007 {
1008 oso_dwarf = GetSymbolFile (sc);
1009 if (oso_dwarf)
1010 return oso_dwarf->FindTypes (sc, name, append, max_matches, types);
1011 }
1012 else
1013 {
1014 uint32_t oso_idx = 0;
1015 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
1016 oso_dwarf->FindTypes (sc, name, append, max_matches, types);
1017 }
1018
1019 return types.GetSize() - initial_types_size;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001020}
1021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001022//
1023//uint32_t
1024//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)
1025//{
1026// SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
1027// if (oso_dwarf)
1028// return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types);
1029// return 0;
1030//}
1031
Greg Clayton96d7d742010-11-10 23:42:09 +00001032
Greg Clayton526e5af2010-11-13 03:52:47 +00001033ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00001034SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc,
1035 const lldb_private::ConstString &name)
1036{
Greg Clayton526e5af2010-11-13 03:52:47 +00001037 ClangNamespaceDecl matching_namespace;
Greg Clayton96d7d742010-11-10 23:42:09 +00001038 SymbolFileDWARF *oso_dwarf;
1039
1040 if (sc.comp_unit)
1041 {
1042 oso_dwarf = GetSymbolFile (sc);
1043 if (oso_dwarf)
1044 matching_namespace = oso_dwarf->FindNamespace (sc, name);
1045 }
1046 else
1047 {
1048 for (uint32_t oso_idx = 0;
1049 ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL);
1050 ++oso_idx)
1051 {
1052 matching_namespace = oso_dwarf->FindNamespace (sc, name);
1053
1054 if (matching_namespace)
1055 break;
1056 }
1057 }
1058
1059 return matching_namespace;
1060}
1061
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001062//------------------------------------------------------------------
1063// PluginInterface protocol
1064//------------------------------------------------------------------
1065const char *
1066SymbolFileDWARFDebugMap::GetPluginName()
1067{
1068 return "SymbolFileDWARFDebugMap";
1069}
1070
1071const char *
1072SymbolFileDWARFDebugMap::GetShortPluginName()
1073{
1074 return GetPluginNameStatic();
1075}
1076
1077uint32_t
1078SymbolFileDWARFDebugMap::GetPluginVersion()
1079{
1080 return 1;
1081}
1082
1083void
Greg Clayton450e3f32010-10-12 02:24:53 +00001084SymbolFileDWARFDebugMap::SetCompileUnit (SymbolFileDWARF *oso_dwarf, const CompUnitSP &cu_sp)
1085{
1086 const uint32_t cu_count = GetNumCompileUnits();
1087 for (uint32_t i=0; i<cu_count; ++i)
1088 {
1089 if (m_compile_unit_infos[i].oso_symbol_vendor &&
1090 m_compile_unit_infos[i].oso_symbol_vendor->GetSymbolFile() == oso_dwarf)
1091 {
1092 if (m_compile_unit_infos[i].oso_compile_unit_sp)
1093 {
1094 assert (m_compile_unit_infos[i].oso_compile_unit_sp.get() == cu_sp.get());
1095 }
1096 else
1097 {
1098 m_compile_unit_infos[i].oso_compile_unit_sp = cu_sp;
1099 }
1100 }
1101 }
1102}
1103
Greg Clayton6beaaa62011-01-17 03:46:26 +00001104
1105void
1106SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl)
1107{
1108 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1109 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1110 if (clang_type)
1111 {
1112 SymbolFileDWARF *oso_dwarf;
1113
1114 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1115 {
1116 if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1117 {
1118 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1119 return;
1120 }
1121 }
1122 }
1123}
1124
1125void
1126SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
1127{
1128 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1129 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1130 if (clang_type)
1131 {
1132 SymbolFileDWARF *oso_dwarf;
1133
1134 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1135 {
1136 if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1137 {
1138 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1139 return;
1140 }
1141 }
1142 }
1143}
1144