mirror of
https://github.com/golang/go
synced 2024-09-30 17:28:32 -06:00
cmd/go: add distribution-specific info for Linux to bug command
Also remove the hard-coded path for getting glibc information. As an example, the following is the diff for `go bug` on Ubuntu before and after the change: >>> --- /tmp/01 2016-09-13 15:08:53.202758043 +0530 +++ /tmp/02 2016-09-13 21:38:17.485039867 +0530 @@ -1,7 +1,7 @@ Please check whether the issue also reproduces on the latest release, go1.7.1. ``` -go version devel +bdb3b79 Wed Sep 7 03:23:44 2016 +0000 linux/amd64 +go version devel +cb13150 Wed Sep 7 09:46:58 2016 +0530 linux/amd64 GOARCH="amd64" GOBIN="" GOEXE="" @@ -18,5 +18,23 @@ CXX="g++" CGO_ENABLED="1" uname -sr: Linux 4.4.0-36-generic +Distributor ID: Ubuntu +Description: Ubuntu 16.04.1 LTS +Release: 16.04 +Codename: xenial +/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.23-0ubuntu3) stable release version 2.23, by Roland McGrath et al. gdb --version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 ``` <<< Change-Id: I7e3730a797af0f94d6e43fe4743ab48bc0f11f1b Reviewed-on: https://go-review.googlesource.com/28581 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
3eb16c059d
commit
4466298df4
@ -9,7 +9,10 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
@ -74,7 +77,8 @@ func printOSDetails(w io.Writer) {
|
||||
printCmdOut(w, "", "sw_vers")
|
||||
case "linux":
|
||||
printCmdOut(w, "uname -sr: ", "uname", "-sr")
|
||||
printCmdOut(w, "libc:", "/lib/libc.so.6")
|
||||
printCmdOut(w, "", "lsb_release", "-a")
|
||||
printGlibcVersion(w)
|
||||
case "openbsd", "netbsd", "freebsd", "dragonfly":
|
||||
printCmdOut(w, "uname -v: ", "uname", "-v")
|
||||
case "solaris":
|
||||
@ -97,10 +101,7 @@ func printCDetails(w io.Writer) {
|
||||
// There's apparently no combination of command line flags
|
||||
// to get gdb to spit out its version without the license and warranty.
|
||||
// Print up to the first newline.
|
||||
idx := bytes.Index(out, []byte{'\n'})
|
||||
line := out[:idx]
|
||||
line = bytes.TrimSpace(line)
|
||||
fmt.Fprintf(w, "gdb --version: %s\n", line)
|
||||
fmt.Fprintf(w, "gdb --version: %s\n", firstLine(out))
|
||||
} else {
|
||||
if buildV {
|
||||
fmt.Printf("failed to run gdb --version: %v\n", err)
|
||||
@ -145,3 +146,56 @@ func printCmdOut(w io.Writer, prefix, path string, args ...string) {
|
||||
}
|
||||
fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
|
||||
}
|
||||
|
||||
// firstLine returns the first line of a given byte slice.
|
||||
func firstLine(buf []byte) []byte {
|
||||
idx := bytes.IndexByte(buf, '\n')
|
||||
if idx > 0 {
|
||||
buf = buf[:idx]
|
||||
}
|
||||
return bytes.TrimSpace(buf)
|
||||
}
|
||||
|
||||
// printGlibcVersion prints information about the glibc version.
|
||||
// It ignores failures.
|
||||
func printGlibcVersion(w io.Writer) {
|
||||
tempdir := os.TempDir()
|
||||
if tempdir == "" {
|
||||
return
|
||||
}
|
||||
src := []byte(`int main() {}`)
|
||||
srcfile := filepath.Join(tempdir, "go-bug.c")
|
||||
outfile := filepath.Join(tempdir, "go-bug")
|
||||
err := ioutil.WriteFile(srcfile, src, 0644)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(srcfile)
|
||||
cmd := exec.Command("gcc", "-o", outfile, srcfile)
|
||||
if _, err = cmd.CombinedOutput(); err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(outfile)
|
||||
|
||||
cmd = exec.Command("ldd", outfile)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
re := regexp.MustCompile(`libc\.so[^ ]* => ([^ ]+)`)
|
||||
m := re.FindStringSubmatch(string(out))
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
cmd = exec.Command(m[1])
|
||||
out, err = cmd.Output()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "%s: %s\n", m[1], firstLine(out))
|
||||
|
||||
// print another line (the one containing version string) in case of musl libc
|
||||
if idx := bytes.IndexByte(out, '\n'); bytes.Index(out, []byte("musl")) != -1 && idx > -1 {
|
||||
fmt.Fprintf(w, "%s\n", firstLine(out[idx+1:]))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user