proc: keep track of nesting depth while reading compile units

Fully read compile units that contain nested entries we don't
understand (such as DW_TAG_namespace) by keeping track of the depth
we're at.
This commit is contained in:
aarzilli
2020-07-16 14:53:59 +02:00
committed by Alessandro Arzilli
parent 8571fddbc1
commit 136f4de4b8
3 changed files with 34 additions and 1 deletions

View File

@ -337,3 +337,19 @@ func TestUnsupportedType(t *testing.T) {
t.Errorf("unexpected error reading unsupported type: %#v", err)
}
}
func TestNestedCompileUnts(t *testing.T) {
// Tests that a compile unit with a nested entry that we don't care about
// (such as a DW_TAG_namespace) is read fully.
dwb := dwarfbuilder.New()
dwb.AddCompileUnit("main", 0x0)
dwb.TagOpen(dwarf.TagNamespace, "namespace")
dwb.AddVariable("var1", 0x0, uint64(0x0))
dwb.TagClose()
dwb.AddVariable("var2", 0x0, uint64(0x0))
dwb.TagClose()
bi, _ := fakeBinaryInfo(t, dwb)
if n := len(bi.PackageVars()); n != 2 {
t.Errorf("expected 2 variables, got %d", n)
}
}