Skip to content

Commit 130eddf

Browse files
authored
[lldb] Deal with SupportFiles in SourceManager (NFC) (#106740)
To support detecting MD5 checksum mismatches, deal with SupportFiles rather than a plain FileSpecs in the SourceManager.
1 parent 0efa386 commit 130eddf

11 files changed

+107
-94
lines changed

lldb/include/lldb/Core/SourceManager.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,13 @@ class SourceManager {
141141

142142
~SourceManager();
143143

144-
FileSP GetLastFile() { return GetFile(m_last_file_spec); }
144+
FileSP GetLastFile() { return GetFile(m_last_support_file_sp); }
145145

146-
size_t
147-
DisplaySourceLinesWithLineNumbers(const FileSpec &file, uint32_t line,
148-
uint32_t column, uint32_t context_before,
149-
uint32_t context_after,
150-
const char *current_line_cstr, Stream *s,
151-
const SymbolContextList *bp_locs = nullptr);
146+
size_t DisplaySourceLinesWithLineNumbers(
147+
lldb::SupportFileSP support_file_sp, uint32_t line, uint32_t column,
148+
uint32_t context_before, uint32_t context_after,
149+
const char *current_line_cstr, Stream *s,
150+
const SymbolContextList *bp_locs = nullptr);
152151

153152
// This variant uses the last file we visited.
154153
size_t DisplaySourceLinesWithLineNumbersUsingLastFile(
@@ -159,22 +158,31 @@ class SourceManager {
159158
size_t DisplayMoreWithLineNumbers(Stream *s, uint32_t count, bool reverse,
160159
const SymbolContextList *bp_locs = nullptr);
161160

162-
bool SetDefaultFileAndLine(const FileSpec &file_spec, uint32_t line);
161+
bool SetDefaultFileAndLine(lldb::SupportFileSP support_file_sp,
162+
uint32_t line);
163+
164+
struct SupportFileAndLine {
165+
lldb::SupportFileSP support_file_sp;
166+
uint32_t line;
167+
SupportFileAndLine(lldb::SupportFileSP support_file_sp, uint32_t line)
168+
: support_file_sp(support_file_sp), line(line) {}
169+
};
163170

164-
bool GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line);
171+
std::optional<SupportFileAndLine> GetDefaultFileAndLine();
165172

166173
bool DefaultFileAndLineSet() {
167-
return (GetFile(m_last_file_spec).get() != nullptr);
174+
return (GetFile(m_last_support_file_sp).get() != nullptr);
168175
}
169176

170-
void FindLinesMatchingRegex(FileSpec &file_spec, RegularExpression &regex,
171-
uint32_t start_line, uint32_t end_line,
177+
void FindLinesMatchingRegex(lldb::SupportFileSP support_file_sp,
178+
RegularExpression &regex, uint32_t start_line,
179+
uint32_t end_line,
172180
std::vector<uint32_t> &match_lines);
173181

174-
FileSP GetFile(const FileSpec &file_spec);
182+
FileSP GetFile(lldb::SupportFileSP support_file_sp);
175183

176184
protected:
177-
FileSpec m_last_file_spec;
185+
lldb::SupportFileSP m_last_support_file_sp;
178186
uint32_t m_last_line;
179187
uint32_t m_last_count;
180188
bool m_default_set;

lldb/source/API/SBSourceManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class SourceManagerImpl {
4646
lldb::TargetSP target_sp(m_target_wp.lock());
4747
if (target_sp) {
4848
return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers(
49-
file, line, column, context_before, context_after, current_line_cstr,
50-
s);
49+
std::make_shared<SupportFile>(file), line, column, context_before,
50+
context_after, current_line_cstr, s);
5151
} else {
5252
lldb::DebuggerSP debugger_sp(m_debugger_wp.lock());
5353
if (debugger_sp) {
5454
return debugger_sp->GetSourceManager()
55-
.DisplaySourceLinesWithLineNumbers(file, line, column,
56-
context_before, context_after,
57-
current_line_cstr, s);
55+
.DisplaySourceLinesWithLineNumbers(
56+
std::make_shared<SupportFile>(file), line, column,
57+
context_before, context_after, current_line_cstr, s);
5858
}
5959
}
6060
return 0;

lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ Searcher::CallbackReturn BreakpointResolverFileRegex::SearchCallback(
102102
FileSpec cu_file_spec = cu->GetPrimaryFile();
103103
std::vector<uint32_t> line_matches;
104104
context.target_sp->GetSourceManager().FindLinesMatchingRegex(
105-
cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
105+
std::make_shared<SupportFile>(cu_file_spec), m_regex, 1, UINT32_MAX,
106+
line_matches);
106107

107108
uint32_t num_matches = line_matches.size();
108109
for (uint32_t i = 0; i < num_matches; i++) {

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,20 +769,26 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
769769
private:
770770
bool GetDefaultFile(Target &target, FileSpec &file,
771771
CommandReturnObject &result) {
772-
uint32_t default_line;
773772
// First use the Source Manager's default file. Then use the current stack
774773
// frame's file.
775-
if (!target.GetSourceManager().GetDefaultFileAndLine(file, default_line)) {
774+
if (auto maybe_file_and_line =
775+
target.GetSourceManager().GetDefaultFileAndLine()) {
776+
file = maybe_file_and_line->support_file_sp->GetSpecOnly();
777+
return true;
778+
}
779+
776780
StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
777781
if (cur_frame == nullptr) {
778782
result.AppendError(
779783
"No selected frame to use to find the default file.");
780784
return false;
781-
} else if (!cur_frame->HasDebugInformation()) {
785+
}
786+
if (!cur_frame->HasDebugInformation()) {
782787
result.AppendError("Cannot use the selected frame to find the default "
783788
"file, it has no debug info.");
784789
return false;
785-
} else {
790+
}
791+
786792
const SymbolContext &sc =
787793
cur_frame->GetSymbolContext(eSymbolContextLineEntry);
788794
if (sc.line_entry.GetFile()) {
@@ -791,8 +797,6 @@ class CommandObjectBreakpointSet : public CommandObjectParsed {
791797
result.AppendError("Can't find the file for the selected frame to "
792798
"use as the default file.");
793799
return false;
794-
}
795-
}
796800
}
797801
return true;
798802
}

lldb/source/Commands/CommandObjectSource.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,16 @@ class CommandObjectSourceList : public CommandObjectParsed {
777777
if (sc.function) {
778778
Target &target = GetTarget();
779779

780-
FileSpec start_file;
780+
SupportFileSP start_file = std::make_shared<SupportFile>();
781781
uint32_t start_line;
782782
uint32_t end_line;
783783
FileSpec end_file;
784784

785785
if (sc.block == nullptr) {
786786
// Not an inlined function
787-
sc.function->GetStartLineSourceInfo(start_file, start_line);
787+
FileSpec function_file_spec;
788+
sc.function->GetStartLineSourceInfo(function_file_spec, start_line);
789+
start_file = std::make_shared<SupportFile>(function_file_spec);
788790
if (start_line == 0) {
789791
result.AppendErrorWithFormat("Could not find line information for "
790792
"start of function: \"%s\".\n",
@@ -794,7 +796,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
794796
sc.function->GetEndLineSourceInfo(end_file, end_line);
795797
} else {
796798
// We have an inlined function
797-
start_file = source_info.line_entry.GetFile();
799+
start_file = source_info.line_entry.file_sp;
798800
start_line = source_info.line_entry.line;
799801
end_line = start_line + m_options.num_lines;
800802
}
@@ -825,14 +827,15 @@ class CommandObjectSourceList : public CommandObjectParsed {
825827

826828
if (m_options.show_bp_locs) {
827829
const bool show_inlines = true;
828-
m_breakpoint_locations.Reset(start_file, 0, show_inlines);
830+
m_breakpoint_locations.Reset(start_file->GetSpecOnly(), 0,
831+
show_inlines);
829832
SearchFilterForUnconstrainedSearches target_search_filter(
830833
m_exe_ctx.GetTargetSP());
831834
target_search_filter.Search(m_breakpoint_locations);
832835
}
833836

834-
result.AppendMessageWithFormat("File: %s\n",
835-
start_file.GetPath().c_str());
837+
result.AppendMessageWithFormat(
838+
"File: %s\n", start_file->GetSpecOnly().GetPath().c_str());
836839
// We don't care about the column here.
837840
const uint32_t column = 0;
838841
return target.GetSourceManager().DisplaySourceLinesWithLineNumbers(
@@ -1050,8 +1053,9 @@ class CommandObjectSourceList : public CommandObjectParsed {
10501053
? sc.line_entry.column
10511054
: 0;
10521055
target.GetSourceManager().DisplaySourceLinesWithLineNumbers(
1053-
sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column,
1054-
lines_to_back_up, m_options.num_lines - lines_to_back_up, "->",
1056+
std::make_shared<SupportFile>(sc.comp_unit->GetPrimaryFile()),
1057+
sc.line_entry.line, column, lines_to_back_up,
1058+
m_options.num_lines - lines_to_back_up, "->",
10551059
&result.GetOutputStream(), GetBreakpointLocations());
10561060
result.SetStatus(eReturnStatusSuccessFinishResult);
10571061
}
@@ -1170,9 +1174,9 @@ class CommandObjectSourceList : public CommandObjectParsed {
11701174
m_options.num_lines = 10;
11711175
const uint32_t column = 0;
11721176
target.GetSourceManager().DisplaySourceLinesWithLineNumbers(
1173-
sc.comp_unit->GetPrimaryFile(), m_options.start_line, column, 0,
1174-
m_options.num_lines, "", &result.GetOutputStream(),
1175-
GetBreakpointLocations());
1177+
std::make_shared<SupportFile>(sc.comp_unit->GetPrimaryFile()),
1178+
m_options.start_line, column, 0, m_options.num_lines, "",
1179+
&result.GetOutputStream(), GetBreakpointLocations());
11761180

11771181
result.SetStatus(eReturnStatusSuccessFinishResult);
11781182
} else {

lldb/source/Core/Disassembler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch,
517517
line_highlight = "**";
518518
}
519519
source_manager.DisplaySourceLinesWithLineNumbers(
520-
ln.file, ln.line, ln.column, 0, 0, line_highlight, &strm);
520+
std::make_shared<SupportFile>(ln.file), ln.line, ln.column, 0, 0,
521+
line_highlight, &strm);
521522
}
522523
if (source_lines_to_display.print_source_context_end_eol)
523524
strm.EOL();

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6910,8 +6910,8 @@ class SourceFileWindowDelegate : public WindowDelegate {
69106910
} else {
69116911
// File changed, set selected line to the line with the PC
69126912
m_selected_line = m_pc_line;
6913-
m_file_sp = m_debugger.GetSourceManager().GetFile(
6914-
m_sc.line_entry.GetFile());
6913+
m_file_sp =
6914+
m_debugger.GetSourceManager().GetFile(m_sc.line_entry.file_sp);
69156915
if (m_file_sp) {
69166916
const size_t num_lines = m_file_sp->GetNumLines();
69176917
m_line_width = 1;

0 commit comments

Comments
 (0)