aboutsummaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Core/Module.h6
-rw-r--r--lldb/include/lldb/Symbol/Type.h4
-rw-r--r--lldb/include/lldb/Utility/StreamString.h2
-rw-r--r--lldb/source/Core/Module.cpp17
-rw-r--r--lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp51
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp35
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp57
-rw-r--r--lldb/source/Plugins/Language/CPlusPlus/LibCxx.h8
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp44
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp11
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp4
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp32
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/DecodedThread.h26
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp4
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp4
-rw-r--r--lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp13
-rw-r--r--lldb/source/Symbol/Type.cpp4
-rw-r--r--lldb/source/Target/ProcessTrace.cpp2
-rw-r--r--lldb/source/Utility/StreamString.cpp2
19 files changed, 232 insertions, 94 deletions
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index f4973cdda1ef..0188057247a6 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -337,6 +337,12 @@ public:
const ModuleFunctionSearchOptions &options,
SymbolContextList &sc_list);
+ /// Find functions by compiler context.
+ void FindFunctions(llvm::ArrayRef<CompilerContext> compiler_ctx,
+ lldb::FunctionNameType name_type_mask,
+ const ModuleFunctionSearchOptions &options,
+ SymbolContextList &sc_list);
+
/// Find functions by name.
///
/// If the function is an inlined function, it will have a block,
diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index 307be6c55e01..acd1a769f13c 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -247,6 +247,10 @@ public:
/// match.
void AddLanguage(lldb::LanguageType language);
+ /// Set the list of languages that should produce a match to only the ones
+ /// specified in \ref languages.
+ void SetLanguages(LanguageSet languages);
+
/// Check if the language matches any languages that have been added to this
/// match object.
///
diff --git a/lldb/include/lldb/Utility/StreamString.h b/lldb/include/lldb/Utility/StreamString.h
index 4c568acdcc6f..3d675caf8f3f 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -22,7 +22,7 @@ namespace lldb_private {
class StreamString : public Stream {
public:
- StreamString();
+ StreamString(bool colors = false);
StreamString(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index c0574b724ace..331cf3246641 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -855,6 +855,23 @@ void Module::FindFunctions(ConstString name,
}
}
+void Module::FindFunctions(llvm::ArrayRef<CompilerContext> compiler_ctx,
+ FunctionNameType name_type_mask,
+ const ModuleFunctionSearchOptions &options,
+ SymbolContextList &sc_list) {
+ if (compiler_ctx.empty() ||
+ compiler_ctx.back().kind != CompilerContextKind::Function)
+ return;
+ ConstString name = compiler_ctx.back().name;
+ SymbolContextList unfiltered;
+ FindFunctions(name, CompilerDeclContext(), name_type_mask, options,
+ unfiltered);
+ // Filter by context.
+ for (auto &sc : unfiltered)
+ if (sc.function && compiler_ctx.equals(sc.function->GetCompilerContext()))
+ sc_list.Append(sc);
+}
+
void Module::FindFunctions(const RegularExpression &regex,
const ModuleFunctionSearchOptions &options,
SymbolContextList &sc_list) {
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 5d109feb3d39..62a30c14912b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -943,44 +943,41 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
// the class was originally sourced from symbols.
if (ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to)) {
- do {
- ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
+ ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
- if (to_superclass)
- break; // we're not going to override it if it's set
+ if (to_superclass)
+ return; // we're not going to override it if it's set
- ObjCInterfaceDecl *from_objc_interface =
- dyn_cast<ObjCInterfaceDecl>(from);
+ ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from);
- if (!from_objc_interface)
- break;
+ if (!from_objc_interface)
+ return;
- ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
+ ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
- if (!from_superclass)
- break;
+ if (!from_superclass)
+ return;
- llvm::Expected<Decl *> imported_from_superclass_decl =
- Import(from_superclass);
+ llvm::Expected<Decl *> imported_from_superclass_decl =
+ Import(from_superclass);
- if (!imported_from_superclass_decl) {
- LLDB_LOG_ERROR(log, imported_from_superclass_decl.takeError(),
- "Couldn't import decl: {0}");
- break;
- }
+ if (!imported_from_superclass_decl) {
+ LLDB_LOG_ERROR(log, imported_from_superclass_decl.takeError(),
+ "Couldn't import decl: {0}");
+ return;
+ }
- ObjCInterfaceDecl *imported_from_superclass =
- dyn_cast<ObjCInterfaceDecl>(*imported_from_superclass_decl);
+ ObjCInterfaceDecl *imported_from_superclass =
+ dyn_cast<ObjCInterfaceDecl>(*imported_from_superclass_decl);
- if (!imported_from_superclass)
- break;
+ if (!imported_from_superclass)
+ return;
- if (!to_objc_interface->hasDefinition())
- to_objc_interface->startDefinition();
+ if (!to_objc_interface->hasDefinition())
+ to_objc_interface->startDefinition();
- to_objc_interface->setSuperClass(m_source_ctx->getTrivialTypeSourceInfo(
- m_source_ctx->getObjCInterfaceType(imported_from_superclass)));
- } while (false);
+ to_objc_interface->setSuperClass(m_source_ctx->getTrivialTypeSourceInfo(
+ m_source_ctx->getObjCInterfaceType(imported_from_superclass)));
}
}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 586cc08a6f12..c6937ebca319 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1031,6 +1031,41 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
"^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
TypeSummaryImplSP(new StringSummaryFormat(
eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
+
+ // Chrono calendar types
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::day$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "day=${var.__d_%u}")));
+ AddCXXSummary(cpp_category_sp,
+ lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
+ "libc++ std::chrono::month summary provider",
+ "^std::__[[:alnum:]]+::chrono::month$",
+ eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::year$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(
+ eTypeOptionHideChildren | eTypeOptionHideValue, "year=${var.__y_}")));
+
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__m_} ${var.__d_}")));
+ cpp_category_sp->AddTypeSummary(
+ "^std::__[[:alnum:]]+::chrono::month_day_last$", eFormatterMatchRegex,
+ TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+ eTypeOptionHideValue,
+ "${var.__m_} day=last")));
+ AddCXXSummary(
+ cpp_category_sp,
+ lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
+ "libc++ std::chrono::year_month_day summary provider",
+ "^std::__[[:alnum:]]+::chrono::year_month_day$",
+ eTypeOptionHideChildren | eTypeOptionHideValue, true);
}
static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index cae17ef992b2..f8be4f785dc4 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1084,3 +1084,60 @@ bool lldb_private::formatters::LibcxxWStringViewSummaryProvider(
return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
dataobj, size);
}
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+ // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
+ // uses C++17 it's not possible to use the ostream operator directly.
+ static const std::array<std::string_view, 12> months = {
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"};
+
+ ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__m_");
+ if (!ptr_sp)
+ return false;
+
+ const unsigned month = ptr_sp->GetValueAsUnsigned(0);
+ if (month >= 1 && month <= 12)
+ stream << "month=" << months[month - 1];
+ else
+ stream.Printf("month=%u", month);
+
+ return true;
+}
+
+bool lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider(
+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+ ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__y_");
+ if (!ptr_sp)
+ return false;
+ ptr_sp = ptr_sp->GetChildMemberWithName("__y_");
+ if (!ptr_sp)
+ return false;
+ int year = ptr_sp->GetValueAsSigned(0);
+
+ ptr_sp = valobj.GetChildMemberWithName("__m_");
+ if (!ptr_sp)
+ return false;
+ ptr_sp = ptr_sp->GetChildMemberWithName("__m_");
+ if (!ptr_sp)
+ return false;
+ const unsigned month = ptr_sp->GetValueAsUnsigned(0);
+
+ ptr_sp = valobj.GetChildMemberWithName("__d_");
+ if (!ptr_sp)
+ return false;
+ ptr_sp = ptr_sp->GetChildMemberWithName("__d_");
+ if (!ptr_sp)
+ return false;
+ const unsigned day = ptr_sp->GetValueAsUnsigned(0);
+
+ stream << "date=";
+ if (year < 0) {
+ stream << '-';
+ year = -year;
+ }
+ stream.Printf("%04d-%02u-%02u", year, month, day);
+
+ return true;
+}
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index f65801e2cb1b..c252ae382dd9 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -261,6 +261,14 @@ SyntheticChildrenFrontEnd *
LibcxxStdRangesRefViewSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
+bool LibcxxChronoMonthSummaryProvider(
+ ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options); // libc++ std::chrono::month
+
+bool LibcxxChronoYearMonthDaySummaryProvider(
+ ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options); // libc++ std::chrono::year_month_day
+
} // namespace formatters
} // namespace lldb_private
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index bed68f45426f..d4446befd83b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -373,44 +373,51 @@ std::vector<DWARFDIE> DWARFDIE::GetDeclContextDIEs() const {
return result;
}
-std::vector<lldb_private::CompilerContext> DWARFDIE::GetDeclContext() const {
+static std::vector<lldb_private::CompilerContext>
+GetDeclContextImpl(llvm::SmallSet<lldb::user_id_t, 4> &seen, DWARFDIE die) {
std::vector<lldb_private::CompilerContext> context;
- const dw_tag_t tag = Tag();
- if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
+ // Stop if we hit a cycle.
+ if (!die || !seen.insert(die.GetID()).second)
return context;
- DWARFDIE parent = GetParent();
- if (parent)
- context = parent.GetDeclContext();
+
+ // Handle outline member function DIEs by following the specification.
+ if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_specification))
+ return GetDeclContextImpl(seen, spec);
+
+ // Get the parent context chain.
+ context = GetDeclContextImpl(seen, die.GetParent());
+
+ // Add this DIE's contribution at the end of the chain.
auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
context.push_back({kind, ConstString(name)});
};
- switch (tag) {
+ switch (die.Tag()) {
case DW_TAG_module:
- push_ctx(CompilerContextKind::Module, GetName());
+ push_ctx(CompilerContextKind::Module, die.GetName());
break;
case DW_TAG_namespace:
- push_ctx(CompilerContextKind::Namespace, GetName());
+ push_ctx(CompilerContextKind::Namespace, die.GetName());
break;
case DW_TAG_structure_type:
- push_ctx(CompilerContextKind::Struct, GetName());
+ push_ctx(CompilerContextKind::Struct, die.GetName());
break;
case DW_TAG_union_type:
- push_ctx(CompilerContextKind::Union, GetName());
+ push_ctx(CompilerContextKind::Union, die.GetName());
break;
case DW_TAG_class_type:
- push_ctx(CompilerContextKind::Class, GetName());
+ push_ctx(CompilerContextKind::Class, die.GetName());
break;
case DW_TAG_enumeration_type:
- push_ctx(CompilerContextKind::Enum, GetName());
+ push_ctx(CompilerContextKind::Enum, die.GetName());
break;
case DW_TAG_subprogram:
- push_ctx(CompilerContextKind::Function, GetPubname());
+ push_ctx(CompilerContextKind::Function, die.GetName());
break;
case DW_TAG_variable:
- push_ctx(CompilerContextKind::Variable, GetPubname());
+ push_ctx(CompilerContextKind::Variable, die.GetPubname());
break;
case DW_TAG_typedef:
- push_ctx(CompilerContextKind::Typedef, GetName());
+ push_ctx(CompilerContextKind::Typedef, die.GetName());
break;
default:
break;
@@ -418,6 +425,11 @@ std::vector<lldb_private::CompilerContext> DWARFDIE::GetDeclContext() const {
return context;
}
+std::vector<lldb_private::CompilerContext> DWARFDIE::GetDeclContext() const {
+ llvm::SmallSet<lldb::user_id_t, 4> seen;
+ return GetDeclContextImpl(seen, *this);
+}
+
std::vector<lldb_private::CompilerContext>
DWARFDIE::GetTypeLookupContext() const {
std::vector<lldb_private::CompilerContext> context;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 737da7798b82..1a16b70f42fe 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2574,11 +2574,12 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
Module::LookupInfo no_tp_lookup_info(lookup_info);
no_tp_lookup_info.SetLookupName(ConstString(name_no_template_params));
- m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) {
- if (resolved_dies.insert(die.GetDIE()).second)
- ResolveFunction(die, include_inlines, sc_list);
- return true;
- });
+ m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx,
+ [&](DWARFDIE die) {
+ if (resolved_dies.insert(die.GetDIE()).second)
+ ResolveFunction(die, include_inlines, sc_list);
+ return true;
+ });
}
}
diff --git a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index d4f7dc354e9f..44224229e625 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -158,7 +158,7 @@ CommandObjectProcessTraceStartIntelPT::CommandOptions::GetDefinitions() {
return llvm::ArrayRef(g_process_trace_start_intel_pt_options);
}
-bool CommandObjectProcessTraceStartIntelPT::DoExecute(
+void CommandObjectProcessTraceStartIntelPT::DoExecute(
Args &command, CommandReturnObject &result) {
if (Error err = m_trace.Start(
m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
@@ -167,8 +167,6 @@ bool CommandObjectProcessTraceStartIntelPT::DoExecute(
result.SetError(Status(std::move(err)));
else
result.SetStatus(eReturnStatusSuccessFinishResult);
-
- return result.Succeeded();
}
std::optional<uint64_t>
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
index 17f8f51bdf0e..9c075398d547 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -85,11 +85,11 @@ double DecodedThread::NanosecondsRange::GetInterpolatedTime(
return interpolate(next_range->nanos);
}
-uint64_t DecodedThread::GetItemsCount() const { return m_item_kinds.size(); }
+uint64_t DecodedThread::GetItemsCount() const { return m_item_data.size(); }
lldb::addr_t
DecodedThread::GetInstructionLoadAddress(uint64_t item_index) const {
- return m_item_data[item_index].load_address;
+ return std::get<lldb::addr_t>(m_item_data[item_index]);
}
lldb::addr_t
@@ -99,14 +99,16 @@ DecodedThread::GetSyncPointOffsetByIndex(uint64_t item_index) const {
ThreadSP DecodedThread::GetThread() { return m_thread_sp; }
+template <typename Data>
DecodedThread::TraceItemStorage &
-DecodedThread::CreateNewTraceItem(lldb::TraceItemKind kind) {
- m_item_kinds.push_back(kind);
- m_item_data.emplace_back();
+DecodedThread::CreateNewTraceItem(lldb::TraceItemKind kind, Data &&data) {
+ m_item_data.emplace_back(data);
+
if (m_last_tsc)
(*m_last_tsc)->second.items_count++;
if (m_last_nanoseconds)
(*m_last_nanoseconds)->second.items_count++;
+
return m_item_data.back();
}
@@ -176,27 +178,27 @@ uint64_t DecodedThread::GetTotalInstructionCount() const {
}
void DecodedThread::AppendEvent(lldb::TraceEvent event) {
- CreateNewTraceItem(lldb::eTraceItemKindEvent).event = event;
+ CreateNewTraceItem(lldb::eTraceItemKindEvent, event);
m_events_stats.RecordEvent(event);
}
void DecodedThread::AppendInstruction(const pt_insn &insn) {
- CreateNewTraceItem(lldb::eTraceItemKindInstruction).load_address = insn.ip;
+ CreateNewTraceItem(lldb::eTraceItemKindInstruction, insn.ip);
m_insn_count++;
}
void DecodedThread::AppendError(const IntelPTError &error) {
- CreateNewTraceItem(lldb::eTraceItemKindError).error = error.message();
+ CreateNewTraceItem(lldb::eTraceItemKindError, error.message());
m_error_stats.RecordError(/*fatal=*/false);
}
void DecodedThread::AppendCustomError(StringRef err, bool fatal) {
- CreateNewTraceItem(lldb::eTraceItemKindError).error = err.str();
+ CreateNewTraceItem(lldb::eTraceItemKindError, err.str());
m_error_stats.RecordError(fatal);
}
lldb::TraceEvent DecodedThread::GetEventByIndex(int item_index) const {
- return m_item_data[item_index].event;
+ return std::get<lldb::TraceEvent>(m_item_data[item_index]);
}
const DecodedThread::EventsStats &DecodedThread::GetEventsStats() const {
@@ -233,13 +235,18 @@ const DecodedThread::ErrorStats &DecodedThread::GetErrorStats() const {
lldb::TraceItemKind
DecodedThread::GetItemKindByIndex(uint64_t item_index) const {
- return static_cast<lldb::TraceItemKind>(m_item_kinds[item_index]);
+ return std::visit(
+ llvm::makeVisitor(
+ [](const std::string &) { return lldb::eTraceItemKindError; },
+ [](lldb::TraceEvent) { return lldb::eTraceItemKindEvent; },
+ [](lldb::addr_t) { return lldb::eTraceItemKindInstruction; }),
+ m_item_data[item_index]);
}
llvm::StringRef DecodedThread::GetErrorByIndex(uint64_t item_index) const {
if (item_index >= m_item_data.size())
return llvm::StringRef();
- return m_item_data[item_index].error;
+ return std::get<std::string>(m_item_data[item_index]);
}
DecodedThread::DecodedThread(
@@ -249,7 +256,6 @@ DecodedThread::DecodedThread(
size_t DecodedThread::CalculateApproximateMemoryUsage() const {
return sizeof(TraceItemStorage) * m_item_data.size() +
- sizeof(uint8_t) * m_item_kinds.size() +
(sizeof(uint64_t) + sizeof(TSC)) * m_tscs.size() +
(sizeof(uint64_t) + sizeof(uint64_t)) * m_nanoseconds.size() +
(sizeof(uint64_t) + sizeof(lldb::cpu_id_t)) * m_cpus.size();
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
index 5745cdb67ab6..a48c55cc76df 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -14,9 +14,10 @@
#include "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
+#include <deque>
#include <optional>
#include <utility>
-#include <vector>
+#include <variant>
namespace lldb_private {
namespace trace_intel_pt {
@@ -265,30 +266,19 @@ private:
/// to update \a CalculateApproximateMemoryUsage() accordingly.
lldb::ThreadSP m_thread_sp;
- /// We use a union to optimize the memory usage for the different kinds of
- /// trace items.
- union TraceItemStorage {
- /// The load addresses of this item if it's an instruction.
- uint64_t load_address;
-
- /// The event kind of this item if it's an event
- lldb::TraceEvent event;
-
- /// The string message of this item if it's an error
- std::string error;
- };
+ using TraceItemStorage =
+ std::variant<std::string, lldb::TraceEvent, lldb::addr_t>;
/// Create a new trace item.
///
/// \return
/// The index of the new item.
- DecodedThread::TraceItemStorage &CreateNewTraceItem(lldb::TraceItemKind kind);
+ template <typename Data>
+ DecodedThread::TraceItemStorage &CreateNewTraceItem(lldb::TraceItemKind kind,
+ Data &&data);
/// Most of the trace data is stored here.
- std::vector<TraceItemStorage> m_item_data;
- /// The TraceItemKind for each trace item encoded as uint8_t. We don't include
- /// it in TraceItemStorage to avoid padding.
- std::vector<uint8_t> m_item_kinds;
+ std::deque<TraceItemStorage> m_item_data;
/// This map contains the TSCs of the decoded trace items. It maps
/// `item index -> TSC`, where `item index` is the first index
diff --git a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
index cdf81954eee9..f8241ef6a793 100644
--- a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
@@ -572,7 +572,7 @@ Error lldb_private::trace_intel_pt::DecodeSingleTraceForThread(
Expected<PSBBlockDecoder> decoder = PSBBlockDecoder::Create(
trace_intel_pt, block, buffer.slice(block.psb_offset, block.size),
*decoded_thread.GetThread()->GetProcess(),
- i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : None,
+ i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : std::nullopt,
decoded_thread, std::nullopt);
if (!decoder)
return decoder.takeError();
@@ -640,7 +640,7 @@ Error lldb_private::trace_intel_pt::DecodeSystemWideTraceForThread(
*decoded_thread.GetThread()->GetProcess(),
j + 1 < execution.psb_blocks.size()
? execution.psb_blocks[j + 1].starting_ip
- : None,
+ : std::nullopt,
decoded_thread, execution.thread_execution.GetEndTSC());
if (!decoder)
return decoder.takeError();
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
index 66d342196cf1..dda6cd74343f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -35,7 +35,7 @@ void TraceCursorIntelPT::Next() {
void TraceCursorIntelPT::ClearTimingRangesIfInvalid() {
if (m_tsc_range_calculated) {
if (!m_tsc_range || m_pos < 0 || !m_tsc_range->InRange(m_pos)) {
- m_tsc_range = None;
+ m_tsc_range = std::nullopt;
m_tsc_range_calculated = false;
}
}
@@ -43,7 +43,7 @@ void TraceCursorIntelPT::ClearTimingRangesIfInvalid() {
if (m_nanoseconds_range_calculated) {
if (!m_nanoseconds_range || m_pos < 0 ||
!m_nanoseconds_range->InRange(m_pos)) {
- m_nanoseconds_range = None;
+ m_nanoseconds_range = std::nullopt;
m_nanoseconds_range_calculated = false;
}
}
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp
index bd9cca675f2d..1a9f6fe30509 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp
@@ -15,6 +15,7 @@
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/ProcessTrace.h"
#include "lldb/Target/Target.h"
#include <optional>
@@ -103,11 +104,11 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t pid,
ParsedProcess parsed_process;
parsed_process.target_sp = target_sp;
- // This should instead try to directly create an instance of ProcessTrace.
- // ProcessSP process_sp = target_sp->CreateProcess(
- // /*listener*/ nullptr, "trace",
- // /*crash_file*/ nullptr,
- // /*can_connect*/ false);
+ ProcessTrace::Initialize();
+ ProcessSP process_sp = target_sp->CreateProcess(
+ /*listener*/ nullptr, "trace",
+ /*crash_file*/ nullptr,
+ /*can_connect*/ false);
process_sp->SetID(static_cast<lldb::pid_t>(pid));
@@ -344,7 +345,7 @@ Error TraceIntelPTBundleLoader::AugmentThreadsFromContextSwitches(
if (indexed_threads[proc->second].count(tid))
return;
indexed_threads[proc->second].insert(tid);
- proc->second->threads.push_back({tid, /*ipt_trace=*/None});
+ proc->second->threads.push_back({tid, /*ipt_trace=*/std::nullopt});
};
for (const JSONCpu &cpu : *bundle_description.cpus) {
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 293fe1b78f4a..6069d066eaf6 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -145,6 +145,10 @@ void TypeQuery::AddLanguage(LanguageType language) {
m_languages->Insert(language);
}
+void TypeQuery::SetLanguages(LanguageSet languages) {
+ m_languages = std::move(languages);
+}
+
bool TypeQuery::ContextMatches(
llvm::ArrayRef<CompilerContext> context_chain) const {
if (GetExactMatch() || context_chain.size() == m_context.size())
diff --git a/lldb/source/Target/ProcessTrace.cpp b/lldb/source/Target/ProcessTrace.cpp
index 6e5ef6a379f9..3a41f257627c 100644
--- a/lldb/source/Target/ProcessTrace.cpp
+++ b/lldb/source/Target/ProcessTrace.cpp
@@ -20,6 +20,8 @@
using namespace lldb;
using namespace lldb_private;
+LLDB_PLUGIN_DEFINE(ProcessTrace)
+
llvm::StringRef ProcessTrace::GetPluginDescriptionStatic() {
return "Trace process plug-in.";
}
diff --git a/lldb/source/Utility/StreamString.cpp b/lldb/source/Utility/StreamString.cpp
index 745a85b75765..0d35ccbdbbd0 100644
--- a/lldb/source/Utility/StreamString.cpp
+++ b/lldb/source/Utility/StreamString.cpp
@@ -11,7 +11,7 @@
using namespace lldb;
using namespace lldb_private;
-StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
+StreamString::StreamString(bool colors) : Stream(0, 4, eByteOrderBig, colors) {}
StreamString::StreamString(uint32_t flags, uint32_t addr_size,
ByteOrder byte_order)