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 <n> // stack up shift n layer omitting default layer down <n> // stack down nceng omitting default layer select-frame <n >== frame // just do not output stack information up-silently <n >=up // just do not output stack information down-silently <n >== down // just do not output stack information info args // display the current function parameter name and value info locals // display all local variables in the function info catch // display the exception handling information of the first function display source code list <function> // display the source process of the function Sequential list // display the listsize before and after the current row/two lines of code list-// display the code list before the current row + // display the code set listsize after the current row <number> // set the number of lines to display the source code at a time. show listsize // view the Value list of listsize <first>, <last> // display the list of all source code, <last> // display the source code list from the current row to the last <linenum> // display the listsize/list of two lines of code <+ ffset> before and after the linenum line positive Offset list <-ffset> // display the negative offset of the current row search source code forward-search <regexp> = search <regexp> // search reverse-search <regexp> // search up directory <Dirname:...> // 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 // display the dynamic array print * array // display the static array print/<f> <expr> // format output data 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/f/u> <addr> // n indicates the number of the third parameter displayed, for the f format, see the preceding description. The number of bytes requested by u from the current address. The default value is Is 4, B represents a single byte, h Represents dual byte, w represents 4 bytes, g indicates that the display is automatically displayed in 8 bytes <expr> // undisplay is displayed as long as the variable is valid | delete display <dnums...> // Delete the automatic display numbered dnums, and delete several disable display separated by spaces <dnums...> // disable automatic display numbered dnums. enable display is separated by spaces. <dnums...> // 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, set print address off // gdb is enabled by default. The show print address of the parameter is generally not displayed. // check whether set print is enabled. Array on // each element of the open array occupies a line set print array off // close each element of the array separated by commas show print array // check whether set print element is enabled <number- -elements> // display the maximum length of the array. show print elementset print null-stop <on/off> // whether the display stops when an Terminator is encountered, set print pretyy on is disabled by default. // The structure display is pretty. show print pretyy // you can view how to display the structure set print sevenbit-strings // whether to enable set print union. <on/ off> // indicates whether to display the consortium data in the struct. show print unionset print object <on/off> // in c ++: When an object points to a derived class, open this option, gdb automatically displays the set print static-members <on/off>/C ++ object according to the rules called by the virtual method, default onshow print static-membersset print vtbl <on/off> // gdb displays virtual functions in a regular format, show pritn vtbl is disabled by default. view the register info registers // view the register status (except floating-point registers) info all-registers // view the status of all registers (including floating-point registers) info registers <regname...> // 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, simply press Enter to repeat the previous statement, environment variables 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 <linenumber> // jump to linenumber line jump <address>/ /jump to the address jump <+ offse> // jump down the offse line // use the jump command to jump to the current function, an error occurs when redirecting over a function. The signal <singal> // semaphore is returned between 1 and 15. return <expr> // force return, you can call <func> with the return value. // force call different languages of the function. Use gdb show language // to view the current language environment info frame // to view the program language info source/of the current function/ /view the current file program language set language + language name // manually set language // c/c ++/asm/fortran/java/modula-2/pascal/scheme core dump analysis ulimit -c unlimited // you have the permission to use core dump. The gdb test core + xxx // system prevents the generated core from overwriting the previous one, all cores are differentiated by pid numbers.