@@ -520,6 +520,13 @@ TEST_P(GetAttributesTestFixture, TestGetAttributes_IterationOrder) {
520520TEST_P (GetAttributesTestFixture, TestGetAttributes_Cycle) {
521521 // Tests that GetAttributes can deal with cycles in
522522 // specifications/abstract origins.
523+ //
524+ // Contrived example:
525+ //
526+ // func1 -> func3
527+ // ^ |
528+ // | v
529+ // +------func2
523530
524531 const char *yamldata = R"(
525532--- !ELF
@@ -578,12 +585,45 @@ TEST_P(GetAttributesTestFixture, TestGetAttributes_Cycle) {
578585 ASSERT_EQ (unit->GetDWARFLanguageType (), DW_LANG_C_plus_plus);
579586 DWARFDIE cu_die (unit, cu_entry);
580587
581- auto func = cu_die.GetFirstChild ();
582- ASSERT_TRUE (func.IsValid ());
583- ASSERT_EQ (func.Tag (), DW_TAG_subprogram);
588+ auto func1 = cu_die.GetFirstChild ();
589+ ASSERT_TRUE (func1.IsValid ());
590+ ASSERT_EQ (func1.Tag (), DW_TAG_subprogram);
591+
592+ auto func2 = func1.GetSibling ();
593+ ASSERT_TRUE (func2.IsValid ());
594+ ASSERT_EQ (func2.Tag (), DW_TAG_subprogram);
595+
596+ auto func3 = func2.GetSibling ();
597+ ASSERT_TRUE (func3.IsValid ());
598+ ASSERT_EQ (func3.Tag (), DW_TAG_subprogram);
584599
585- auto attrs = func .GetAttributes (DWARFDebugInfoEntry::Recurse::yes);
600+ auto attrs = func1 .GetAttributes (DWARFDebugInfoEntry::Recurse::yes);
586601 EXPECT_EQ (attrs.Size (), 3U );
602+
603+ // Confirm that the specifications do form a cycle.
604+ {
605+ DWARFFormValue form_value;
606+ auto success = attrs.ExtractFormValueAtIndex (0 , form_value);
607+ ASSERT_TRUE (success);
608+
609+ EXPECT_EQ (form_value.Reference (), func3);
610+ }
611+
612+ {
613+ DWARFFormValue form_value;
614+ auto success = attrs.ExtractFormValueAtIndex (1 , form_value);
615+ ASSERT_TRUE (success);
616+
617+ EXPECT_EQ (form_value.Reference (), func2);
618+ }
619+
620+ {
621+ DWARFFormValue form_value;
622+ auto success = attrs.ExtractFormValueAtIndex (2 , form_value);
623+ ASSERT_TRUE (success);
624+
625+ EXPECT_EQ (form_value.Reference (), func1);
626+ }
587627}
588628
589629TEST_P (GetAttributesTestFixture,
0 commit comments