summaryrefslogtreecommitdiffstats
path: root/libgo/go/debug/elf
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-28 14:48:30 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-28 14:48:30 +0000
commite4fbfaf5e89dd4fdb395042faf041d5fd65b34a6 (patch)
tree925434497da8b45f5bb1b591f8748e05c857d9a0 /libgo/go/debug/elf
parent71893c98c1745cd6fde434088f876087572961aa (diff)
downloadppe42-gcc-e4fbfaf5e89dd4fdb395042faf041d5fd65b34a6.tar.gz
ppe42-gcc-e4fbfaf5e89dd4fdb395042faf041d5fd65b34a6.zip
libgo: Use libbacktrace rather than debug/elf registration.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191831 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/debug/elf')
-rw-r--r--libgo/go/debug/elf/elf_test.go3
-rw-r--r--libgo/go/debug/elf/file_test.go3
-rw-r--r--libgo/go/debug/elf/runtime.go161
3 files changed, 2 insertions, 165 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
-}
OpenPOWER on IntegriCloud