Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/debug/cmd/viewcore: Error reading core file produced by gcore "bad magic number" #28140

Closed
Matt-Esch opened this issue Oct 11, 2018 · 5 comments

Comments

@Matt-Esch
Copy link

What version of Go are you using (go version)?

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/matt/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/matt/gocode"
GOPROXY=""
GORACE=""
GOROOT="/Users/matt/repos/go"
GOTMPDIR=""
GOTOOLDIR="/Users/matt/repos/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l_/ldzhcfsd1g3fg8bdzfgrc_840000gn/T/go-build487155815=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  • Compile an example program. This program is used to assess the current heap exploration tools for go. I'm considering using the go heapdump format as a more consistent method for debugging the heap as I have not yet been able to debug a single core file with the viewcore tool yet.

example.go

package main

import (
	"os"
	"os/signal"
	"runtime/debug"
	"syscall"
	"time"
)

type leakyFoo struct {
	index int
}

// Leaky program writes heapdump to stdout on SIGUSR2
func main() {
	setupHeapdumpHandler()

	// Leak some structs forever
	leak := []*leakyFoo{}

	for i := 0; ; i++ {
		leak = append(leak, &leakyFoo{
			index: i,
		})
		time.Sleep(100000000)
	}
}

func setupHeapdumpHandler() {
	go func() {
		usr2sig := make(chan os.Signal, 1)
		signal.Notify(usr2sig, syscall.SIGUSR2)
		for {
			<-usr2sig
			debug.WriteHeapDump(os.Stdout.Fd())
		}
	}()
}
  • Compile/run the program: go build -o ./example && ./example

  • Take a core dump with sudo gcore $pid -o ./core

  • Open the core file with viewcore ./core

What did you expect to see?

I expected to be able to debug the core file

What did you see instead?

An error reading the core file: bad magic number '[207 250 237 254]' in record at byte 0x0

@gopherbot gopherbot added this to the Unreleased milestone Oct 11, 2018
@Matt-Esch Matt-Esch changed the title x/debug/cmd/viewcore: Error reading core file produced by gcore "bad magic number" x/debug/cmd/viewcore: Error reading core file produced by gcore "bad magic number" Oct 11, 2018
@Matt-Esch
Copy link
Author

cc: @randall77 @hyangah

@randall77
Copy link
Contributor

viewcore does not work on Darwin. That error means it's trying to read an elf format core dump and isn't finding one. The cores on Darwin are in macho format.
An upgrade of viewcore to handle macho would be welcome.

@Matt-Esch
Copy link
Author

Which versions of go is this likely to work for? I tried a while back with 1.10.3 on linux with the same example and I was finding errors there too (not the same error, missing entries in the core file). I'll try again with 1.11.1 but I do wonder how version management and support will work for this tool if there are issues between go versions. Ideally the version would be extracted from the core file somehow and this won't break.

@Matt-Esch
Copy link
Author

building with go 1.11.1 fails with "missing executable" (the executable does exist in the path it was looking), which is probably the same as #28091

@randall77
Copy link
Contributor

The intent is that viewcore should work with any core generated by Go 1.9 or later.

I'll close this issue. Feel free to open another if #28091 turns out not to be the problem you were having.

@golang golang locked and limited conversation to collaborators Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants