Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created November 6, 2017 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmm1/d83b7891a1d8e5887cba7ebde62cbff4 to your computer and use it in GitHub Desktop.
Save tmm1/d83b7891a1d8e5887cba7ebde62cbff4 to your computer and use it in GitHub Desktop.
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index c104067a93..d9d6d7c7bf 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -64,6 +64,9 @@ func cname(s string) string {
if strings.HasPrefix(s, "sizeof_") {
return "sizeof(" + cname(s[len("sizeof_"):]) + ")"
}
+ if strings.HasPrefix(s, "objc_class_") {
+ return s[len("objc_class_"):]
+ }
return s
}
@@ -1269,7 +1272,8 @@ func (p *Package) gccCmd() []string {
"-o"+gccTmp(), // write object to tmp
"-gdwarf-2", // generate DWARF v2 debugging symbols
"-c", // do not link
- "-xc", // input language is C
+
+ "-xobjective-c", // input language is C
)
if p.GccIsClang {
c = append(c,
@@ -1588,7 +1592,7 @@ func (p *Package) gccDebug(stdin []byte, nnames int) (d *dwarf.Data, ints []int6
// #defines that gcc encountered while processing the input
// and its included files.
func (p *Package) gccDefines(stdin []byte) string {
- base := append(p.gccBaseCmd(), "-E", "-dM", "-xc")
+ base := append(p.gccBaseCmd(), "-E", "-dM", "-xobjective-c")
base = append(base, p.gccMachine()...)
stdout, _ := runGcc(stdin, append(append(base, p.GccOptions...), "-"))
return stdout
@@ -2036,6 +2040,11 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
}
t.Align = 1 // TODO: should probably base this on field alignment.
typedef[name.Name] = t
+ case "objc_class":
+ t.C.Set("%s", tag)
+ t.Go = c.Opaque(t.Size)
+ //t.Go = &ast.StructType{Fields: &ast.FieldList{List: nil}}
+ typedef[name.Name] = t
case "struct":
g, csyntax, align := c.Struct(dt, pos)
if t.C.Empty() {
@@ -2200,6 +2209,7 @@ func isStructUnionClass(x ast.Expr) bool {
name := id.Name
return strings.HasPrefix(name, "_Ctype_struct_") ||
strings.HasPrefix(name, "_Ctype_union_") ||
+ strings.HasPrefix(name, "_Ctype_objc_class_") ||
strings.HasPrefix(name, "_Ctype_class_")
}
diff --git a/src/debug/dwarf/const.go b/src/debug/dwarf/const.go
index 04d8c506b0..a0d0a8e12c 100644
--- a/src/debug/dwarf/const.go
+++ b/src/debug/dwarf/const.go
@@ -84,6 +84,8 @@ const (
AttrCallFile Attr = 0x58
AttrCallLine Attr = 0x59
AttrDescription Attr = 0x5A
+
+ AttrAppleRuntimeClass Attr = 0x3FE6
)
var attrNames = [...]string{
diff --git a/src/debug/dwarf/type.go b/src/debug/dwarf/type.go
index 9b39078a6f..2483b9c0f5 100644
--- a/src/debug/dwarf/type.go
+++ b/src/debug/dwarf/type.go
@@ -508,6 +508,9 @@ func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Off
case TagUnionType:
t.Kind = "union"
}
+ if e.Val(AttrAppleRuntimeClass) != nil {
+ t.Kind = "objc_class"
+ }
t.StructName, _ = e.Val(AttrName).(string)
t.Incomplete = e.Val(AttrDeclaration) != nil
t.Field = make([]*StructField, 0, 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment