delve/service/debugger/debugger_windows.go
Alessandro Arzilli 7ab33ac92f
service/debugger: close executable file (#2976)
Close executable file after we open it.
2022-04-26 14:32:22 -07:00

45 lines
818 B
Go

package debugger
import (
"debug/pe"
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/go-delve/delve/service/api"
)
func attachErrorMessage(pid int, err error) error {
return fmt.Errorf("could not attach to pid %d: %s", pid, err)
}
func stopProcess(pid int) error {
// We cannot gracefully stop a process on Windows,
// so just ignore this request and let `Detach` kill
// the process.
return nil
}
func verifyBinaryFormat(exePath string) error {
f, err := os.Open(exePath)
if err != nil {
return err
}
defer f.Close()
// Make sure the binary exists and is an executable file
if filepath.Base(exePath) == exePath {
if _, err := exec.LookPath(exePath); err != nil {
return err
}
}
exe, err := pe.NewFile(f)
if err != nil {
return api.ErrNotExecutable
}
exe.Close()
return nil
}