Linux - GNU Debugger (GDB)
GDB is the world famous GNU debugger, which is very powerful. In this article, its elementary usages can be listed as follows.
b(reak) LINE_IDX: set breakpoint in lineLINE_IDX.b(reak) FUN_NAME: set breakpoint at the begin of functionFUN_NAME.b(reak) ... if ...: set conditional breakpoint.delete breakpoints BP_IDX: delete breakpointBP_IDX(ifBP_IDXis omitted, all the breakpoints will be deleted).disable breakpoints BP_IDX: disable breakpointBP_IDX(ifBP_IDXis omitted, all the breakpoints will be disabled).enable breakpoints BP_IDX: enable breakpointBP_IDX(ifBP_IDXis omitted, all the breakpoints will be enabled).display VAR_NAME: track varableVAR_NAME, every time the program stops, its value will be displayed.undisplay VAR_NAME: cancel tracking of variableVAR_NAME.start: start to excute the program and stop at the first statement of main.r(un): excute the program from beginning continuously.c(ontinue): excute the program from current position contiously.s(tep): excute the program by one step and enter the function if available.n(ext): excute the program by one step and don’t enter any function.backtrace(or bt): view the function call of all the levels and their parameters.f(rame) FRM_IDX: select the stack frame of indexFRM_IDX.watch: set observation point.i(nfo) locals: view the values of local variables in current stack frame.i(nfo) b(reakpoints): view current breakpoints.i(nfo) watchpoints: view current observation points.l(ist): list 10 lines of source code, continuing the last.l(ist) LINE_IDX: list the source code around lineLINE_IDX.l(ist) FUN_NAME: list the source code of functionFUN_NAME.x: print part content of register from some position. All the contents are treated as bytes without consideration that which bytes correspond to which variable. For example,x/7b pwill print the content of size 7 bytes after point variablep.p(rint) expr: print the value ofexpr. This functionality can be used to change the values of variables or provoke a function.finish: excute the current function until return, and then stop.