blob: 1c2af0083f3101d5be495c080f9c1eb5fdce0071 [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
24 "git.monogon.dev/source/nexantic.git/core/internal/common"
25 "git.monogon.dev/source/nexantic.git/core/internal/network"
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
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.
35 networkSvc.GetIP(context.Background(), true)
36 dlvCmd := exec.Command("/dlv", "--headless=true", fmt.Sprintf("--listen=:%v", common.DebuggerPort),
37 "--accept-multiclient", "--only-same-user=false", "attach", "--continue", "1", "/init")
38 if err := dlvCmd.Start(); err != nil {
39 panic(err)
40 }
41 }()
42}