Skip to content

Commit

Permalink
Pass LD_/DYLD_ env vars to debugserver (fixes go-delve#877) (go-delve…
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsniper authored and derekparker committed Jul 18, 2017
1 parent 5cd2ac1 commit 135330c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
13 changes: 13 additions & 0 deletions _fixtures/issue877.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"os"
"runtime"
)

func main() {
dyldenv := os.Getenv("DYLD_LIBRARY_PATH")
runtime.Breakpoint()
fmt.Println(dyldenv)
}
18 changes: 17 additions & 1 deletion pkg/proc/gdbserial/gdbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ const debugserverExecutable = "/Library/Developer/CommandLineTools/Library/Priva

var ErrUnsupportedOS = errors.New("lldb backend not supported on windows")

func getLdEnvVars() []string {
var result []string

environ := os.Environ()
for i := 0; i < len(environ); i++ {
if strings.HasPrefix(environ[i], "LD_") ||
strings.HasPrefix(environ[i], "DYLD_") {
result = append(result, "-e", environ[i])
}
}

return result
}

// LLDBLaunch starts an instance of lldb-server and connects to it, asking
// it to launch the specified target program with the specified arguments
// (cmd) on the specified directory wd.
Expand All @@ -358,7 +372,9 @@ func LLDBLaunch(cmd []string, wd string) (*Process, error) {
if err != nil {
return nil, err
}
args := make([]string, 0, len(cmd)+4)
ldEnvVars := getLdEnvVars()
args := make([]string, 0, len(cmd)+4+len(ldEnvVars))
args = append(args, ldEnvVars...)
args = append(args, "-F", "-R", fmt.Sprintf("127.0.0.1:%d", listener.Addr().(*net.TCPAddr).Port), "--")
args = append(args, cmd...)

Expand Down
20 changes: 20 additions & 0 deletions pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2934,3 +2934,23 @@ func TestRecursiveNext(t *testing.T) {
}
})
}

// TestIssue877 ensures that the environment variables starting with DYLD_ and LD_
// are passed when executing the binary on OSX via debugserver
func TestIssue877(t *testing.T) {
if runtime.GOOS != "darwin" && testBackend == "lldb" {
return
}
const envval = "/usr/local/lib"
os.Setenv("DYLD_LIBRARY_PATH", envval)
withTestProcess("issue877", t, func(p proc.Process, fixture protest.Fixture) {
assertNoError(proc.Continue(p), t, "Continue()")
v, err := evalVariable(p, "dyldenv")
assertNoError(err, t, "EvalVariable()")
vv := constant.StringVal(v.Value)
t.Logf("v = %q", vv)
if vv != envval {
t.Fatalf("value of v is %q (expected %q)", vv, envval)
}
})
}

0 comments on commit 135330c

Please sign in to comment.