This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Environment variables undefined during debug. #947
Closed
Description
Hi
Im on Mac 10.12.4.
VSCode 1.9.0 - Go plugin 0.6.59
GO 1.8.
My program is single file
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
var (
cmdOut []byte
err error
)
fmt.Println( "PATH is " + os.Getenv("PATH"))
cmdName := "git"
cmdArgs := []string{"rev-parse", "--verify", "HEAD"}
if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
fmt.Fprintln(os.Stderr, "There was an error running git rev-parse command: ", err)
os.Exit(1)
}
sha := string(cmdOut)
firstSix := sha[:6]
fmt.Println("The first six chars of the SHA at HEAD in this repo are", firstSix)
}
my launch config is
{
"name": "Launch GO prog",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}",
"env": {
"TEST_ENV": "development"
}
},
The probelm
exec.Command(cmdName, cmdArgs...).Output() fails under debugger since git cannot be found
There was an error running git rev-parse command: exec: "git": executable file not found in $PATH
Ive tried to figure out whats wrong so ive tried to print out os.Getenv("PATH") under debugger its empty.
When i run it from command line go run test.go it works ok.
I think i messed up configuration of VSCode but i dont know what it is.
Thanks.
Activity
[-]Cannot read env variables[/-][+]Environment variables undefined during debug.[/+]ramya-rao-a commentedon Apr 29, 2017
I tried your code, and I am able to debug through it and no errors.
Does
go run test.go
work in the integrated terminal as well?Also, can you try using dlv from the command line and see if this works?
AlexShemeshWix commentedon Apr 30, 2017
Hi
dlv is not working as well.
Any env variable is not defined when im running under debugger.
Ive tried to reainstall golang and vscode.
No luck.
Its really frustrating that such simple thing does not work properly.
May be i can try some other editor? gogland didnt worked for me. It stack with Module "" is undefined when i define run configuration.
Thanks
AlexShemeshWix commentedon Apr 30, 2017
In the end i went for gogland IDE. Its not 100% and it has its own glitches but debugging of tests and project itself works ok.
ramya-rao-a commentedon May 1, 2017
@AlexShemeshWix Sorry that the Go extension for VS Code didn't work out for you.
But before you totally give up on it, would you mind helping us figure out the root cause of your issue?
Do you have your env variables set in
.bashrc
or~/.profile
?See #708 (comment) for the difference.
xoob commentedon May 2, 2017
Okay I've been wrangling with the same issue. It looks like it has something to do with the
lldb
backend on macOS.Note that I'm still on 10.11, not 10.12.
main.go
Tests
Normal go-run:
Default dlv-debug:
Native dlv-debug with
--backend=native
:As you can see, the run with
dlv debug main.go
does not receive any environment variables, while the run withdlv debug --backend=native main.go
works as expected.The backend flag is documented as follows:
Not sure what to do about it, but I hope this is helpful.
xoob commentedon May 2, 2017
Possibly related: microsoft/vscode-cpptools#191
ramya-rao-a commentedon May 2, 2017
@xoob Thanks for the detailed investigation!
@derekparker
--backend
is a recent addition to delve.Is the behavior described by @xoob above expected/known and do you expect editors to pass the backend option?
AlexShemeshWix commentedon May 3, 2017
When using dlv --backend indeed helps.
Using dlv and remote debugging in VSCode works ok.
Still i when i run it from VSCode directly - its the same.
Ive checked bashrc and all other shell configuration stuff, i dont think its the issue.
Thanks
zcmack commentedon May 3, 2017
i'm having a similar issue. using fish shell so if the problem is related to shell config i figure i'd be worse off as it lacks full POSIX compliance.
could not launch process: exec: "lldb-server": executable file not found in $PATH Process exiting with code: 1
i'd prefer not to switch to gogland if possible so let me know what i can do to help. i'm on sierra 10.12.4 and go version 1.8.1, delve installed via
go get github.com/derekparker/delve/cmd/dlv
ramya-rao-a commentedon May 3, 2017
Alright, looks like this is a Mac + latest delve issue.
The reason I couldn't repro must be because I am using the previous version of delve.
I'll update delve and try to get a repro and log an issue for delve
Meanwhile, I'll also add the
backend
option in the launch.config so that Mac users using the latest delve can be unblocked.AlexShemeshWix commentedon May 3, 2017
Awesome 10x
zcmack commentedon May 3, 2017
i reinstalled xcode tools and now it is working for me. might be worth a shot.
xcode-select --install
11 remaining items