@@ -87,8 +87,10 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
87
87
LLDB_LOG (log, " Source file caching disabled: creating new source file: {0}" ,
88
88
file_spec);
89
89
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);
92
94
}
93
95
94
96
ProcessSP process_sp = target_sp ? target_sp->GetProcessSP () : ProcessSP ();
@@ -136,7 +138,8 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
136
138
}
137
139
138
140
// 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 ())) {
140
143
LLDB_LOG (log, " File doesn't exist on disk: {0}" , file_spec);
141
144
file_sp.reset ();
142
145
}
@@ -148,9 +151,11 @@ SourceManager::FileSP SourceManager::GetFile(const FileSpec &file_spec) {
148
151
149
152
// (Re)create the file.
150
153
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);
152
156
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);
154
159
155
160
// Add the file to the debugger and process cache. If the file was
156
161
// invalidated, this will overwrite it.
@@ -444,25 +449,25 @@ void SourceManager::FindLinesMatchingRegex(FileSpec &file_spec,
444
449
match_lines);
445
450
}
446
451
447
- SourceManager::File::File (const FileSpec &file_spec ,
452
+ SourceManager::File::File (SupportFileSP support_file_sp ,
448
453
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(),
450
455
m_debugger_wp(debugger_sp), m_target_wp(TargetSP()) {
451
- CommonInitializer (file_spec , {});
456
+ CommonInitializer (support_file_sp , {});
452
457
}
453
458
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(),
456
461
m_debugger_wp(target_sp ? target_sp->GetDebugger ().shared_from_this()
457
462
: DebuggerSP()),
458
463
m_target_wp(target_sp) {
459
- CommonInitializer (file_spec , target_sp);
464
+ CommonInitializer (support_file_sp , target_sp);
460
465
}
461
466
462
- void SourceManager::File::CommonInitializer (const FileSpec &file_spec ,
467
+ void SourceManager::File::CommonInitializer (SupportFileSP support_file_sp ,
463
468
TargetSP target_sp) {
464
469
// Set the file and update the modification time.
465
- SetFileSpec (file_spec );
470
+ SetSupportFile (support_file_sp );
466
471
467
472
// Always update the source map modification ID if we have a target.
468
473
if (target_sp)
@@ -472,65 +477,76 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
472
477
if (m_mod_time == llvm::sys::TimePoint<>()) {
473
478
if (target_sp) {
474
479
// 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
+ }
496
504
}
497
505
}
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
+ }
504
513
}
505
514
}
506
515
}
507
516
508
517
// 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 ()));
518
533
}
519
- if (remapped)
520
- SetFileSpec (*remapped);
521
534
}
522
535
}
523
536
}
524
537
525
538
// If the file exists, read in the data.
526
539
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 ());
528
542
}
529
543
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 ();
531
546
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);
534
550
}
535
551
536
552
uint32_t SourceManager::File::GetLineOffset (uint32_t line) {
@@ -603,7 +619,8 @@ bool SourceManager::File::ModificationTimeIsStale() const {
603
619
// TODO: use host API to sign up for file modifications to anything in our
604
620
// source cache and only update when we determine a file has been updated.
605
621
// 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 ());
607
624
return curr_mod_time != llvm::sys::TimePoint<>() &&
608
625
m_mod_time != curr_mod_time;
609
626
}
@@ -644,7 +661,8 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line,
644
661
debugger_sp->GetStopShowColumnAnsiSuffix ());
645
662
646
663
HighlighterManager mgr;
647
- std::string path = GetFileSpec ().GetPath (/* denormalize*/ false );
664
+ std::string path =
665
+ GetSupportFile ()->GetSpecOnly ().GetPath (/* denormalize*/ false );
648
666
// FIXME: Find a way to get the definitive language this file was written in
649
667
// and pass it to the highlighter.
650
668
const auto &h = mgr.getHighlighterFor (lldb::eLanguageTypeUnknown, path);
@@ -698,7 +716,8 @@ void SourceManager::File::FindLinesMatchingRegex(
698
716
699
717
bool lldb_private::operator ==(const SourceManager::File &lhs,
700
718
const SourceManager::File &rhs) {
701
- if (lhs.m_file_spec != rhs.m_file_spec )
719
+ if (!lhs.GetSupportFile ()->Equal (*rhs.GetSupportFile (),
720
+ SupportFile::eEqualChecksumIfSet))
702
721
return false ;
703
722
return lhs.m_mod_time == rhs.m_mod_time ;
704
723
}
@@ -778,9 +797,9 @@ void SourceManager::SourceFileCache::AddSourceFile(const FileSpec &file_spec,
778
797
assert (file_sp && " invalid FileSP" );
779
798
780
799
AddSourceFileImpl (file_spec, file_sp);
781
- const FileSpec &resolved_file_spec = file_sp->GetFileSpec ();
800
+ const FileSpec &resolved_file_spec = file_sp->GetSupportFile ()-> GetSpecOnly ();
782
801
if (file_spec != resolved_file_spec)
783
- AddSourceFileImpl (file_sp->GetFileSpec (), file_sp);
802
+ AddSourceFileImpl (file_sp->GetSupportFile ()-> GetSpecOnly (), file_sp);
784
803
}
785
804
786
805
void SourceManager::SourceFileCache::RemoveSourceFile (const FileSP &file_sp) {
0 commit comments