| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame^] | 1 | // Copyright The Monogon Project Authors. |
| Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 2 | // SPDX-License-Identifier: Apache-2.0 |
| Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 3 | |
| 4 | package main |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "fmt" |
| 9 | "os/exec" |
| 10 | |
| Serge Bazanski | c3ad846 | 2021-01-08 16:45:51 +0100 | [diff] [blame] | 11 | "source.monogon.dev/metropolis/node" |
| Serge Bazanski | 31370b0 | 2021-01-07 16:31:14 +0100 | [diff] [blame] | 12 | "source.monogon.dev/metropolis/node/core/network" |
| Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 13 | ) |
| 14 | |
| Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 15 | // initializeDebugger attaches Delve to ourselves and exposes it on |
| 16 | // common.DebuggerPort |
| 17 | // This is coupled to compilation_mode=dbg because otherwise Delve doesn't have |
| 18 | // the necessary DWARF debug info |
| Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 19 | func initializeDebugger(networkSvc *network.Service) { |
| 20 | go func() { |
| Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 21 | // This is intentionally delayed until network becomes available since |
| 22 | // Delve for some reason connects to itself and in early-boot no |
| 23 | // network interface is available to do that through. Also external |
| 24 | // access isn't possible early on anyways. |
| Serge Bazanski | b63ed8a | 2024-03-05 14:24:38 +0000 | [diff] [blame] | 25 | watcher := networkSvc.Status.Watch() |
| Serge Bazanski | d8af5bf | 2021-03-16 13:38:29 +0100 | [diff] [blame] | 26 | _, err := watcher.Get(context.Background()) |
| 27 | if err != nil { |
| 28 | panic(err) |
| 29 | } |
| Lorenz Brun | 313816f | 2020-12-22 16:52:26 +0100 | [diff] [blame] | 30 | dlvCmd := exec.Command("/dlv", "--headless=true", fmt.Sprintf("--listen=:%v", node.DebuggerPort), |
| Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 31 | "--accept-multiclient", "--only-same-user=false", "attach", "--continue", "1", "/init") |
| 32 | if err := dlvCmd.Start(); err != nil { |
| 33 | panic(err) |
| 34 | } |
| 35 | }() |
| 36 | } |