Open dataf3l opened 1 year ago
I also would like to use that on OSX and tried some stuff but didn't make it work (yet).
I got the same error in Windows 11
go build -ldflags="-s -w"
.\main.go:61:3: unknown field Pdeathsig in struct literal of type syscall.SysProcAttr
@zanezhub maybe change main.go and who knows what else, I asked ChatGPT, it did this:
The given code appears to be written for Linux, and it makes use of specific commands and file paths that might not be valid or exist on Windows and macOS.
Here's how to make this code platform-agnostic:
Platform-specific logic:
runtime
package's GOOS
constant.File Paths:
/home/username/...
. This is not valid on Windows (which uses C:\Users\username\...
) or macOS. os
and filepath
packages to work with paths to make it OS-agnostic.System Calls:
syscall.SysProcAttr
and Pdeathsig
are Linux-specific. These aren't applicable to macOS and Windows. Commands:
dlv
) should be available on all platforms. This will only work if the dlv
command is available on the PATH of each OS. Here's a simplified version of your code to make it work on all platforms:
// ... [other imports]
import (
"runtime"
)
// ...
func startDebugger(commandArgs []string) int {
log.Printf("Starting dlv-backend: dlv %s", strings.Join(commandArgs, " "))
cmd := exec.Command(
"dlv",
commandArgs...,
)
// Platform-specific logic for Linux
if runtime.GOOS == "linux" {
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
}
// ... [rest of the function]
}
// ...
func init() {
// ...
// Platform-specific default log path logic
defaultLogFile := "$XDG_DATA_HOME/dlvtui.log"
if runtime.GOOS == "windows" {
defaultLogFile = "$APPDATA/dlvtui.log"
} else if runtime.GOOS == "darwin" { // macOS
defaultLogFile = "$HOME/Library/Application Support/dlvtui.log"
}
exFlags.StringVar(&logfile, "logfile", defaultLogFile, "Path to the log file.")
// ... [rest of the function]
}
// ...
func main() {
// ...
// Platform-specific logic to resolve dir
var defaultPrefix string
switch runtime.GOOS {
case "linux":
defaultPrefix = "/home/"
case "windows":
defaultPrefix = "C:/Users/"
case "darwin":
defaultPrefix = "/Users/"
default:
defaultPrefix = ""
}
// Replace /home/ with the relevant prefix for the OS
for _, f := range fileList {
if strings.HasPrefix(f, defaultPrefix) && !strings.Contains(f, "/go/pkg") {
dir = filepath.Dir(f)
break
}
}
// ... [rest of the function]
}
Changes made:
runtime
package to detect the platform.startDebugger
function to only set Pdeathsig
for Linux.init
function to set the default log path based on the OS.main
function to have OS-specific logic for determining the directory prefix.Keep in mind:
dlv
command is available on the PATH of each OS.I hope this ChatGPT thing is useful, have a nice day
Tried to build, it shows an error:
./main.go:61:3: unknown field 'Pdeathsig' in struct literal of type syscall.SysProcAttr
what to do?