1. 说明

    • gdb断点

      • 有三种: 模糊行级匹配,精确行级匹配,指令级匹配.
    • 模糊行级匹配

      • 即断点是在某行,但是给的表达式可以匹配多个行.
      • 即设置了多个断点.
    • 精确行级匹配

      • 同上,去除上面的二义性.
    • 指令级匹配

      • 断点精确到具体的某个指令,虽然最终也会落在某行.
  2. 模糊行级匹配

    • 代码

      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设置断点添加了两个断点.
  3. 精确行级匹配

    • 说明

      • 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跳转位置.
  4. 指令级断点

    • 说明

      • 通过反汇编获取虚拟地址,设置对应位置的断点.
      • 注意指令前面加 * .
    • 案例

      [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   %rbp0x000000000040050e <+1>:     mov    %rsp,%rbp0x0000000000400511 <+4>:     mov    %edi,-0x4(%rbp)0x0000000000400514 <+7>:     mov    0x200b16(%rip),%eax        # 0x601030 <a>0x000000000040051a <+13>:    add    $0x2,%eax0x000000000040051d <+16>:    mov    %eax,0x200b0d(%rip)        # 0x601030 <a>0x0000000000400523 <+22>:    pop    %rbp0x0000000000400524 <+23>:    retq
      End of assembler dump.
      (gdb) break *0x000000000040050e
      Breakpoint 1 at 0x40050e: file test.cpp, line 2.
  5. 总结

    • 转化为行显示断点位置.
    • 多种指定方式,模糊到精确,简单到复杂.

gdb给指定位置设置断点相关推荐

  1. gdb的break命令设置断点

    一 指定在源代码的某行处设置断点 1 源代码 #include <iostream> using namespace std; void zww(int age) {int a, b, c ...

  2. gdb设置断点出现Cannot access memory at address的错误

    文章目录 1.0 问题描述 1.1 问题复现 2.0 2.1 静态链接库 2.2 动态链接库 2.3 PIC 1.0 问题描述 今天在给一个可执行c程序的entry point address设置断点 ...

  3. Fiddler设置断点

    Fiddler设置断点 一.全局代理 Fiddler全局断点:点击rules-> automatic breakpoint ->before requests,Before Request ...

  4. Linux+gcc设置断点,gcc/g++常用编译选项和gdb常用调试命令

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? gcc/g++编译器是我们写编译C/C++程序时离不开的编译工具,而gdb又是调试C/C++程序的利器,这一篇文章我们记 ...

  5. gdb使用watch命令设置数据断点

    文章目录 前言 数据变化断点 编写测试程序代码 加数据断点并调试 总结 前言 "数据断点"这个说法是沿用在Visual Studio中学到的设置断点的方法,在gdb中一般被叫做&q ...

  6. gdb 笔记(03)— 某一行设置断点、为函数(单个唯一函数、多个同名函数、使用正则)设置断点、设置条件断点、设置临时断点

    断点 breakpoint,即为了调试的需要,在程序中设置一些特殊标志,代码执行到这些具有特殊标志的位置时会暂停.一旦程序暂停,我们就可以查看或者修改程序运行的一些信息,比如内存信息.堆栈信息等,并且 ...

  7. 获取光标位置及动态设置光标到指定位置

    问题场景:页面有一个字段框(可以理解为一个div中有很多label),一个input框,进入页面,input框自动获取焦点,点击每一个label会把label的内容进行处理,比如加个括号()表示是个函 ...

  8. 【Android 逆向】代码调试器开发 ( 代码调试器功能简介 | 设置断点 | 读写内存 | 读写寄存器 | 恢复运行 | Attach 进程 )

    文章目录 一.代码调试器功能简介 二.Attach 进程 一.代码调试器功能简介 代码调试器功能 : 设置断点 : 无论什么类型的调试器 , 都必须可以设置断点 , 运行到断点处 , 挂起被调试进程 ...

  9. 通过 Visual Studio 对 SQL Server 中的存储过程设置断点并进入存储过程对其进行调试...

    通过 Visual Studio 的 Professional 和 Team System 版本,我们可以对 SQL Server 中的存储过程设置断点并进入存储过程对其进行调试,这样我们可以象调试应 ...

最新文章

  1. 简单介绍MySQL开启事务的两种方式
  2. linux红帽网页中文乱码解决,【linux学习笔记】安装redhat时中文显示乱码(小方框)解决方法...
  3. false sharing
  4. 用 SpringBoot,亲自打造一个在线题库系统
  5. Linux 基础知识(九)
  6. Struts2中的OGNL表达式
  7. mysql定义条件和处理_mysql sql存储过程条件定义与处理
  8. JUC:ConcurrentSkipListMap/ConcurrentSkipListSet(并发容器)
  9. 关于Content-Type: multipart/form-data的支持
  10. 树莓派之OLED12864视频播放—BadApple
  11. 微信小程序期末大作业,飞机大战
  12. bootstrap table背景_bootstrap table给行怎么加背景色
  13. 原生js实现删除节点操作
  14. [基础服务] 常用邮箱服务地址
  15. 数据分析实例-获取某宝评论数据做词云图可视化
  16. [推荐](穆穆推荐)如果你现在不成功,请看看你是不是选错了老板
  17. python 高斯约当消元法求逆矩阵
  18. adb shell提示:device unauthorized
  19. php artisan命令表,php artisan 命令列表
  20. 回顾知识付费近几年的发展历程,浅谈知识付费项目的发展空间

热门文章

  1. 基于深度学习的道路交通标志
  2. 2021年7月更新最新版去水印小程序
  3. 杰理主浪涌测试仪2【篇】
  4. JNI学习笔记:JNI原理
  5. office转pdf实现office在线预览(aspose)
  6. 【面试题】面试官:说说你对MySQL的了解
  7. 读《哈佛大学的 500 个数独游戏》
  8. FtpURLConnecton 可以下载ftp地址格式的图片
  9. linux中gnome的使用教程,如何定制你的Linux桌面:Gnome 3
  10. 使用C2P工业云获取门店每日销售统计