8 查看栈信息
The call stack is divided up into contiguous pieces called stack frames, or frames for short; each frame is the data associated with one call to one function. The frame contains the arguments given to the function, the function’s local variables, and the address at which the function is executing. When your program is started, the stack has only one frame, that of the function main. This is called the initial frame or the outermost frame. Each time a function is called, a new frame is made. Each time a function returns, the frame for that function invocation is eliminated. If a function is recursive, there can be many frames for the same function. The frame for the function in which execution is actually occurring is called the innermost frame.
This is the most recently created of all the stack frames that still exist.
Inside your program, stack frames are identified by their addresses. A stack frame consists of many bytes, each of which has its own address; each kind of computer has a convention for choosing one byte whose address serves as the address of the frame. Usually
this address is kept in a register called the frame pointer register while execution is going on in that frame. gdb assigns numbers to all existing stack frames, starting with zero for the innermost frame, one for the frame that called it, and so on upward. These numbers do not really exist in your program;
they are assigned by gdb to give you a way of designating stack frames in gdb commands.

当程序被停住了,你需要做的第一件事就是查看程序是在哪里停住的。当你的程序调用了一个函数,函数的地址,函数参数,函数内的局部变量都会被压入“栈”(Stack)中。你可以用GDB命令来查看当前的栈中的信息。
下面是一些查看函数调用栈信息的GDB命令:
backtrace
bt

打印当前的函数调用栈的所有信息。如:
(gdb) bt
#0 func (n=250) at tst.c:6
#1 0x08048524 in
main (argc=1, argv=0xbffff674) at tst.c:30
#2 0x40040Arrayed in __libc_start_main () from /lib/libc.so.6
从上可以看出函数的调用栈信息:__libc_start_main
--> main() --> func()

backtrace n
bt n

n是一个正整数,表示只打印栈顶上n层的栈信息。
backtrace -n
bt -n
-n表一个负整数,表示只打印栈底下n层的栈信息。
如果你要查看某一层的信息,你需要在切换当前的栈,一般来说,程序停止时,最顶层的栈就是当前栈,如果你要查看栈下面层的详细信息,首先要做的是切换当前栈。
frame n
n是一个从0开始的整数,是栈中的层编号。比如:frame 0,表示栈顶,frame 1,表示栈的第二层。
frame addr
f addr

Select the frame at address addr. This is useful mainly if the chaining of
stack frames has been damaged by a bug, making it impossible for gdb to assign
numbers
properly to all frames. In addition, this can be useful when your program has
multiple stacks and switches between them.

up n
表示向栈的上面移动n层,可以不打n,表示向上移动一层。
down n
表示向栈的下面移动n层,可以不打n,表示向下移动一层。
上面的命令,都会打印出移动到的栈层的信息。如果你不想让其打出信息。你可以使用这三个命令:
select-frame 对应于 frame 命令。
up-silently n 对应于 up 命令。
down-silently n 对应于 down 命令。
查看当前栈层的信息,你可以用以下GDB命令:
frame 或 f
会打印出这些信息:栈的层编号,当前的函数名,函数参数值,函数所在文件及行号,函数执行到的语句。
info frame
info f
This command prints a verbose description of
the selected stack frame, including:
• the
address of the frame
• the
address of the next frame down (called by this frame)
• the
address of the next frame up (caller of this frame)
• the
language in which the source code corresponding to this frame is written
• the
address of the frame’s arguments
• the
address of the frame’s local variables
• the
program counter saved in it (the address of execution in the caller
frame)

which registers were saved in the frame
The
verbose description is useful when something has gone wrong that has made
the
stack format fail to fit the usual conventions.
    这个命令会打印出更为详细的当前栈层的信息,只不过,大多数都是运行时的内内地址。比如:函数地址,调用函数的地址,被调用函数的地址,目前的函数是由什么样的程序语言写成的、函数参数地址及值、局部变量的地址等等。如:
(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
frame addr
info f
addr
Print
a verbose description of the frame at address addr, without selecting that
frame.
The selected frame remains unchanged by this command. This requires the same
kind of address (more than one for some architectures) that you specify
in the
frame command.
info args
Print the arguments of the selected frame, each on a separate line.
info locals
打印出当前函数中所有局部变量及其值。
info catch
打印出当前的函数中的异常处理信息。

GDB backtrace bt 查看程序crash堆栈信息相关推荐

  1. adb查看activity的堆栈信息

    adb查看activity的堆栈信息 adb shell dumpsys activity 该命令可以看到当前运行的是哪个activity,运行的一些进程等 看到运行的进程信息: ACTIVITY M ...

  2. -heap 查看当前jvm堆栈信息_必知必会的JVM工具系列二,读懂会用jhat,jstack,jstatd,JConsole...

    1.5 jhat命令 使用 jhat 工具可以用于分析Java应用程序的堆快照内容.以前文中jmap的输出对文件 heap.hprof 为例: jhat 在分析完成后,使用HTTP服务器展示其分析结果 ...

  3. jstack查看某个进程堆栈信息

    jstack主要用来查看某个进程内线程的堆栈信息 一个死锁的模拟代码 package test;import java.util.concurrent.Executor; import java.ut ...

  4. linux的gdb命令bt,Linux 程序调式命令 GDB 概述

    1 GDB 概述 一般来说,GDB主要帮助你完成下面四个方面的功能: https://www.cndba.cn/dave/article/3731https://www.cndba.cn/dave/a ...

  5. Linux反汇编根据程序崩溃堆栈信息定位问题2

    进程崩溃打印 ifotond: unhandled page fault (11) at 0x00000000, code 0x017 pgd = c5770000 [00000000] *pgd=8 ...

  6. gdb 命令_gdb实用的调试技巧:启动方式、堆栈信息、单步调试

    对于很多开发者来说,开发过程中难免会遇到各种各样的bug, 所以,每个开发者应该考虑如何快速高效定位问题原因,而gdb是linux上很实用的调试工具,熟练掌握其调试技巧,将有助于提高解决问题的效率,也 ...

  7. timed_waiting线程是否占用cpu_程序CPU占用率飙升,如何定位线程的堆栈信息?超详细,值得收藏看不懂还有配套视频 第319篇...

    相关历史文章(阅读本文前,您可能需要先看下之前的系列?) 国内最全的Spring Boot系列之三 2020上半年发文汇总「值得收藏」 GraphQL的探索之路 – SpringBoot集成Graph ...

  8. MiniDump文件的创建、分析堆栈信息、定位错误、查看异常处理信息

    1.MiniDump文件的创建: 创建miniDump的方法有很多.可以通过MiniDumpCreateDumpWin32Api创建.必要参数为EXCEPTION_POINTERS结构,获取这个结构可 ...

  9. 用GDB调试c/c++程序

    本文系转载,我仅仅是完整的读了一遍,实际的根据流程对命令执行了一遍,并做了界面排版工作.我从地址luckywqf中看到,他也是转载的,因此也不太知道源地址是哪个了,在此感谢. GDB概述 GDB是GN ...

最新文章

  1. android之利用SQLite数据库实现登陆和注册
  2. 系统监控:top vs Htop vs Glances
  3. ArcGIS AO开发高亮显示某些要素
  4. 2018-12-25 上机作业
  5. java设计模式2-观察者模式
  6. 一只青蛙跳向三个台阶_9. 变态跳台阶
  7. Citrix HDX 3D Pro - 注意事项 - 2017H1
  8. 华为软件开发云又出新服务:开源镜像站正式上线,致敬开源,使能开发者!
  9. 【sql的四大连接】
  10. c++小学生信息学奥赛变量练习(魔方)
  11. Foxmail设置方法
  12. uni真机showToast不显示
  13. windows powershell实战指南(第3版)_Windows命令行工具cmder配置(转)
  14. CMAP1000-05气象数字压力校验系统
  15. 从购买ECS到SpringCloud项目的自动化部署及发布
  16. 记录:解决firefox不同电脑上不能同步的问题
  17. 你管这叫操作系统源码(六)
  18. 去掉CodeGear的Welcome page.
  19. Pandas——ix vs loc vs iloc区别
  20. PPT中绘制图形如何导入VISIO编辑

热门文章

  1. 亚特兰蒂斯【线段树+扫描线+离散化】
  2. 学Java 这样入门 28天轻松掌握
  3. 09年生日送我的煎蛋超级技术
  4. 博途PLC 1200/1500PLC MODBUS-RTU通讯优化(状态机编程)
  5. 使用webpack脚手架创建一个vue项目
  6. 使用mac搭建vue脚手架项目
  7. Windows异常世界历险记(五)——VC6中结构化异常处理机制的反汇编分析(下)
  8. Win7的不关闭防火墙下的FTP设置
  9. CentOS 7安装MySQL集群-GALERA CLUSTER 4 FOR MYSQL 8 RELEASE
  10. mysql bitand函数_有趣的SQL(一)