@@ -227,7 +227,10 @@ class ReflectionContext
227
227
return sizeof (StoredPointer) * 2 ;
228
228
}
229
229
230
- template <typename T> bool readMachOSections (RemoteAddress ImageStart) {
230
+ template <typename T>
231
+ bool readMachOSections (
232
+ RemoteAddress ImageStart,
233
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
231
234
auto Buf =
232
235
this ->getReader ().readBytes (ImageStart, sizeof (typename T::Header));
233
236
if (!Buf)
@@ -337,15 +340,15 @@ class ReflectionContext
337
340
MPEnumMdSec.first == nullptr )
338
341
return false ;
339
342
340
- ReflectionInfo info = {
341
- {FieldMdSec .first , FieldMdSec .second },
342
- {AssocTySec .first , AssocTySec .second },
343
- {BuiltinTySec .first , BuiltinTySec .second },
344
- {CaptureSec .first , CaptureSec .second },
345
- {TypeRefMdSec .first , TypeRefMdSec .second },
346
- {ReflStrMdSec .first , ReflStrMdSec .second },
347
- {ConformMdSec .first , ConformMdSec .second },
348
- {MPEnumMdSec. first , MPEnumMdSec. second } };
343
+ ReflectionInfo info = {{FieldMdSec. first , FieldMdSec. second },
344
+ {AssocTySec .first , AssocTySec .second },
345
+ {BuiltinTySec .first , BuiltinTySec .second },
346
+ {CaptureSec .first , CaptureSec .second },
347
+ {TypeRefMdSec .first , TypeRefMdSec .second },
348
+ {ReflStrMdSec .first , ReflStrMdSec .second },
349
+ {ConformMdSec .first , ConformMdSec .second },
350
+ {MPEnumMdSec .first , MPEnumMdSec .second },
351
+ PotentialModuleNames };
349
352
350
353
this ->addReflectionInfo (info);
351
354
@@ -374,7 +377,9 @@ class ReflectionContext
374
377
return true ;
375
378
}
376
379
377
- bool readPECOFFSections (RemoteAddress ImageStart) {
380
+ bool readPECOFFSections (
381
+ RemoteAddress ImageStart,
382
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
378
383
auto DOSHdrBuf = this ->getReader ().readBytes (
379
384
ImageStart, sizeof (llvm::object::dos_header));
380
385
if (!DOSHdrBuf)
@@ -463,20 +468,21 @@ class ReflectionContext
463
468
MPEnumMdSec.first == nullptr )
464
469
return false ;
465
470
466
- ReflectionInfo Info = {
467
- {FieldMdSec .first , FieldMdSec .second },
468
- {AssocTySec .first , AssocTySec .second },
469
- {BuiltinTySec .first , BuiltinTySec .second },
470
- {CaptureSec .first , CaptureSec .second },
471
- {TypeRefMdSec .first , TypeRefMdSec .second },
472
- {ReflStrMdSec .first , ReflStrMdSec .second },
473
- {ConformMdSec .first , ConformMdSec .second },
474
- {MPEnumMdSec. first , MPEnumMdSec. second } };
471
+ ReflectionInfo Info = {{FieldMdSec. first , FieldMdSec. second },
472
+ {AssocTySec .first , AssocTySec .second },
473
+ {BuiltinTySec .first , BuiltinTySec .second },
474
+ {CaptureSec .first , CaptureSec .second },
475
+ {TypeRefMdSec .first , TypeRefMdSec .second },
476
+ {ReflStrMdSec .first , ReflStrMdSec .second },
477
+ {ConformMdSec .first , ConformMdSec .second },
478
+ {MPEnumMdSec .first , MPEnumMdSec .second },
479
+ PotentialModuleNames };
475
480
this ->addReflectionInfo (Info);
476
481
return true ;
477
482
}
478
483
479
- bool readPECOFF (RemoteAddress ImageStart) {
484
+ bool readPECOFF (RemoteAddress ImageStart,
485
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
480
486
auto Buf = this ->getReader ().readBytes (ImageStart,
481
487
sizeof (llvm::object::dos_header));
482
488
if (!Buf)
@@ -495,12 +501,14 @@ class ReflectionContext
495
501
if (memcmp (Buf.get (), llvm::COFF::PEMagic, sizeof (llvm::COFF::PEMagic)))
496
502
return false ;
497
503
498
- return readPECOFFSections (ImageStart);
504
+ return readPECOFFSections (ImageStart, PotentialModuleNames );
499
505
}
500
506
501
507
template <typename T>
502
- bool readELFSections (RemoteAddress ImageStart,
503
- llvm::Optional<llvm::sys::MemoryBlock> FileBuffer) {
508
+ bool readELFSections (
509
+ RemoteAddress ImageStart,
510
+ llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
511
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
504
512
// When reading from the FileBuffer we can simply return a pointer to
505
513
// the underlying data.
506
514
// When reading from the process, we need to keep the memory around
@@ -655,15 +663,15 @@ class ReflectionContext
655
663
MPEnumMdSec.first == nullptr )
656
664
return false ;
657
665
658
- ReflectionInfo info = {
659
- {FieldMdSec .first , FieldMdSec .second },
660
- {AssocTySec .first , AssocTySec .second },
661
- {BuiltinTySec .first , BuiltinTySec .second },
662
- {CaptureSec .first , CaptureSec .second },
663
- {TypeRefMdSec .first , TypeRefMdSec .second },
664
- {ReflStrMdSec .first , ReflStrMdSec .second },
665
- {ConformMdSec .first , ConformMdSec .second },
666
- {MPEnumMdSec. first , MPEnumMdSec. second } };
666
+ ReflectionInfo info = {{FieldMdSec. first , FieldMdSec. second },
667
+ {AssocTySec .first , AssocTySec .second },
668
+ {BuiltinTySec .first , BuiltinTySec .second },
669
+ {CaptureSec .first , CaptureSec .second },
670
+ {TypeRefMdSec .first , TypeRefMdSec .second },
671
+ {ReflStrMdSec .first , ReflStrMdSec .second },
672
+ {ConformMdSec .first , ConformMdSec .second },
673
+ {MPEnumMdSec .first , MPEnumMdSec .second },
674
+ PotentialModuleNames };
667
675
668
676
this ->addReflectionInfo (info);
669
677
return true ;
@@ -687,7 +695,10 @@ class ReflectionContext
687
695
// / \return
688
696
// / /b True if the metadata information was parsed successfully,
689
697
// / /b false otherwise.
690
- bool readELF (RemoteAddress ImageStart, llvm::Optional<llvm::sys::MemoryBlock> FileBuffer) {
698
+ bool
699
+ readELF (RemoteAddress ImageStart,
700
+ llvm::Optional<llvm::sys::MemoryBlock> FileBuffer,
701
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
691
702
auto Buf =
692
703
this ->getReader ().readBytes (ImageStart, sizeof (llvm::ELF::Elf64_Ehdr));
693
704
if (!Buf)
@@ -703,16 +714,18 @@ class ReflectionContext
703
714
unsigned char FileClass = Hdr->getFileClass ();
704
715
if (FileClass == llvm::ELF::ELFCLASS64) {
705
716
return readELFSections<ELFTraits<llvm::ELF::ELFCLASS64>>(
706
- ImageStart, FileBuffer);
717
+ ImageStart, FileBuffer, PotentialModuleNames );
707
718
} else if (FileClass == llvm::ELF::ELFCLASS32) {
708
719
return readELFSections<ELFTraits<llvm::ELF::ELFCLASS32>>(
709
- ImageStart, FileBuffer);
720
+ ImageStart, FileBuffer, PotentialModuleNames );
710
721
} else {
711
722
return false ;
712
723
}
713
724
}
714
725
715
- bool addImage (RemoteAddress ImageStart) {
726
+ bool
727
+ addImage (RemoteAddress ImageStart,
728
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
716
729
// Read the first few bytes to look for a magic header.
717
730
auto Magic = this ->getReader ().readBytes (ImageStart, sizeof (uint32_t ));
718
731
if (!Magic)
@@ -723,18 +736,18 @@ class ReflectionContext
723
736
724
737
// 32- and 64-bit Mach-O.
725
738
if (MagicWord == llvm::MachO::MH_MAGIC) {
726
- return readMachOSections<MachOTraits<4 >>(ImageStart);
739
+ return readMachOSections<MachOTraits<4 >>(ImageStart, PotentialModuleNames );
727
740
}
728
741
729
742
if (MagicWord == llvm::MachO::MH_MAGIC_64) {
730
- return readMachOSections<MachOTraits<8 >>(ImageStart);
743
+ return readMachOSections<MachOTraits<8 >>(ImageStart, PotentialModuleNames );
731
744
}
732
745
733
746
// PE. (This just checks for the DOS header; `readPECOFF` will further
734
747
// validate the existence of the PE header.)
735
748
auto MagicBytes = (const char *)Magic.get ();
736
749
if (MagicBytes[0 ] == ' M' && MagicBytes[1 ] == ' Z' ) {
737
- return readPECOFF (ImageStart);
750
+ return readPECOFF (ImageStart, PotentialModuleNames );
738
751
}
739
752
740
753
@@ -743,7 +756,8 @@ class ReflectionContext
743
756
&& MagicBytes[1 ] == llvm::ELF::ElfMagic[1 ]
744
757
&& MagicBytes[2 ] == llvm::ELF::ElfMagic[2 ]
745
758
&& MagicBytes[3 ] == llvm::ELF::ElfMagic[3 ]) {
746
- return readELF (ImageStart, llvm::Optional<llvm::sys::MemoryBlock>());
759
+ return readELF (ImageStart, llvm::Optional<llvm::sys::MemoryBlock>(),
760
+ PotentialModuleNames);
747
761
}
748
762
749
763
// We don't recognize the format.
@@ -758,9 +772,11 @@ class ReflectionContext
758
772
// / \return
759
773
// / \b True if any of the reflection sections were registered,
760
774
// / \b false otherwise.
761
- bool addImage (llvm::function_ref<
762
- std::pair<RemoteRef<void >, uint64_t >(ReflectionSectionKind)>
763
- FindSection) {
775
+ bool
776
+ addImage (llvm::function_ref<
777
+ std::pair<RemoteRef<void >, uint64_t >(ReflectionSectionKind)>
778
+ FindSection,
779
+ llvm::SmallVector<llvm::StringRef, 1 > PotentialModuleNames = {}) {
764
780
auto Sections = {
765
781
ReflectionSectionKind::fieldmd, ReflectionSectionKind::assocty,
766
782
ReflectionSectionKind::builtin, ReflectionSectionKind::capture,
@@ -784,11 +800,15 @@ class ReflectionContext
784
800
if (llvm::all_of (Pairs, [](const auto &Pair) { return !Pair.first ; }))
785
801
return false ;
786
802
787
- ReflectionInfo Info = {
788
- {Pairs[0 ].first , Pairs[0 ].second }, {Pairs[1 ].first , Pairs[1 ].second },
789
- {Pairs[2 ].first , Pairs[2 ].second }, {Pairs[3 ].first , Pairs[3 ].second },
790
- {Pairs[4 ].first , Pairs[4 ].second }, {Pairs[5 ].first , Pairs[5 ].second },
791
- {Pairs[6 ].first , Pairs[6 ].second }, {Pairs[7 ].first , Pairs[7 ].second }};
803
+ ReflectionInfo Info = {{Pairs[0 ].first , Pairs[0 ].second },
804
+ {Pairs[1 ].first , Pairs[1 ].second },
805
+ {Pairs[2 ].first , Pairs[2 ].second },
806
+ {Pairs[3 ].first , Pairs[3 ].second },
807
+ {Pairs[4 ].first , Pairs[4 ].second },
808
+ {Pairs[5 ].first , Pairs[5 ].second },
809
+ {Pairs[6 ].first , Pairs[6 ].second },
810
+ {Pairs[7 ].first , Pairs[7 ].second },
811
+ PotentialModuleNames};
792
812
this ->addReflectionInfo (Info);
793
813
return true ;
794
814
}
0 commit comments