GDB View stack Information

Source: Internet
Author: User
Keywords nbsp; function view GDB
Tags address aliyun calls function function call gdb http info

When the program is stopped, the first thing you need to do is to see where the program stops. When your program calls a function, the address of the function, the function arguments, the local variables within the function are pressed into the stack. You can use the GDB command to view the information in the current stack.

Here are some GDB commands for viewing the function call stack information:

BackTrace
Bt

Prints all the information for the current function call stack. As:
&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP;
(GDB) bt
#0 func (n=250) at Tst.c:6
#1 0x08048524 in Main (Argc=1, argv=0xbffff674) at tst.c:30
#2 0x400409ed in __libc_start_main () from/lib/libc.so.6

From above you can see the call stack information for the function: __libc_start_main--> main ()--> func ()

BackTrace <n>
BT <n>

n is a positive integer that prints only the stack information at the top n level of the stack.

BackTrace <-n>
BT <-n>

-N Table A negative integer that represents only the stack information at the bottom n level of the stack.

If you want to see a layer of information, you need to switch the current stack, in general, when the program stops, the topmost stack is the current stack, if you want to see the stack below the details of the layer, the first thing to do is to switch the current stack.

Frame <n>
F <n>

n is an integer that starts at 0 and is the layer number in the stack. For example: Frame 0, which represents the top of the stack, frame 1, represents the second layer of the stack.

Up <n>

To move an n layer above the stack, you can move it up one level without hitting N.

Down <n>

Represents moving an n layer underneath the stack, without hitting N, to move down one level.

The above command will print out the information of the stack layer that is moved to. If you don't want it to be typed. You can use these three commands:

Select-frame <n> corresponds to the frame command.
up-silently <n> corresponds to up command.
down-silently <n> corresponds to down command.

To view the current stack layer information, you can use the following GDB command:

Frame or F

Will print out this information: Stack layer number, current function name, function parameter value, function file and line number, function to execute the statement.
Info frame
Info F

This command prints more detailed information about the current stack layer, except that most are memory addresses at run time. For example: function address, call function address, call function address, current function is written by what program language, function parameter address and value, local variable address and so on. 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 0xbffff5d8

Info args

Prints the parameter name and its value of the current function.

Info locals

Prints out all local variables and their values in the current function.

Info catch

Prints exception handling information in the current function.

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.