blob: 5efda2aca1ac66e3aa9db8874a6abda02f34d90d [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"
Greg Clayton1f746072012-08-29 21:13:06 +000016#include "lldb/Core/Section.h"
Greg Clayton9422dd62013-03-04 21:46:16 +000017
18//#define DEBUG_OSO_DMAP // DO NOT CHECKIN WITH THIS NOT COMMENTED OUT
Greg Clayton1f746072012-08-29 21:13:06 +000019#if defined(DEBUG_OSO_DMAP)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/StreamFile.h"
Greg Clayton1f746072012-08-29 21:13:06 +000021#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Timer.h"
Greg Clayton6beaaa62011-01-17 03:46:26 +000023
24#include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Symbol/CompileUnit.h"
Greg Clayton9422dd62013-03-04 21:46:16 +000026#include "lldb/Symbol/LineTable.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Symbol/ObjectFile.h"
28#include "lldb/Symbol/SymbolVendor.h"
29#include "lldb/Symbol/VariableList.h"
30
Sean Callanan60217122012-04-13 00:10:03 +000031#include "LogChannelDWARF.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "SymbolFileDWARF.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
Greg Clayton1f746072012-08-29 21:13:06 +000037// Subclass lldb_private::Module so we can intercept the "Module::GetObjectFile()"
38// (so we can fixup the object file sections) and also for "Module::GetSymbolVendor()"
39// (so we can fixup the symbol file id.
40
Greg Clayton9422dd62013-03-04 21:46:16 +000041
42
43
44const SymbolFileDWARFDebugMap::FileRangeMap &
45SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile)
46{
47 if (file_range_map_valid)
48 return file_range_map;
49
50 file_range_map_valid = true;
51
52 Module *oso_module = exe_symfile->GetModuleByCompUnitInfo (this);
53 ObjectFile *oso_objfile = oso_module->GetObjectFile();
54
55 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_MAP));
56 if (log)
57 {
58 ConstString object_name (oso_module->GetObjectName());
59 log->Printf("%p: SymbolFileDWARFDebugMap::CompileUnitInfo::GetFileRangeMap ('%s/%s%s%s%s')",
60 this,
61 oso_module->GetFileSpec().GetDirectory().GetCString(),
62 oso_module->GetFileSpec().GetFilename().GetCString(),
63 object_name ? "(" : "",
64 object_name ? object_name.GetCString() : "",
65 object_name ? ")" : "");
66 }
67
68
69 std::vector<SymbolFileDWARFDebugMap::CompileUnitInfo *> cu_infos;
70 if (exe_symfile->GetCompUnitInfosForModule(oso_module, cu_infos))
71 {
72 for (auto comp_unit_info : cu_infos)
73 {
74 Symtab *exe_symtab = exe_symfile->GetObjectFile()->GetSymtab();
75 ModuleSP oso_module_sp (oso_objfile->GetModule());
76 Symtab *oso_symtab = oso_objfile->GetSymtab();
Greg Clayton9422dd62013-03-04 21:46:16 +000077
78 ///const uint32_t fun_resolve_flags = SymbolContext::Module | eSymbolContextCompUnit | eSymbolContextFunction;
79 //SectionList *oso_sections = oso_objfile->Sections();
80 // Now we need to make sections that map from zero based object
81 // file addresses to where things eneded up in the main executable.
82
83 assert (comp_unit_info->first_symbol_index != UINT32_MAX);
84 // End index is one past the last valid symbol index
85 const uint32_t oso_end_idx = comp_unit_info->last_symbol_index + 1;
86 for (uint32_t idx = comp_unit_info->first_symbol_index + 2; // Skip the N_SO and N_OSO
87 idx < oso_end_idx;
88 ++idx)
89 {
90 Symbol *exe_symbol = exe_symtab->SymbolAtIndex(idx);
91 if (exe_symbol)
92 {
93 if (exe_symbol->IsDebug() == false)
94 continue;
95
96 switch (exe_symbol->GetType())
97 {
98 default:
99 break;
100
101 case eSymbolTypeCode:
102 {
103 // For each N_FUN, or function that we run into in the debug map
104 // we make a new section that we add to the sections found in the
105 // .o file. This new section has the file address set to what the
106 // addresses are in the .o file, and the load address is adjusted
107 // to match where it ended up in the final executable! We do this
108 // before we parse any dwarf info so that when it goes get parsed
109 // all section/offset addresses that get registered will resolve
110 // correctly to the new addresses in the main executable.
111
112 // First we find the original symbol in the .o file's symbol table
113 Symbol *oso_fun_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(Mangled::ePreferMangled),
114 eSymbolTypeCode,
115 Symtab::eDebugNo,
116 Symtab::eVisibilityAny);
117 if (oso_fun_symbol)
118 {
119 // Add the inverse OSO file address to debug map entry mapping
120 exe_symfile->AddOSOFileRange (this,
121 exe_symbol->GetAddress().GetFileAddress(),
122 oso_fun_symbol->GetAddress().GetFileAddress(),
123 std::min<addr_t>(exe_symbol->GetByteSize(), oso_fun_symbol->GetByteSize()));
124
125 }
126 }
127 break;
128
129 case eSymbolTypeData:
130 {
131 // For each N_GSYM we remap the address for the global by making
132 // a new section that we add to the sections found in the .o file.
133 // This new section has the file address set to what the
134 // addresses are in the .o file, and the load address is adjusted
135 // to match where it ended up in the final executable! We do this
136 // before we parse any dwarf info so that when it goes get parsed
137 // all section/offset addresses that get registered will resolve
138 // correctly to the new addresses in the main executable. We
139 // initially set the section size to be 1 byte, but will need to
140 // fix up these addresses further after all globals have been
141 // parsed to span the gaps, or we can find the global variable
142 // sizes from the DWARF info as we are parsing.
143
144 // Next we find the non-stab entry that corresponds to the N_GSYM in the .o file
145 Symbol *oso_gsym_symbol = oso_symtab->FindFirstSymbolWithNameAndType (exe_symbol->GetMangled().GetName(Mangled::ePreferMangled),
146 eSymbolTypeData,
147 Symtab::eDebugNo,
148 Symtab::eVisibilityAny);
149
150 if (exe_symbol && oso_gsym_symbol &&
151 exe_symbol->ValueIsAddress() &&
152 oso_gsym_symbol->ValueIsAddress())
153 {
154 // Add the inverse OSO file address to debug map entry mapping
155 exe_symfile->AddOSOFileRange (this,
156 exe_symbol->GetAddress().GetFileAddress(),
157 oso_gsym_symbol->GetAddress().GetFileAddress(),
158 std::min<addr_t>(exe_symbol->GetByteSize(), oso_gsym_symbol->GetByteSize()));
159 }
160 }
161 break;
162 }
163 }
164 }
165
166 exe_symfile->FinalizeOSOFileRanges (this);
Greg Clayton9422dd62013-03-04 21:46:16 +0000167 // We don't need the symbols anymore for the .o files
168 oso_objfile->ClearSymtab();
169 }
170 }
171 return file_range_map;
172}
173
174
Greg Clayton1f746072012-08-29 21:13:06 +0000175class DebugMapModule : public Module
176{
177public:
178 DebugMapModule (const ModuleSP &exe_module_sp,
179 uint32_t cu_idx,
180 const FileSpec& file_spec,
181 const ArchSpec& arch,
182 const ConstString *object_name,
183 off_t object_offset) :
184 Module (file_spec, arch, object_name, object_offset),
185 m_exe_module_wp (exe_module_sp),
186 m_cu_idx (cu_idx)
187 {
188 }
189
Greg Clayton9ba42d12012-10-08 22:48:57 +0000190 virtual
191 ~DebugMapModule ()
192 {
193 }
194
Greg Clayton1f746072012-08-29 21:13:06 +0000195
196 virtual SymbolVendor*
Greg Clayton136dff82012-12-14 02:15:00 +0000197 GetSymbolVendor(bool can_create = true, lldb_private::Stream *feedback_strm = NULL)
Greg Clayton1f746072012-08-29 21:13:06 +0000198 {
199 // Scope for locker
200 if (m_symfile_ap.get() || can_create == false)
201 return m_symfile_ap.get();
202
203 ModuleSP exe_module_sp (m_exe_module_wp.lock());
204 if (exe_module_sp)
205 {
206 // Now get the object file outside of a locking scope
207 ObjectFile *oso_objfile = GetObjectFile ();
208 if (oso_objfile)
209 {
210 Mutex::Locker locker (m_mutex);
Greg Clayton136dff82012-12-14 02:15:00 +0000211 SymbolVendor* symbol_vendor = Module::GetSymbolVendor(can_create, feedback_strm);
Greg Clayton1f746072012-08-29 21:13:06 +0000212 if (symbol_vendor)
213 {
214 // Set a a pointer to this class to set our OSO DWARF file know
215 // that the DWARF is being used along with a debug map and that
216 // it will have the remapped sections that we do below.
217 SymbolFileDWARF *oso_symfile = (SymbolFileDWARF *)symbol_vendor->GetSymbolFile();
218
219 if (!oso_symfile)
220 return NULL;
221
222 ObjectFile *exe_objfile = exe_module_sp->GetObjectFile();
223 SymbolVendor *exe_sym_vendor = exe_module_sp->GetSymbolVendor();
224
225 if (exe_objfile && exe_sym_vendor)
226 {
227 if (oso_symfile->GetNumCompileUnits() == 1)
228 {
229 oso_symfile->SetDebugMapModule(exe_module_sp);
230 // Set the ID of the symbol file DWARF to the index of the OSO
231 // shifted left by 32 bits to provide a unique prefix for any
232 // UserID's that get created in the symbol file.
233 oso_symfile->SetID (((uint64_t)m_cu_idx + 1ull) << 32ull);
234 }
235 else
236 {
237 oso_symfile->SetID (UINT64_MAX);
238 }
239 }
240 return symbol_vendor;
241 }
242 }
243 }
244 return NULL;
245 }
246
247protected:
248 ModuleWP m_exe_module_wp;
249 const uint32_t m_cu_idx;
250};
251
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252void
253SymbolFileDWARFDebugMap::Initialize()
254{
255 PluginManager::RegisterPlugin (GetPluginNameStatic(),
256 GetPluginDescriptionStatic(),
257 CreateInstance);
258}
259
260void
261SymbolFileDWARFDebugMap::Terminate()
262{
263 PluginManager::UnregisterPlugin (CreateInstance);
264}
265
266
267const char *
268SymbolFileDWARFDebugMap::GetPluginNameStatic()
269{
Greg Claytond4a2b372011-09-12 23:21:58 +0000270 return "dwarf-debugmap";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271}
272
273const char *
274SymbolFileDWARFDebugMap::GetPluginDescriptionStatic()
275{
276 return "DWARF and DWARF3 debug symbol file reader (debug map).";
277}
278
279SymbolFile*
280SymbolFileDWARFDebugMap::CreateInstance (ObjectFile* obj_file)
281{
282 return new SymbolFileDWARFDebugMap (obj_file);
283}
284
285
286SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap (ObjectFile* ofile) :
287 SymbolFile(ofile),
288 m_flags(),
289 m_compile_unit_infos(),
290 m_func_indexes(),
Greg Claytonc7f03b62012-01-12 04:33:28 +0000291 m_glob_indexes(),
292 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293{
294}
295
296
297SymbolFileDWARFDebugMap::~SymbolFileDWARFDebugMap()
298{
299}
300
Greg Clayton6beaaa62011-01-17 03:46:26 +0000301void
302SymbolFileDWARFDebugMap::InitializeObject()
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000303{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000304 // Install our external AST source callbacks so we can complete Clang types.
305 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
306 new ClangExternalASTSourceCallbacks (SymbolFileDWARFDebugMap::CompleteTagDecl,
307 SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl,
Greg Claytona2721472011-06-25 00:44:06 +0000308 NULL,
Greg Claytoncaab74e2012-01-28 00:48:57 +0000309 SymbolFileDWARFDebugMap::LayoutRecordType,
Greg Clayton6beaaa62011-01-17 03:46:26 +0000310 this));
311
312 GetClangASTContext().SetExternalSource (ast_source_ap);
Greg Clayton2d95dc9b2010-11-10 04:57:04 +0000313}
314
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315void
Greg Clayton1f746072012-08-29 21:13:06 +0000316SymbolFileDWARFDebugMap::InitOSO()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000317{
318 if (m_flags.test(kHaveInitializedOSOs))
319 return;
Greg Clayton9422dd62013-03-04 21:46:16 +0000320
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 m_flags.set(kHaveInitializedOSOs);
322 // In order to get the abilities of this plug-in, we look at the list of
323 // N_OSO entries (object files) from the symbol table and make sure that
324 // these files exist and also contain valid DWARF. If we get any of that
325 // then we return the abilities of the first N_OSO's DWARF.
326
327 Symtab* symtab = m_obj_file->GetSymtab();
328 if (symtab)
329 {
Sean Callanan60217122012-04-13 00:10:03 +0000330 LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_MAP));
331
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332 std::vector<uint32_t> oso_indexes;
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000333 // When a mach-o symbol is encoded, the n_type field is encoded in bits
334 // 23:16, and the n_desc field is encoded in bits 15:0.
335 //
336 // To find all N_OSO entries that are part of the DWARF + debug map
337 // we find only object file symbols with the flags value as follows:
338 // bits 23:16 == 0x66 (N_OSO)
339 // bits 15: 0 == 0x0001 (specifies this is a debug map object file)
340 const uint32_t k_oso_symbol_flags_value = 0x660001u;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000342 const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithTypeAndFlagsValue(eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000343
344 if (oso_index_count > 0)
345 {
Greg Clayton16b2d2b2011-01-20 06:08:59 +0000346 symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes);
347 symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes);
348
349 symtab->SortSymbolIndexesByValue(m_func_indexes, true);
350 symtab->SortSymbolIndexesByValue(m_glob_indexes, true);
351
Greg Clayton9422dd62013-03-04 21:46:16 +0000352 for (uint32_t sym_idx : m_func_indexes)
353 {
354 const Symbol *symbol = symtab->SymbolAtIndex(sym_idx);
355 lldb::addr_t file_addr = symbol->GetAddress().GetFileAddress();
356 lldb::addr_t byte_size = symbol->GetByteSize();
357 DebugMap::Entry debug_map_entry(file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS));
358 m_debug_map.Append(debug_map_entry);
359 }
360 for (uint32_t sym_idx : m_glob_indexes)
361 {
362 const Symbol *symbol = symtab->SymbolAtIndex(sym_idx);
363 lldb::addr_t file_addr = symbol->GetAddress().GetFileAddress();
364 lldb::addr_t byte_size = symbol->GetByteSize();
365 DebugMap::Entry debug_map_entry(file_addr, byte_size, OSOEntry(sym_idx, LLDB_INVALID_ADDRESS));
366 m_debug_map.Append(debug_map_entry);
367 }
368 m_debug_map.Sort();
369
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 m_compile_unit_infos.resize(oso_index_count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371
372 for (uint32_t i=0; i<oso_index_count; ++i)
373 {
Greg Clayton906ba472013-02-06 00:38:25 +0000374 const uint32_t so_idx = oso_indexes[i] - 1;
Greg Clayton61f39ce2013-02-05 18:40:36 +0000375 const uint32_t oso_idx = oso_indexes[i];
Greg Clayton906ba472013-02-06 00:38:25 +0000376 const Symbol *so_symbol = symtab->SymbolAtIndex(so_idx);
Greg Clayton61f39ce2013-02-05 18:40:36 +0000377 const Symbol *oso_symbol = symtab->SymbolAtIndex(oso_idx);
378 if (so_symbol &&
379 oso_symbol &&
380 so_symbol->GetType() == eSymbolTypeSourceFile &&
381 oso_symbol->GetType() == eSymbolTypeObjectFile)
Greg Claytonb9cafbb2012-07-17 20:18:12 +0000382 {
Greg Clayton613641d2013-03-08 21:46:30 +0000383 m_compile_unit_infos[i].so_file.SetFile(so_symbol->GetName().AsCString(), false);
Greg Clayton906ba472013-02-06 00:38:25 +0000384 m_compile_unit_infos[i].oso_path = oso_symbol->GetName();
Greg Clayton61f39ce2013-02-05 18:40:36 +0000385 uint32_t sibling_idx = so_symbol->GetSiblingIndex();
386 // The sibling index can't be less that or equal to the current index "i"
387 if (sibling_idx <= i)
388 {
389 m_obj_file->GetModule()->ReportError ("N_SO in symbol with UID %u has invalid sibling in debug map, please file a bug and attach the binary listed in this error", so_symbol->GetID());
390 }
391 else
392 {
393 const Symbol* last_symbol = symtab->SymbolAtIndex (sibling_idx - 1);
Greg Clayton906ba472013-02-06 00:38:25 +0000394 m_compile_unit_infos[i].first_symbol_index = so_idx;
395 m_compile_unit_infos[i].last_symbol_index = sibling_idx - 1;
Greg Clayton61f39ce2013-02-05 18:40:36 +0000396 m_compile_unit_infos[i].first_symbol_id = so_symbol->GetID();
397 m_compile_unit_infos[i].last_symbol_id = last_symbol->GetID();
398
399 if (log)
400 log->Printf("Initialized OSO 0x%8.8x: file=%s", i, oso_symbol->GetName().GetCString());
401 }
Greg Claytonb9cafbb2012-07-17 20:18:12 +0000402 }
403 else
404 {
Greg Clayton61f39ce2013-02-05 18:40:36 +0000405 if (oso_symbol == NULL)
406 m_obj_file->GetModule()->ReportError ("N_OSO symbol[%u] can't be found, please file a bug and attach the binary listed in this error", oso_idx);
407 else if (so_symbol == NULL)
408 m_obj_file->GetModule()->ReportError ("N_SO not found for N_OSO symbol[%u], please file a bug and attach the binary listed in this error", oso_idx);
409 else if (so_symbol->GetType() != eSymbolTypeSourceFile)
410 m_obj_file->GetModule()->ReportError ("N_SO has incorrect symbol type (%u) for N_OSO symbol[%u], please file a bug and attach the binary listed in this error", so_symbol->GetType(), oso_idx);
411 else if (oso_symbol->GetType() != eSymbolTypeSourceFile)
412 m_obj_file->GetModule()->ReportError ("N_OSO has incorrect symbol type (%u) for N_OSO symbol[%u], please file a bug and attach the binary listed in this error", oso_symbol->GetType(), oso_idx);
Greg Claytonb9cafbb2012-07-17 20:18:12 +0000413 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 }
415 }
416 }
417}
418
419Module *
420SymbolFileDWARFDebugMap::GetModuleByOSOIndex (uint32_t oso_idx)
421{
422 const uint32_t cu_count = GetNumCompileUnits();
423 if (oso_idx < cu_count)
424 return GetModuleByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
425 return NULL;
426}
427
428Module *
429SymbolFileDWARFDebugMap::GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info)
430{
Greg Clayton906ba472013-02-06 00:38:25 +0000431 if (!comp_unit_info->oso_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 {
Greg Clayton906ba472013-02-06 00:38:25 +0000433 auto pos = m_oso_map.find (comp_unit_info->oso_path);
434 if (pos != m_oso_map.end())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 {
Greg Clayton906ba472013-02-06 00:38:25 +0000436 comp_unit_info->oso_sp = pos->second;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 }
Greg Clayton906ba472013-02-06 00:38:25 +0000438 else
439 {
440 comp_unit_info->oso_sp.reset (new OSOInfo());
441 m_oso_map[comp_unit_info->oso_path] = comp_unit_info->oso_sp;
442 const char *oso_path = comp_unit_info->oso_path.GetCString();
443 FileSpec oso_file (oso_path, true);
444 ConstString oso_object;
445 if (!oso_file.Exists())
446 {
447 const bool must_exist = true;
448
449 if (!ObjectFile::SplitArchivePathWithObject (oso_path,
450 oso_file,
451 oso_object,
452 must_exist))
453 {
454 comp_unit_info->oso_sp->symbol_file_supported = false;
455 return NULL;
456 }
457 }
458 // Always create a new module for .o files. Why? Because we
459 // use the debug map, to add new sections to each .o file and
460 // even though a .o file might not have changed, the sections
461 // that get added to the .o file can change.
462 comp_unit_info->oso_sp->module_sp.reset (new DebugMapModule (GetObjectFile()->GetModule(),
463 GetCompUnitInfoIndex(comp_unit_info),
464 oso_file,
465 m_obj_file->GetModule()->GetArchitecture(),
466 oso_object ? &oso_object : NULL,
467 0));
468 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 }
Greg Clayton906ba472013-02-06 00:38:25 +0000470 if (comp_unit_info->oso_sp)
471 return comp_unit_info->oso_sp->module_sp.get();
472 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473}
474
475
476bool
477SymbolFileDWARFDebugMap::GetFileSpecForSO (uint32_t oso_idx, FileSpec &file_spec)
478{
479 if (oso_idx < m_compile_unit_infos.size())
480 {
Greg Clayton1f746072012-08-29 21:13:06 +0000481 if (m_compile_unit_infos[oso_idx].so_file)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 {
Greg Clayton1f746072012-08-29 21:13:06 +0000483 file_spec = m_compile_unit_infos[oso_idx].so_file;
484 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 }
487 return false;
488}
489
490
491
492ObjectFile *
493SymbolFileDWARFDebugMap::GetObjectFileByOSOIndex (uint32_t oso_idx)
494{
495 Module *oso_module = GetModuleByOSOIndex (oso_idx);
496 if (oso_module)
497 return oso_module->GetObjectFile();
498 return NULL;
499}
500
501SymbolFileDWARF *
502SymbolFileDWARFDebugMap::GetSymbolFile (const SymbolContext& sc)
503{
504 CompileUnitInfo *comp_unit_info = GetCompUnitInfo (sc);
505 if (comp_unit_info)
506 return GetSymbolFileByCompUnitInfo (comp_unit_info);
507 return NULL;
508}
509
510ObjectFile *
511SymbolFileDWARFDebugMap::GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
512{
513 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info);
514 if (oso_module)
515 return oso_module->GetObjectFile();
516 return NULL;
517}
518
Greg Clayton81c22f62011-10-19 18:09:39 +0000519
520uint32_t
521SymbolFileDWARFDebugMap::GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info)
522{
523 if (!m_compile_unit_infos.empty())
524 {
525 const CompileUnitInfo *first_comp_unit_info = &m_compile_unit_infos.front();
526 const CompileUnitInfo *last_comp_unit_info = &m_compile_unit_infos.back();
527 if (first_comp_unit_info <= comp_unit_info && comp_unit_info <= last_comp_unit_info)
528 return comp_unit_info - first_comp_unit_info;
529 }
530 return UINT32_MAX;
531}
532
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533SymbolFileDWARF *
534SymbolFileDWARFDebugMap::GetSymbolFileByOSOIndex (uint32_t oso_idx)
535{
536 if (oso_idx < m_compile_unit_infos.size())
537 return GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[oso_idx]);
538 return NULL;
539}
540
541SymbolFileDWARF *
542SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info)
543{
Greg Clayton1f746072012-08-29 21:13:06 +0000544 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info);
545 if (oso_module)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546 {
Greg Clayton1f746072012-08-29 21:13:06 +0000547 SymbolVendor *sym_vendor = oso_module->GetSymbolVendor();
548 if (sym_vendor)
549 return (SymbolFileDWARF *)sym_vendor->GetSymbolFile();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 return NULL;
552}
553
554uint32_t
Sean Callananbfaf54d2011-12-03 04:38:43 +0000555SymbolFileDWARFDebugMap::CalculateAbilities ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556{
557 // In order to get the abilities of this plug-in, we look at the list of
558 // N_OSO entries (object files) from the symbol table and make sure that
559 // these files exist and also contain valid DWARF. If we get any of that
560 // then we return the abilities of the first N_OSO's DWARF.
561
562 const uint32_t oso_index_count = GetNumCompileUnits();
563 if (oso_index_count > 0)
564 {
565 const uint32_t dwarf_abilities = SymbolFile::CompileUnits |
566 SymbolFile::Functions |
567 SymbolFile::Blocks |
568 SymbolFile::GlobalVariables |
569 SymbolFile::LocalVariables |
570 SymbolFile::VariableTypes |
571 SymbolFile::LineTables;
572
Greg Clayton1f746072012-08-29 21:13:06 +0000573 InitOSO();
574 if (!m_compile_unit_infos.empty())
575 return dwarf_abilities;
576// for (uint32_t oso_idx=0; oso_idx<oso_index_count; ++oso_idx)
577// {
578// SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
579// if (oso_dwarf)
580// {
581// uint32_t oso_abilities = oso_dwarf->GetAbilities();
582// if ((oso_abilities & dwarf_abilities) == dwarf_abilities)
583// return oso_abilities;
584// }
585// }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 }
587 return 0;
588}
589
590uint32_t
591SymbolFileDWARFDebugMap::GetNumCompileUnits()
592{
593 InitOSO ();
594 return m_compile_unit_infos.size();
595}
596
597
598CompUnitSP
599SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx)
600{
601 CompUnitSP comp_unit_sp;
602 const uint32_t cu_count = GetNumCompileUnits();
603
604 if (cu_idx < cu_count)
605 {
Greg Clayton906ba472013-02-06 00:38:25 +0000606 Module *oso_module = GetModuleByCompUnitInfo (&m_compile_unit_infos[cu_idx]);
607 if (oso_module)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608 {
Greg Clayton1f746072012-08-29 21:13:06 +0000609 FileSpec so_file_spec;
610 if (GetFileSpecForSO (cu_idx, so_file_spec))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000612 // User zero as the ID to match the compile unit at offset
613 // zero in each .o file since each .o file can only have
614 // one compile unit for now.
615 lldb::user_id_t cu_id = 0;
616 m_compile_unit_infos[cu_idx].compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
617 NULL,
618 so_file_spec,
619 cu_id,
620 eLanguageTypeUnknown));
Greg Clayton1f746072012-08-29 21:13:06 +0000621
Greg Clayton906ba472013-02-06 00:38:25 +0000622 if (m_compile_unit_infos[cu_idx].compile_unit_sp)
Greg Clayton1f746072012-08-29 21:13:06 +0000623 {
Greg Clayton450e3f32010-10-12 02:24:53 +0000624 // Let our symbol vendor know about this compile unit
Greg Clayton9422dd62013-03-04 21:46:16 +0000625 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex (cu_idx, m_compile_unit_infos[cu_idx].compile_unit_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626 }
627 }
628 }
Greg Clayton906ba472013-02-06 00:38:25 +0000629 comp_unit_sp = m_compile_unit_infos[cu_idx].compile_unit_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630 }
631
632 return comp_unit_sp;
633}
634
635SymbolFileDWARFDebugMap::CompileUnitInfo *
636SymbolFileDWARFDebugMap::GetCompUnitInfo (const SymbolContext& sc)
637{
638 const uint32_t cu_count = GetNumCompileUnits();
639 for (uint32_t i=0; i<cu_count; ++i)
640 {
Greg Clayton906ba472013-02-06 00:38:25 +0000641 if (sc.comp_unit == m_compile_unit_infos[i].compile_unit_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 return &m_compile_unit_infos[i];
643 }
644 return NULL;
645}
646
Greg Clayton1f746072012-08-29 21:13:06 +0000647
Greg Clayton906ba472013-02-06 00:38:25 +0000648size_t
649SymbolFileDWARFDebugMap::GetCompUnitInfosForModule (const lldb_private::Module *module, std::vector<CompileUnitInfo *>& cu_infos)
Greg Clayton1f746072012-08-29 21:13:06 +0000650{
651 const uint32_t cu_count = GetNumCompileUnits();
652 for (uint32_t i=0; i<cu_count; ++i)
653 {
Greg Clayton906ba472013-02-06 00:38:25 +0000654 if (module == GetModuleByCompUnitInfo (&m_compile_unit_infos[i]))
655 cu_infos.push_back (&m_compile_unit_infos[i]);
Greg Clayton1f746072012-08-29 21:13:06 +0000656 }
Greg Clayton906ba472013-02-06 00:38:25 +0000657 return cu_infos.size();
Greg Clayton1f746072012-08-29 21:13:06 +0000658}
659
660lldb::LanguageType
661SymbolFileDWARFDebugMap::ParseCompileUnitLanguage (const SymbolContext& sc)
662{
663 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
664 if (oso_dwarf)
665 return oso_dwarf->ParseCompileUnitLanguage (sc);
666 return eLanguageTypeUnknown;
667}
668
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669size_t
670SymbolFileDWARFDebugMap::ParseCompileUnitFunctions (const SymbolContext& sc)
671{
672 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
673 if (oso_dwarf)
674 return oso_dwarf->ParseCompileUnitFunctions (sc);
675 return 0;
676}
677
678bool
679SymbolFileDWARFDebugMap::ParseCompileUnitLineTable (const SymbolContext& sc)
680{
681 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
682 if (oso_dwarf)
683 return oso_dwarf->ParseCompileUnitLineTable (sc);
684 return false;
685}
686
687bool
688SymbolFileDWARFDebugMap::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList &support_files)
689{
690 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
691 if (oso_dwarf)
692 return oso_dwarf->ParseCompileUnitSupportFiles (sc, support_files);
693 return false;
694}
695
696
697size_t
698SymbolFileDWARFDebugMap::ParseFunctionBlocks (const SymbolContext& sc)
699{
700 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
701 if (oso_dwarf)
702 return oso_dwarf->ParseFunctionBlocks (sc);
703 return 0;
704}
705
706
707size_t
708SymbolFileDWARFDebugMap::ParseTypes (const SymbolContext& sc)
709{
710 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
711 if (oso_dwarf)
712 return oso_dwarf->ParseTypes (sc);
713 return 0;
714}
715
716
717size_t
718SymbolFileDWARFDebugMap::ParseVariablesForContext (const SymbolContext& sc)
719{
720 SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
721 if (oso_dwarf)
Greg Clayton1f746072012-08-29 21:13:06 +0000722 return oso_dwarf->ParseVariablesForContext (sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000723 return 0;
724}
725
726
727
728Type*
729SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid)
730{
Greg Clayton81c22f62011-10-19 18:09:39 +0000731 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
732 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
733 if (oso_dwarf)
Greg Clayton9422dd62013-03-04 21:46:16 +0000734 return oso_dwarf->ResolveTypeUID (type_uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 return NULL;
736}
737
Greg Clayton1be10fc2010-09-29 01:12:09 +0000738lldb::clang_type_t
Greg Clayton81c22f62011-10-19 18:09:39 +0000739SymbolFileDWARFDebugMap::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
Greg Clayton1be10fc2010-09-29 01:12:09 +0000740{
741 // We have a struct/union/class/enum that needs to be fully resolved.
742 return NULL;
743}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744
745uint32_t
746SymbolFileDWARFDebugMap::ResolveSymbolContext (const Address& exe_so_addr, uint32_t resolve_scope, SymbolContext& sc)
747{
748 uint32_t resolved_flags = 0;
749 Symtab* symtab = m_obj_file->GetSymtab();
750 if (symtab)
751 {
752 const addr_t exe_file_addr = exe_so_addr.GetFileAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753
Greg Clayton9422dd62013-03-04 21:46:16 +0000754 const DebugMap::Entry *debug_map_entry = m_debug_map.FindEntryThatContains (exe_file_addr);
755 if (debug_map_entry)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757
Greg Clayton9422dd62013-03-04 21:46:16 +0000758 sc.symbol = symtab->SymbolAtIndex(debug_map_entry->data.GetExeSymbolIndex());
759
760 if (sc.symbol != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000762 resolved_flags |= eSymbolContextSymbol;
763
764 uint32_t oso_idx = 0;
765 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithID (sc.symbol->GetID(), &oso_idx);
766 if (comp_unit_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000768 Module *oso_module = GetModuleByCompUnitInfo (comp_unit_info);
769 if (oso_module)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 {
Greg Clayton9422dd62013-03-04 21:46:16 +0000771 lldb::addr_t oso_file_addr = exe_file_addr - debug_map_entry->GetRangeBase() + debug_map_entry->data.GetOSOFileAddress();
772 Address oso_so_addr;
773 if (oso_module->ResolveFileAddress(oso_file_addr, oso_so_addr))
774 {
775 resolved_flags |= oso_module->GetSymbolVendor()->ResolveSymbolContext (oso_so_addr, resolve_scope, sc);
776 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778 }
779 }
780 }
781 }
782 return resolved_flags;
783}
784
785
786uint32_t
787SymbolFileDWARFDebugMap::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
788{
Greg Clayton1f746072012-08-29 21:13:06 +0000789 const uint32_t initial = sc_list.GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 const uint32_t cu_count = GetNumCompileUnits();
791
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792 for (uint32_t i=0; i<cu_count; ++i)
793 {
Greg Clayton1f746072012-08-29 21:13:06 +0000794 // If we are checking for inlines, then we need to look through all
795 // compile units no matter if "file_spec" matches.
796 bool resolve = check_inlines;
797
798 if (!resolve)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799 {
Greg Clayton1f746072012-08-29 21:13:06 +0000800 FileSpec so_file_spec;
801 if (GetFileSpecForSO (i, so_file_spec))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802 {
Greg Clayton1f746072012-08-29 21:13:06 +0000803 // Match the full path if the incoming file_spec has a directory (not just a basename)
804 const bool full_match = file_spec.GetDirectory();
805 resolve = FileSpec::Equal (file_spec, so_file_spec, full_match);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806 }
807 }
Greg Clayton1f746072012-08-29 21:13:06 +0000808 if (resolve)
809 {
810 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (i);
811 if (oso_dwarf)
812 oso_dwarf->ResolveSymbolContext(file_spec, line, check_inlines, resolve_scope, sc_list);
813 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814 }
815 return sc_list.GetSize() - initial;
816}
817
818uint32_t
819SymbolFileDWARFDebugMap::PrivateFindGlobalVariables
820(
821 const ConstString &name,
Sean Callanan213fdb82011-10-13 01:49:10 +0000822 const ClangNamespaceDecl *namespace_decl,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823 const std::vector<uint32_t> &indexes, // Indexes into the symbol table that match "name"
824 uint32_t max_matches,
825 VariableList& variables
826)
827{
828 const uint32_t original_size = variables.GetSize();
829 const size_t match_count = indexes.size();
830 for (size_t i=0; i<match_count; ++i)
831 {
832 uint32_t oso_idx;
833 CompileUnitInfo* comp_unit_info = GetCompileUnitInfoForSymbolWithIndex (indexes[i], &oso_idx);
834 if (comp_unit_info)
835 {
836 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
837 if (oso_dwarf)
838 {
Sean Callanan213fdb82011-10-13 01:49:10 +0000839 if (oso_dwarf->FindGlobalVariables(name, namespace_decl, true, max_matches, variables))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840 if (variables.GetSize() > max_matches)
841 break;
842 }
843 }
844 }
845 return variables.GetSize() - original_size;
846}
847
848uint32_t
Sean Callanan213fdb82011-10-13 01:49:10 +0000849SymbolFileDWARFDebugMap::FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850{
851
852 // If we aren't appending the results to this list, then clear the list
853 if (!append)
854 variables.Clear();
855
856 // Remember how many variables are in the list before we search in case
857 // we are appending the results to a variable list.
858 const uint32_t original_size = variables.GetSize();
859
Greg Claytonba2d22d2010-11-13 22:57:37 +0000860 uint32_t total_matches = 0;
861 SymbolFileDWARF *oso_dwarf;
862 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 {
Sean Callanan213fdb82011-10-13 01:49:10 +0000864 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (name,
865 namespace_decl,
Greg Claytonba2d22d2010-11-13 22:57:37 +0000866 true,
867 max_matches,
868 variables);
869 if (oso_matches > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
Greg Claytonba2d22d2010-11-13 22:57:37 +0000871 total_matches += oso_matches;
872
873 // Are we getting all matches?
874 if (max_matches == UINT32_MAX)
875 continue; // Yep, continue getting everything
876
877 // If we have found enough matches, lets get out
878 if (max_matches >= total_matches)
879 break;
880
881 // Update the max matches for any subsequent calls to find globals
882 // in any other object files with DWARF
883 max_matches -= oso_matches;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000884 }
885 }
886 // Return the number of variable that were appended to the list
887 return variables.GetSize() - original_size;
888}
889
890
891uint32_t
892SymbolFileDWARFDebugMap::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
893{
Greg Claytonba2d22d2010-11-13 22:57:37 +0000894 // If we aren't appending the results to this list, then clear the list
895 if (!append)
896 variables.Clear();
897
898 // Remember how many variables are in the list before we search in case
899 // we are appending the results to a variable list.
900 const uint32_t original_size = variables.GetSize();
901
902 uint32_t total_matches = 0;
903 SymbolFileDWARF *oso_dwarf;
904 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
905 {
906 const uint32_t oso_matches = oso_dwarf->FindGlobalVariables (regex,
907 true,
908 max_matches,
909 variables);
910 if (oso_matches > 0)
911 {
912 total_matches += oso_matches;
913
914 // Are we getting all matches?
915 if (max_matches == UINT32_MAX)
916 continue; // Yep, continue getting everything
917
918 // If we have found enough matches, lets get out
919 if (max_matches >= total_matches)
920 break;
921
922 // Update the max matches for any subsequent calls to find globals
923 // in any other object files with DWARF
924 max_matches -= oso_matches;
925 }
926 }
927 // Return the number of variable that were appended to the list
928 return variables.GetSize() - original_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000929}
930
931
932int
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000933SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000934{
935 const uint32_t symbol_idx = *symbol_idx_ptr;
936
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000937 if (symbol_idx < comp_unit_info->first_symbol_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938 return -1;
939
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000940 if (symbol_idx <= comp_unit_info->last_symbol_index)
941 return 0;
942
943 return 1;
944}
945
946
947int
948SymbolFileDWARFDebugMap::SymbolContainsSymbolWithID (user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
949{
950 const user_id_t symbol_id = *symbol_idx_ptr;
951
Greg Clayton1f746072012-08-29 21:13:06 +0000952 if (symbol_id < comp_unit_info->first_symbol_id)
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000953 return -1;
954
Greg Clayton1f746072012-08-29 21:13:06 +0000955 if (symbol_id <= comp_unit_info->last_symbol_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956 return 0;
957
958 return 1;
959}
960
961
962SymbolFileDWARFDebugMap::CompileUnitInfo*
963SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr)
964{
965 const uint32_t oso_index_count = m_compile_unit_infos.size();
966 CompileUnitInfo *comp_unit_info = NULL;
967 if (oso_index_count)
968 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000969 comp_unit_info = (CompileUnitInfo*)bsearch(&symbol_idx,
970 &m_compile_unit_infos[0],
971 m_compile_unit_infos.size(),
972 sizeof(CompileUnitInfo),
973 (ComparisonFunction)SymbolContainsSymbolWithIndex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000974 }
975
976 if (oso_idx_ptr)
977 {
978 if (comp_unit_info != NULL)
979 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
980 else
981 *oso_idx_ptr = UINT32_MAX;
982 }
983 return comp_unit_info;
984}
985
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000986SymbolFileDWARFDebugMap::CompileUnitInfo*
987SymbolFileDWARFDebugMap::GetCompileUnitInfoForSymbolWithID (user_id_t symbol_id, uint32_t *oso_idx_ptr)
988{
989 const uint32_t oso_index_count = m_compile_unit_infos.size();
990 CompileUnitInfo *comp_unit_info = NULL;
991 if (oso_index_count)
992 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000993 comp_unit_info = (CompileUnitInfo*)::bsearch (&symbol_id,
994 &m_compile_unit_infos[0],
995 m_compile_unit_infos.size(),
996 sizeof(CompileUnitInfo),
997 (ComparisonFunction)SymbolContainsSymbolWithID);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000998 }
999
1000 if (oso_idx_ptr)
1001 {
1002 if (comp_unit_info != NULL)
1003 *oso_idx_ptr = comp_unit_info - &m_compile_unit_infos[0];
1004 else
1005 *oso_idx_ptr = UINT32_MAX;
1006 }
1007 return comp_unit_info;
1008}
1009
1010
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001011static void
Greg Claytone72dfb32012-02-24 01:59:29 +00001012RemoveFunctionsWithModuleNotEqualTo (const ModuleSP &module_sp, SymbolContextList &sc_list, uint32_t start_idx)
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001013{
1014 // We found functions in .o files. Not all functions in the .o files
1015 // will have made it into the final output file. The ones that did
1016 // make it into the final output file will have a section whose module
1017 // matches the module from the ObjectFile for this SymbolFile. When
1018 // the modules don't match, then we have something that was in a
1019 // .o file, but doesn't map to anything in the final executable.
1020 uint32_t i=start_idx;
1021 while (i < sc_list.GetSize())
1022 {
1023 SymbolContext sc;
1024 sc_list.GetContextAtIndex(i, sc);
1025 if (sc.function)
1026 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001027 const SectionSP section_sp (sc.function->GetAddressRange().GetBaseAddress().GetSection());
1028 if (section_sp->GetModule() != module_sp)
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001029 {
1030 sc_list.RemoveContextAtIndex(i);
1031 continue;
1032 }
1033 }
1034 ++i;
1035 }
1036}
1037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00001039SymbolFileDWARFDebugMap::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040{
1041 Timer scoped_timer (__PRETTY_FUNCTION__,
1042 "SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
1043 name.GetCString());
1044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 uint32_t initial_size = 0;
1046 if (append)
1047 initial_size = sc_list.GetSize();
1048 else
1049 sc_list.Clear();
1050
Greg Clayton57a6b992010-08-17 00:35:34 +00001051 uint32_t oso_idx = 0;
1052 SymbolFileDWARF *oso_dwarf;
1053 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 {
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001055 uint32_t sc_idx = sc_list.GetSize();
Sean Callanan9df05fb2012-02-10 22:52:19 +00001056 if (oso_dwarf->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, true, sc_list))
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001057 {
1058 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
1059 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001060 }
1061
1062 return sc_list.GetSize() - initial_size;
1063}
1064
1065
1066uint32_t
Sean Callanan9df05fb2012-02-10 22:52:19 +00001067SymbolFileDWARFDebugMap::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068{
1069 Timer scoped_timer (__PRETTY_FUNCTION__,
1070 "SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
1071 regex.GetText());
1072
Greg Clayton57a6b992010-08-17 00:35:34 +00001073 uint32_t initial_size = 0;
1074 if (append)
1075 initial_size = sc_list.GetSize();
1076 else
1077 sc_list.Clear();
1078
1079 uint32_t oso_idx = 0;
1080 SymbolFileDWARF *oso_dwarf;
1081 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
1082 {
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001083 uint32_t sc_idx = sc_list.GetSize();
1084
Sean Callanan9df05fb2012-02-10 22:52:19 +00001085 if (oso_dwarf->FindFunctions(regex, include_inlines, true, sc_list))
Greg Clayton3ef3fc62010-08-17 23:16:15 +00001086 {
1087 RemoveFunctionsWithModuleNotEqualTo (m_obj_file->GetModule(), sc_list, sc_idx);
1088 }
Greg Clayton57a6b992010-08-17 00:35:34 +00001089 }
1090
1091 return sc_list.GetSize() - initial_size;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092}
1093
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00001094TypeSP
Greg Claytona8022fa2012-04-24 21:22:41 +00001095SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx)
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00001096{
1097 TypeSP type_sp;
1098 SymbolFileDWARF *oso_dwarf;
1099 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1100 {
Greg Claytona8022fa2012-04-24 21:22:41 +00001101 type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
Greg Clayton2ccf8cf2010-11-07 21:02:03 +00001102 if (type_sp)
1103 break;
1104 }
1105 return type_sp;
1106}
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001107
Greg Clayton901c5ca2011-12-03 04:40:03 +00001108
Greg Claytonc7f03b62012-01-12 04:33:28 +00001109
1110bool
1111SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso)
1112{
1113 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
1114 {
1115 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
1116 SymbolFileDWARF *oso_dwarf;
1117 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1118 {
1119 if (skip_dwarf_oso != oso_dwarf && oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(NULL))
1120 {
1121 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
1122 break;
1123 }
1124 }
1125 }
1126 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
1127}
1128
Greg Clayton901c5ca2011-12-03 04:40:03 +00001129TypeSP
Greg Claytonc7f03b62012-01-12 04:33:28 +00001130SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
1131 const ConstString &type_name,
1132 bool must_be_implementation)
Greg Clayton901c5ca2011-12-03 04:40:03 +00001133{
1134 TypeSP type_sp;
1135 SymbolFileDWARF *oso_dwarf;
1136 for (uint32_t oso_idx = 0; ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1137 {
Greg Claytonc7f03b62012-01-12 04:33:28 +00001138 type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name, must_be_implementation);
Greg Clayton901c5ca2011-12-03 04:40:03 +00001139 if (type_sp)
1140 break;
1141 }
1142 return type_sp;
1143}
1144
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001145uint32_t
Greg Clayton6dbd3982010-09-15 05:51:24 +00001146SymbolFileDWARFDebugMap::FindTypes
1147(
1148 const SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00001149 const ConstString &name,
1150 const ClangNamespaceDecl *namespace_decl,
Greg Clayton6dbd3982010-09-15 05:51:24 +00001151 bool append,
1152 uint32_t max_matches,
1153 TypeList& types
1154)
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001155{
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001156 if (!append)
1157 types.Clear();
Greg Clayton6dbd3982010-09-15 05:51:24 +00001158
1159 const uint32_t initial_types_size = types.GetSize();
1160 SymbolFileDWARF *oso_dwarf;
1161
1162 if (sc.comp_unit)
1163 {
1164 oso_dwarf = GetSymbolFile (sc);
1165 if (oso_dwarf)
Sean Callanan213fdb82011-10-13 01:49:10 +00001166 return oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
Greg Clayton6dbd3982010-09-15 05:51:24 +00001167 }
1168 else
1169 {
1170 uint32_t oso_idx = 0;
1171 while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
Sean Callanan213fdb82011-10-13 01:49:10 +00001172 oso_dwarf->FindTypes (sc, name, namespace_decl, append, max_matches, types);
Greg Clayton6dbd3982010-09-15 05:51:24 +00001173 }
1174
1175 return types.GetSize() - initial_types_size;
Greg Claytonb0b9fe62010-08-03 00:35:52 +00001176}
1177
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178//
1179//uint32_t
1180//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)
1181//{
1182// SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
1183// if (oso_dwarf)
1184// return oso_dwarf->FindTypes (sc, regex, append, max_matches, encoding, udt_uid, types);
1185// return 0;
1186//}
1187
Greg Clayton96d7d742010-11-10 23:42:09 +00001188
Greg Clayton526e5af2010-11-13 03:52:47 +00001189ClangNamespaceDecl
Greg Clayton96d7d742010-11-10 23:42:09 +00001190SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc,
Sean Callanan213fdb82011-10-13 01:49:10 +00001191 const lldb_private::ConstString &name,
1192 const ClangNamespaceDecl *parent_namespace_decl)
Greg Clayton96d7d742010-11-10 23:42:09 +00001193{
Greg Clayton526e5af2010-11-13 03:52:47 +00001194 ClangNamespaceDecl matching_namespace;
Greg Clayton96d7d742010-11-10 23:42:09 +00001195 SymbolFileDWARF *oso_dwarf;
1196
1197 if (sc.comp_unit)
1198 {
1199 oso_dwarf = GetSymbolFile (sc);
1200 if (oso_dwarf)
Sean Callanan213fdb82011-10-13 01:49:10 +00001201 matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
Greg Clayton96d7d742010-11-10 23:42:09 +00001202 }
1203 else
1204 {
1205 for (uint32_t oso_idx = 0;
1206 ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) != NULL);
1207 ++oso_idx)
1208 {
Sean Callanan213fdb82011-10-13 01:49:10 +00001209 matching_namespace = oso_dwarf->FindNamespace (sc, name, parent_namespace_decl);
Greg Clayton96d7d742010-11-10 23:42:09 +00001210
1211 if (matching_namespace)
1212 break;
1213 }
1214 }
1215
1216 return matching_namespace;
1217}
1218
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219//------------------------------------------------------------------
1220// PluginInterface protocol
1221//------------------------------------------------------------------
1222const char *
1223SymbolFileDWARFDebugMap::GetPluginName()
1224{
1225 return "SymbolFileDWARFDebugMap";
1226}
1227
1228const char *
1229SymbolFileDWARFDebugMap::GetShortPluginName()
1230{
1231 return GetPluginNameStatic();
1232}
1233
1234uint32_t
1235SymbolFileDWARFDebugMap::GetPluginVersion()
1236{
1237 return 1;
1238}
1239
Greg Clayton1f746072012-08-29 21:13:06 +00001240lldb::CompUnitSP
1241SymbolFileDWARFDebugMap::GetCompileUnit (SymbolFileDWARF *oso_dwarf)
1242{
1243 if (oso_dwarf)
1244 {
1245 const uint32_t cu_count = GetNumCompileUnits();
1246 for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx)
1247 {
1248 SymbolFileDWARF *oso_symfile = GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[cu_idx]);
1249 if (oso_symfile == oso_dwarf)
1250 {
Greg Clayton906ba472013-02-06 00:38:25 +00001251 if (!m_compile_unit_infos[cu_idx].compile_unit_sp)
1252 m_compile_unit_infos[cu_idx].compile_unit_sp = ParseCompileUnitAtIndex (cu_idx);
Greg Clayton1f746072012-08-29 21:13:06 +00001253
Greg Clayton906ba472013-02-06 00:38:25 +00001254 return m_compile_unit_infos[cu_idx].compile_unit_sp;
Greg Clayton1f746072012-08-29 21:13:06 +00001255 }
1256 }
1257 }
1258 assert(!"this shouldn't happen");
1259 return lldb::CompUnitSP();
1260}
1261
Greg Clayton9422dd62013-03-04 21:46:16 +00001262SymbolFileDWARFDebugMap::CompileUnitInfo *
1263SymbolFileDWARFDebugMap::GetCompileUnitInfo (SymbolFileDWARF *oso_dwarf)
1264{
1265 if (oso_dwarf)
1266 {
1267 const uint32_t cu_count = GetNumCompileUnits();
1268 for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx)
1269 {
1270 SymbolFileDWARF *oso_symfile = GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[cu_idx]);
1271 if (oso_symfile == oso_dwarf)
1272 {
1273 return &m_compile_unit_infos[cu_idx];
1274 }
1275 }
1276 }
1277 return NULL;
1278}
1279
Greg Clayton1f746072012-08-29 21:13:06 +00001280
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281void
Greg Clayton450e3f32010-10-12 02:24:53 +00001282SymbolFileDWARFDebugMap::SetCompileUnit (SymbolFileDWARF *oso_dwarf, const CompUnitSP &cu_sp)
1283{
Greg Clayton1f746072012-08-29 21:13:06 +00001284 if (oso_dwarf)
Greg Clayton450e3f32010-10-12 02:24:53 +00001285 {
Greg Clayton1f746072012-08-29 21:13:06 +00001286 const uint32_t cu_count = GetNumCompileUnits();
1287 for (uint32_t cu_idx=0; cu_idx<cu_count; ++cu_idx)
Greg Clayton450e3f32010-10-12 02:24:53 +00001288 {
Greg Clayton1f746072012-08-29 21:13:06 +00001289 SymbolFileDWARF *oso_symfile = GetSymbolFileByCompUnitInfo (&m_compile_unit_infos[cu_idx]);
1290 if (oso_symfile == oso_dwarf)
Greg Clayton450e3f32010-10-12 02:24:53 +00001291 {
Greg Clayton906ba472013-02-06 00:38:25 +00001292 if (m_compile_unit_infos[cu_idx].compile_unit_sp)
Greg Clayton1f746072012-08-29 21:13:06 +00001293 {
Greg Clayton906ba472013-02-06 00:38:25 +00001294 assert (m_compile_unit_infos[cu_idx].compile_unit_sp.get() == cu_sp.get());
Greg Clayton1f746072012-08-29 21:13:06 +00001295 }
1296 else
1297 {
Greg Clayton906ba472013-02-06 00:38:25 +00001298 m_compile_unit_infos[cu_idx].compile_unit_sp = cu_sp;
Greg Clayton1f746072012-08-29 21:13:06 +00001299 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
1300 }
Greg Clayton450e3f32010-10-12 02:24:53 +00001301 }
1302 }
1303 }
1304}
1305
Greg Clayton6beaaa62011-01-17 03:46:26 +00001306
1307void
1308SymbolFileDWARFDebugMap::CompleteTagDecl (void *baton, clang::TagDecl *decl)
1309{
1310 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1311 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1312 if (clang_type)
1313 {
1314 SymbolFileDWARF *oso_dwarf;
1315
1316 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1317 {
1318 if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1319 {
1320 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1321 return;
1322 }
1323 }
1324 }
1325}
1326
1327void
1328SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
1329{
1330 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1331 clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
1332 if (clang_type)
1333 {
1334 SymbolFileDWARF *oso_dwarf;
1335
1336 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1337 {
1338 if (oso_dwarf->HasForwardDeclForClangType (clang_type))
1339 {
1340 oso_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
1341 return;
1342 }
1343 }
1344 }
1345}
1346
Greg Claytoncaab74e2012-01-28 00:48:57 +00001347bool
1348SymbolFileDWARFDebugMap::LayoutRecordType (void *baton,
1349 const clang::RecordDecl *record_decl,
1350 uint64_t &size,
1351 uint64_t &alignment,
1352 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
1353 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
1354 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
1355{
1356 SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton;
1357 SymbolFileDWARF *oso_dwarf;
1358 for (uint32_t oso_idx = 0; ((oso_dwarf = symbol_file_dwarf->GetSymbolFileByOSOIndex (oso_idx)) != NULL); ++oso_idx)
1359 {
1360 if (oso_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets))
1361 return true;
1362 }
1363 return false;
1364}
1365
1366
1367
Greg Clayton81c22f62011-10-19 18:09:39 +00001368clang::DeclContext*
1369SymbolFileDWARFDebugMap::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
1370{
1371 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1372 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1373 if (oso_dwarf)
1374 return oso_dwarf->GetClangDeclContextContainingTypeUID (type_uid);
1375 return NULL;
1376}
1377
1378clang::DeclContext*
1379SymbolFileDWARFDebugMap::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1380{
1381 const uint64_t oso_idx = GetOSOIndexFromUserID (type_uid);
1382 SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx);
1383 if (oso_dwarf)
1384 return oso_dwarf->GetClangDeclContextForTypeUID (sc, type_uid);
1385 return NULL;
1386}
1387
Greg Clayton9422dd62013-03-04 21:46:16 +00001388bool
1389SymbolFileDWARFDebugMap::AddOSOFileRange (CompileUnitInfo *cu_info,
1390 lldb::addr_t exe_file_addr,
1391 lldb::addr_t oso_file_addr,
1392 lldb::addr_t oso_byte_size)
1393{
1394 assert (cu_info);// REMOVE THIS PRIOR TO CHECKIN
1395 const uint32_t debug_map_idx = m_debug_map.FindEntryIndexThatContains(exe_file_addr);
1396 if (debug_map_idx != UINT32_MAX)
1397 {
1398 DebugMap::Entry *debug_map_entry = m_debug_map.FindEntryThatContains(exe_file_addr);
1399 assert (debug_map_entry);// REMOVE THIS PRIOR TO CHECKIN
1400 debug_map_entry->data.SetOSOFileAddress(oso_file_addr);
1401 cu_info->file_range_map.Append(FileRangeMap::Entry(oso_file_addr, oso_byte_size, exe_file_addr));
1402 return true;
1403 }
1404 return false;
1405}
1406
1407void
1408SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (CompileUnitInfo *cu_info)
1409{
1410 cu_info->file_range_map.Sort();
1411#if defined(DEBUG_OSO_DMAP)
1412 const FileRangeMap &oso_file_range_map = cu_info->GetFileRangeMap(this);
1413 const size_t n = oso_file_range_map.GetSize();
Greg Clayton084fad62013-03-06 23:23:27 +00001414 printf ("SymbolFileDWARFDebugMap::FinalizeOSOFileRanges (cu_info = %p) %s/%s\n",
1415 cu_info,
1416 cu_info->oso_sp->module_sp->GetFileSpec().GetDirectory().GetCString(),
1417 cu_info->oso_sp->module_sp->GetFileSpec().GetFilename().GetCString());
Greg Clayton9422dd62013-03-04 21:46:16 +00001418 for (size_t i=0; i<n; ++i)
1419 {
1420 const FileRangeMap::Entry &entry = oso_file_range_map.GetEntryRef(i);
1421 printf ("oso [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ") ==> exe [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n",
1422 entry.GetRangeBase(), entry.GetRangeEnd(),
1423 entry.data, entry.data + entry.GetByteSize());
1424 }
1425#endif
1426}
1427
1428lldb::addr_t
1429SymbolFileDWARFDebugMap::LinkOSOFileAddress (SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr)
1430{
1431 CompileUnitInfo *cu_info = GetCompileUnitInfo (oso_symfile);
1432 if (cu_info)
1433 {
1434 const FileRangeMap::Entry *oso_range_entry = cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1435 if (oso_range_entry)
1436 {
1437 const DebugMap::Entry *debug_map_entry = m_debug_map.FindEntryThatContains(oso_range_entry->data);
1438 if (debug_map_entry)
1439 {
1440 const lldb::addr_t offset = oso_file_addr - oso_range_entry->GetRangeBase();
1441 const lldb::addr_t exe_file_addr = debug_map_entry->GetRangeBase() + offset;
1442 return exe_file_addr;
1443 }
1444 }
1445 }
1446 return LLDB_INVALID_ADDRESS;
1447}
1448
1449bool
1450SymbolFileDWARFDebugMap::LinkOSOAddress (Address &addr)
1451{
1452 // Make sure this address hasn't been fixed already
1453 Module *exe_module = GetObjectFile()->GetModule().get();
1454 Module *addr_module = addr.GetModule().get();
1455 if (addr_module == exe_module)
1456 return true; // Address is already in terms of the main executable module
1457
1458 CompileUnitInfo *cu_info = GetCompileUnitInfo ((SymbolFileDWARF *)addr_module->GetSymbolVendor()->GetSymbolFile());
1459 if (cu_info)
1460 {
1461 const lldb::addr_t oso_file_addr = addr.GetFileAddress();
1462 const FileRangeMap::Entry *oso_range_entry = cu_info->GetFileRangeMap(this).FindEntryThatContains(oso_file_addr);
1463 if (oso_range_entry)
1464 {
1465 const DebugMap::Entry *debug_map_entry = m_debug_map.FindEntryThatContains(oso_range_entry->data);
1466 if (debug_map_entry)
1467 {
1468 const lldb::addr_t offset = oso_file_addr - oso_range_entry->GetRangeBase();
1469 const lldb::addr_t exe_file_addr = debug_map_entry->GetRangeBase() + offset;
1470 return exe_module->ResolveFileAddress(exe_file_addr, addr);
1471 }
1472 }
1473 }
1474 return true;
1475}
1476
1477LineTable *
1478SymbolFileDWARFDebugMap::LinkOSOLineTable (SymbolFileDWARF *oso_dwarf, LineTable *line_table)
1479{
1480 CompileUnitInfo *cu_info = GetCompileUnitInfo (oso_dwarf);
1481 if (cu_info)
1482 return line_table->LinkLineTable(cu_info->GetFileRangeMap(this));
1483 return NULL;
1484}
1485
Greg Clayton81c22f62011-10-19 18:09:39 +00001486