-
说明
-
模糊行级匹配
-
代码
int a = 0; void show(int) { a += 2; } void show() { a ++; } int main() { show(1); show(2); return 0; }
-
编译调试
[root@localhost temp]# g++ test.cpp -g [root@localhost temp]# gdb ./a.out GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu".a For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /root/cfile/temp/a.out...done. (gdb) break show Breakpoint 1 at 0x400514: show. (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x0000000000400514 in show(int) at test.cpp:3 1.2 y 0x0000000000400529 in show() at test.cpp:6 (gdb)
- 可以看到
break show
设置断点添加了两个断点.
- 可以看到
-
-
精确行级匹配
-
说明
gdb
需要升级才支持.与gcc4.8.5
配对的不支持.
-
升级
- 下载
wget https://repo.huaweicloud.com/centos/7/sclo/x86_64/rh/Packages/d/devtoolset-7-gdb-8.0-17.el7.x86_64.rpm
- 配置
yum install ./devtoolset-7-gdb-8.0-17.el7.x86_64.rpm
- 安装
yum install devtoolset-7-gdb.x86_64 -y
- 下载
-
指定
[root@localhost temp]# /opt/rh/devtoolset-7/root/usr/bin/gdb a.out GNU gdb (GDB) Red Hat Enterprise Linux 8.0.1-36.el7 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...done. (gdb) break -source test.cpp -function show -line 3 Breakpoint 1 at 0x400514: file test.cpp, line 3. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x0000000000400514 in show(int) at test.cpp:3 (gdb)
-
说明
- 支持指定
source
源文件,-function
函数,-line
行号,-label
跳转位置.
- 支持指定
-
-
指令级断点
-
说明
-
案例
[root@localhost temp]# gdb ./a.out GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /root/cfile/temp/a.out...done. (gdb) disassemble show Dump of assembler code for function show(int): 0x000000000040050d <+0>: push %rbp 0x000000000040050e <+1>: mov %rsp,%rbp 0x0000000000400511 <+4>: mov %edi,-0x4(%rbp) 0x0000000000400514 <+7>: mov 0x200b16(%rip),%eax # 0x601030 <a> 0x000000000040051a <+13>: add $0x2,%eax 0x000000000040051d <+16>: mov %eax,0x200b0d(%rip) # 0x601030 <a> 0x0000000000400523 <+22>: pop %rbp 0x0000000000400524 <+23>: retq End of assembler dump. (gdb) break *0x000000000040050e Breakpoint 1 at 0x40050e: file test.cpp, line 2.
-
-
总结
- 转化为行显示断点位置.
- 多种指定方式,模糊到精确,简单到复杂.
gdb给指定位置设置断点
最新推荐文章于 2024-05-13 11:10:45 发布