aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorHiroshi Ioka <hirochachacha@gmail.com>2017-08-14 17:26:22 +0900
committerIan Lance Taylor <iant@golang.org>2017-08-15 00:13:36 +0000
commitc3fa6f4ddc4a79f436e842742ae735e617f8522e (patch)
treeddd5381043ebca33cd1e3a82042d31a022917b38 /src/debug
parent90ffc40e4f3d81ad6b9f57092074f8fef68cf128 (diff)
downloadgo-c3fa6f4ddc4a79f436e842742ae735e617f8522e.tar.xz
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 <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/macho/file_test.go9
-rw-r--r--src/debug/macho/macho.go10
2 files changed, 19 insertions, 0 deletions
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