[lldb] Store SupportFile in LineEntry (NFC) (#77999)

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.
This commit is contained in:
Jonas Devlieghere 2024-01-16 21:09:23 -08:00 committed by GitHub
parent 3e0d71cdf4
commit 933c25e558
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 40 additions and 29 deletions

View File

@ -11,6 +11,7 @@
#include "lldb/Core/AddressRange.h" #include "lldb/Core/AddressRange.h"
#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SupportFile.h"
#include "lldb/lldb-private.h" #include "lldb/lldb-private.h"
namespace lldb_private { namespace lldb_private {
@ -133,7 +134,8 @@ struct LineEntry {
AddressRange range; ///< The section offset address range for this line entry. AddressRange range; ///< The section offset address range for this line entry.
FileSpec file; ///< The source file, possibly mapped by the target.source-map FileSpec file; ///< The source file, possibly mapped by the target.source-map
///setting ///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 uint32_t line = LLDB_INVALID_LINE_NUMBER; ///< The source line number, or zero
///< if there is no line number ///< if there is no line number
/// information. /// information.

View File

@ -11,6 +11,7 @@
#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SupportFile.h" #include "lldb/Utility/SupportFile.h"
#include "lldb/lldb-forward.h"
#include <cstddef> #include <cstddef>
#include <vector> #include <vector>
@ -40,7 +41,7 @@ public:
bool AppendIfUnique(const FileSpec &file); bool AppendIfUnique(const FileSpec &file);
size_t GetSize() const { return m_files.size(); } size_t GetSize() const { return m_files.size(); }
const FileSpec &GetFileSpecAtIndex(size_t idx) const; 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; size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const;
/// Find a compatible file index. /// Find a compatible file index.
/// ///

View File

@ -20,6 +20,7 @@ namespace lldb_private {
/// file yet. This also stores an optional checksum of the on-disk content. /// file yet. This also stores an optional checksum of the on-disk content.
class SupportFile { class SupportFile {
public: public:
SupportFile() : m_file_spec(), m_checksum() {}
SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {} SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {}
SupportFile(const FileSpec &spec, const Checksum &checksum) SupportFile(const FileSpec &spec, const Checksum &checksum)
: m_file_spec(spec), m_checksum(checksum) {} : m_file_spec(spec), m_checksum(checksum) {}
@ -29,10 +30,12 @@ public:
virtual ~SupportFile() = default; 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; 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. /// Return the file name only. Useful for resolving breakpoints by file name.
const FileSpec &GetSpecOnly() const { return m_file_spec; }; const FileSpec &GetSpecOnly() const { return m_file_spec; };

View File

@ -212,6 +212,7 @@ class StringList;
class StringTableReader; class StringTableReader;
class StructuredDataImpl; class StructuredDataImpl;
class StructuredDataPlugin; class StructuredDataPlugin;
class SupportFile;
class Symbol; class Symbol;
class SymbolContext; class SymbolContext;
class SymbolContextList; 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::TypeSummaryOptions> TypeSummaryOptionsSP;
typedef std::shared_ptr<lldb_private::ScriptedSyntheticChildren> typedef std::shared_ptr<lldb_private::ScriptedSyntheticChildren>
ScriptedSyntheticChildrenSP; ScriptedSyntheticChildrenSP;
typedef std::shared_ptr<lldb_private::SupportFile> SupportFileSP;
typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP; typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP;
typedef std::weak_ptr<lldb_private::UnixSignals> UnixSignalsWP; typedef std::weak_ptr<lldb_private::UnixSignals> UnixSignalsWP;
typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP; typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP;

View File

@ -214,7 +214,8 @@ void BreakpointResolver::SetSCMatchesByLine(
auto worklist_begin = std::partition( auto worklist_begin = std::partition(
all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) { all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) {
if (sc.line_entry.file == match.line_entry.file || 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. // When a match is found, keep track of the smallest line number.
closest_line = std::min(closest_line, sc.line_entry.line); closest_line = std::min(closest_line, sc.line_entry.line);
return false; return false;

View File

@ -747,13 +747,13 @@ protected:
bool operator==(const SourceInfo &rhs) const { bool operator==(const SourceInfo &rhs) const {
return function == rhs.function && 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; line_entry.line == rhs.line_entry.line;
} }
bool operator!=(const SourceInfo &rhs) const { bool operator!=(const SourceInfo &rhs) const {
return function != rhs.function || 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; line_entry.line != rhs.line_entry.line;
} }

View File

@ -202,7 +202,7 @@ Disassembler::GetFunctionDeclLineEntry(const SymbolContext &sc) {
sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line); sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line);
if (func_decl_file != prologue_end_line.file && 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 {}; return {};
SourceLine decl_line; SourceLine decl_line;
@ -407,7 +407,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
sc.function->GetStartLineSourceInfo(func_decl_file, sc.function->GetStartLineSourceInfo(func_decl_file,
func_decl_line); func_decl_line);
if (func_decl_file == prologue_end_line.file || 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 // Add all the lines between the function declaration and
// the first non-prologue source line to the list of lines // the first non-prologue source line to the list of lines
// to print. // to print.

View File

@ -20,7 +20,7 @@ LineEntry::LineEntry()
void LineEntry::Clear() { void LineEntry::Clear() {
range.Clear(); range.Clear();
file.Clear(); file.Clear();
original_file.Clear(); original_file_sp = std::make_shared<SupportFile>();
line = LLDB_INVALID_LINE_NUMBER; line = LLDB_INVALID_LINE_NUMBER;
column = 0; column = 0;
is_start_of_statement = 0; is_start_of_statement = 0;
@ -182,7 +182,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
// different file / line number. // different file / line number.
AddressRange complete_line_range = range; AddressRange complete_line_range = range;
auto symbol_context_scope = lldb::eSymbolContextLineEntry; 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) if (include_inlined_functions)
symbol_context_scope |= lldb::eSymbolContextBlock; symbol_context_scope |= lldb::eSymbolContextBlock;
@ -196,7 +196,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
next_line_sc.line_entry.range.GetByteSize() == 0) next_line_sc.line_entry.range.GetByteSize() == 0)
break; 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 || (next_line_sc.line_entry.line == 0 ||
line == next_line_sc.line_entry.line)) { line == next_line_sc.line_entry.line)) {
// Include any line 0 entries - they indicate that this is compiler- // 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) { void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) {
if (target_sp) { if (target_sp) {
// Apply any file remappings to our file. // Apply any file remappings to our file.
if (auto new_file_spec = if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile(
target_sp->GetSourcePathMap().FindFile(original_file)) original_file_sp->GetSpecOnly()))
file = *new_file_spec; file = *new_file_spec;
} }
} }

View File

@ -290,8 +290,8 @@ bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx,
line_entry.file = line_entry.file =
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
line_entry.original_file = line_entry.original_file_sp =
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); m_comp_unit->GetSupportFiles().GetSupportFileAtIndex(entry.file_idx);
line_entry.line = entry.line; line_entry.line = entry.line;
line_entry.column = entry.column; line_entry.column = entry.column;
line_entry.is_start_of_statement = entry.is_start_of_statement; 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) { Address::DumpStyle fallback_style, bool show_line_ranges) {
const size_t count = m_entries.size(); const size_t count = m_entries.size();
LineEntry line_entry; LineEntry line_entry;
FileSpec prev_file; SupportFileSP prev_file;
for (size_t idx = 0; idx < count; ++idx) { for (size_t idx = 0; idx < count; ++idx) {
ConvertEntryAtIndexToLineEntry(idx, line_entry); ConvertEntryAtIndexToLineEntry(idx, line_entry);
line_entry.Dump(s, target, prev_file != line_entry.original_file, style, line_entry.Dump(s, target, *prev_file != *line_entry.original_file_sp,
fallback_style, show_line_ranges); style, fallback_style, show_line_ranges);
s->EOL(); s->EOL();
prev_file = line_entry.original_file; prev_file = line_entry.original_file_sp;
} }
} }

View File

@ -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.range.GetBaseAddress() = next_frame_pc;
next_frame_sc.line_entry.file = next_frame_sc.line_entry.file =
curr_inlined_block_inlined_info->GetCallSite().GetFile(); curr_inlined_block_inlined_info->GetCallSite().GetFile();
next_frame_sc.line_entry.original_file = next_frame_sc.line_entry.original_file_sp =
curr_inlined_block_inlined_info->GetCallSite().GetFile(); std::make_shared<SupportFile>(
curr_inlined_block_inlined_info->GetCallSite().GetFile());
next_frame_sc.line_entry.line = next_frame_sc.line_entry.line =
curr_inlined_block_inlined_info->GetCallSite().GetLine(); curr_inlined_block_inlined_info->GetCallSite().GetLine();
next_frame_sc.line_entry.column = next_frame_sc.line_entry.column =

View File

@ -220,8 +220,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
StackFrameSP frame_sp = thread.GetStackFrameAtIndex(0); StackFrameSP frame_sp = thread.GetStackFrameAtIndex(0);
sc = frame_sp->GetSymbolContext(eSymbolContextEverything); sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
if (sc.line_entry.IsValid()) { if (sc.line_entry.IsValid()) {
if (sc.line_entry.original_file != if (*sc.line_entry.original_file_sp !=
m_addr_context.line_entry.original_file && *m_addr_context.line_entry.original_file_sp &&
sc.comp_unit == m_addr_context.comp_unit && sc.comp_unit == m_addr_context.comp_unit &&
sc.function == m_addr_context.function) { sc.function == m_addr_context.function) {
// Okay, find the next occurrence of this file in the line table: // 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; LineEntry prev_line_entry;
if (line_table->GetLineEntryAtIndex(entry_idx - 1, if (line_table->GetLineEntryAtIndex(entry_idx - 1,
prev_line_entry) && prev_line_entry) &&
prev_line_entry.original_file == *prev_line_entry.original_file_sp ==
line_entry.original_file) { *line_entry.original_file_sp) {
SymbolContext prev_sc; SymbolContext prev_sc;
Address prev_address = Address prev_address =
prev_line_entry.range.GetBaseAddress(); prev_line_entry.range.GetBaseAddress();
@ -279,8 +279,8 @@ bool ThreadPlanStepOverRange::ShouldStop(Event *event_ptr) {
if (next_line_function != m_addr_context.function) if (next_line_function != m_addr_context.function)
break; break;
if (next_line_entry.original_file == if (*next_line_entry.original_file_sp ==
m_addr_context.line_entry.original_file) { *m_addr_context.line_entry.original_file_sp) {
const bool abort_other_plans = false; const bool abort_other_plans = false;
const RunMode stop_other_threads = RunMode::eAllThreads; const RunMode stop_other_threads = RunMode::eAllThreads;
lldb::addr_t cur_pc = thread.GetStackFrameAtIndex(0) lldb::addr_t cur_pc = thread.GetStackFrameAtIndex(0)

View File

@ -120,8 +120,8 @@ bool ThreadPlanStepRange::InRange() {
frame->GetSymbolContext(eSymbolContextEverything)); frame->GetSymbolContext(eSymbolContextEverything));
if (m_addr_context.line_entry.IsValid() && if (m_addr_context.line_entry.IsValid() &&
new_context.line_entry.IsValid()) { new_context.line_entry.IsValid()) {
if (m_addr_context.line_entry.original_file == if (*m_addr_context.line_entry.original_file_sp ==
new_context.line_entry.original_file) { *new_context.line_entry.original_file_sp) {
if (m_addr_context.line_entry.line == new_context.line_entry.line) { if (m_addr_context.line_entry.line == new_context.line_entry.line) {
m_addr_context = new_context; m_addr_context = new_context;
const bool include_inlined_functions = const bool include_inlined_functions =