Evgeny Pokhilko's Weblog

Programmer's den

GDB: How do I set current source file for list and break commands

People who start using GDB after GUI debuggers often ask this question in the title. It is not obvious from the documentation and it is not googled easily either. So the trick I use is to specify a function that I want to debug like this.

list GetName

I can type Get and press tab. GDB suggests names. The command above will set the source file with GetName as its current source file.

If I don’t know the function name, I can specify the file name and line number directly.

list document.cpp:1

This is what most people look for. Then list command will output document.cpp and break 10 will set a breakpoint in document.cpp.

May 17, 2015 Posted by | C++ | Leave a comment