nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.66k stars 372 forks source link

Delve doesn't attach #178

Open pjebs opened 6 years ago

pjebs commented 6 years ago

For some reason, Delve debugger doesn't attach to programs that use this package

gdlv run *.go (gdlv is just a graphical front-end for delve)

OUTPUT error:
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

exit status 2
rationull commented 6 years ago

When I try to run a termbox application of mine with gdlv on macOS or Linux, I definitely hit some issues with input handling but do not see the error message you mention -- I can successfully attach to the application. Maybe there's something peculiar about your project layout that could help point to the issue?

pjebs commented 6 years ago

That error no longer displays but it still doesn't work. Nothing happens. In fact, gdlv just appears to be frozen.

rationull commented 6 years ago

I have never used gdlv (or dlv itself) before testing this out, but we might be seeing the same issue. Have you tried typing "continue" in the text box at the bottom of the section of the window that has the play button in it and shows the delve console?

I can get the debuggee to run that way (it seems to start paused) but once I do that I can't get the debuggee to stop again, nor to respond correctly to keyboard/mouse input. I wonder if delve or gdlv is doing something that interferes with the terminal input modes termbox uses.

I see the same problems when I attach to an existing process and when I start the process via gdlv. You too?

pjebs commented 6 years ago

that's exactly what happens to me. I use delve for all my other Go programs and i've never had any issues. I do the same process:

gdlv debug *.go
b <filename>:<line nu> //inside gdlv

and use to continue and step buttons. Works all the time except for this program.

nsf commented 6 years ago

Related: https://github.com/nsf/termbox-go/issues/154

Sorry for not looking at it. Probably won't do it any time soon.

teolandon commented 6 years ago

A workaround is to run the termbox-go application, and then attach with delve from another terminal.

./tb-app
dlv attach <PID>

This allows delve to manipulate the terminal in its own terms, while termbox-go manipulates the other terminal in its own. It's a bit more tedious, especially since you need to find the PID of the app you're debugging, and you might want to block the app's execution until after you've attached, probably using a signal. But using the $! variable in bash you can easily get the PID of the last process and automate this using a small script (works especially well with a terminal multiplexer, since you can actually execute things in both terminals through the script to set everything up).