Call Delve using exec() instead of "dlv attach".
"dlv attach":
- Spams the terminal
- Requires sysctl -w kernel.yama.ptrace_scope=0
- Apparently, does not allow the debugger to inspect variables
Test: Manual.
Change-Id: I625369effaf5abda2b5d884c8ce5bde7247774eb
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index bd1a9ed..905f206 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -18,12 +18,7 @@
"flag"
"fmt"
"os"
- "os/exec"
"path/filepath"
- "strconv"
- "strings"
- "syscall"
- "time"
"github.com/google/blueprint/bootstrap"
@@ -55,42 +50,7 @@
}
func main() {
- if android.SoongDelveListen != "" {
- if android.SoongDelvePath == "" {
- fmt.Fprintln(os.Stderr, "SOONG_DELVE is set but failed to find dlv")
- os.Exit(1)
- }
- pid := strconv.Itoa(os.Getpid())
- cmd := []string{android.SoongDelvePath,
- "attach", pid,
- "--headless",
- "-l", android.SoongDelveListen,
- "--api-version=2",
- "--accept-multiclient",
- "--log",
- }
-
- fmt.Println("Starting", strings.Join(cmd, " "))
- dlv := exec.Command(cmd[0], cmd[1:]...)
- dlv.Stdout = os.Stdout
- dlv.Stderr = os.Stderr
- dlv.Stdin = nil
-
- // Put dlv into its own process group so we can kill it and the child process it starts.
- dlv.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
-
- err := dlv.Start()
- if err != nil {
- // Print the error starting dlv and continue.
- fmt.Println(err)
- } else {
- // Kill the process group for dlv when soong_build exits.
- defer syscall.Kill(-dlv.Process.Pid, syscall.SIGKILL)
- // Wait to give dlv a chance to connect and pause the process.
- time.Sleep(time.Second)
- }
- }
-
+ android.ReexecWithDelveMaybe()
flag.Parse()
// The top-level Blueprints file is passed as the first argument.