delve icon indicating copy to clipboard operation
delve copied to clipboard

Feature request: invoke debugger from inside program

Open icholy opened this issue 5 years ago • 7 comments

Python's PDB and Ruby's IRB both have a convenient feature for starting the debugger programatically from inside the code. The advantage is that it's equal or less effort than printf debugging.

Ex:

package main

import "github.com/go-delve/delve"

func main() {
	delve.Debug()
}

I don't know if this is feasible, but I figured it would be worth asking.

icholy avatar Dec 10 '19 18:12 icholy

Maybe what you want is runtime.Breakpoint.

package main

import (
	"fmt"
	"runtime"
)

func main() {
	runtime.Breakpoint()
	fmt.Printf("hello world")
}

dlv debug main.go then c

chainhelen avatar Dec 11 '19 03:12 chainhelen

@chainhelen I'm aware of runtime.Breakpoint. What I'm suggesting is a purely ergonomic improvement which would make me (and I think a lot of others) reach for delve in a lot of cases where I/they usually wouldn't. I get that it seems trivial/insignificant, but I think it's the reason I find myself using pdb all the time, any only using delve as a last resort.

icholy avatar Dec 11 '19 03:12 icholy

The only way to do this would be to have the target program start the delve (as a separate process) and ask it to attach. It's likely to be a lot of work to provide a minor convenience.

aarzilli avatar Dec 13 '19 10:12 aarzilli

@aarzilli complexity aside, would it be possible to run delve in the same process as the target program?

icholy avatar Dec 13 '19 15:12 icholy

No, it would deadlock itself.

aarzilli avatar Dec 13 '19 15:12 aarzilli

I see. Would you be opposed to leaving this issue open just to gauge interest?

icholy avatar Dec 13 '19 15:12 icholy

Yes, that's fine.

aarzilli avatar Dec 13 '19 15:12 aarzilli

Doesn't look like there's been enough interest for this in the past 3 years.

aarzilli avatar Nov 21 '22 08:11 aarzilli