diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-02 19:22:40 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-02 19:22:40 +0000 |
commit | e18a8ca20bda043a85e95113e7288b4170023785 (patch) | |
tree | 5903f739377a9d23396281e6491570f3103529de /libgo/go | |
parent | dabe786b59ca225bc2389fbfa5616e5ddd85d2fa (diff) | |
download | gcc-e18a8ca20bda043a85e95113e7288b4170023785.tar.gz |
2012-10-02 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 191993 using svnmerge.py
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@191994 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/debug/elf/elf_test.go | 3 | ||||
-rw-r--r-- | libgo/go/debug/elf/file_test.go | 3 | ||||
-rw-r--r-- | libgo/go/debug/elf/runtime.go | 161 | ||||
-rw-r--r-- | libgo/go/net/http/pprof/pprof.go | 1 | ||||
-rw-r--r-- | libgo/go/net/ip_test.go | 1 | ||||
-rw-r--r-- | libgo/go/runtime/debug/stack.go | 1 | ||||
-rw-r--r-- | libgo/go/runtime/pprof/pprof.go | 1 | ||||
-rw-r--r-- | libgo/go/testing/testing.go | 1 |
8 files changed, 2 insertions, 170 deletions
diff --git a/libgo/go/debug/elf/elf_test.go b/libgo/go/debug/elf/elf_test.go index b8cdbcc7e51..67b961b5c6c 100644 --- a/libgo/go/debug/elf/elf_test.go +++ b/libgo/go/debug/elf/elf_test.go @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package elf_test +package elf import ( - . "debug/elf" "fmt" "testing" ) diff --git a/libgo/go/debug/elf/file_test.go b/libgo/go/debug/elf/file_test.go index 105b697a4fb..98f2723c86e 100644 --- a/libgo/go/debug/elf/file_test.go +++ b/libgo/go/debug/elf/file_test.go @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package elf_test +package elf import ( "debug/dwarf" - . "debug/elf" "encoding/binary" "net" "os" diff --git a/libgo/go/debug/elf/runtime.go b/libgo/go/debug/elf/runtime.go deleted file mode 100644 index 17cb6fbc99e..00000000000 --- a/libgo/go/debug/elf/runtime.go +++ /dev/null @@ -1,161 +0,0 @@ -// 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. - -// This is gccgo-specific code that uses DWARF information to fetch -// file/line information for PC values. This package registers itself -// with the runtime package. - -package elf - -import ( - "debug/dwarf" - "debug/macho" - "os" - "runtime" - "sort" - "sync" -) - -func init() { - // Register our lookup functions with the runtime package. - runtime.RegisterDebugLookup(funcFileLine, symbolValue) -} - -// The file struct holds information for a specific file that is part -// of the execution. -type file struct { - elf *File // If ELF - macho *macho.File // If Mach-O - dwarf *dwarf.Data // DWARF information - - symsByName []sym // Sorted by name - symsByAddr []sym // Sorted by address -} - -// Sort symbols by name. -type symsByName []sym - -func (s symsByName) Len() int { return len(s) } -func (s symsByName) Less(i, j int) bool { return s[i].name < s[j].name } -func (s symsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// Sort symbols by address. -type symsByAddr []sym - -func (s symsByAddr) Len() int { return len(s) } -func (s symsByAddr) Less(i, j int) bool { return s[i].addr < s[j].addr } -func (s symsByAddr) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// The sym structure holds the information we care about for a symbol, -// namely name and address. -type sym struct { - name string - addr uintptr -} - -// Open an input file. -func open(name string) (*file, error) { - efile, err := Open(name) - var mfile *macho.File - if err != nil { - var merr error - mfile, merr = macho.Open(name) - if merr != nil { - return nil, err - } - } - - r := &file{elf: efile, macho: mfile} - - if efile != nil { - r.dwarf, err = efile.DWARF() - } else { - r.dwarf, err = mfile.DWARF() - } - if err != nil { - return nil, err - } - - var syms []sym - if efile != nil { - esyms, err := efile.Symbols() - if err != nil { - return nil, err - } - syms = make([]sym, 0, len(esyms)) - for _, s := range esyms { - if ST_TYPE(s.Info) == STT_FUNC { - syms = append(syms, sym{s.Name, uintptr(s.Value)}) - } - } - } else { - syms = make([]sym, 0, len(mfile.Symtab.Syms)) - for _, s := range mfile.Symtab.Syms { - syms = append(syms, sym{s.Name, uintptr(s.Value)}) - } - } - - r.symsByName = make([]sym, len(syms)) - copy(r.symsByName, syms) - sort.Sort(symsByName(r.symsByName)) - - r.symsByAddr = syms - sort.Sort(symsByAddr(r.symsByAddr)) - - return r, nil -} - -// The main executable -var executable *file - -// Only open the executable once. -var executableOnce sync.Once - -func openExecutable() { - executableOnce.Do(func() { - f, err := open("/proc/self/exe") - if err != nil { - f, err = open(os.Args[0]) - if err != nil { - return - } - } - executable = f - }) -} - -// The funcFileLine function looks up the function name, file name, -// and line number for a PC value. -func funcFileLine(pc uintptr, function *string, file *string, line *int) bool { - openExecutable() - if executable == nil || executable.dwarf == nil { - return false - } - f, ln, err := executable.dwarf.FileLine(uint64(pc)) - if err != nil { - return false - } - *file = f - *line = ln - - *function = "" - if len(executable.symsByAddr) > 0 && pc >= executable.symsByAddr[0].addr { - i := sort.Search(len(executable.symsByAddr), - func(i int) bool { return executable.symsByAddr[i].addr > pc }) - *function = executable.symsByAddr[i-1].name - } - - return true -} - -// The symbolValue function fetches the value of a symbol. -func symbolValue(name string, val *uintptr) bool { - i := sort.Search(len(executable.symsByName), - func(i int) bool { return executable.symsByName[i].name >= name }) - if i >= len(executable.symsByName) || executable.symsByName[i].name != name { - return false - } - *val = executable.symsByName[i].addr - return true -} diff --git a/libgo/go/net/http/pprof/pprof.go b/libgo/go/net/http/pprof/pprof.go index b8874f35d2f..06fcde1447f 100644 --- a/libgo/go/net/http/pprof/pprof.go +++ b/libgo/go/net/http/pprof/pprof.go @@ -35,7 +35,6 @@ package pprof import ( "bufio" "bytes" - _ "debug/elf" "fmt" "html/template" "io" diff --git a/libgo/go/net/ip_test.go b/libgo/go/net/ip_test.go index d0e987b85f7..df647ef73c0 100644 --- a/libgo/go/net/ip_test.go +++ b/libgo/go/net/ip_test.go @@ -6,7 +6,6 @@ package net import ( "bytes" - _ "debug/elf" "reflect" "runtime" "testing" diff --git a/libgo/go/runtime/debug/stack.go b/libgo/go/runtime/debug/stack.go index fc74e537b75..a533a5c3bf4 100644 --- a/libgo/go/runtime/debug/stack.go +++ b/libgo/go/runtime/debug/stack.go @@ -8,7 +8,6 @@ package debug import ( "bytes" - _ "debug/elf" "fmt" "io/ioutil" "os" diff --git a/libgo/go/runtime/pprof/pprof.go b/libgo/go/runtime/pprof/pprof.go index 87f17d2db12..f67e8a8f9ae 100644 --- a/libgo/go/runtime/pprof/pprof.go +++ b/libgo/go/runtime/pprof/pprof.go @@ -11,7 +11,6 @@ package pprof import ( "bufio" "bytes" - _ "debug/elf" "fmt" "io" "runtime" diff --git a/libgo/go/testing/testing.go b/libgo/go/testing/testing.go index 1cb8a078c6d..f59ce8ed6f7 100644 --- a/libgo/go/testing/testing.go +++ b/libgo/go/testing/testing.go @@ -79,7 +79,6 @@ package testing import ( - _ "debug/elf" "flag" "fmt" "os" |