Pass LD_/DYLD_ env vars to debugserver (fixes #877) (#910)

This commit is contained in:
Florin Pățan 2017-07-18 19:57:41 +01:00 committed by Derek Parker
parent 5cd2ac1d49
commit 135330cbb2
3 changed files with 50 additions and 1 deletions

13
_fixtures/issue877.go Normal file

@ -0,0 +1,13 @@
package main
import (
"fmt"
"os"
"runtime"
)
func main() {
dyldenv := os.Getenv("DYLD_LIBRARY_PATH")
runtime.Breakpoint()
fmt.Println(dyldenv)
}

@ -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.
@ -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...)

@ -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)
}
})
}