Debugging with GDB
To debug, you must generate debugging info when compiling , and this requires you to pass the -g option to the compiler. If you don't know why, just think of how you debug with visual studio. ( FAQ之 Debug单步调试 )
I'll illustrate how to debug with GDB with a simple C program.
I run the compiler with release mode and debug mode, respectively. Accordingly, executable file are named with release and debug. As it shown in the picture above, the release version is smaller than the debug one, which is resulted from the lack of debug info.
To start the debugging, type gdb exe_name . Note the name here is the debugged executable file, not the source code.
break to set breakpoints, e.g., break 20 to set at the 20th line.
the command is run
You can type continue to let the program go on.
2024-07-01 广告