Home >Backend Development >Golang >Can Go Detect GoLand Debugger Attachment Like C#\'s `Debugger.IsAttached`?
In C#, a running program can identify whether it's under debugger supervision through the "System.Diagnostics.Debugger.IsAttached" method.
Can Go achieve a similar functionality? This is particularly desirable for disabling timeouts while code is being debugged.
Specifically, this question arises in the context of using the GoLand debugger.
Using Build Tags:
In "isdelve/delve.go," add the following build tag:
// +build delve
In "isdelve/nodelve.go," add the following build tag:
// +build !delve
Add a "package isdelve" declaration to both files and declare the "Enabled" constant:
package isdelve const Enabled = true // or package isdelve const Enabled = false
Create a third Go file, "a.go," which imports the "isdelve" package:
package main import ( "isdelve" "fmt" ) func main() { fmt.Println("delve", isdelve.Enabled) }
Configuring GoLand:
Usage:
Alternative:
Alternatively, delve's "set" command can manually set a variable after starting the debugger.
The above is the detailed content of Can Go Detect GoLand Debugger Attachment Like C#'s `Debugger.IsAttached`?. For more information, please follow other related articles on the PHP Chinese website!