@@ -640,6 +640,100 @@ TEST_F(DebugLineBasicFixture,
640
640
EXPECT_EQ ((*ExpectedLineTable)->Rows [1 ].Address .Address , Addr2);
641
641
}
642
642
643
+ TEST_F (DebugLineBasicFixture,
644
+ ErrorForUnsupportedAddressSizeInSetAddressLength) {
645
+ // Use DWARF v4, and 0 for data extractor address size so that the address
646
+ // size is derived from the opcode length.
647
+ if (!setupGenerator (4 , 0 ))
648
+ return ;
649
+
650
+ LineTable < = Gen->addLineTable ();
651
+ // 4 == length of the extended opcode, i.e. 1 for the opcode itself and 3 for
652
+ // the Half (2) + Byte (1) operand, representing the unsupported address size.
653
+ LT.addExtendedOpcode (4 , DW_LNE_set_address,
654
+ {{0x1234 , LineTable::Half}, {0x56 , LineTable::Byte}});
655
+ LT.addStandardOpcode (DW_LNS_copy, {});
656
+ // Special opcode to ensure the address has changed between the first and last
657
+ // row in the sequence. Without this, the sequence will not be recorded.
658
+ LT.addByte (0xaa );
659
+ LT.addExtendedOpcode (1 , DW_LNE_end_sequence, {});
660
+
661
+ generate ();
662
+
663
+ auto ExpectedLineTable = Line.getOrParseLineTable (LineData, 0 , *Context,
664
+ nullptr , RecordRecoverable);
665
+ checkError (
666
+ " address size 0x03 of DW_LNE_set_address opcode at offset 0x00000030 is "
667
+ " unsupported" ,
668
+ std::move (Recoverable));
669
+ ASSERT_THAT_EXPECTED (ExpectedLineTable, Succeeded ());
670
+ ASSERT_EQ ((*ExpectedLineTable)->Rows .size (), 3u );
671
+ EXPECT_EQ ((*ExpectedLineTable)->Sequences .size (), 1u );
672
+ // Show that the set address opcode is ignored in this case.
673
+ EXPECT_EQ ((*ExpectedLineTable)->Rows [0 ].Address .Address , 0 );
674
+ }
675
+
676
+ TEST_F (DebugLineBasicFixture, ErrorForAddressSizeGreaterThanByteSize) {
677
+ // Use DWARF v4, and 0 for data extractor address size so that the address
678
+ // size is derived from the opcode length.
679
+ if (!setupGenerator (4 , 0 ))
680
+ return ;
681
+
682
+ LineTable < = Gen->addLineTable ();
683
+ // Specifically use an operand size that has a trailing byte of a supported
684
+ // size (8), so that any potential truncation would result in a valid size.
685
+ std::vector<LineTable::ValueAndLength> Operands (0x108 );
686
+ LT.addExtendedOpcode (Operands.size () + 1 , DW_LNE_set_address, Operands);
687
+ LT.addExtendedOpcode (1 , DW_LNE_end_sequence, {});
688
+
689
+ generate ();
690
+
691
+ auto ExpectedLineTable = Line.getOrParseLineTable (LineData, 0 , *Context,
692
+ nullptr , RecordRecoverable);
693
+ checkError (
694
+ " address size 0x108 of DW_LNE_set_address opcode at offset 0x00000031 is "
695
+ " unsupported" ,
696
+ std::move (Recoverable));
697
+ ASSERT_THAT_EXPECTED (ExpectedLineTable, Succeeded ());
698
+ }
699
+
700
+ TEST_F (DebugLineBasicFixture, ErrorForUnsupportedAddressSizeDefinedInHeader) {
701
+ // Use 0 for data extractor address size so that it does not clash with the
702
+ // header address size.
703
+ if (!setupGenerator (5 , 0 ))
704
+ return ;
705
+
706
+ LineTable < = Gen->addLineTable ();
707
+ // AddressSize + 1 == length of the extended opcode, i.e. 1 for the opcode
708
+ // itself and 9 for the Quad (8) + Byte (1) operand representing the
709
+ // unsupported address size.
710
+ uint8_t AddressSize = 9 ;
711
+ LT.addExtendedOpcode (AddressSize + 1 , DW_LNE_set_address,
712
+ {{0x12345678 , LineTable::Quad}, {0 , LineTable::Byte}});
713
+ LT.addStandardOpcode (DW_LNS_copy, {});
714
+ // Special opcode to ensure the address has changed between the first and last
715
+ // row in the sequence. Without this, the sequence will not be recorded.
716
+ LT.addByte (0xaa );
717
+ LT.addExtendedOpcode (1 , DW_LNE_end_sequence, {});
718
+ DWARFDebugLine::Prologue Prologue = LT.createBasicPrologue ();
719
+ Prologue.FormParams .AddrSize = AddressSize;
720
+ LT.setPrologue (Prologue);
721
+
722
+ generate ();
723
+
724
+ auto ExpectedLineTable = Line.getOrParseLineTable (LineData, 0 , *Context,
725
+ nullptr , RecordRecoverable);
726
+ checkError (
727
+ " address size 0x09 of DW_LNE_set_address opcode at offset 0x00000038 is "
728
+ " unsupported" ,
729
+ std::move (Recoverable));
730
+ ASSERT_THAT_EXPECTED (ExpectedLineTable, Succeeded ());
731
+ ASSERT_EQ ((*ExpectedLineTable)->Rows .size (), 3u );
732
+ EXPECT_EQ ((*ExpectedLineTable)->Sequences .size (), 1u );
733
+ // Show that the set address opcode is ignored in this case.
734
+ EXPECT_EQ ((*ExpectedLineTable)->Rows [0 ].Address .Address , 0 );
735
+ }
736
+
643
737
TEST_F (DebugLineBasicFixture, CallbackUsedForUnterminatedSequence) {
644
738
if (!setupGenerator ())
645
739
return ;
0 commit comments