@@ -87,8 +87,10 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
8787 LLDB_LOG (log, " Source file caching disabled: creating new source file: {0}" ,
8888 file_spec);
8989 if (target_sp)
90- return std::make_shared<File>(file_spec, target_sp);
91- return std::make_shared<File>(file_spec, debugger_sp);
90+ return std::make_shared<File>(std::make_shared<SupportFile>(file_spec),
91+ target_sp);
92+ return std::make_shared<File>(std::make_shared<SupportFile>(file_spec),
93+ debugger_sp);
9294 }
9395
9496 ProcessSP process_sp = target_sp ? target_sp->GetProcessSP () : ProcessSP ();
@@ -136,7 +138,8 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
136138 }
137139
138140 // Check if the file exists on disk.
139- if (file_sp && !FileSystem::Instance ().Exists (file_sp->GetFileSpec ())) {
141+ if (file_sp && !FileSystem::Instance ().Exists (
142+ file_sp->GetSupportFile ()->GetSpecOnly ())) {
140143 LLDB_LOG (log, " File doesn't exist on disk: {0}" , file_spec);
141144 file_sp.reset ();
142145 }
@@ -148,9 +151,11 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
148151
149152 // (Re)create the file.
150153 if (target_sp)
151- file_sp = std::make_shared<File>(file_spec, target_sp);
154+ file_sp = std::make_shared<File>(std::make_shared<SupportFile>(file_spec),
155+ target_sp);
152156 else
153- file_sp = std::make_shared<File>(file_spec, debugger_sp);
157+ file_sp = std::make_shared<File>(std::make_shared<SupportFile>(file_spec),
158+ debugger_sp);
154159
155160 // Add the file to the debugger and process cache. If the file was
156161 // invalidated, this will overwrite it.
@@ -444,25 +449,25 @@ void SourceManager::FindLinesMatchingRegex(FileSpec &file_spec,
444449 match_lines);
445450}
446451
447- SourceManager::File::File (const FileSpec &file_spec ,
452+ SourceManager::File::File (SupportFileSP support_file_sp ,
448453 lldb::DebuggerSP debugger_sp)
449- : m_file_spec_orig(file_spec), m_file_spec( ), m_mod_time(),
454+ : m_support_file_sp(std::make_shared<SupportFile>() ), m_mod_time(),
450455 m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) {
451- CommonInitializer (file_spec , {});
456+ CommonInitializer (support_file_sp , {});
452457}
453458
454- SourceManager::File::File (const FileSpec &file_spec , TargetSP target_sp)
455- : m_file_spec_orig(file_spec), m_file_spec( ), m_mod_time(),
459+ SourceManager::File::File (SupportFileSP support_file_sp , TargetSP target_sp)
460+ : m_support_file_sp(std::make_shared<SupportFile>() ), m_mod_time(),
456461 m_debugger_wp(target_sp ? target_sp->GetDebugger ().shared_from_this()
457462 : DebuggerSP()),
458463 m_target_wp(target_sp) {
459- CommonInitializer (file_spec , target_sp);
464+ CommonInitializer (support_file_sp , target_sp);
460465}
461466
462- void SourceManager::File::CommonInitializer (const FileSpec &file_spec ,
467+ void SourceManager::File::CommonInitializer (SupportFileSP support_file_sp ,
463468 TargetSP target_sp) {
464469 // Set the file and update the modification time.
465- SetFileSpec (file_spec );
470+ SetSupportFile (support_file_sp );
466471
467472 // Always update the source map modification ID if we have a target.
468473 if (target_sp)
@@ -472,65 +477,76 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
472477 if (m_mod_time == llvm::sys::TimePoint<>()) {
473478 if (target_sp) {
474479 // If this is just a file name, try finding it in the target.
475- if (!file_spec.GetDirectory () && file_spec.GetFilename ()) {
476- bool check_inlines = false ;
477- SymbolContextList sc_list;
478- size_t num_matches =
479- target_sp->GetImages ().ResolveSymbolContextForFilePath (
480- file_spec.GetFilename ().AsCString (), 0 , check_inlines,
481- SymbolContextItem (eSymbolContextModule |
482- eSymbolContextCompUnit),
483- sc_list);
484- bool got_multiple = false ;
485- if (num_matches != 0 ) {
486- if (num_matches > 1 ) {
487- CompileUnit *test_cu = nullptr ;
488- for (const SymbolContext &sc : sc_list) {
489- if (sc.comp_unit ) {
490- if (test_cu) {
491- if (test_cu != sc.comp_unit )
492- got_multiple = true ;
493- break ;
494- } else
495- test_cu = sc.comp_unit ;
480+ {
481+ FileSpec file_spec = support_file_sp->GetSpecOnly ();
482+ if (!file_spec.GetDirectory () && file_spec.GetFilename ()) {
483+ bool check_inlines = false ;
484+ SymbolContextList sc_list;
485+ size_t num_matches =
486+ target_sp->GetImages ().ResolveSymbolContextForFilePath (
487+ file_spec.GetFilename ().AsCString (), 0 , check_inlines,
488+ SymbolContextItem (eSymbolContextModule |
489+ eSymbolContextCompUnit),
490+ sc_list);
491+ bool got_multiple = false ;
492+ if (num_matches != 0 ) {
493+ if (num_matches > 1 ) {
494+ CompileUnit *test_cu = nullptr ;
495+ for (const SymbolContext &sc : sc_list) {
496+ if (sc.comp_unit ) {
497+ if (test_cu) {
498+ if (test_cu != sc.comp_unit )
499+ got_multiple = true ;
500+ break ;
501+ } else
502+ test_cu = sc.comp_unit ;
503+ }
496504 }
497505 }
498- }
499- if (!got_multiple) {
500- SymbolContext sc;
501- sc_list.GetContextAtIndex (0 , sc);
502- if (sc.comp_unit )
503- SetFileSpec (sc.comp_unit ->GetPrimaryFile ());
506+ if (!got_multiple) {
507+ SymbolContext sc;
508+ sc_list.GetContextAtIndex (0 , sc);
509+ if (sc.comp_unit )
510+ SetSupportFile (std::make_shared<SupportFile>(
511+ sc.comp_unit ->GetPrimaryFile ()));
512+ }
504513 }
505514 }
506515 }
507516
508517 // Try remapping the file if it doesn't exist.
509- if (!FileSystem::Instance ().Exists (m_file_spec)) {
510- // Check target specific source remappings (i.e., the
511- // target.source-map setting), then fall back to the module
512- // specific remapping (i.e., the .dSYM remapping dictionary).
513- auto remapped = target_sp->GetSourcePathMap ().FindFile (m_file_spec);
514- if (!remapped) {
515- FileSpec new_spec;
516- if (target_sp->GetImages ().FindSourceFile (m_file_spec, new_spec))
517- remapped = new_spec;
518+ {
519+ FileSpec file_spec = support_file_sp->GetSpecOnly ();
520+ if (!FileSystem::Instance ().Exists (file_spec)) {
521+ // Check target specific source remappings (i.e., the
522+ // target.source-map setting), then fall back to the module
523+ // specific remapping (i.e., the .dSYM remapping dictionary).
524+ auto remapped = target_sp->GetSourcePathMap ().FindFile (file_spec);
525+ if (!remapped) {
526+ FileSpec new_spec;
527+ if (target_sp->GetImages ().FindSourceFile (file_spec, new_spec))
528+ remapped = new_spec;
529+ }
530+ if (remapped)
531+ SetSupportFile (std::make_shared<SupportFile>(
532+ *remapped, support_file_sp->GetChecksum ()));
518533 }
519- if (remapped)
520- SetFileSpec (*remapped);
521534 }
522535 }
523536 }
524537
525538 // If the file exists, read in the data.
526539 if (m_mod_time != llvm::sys::TimePoint<>())
527- m_data_sp = FileSystem::Instance ().CreateDataBuffer (m_file_spec);
540+ m_data_sp = FileSystem::Instance ().CreateDataBuffer (
541+ m_support_file_sp->GetSpecOnly ());
528542}
529543
530- void SourceManager::File::SetFileSpec (FileSpec file_spec) {
544+ void SourceManager::File::SetSupportFile (lldb::SupportFileSP support_file_sp) {
545+ FileSpec file_spec = support_file_sp->GetSpecOnly ();
531546 resolve_tilde (file_spec);
532- m_file_spec = std::move (file_spec);
533- m_mod_time = FileSystem::Instance ().GetModificationTime (m_file_spec);
547+ m_support_file_sp =
548+ std::make_shared<SupportFile>(file_spec, support_file_sp->GetChecksum ());
549+ m_mod_time = FileSystem::Instance ().GetModificationTime (file_spec);
534550}
535551
536552uint32_t SourceManager::File::GetLineOffset (uint32_t line) {
@@ -603,7 +619,8 @@ bool SourceManager::File::ModificationTimeIsStale() const {
603619 // TODO: use host API to sign up for file modifications to anything in our
604620 // source cache and only update when we determine a file has been updated.
605621 // For now we check each time we want to display info for the file.
606- auto curr_mod_time = FileSystem::Instance ().GetModificationTime (m_file_spec);
622+ auto curr_mod_time = FileSystem::Instance ().GetModificationTime (
623+ m_support_file_sp->GetSpecOnly ());
607624 return curr_mod_time != llvm::sys::TimePoint<>() &&
608625 m_mod_time != curr_mod_time;
609626}
@@ -644,7 +661,8 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line,
644661 debugger_sp->GetStopShowColumnAnsiSuffix ());
645662
646663 HighlighterManager mgr;
647- std::string path = GetFileSpec ().GetPath (/* denormalize*/ false );
664+ std::string path =
665+ GetSupportFile ()->GetSpecOnly ().GetPath (/* denormalize*/ false );
648666 // FIXME: Find a way to get the definitive language this file was written in
649667 // and pass it to the highlighter.
650668 const auto &h = mgr.getHighlighterFor (lldb::eLanguageTypeUnknown, path);
@@ -698,7 +716,8 @@ void SourceManager::File::FindLinesMatchingRegex(
698716
699717bool lldb_private::operator ==(const SourceManager::File &lhs,
700718 const SourceManager::File &rhs) {
701- if (lhs.m_file_spec != rhs.m_file_spec )
719+ if (!lhs.GetSupportFile ()->Equal (*rhs.GetSupportFile (),
720+ SupportFile::eEqualChecksumIfSet))
702721 return false ;
703722 return lhs.m_mod_time == rhs.m_mod_time ;
704723}
@@ -778,9 +797,9 @@ void SourceManager::SourceFileCache::AddSourceFile(const FileSpec &file_spec,
778797 assert (file_sp && " invalid FileSP" );
779798
780799 AddSourceFileImpl (file_spec, file_sp);
781- const FileSpec &resolved_file_spec = file_sp->GetFileSpec ();
800+ const FileSpec &resolved_file_spec = file_sp->GetSupportFile ()-> GetSpecOnly ();
782801 if (file_spec != resolved_file_spec)
783- AddSourceFileImpl (file_sp->GetFileSpec (), file_sp);
802+ AddSourceFileImpl (file_sp->GetSupportFile ()-> GetSpecOnly (), file_sp);
784803}
785804
786805void SourceManager::SourceFileCache::RemoveSourceFile (const FileSP &file_sp) {
0 commit comments