github.com/undoio/delve@v1.9.0/service/debugger/debugger_windows.go (about) 1 package debugger 2 3 import ( 4 "debug/pe" 5 "fmt" 6 "os" 7 "os/exec" 8 "path/filepath" 9 10 "github.com/undoio/delve/service/api" 11 ) 12 13 func attachErrorMessage(pid int, err error) error { 14 return fmt.Errorf("could not attach to pid %d: %s", pid, err) 15 } 16 17 func stopProcess(pid int) error { 18 // We cannot gracefully stop a process on Windows, 19 // so just ignore this request and let `Detach` kill 20 // the process. 21 return nil 22 } 23 24 func verifyBinaryFormat(exePath string) error { 25 f, err := os.Open(exePath) 26 if err != nil { 27 return err 28 } 29 defer f.Close() 30 31 // Make sure the binary exists and is an executable file 32 if filepath.Base(exePath) == exePath { 33 if _, err := exec.LookPath(exePath); err != nil { 34 return err 35 } 36 } 37 38 exe, err := pe.NewFile(f) 39 if err != nil { 40 return api.ErrNotExecutable 41 } 42 exe.Close() 43 return nil 44 }