In python, you can use pdb.set_trace() in the code to launch a pdb debugger right there when the code reaches that point, without having to deal with debuggers or breakpoints. Is there such an equivalent with gdb or any other debugger for go? I see https://golang.org/doc/gdb#Naming but I don't see how to apply it the same way.
1 Answers
No, there is no such equivalent. Python is inherently interpreted1 and pdb
is simply part of any running instance of Python, so this is a lot easier there.
Once you are running under gdb or dlv, though, it's not that hard to set a breakpoint in some known function. Calling that function from the point at which you want to drop into the debugger will drop you into the debugger. So instead of pdb.set_trace
just call debugging.Stop()
and write a debugging
package with a Stop
function that just returns. Set your breakpoint there and run your program.
1Python can in theory be compiled or JIT-ted, but this tends not to work as well as with other languages due to the extremely dynamic nature of the language, e.g., method invocation for instance. Adding a few small restrictions to the language, none of which make it less usable, would make compilation to fast code much easier. For further details see Does the Python 3 interpreter have a JIT feature? (Removing the Global Interpreter Lock would have a big payoff as well, but is also hard: see the PyPy FAQ.)

- 448,244
- 59
- 642
- 775