mirror of
https://github.com/go-delve/delve.git
synced 2026-05-05 20:26:14 +02:00
* pkg/debugdetect: add package for detecting debugger attachment Implement new pkg/debugdetect package that detects if a program is running under a debugger on Linux, macOS, Windows, and FreeBSD. Platform-specific detection methods: - Linux: Parse /proc/self/status for TracerPid field - macOS: Use sysctl with KERN_PROC_PID to check P_TRACED flag - Windows: Call IsDebuggerPresent() Win32 API - FreeBSD: Try sysctl first, fall back to /proc/curproc/status Fixes #4243 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
18 lines
408 B
Go
18 lines
408 B
Go
package debugdetect
|
|
|
|
import (
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
var (
|
|
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
|
procIsDebuggerPresent = kernel32.NewProc("IsDebuggerPresent")
|
|
)
|
|
|
|
func detectDebuggerAttached() (bool, error) {
|
|
// Use IsDebuggerPresent from kernel32.dll
|
|
// This checks the BeingDebugged flag in the PEB
|
|
flag, _, _ := procIsDebuggerPresent.Call()
|
|
return flag != 0, nil
|
|
}
|