Skip to content

Commit d5a277d

Browse files
authored
[lldb] Store SupportFile in FileEntry (NFC) (#85468)
This is another step towards supporting DWARF5 checksums and inline source code in LLDB.
1 parent 8ebf408 commit d5a277d

26 files changed

+89
-71
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ class Disassembler : public std::enable_shared_from_this<Disassembler>,
538538
ElideMixedSourceAndDisassemblyLine(const ExecutionContext &exe_ctx,
539539
const SymbolContext &sc, LineEntry &line) {
540540
SourceLine sl;
541-
sl.file = line.file;
541+
sl.file = line.GetFile();
542542
sl.line = line.line;
543543
sl.column = line.column;
544544
return ElideMixedSourceAndDisassemblyLine(exe_ctx, sc, sl);

lldb/include/lldb/Symbol/LineEntry.h

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,28 @@ struct LineEntry {
130130
/// Shared pointer to the target this LineEntry belongs to.
131131
void ApplyFileMappings(lldb::TargetSP target_sp);
132132

133-
// Member variables.
134-
AddressRange range; ///< The section offset address range for this line entry.
135-
FileSpec file; ///< The source file, possibly mapped by the target.source-map
136-
///setting
137-
lldb::SupportFileSP
138-
original_file_sp; ///< The original source file, from debug info.
139-
uint32_t line = LLDB_INVALID_LINE_NUMBER; ///< The source line number, or zero
140-
///< if there is no line number
141-
/// information.
142-
uint16_t column =
143-
0; ///< The column number of the source line, or zero if there
144-
/// is no column information.
133+
const FileSpec &GetFile() const {
134+
assert(file_sp);
135+
return file_sp->GetSpecOnly();
136+
}
137+
138+
/// The section offset address range for this line entry.
139+
AddressRange range;
140+
141+
/// The source file, possibly mapped by the target.source-map setting.
142+
lldb::SupportFileSP file_sp;
143+
144+
/// The original source file, from debug info.
145+
lldb::SupportFileSP original_file_sp;
146+
147+
/// The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line
148+
/// number information.
149+
uint32_t line = LLDB_INVALID_LINE_NUMBER;
150+
151+
/// The column number of the source line, or zero if there is no column
152+
/// information.
153+
uint16_t column = 0;
154+
145155
uint16_t is_start_of_statement : 1, ///< Indicates this entry is the beginning
146156
///of a statement.
147157
is_start_of_basic_block : 1, ///< Indicates this entry is the beginning of

lldb/include/lldb/Utility/SupportFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class SupportFile {
4545
/// Materialize the file to disk and return the path to that temporary file.
4646
virtual const FileSpec &Materialize() { return m_file_spec; }
4747

48+
/// Change the file name.
49+
void Update(const FileSpec &file_spec) { m_file_spec = file_spec; }
50+
4851
protected:
4952
FileSpec m_file_spec;
5053
Checksum m_checksum;

lldb/source/API/SBLineEntry.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ SBFileSpec SBLineEntry::GetFileSpec() const {
8181
LLDB_INSTRUMENT_VA(this);
8282

8383
SBFileSpec sb_file_spec;
84-
if (m_opaque_up.get() && m_opaque_up->file)
85-
sb_file_spec.SetFileSpec(m_opaque_up->file);
84+
if (m_opaque_up.get() && m_opaque_up->GetFile())
85+
sb_file_spec.SetFileSpec(m_opaque_up->GetFile());
8686

8787
return sb_file_spec;
8888
}
@@ -109,9 +109,9 @@ void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {
109109
LLDB_INSTRUMENT_VA(this, filespec);
110110

111111
if (filespec.IsValid())
112-
ref().file = filespec.ref();
112+
ref().file_sp->Update(filespec.ref());
113113
else
114-
ref().file.Clear();
114+
ref().file_sp->Update(FileSpec());
115115
}
116116
void SBLineEntry::SetLine(uint32_t line) {
117117
LLDB_INSTRUMENT_VA(this, line);
@@ -168,7 +168,7 @@ bool SBLineEntry::GetDescription(SBStream &description) {
168168

169169
if (m_opaque_up) {
170170
char file_path[PATH_MAX * 2];
171-
m_opaque_up->file.GetPath(file_path, sizeof(file_path));
171+
m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));
172172
strm.Printf("%s:%u", file_path, GetLine());
173173
if (GetColumn() > 0)
174174
strm.Printf(":%u", GetColumn());

lldb/source/API/SBThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
819819
step_file_spec = sb_file_spec.ref();
820820
} else {
821821
if (frame_sc.line_entry.IsValid())
822-
step_file_spec = frame_sc.line_entry.file;
822+
step_file_spec = frame_sc.line_entry.GetFile();
823823
else {
824824
sb_error.SetErrorString("invalid file argument or no file for frame");
825825
return sb_error;

lldb/source/Breakpoint/BreakpointResolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void BreakpointResolver::SetSCMatchesByLine(
221221
auto &match = all_scs[0];
222222
auto worklist_begin = std::partition(
223223
all_scs.begin(), all_scs.end(), [&](const SymbolContext &sc) {
224-
if (sc.line_entry.file == match.line_entry.file ||
224+
if (sc.line_entry.GetFile() == match.line_entry.GetFile() ||
225225
*sc.line_entry.original_file_sp ==
226226
*match.line_entry.original_file_sp) {
227227
// When a match is found, keep track of the smallest line number.

lldb/source/Breakpoint/BreakpointResolverFileLine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list) {
147147
else
148148
continue;
149149

150-
if (file != sc.line_entry.file) {
151-
LLDB_LOG(log, "unexpected symbol context file {0}", sc.line_entry.file);
150+
if (file != sc.line_entry.GetFile()) {
151+
LLDB_LOG(log, "unexpected symbol context file {0}",
152+
sc.line_entry.GetFile());
152153
continue;
153154
}
154155

@@ -223,7 +224,7 @@ void BreakpointResolverFileLine::DeduceSourceMapping(
223224

224225
const bool case_sensitive = request_file.IsCaseSensitive();
225226
for (const SymbolContext &sc : sc_list) {
226-
FileSpec sc_file = sc.line_entry.file;
227+
FileSpec sc_file = sc.line_entry.GetFile();
227228

228229
if (FileSpec::Equal(sc_file, request_file, /*full*/ true))
229230
continue;

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
780780
} else {
781781
const SymbolContext &sc =
782782
cur_frame->GetSymbolContext(eSymbolContextLineEntry);
783-
if (sc.line_entry.file) {
784-
file = sc.line_entry.file;
783+
if (sc.line_entry.GetFile()) {
784+
file = sc.line_entry.GetFile();
785785
} else {
786786
result.AppendError("Can't find the file for the selected frame to "
787787
"use as the default file.");

lldb/source/Commands/CommandObjectSource.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
158158
if (module_list.GetSize() &&
159159
module_list.GetIndexForModule(module) == LLDB_INVALID_INDEX32)
160160
continue;
161-
if (!FileSpec::Match(file_spec, line_entry.file))
161+
if (!FileSpec::Match(file_spec, line_entry.GetFile()))
162162
continue;
163163
if (start_line > 0 && line_entry.line < start_line)
164164
continue;
@@ -239,7 +239,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
239239
num_matches++;
240240
if (num_lines > 0 && num_matches > num_lines)
241241
break;
242-
assert(cu_file_spec == line_entry.file);
242+
assert(cu_file_spec == line_entry.GetFile());
243243
if (!cu_header_printed) {
244244
if (num_matches > 0)
245245
strm << "\n\n";
@@ -760,11 +760,11 @@ class CommandObjectSourceList : public CommandObjectParsed {
760760
bool operator<(const SourceInfo &rhs) const {
761761
if (function.GetCString() < rhs.function.GetCString())
762762
return true;
763-
if (line_entry.file.GetDirectory().GetCString() <
764-
rhs.line_entry.file.GetDirectory().GetCString())
763+
if (line_entry.GetFile().GetDirectory().GetCString() <
764+
rhs.line_entry.GetFile().GetDirectory().GetCString())
765765
return true;
766-
if (line_entry.file.GetFilename().GetCString() <
767-
rhs.line_entry.file.GetFilename().GetCString())
766+
if (line_entry.GetFile().GetFilename().GetCString() <
767+
rhs.line_entry.GetFile().GetFilename().GetCString())
768768
return true;
769769
if (line_entry.line < rhs.line_entry.line)
770770
return true;
@@ -799,7 +799,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
799799
sc.function->GetEndLineSourceInfo(end_file, end_line);
800800
} else {
801801
// We have an inlined function
802-
start_file = source_info.line_entry.file;
802+
start_file = source_info.line_entry.GetFile();
803803
start_line = source_info.line_entry.line;
804804
end_line = start_line + m_options.num_lines;
805805
}

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ class CommandObjectThreadJump : public CommandObjectParsed {
17051705
line = sym_ctx.line_entry.line + m_options.m_line_offset;
17061706

17071707
// Try the current file, but override if asked.
1708-
FileSpec file = sym_ctx.line_entry.file;
1708+
FileSpec file = sym_ctx.line_entry.file_sp->GetSpecOnly();
17091709
if (m_options.m_filenames.GetSize() == 1)
17101710
file = m_options.m_filenames.GetFileSpecAtIndex(0);
17111711

0 commit comments

Comments
 (0)