~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/addr2line/main.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
4
 
 
5
 
/*
6
 
 * addr2line simulation - only enough to make pprof work on Macs
7
 
 */
8
 
 
9
 
#include <u.h>
10
 
#include <libc.h>
11
 
#include <bio.h>
12
 
#include <mach.h>
13
 
 
14
 
void
15
 
printusage(int fd)
16
 
{
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");
21
 
}
22
 
 
23
 
void
24
 
usage(void)
25
 
{
26
 
        printusage(2);
27
 
        exits("usage");
28
 
}
29
 
 
30
 
void
31
 
main(int argc, char **argv)
32
 
{
33
 
        int fd;
34
 
        char *p, *q;
35
 
        uvlong pc;
36
 
        Symbol s;
37
 
        Fhdr fhdr;
38
 
        Biobuf bin, bout;
39
 
        char file[1024];
40
 
 
41
 
        if(argc > 1 && strcmp(argv[1], "--help") == 0) {
42
 
                printusage(1);
43
 
                exits(0);
44
 
        }
45
 
 
46
 
        ARGBEGIN{
47
 
        default:
48
 
                usage();
49
 
        }ARGEND
50
 
 
51
 
        if(argc != 1)
52
 
                usage();
53
 
 
54
 
        fd = open(argv[0], OREAD);
55
 
        if(fd < 0)
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");
62
 
 
63
 
        Binit(&bin, 0, OREAD);
64
 
        Binit(&bout, 1, OWRITE);
65
 
        for(;;) {
66
 
                p = Brdline(&bin, '\n');
67
 
                if(p == nil)
68
 
                        break;
69
 
                p[Blinelen(&bin)-1] = '\0';
70
 
                q = strchr(p, ':');
71
 
                if(q != nil) {
72
 
                        // reverse: translate file:line to pc
73
 
                        *q++ = '\0';
74
 
                        pc = file2pc(p, atoi(q));
75
 
                        if(pc == ~(uvlong)0)
76
 
                                Bprint(&bout, "!%r\n");
77
 
                        else
78
 
                                Bprint(&bout, "0x%llux\n", pc);
79
 
                        continue;
80
 
                }                       
81
 
                pc = strtoull(p, 0, 16);
82
 
                if(!findsym(pc, CTEXT, &s))
83
 
                        s.name = "??";
84
 
                if(!fileline(file, sizeof file, pc))
85
 
                        strcpy(file, "??:0");
86
 
                Bprint(&bout, "%s\n%s\n", s.name, file);
87
 
        }
88
 
        Bflush(&bout);
89
 
        exits(0);
90
 
}