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