Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "fmt" |
| 22 | "os/exec" |
| 23 | |
Serge Bazanski | c3ad846 | 2021-01-08 16:45:51 +0100 | [diff] [blame] | 24 | "source.monogon.dev/metropolis/node" |
Serge Bazanski | 31370b0 | 2021-01-07 16:31:14 +0100 | [diff] [blame] | 25 | "source.monogon.dev/metropolis/node/core/network" |
Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // initializeDebugger attaches Delve to ourselves and exposes it on common.DebuggerPort |
| 29 | // This is coupled to compilation_mode=dbg because otherwise Delve doesn't have the necessary DWARF debug info |
| 30 | func initializeDebugger(networkSvc *network.Service) { |
| 31 | go func() { |
| 32 | // This is intentionally delayed until network becomes available since Delve for some reason connects to itself |
| 33 | // and in early-boot no network interface is available to do that through. Also external access isn't possible |
| 34 | // early on anyways. |
| 35 | networkSvc.GetIP(context.Background(), true) |
Lorenz Brun | 313816f | 2020-12-22 16:52:26 +0100 | [diff] [blame] | 36 | dlvCmd := exec.Command("/dlv", "--headless=true", fmt.Sprintf("--listen=:%v", node.DebuggerPort), |
Lorenz Brun | 70f65b2 | 2020-07-08 17:02:47 +0200 | [diff] [blame] | 37 | "--accept-multiclient", "--only-same-user=false", "attach", "--continue", "1", "/init") |
| 38 | if err := dlvCmd.Start(); err != nil { |
| 39 | panic(err) |
| 40 | } |
| 41 | }() |
| 42 | } |