diff options
| author | Russ Cox <rsc@golang.org> | 2012-02-28 16:18:24 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2012-02-28 16:18:24 -0500 |
| commit | 6e2ae0a12c0f73da56d4f465e68208731b4b16be (patch) | |
| tree | 97b35b94a6880d7eb9a458663e1bfe432e4731e9 /src/cmd/objdump | |
| parent | c10f50859ead8f1578e86e65d5f376ae6a3a32df (diff) | |
| download | go-6e2ae0a12c0f73da56d4f465e68208731b4b16be.tar.xz | |
runtime/pprof: support OS X CPU profiling
Work around profiling kernel bug with signal masks.
Still broken on 64-bit Snow Leopard kernel,
but I think we can ignore that one and let people
upgrade to Lion.
Add new trivial tools addr2line and objdump to take
the place of the GNU tools of the same name, since
those are not installed on OS X.
Adapt pprof to invoke 'go tool addr2line' and
'go tool objdump' if the system tools do not exist.
Clean up disassembly of base register on amd64.
Fixes #2008.
R=golang-dev, bradfitz, mikioh.mikioh, r, iant
CC=golang-dev
https://golang.org/cl/5697066
Diffstat (limited to 'src/cmd/objdump')
| -rw-r--r-- | src/cmd/objdump/main.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/cmd/objdump/main.c b/src/cmd/objdump/main.c new file mode 100644 index 0000000000..b684be7fbe --- /dev/null +++ b/src/cmd/objdump/main.c @@ -0,0 +1,68 @@ +// Copyright 2012 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. + +/* + * objdump simulation - only enough to make pprof work on Macs + */ + +#include <u.h> +#include <libc.h> +#include <bio.h> +#include <mach.h> + +void +usage(void) +{ + fprint(2, "usage: objdump binary start stop\n"); + fprint(2, "Disassembles binary from PC start up to stop.\n"); + exits("usage"); +} + +void +main(int argc, char **argv) +{ + int fd, n; + uvlong pc, start, stop; + Fhdr fhdr; + Biobuf bout; + char buf[1024]; + Map *text; + + ARGBEGIN{ + default: + usage(); + }ARGEND + + if(argc != 3) + usage(); + start = strtoull(argv[1], 0, 16); + stop = strtoull(argv[2], 0, 16); + + fd = open(argv[0], OREAD); + if(fd < 0) + sysfatal("open %s: %r", argv[0]); + if(crackhdr(fd, &fhdr) <= 0) + sysfatal("crackhdr: %r"); + machbytype(fhdr.type); + if(syminit(fd, &fhdr) <= 0) + sysfatal("syminit: %r"); + text = loadmap(nil, fd, &fhdr); + if(text == nil) + sysfatal("loadmap: %r"); + + Binit(&bout, 1, OWRITE); + for(pc=start; pc<stop; ) { + if(fileline(buf, sizeof buf, pc)) + Bprint(&bout, "%s\n", buf); + buf[0] = '\0'; + machdata->das(text, pc, 0, buf, sizeof buf); + Bprint(&bout, " %llx: %s\n", pc, buf); + n = machdata->instsize(text, pc); + if(n <= 0) + break; + pc += n; + } + Bflush(&bout); + exits(0); +} |
