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