debug: better computation of stride for ArrayType

If the DWARF attribute for the stride of an array in bits is not
present, fall back to the attribute that measures the stride in
bytes, and then to the size of the type of the array's elements.

Change-Id: Ied5afbba6bf05481731a115c8c22d46892330e60
Reviewed-on: https://go-review.googlesource.com/10249
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/dwarf/type.go b/dwarf/type.go
index d61cfa9..1c3223a 100644
--- a/dwarf/type.go
+++ b/dwarf/type.go
@@ -431,7 +431,8 @@
 		// Multi-dimensional array.  (DWARF v2 §5.4)
 		// Attributes:
 		//	AttrType:subtype [required]
-		//	AttrStrideSize: size in bits of each element of the array
+		//	AttrStrideSize: distance in bits between each element of the array
+		//	AttrStride: distance in bytes between each element of the array
 		//	AttrByteSize: size of entire array
 		// Children:
 		//	TagSubrangeType or TagEnumerationType giving one dimension.
@@ -443,7 +444,15 @@
 		if t.Type = typeOf(e, AttrType); err != nil {
 			goto Error
 		}
-		t.StrideBitSize, _ = e.Val(AttrStrideSize).(int64)
+		if bytes, ok := e.Val(AttrStride).(int64); ok {
+			t.StrideBitSize = 8 * bytes
+		} else if bits, ok := e.Val(AttrStrideSize).(int64); ok {
+			t.StrideBitSize = bits
+		} else {
+			// If there's no stride specified, assume it's the size of the
+			// array's element type.
+			t.StrideBitSize = 8 * t.Type.Size()
+		}
 
 		// Accumulate dimensions,
 		ndim := 0