https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/77999
>From dcc17c06960845deccfcd0efe78434110c2add9e Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Fri, 12 Jan 2024 15:20:12 -0800 Subject: [PATCH] [lldb] Store SupportFile in LineEntry (NFC) Store a SupportFile, rather than a FileSpec, in LineEntry. This commit works towards having the SourceManageroperate on SupportFiles so that it can (1) validate the Checksum and (2) materialize the content of inline source information. --- lldb/include/lldb/Symbol/LineEntry.h | 4 +++- lldb/include/lldb/Utility/FileSpecList.h | 3 ++- lldb/include/lldb/Utility/SupportFile.h | 5 ++++- lldb/include/lldb/lldb-forward.h | 2 ++ lldb/source/Breakpoint/BreakpointResolver.cpp | 3 ++- lldb/source/Commands/CommandObjectSource.cpp | 4 ++-- lldb/source/Core/Disassembler.cpp | 5 +++-- lldb/source/Symbol/LineEntry.cpp | 10 +++++----- lldb/source/Symbol/LineTable.cpp | 12 ++++++------ lldb/source/Symbol/SymbolContext.cpp | 5 +++-- lldb/source/Target/ThreadPlanStepOverRange.cpp | 12 ++++++------ lldb/source/Target/ThreadPlanStepRange.cpp | 4 ++-- 12 files changed, 40 insertions(+), 29 deletions(-) diff --git a/lldb/include/lldb/Symbol/LineEntry.h b/lldb/include/lldb/Symbol/LineEntry.h index 1c7a9030a97932..c2daba916e3f98 100644 --- a/lldb/include/lldb/Symbol/LineEntry.h +++ b/lldb/include/lldb/Symbol/LineEntry.h @@ -11,6 +11,7 @@ #include "lldb/Core/AddressRange.h" #include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/SupportFile.h" #include "lldb/lldb-private.h" namespace lldb_private { @@ -133,7 +134,8 @@ struct LineEntry { AddressRange range; ///< The section offset address range for this line entry. FileSpec file; ///< The source file, possibly mapped by the target.source-map ///setting - FileSpec original_file; ///< The original source file, from debug info. + lldb::SupportFileSP + original_file_sp; ///< The original source file, from debug info. uint32_t line = LLDB_INVALID_LINE_NUMBER; ///< The source line number, or zero ///< if there is no line number /// information. diff --git a/lldb/include/lldb/Utility/FileSpecList.h b/lldb/include/lldb/Utility/FileSpecList.h index 9edff64a4bd081..49edc667ddd5b6 100644 --- a/lldb/include/lldb/Utility/FileSpecList.h +++ b/lldb/include/lldb/Utility/FileSpecList.h @@ -11,6 +11,7 @@ #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/SupportFile.h" +#include "lldb/lldb-forward.h" #include <cstddef> #include <vector> @@ -40,7 +41,7 @@ class SupportFileList { bool AppendIfUnique(const FileSpec &file); size_t GetSize() const { return m_files.size(); } const FileSpec &GetFileSpecAtIndex(size_t idx) const; - std::shared_ptr<SupportFile> GetSupportFileAtIndex(size_t idx) const; + lldb::SupportFileSP GetSupportFileAtIndex(size_t idx) const; size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const; /// Find a compatible file index. /// diff --git a/lldb/include/lldb/Utility/SupportFile.h b/lldb/include/lldb/Utility/SupportFile.h index 5156b3e72b32d4..0ea0ca4e7c97a1 100644 --- a/lldb/include/lldb/Utility/SupportFile.h +++ b/lldb/include/lldb/Utility/SupportFile.h @@ -20,6 +20,7 @@ namespace lldb_private { /// file yet. This also stores an optional checksum of the on-disk content. class SupportFile { public: + SupportFile() : m_file_spec(), m_checksum() {} SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {} SupportFile(const FileSpec &spec, const Checksum &checksum) : m_file_spec(spec), m_checksum(checksum) {} @@ -29,10 +30,12 @@ class SupportFile { virtual ~SupportFile() = default; - bool operator==(const SupportFile &other) { + bool operator==(const SupportFile &other) const { return m_file_spec == other.m_file_spec && m_checksum == other.m_checksum; } + bool operator!=(const SupportFile &other) const { return !(*this == other); } + /// Return the file name only. Useful for resolving breakpoints by file name. const FileSpec &GetSpecOnly() const { return m_file_spec; }; diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 4e0c62fa26cae4..d89ad21512215f 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -212,6 +212,7 @@ class StringList; class StringTableReader; class StructuredDataImpl; class StructuredDataPlugin; +class SupportFile; class Symbol; class SymbolContext; class SymbolContextList; @@ -462,6 +463,7 @@ typedef std::shared_ptr<lldb_private::TypeSummaryImpl> TypeSummaryImplSP; typedef std::shared_ptr<lldb_private::TypeSummaryOptions> TypeSummaryOptionsSP; typedef std::shared_ptr<lldb_private::ScriptedSyntheticChildren> ScriptedSyntheticChildrenSP; +typedef std::shared_ptr<lldb_private::SupportFile> SupportFileSP; typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP; typedef std::weak_ptr<lldb_private::UnixSignals> UnixSignalsWP; typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP; diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp index 89ea308b1eb070..bc6348716ef418 100644 --- a/lldb/source/Breakpoint/BreakpointResolver.cpp +++ b/lldb/source/Breakpoint/BreakpointResolver.cpp @@ -214,7 +214,8 @@ void BreakpointResolver::SetSCMatchesByLine( auto worklist_begin = std::partition( all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) { if (sc.line_entry.file == match.line_entry.file || - sc.line_entry.original_file == match.line_entry.original_file) { + *sc.line_entry.original_file_sp == + *match.line_entry.original_file_sp) { // When a match is found, keep track of the smallest line number. closest_line = std::min(closest_line, sc.line_entry.line); return false; diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index cabf6f0436f176..fde74f02aea644 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -747,13 +747,13 @@ class CommandObjectSourceList : public CommandObjectParsed { bool operator==(const SourceInfo &rhs) const { return function == rhs.function && - line_entry.original_file == rhs.line_entry.original_file && + *line_entry.original_file_sp == *rhs.line_entry.original_file_sp && line_entry.line == rhs.line_entry.line; } bool operator!=(const SourceInfo &rhs) const { return function != rhs.function || - line_entry.original_file != rhs.line_entry.original_file || + *line_entry.original_file_sp != *rhs.line_entry.original_file_sp || line_entry.line != rhs.line_entry.line; } diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp index 166b5fdf22f0b4..7b07fcb2681307 100644 --- a/lldb/source/Core/Disassembler.cpp +++ b/lldb/source/Core/Disassembler.cpp @@ -202,7 +202,7 @@ Disassembler::GetFunctionDeclLineEntry(const SymbolContext &sc) { sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line); if (func_decl_file != prologue_end_line.file && - func_decl_file != prologue_end_line.original_file) + func_decl_file != prologue_end_line.original_file_sp->GetSpecOnly()) return {}; SourceLine decl_line; @@ -407,7 +407,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch, sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line); if (func_decl_file == prologue_end_line.file || - func_decl_file == prologue_end_line.original_file) { + func_decl_file == + prologue_end_line.original_file_sp->GetSpecOnly()) { // Add all the lines between the function declaration and // the first non-prologue source line to the list of lines // to print. diff --git a/lldb/source/Symbol/LineEntry.cpp b/lldb/source/Symbol/LineEntry.cpp index e89d1fd1f479bc..389f8dcb65d8d8 100644 --- a/lldb/source/Symbol/LineEntry.cpp +++ b/lldb/source/Symbol/LineEntry.cpp @@ -20,7 +20,7 @@ LineEntry::LineEntry() void LineEntry::Clear() { range.Clear(); file.Clear(); - original_file.Clear(); + original_file_sp = std::make_shared<SupportFile>(); line = LLDB_INVALID_LINE_NUMBER; column = 0; is_start_of_statement = 0; @@ -182,7 +182,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange( // different file / line number. AddressRange complete_line_range = range; auto symbol_context_scope = lldb::eSymbolContextLineEntry; - Declaration start_call_site(original_file, line); + Declaration start_call_site(original_file_sp->GetSpecOnly(), line); if (include_inlined_functions) symbol_context_scope |= lldb::eSymbolContextBlock; @@ -196,7 +196,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange( next_line_sc.line_entry.range.GetByteSize() == 0) break; - if (original_file == next_line_sc.line_entry.original_file && + if (*original_file_sp == *next_line_sc.line_entry.original_file_sp && (next_line_sc.line_entry.line == 0 || line == next_line_sc.line_entry.line)) { // Include any line 0 entries - they indicate that this is compiler- @@ -240,8 +240,8 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange( void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) { if (target_sp) { // Apply any file remappings to our file. - if (auto new_file_spec = - target_sp->GetSourcePathMap().FindFile(original_file)) + if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile( + original_file_sp->GetSpecOnly())) file = *new_file_spec; } } diff --git a/lldb/source/Symbol/LineTable.cpp b/lldb/source/Symbol/LineTable.cpp index abe4c98d592878..444135f63bc0c9 100644 --- a/lldb/source/Symbol/LineTable.cpp +++ b/lldb/source/Symbol/LineTable.cpp @@ -290,8 +290,8 @@ bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx, line_entry.file = m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); - line_entry.original_file = - m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); + line_entry.original_file_sp = + m_comp_unit->GetSupportFiles().GetSupportFileAtIndex(entry.file_idx); line_entry.line = entry.line; line_entry.column = entry.column; line_entry.is_start_of_statement = entry.is_start_of_statement; @@ -357,13 +357,13 @@ void LineTable::Dump(Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_line_ranges) { const size_t count = m_entries.size(); LineEntry line_entry; - FileSpec prev_file; + SupportFileSP prev_file; for (size_t idx = 0; idx < count; ++idx) { ConvertEntryAtIndexToLineEntry(idx, line_entry); - line_entry.Dump(s, target, prev_file != line_entry.original_file, style, - fallback_style, show_line_ranges); + line_entry.Dump(s, target, *prev_file != *line_entry.original_file_sp, + style, fallback_style, show_line_ranges); s->EOL(); - prev_file = line_entry.original_file; + prev_file = line_entry.original_file_sp; } } diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index 9fd40b5ca567f8..d581c90cede7d3 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/lldb/source/Symbol/SymbolContext.cpp @@ -489,8 +489,9 @@ bool SymbolContext::GetParentOfInlinedScope(const Address &curr_frame_pc, next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc; next_frame_sc.line_entry.file = curr_inlined_block_inlined_info->GetCallSite().GetFile(); - next_frame_sc.line_entry.original_file = - curr_inlined_block_inlined_info->GetCallSite().GetFile(); + next_frame_sc.line_entry.original_file_sp = + std::make_shared<SupportFile>( + curr_inlined_block_inlined_info->GetCallSite().GetFile()); next_frame_sc.line_entry.line = curr_inlined_block_inlined_info->GetCallSite().GetLine(); next_frame_sc.line_entry.column = diff --git a/lldb/source/Target/ThreadPlanStepOverRange.cpp b/lldb/source/Target/ThreadPlanStepOverRange.cpp index b1cb070e0a3d0c..84f282f1de5207 100644 --- a/lldb/source/Target/ThreadPlanStepOverRange.cpp +++ b/lldb/source/Target/ThreadPlanStepOverRange.cpp @@ -220,8 +220,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) { StackFrameSP frame_sp = thread.GetStackFrameAtIndex(0); sc = frame_sp->GetSymbolContext(eSymbolContextEverything); if (sc.line_entry.IsValid()) { - if (sc.line_entry.original_file != - m_addr_context.line_entry.original_file && + if (*sc.line_entry.original_file_sp != + *m_addr_context.line_entry.original_file_sp && sc.comp_unit == m_addr_context.comp_unit && sc.function == m_addr_context.function) { // Okay, find the next occurrence of this file in the line table: @@ -244,8 +244,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) { LineEntry prev_line_entry; if (line_table->GetLineEntryAtIndex(entry_idx - 1, prev_line_entry) && - prev_line_entry.original_file == - line_entry.original_file) { + *prev_line_entry.original_file_sp == + *line_entry.original_file_sp) { SymbolContext prev_sc; Address prev_address = prev_line_entry.range.GetBaseAddress(); @@ -279,8 +279,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) { if (next_line_function != m_addr_context.function) break; - if (next_line_entry.original_file == - m_addr_context.line_entry.original_file) { + if (*next_line_entry.original_file_sp == + *m_addr_context.line_entry.original_file_sp) { const bool abort_other_plans = false; const RunMode stop_other_threads = RunMode::eAllThreads; lldb::addr_t cur_pc = thread.GetStackFrameAtIndex(0) diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp index bb92adcae78b71..998e76cb65d137 100644 --- a/lldb/source/Target/ThreadPlanStepRange.cpp +++ b/lldb/source/Target/ThreadPlanStepRange.cpp @@ -120,8 +120,8 @@ bool ThreadPlanStepRange::InRange() { frame->GetSymbolContext(eSymbolContextEverything)); if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid()) { - if (m_addr_context.line_entry.original_file == - new_context.line_entry.original_file) { + if (*m_addr_context.line_entry.original_file_sp == + *new_context.line_entry.original_file_sp) { if (m_addr_context.line_entry.line == new_context.line_entry.line) { m_addr_context = new_context; const bool include_inlined_functions = _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits