cmd/dlv: Add ability to connect to headless server
Fixes #201. Use to connect to a running headless server
This commit is contained in:
parent
5d489bef99
commit
96dd44bd6e
@ -58,7 +58,7 @@ The goal of this tool is to provide a simple yet powerful interface for debuggin
|
|||||||
runCommand := &cobra.Command{
|
runCommand := &cobra.Command{
|
||||||
Use: "run",
|
Use: "run",
|
||||||
Short: "Compile and begin debugging program.",
|
Short: "Compile and begin debugging program.",
|
||||||
Long: `Compiles your program with optimizations disabled,
|
Long: `Compiles your program with optimizations disabled,
|
||||||
starts and attaches to it, and enables you to immediately begin debugging your program.`,
|
starts and attaches to it, and enables you to immediately begin debugging your program.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
status := func() int {
|
status := func() int {
|
||||||
@ -179,7 +179,7 @@ starts and attaches to it, and enables you to immediately begin debugging your p
|
|||||||
testCommand := &cobra.Command{
|
testCommand := &cobra.Command{
|
||||||
Use: "test",
|
Use: "test",
|
||||||
Short: "Compile test binary and begin debugging program.",
|
Short: "Compile test binary and begin debugging program.",
|
||||||
Long: `Compiles a test binary with optimizations disabled,
|
Long: `Compiles a test binary with optimizations disabled,
|
||||||
starts and attaches to it, and enable you to immediately begin debugging your program.`,
|
starts and attaches to it, and enable you to immediately begin debugging your program.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
status := func() int {
|
status := func() int {
|
||||||
@ -222,9 +222,41 @@ starts and attaches to it, and enable you to immediately begin debugging your pr
|
|||||||
}
|
}
|
||||||
rootCommand.AddCommand(attachCommand)
|
rootCommand.AddCommand(attachCommand)
|
||||||
|
|
||||||
|
// 'connect' subcommand.
|
||||||
|
connectCommand := &cobra.Command{
|
||||||
|
Use: "connect [addr]",
|
||||||
|
Short: "Connect to a headless debug server.",
|
||||||
|
Long: "Connect to a headless debug server.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
fmt.Fprintf(os.Stderr, "An address was not provided. You must provide an address as the first argument.\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
addr := args[0]
|
||||||
|
if addr == "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "An empty address was provided. You must provide an address as the first argument.\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(connect(addr))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
rootCommand.AddCommand(connectCommand)
|
||||||
|
|
||||||
rootCommand.Execute()
|
rootCommand.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func connect(addr string) int {
|
||||||
|
// Create and start a terminal - attach to running instance
|
||||||
|
var client service.Client
|
||||||
|
client = rpc.NewClient(addr)
|
||||||
|
term := terminal.New(client)
|
||||||
|
err, status := term.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
func execute(attachPid int, processArgs []string) int {
|
func execute(attachPid int, processArgs []string) int {
|
||||||
// Make a TCP listener
|
// Make a TCP listener
|
||||||
listener, err := net.Listen("tcp", Addr)
|
listener, err := net.Listen("tcp", Addr)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user