2010-06-08 16:52:24 +00:00
|
|
|
//===-- CompileUnit.cpp -----------------------------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
|
#include "lldb/Core/Module.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
#include "lldb/Symbol/LineTable.h"
|
2019-08-06 09:12:42 +00:00
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2015-09-02 01:06:46 +00:00
|
|
|
#include "lldb/Target/Language.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2016-07-05 23:01:20 +00:00
|
|
|
CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
|
|
|
|
|
const char *pathname, const lldb::user_id_t cu_sym_id,
|
|
|
|
|
lldb::LanguageType language,
|
|
|
|
|
lldb_private::LazyBool is_optimized)
|
2018-11-01 21:05:36 +00:00
|
|
|
: ModuleChild(module_sp), FileSpec(pathname), UserID(cu_sym_id),
|
2018-08-11 23:40:27 +00:00
|
|
|
m_user_data(user_data), m_language(language), m_flags(0),
|
2019-02-13 06:25:41 +00:00
|
|
|
m_support_files(), m_line_table_up(), m_variables(),
|
2016-07-05 23:01:20 +00:00
|
|
|
m_is_optimized(is_optimized) {
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
if (language != eLanguageTypeUnknown)
|
|
|
|
|
m_flags.Set(flagsParsedLanguage);
|
2012-02-24 01:59:29 +00:00
|
|
|
assert(module_sp);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-05 23:01:20 +00:00
|
|
|
CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
|
|
|
|
|
const FileSpec &fspec, const lldb::user_id_t cu_sym_id,
|
|
|
|
|
lldb::LanguageType language,
|
|
|
|
|
lldb_private::LazyBool is_optimized)
|
|
|
|
|
: ModuleChild(module_sp), FileSpec(fspec), UserID(cu_sym_id),
|
2018-08-11 23:40:27 +00:00
|
|
|
m_user_data(user_data), m_language(language), m_flags(0),
|
2019-02-13 06:25:41 +00:00
|
|
|
m_support_files(), m_line_table_up(), m_variables(),
|
2016-07-05 23:01:20 +00:00
|
|
|
m_is_optimized(is_optimized) {
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
if (language != eLanguageTypeUnknown)
|
|
|
|
|
m_flags.Set(flagsParsedLanguage);
|
2012-02-24 01:59:29 +00:00
|
|
|
assert(module_sp);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CompileUnit::~CompileUnit() {}
|
|
|
|
|
|
|
|
|
|
void CompileUnit::CalculateSymbolContext(SymbolContext *sc) {
|
|
|
|
|
sc->comp_unit = this;
|
|
|
|
|
GetModule()->CalculateSymbolContext(sc);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-12 21:40:01 +00:00
|
|
|
ModuleSP CompileUnit::CalculateSymbolContextModule() { return GetModule(); }
|
|
|
|
|
|
|
|
|
|
CompileUnit *CompileUnit::CalculateSymbolContextCompileUnit() { return this; }
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void CompileUnit::DumpSymbolContext(Stream *s) {
|
|
|
|
|
GetModule()->DumpSymbolContext(s);
|
2012-11-29 21:49:15 +00:00
|
|
|
s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID());
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-28 21:30:43 +00:00
|
|
|
void CompileUnit::GetDescription(Stream *s,
|
|
|
|
|
lldb::DescriptionLevel level) const {
|
2015-09-02 01:06:46 +00:00
|
|
|
const char *language = Language::GetNameForLanguageType(m_language);
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
*s << "id = " << (const UserID &)*this << ", file = \""
|
|
|
|
|
<< (const FileSpec &)*this << "\", language = \"" << language << '"';
|
2010-06-28 21:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 23:40:27 +00:00
|
|
|
void CompileUnit::ForeachFunction(
|
|
|
|
|
llvm::function_ref<bool(const FunctionSP &)> lambda) const {
|
|
|
|
|
std::vector<lldb::FunctionSP> sorted_functions;
|
|
|
|
|
sorted_functions.reserve(m_functions_by_uid.size());
|
|
|
|
|
for (auto &p : m_functions_by_uid)
|
|
|
|
|
sorted_functions.push_back(p.second);
|
2019-01-08 23:25:06 +00:00
|
|
|
llvm::sort(sorted_functions.begin(), sorted_functions.end(),
|
|
|
|
|
[](const lldb::FunctionSP &a, const lldb::FunctionSP &b) {
|
|
|
|
|
return a->GetID() < b->GetID();
|
|
|
|
|
});
|
2018-08-11 23:40:27 +00:00
|
|
|
|
|
|
|
|
for (auto &f : sorted_functions)
|
|
|
|
|
if (lambda(f))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Dump the current contents of this object. No functions that cause on demand
|
|
|
|
|
// parsing of functions, globals, statics are called, so this is a good
|
|
|
|
|
// function to call to get an idea of the current contents of the CompileUnit
|
|
|
|
|
// object.
|
2010-06-08 16:52:24 +00:00
|
|
|
void CompileUnit::Dump(Stream *s, bool show_context) const {
|
2015-09-02 01:06:46 +00:00
|
|
|
const char *language = Language::GetNameForLanguageType(m_language);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-04-04 04:06:10 +00:00
|
|
|
s->Printf("%p: ", static_cast<const void *>(this));
|
2010-06-08 16:52:24 +00:00
|
|
|
s->Indent();
|
2014-04-04 04:06:10 +00:00
|
|
|
*s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \""
|
|
|
|
|
<< language << "\", file = '" << static_cast<const FileSpec &>(*this)
|
|
|
|
|
<< "'\n";
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
// m_types.Dump(s);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_variables.get()) {
|
|
|
|
|
s->IndentMore();
|
|
|
|
|
m_variables->Dump(s, show_context);
|
|
|
|
|
s->IndentLess();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 23:40:27 +00:00
|
|
|
if (!m_functions_by_uid.empty()) {
|
2010-06-08 16:52:24 +00:00
|
|
|
s->IndentMore();
|
2018-08-11 23:40:27 +00:00
|
|
|
ForeachFunction([&s, show_context](const FunctionSP &f) {
|
|
|
|
|
f->Dump(s, show_context);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
s->IndentLess();
|
|
|
|
|
s->EOL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add a function to this compile unit
|
|
|
|
|
void CompileUnit::AddFunction(FunctionSP &funcSP) {
|
2018-08-11 23:40:27 +00:00
|
|
|
m_functions_by_uid[funcSP->GetID()] = funcSP;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) {
|
2018-08-11 23:40:27 +00:00
|
|
|
auto it = m_functions_by_uid.find(func_uid);
|
|
|
|
|
if (it == m_functions_by_uid.end())
|
|
|
|
|
return FunctionSP();
|
|
|
|
|
return it->second;
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
lldb::LanguageType CompileUnit::GetLanguage() {
|
2014-04-20 13:17:36 +00:00
|
|
|
if (m_language == eLanguageTypeUnknown) {
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_flags.IsClear(flagsParsedLanguage)) {
|
|
|
|
|
m_flags.Set(flagsParsedLanguage);
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile())
|
|
|
|
|
m_language = symfile->ParseLanguage(*this);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return m_language;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LineTable *CompileUnit::GetLineTable() {
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_line_table_up == nullptr) {
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_flags.IsClear(flagsParsedLineTable)) {
|
|
|
|
|
m_flags.Set(flagsParsedLineTable);
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile())
|
|
|
|
|
symfile->ParseLineTable(*this);
|
2015-12-16 00:22:08 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-02-13 06:25:41 +00:00
|
|
|
return m_line_table_up.get();
|
2015-12-16 00:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompileUnit::SetLineTable(LineTable *line_table) {
|
|
|
|
|
if (line_table == nullptr)
|
|
|
|
|
m_flags.Clear(flagsParsedLineTable);
|
|
|
|
|
else
|
|
|
|
|
m_flags.Set(flagsParsedLineTable);
|
2019-02-13 06:25:41 +00:00
|
|
|
m_line_table_up.reset(line_table);
|
2015-12-16 00:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-13 19:51:51 +00:00
|
|
|
void CompileUnit::SetSupportFiles(const FileSpecList &support_files) {
|
|
|
|
|
m_support_files = support_files;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
DebugMacros *CompileUnit::GetDebugMacros() {
|
2014-04-20 13:17:36 +00:00
|
|
|
if (m_debug_macros_sp.get() == nullptr) {
|
|
|
|
|
if (m_flags.IsClear(flagsParsedDebugMacros)) {
|
2015-12-16 00:22:08 +00:00
|
|
|
m_flags.Set(flagsParsedDebugMacros);
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile())
|
|
|
|
|
symfile->ParseDebugMacros(*this);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
return m_debug_macros_sp.get();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-23 00:54:11 +00:00
|
|
|
void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) {
|
|
|
|
|
if (debug_macros_sp.get() == nullptr)
|
2010-06-08 16:52:24 +00:00
|
|
|
m_flags.Clear(flagsParsedDebugMacros);
|
|
|
|
|
else
|
2011-09-23 00:54:11 +00:00
|
|
|
m_flags.Set(flagsParsedDebugMacros);
|
|
|
|
|
m_debug_macros_sp = debug_macros_sp;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VariableListSP CompileUnit::GetVariableList(bool can_create) {
|
2015-12-16 00:22:08 +00:00
|
|
|
if (m_variables.get() == nullptr && can_create) {
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
CalculateSymbolContext(&sc);
|
2010-06-08 16:52:24 +00:00
|
|
|
assert(sc.module_sp);
|
2019-08-06 09:12:42 +00:00
|
|
|
sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
return m_variables;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2011-09-23 00:54:11 +00:00
|
|
|
uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line,
|
|
|
|
|
const FileSpec *file_spec_ptr, bool exact,
|
|
|
|
|
LineEntry *line_entry_ptr) {
|
2010-06-08 16:52:24 +00:00
|
|
|
uint32_t file_idx = 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
if (file_spec_ptr) {
|
2014-11-15 01:54:26 +00:00
|
|
|
file_idx = GetSupportFiles().FindFileIndex(1, *file_spec_ptr, true);
|
2010-06-08 16:52:24 +00:00
|
|
|
if (file_idx == UINT32_MAX)
|
|
|
|
|
return UINT32_MAX;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2010-06-08 16:52:24 +00:00
|
|
|
// All the line table entries actually point to the version of the Compile
|
2015-06-18 05:27:05 +00:00
|
|
|
// Unit that is in the support files (the one at 0 was artificially added.)
|
2010-06-08 16:52:24 +00:00
|
|
|
// So prefer the one further on in the support files if it exists...
|
2019-05-30 08:21:25 +00:00
|
|
|
const FileSpecList &support_files = GetSupportFiles();
|
2011-09-23 00:54:11 +00:00
|
|
|
const bool full = true;
|
|
|
|
|
file_idx = support_files.FindFileIndex(
|
|
|
|
|
1, support_files.GetFileSpecAtIndex(0), full);
|
2010-06-08 16:52:24 +00:00
|
|
|
if (file_idx == UINT32_MAX)
|
|
|
|
|
file_idx = 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
LineTable *line_table = GetLineTable();
|
|
|
|
|
if (line_table)
|
2011-09-23 00:54:11 +00:00
|
|
|
return line_table->FindLineEntryIndexByFileIndex(start_idx, file_idx, line,
|
|
|
|
|
exact, line_entry_ptr);
|
2010-06-08 16:52:24 +00:00
|
|
|
return UINT32_MAX;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
uint32_t CompileUnit::ResolveSymbolContext(const FileSpec &file_spec,
|
|
|
|
|
uint32_t line, bool check_inlines,
|
2018-10-25 20:45:19 +00:00
|
|
|
bool exact,
|
|
|
|
|
SymbolContextItem resolve_scope,
|
2010-06-08 16:52:24 +00:00
|
|
|
SymbolContextList &sc_list) {
|
2010-09-12 06:24:05 +00:00
|
|
|
// First find all of the file indexes that match our "file_spec". If
|
2018-04-30 16:49:04 +00:00
|
|
|
// "file_spec" has an empty directory, then only compare the basenames when
|
|
|
|
|
// finding file indexes
|
2010-09-12 06:24:05 +00:00
|
|
|
std::vector<uint32_t> file_indexes;
|
2013-10-03 22:27:29 +00:00
|
|
|
const bool full_match = (bool)file_spec.GetDirectory();
|
2014-11-15 01:54:26 +00:00
|
|
|
bool file_spec_matches_cu_file_spec =
|
2018-04-27 15:45:58 +00:00
|
|
|
FileSpec::Equal(file_spec, *this, full_match);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
// If we are not looking for inlined functions and our file spec doesn't
|
|
|
|
|
// match then we are done...
|
2018-12-15 00:15:33 +00:00
|
|
|
if (!file_spec_matches_cu_file_spec && !check_inlines)
|
2010-09-12 06:24:05 +00:00
|
|
|
return 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-11-15 01:54:26 +00:00
|
|
|
uint32_t file_idx =
|
2018-04-27 15:45:58 +00:00
|
|
|
GetSupportFiles().FindFileIndex(1, file_spec, true);
|
2010-09-12 06:24:05 +00:00
|
|
|
while (file_idx != UINT32_MAX) {
|
|
|
|
|
file_indexes.push_back(file_idx);
|
2018-04-27 15:45:58 +00:00
|
|
|
file_idx = GetSupportFiles().FindFileIndex(file_idx + 1, file_spec, true);
|
2010-09-12 06:24:05 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
const size_t num_file_indexes = file_indexes.size();
|
|
|
|
|
if (num_file_indexes == 0)
|
|
|
|
|
return 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
const uint32_t prev_size = sc_list.GetSize();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
SymbolContext sc(GetModule());
|
|
|
|
|
sc.comp_unit = this;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-04-20 13:17:36 +00:00
|
|
|
if (line != 0) {
|
2012-05-21 23:06:47 +00:00
|
|
|
LineTable *line_table = sc.comp_unit->GetLineTable();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
if (line_table != nullptr) {
|
|
|
|
|
uint32_t found_line;
|
|
|
|
|
uint32_t line_idx;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
if (num_file_indexes == 1) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// We only have a single support file that matches, so use the line
|
|
|
|
|
// table function that searches for a line entries that match a single
|
|
|
|
|
// support file index
|
2012-05-21 23:06:47 +00:00
|
|
|
LineEntry line_entry;
|
|
|
|
|
line_idx = line_table->FindLineEntryIndexByFileIndex(
|
|
|
|
|
0, file_indexes.front(), line, exact, &line_entry);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// If "exact == true", then "found_line" will be the same as "line". If
|
|
|
|
|
// "exact == false", the "found_line" will be the closest line entry
|
|
|
|
|
// with a line number greater than "line" and we will use this for our
|
|
|
|
|
// subsequent line exact matches below.
|
2012-05-21 23:06:47 +00:00
|
|
|
found_line = line_entry.line;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-14 02:20:48 +00:00
|
|
|
while (line_idx != UINT32_MAX) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If they only asked for the line entry, then we're done, we can
|
|
|
|
|
// just copy that over. But if they wanted more than just the line
|
|
|
|
|
// number, fill it in.
|
2012-05-21 23:06:47 +00:00
|
|
|
if (resolve_scope == eSymbolContextLineEntry) {
|
|
|
|
|
sc.line_entry = line_entry;
|
|
|
|
|
} else {
|
|
|
|
|
line_entry.range.GetBaseAddress().CalculateSymbolContext(
|
|
|
|
|
&sc, resolve_scope);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
sc_list.Append(sc);
|
2012-05-21 23:06:47 +00:00
|
|
|
line_idx = line_table->FindLineEntryIndexByFileIndex(
|
|
|
|
|
line_idx + 1, file_indexes.front(), found_line, true,
|
|
|
|
|
&line_entry);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2018-04-30 16:49:04 +00:00
|
|
|
// We found multiple support files that match "file_spec" so use the
|
|
|
|
|
// line table function that searches for a line entries that match a
|
|
|
|
|
// multiple support file indexes.
|
2012-05-21 23:06:47 +00:00
|
|
|
LineEntry line_entry;
|
|
|
|
|
line_idx = line_table->FindLineEntryIndexByFileIndex(
|
|
|
|
|
0, file_indexes, line, exact, &line_entry);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// If "exact == true", then "found_line" will be the same as "line". If
|
|
|
|
|
// "exact == false", the "found_line" will be the closest line entry
|
|
|
|
|
// with a line number greater than "line" and we will use this for our
|
|
|
|
|
// subsequent line exact matches below.
|
2012-05-21 23:06:47 +00:00
|
|
|
found_line = line_entry.line;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-09-14 02:20:48 +00:00
|
|
|
while (line_idx != UINT32_MAX) {
|
2012-05-21 23:06:47 +00:00
|
|
|
if (resolve_scope == eSymbolContextLineEntry) {
|
|
|
|
|
sc.line_entry = line_entry;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-05-21 23:06:47 +00:00
|
|
|
line_entry.range.GetBaseAddress().CalculateSymbolContext(
|
|
|
|
|
&sc, resolve_scope);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-12 06:24:05 +00:00
|
|
|
sc_list.Append(sc);
|
2012-05-21 23:06:47 +00:00
|
|
|
line_idx = line_table->FindLineEntryIndexByFileIndex(
|
|
|
|
|
line_idx + 1, file_indexes, found_line, true, &line_entry);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-09-12 06:24:05 +00:00
|
|
|
}
|
|
|
|
|
} else if (file_spec_matches_cu_file_spec && !check_inlines) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// only append the context if we aren't looking for inline call sites by
|
|
|
|
|
// file and line and if the file spec matches that of the compile unit
|
2010-09-12 06:24:05 +00:00
|
|
|
sc_list.Append(sc);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
return sc_list.GetSize() - prev_size;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 00:42:47 +00:00
|
|
|
bool CompileUnit::GetIsOptimized() {
|
2016-07-05 23:01:20 +00:00
|
|
|
if (m_is_optimized == eLazyBoolCalculate) {
|
|
|
|
|
m_is_optimized = eLazyBoolNo;
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
|
|
|
|
|
if (symfile->ParseIsOptimized(*this))
|
2016-07-05 23:01:20 +00:00
|
|
|
m_is_optimized = eLazyBoolYes;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-07-29 00:42:47 +00:00
|
|
|
return m_is_optimized;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void CompileUnit::SetVariableList(VariableListSP &variables) {
|
|
|
|
|
m_variables = variables;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 18:10:41 +00:00
|
|
|
const std::vector<SourceModule> &CompileUnit::GetImportedModules() {
|
2015-04-20 16:31:29 +00:00
|
|
|
if (m_imported_modules.empty() &&
|
|
|
|
|
m_flags.IsClear(flagsParsedImportedModules)) {
|
|
|
|
|
m_flags.Set(flagsParsedImportedModules);
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
|
2015-04-20 16:31:29 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
CalculateSymbolContext(&sc);
|
2019-08-06 09:12:42 +00:00
|
|
|
symfile->ParseImportedModules(sc, m_imported_modules);
|
2015-04-20 16:31:29 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-04-20 16:31:29 +00:00
|
|
|
return m_imported_modules;
|
|
|
|
|
}
|
|
|
|
|
|
[lldb] Decouple importing the std C++ module from the way the program is compiled
Summary:
At the moment, when trying to import the `std` module in LLDB, we look at the imported modules used in the compiled program
and try to infer the Clang configuration we need from the DWARF module-import. That was the initial idea but turned out to
cause a few problems or inconveniences:
* It requires that users compile their programs with C++ modules. Given how experimental C++ modules are makes this feature inaccessible
for many users. Also it means that people can't just get the benefits of this feature for free when we activate it by default
(and we can't just close all the associated bug reports).
* Relying on DWARF's imported module tags (that are only emitted by default on macOS) means this can only be used when using DWARF (and with -glldb on Linux).
* We essentially hardcoded the C standard library paths on some platforms (Linux) or just couldn't support this feature on other platforms (macOS).
This patch drops the whole idea of looking at the imported module DWARF tags and instead just uses the support files of the compilation unit.
If we look at the support files and see file paths that indicate where the C standard library and libc++ are, we can just create the module
configuration this information. This fixes all the problems above which means we can enable all the tests now on Linux, macOS and with other debug information
than what we currently had. The only debug information specific code is now the iteration over external type module when -gmodules is used (as `std` and also the
`Darwin` module are their own external type module with their own files).
The meat of this patch is the CppModuleConfiguration which looks at the file paths from the compilation unit and then figures out the include paths
based on those paths. It's quite conservative in that it only enables modules if we find a single C library and single libc++ library. It's still missing some
test mode where we try to compile an expression before we actually activate the config for the user (which probably also needs some caching mechanism),
but for now it works and makes the feature usable.
Reviewers: aprantl, shafik, jdoerfert
Reviewed By: aprantl
Subscribers: mgorny, abidh, JDevlieghere, lldb-commits
Tags: #c_modules_in_lldb, #lldb
Differential Revision: https://reviews.llvm.org/D67760
llvm-svn: 372716
2019-09-24 10:08:18 +00:00
|
|
|
void CompileUnit::ForEachExternalModule(llvm::function_ref<void(ModuleSP)> f) {
|
|
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile())
|
|
|
|
|
symfile->ForEachExternalModule(*this, f);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-30 08:21:25 +00:00
|
|
|
const FileSpecList &CompileUnit::GetSupportFiles() {
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_support_files.GetSize() == 0) {
|
|
|
|
|
if (m_flags.IsClear(flagsParsedSupportFiles)) {
|
|
|
|
|
m_flags.Set(flagsParsedSupportFiles);
|
2019-08-06 09:12:42 +00:00
|
|
|
if (SymbolFile *symfile = GetModule()->GetSymbolFile())
|
|
|
|
|
symfile->ParseSupportFiles(*this, m_support_files);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return m_support_files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *CompileUnit::GetUserData() const { return m_user_data; }
|