aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Symbol/SymbolFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Symbol/SymbolFile.cpp')
-rw-r--r--lldb/source/Symbol/SymbolFile.cpp124
1 files changed, 73 insertions, 51 deletions
diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp
index b85901af4d67..e69150e9a356 100644
--- a/lldb/source/Symbol/SymbolFile.cpp
+++ b/lldb/source/Symbol/SymbolFile.cpp
@@ -12,6 +12,7 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolFileOnDemand.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
@@ -25,6 +26,7 @@ using namespace lldb_private;
using namespace lldb;
char SymbolFile::ID;
+char SymbolFileCommon::ID;
void SymbolFile::PreloadSymbols() {
// No-op for most implementations.
@@ -33,9 +35,6 @@ void SymbolFile::PreloadSymbols() {
std::recursive_mutex &SymbolFile::GetModuleMutex() const {
return GetObjectFile()->GetModule()->GetMutex();
}
-ObjectFile *SymbolFile::GetMainObjectFile() {
- return m_objfile_sp->GetModule()->GetObjectFile();
-}
SymbolFile *SymbolFile::FindPlugin(ObjectFileSP objfile_sp) {
std::unique_ptr<SymbolFile> best_symfile_up;
@@ -79,6 +78,24 @@ SymbolFile *SymbolFile::FindPlugin(ObjectFileSP objfile_sp) {
}
}
if (best_symfile_up) {
+ // If symbol on-demand is enabled the winning symbol file parser is
+ // wrapped with SymbolFileOnDemand so that hydration of the debug info
+ // can be controlled to improve performance.
+ //
+ // Currently the supported on-demand symbol files include:
+ // executables, shared libraries and debug info files.
+ //
+ // To reduce unnecessary wrapping files with zero debug abilities are
+ // skipped.
+ ObjectFile::Type obj_file_type = objfile_sp->CalculateType();
+ if (ModuleList::GetGlobalModuleListProperties().GetLoadSymbolOnDemand() &&
+ best_symfile_abilities > 0 &&
+ (obj_file_type == ObjectFile::eTypeExecutable ||
+ obj_file_type == ObjectFile::eTypeSharedLibrary ||
+ obj_file_type == ObjectFile::eTypeDebugInfo)) {
+ best_symfile_up =
+ std::make_unique<SymbolFileOnDemand>(std::move(best_symfile_up));
+ }
// Let the winning symbol file parser initialize itself more completely
// now that it has been chosen
best_symfile_up->InitializeObject();
@@ -87,16 +104,6 @@ SymbolFile *SymbolFile::FindPlugin(ObjectFileSP objfile_sp) {
return best_symfile_up.release();
}
-llvm::Expected<TypeSystem &>
-SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
- auto type_system_or_err =
- m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
- if (type_system_or_err) {
- type_system_or_err->SetSymbolFile(this);
- }
- return type_system_or_err;
-}
-
uint32_t
SymbolFile::ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
lldb::SymbolContextItem resolve_scope,
@@ -154,7 +161,37 @@ void SymbolFile::AssertModuleLock() {
#endif
}
-uint32_t SymbolFile::GetNumCompileUnits() {
+SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;
+
+Symtab *SymbolFileCommon::GetSymtab() {
+ std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
+ if (m_symtab)
+ return m_symtab;
+
+ // Fetch the symtab from the main object file.
+ m_symtab = GetMainObjectFile()->GetSymtab();
+
+ // Then add our symbols to it.
+ if (m_symtab)
+ AddSymbols(*m_symtab);
+
+ return m_symtab;
+}
+
+ObjectFile *SymbolFileCommon::GetMainObjectFile() {
+ return m_objfile_sp->GetModule()->GetObjectFile();
+}
+
+void SymbolFileCommon::SectionFileAddressesChanged() {
+ ObjectFile *module_objfile = GetMainObjectFile();
+ ObjectFile *symfile_objfile = GetObjectFile();
+ if (symfile_objfile != module_objfile)
+ symfile_objfile->SectionFileAddressesChanged();
+ if (m_symtab)
+ m_symtab->SectionFileAddressesChanged();
+}
+
+uint32_t SymbolFileCommon::GetNumCompileUnits() {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
if (!m_compile_units) {
// Create an array of compile unit shared pointers -- which will each
@@ -164,7 +201,7 @@ uint32_t SymbolFile::GetNumCompileUnits() {
return m_compile_units->size();
}
-CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) {
+CompUnitSP SymbolFileCommon::GetCompileUnitAtIndex(uint32_t idx) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
uint32_t num = GetNumCompileUnits();
if (idx >= num)
@@ -175,7 +212,8 @@ CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) {
return cu_sp;
}
-void SymbolFile::SetCompileUnitAtIndex(uint32_t idx, const CompUnitSP &cu_sp) {
+void SymbolFileCommon::SetCompileUnitAtIndex(uint32_t idx,
+ const CompUnitSP &cu_sp) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
const size_t num_compile_units = GetNumCompileUnits();
assert(idx < num_compile_units);
@@ -190,31 +228,29 @@ void SymbolFile::SetCompileUnitAtIndex(uint32_t idx, const CompUnitSP &cu_sp) {
(*m_compile_units)[idx] = cu_sp;
}
-Symtab *SymbolFile::GetSymtab() {
- std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
- if (m_symtab)
- return m_symtab;
-
- // Fetch the symtab from the main object file.
- m_symtab = GetMainObjectFile()->GetSymtab();
-
- // Then add our symbols to it.
- if (m_symtab)
- AddSymbols(*m_symtab);
-
- return m_symtab;
+llvm::Expected<TypeSystem &>
+SymbolFileCommon::GetTypeSystemForLanguage(lldb::LanguageType language) {
+ auto type_system_or_err =
+ m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
+ if (type_system_or_err) {
+ type_system_or_err->SetSymbolFile(this);
+ }
+ return type_system_or_err;
}
-void SymbolFile::SectionFileAddressesChanged() {
- ObjectFile *module_objfile = GetMainObjectFile();
- ObjectFile *symfile_objfile = GetObjectFile();
- if (symfile_objfile != module_objfile)
- symfile_objfile->SectionFileAddressesChanged();
- if (m_symtab)
- m_symtab->SectionFileAddressesChanged();
+uint64_t SymbolFileCommon::GetDebugInfoSize() {
+ if (!m_objfile_sp)
+ return 0;
+ ModuleSP module_sp(m_objfile_sp->GetModule());
+ if (!module_sp)
+ return 0;
+ const SectionList *section_list = module_sp->GetSectionList();
+ if (section_list)
+ return section_list->GetDebugInfoSize();
+ return 0;
}
-void SymbolFile::Dump(Stream &s) {
+void SymbolFileCommon::Dump(Stream &s) {
s.Format("SymbolFile {0} ({1})\n", GetPluginName(),
GetMainObjectFile()->GetFileSpec());
s.PutCString("Types:\n");
@@ -234,17 +270,3 @@ void SymbolFile::Dump(Stream &s) {
if (Symtab *symtab = GetSymtab())
symtab->Dump(&s, nullptr, eSortOrderNone);
}
-
-SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;
-
-uint64_t SymbolFile::GetDebugInfoSize() {
- if (!m_objfile_sp)
- return 0;
- ModuleSP module_sp(m_objfile_sp->GetModule());
- if (!module_sp)
- return 0;
- const SectionList *section_list = module_sp->GetSectionList();
- if (section_list)
- return section_list->GetDebugInfoSize();
- return 0;
-}