blob: b3b859cf25375970e49dcb160ffef16c14a65268 [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 Bazanski77cb6c52020-12-19 00:09:22 +010024 "git.monogon.dev/source/nexantic.git/metropolis/node/core/network"
Lorenz Brun70f65b22020-07-08 17:02:47 +020025)
26
27// initializeDebugger attaches Delve to ourselves and exposes it on common.DebuggerPort
28// This is coupled to compilation_mode=dbg because otherwise Delve doesn't have the necessary DWARF debug info
29func initializeDebugger(networkSvc *network.Service) {
30 go func() {
31 // This is intentionally delayed until network becomes available since Delve for some reason connects to itself
32 // and in early-boot no network interface is available to do that through. Also external access isn't possible
33 // early on anyways.
34 networkSvc.GetIP(context.Background(), true)
35 dlvCmd := exec.Command("/dlv", "--headless=true", fmt.Sprintf("--listen=:%v", common.DebuggerPort),
36 "--accept-multiclient", "--only-same-user=false", "attach", "--continue", "1", "/init")
37 if err := dlvCmd.Start(); err != nil {
38 panic(err)
39 }
40 }()
41}