1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
6
* addr2line simulation - only enough to make pprof work on Macs
17
fprint(fd, "usage: addr2line binary\n");
18
fprint(fd, "reads addresses from standard input and writes two lines for each:\n");
19
fprint(fd, "\tfunction name\n");
20
fprint(fd, "\tfile:line\n");
31
main(int argc, char **argv)
41
if(argc > 1 && strcmp(argv[1], "--help") == 0) {
54
fd = open(argv[0], OREAD);
56
sysfatal("open %s: %r", argv[0]);
57
if(crackhdr(fd, &fhdr) <= 0)
58
sysfatal("crackhdr: %r");
59
machbytype(fhdr.type);
60
if(syminit(fd, &fhdr) <= 0)
61
sysfatal("syminit: %r");
63
Binit(&bin, 0, OREAD);
64
Binit(&bout, 1, OWRITE);
66
p = Brdline(&bin, '\n');
69
p[Blinelen(&bin)-1] = '\0';
72
// reverse: translate file:line to pc
74
pc = file2pc(p, atoi(q));
76
Bprint(&bout, "!%r\n");
78
Bprint(&bout, "0x%llux\n", pc);
81
pc = strtoull(p, 0, 16);
82
if(!findsym(pc, CTEXT, &s))
84
if(!fileline(file, sizeof file, pc))
86
Bprint(&bout, "%s\n%s\n", s.name, file);