Linuxgcc and gdb program debugging usage

Source: Internet
Author: User
Tags print object
Linuxgcc and gdb program debugging usage gcc General debugging format: www.2cto. comgcc-Wall-otesttest.c //-wall display program error details gcc-v // Display gcc version gcc-o {, 3} testtest. c // 1, 2, 3... linux gcc And gdb program debugging usage gcc General debugging format: www.2cto.com gcc-Wall-o test. c //-wall display program error details gcc-v // Display gcc version gcc-o {1, 2, 3} test. the higher the optimization level, the longer the compilation time, the gcc-ggdb3-Wall-o test. c // you can use gdb to track debugging programs. running this command gdb tells gcc to generate debugging using gdb extension, where 3 indicates the level 3 debugging information used and more information can be obtained by programmers. If the program has multiple modules, you can compile them separately, then generate an executable file gcc-o test1.c // Generate test1.ogcc-o test2.c // Generate test2.ogcc-o test3.c // Generate test3.ogcc-o program test1.c test2.o test3.o // Generate there are so many finally executable files in program about gcc, it will be used later. Www.2cto.com gdb symbol Debugger gdb mainly provides the following functions: 1. variable value variation in the monitoring program 2. set a breakpoint to suspend the execution of the program on the specified code line for observation. code execution in one step 4. analysis of the crash program to generate the core file is first gcc-ggdb3-Wall-o test. c. debug the program. /test is a normal execution program. If an incorrect result is displayed, debug gdb test with gdb to run the program at the (gdb) interface prompt. set the breakpoint to run before it starts, all other commands are executed in step | s // One-step execution in the running program. when a function is executed, the next function is executed. | n // One-step execution is performed, but do not enter the quit function | q // exit gdb break LineNumber | functionNamecontinue | cont N // indicates the number of broken points skipped tbreak LineNumber | functionName // This is only one When a temporary power failure occurs, the enable/disable breakpoint number will be automatically deleted once it is executed. // The failed breakpoint will be restored. | make the valid breakpoint invalid. (if multiple breakpoints are operated, separate them with spaces in the middle) clear: the line number of the breakpoint. the number of the delete breakpoint is clear. the variable is different. watch logical expression // This command is used in the program run. you must set the main function as a breakpoint, then, the program stops where the logical expression is satisfied. View stack information bt number // if number> 0 indicates that the information of the number stack on the top of the stack is displayed // if number <0 indicates that the information of the number stack on the bottom of the stack is displayed // omitted display All stack information frame | f n // display the information stack top of layer n is 0, up once // Stack upward shift n layer omitting default layer down // Stack downward shift nceng omitting the default select-frame layer = Frame // just do not output stack information up-silently = Up // just do not output stack information down-silently = Down // just do not output stack information info args // display the current function parameter name and value info locals // display all the local variables in the function info catch // display the first function exception handling information display source code list // Display function Source program list // Display listsize before and after the current row/two lines of code list-// display the code list before the current row + // display the code list behind the current row code set listsize // Set the number of lines displaying the source code at a time. show listsize // view the value list of listsize. , // Display the list of all source codes, // Display the source code list from the current row to the last row // Display the listsize/list of two lines of code <+ ffset> before and after linenum rows. // display the list of positive offsets of the current row <-ffset> // display the negative offset of the current row for search source code forward-search = Search // Search for reverse-search // Search for directory // Add a search path for a custom file. multiple paths are used: separate directory // clear all custom source file search path information show directories // display the source code of the custom source file search path in the memory info line to view the source code address in the memory. Info line can be followed by "line number", "function name", "File name: line number", and "File name: function name "disassemble <> // add the same parameters as above. display the assembly code to view the data print variable print file: variable | function :: variable // If you are viewing global variables, in order to avoid duplicate names with local variables, print * array @ len // displays the dynamic array print * array // displays the static array print/ // The output format is as follows: x hexadecimal display d Decimal Display u hexadecimal display unsigned integer o octal display t binary display a hexadecimal display c character format display f floating point format display view memory x/ // N indicates the number of the third parameter displayed. for the f format, see the preceding section. the number of bytes requested by u from the current address. the default value is 4. B indicates a single byte, h indicates double bytes, w indicates 4 bytes, and g indicates that 8 bytes are automatically displayed. // Undisplay is displayed as long as the variable is valid. | delete display // Delete the automatic display numbered dnums, and delete several disable display separated by spaces // Disable automatic display numbered dnums. enable display is separated by spaces. // Enable automatic display reply with the ID of dnum, multiple display information is separated by spaces. The display option set print address on // gdb usually displays the parameter address information, by default, set print address off is enabled. // gdb generally does not display the parameter address information. show print address // Check Whether set print array on is not enabled. // Each element of the open array occupies a set row. print array off // close each element of the array separated by commas show print array // Check Whether set print element is enabled // Display the maximum length of the array. show print elementset print null-stop // Whether the display stops when an Terminator is encountered, set print pretyy on is disabled by default. // The structure display is pretty good. show print pretyy // You can view how to display the structure set print sevenbit-strings // whether to enable set print union. // Whether to display the consortium data in the struct show print unionset print object // In c ++, when an object points to a derived class, with this option enabled, gdb automatically displays set print static-members according to the rules for calling the virtual method. // Whether the static data member is displayed in the C ++ object. the default value is onshow print static-membersset print vtbl. // Gdb displays the virtual functions in a regular format. by default, show pritn vtbl is disabled to view the Register info registers. // You can view the status of the registers (except floating-point registers) info all-registers // view all registers (including floating-point registers) info registers // View the environment variables of gdb when the register is set // you can define your own variables in environment debugging to save running data in the debugging program. Set $ var = exprshow convenience // view all the currently set environment variables ex> set $ I = 0 print bar [$ I ++]-> contents // after entering such a command, just press Enter and repeat the previous statement. the environment variable will automatically accumulate and modify the variable value print s = expr | set var s = expr // it is best to use the latter to jump to and execute jump // Jump to linenumber line jump // jump to address place jump <+ offse> // jump down the offse line // it is best to use the jump command to jump to the current function, an error occurs when redirecting over a function. signal // Return at 1 to 15 semaphores // Force return. a return value can be called. // Force call the function to use gdb show language in different languages // view the current language environment info frame // view the current function's program language info source // view the current file's program language set language + language name // manually set language // c/c ++/asm/fortran/java/Modula-2/pascal/scheme core dump analysis ulimit-c unlimited // is your own use the core dump permission gdb test core + xxx // The system prevents this generated core from overwriting the previous one, all cores are differentiated by pid numbers.
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.