标签:设置 action stop ecif other linu gcc exp eve
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 -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 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 触发断点或者使用 Ctrl + C 命令中断下来后,想让程序继续运行,只要输入 continue 命令即可。
添加断点。
(gdb) break function_name # 在函数入口加断点
(gdb) break line_No # 在当前文件行号为 line_no 加断点
(gdb) break file_name:line_no # 在文件名为 file_name 文件,第 line_no 行加断点
### backtrace (bt)
查看当前调用堆栈。
切换堆栈。
(gdb) f 2 #切换到编号为 2 的堆栈(第三层)
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 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 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 + (加号)”和“list - (减号)”。
可以查看、计算和修改变量的值
(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 字段的值
打印变量的类型
查看断点们的状态,可以显示断点被触发的次数。
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.
查看当前函数被执行的,实参的值。
next over,运行下一行,遇到函数调用不进入。
step into,运行下一行,遇到函数调用时会进入。
结束当前函数,返回上层。
结束当前函数,返回上层。同时可以指定该函数的返回值。
(gdb) return 99 # 指定当前函数返回值 99
指定程序运行到某一行停下来。
让程序执行流跳转到指定位置执行。
可以执行一些我们想要执行的代码,而这些代码在正常的逻辑下可能并不会执行
反汇编
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.
监视一个变量或者一段内存,当这个变量或者该内存处的值发生变化时,GDB 就会中断下来。被监视的某个变量或者某个内存地址会产生一个 watch point(观察点)。
当设置的观察点是一个局部变量时,局部变量无效后,观察点也会失效。
监视变量或者内存地址,每次程序中断下来都会自动输出这些变量或内存的值。
Continue program with the specified signal.
signal [SIGNAL]
The SIGNAL argument is processed the same as the handle command.
SIGNAL: SIGCHLD, SIGPIPE, SIGINT, SIGTERM......
Specify how to handle signals.
handle [SIGNAL]
for example
handle SIGINT nostop print
告诉 GDB 在接收到 SIGINT 时不要停止,并把该信号传递给调试目标程序 。
条件断点。
break 11 if i==5000 # 意为当 i = 5000 时,程序中断在第 11 行
添加条件断点还有一个方法就是先添加一个普通断点,然后使用“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 mode for locking scheduler during execution.
Set debugger response to a program call of fork or vfork.
A fork or vfork creates a new process. follow-fork-mode can be:
The unfollowed process will continue to run.
By default, the debugger will follow the parent process.
Set limit on string chars or array elements to print.
"set print elements unlimited" causes there to be no limit.
"set print element 0" 完整地显示变量的整个字符串。
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
[1] 《Linux GDB 调试指南》. 范蠡. https://gitbook.cn/gitchat/column/5c0e149eedba1b683458fd5f
标签:设置 action stop ecif other linu gcc exp eve
原文地址:https://www.cnblogs.com/fengyubo/p/10321738.html