GDB in Action
GDB in Action
入门
编译
gcc -g -O0 -o word2vec.c word2vec
-g 选项:要求 gcc 编译器保留调试符号信息。
-O0 选项表示不优化,从 O1 ~ O4 优化级别越来越高,O4 最高。
strip 命令 = 不加 -g 选项。
启动
第一种
gdb word2vec
第二种
gdb attach (pid)
第三种
gdb word2vec core.21985
(gdb) 命令助记
run (r)
运行程序。也可以设置被调试程序的运行参数,如下例。
(gdb) run -train text8 -output vectors.bin -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 20 -binary 1 -iter 15
show args
Show argument list to give program being debugged when it is started.
Follow this command with any number of args, to be passed to the program.
continue (c)
当 GDB 触发断点或者使用 Ctrl + C 命令中断下来后,想让程序继续运行,只要输入 continue 命令即可。
break (b)
添加断点。
(gdb) break function_name # 在函数入口加断点
(gdb) break line_No # 在当前文件行号为 line_no 加断点
(gdb) break file_name:line_no # 在文件名为 file_name 文件,第 line_no 行加断点
backtrace (bt)
查看当前调用堆栈。
frame (f)
切换堆栈。
(gdb) f 2 #切换到编号为 2 的堆栈(第三层)
disble
Disable some breakpoints.
Arguments are breakpoint numbers with spaces in between.
To disable all breakpoints, give no argument.
A disabled breakpoint is not forgotten, but has no effect until re-enabled.
This command may be abbreviated "disable".
enable
Enable some breakpoints.
Give breakpoint numbers (separated by spaces) as arguments.
This is used to cancel the effect of the "disable" command.
May be abbreviated to simply "enable".
delete
Delete some breakpoints or auto-display expressions.
Arguments are breakpoint numbers with spaces in between.
To delete all breakpoints, give no argument.
This command may be abbreviated "delete".
list (l)
查看当前断点处的代码。往前和往后显示代码,命令分别是“list + (加号)”和“list - (减号)”。
where
打印当前程序运行位置和 frame。
print (p)
可以查看、计算和修改变量的值
(gdb) print a # 查看变量 a 的值
10
(gdb) print &a # 查看变量 a 的地址
(int *) 0x7ffffffde52c
(gdb) print a=12 # 打印并设置变量 a 的值为 12
12
(gdb) print a+a+a # 打印并计算 a+a+a 的值
36
(gdb) print a=a+a # 打印并设置变量 a 的值为 a+a
22
(gdb) print *p # 打印指针 p 指向对象的值
(gdb) print node->name # 打印结构体变量 node 的 name 字段的值
(gdb) p *a@4 # 打印数组 a 的前四个元素
ptype
打印变量的类型
info
info break (info b)
查看断点们的状态,可以显示断点被触发的次数。
info thread
Display currently known threads.
info threads [-gid] [ID]... # -gid: Show global thread IDs.
If ID is given, it is a space-separated list of IDs of threads to display.
Otherwise, all threads are displayed.
info args
查看当前函数被执行的,实参的值。
next
next over,运行下一行,遇到函数调用不进入。
step
step into,运行下一行,遇到函数调用时会进入。
finsh
结束当前函数,返回上层。
return
结束当前函数,返回上层。同时可以指定该函数的返回值。
(gdb) return 99 # 指定当前函数返回值 99
until (u)
指定程序运行到某一行停下来。
jump
让程序执行流跳转到指定位置执行。
可以执行一些我们想要执行的代码,而这些代码在正常的逻辑下可能并不会执行
disassemble
反汇编
tbreak
Set a temporary breakpoint.
Like "break" except the breakpoint is only temporary, so it will be deleted when hit. Equivalent to "break" followed by using "enable delete" on the breakpoint number.
watch
监视一个变量或者一段内存,当这个变量或者该内存处的值发生变化时,GDB 就会中断下来。被监视的某个变量或者某个内存地址会产生一个 watch point(观察点)。
当设置的观察点是一个局部变量时,局部变量无效后,观察点也会失效。
display
监视变量或者内存地址,每次程序中断下来都会自动输出这些变量或内存的值。
signal
Continue program with the specified signal.
signal [SIGNAL]
The SIGNAL argument is processed the same as the handle command.
SIGNAL: SIGCHLD, SIGPIPE, SIGINT, SIGTERM......
handle
Specify how to handle signals.
handle [SIGNAL]
for example
handle SIGINT nostop print
告诉 GDB 在接收到 SIGINT 时不要停止,并把该信号传递给调试目标程序 。
break [lineNo] if [condition]
条件断点。
break 11 if i==5000 # 意为当 i = 5000 时,程序中断在第 11 行
添加条件断点还有一个方法就是先添加一个普通断点,然后使用“condition 断点编号断点触发条件”这样的方式来添加。
condition
Specify breakpoint number N to break only if COND is true.
condition N COND
where N is an integer and COND is an expression to be evaluated whenever breakpoint N is reached.
set
scheduler-locking
Set mode for locking scheduler during execution.
- off - no locking (threads may preempt at any time)
- on - full locking (no thread except the current thread may run). This applies to both normal execution and replay mode.
- step - scheduler locked during stepping commands (step, next, stepi, nexti). In this mode, other threads may run during other commands. This applies to both normal execution and replay mode.
- replay - scheduler locked in replay mode and unlocked during normal execution.
follow-fork-mode
Set debugger response to a program call of fork or vfork.
A fork or vfork creates a new process. follow-fork-mode can be:
- parent - the original process is debugged after a fork
- child - the new process is debugged after a fork
The unfollowed process will continue to run.
By default, the debugger will follow the parent process.
print element
Set limit on string chars or array elements to print.
"set print elements unlimited" causes there to be no limit.
"set print element 0" 完整地显示变量的整个字符串。
args
Set argument list to give program being debugged when it is started.
Follow this command with any number of args, to be passed to the program.
(gdb) set args -train text8 -output vectors.bin -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 20 -binary 1 -iter 15
Reference
[1] 《Linux GDB 调试指南》. 范蠡. https://gitbook.cn/gitchat/column/5c0e149eedba1b683458fd5f
GDB in Action的更多相关文章
- Oracle Solaris 11.4安装桌面/gdb
文章目录 1. 说明 2. 挂载镜像 3. 安装桌面 4. 安装gdb 5. 重启OS 1. 说明 该文承接上文Solaris 11.4安装,映像包管理系统(IPS)搭建. Solaris 11.4的 ...
- GDB 调试 一些命令
1. gdb查看指定地址的内存地址的值:examine 简写 x-----使用gdb> help x 来查看使用方式 x/ (n,f,u为可选参数)n: 需要显示的内存单元个数,也就是从 ...
- Android隐式启动匹配:action,category,data
简介 Android开发中,Activity,Service 和 BroadcastReceiver 启动有两种方式,显示启动和隐式启动. 为方便下面描述,我以Activity启动为例. 显示启动便是 ...
- 用gdb调试python多线程代码-记一次死锁的发现
| 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.如有问题,可以邮件:wangxu198709@gmail.com 前言 相信很多人都有 ...
- gdb 调试入门,大牛写的高质量指南
引用自:http://blog.jobbole.com/107759/ gdb 调试 ncurses 全过程: 发现网上的“gdb 示例”只有命令而没有对应的输出,我有点不满意.gdb 是 GNU 调 ...
- gdb 调试 ncurses 全过程:
转载地址: http://blog.jobbole.com/107759/ gdb 调试 ncurses 全过程: 发现网上的“gdb 示例”只有命令而没有对应的输出,我有点不满意.gdb 是 GNU ...
- GDB调试,转载一位大牛的东西
http://www.wuzesheng.com/?p=1327 手把手教你玩转GDB(一)——牛刀小试:启动GDB开始调试 写在最前面:GDB是unix相关操作系统中C/C++程序开发必不可少的工具 ...
- gdb调试汇总
1. 启动GDB开始调试: (1)gdb program ///最常用的用gdb启动程序,开始调试的方式(2)gdb program core ///用gdb查看core dump文件,跟踪程序cor ...
- gdb core调试
原文链接 http://blog.163.com/lanka83/blog/static/32637615200801793020182/http://blog.csdn.net/taina2008/ ...
随机推荐
- Python读取一个目录下的所有文件
#!/usr/bin/python # -*- coding:utf8 -*- import os allFileNum = 0 def printPath(level, path): global ...
- CString数组和CStringArray
CStringArray是编译器定义的类型!可以进行一些(如:访问.增.删.改)等操作. 集中单个字符串的操作使用Cstring,集中一批字符串的管理使用CstringArray. 一个是动态,CSt ...
- PHP(一般标签介绍,标签特性,实体名称,绝对路径与相对路径)
h1:为标题 h1~h6 标题会逐渐变小 需更换标签里面的数字 如: <h1>这是标题123</h1>---标题 <h2>这是标题123</h2>-- ...
- redis数据库通过dump.rdb文件恢复数据库或者数据库迁移
环境:centos7.2软件:redis-3.2.10(yum安装) 情景一:公司之前的redis没有开启aof模式,一直是rdb模式,但是数据又非常重要,数据一点也不能丢失,所以需要开启aof,但是 ...
- 实战一个职业技术学校。 by:hack某某
这是我们的目标,某一技术学院,这是一个注入点 上sqlmap 跑出了管理账号密码 扫后台 没有找到,注入就相当鸡肋了 换换其他思路 dba权限,想到了直接写入 找找路径之类的 找到了,运气相当的好 直 ...
- 树状数组 || 线段树 || Luogu P5200 [USACO19JAN]Sleepy Cow Sorting
题面:P5200 [USACO19JAN]Sleepy Cow Sorting 题解: 最小操作次数(记为k)即为将序列倒着找第一个P[i]>P[i+1]的下标,然后将序列分成三部分:前缀部分( ...
- spss缺失值填充步骤
缺失值填充是数据预处理最基本的步骤,一般能想到的是固定值填充(均值等统计学方法).根据与本列有相关关系的列函数表示来填充.这次我用的是em算法进行填充,具体原理后续补充. 主要记录一下步骤: 工具栏: ...
- ajax中的同步与异步修改数据的问题
这次项目中因为前端有事儿,项目紧急加个新需求,于是自己硬着头皮上去看了下前端的逻辑后便开始动手了,但是为了简单起见就直接自己写了个ajax调服务来获取数据,然后修改前端定义的全局数据 //ajax来请 ...
- freeswitch的拨号规则配置
当一个呼叫在ROUTING状态下达到命中拨号规则解析器时,相应的拨号规则就开始解析了.随着解析的进行,在xml文件中的符合条件的或标签中的指令形成一个指令表,安装到这个通道中. 你可以将拨号规则文件放 ...
- window.onload和jquery等待加载的区别
1.区别 window.onload是等待页面所有文档,图片等元素都加载完成再进行操作,是javascript原生语法. jquery是等待页面文档加载完成时,就进行操作. $(function(){ ...