blob: 24ea47011a916e22133643d7ed3a1b5c7640f431 [file] [log] [blame]
Lorenz Brun70f65b22020-07-08 17:02:47 +02001// 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
17package main
18
19import (
20 "context"
21 "fmt"
22 "os/exec"
23
Serge Bazanskic3ad8462021-01-08 16:45:51 +010024 "source.monogon.dev/metropolis/node"
Serge Bazanski31370b02021-01-07 16:31:14 +010025 "source.monogon.dev/metropolis/node/core/network"
Lorenz Brun70f65b22020-07-08 17:02:47 +020026)
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
30func 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.
Serge Bazanskid8af5bf2021-03-16 13:38:29 +010035 watcher := networkSvc.Watch()
36 _, err := watcher.Get(context.Background())
37 if err != nil {
38 panic(err)
39 }
Lorenz Brun313816f2020-12-22 16:52:26 +010040 dlvCmd := exec.Command("/dlv", "--headless=true", fmt.Sprintf("--listen=:%v", node.DebuggerPort),
Lorenz Brun70f65b22020-07-08 17:02:47 +020041 "--accept-multiclient", "--only-same-user=false", "attach", "--continue", "1", "/init")
42 if err := dlvCmd.Start(); err != nil {
43 panic(err)
44 }
45 }()
46}