提交 136f4de4 编写于 作者: A aarzilli 提交者: Alessandro Arzilli

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.
上级 8571fddb
......@@ -1618,6 +1618,8 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugLineBytes []byte, wg
func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContext, image *Image, reader *reader.Reader, cu *compileUnit) {
hasAttrGoPkgName := goversion.ProducerAfterOrEqual(cu.producer, 1, 13)
depth := 0
for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() {
if err != nil {
image.setLoadError("error reading debug_info: %v", err)
......@@ -1625,7 +1627,11 @@ func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContex
}
switch entry.Tag {
case 0:
return
if depth == 0 {
return
} else {
depth--
}
case dwarf.TagImportedUnit:
bi.loadDebugInfoMapsImportedUnit(entry, ctxt, image, cu)
reader.SkipChildren()
......@@ -1695,6 +1701,11 @@ func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContex
bi.addConcreteSubprogram(entry, ctxt, reader, cu)
}
}
default:
if entry.Children {
depth++
}
}
}
}
......
package proc
// PackageVars returns bi.packageVars (for tests)
func (bi *BinaryInfo) PackageVars() []packageVar {
return bi.packageVars
}
......@@ -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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册