@@ -211,9 +211,10 @@ class ReflectionContext
211
211
uint32_t ThreadPort;
212
212
};
213
213
214
- explicit ReflectionContext (std::shared_ptr<MemoryReader> reader)
215
- : super(std::move(reader), *this)
216
- {}
214
+ explicit ReflectionContext (
215
+ std::shared_ptr<MemoryReader> reader,
216
+ remote::ExternalTypeRefCacheProvider *provider = nullptr )
217
+ : super(std::move(reader), *this, provider) {}
217
218
218
219
ReflectionContext (const ReflectionContext &other) = delete ;
219
220
ReflectionContext &operator =(const ReflectionContext &other) = delete ;
@@ -228,7 +229,8 @@ class ReflectionContext
228
229
}
229
230
230
231
template <typename T>
231
- bool readMachOSections (
232
+ llvm::Optional<uint64_t >
233
+ readMachOSections (
232
234
RemoteAddress ImageStart,
233
235
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
234
236
auto Buf =
@@ -350,7 +352,7 @@ class ReflectionContext
350
352
{MPEnumMdSec.first , MPEnumMdSec.second },
351
353
PotentialModuleNames};
352
354
353
- this ->addReflectionInfo (info);
355
+ auto InfoID = this ->addReflectionInfo (info);
354
356
355
357
// Find the __DATA segment.
356
358
for (unsigned I = 0 ; I < NumCommands; ++I) {
@@ -374,10 +376,10 @@ class ReflectionContext
374
376
375
377
savedBuffers.push_back (std::move (Buf));
376
378
savedBuffers.push_back (std::move (Sections));
377
- return true ;
379
+ return InfoID ;
378
380
}
379
381
380
- bool readPECOFFSections (
382
+ llvm::Optional< uint64_t > readPECOFFSections (
381
383
RemoteAddress ImageStart,
382
384
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
383
385
auto DOSHdrBuf = this ->getReader ().readBytes (
@@ -477,11 +479,10 @@ class ReflectionContext
477
479
{ConformMdSec.first , ConformMdSec.second },
478
480
{MPEnumMdSec.first , MPEnumMdSec.second },
479
481
PotentialModuleNames};
480
- this ->addReflectionInfo (Info);
481
- return true ;
482
+ return this ->addReflectionInfo (Info);
482
483
}
483
484
484
- bool readPECOFF (RemoteAddress ImageStart,
485
+ llvm::Optional< uint64_t > readPECOFF (RemoteAddress ImageStart,
485
486
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
486
487
auto Buf = this ->getReader ().readBytes (ImageStart,
487
488
sizeof (llvm::object::dos_header));
@@ -505,7 +506,7 @@ class ReflectionContext
505
506
}
506
507
507
508
template <typename T>
508
- bool readELFSections (
509
+ llvm::Optional< uint64_t > readELFSections (
509
510
RemoteAddress ImageStart,
510
511
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
511
512
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
@@ -673,8 +674,7 @@ class ReflectionContext
673
674
{MPEnumMdSec.first , MPEnumMdSec.second },
674
675
PotentialModuleNames};
675
676
676
- this ->addReflectionInfo (info);
677
- return true ;
677
+ return this ->addReflectionInfo (info);
678
678
}
679
679
680
680
// / Parses metadata information from an ELF image. Because the Section
@@ -693,22 +693,22 @@ class ReflectionContext
693
693
// / instance's memory reader.
694
694
// /
695
695
// / \return
696
- // / /b True if the metadata information was parsed successfully ,
697
- // / /b false otherwise.
698
- bool
696
+ // / \b The newly added reflection info ID if successful ,
697
+ // / \b llvm::None otherwise.
698
+ llvm::Optional< uint64_t >
699
699
readELF (RemoteAddress ImageStart,
700
700
llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
701
701
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
702
702
auto Buf =
703
703
this ->getReader ().readBytes (ImageStart, sizeof (llvm::ELF::Elf64_Ehdr));
704
704
if (!Buf)
705
- return false ;
705
+ return llvm::None ;
706
706
707
707
// Read the header.
708
708
auto Hdr = reinterpret_cast <const llvm::ELF::Elf64_Ehdr *>(Buf.get ());
709
709
710
710
if (!Hdr->checkMagic ())
711
- return false ;
711
+ return llvm::None ;
712
712
713
713
// Check if we have a ELFCLASS32 or ELFCLASS64
714
714
unsigned char FileClass = Hdr->getFileClass ();
@@ -719,11 +719,11 @@ class ReflectionContext
719
719
return readELFSections<ELFTraits<llvm::ELF::ELFCLASS32>>(
720
720
ImageStart, FileBuffer, PotentialModuleNames);
721
721
} else {
722
- return false ;
722
+ return llvm::None ;
723
723
}
724
724
}
725
725
726
- bool
726
+ llvm::Optional< uint64_t >
727
727
addImage (RemoteAddress ImageStart,
728
728
llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
729
729
// Read the first few bytes to look for a magic header.
@@ -761,7 +761,7 @@ class ReflectionContext
761
761
}
762
762
763
763
// We don't recognize the format.
764
- return false ;
764
+ return llvm::None ;
765
765
}
766
766
767
767
// / Adds an image using the FindSection closure to find the swift metadata
@@ -770,9 +770,9 @@ class ReflectionContext
770
770
// / of freeing the memory buffer in the RemoteRef return value.
771
771
// / process.
772
772
// / \return
773
- // / \b True if any of the reflection sections were registered ,
774
- // / \b false otherwise.
775
- bool
773
+ // / \b The newly added reflection info ID if successful ,
774
+ // / \b llvm::None otherwise.
775
+ llvm::Optional< uint64_t >
776
776
addImage (llvm::function_ref<
777
777
std::pair<RemoteRef<void >, uint64_t >(ReflectionSectionKind)>
778
778
FindSection,
@@ -798,7 +798,7 @@ class ReflectionContext
798
798
799
799
// If we didn't find any sections, return.
800
800
if (llvm::all_of (Pairs, [](const auto &Pair) { return !Pair.first ; }))
801
- return false ;
801
+ return {} ;
802
802
803
803
ReflectionInfo Info = {{Pairs[0 ].first , Pairs[0 ].second },
804
804
{Pairs[1 ].first , Pairs[1 ].second },
@@ -809,12 +809,11 @@ class ReflectionContext
809
809
{Pairs[6 ].first , Pairs[6 ].second },
810
810
{Pairs[7 ].first , Pairs[7 ].second },
811
811
PotentialModuleNames};
812
- this ->addReflectionInfo (Info);
813
- return true ;
812
+ return addReflectionInfo (Info);
814
813
}
815
814
816
- void addReflectionInfo (ReflectionInfo I) {
817
- getBuilder ().addReflectionInfo (I);
815
+ llvm::Optional< uint64_t > addReflectionInfo (ReflectionInfo I) {
816
+ return getBuilder ().addReflectionInfo (I);
818
817
}
819
818
820
819
bool ownsObject (RemoteAddress ObjectAddress) {
0 commit comments