Skip to content

Commit 933c25e

Browse files
authored
[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.
1 parent 3e0d71c commit 933c25e

File tree

12 files changed

+40
-29
lines changed

12 files changed

+40
-29
lines changed

lldb/include/lldb/Symbol/LineEntry.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "lldb/Core/AddressRange.h"
1313
#include "lldb/Utility/FileSpec.h"
14+
#include "lldb/Utility/SupportFile.h"
1415
#include "lldb/lldb-private.h"
1516

1617
namespace lldb_private {
@@ -133,7 +134,8 @@ struct LineEntry {
133134
AddressRange range; ///< The section offset address range for this line entry.
134135
FileSpec file; ///< The source file, possibly mapped by the target.source-map
135136
///setting
136-
FileSpec original_file; ///< The original source file, from debug info.
137+
lldb::SupportFileSP
138+
original_file_sp; ///< The original source file, from debug info.
137139
uint32_t line = LLDB_INVALID_LINE_NUMBER; ///< The source line number, or zero
138140
///< if there is no line number
139141
/// information.

lldb/include/lldb/Utility/FileSpecList.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "lldb/Utility/FileSpec.h"
1313
#include "lldb/Utility/SupportFile.h"
14+
#include "lldb/lldb-forward.h"
1415

1516
#include <cstddef>
1617
#include <vector>
@@ -40,7 +41,7 @@ class SupportFileList {
4041
bool AppendIfUnique(const FileSpec &file);
4142
size_t GetSize() const { return m_files.size(); }
4243
const FileSpec &GetFileSpecAtIndex(size_t idx) const;
43-
std::shared_ptr<SupportFile> GetSupportFileAtIndex(size_t idx) const;
44+
lldb::SupportFileSP GetSupportFileAtIndex(size_t idx) const;
4445
size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const;
4546
/// Find a compatible file index.
4647
///

lldb/include/lldb/Utility/SupportFile.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace lldb_private {
2020
/// file yet. This also stores an optional checksum of the on-disk content.
2121
class SupportFile {
2222
public:
23+
SupportFile() : m_file_spec(), m_checksum() {}
2324
SupportFile(const FileSpec &spec) : m_file_spec(spec), m_checksum() {}
2425
SupportFile(const FileSpec &spec, const Checksum &checksum)
2526
: m_file_spec(spec), m_checksum(checksum) {}
@@ -29,10 +30,12 @@ class SupportFile {
2930

3031
virtual ~SupportFile() = default;
3132

32-
bool operator==(const SupportFile &other) {
33+
bool operator==(const SupportFile &other) const {
3334
return m_file_spec == other.m_file_spec && m_checksum == other.m_checksum;
3435
}
3536

37+
bool operator!=(const SupportFile &other) const { return !(*this == other); }
38+
3639
/// Return the file name only. Useful for resolving breakpoints by file name.
3740
const FileSpec &GetSpecOnly() const { return m_file_spec; };
3841

lldb/include/lldb/lldb-forward.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class StringList;
212212
class StringTableReader;
213213
class StructuredDataImpl;
214214
class StructuredDataPlugin;
215+
class SupportFile;
215216
class Symbol;
216217
class SymbolContext;
217218
class SymbolContextList;
@@ -462,6 +463,7 @@ typedef std::shared_ptr<lldb_private::TypeSummaryImpl> TypeSummaryImplSP;
462463
typedef std::shared_ptr<lldb_private::TypeSummaryOptions> TypeSummaryOptionsSP;
463464
typedef std::shared_ptr<lldb_private::ScriptedSyntheticChildren>
464465
ScriptedSyntheticChildrenSP;
466+
typedef std::shared_ptr<lldb_private::SupportFile> SupportFileSP;
465467
typedef std::shared_ptr<lldb_private::UnixSignals> UnixSignalsSP;
466468
typedef std::weak_ptr<lldb_private::UnixSignals> UnixSignalsWP;
467469
typedef std::shared_ptr<lldb_private::UnwindAssembly> UnwindAssemblySP;

lldb/source/Breakpoint/BreakpointResolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ void BreakpointResolver::SetSCMatchesByLine(
214214
auto worklist_begin = std::partition(
215215
all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) {
216216
if (sc.line_entry.file == match.line_entry.file ||
217-
sc.line_entry.original_file == match.line_entry.original_file) {
217+
*sc.line_entry.original_file_sp ==
218+
*match.line_entry.original_file_sp) {
218219
// When a match is found, keep track of the smallest line number.
219220
closest_line = std::min(closest_line, sc.line_entry.line);
220221
return false;

lldb/source/Commands/CommandObjectSource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,13 +747,13 @@ class CommandObjectSourceList : public CommandObjectParsed {
747747

748748
bool operator==(const SourceInfo &rhs) const {
749749
return function == rhs.function &&
750-
line_entry.original_file == rhs.line_entry.original_file &&
750+
*line_entry.original_file_sp == *rhs.line_entry.original_file_sp &&
751751
line_entry.line == rhs.line_entry.line;
752752
}
753753

754754
bool operator!=(const SourceInfo &rhs) const {
755755
return function != rhs.function ||
756-
line_entry.original_file != rhs.line_entry.original_file ||
756+
*line_entry.original_file_sp != *rhs.line_entry.original_file_sp ||
757757
line_entry.line != rhs.line_entry.line;
758758
}
759759

lldb/source/Core/Disassembler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Disassembler::GetFunctionDeclLineEntry(const SymbolContext &sc) {
202202
sc.function->GetStartLineSourceInfo(func_decl_file, func_decl_line);
203203

204204
if (func_decl_file != prologue_end_line.file &&
205-
func_decl_file != prologue_end_line.original_file)
205+
func_decl_file != prologue_end_line.original_file_sp->GetSpecOnly())
206206
return {};
207207

208208
SourceLine decl_line;
@@ -407,7 +407,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
407407
sc.function->GetStartLineSourceInfo(func_decl_file,
408408
func_decl_line);
409409
if (func_decl_file == prologue_end_line.file ||
410-
func_decl_file == prologue_end_line.original_file) {
410+
func_decl_file ==
411+
prologue_end_line.original_file_sp->GetSpecOnly()) {
411412
// Add all the lines between the function declaration and
412413
// the first non-prologue source line to the list of lines
413414
// to print.

lldb/source/Symbol/LineEntry.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LineEntry::LineEntry()
2020
void LineEntry::Clear() {
2121
range.Clear();
2222
file.Clear();
23-
original_file.Clear();
23+
original_file_sp = std::make_shared<SupportFile>();
2424
line = LLDB_INVALID_LINE_NUMBER;
2525
column = 0;
2626
is_start_of_statement = 0;
@@ -182,7 +182,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
182182
// different file / line number.
183183
AddressRange complete_line_range = range;
184184
auto symbol_context_scope = lldb::eSymbolContextLineEntry;
185-
Declaration start_call_site(original_file, line);
185+
Declaration start_call_site(original_file_sp->GetSpecOnly(), line);
186186
if (include_inlined_functions)
187187
symbol_context_scope |= lldb::eSymbolContextBlock;
188188

@@ -196,7 +196,7 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
196196
next_line_sc.line_entry.range.GetByteSize() == 0)
197197
break;
198198

199-
if (original_file == next_line_sc.line_entry.original_file &&
199+
if (*original_file_sp == *next_line_sc.line_entry.original_file_sp &&
200200
(next_line_sc.line_entry.line == 0 ||
201201
line == next_line_sc.line_entry.line)) {
202202
// Include any line 0 entries - they indicate that this is compiler-
@@ -240,8 +240,8 @@ AddressRange LineEntry::GetSameLineContiguousAddressRange(
240240
void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) {
241241
if (target_sp) {
242242
// Apply any file remappings to our file.
243-
if (auto new_file_spec =
244-
target_sp->GetSourcePathMap().FindFile(original_file))
243+
if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile(
244+
original_file_sp->GetSpecOnly()))
245245
file = *new_file_spec;
246246
}
247247
}

lldb/source/Symbol/LineTable.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx,
290290

291291
line_entry.file =
292292
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
293-
line_entry.original_file =
294-
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
293+
line_entry.original_file_sp =
294+
m_comp_unit->GetSupportFiles().GetSupportFileAtIndex(entry.file_idx);
295295
line_entry.line = entry.line;
296296
line_entry.column = entry.column;
297297
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,
357357
Address::DumpStyle fallback_style, bool show_line_ranges) {
358358
const size_t count = m_entries.size();
359359
LineEntry line_entry;
360-
FileSpec prev_file;
360+
SupportFileSP prev_file;
361361
for (size_t idx = 0; idx < count; ++idx) {
362362
ConvertEntryAtIndexToLineEntry(idx, line_entry);
363-
line_entry.Dump(s, target, prev_file != line_entry.original_file, style,
364-
fallback_style, show_line_ranges);
363+
line_entry.Dump(s, target, *prev_file != *line_entry.original_file_sp,
364+
style, fallback_style, show_line_ranges);
365365
s->EOL();
366-
prev_file = line_entry.original_file;
366+
prev_file = line_entry.original_file_sp;
367367
}
368368
}
369369

lldb/source/Symbol/SymbolContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,9 @@ bool SymbolContext::GetParentOfInlinedScope(const Address &curr_frame_pc,
489489
next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc;
490490
next_frame_sc.line_entry.file =
491491
curr_inlined_block_inlined_info->GetCallSite().GetFile();
492-
next_frame_sc.line_entry.original_file =
493-
curr_inlined_block_inlined_info->GetCallSite().GetFile();
492+
next_frame_sc.line_entry.original_file_sp =
493+
std::make_shared<SupportFile>(
494+
curr_inlined_block_inlined_info->GetCallSite().GetFile());
494495
next_frame_sc.line_entry.line =
495496
curr_inlined_block_inlined_info->GetCallSite().GetLine();
496497
next_frame_sc.line_entry.column =

0 commit comments

Comments
 (0)