mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 12:59:01 +08:00
Fix: Pass args to OSX fork_exec / trim args
This commit is contained in:
@ -80,7 +80,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer os.Remove(debugname)
|
defer os.Remove(debugname)
|
||||||
|
|
||||||
processArgs = append([]string{"./" + debugname}, flag.Args()...)
|
processArgs = append([]string{"./" + debugname}, flag.Args()[1:]...)
|
||||||
case "test":
|
case "test":
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -97,7 +97,7 @@ func main() {
|
|||||||
debugname := "./" + base + ".test"
|
debugname := "./" + base + ".test"
|
||||||
defer os.Remove(debugname)
|
defer os.Remove(debugname)
|
||||||
|
|
||||||
processArgs = append([]string{debugname}, flag.Args()...)
|
processArgs = append([]string{debugname}, flag.Args()[1:]...)
|
||||||
case "attach":
|
case "attach":
|
||||||
pid, err := strconv.Atoi(flag.Args()[1])
|
pid, err := strconv.Atoi(flag.Args()[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package proctl
|
|||||||
|
|
||||||
// #include "proctl_darwin.h"
|
// #include "proctl_darwin.h"
|
||||||
// #include "exec_darwin.h"
|
// #include "exec_darwin.h"
|
||||||
|
// #include <stdlib.h>
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"debug/gosym"
|
"debug/gosym"
|
||||||
@ -29,14 +30,20 @@ type OSProcessDetails struct {
|
|||||||
// custom fork/exec process in order to take advantage of
|
// custom fork/exec process in order to take advantage of
|
||||||
// PT_SIGEXC on Darwin.
|
// PT_SIGEXC on Darwin.
|
||||||
func Launch(cmd []string) (*DebuggedProcess, error) {
|
func Launch(cmd []string) (*DebuggedProcess, error) {
|
||||||
argv0, err := filepath.Abs(cmd[0])
|
argv0Go, err := filepath.Abs(cmd[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
argv0 := C.CString(argv0Go)
|
||||||
|
|
||||||
argv := C.CString(cmd[0])
|
argvSlice := make([]*C.char, 0, len(cmd))
|
||||||
if len(cmd) == 1 {
|
for _, arg := range cmd {
|
||||||
argv = nil
|
argvSlice = append(argvSlice, C.CString(arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
var argv **C.char
|
||||||
|
if len(cmd) > 1 {
|
||||||
|
argv = &argvSlice[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
dbp := &DebuggedProcess{
|
dbp := &DebuggedProcess{
|
||||||
@ -47,13 +54,17 @@ func Launch(cmd []string) (*DebuggedProcess, error) {
|
|||||||
ast: source.New(),
|
ast: source.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
pid := int(C.fork_exec(C.CString(argv0), &argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort))
|
ret := C.fork_exec(argv0, argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort)
|
||||||
|
pid := int(ret)
|
||||||
if pid <= 0 {
|
if pid <= 0 {
|
||||||
return nil, fmt.Errorf("could not fork/exec")
|
return nil, fmt.Errorf("could not fork/exec")
|
||||||
}
|
}
|
||||||
dbp.Pid = pid
|
dbp.Pid = pid
|
||||||
|
for i := range argvSlice {
|
||||||
|
C.free(unsafe.Pointer(argvSlice[i]))
|
||||||
|
}
|
||||||
|
|
||||||
dbp, err = initializeDebugProcess(dbp, argv0, false)
|
dbp, err = initializeDebugProcess(dbp, argv0Go, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user