Beginners of gdb must know

Source: Internet
Author: User
For beginners of gdb, it is required to call gdb compilation and add the-g parameter and-o after cc; [root @ redhathome] # gdb debugging File: start gdb (gdb) l :( l) list source code www.2cto.com (gdb) breakn: Set the breakpoint (gdb) breakfu at line n... 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) finis H: Exit function (gdb) shell command line: execute shell command line (gdb) set args parameter: specify the runtime parameter (gdb) show args: view the set parameters (gdb) show paths: view the program running path. set environment varname [= value] to set environment variables. 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.