From: Hiroshi Ioka Date: Mon, 14 Aug 2017 08:26:22 +0000 (+0900) Subject: debug/macho: make Type implements fmt.(Go)Stringer interfaces X-Git-Tag: go1.10beta1~1581 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c3fa6f4ddc4a79f436e842742ae735e617f8522e;p=gostls13.git debug/macho: make Type implements fmt.(Go)Stringer interfaces Fixes #21436 Change-Id: I56f43e2852696c28edbcc772a54125a9a9c32497 Reviewed-on: https://go-review.googlesource.com/55262 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/debug/macho/file_test.go b/src/debug/macho/file_test.go index 71896d1b2e..fa84064fa9 100644 --- a/src/debug/macho/file_test.go +++ b/src/debug/macho/file_test.go @@ -217,3 +217,12 @@ func TestRelocTypeString(t *testing.T) { t.Errorf("got %v, want %v", X86_64_RELOC_BRANCH.GoString(), "macho.X86_64_RELOC_BRANCH") } } + +func TestTypeString(t *testing.T) { + if TypeExec.String() != "Exec" { + t.Errorf("got %v, want %v", TypeExec.String(), "Exec") + } + if TypeExec.GoString() != "macho.Exec" { + t.Errorf("got %v, want %v", TypeExec.GoString(), "macho.Exec") + } +} diff --git a/src/debug/macho/macho.go b/src/debug/macho/macho.go index 366ce205df..6535ba787b 100644 --- a/src/debug/macho/macho.go +++ b/src/debug/macho/macho.go @@ -41,6 +41,16 @@ const ( TypeBundle Type = 8 ) +var typeStrings = []intName{ + {uint32(TypeObj), "Obj"}, + {uint32(TypeExec), "Exec"}, + {uint32(TypeDylib), "Dylib"}, + {uint32(TypeBundle), "Bundle"}, +} + +func (t Type) String() string { return stringName(uint32(t), typeStrings, false) } +func (t Type) GoString() string { return stringName(uint32(t), typeStrings, true) } + // A Cpu is a Mach-O cpu type. type Cpu uint32