Skip to content

Instantly share code, notes, and snippets.

@tupunco
Last active April 30, 2016 14:42
Show Gist options
  • Save tupunco/7c5d9abcf7b6a65c003e081d1a406b4c to your computer and use it in GitHub Desktop.
Save tupunco/7c5d9abcf7b6a65c003e081d1a406b4c to your computer and use it in GitHub Desktop.
derekparker_delve bug issues_505

windows 'dlv debug' include 'exec.LookPath(os.Args[0])' error #505

issues#505

  1. What version of Delve are you using (dlv version)?

master

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

1.6/windows

  1. What operating system and processor architecture are you using?

windows 10

  1. What did you do?

dlv debug

  1. What did you expect to see?

current exe path

  1. What did you see instead?

error

Detailed instructions

Demo code

package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
)

// execPath returns the executable path.
func execPath() (string, error) {
	filePath := os.Args[0]
	file, err := exec.LookPath(filePath)
	if err != nil {
		return "", err
	}
	return filepath.Abs(file)
}

func main() {
	path, err := execPath()
	fmt.Printf("%s-%s", path, err)
}

Problem code

exec.LookPath(os.Args[0])

Problem analysis On Windows exec.LookPath(path) function implementation to determine whether the path for exe/com /.. File extension. Call the dlv debug command will generate a debug file , it no file extension.

Solve the problem Modify the generated logic of the debug file, add the exe extension. A simple solution, modify commands.go#L50 to :

var (
	debugname     = "debug"
	testdebugname = "debug.test"
)

func init() {
	switch os := runtime.GOOS; os {
	case "windows":
		debugname = "debug.exe"
		testdebugname = "debug.test.exe"
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment