当前位置:网站首页>gdb常用命令
gdb常用命令
2022-07-26 13:45:00 【1.01】
GDB主要完成下面四个方面的功能:
- 启动你的程序,可以按照你的自定义的要求随心所欲的运行程序。
- 可让被调试的程序在你所指定的调置的断点处停住。(断点可以是条件表达式)
- 当程序被停住时,可以检查此时你的程序中所发生的事。
- 动态的改变你程序的执行环境。
常用命令:
——————————————————————————————————————————————————
Linux下如何使用gdb调试core文件
**
1.core文件
**
core文件是程序运行状态的内存映像当程序运行过程中出现segmentation fault(core dumped)错误时,程序停止运行,并产生core文件。
使用gdb调试core文件可以帮我们快速定位程序出现段错误的位置。可执行程序编译时应加上-g编译选项,生成调试信息闭。
当程序访问的内存超出了系统给定的内存空间,就会产生Segmentation fault(core dumped),因此,段错误产生的情况主要有:
- 访问不存在的内存地址
- 访问系统保护的内存地址
- 数组访问越界等
core dumped又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前内存状况储存在一个core文件中。
**
2.控制core文件是否生成
**
- 使用ulimit -c命令可查看core文件的生成开关。若结果为0,则表示关闭了此功能,不会生成core文件。
- 使用ulimit -c filesize命令,可以限制core文件的大小(filesize的单位为kb)。如果生成的信息超过此大小,将会被剪裁,最终说呢过程一个不完整的core文件。例:ulimit -c 1024
- 使用ulimit -c unlimited则表示core文件大小不受限制。
- 在终端通过命令ulimit -c unlimited只是临时修改,重启后无效,永久修改的三种方式。
在/etc/rc.local中增加一行ulimit -c unlimited 在/etc/profile中增加一行ulimit -c unlimited- 1
- 2
3.core文件的名称和生成路径
core默认的文件名称是core.pid,pid指的是产生段错误的程序的进程号。
默认路径是产生段错误的程序的当前目录。
4.gdb调试core文件的步骤
使用gdb调试core文件来查找程序中出现段错误的位置时,需要可执行程序加上-g编译命令选项。
常见的有以下几种(推荐第一种):
步骤一:
(1)启动gdb进入core文件,命令格式:gdb [exec file] [ core file]
例:gdb ./test test.core
(2)进入后,查找段错误位置:where或者bt
可以定位到源程序当中具体文件的具体位置,出现的段错误。
步骤二:
(1)启动gdb进入core文件,命令格式:gdb -core=[core file]
例:gdb -core=test.core
(2)在进入gdb后,指定core文件对应的符号表,命令格式:file [exec file]
在gdb输入bt命令 在遇到段错误时,输入bt命令,即可跟踪错误
边栏推荐
- El table implements editable table
- With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
- Tupu 3D visual national style design | collision between technology and culture "cool" spark“
- Abstract factory and its improvement examples
- ROS2学习(1)ROS2简述
- 图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
- Win11+vs2019 configuration yolox
- Precautions for triggering pytest.main() from other files
- How to remove black edges from hyperimage images (two methods)
- Time complexity analysis of bubble sorting
猜你喜欢

上一次听到易趣,还是上一次

天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞

Docker integrates the redis sentinel mode (one master, two slave and three sentinels)

We were tossed all night by a Kong performance bug

WPS凭什么拒绝广告?
Exploration on cache design optimization of community like business

Precautions for triggering pytest.main() from other files

JS get the current time, time and timestamp conversion

Activity. Onstop() delay 10 seconds? Wonderful investigation process

【C语言学习者必会的题目集锦1】巩固基础,稳步提高
随机推荐
ROS2学习(1)ROS2简述
Basic sentence structure of English ----- origin
The picture moves horizontally with the phone - gyroscope. 360 degree setting conditions
Frisbee, 2022 "black red" top stream
MySQL's practice of SQL analysis and optimization from the index principle
SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
Jenkins 中 shell 脚本执行失败却不自行退出
Abstract factory and its improvement examples
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Go multithread communication, control coordination and main thread shutdown (sync.waitgroup)
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
[turn] judge the relationship between two geometries in ArcGIS
Time complexity analysis of bubble sorting
Completable future practical usage
How to remove black edges from hyperimage images (two methods)
向路由组件传递参数
Sword finger offer (IX): abnormal jumping steps
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
Pass parameters to the routing component
Control the probability of random winning [C | random]
