code review 14575043: debug/dwarf: handle surprising clang encoding (issue 14575043)

66 views
Skip to first unread message

r...@golang.org

unread,
Oct 8, 2013, 9:03:15 PM10/8/13
to golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-dev1,

Message:
Hello golan...@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go/


Description:
debug/dwarf: handle surprising clang encoding

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

Fixes issue 6472.

Please review this at https://codereview.appspot.com/14575043/

Affected files (+54, -12 lines):
A misc/cgo/test/issue6472.go
M src/pkg/debug/dwarf/type.go


Index: misc/cgo/test/issue6472.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/misc/cgo/test/issue6472.go
@@ -0,0 +1,23 @@
+// 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)
+}
+
Index: src/pkg/debug/dwarf/type.go
===================================================================
--- a/src/pkg/debug/dwarf/type.go
+++ b/src/pkg/debug/dwarf/type.go
@@ -271,24 +271,43 @@
// d.Type recursively, to handle circular types correctly.
var typ Type

+ nextDepth := 0
+
// Get next child; set err if error happens.
next := func() *Entry {
if !e.Children {
return nil
}
- kid, err1 := r.Next()
- if err1 != nil {
- err = err1
- return nil
+ // Only return direct children.
+ // Skip over composite entries that happen to be nested
+ // inside this one. Most DWARF generators wouldn't generate
+ // such a thing, but clang does.
+ // See golang.org/issue/6472.
+ for {
+ kid, err1 := r.Next()
+ if err1 != nil {
+ err = err1
+ 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
}
- if kid == nil {
- err = DecodeError{"info", r.b.off, "unexpected end of DWARF entries"}
- return nil
- }
- if kid.Tag == 0 {
- return nil
- }
- return kid
}

// Get Type referred to by Entry's AttrType field.


ia...@golang.org

unread,
Oct 9, 2013, 10:07:01 AM10/9/13
to r...@golang.org, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com

Russ Cox

unread,
Oct 9, 2013, 11:07:59 AM10/9/13
to Russ Cox, golang-dev, Ian Taylor, re...@codereview-hr.appspotmail.com
no +build; we only build that directory to run the cgo tests.
none of the other files have them.

r...@golang.org

unread,
Oct 9, 2013, 11:08:27 AM10/9/13
to r...@golang.org, golan...@googlegroups.com, ia...@golang.org, re...@codereview-hr.appspotmail.com
*** Submitted as
https://code.google.com/p/go/source/detail?r=71051fea795a ***

debug/dwarf: handle surprising clang encoding

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

Fixes issue 6472.

R=golang-dev, iant
CC=golang-dev
https://codereview.appspot.com/14575043


https://codereview.appspot.com/14575043/
Reply all
Reply to author
Forward
0 new messages