Commit 0965459b authored by Russ Cox's avatar Russ Cox

debug/dwarf: handle surprising clang encoding

Fixes a bug in cgo on OS X using clang.
See golang.org/issue/6472 for details.

Fixes #6472.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14575043
parent 7bbe0163
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cgotest
/*
typedef struct
{
struct
{
int x;
} y[16];
} z;
*/
import "C"
func test6472() {
// nothing to run, just make sure this compiles
s := new(C.z)
println(s.y[0].x)
}
...@@ -271,24 +271,43 @@ func (d *Data) Type(off Offset) (Type, error) { ...@@ -271,24 +271,43 @@ func (d *Data) Type(off Offset) (Type, error) {
// d.Type recursively, to handle circular types correctly. // d.Type recursively, to handle circular types correctly.
var typ Type var typ Type
nextDepth := 0
// Get next child; set err if error happens. // Get next child; set err if error happens.
next := func() *Entry { next := func() *Entry {
if !e.Children { if !e.Children {
return nil return nil
} }
kid, err1 := r.Next() // Only return direct children.
if err1 != nil { // Skip over composite entries that happen to be nested
err = err1 // inside this one. Most DWARF generators wouldn't generate
return nil // such a thing, but clang does.
} // See golang.org/issue/6472.
if kid == nil { for {
err = DecodeError{"info", r.b.off, "unexpected end of DWARF entries"} kid, err1 := r.Next()
return nil if err1 != nil {
} err = err1
if kid.Tag == 0 { return nil
return nil }
if kid == nil {
err = DecodeError{"info", r.b.off, "unexpected end of DWARF entries"}
return nil
}
if kid.Tag == 0 {
if nextDepth > 0 {
nextDepth--
continue
}
return nil
}
if kid.Children {
nextDepth++
}
if nextDepth > 0 {
continue
}
return kid
} }
return kid
} }
// Get Type referred to by Entry's AttrType field. // Get Type referred to by Entry's AttrType field.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment