View Stack Information -----
When the program is stopped, the first thing you need to do is to check where to stop. When your program calls a function, the address, function parameters, and the local variables in the function will be pressed into the "stack". You can use the GDB command to see the information in the current stack.
Here is some GDB commands for viewing the function call stack information:
Backtrace BT prints all information about the current function call stack. Such as: (gdb) BT # 0 func (n = 250) at tst.c: 6 # 1 0x08048524 in main (argc = 1, argv = 0xBfffff674) At TST.C: 30 # 2 0x400409ed in __libc_start_main () from / lib / lib / lib / lib / lib / lib / lib / lib / lib / /Libc.so.6 can be seen from the function of the call stack information: __ libc_start_main -> main () -> func () backtrace
BackTrace <-n> bt <-n> -n table a negative integer, indicating that only the stack information of the N layer under the stack. If you want to see a layer of information, you need to switch the current stack, in general, the program is stopped, the top of the stack is the current stack, if you want to check the details of the stack, first you want to do it first. Switch the current stack.
Frame
The above command will print out information of the moving stack layer. If you don't want it to make it. You can use these three commands: SELECT-FRAME
View the current stack of information, you can use the following GDB command:
Frame or F will print this information: the stack layer number, the current function name, the function parameter value, the file in the file and the line number, the function executed by the function. Info frame info f This command prints more detailed information of the current stack layer, but most is the internal address of the runtime. For example, the function address, the address of the call function, the address called function, the current function is written by, the function parameter address, the value, the address, and the like of local variables, etc. Such as: (gdb) info f Stack level 0, frame at 0xbffff5d4: eip = 0x804845d in func (tst.c: 6); saved eip 0x8048524 called by frame at 0xbffff60c source language c Arglist at 0xbffff5d4, args:. N = 250 Locals AT 0xBffff5D4, Previous Frame's SP is 0x0 Saved Registers: EBP AT 0xBffff5D4, EIP AT 0xBffFFF5D8 INFO ARGS Prints the parameter name and its value of the current function. INFO LOCALS prints all local variables and their values in the current function. INFO CATCH prints an exception handling information in the current function. View Source ----- First, Display Source Codes
GDB can print out the source code of the debugprue, of course, be sure to add -g parameters when compiling, and compile the source program information into the execution file. Otherwise, you can't see the source program. When the program stops, the GDB will report that the program stopped on the first few lines of the file. You can use the list command to print the source code of the program. Let's take a look at the GDB command to view the source code. List
Generally, print the top 5 rows of the current row, if the display function is on the top 2 line 8 line, the default is 10 lines, of course, you can customize the range of display, use the following command to set a display source program The number of rows.
Set listsize
The List command has the following usage:
List
Generally speaking, you can follow the following parameters after List:
Not only that, GDB also provides commands for source code search:
Forward-Search
REVERSE-Search
Third, the path to specify the source file
At some point, in the execution program compiled with -g, just includes the name of the source file, no path name. GDB provides commands that allow you to specify the path to the source file to search for GDB.
Directory
Fourth, the memory of the source code
You can use the Info Line command to view the address of the source code in memory. Info Line, you can follow the "Row", "Function Name", "File Name", "File Name: Function Name", this command prints the memory address of the specified source code at runtime, such as:
(GDB) info line tst.c: func line 5 of "TST.C" Starts at address 0x8048456
There is also a command that you can view the current execution of the source program, this command will take the command dump in the current memory. As shown below, the assembly code of the function FUNC is viewed.
(Gdb) disassemble func Dump of assembler code for function func: 0x8048450