For beginners of gdb, it is required to call gdb compilation and add the-g parameter and-o after cc; [root @ redhat home] # gdb debugging file: Start gdb (gdb) l :( l) list source code www.2cto.com (gdb) break n: Set the breakpoint (gdb) break func at the nth row: Set the breakpoint (gdb) at the entrance of the function func) info break: view the checkpoint information (gdb) r: Running Program (gdb) n: single-step execution (gdb) c: continue running (gdb) p variable: print the value of the variable (gdb) bt: view the function stack (gdb) finish: exit the function (gdb) shell Command Line: Execute the shell command line (gdb) set args parameter: specify the runtime parameter (gdb) show args: view the configured parameter (gdb) show paths: view the program running path; set environment Varname [= value] sets the environment variable. For example, set env USER = hchen; show environment [varname] to view environment variables; (gdb) cd is equivalent to shell cd; (gdb) pwd: display the current directory (gdb) info program: to check whether the program is running, the process number, and the reason for suspension. (Gdb) clear row n: clear the breakpoint gdb of line n) disable breakpoint n: Pause the enable breakpoint n of line n: enable the nth breakpoint (gdb) step: for single-step debugging, if a function is called, it enters the function. Unlike command n, n does not enter the list of called functions: note: l. Its function is to list the source code of the program. By default, 10 lines are displayed each time. List row number: displays the first 10 lines of code centered on the current file. For example, list 12 list function name: displays the source code of the function where the "function name" is located, for example: list main list: output the following content of the last list Command without parameters. Note: If you run the list command to get a print similar to the following, it is because the-g option is not added during program Compilation: (gdb) list 1 .. /sysdeps/i386/elf/start. s: No such file or directory. in .. /sysdeps/i386/elf/start. S www.2cto.com run: r, which is used to run a program. When a breakpoint occurs, the program stops running at the breakpoint and waits for the user to enter the next command. Press Enter: repeat the previous command. Set args: set the command line parameters when running the program, for example, set args 33 55 show args: display the command line parameter continue: the message is c, its role is to continue running the program interrupted by the breakpoint. Break: Set a breakpoint for the program. Break row number: Set a breakpoint at the "row number" of the current file, for example, break 33 break function name: Set a breakpoint at the "function name" of the User-Defined Function, for example: break cb_button info breakpoints: displays the breakpoint settings of the current program. disable breakpoints Num: disables the breakpoint "Num" to make it invalid, "Num" is the corresponding value displayed in info breakpoints enable breakpoints Num: enable the breakpoint "Num" to take effect again. step: Note: s, single-step tracking program, when a function is called, enter the function body (generally only the User-Defined Function ). Next: the short note is n, a single-step tracking program. When a function is called, it does not enter the function body. The main difference between this command and step is that, when a user-defined function is encountered in a step, the step will be stepped into the function to run, and next will directly call the function and will not enter the function body. Until: When you get tired of tracking a single step in a loop body, this command can run the program until you exit the loop body. Finish: run the program until the current function finishes returning, and print the stack address, return value, and parameter value when the function returns. Stepi or nexti: One-Step tracking of some machine commands. Print expression: p, where "expression" can be a valid expression of any program being tested, for example, a program that is currently debugging C language, the "expression" can be a valid expression in any C language, including numbers, variables, and even function calls. Print a: print + a: the value of integer a is displayed. print + a: the value in a is added to 1 and the print name is displayed. print gdb_test (22 ): call the gdb_test () function print gdb_test (a) with an integer 22 as the parameter: Call the gdb_test () function bt with variable a as the parameter: display the function call stack of the current program. Display expression: it is very useful when running a single step. After setting an expression using the display command, It outputs the set expression and value after each single step command. For example: display a watch expression: sets a monitoring point. Once the value of the monitored "expression" changes, gdb will forcibly terminate the program being debugged. For example, watch a www.2cto.com kill: The help command of the program currently being debugged will be forcibly terminated. The help command will display the commonly used help information of the "command" call function (parameter): call the "function ", and pass the "parameter", such as: call gdb_test (55) layout: used to split the window, you can view the Code while testing: layout src: display the source code window layout asm: display Disassembly window layout regs: display source code/disassembly and CPU register window layout split: display source code and Disassembly window Ctrl + L: refresh Window quit: Note: q, exit gdb of course, gdb has far more functions than this, including multi-process, multi-thread, signal, remote debugging, and other functions. For more information, see