[LINUX] Trial gdb

It's basically a memo for myself, but I think it will be helpful for those who are thinking of touching gdb from now on.

What is gdb

A debugger that debugs programs such as C and C ++ on Linux.

Preparation

Build the source to be debugged with the -g3 option

--Gdb can be used without the option, but it is recommended to add it because there is almost no debug information without it.

How to use

Load the prepared executable file into gdb as shown below. This time, as an example, the executable file name is ʻa.out`.

$ gdb a.out

command

run [argument]

--Run the program loaded with gdb --The abbreviation is r

(gdb) r

quit [argument]

--Exit gdb --The abbreviation is q

(gdb) q

break filename: number of lines

--Set a breakpoint on the specified file / line --The abbreviation is b

(gdb) b hoge.cpp:10

next --Stepping (not inside the function) --The abbreviation is n

(gdb) n

step --Step execution (enter inside the function) --The abbreviation is s

(gdb) s

continue --Restart a program that was stopped at a breakpoint, etc. until the next breakpoint. --The abbreviation is c

(gdb) b hoge.cpp:10

print --Evaluate and display variables, expressions, etc. --The abbreviation is p

(gdb) p hoge

backtrace --Displays the history of function calls up to the last minute --The abbreviation is bt

(gdb) bt

Recommended Posts

Trial gdb
First gdb
tslearn trial memorandum