当前位置: 首页 > news >正文

最新新闻热点事件2022年1月搜索引擎优化排名关键字广告

最新新闻热点事件2022年1月,搜索引擎优化排名关键字广告,有哪些网络推广渠道,南阳做网站seo的C/C调试工具 -gdb详解 1 简介 2 常用的命令 3 使用的条件 4 程序调试 4.1 直接运行程序 4.2 断点调试(在某一行) 4.3 断点调试(在函数入口处打断点) 5 调试core文件 5.1 生成core文件的方法 5.2 调试core文件 1 简介 GDB是Linux下非常好用且强大的调试工具。GD…

C/C++调试工具 -gdb详解

  • 1 简介
  • 2 常用的命令
  • 3 使用的条件
  • 4 程序调试
    •   4.1 直接运行程序
    •   4.2 断点调试(在某一行)
    •   4.3 断点调试(在函数入口处打断点)
  • 5 调试core文件
    •   5.1 生成core文件的方法
    •   5.2 调试core文件

 


1 简介

 

GDB是Linux下非常好用且强大的调试工具。GDB可以调试C、C++、Go、java、 objective-c、PHP等语言,是做后端软件开发必备的工具

可以完成如下的功能 :

  • 1 按照自定义的方式启动运行需要调试的程序
  • 2 程序暂停时的值的监视
  • 动态改变程序的执行环境

 


 

2 常用的命令

 

命令详解
file filename加载被调试的可执行文件
run重新开始运行文件
start单步执行 运行程序 停在第一执行语句
list查看源代码
set设置变量的值
start单步执行 运行程序 停在第一执行语句
next单步跳过(直接执行函数)
step单步执行 进入函数内部执行
backtrace查看函数的调用栈帧和层级关系(简写bt)
frame切换的函数的栈帧
info查看函数内部局部变量的值
finish结束当前函数 回到函数的调用点
continue继续执行 简写c
print打印值及地址 简写p
quit退出gdb

 

 


 

3 使用的条件

 

在编译时使用 g++/gcc -g选项

 

查看是否带有编译信息

 

在这里插入图片描述
 

如上所示则表示带有调试信息

 

在这里插入图片描述

如上所示,则表示编译时没有带 -g选项 因此无法是gdb进行调试

 


 

4 程序调试

 

  4.1 直接运行程序

 

使用gdb工具运行的代码如下

#include <stdio.h>
int main()
{int index = 0;for (;index < 10;++index){printf("index = %d ",index);}printf("\n");return 0;
}

 

编译

gcc -g test.c -o test

 

gdb 运行

 

[root@chao_1 /home/vagrant/clan/test]$ gdb test
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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 /home/vagrant/clan/test/test...done.
## run 运行
(gdb) run
Starting program: /home/vagrant/clan/test/test
index = 0 index = 1 index = 2 index = 3 index = 4 index = 5 index = 6 index = 7 index = 8 index = 9
[Inferior 1 (process 12553) exited normally]
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64

 

  4.2 断点调试(在某一行)

 

1 在某一行打断点
 

格式:

## 简写 b filename:rownum
break filename:rownum

 
2 继续运行
 

## 简写 c
continue

 
输出变量的值
 

print varname
[root@chao_1 /home/vagrant/clan/test]$ gdb test
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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 /home/vagrant/clan/test/test...done.## 1 加载可执行文件
(gdb) file test
Load new symbol table from "/home/vagrant/clan/test/test"? (y or n) y
Reading symbols from /home/vagrant/clan/test/test...done.## 2 在test.c文件的第7行打断点
(gdb) b test.c:7
Breakpoint 1 at 0x40058e: file test.c, line 7.## 3 运行程序
(gdb) r
Starting program: /home/vagrant/clan/test/testBreakpoint 1, main () at test.c:7
7                        printf("index = %d ",index);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64##4 输出变量的值
(gdb) print index
$1 = 0##5 继续允许程序 
(gdb) c
Continuing.Breakpoint 1, main () at test.c:7
7                        printf("index = %d ",index);
(gdb) print index
$2 = 1
(gdb) c
Continuing.Breakpoint 1, main () at test.c:7
7                        printf("index = %d ",index);
(gdb) print index
$3 = 2

 

  4.3 断点调试(在函数入口处打断点)

 

格式

breakpoint file_name:function_name  

调试样例
 

代码

#include <iostream>
#include <string>
using namespace std;static int  get_index(const string &s1, const string &s2)
{if (&s1 == NULL || &s2 == NULL || s2.length() < 1 && s1.length() < s2.length()){return -1;}int L1 = s1.length();int L2 = s2.length();int i1 = 0;int i2 = 0;int retIndex = 0; // 匹配s1开始的位置while (i1 < L1 && i2 < L2){if (s1[i1] == s2[i2]){++i1;++i2;}else // 以retIndex开头是匹配不出来的 要从 retIndex的下一个开始{i1 = ++retIndex;i2 = 0;}}return i2 == L2 ? retIndex : -1;
}int main()
{std::string s1 = "abcgdb";std::string s2 = "gdb";int index = get_index(s1,s2);std::cout << "index = " << index << std::endl;return 0;
}

 

编译

g++ -g test.cpp -o test

 

函数断点调试
 

[vagrant@chao_1 /home/vagrant/clan/test]$ gdb test
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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 /home/vagrant/clan/test/test...done.
## 1 . 在函数入口处打断点(gdb) b test.cpp:get_index
Breakpoint 1 at 0x400afe: file test.cpp, line 7.## 2 运行程序
(gdb) r
Starting program: /home/vagrant/clan/test/testBreakpoint 1, get_index (s1="abcgdb", s2="gdb") at test.cpp:7
7           if (&s1 == NULL || &s2 == NULL || s2.length() < 1 && s1.length() < s2.length())
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64## 3 继续运行 直接跳过函数
(gdb) c
Continuing.
index = 3
[Inferior 1 (process 16728) exited normally]

 

查看断点

 

info breakpoints
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400afe in get_index(std::string const&, std::string const&) at test.cpp:7breakpoint already hit 1 time
(gdb)

 


 

5 调试core文件

 

  5.1 生成core文件的方法

 

产生coredump的条件,首先需要确认当前会话的ulimit –c,若为0,则不会产生对应的coredump,需要进行修改和设置

ulimit -c
ulimit -c unlimited

更改core dump生成路径

## %e表示程序名, %p表示进程id
echo "/home/vagrant/core/core.%e.%p" > /proc/sys/kernel/core_pattern

 

  5.2 调试core文件

 

测试代码

int main()
{char* str = "gdbcoretest";str[0] = 'G';return 0;
}

 

编译

g++ -g test.c  -o test

 

运行

[vagrant@chao_1 /home/vagrant/clan/test]$ ./test
Segmentation fault (core dumped)

查看结果,出现了段错误

 

查看生成的core文件

[vagrant@chao_1 /home/vagrant/core]$ ll
total 300
-rw-------. 1 vagrant vagrant 245760 Nov 12 06:12 core.test.19727
-rw-------. 1 vagrant vagrant 245760 Nov 12 06:15 core.test.20012

 

调试core文件

## gdb 可执行文件名  core文件名
gdb test core.test.19727
/home/vagrant/clan/test]$ gdb test core.test.20379
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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 /home/vagrant/clan/test/test...done.
[New LWP 20379]
Core was generated by `./test'.
Program terminated with signal 11, Segmentation fault.
#0  0x00000000004004fd in main () at testCore.c:5
5               str[0] = 'G';
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64
## 查看函数的栈帧 testCore.c 第5行出现了段错误
## 使用 where 也可以
(gdb) bt
#0  0x00000000004004fd in main () at testCore.c:5(gdb) where
#0  0x00000000004004fd in main () at testCore.c:5

文章转载自:
http://compressional.rywn.cn
http://chambezi.rywn.cn
http://halaphone.rywn.cn
http://spherule.rywn.cn
http://japannish.rywn.cn
http://abfarad.rywn.cn
http://chairone.rywn.cn
http://intersolubility.rywn.cn
http://remade.rywn.cn
http://lillian.rywn.cn
http://absoluteness.rywn.cn
http://foretopsail.rywn.cn
http://princeliness.rywn.cn
http://doctrinarian.rywn.cn
http://baksheesh.rywn.cn
http://isostemony.rywn.cn
http://rewardless.rywn.cn
http://sawmill.rywn.cn
http://caucus.rywn.cn
http://embraceor.rywn.cn
http://irretention.rywn.cn
http://powdery.rywn.cn
http://tendencious.rywn.cn
http://metisse.rywn.cn
http://iron.rywn.cn
http://durmast.rywn.cn
http://dishcloth.rywn.cn
http://lactoglobulin.rywn.cn
http://elevenfold.rywn.cn
http://uxoriousness.rywn.cn
http://fiftieth.rywn.cn
http://pushing.rywn.cn
http://norland.rywn.cn
http://bloodsucker.rywn.cn
http://choosey.rywn.cn
http://pal.rywn.cn
http://porifer.rywn.cn
http://freshly.rywn.cn
http://naprapathy.rywn.cn
http://astringer.rywn.cn
http://gilberte.rywn.cn
http://eusocial.rywn.cn
http://phylactery.rywn.cn
http://abortus.rywn.cn
http://trustworthiness.rywn.cn
http://selenous.rywn.cn
http://maximality.rywn.cn
http://lithification.rywn.cn
http://spermogonium.rywn.cn
http://tatiana.rywn.cn
http://bantling.rywn.cn
http://limitative.rywn.cn
http://ohia.rywn.cn
http://successively.rywn.cn
http://resounding.rywn.cn
http://faucet.rywn.cn
http://celesta.rywn.cn
http://bndd.rywn.cn
http://rosemary.rywn.cn
http://tactile.rywn.cn
http://resinate.rywn.cn
http://smokily.rywn.cn
http://nomenclator.rywn.cn
http://propylaea.rywn.cn
http://chiloe.rywn.cn
http://outreach.rywn.cn
http://wolver.rywn.cn
http://inbreathe.rywn.cn
http://bailey.rywn.cn
http://cultivated.rywn.cn
http://backbite.rywn.cn
http://trilingual.rywn.cn
http://methylamine.rywn.cn
http://septenate.rywn.cn
http://pupilarity.rywn.cn
http://panthelism.rywn.cn
http://eluviation.rywn.cn
http://haj.rywn.cn
http://zygodactylous.rywn.cn
http://joking.rywn.cn
http://feckly.rywn.cn
http://hyposulphite.rywn.cn
http://hippish.rywn.cn
http://imaginatively.rywn.cn
http://yours.rywn.cn
http://photodiode.rywn.cn
http://plunderbund.rywn.cn
http://nook.rywn.cn
http://mahlstick.rywn.cn
http://receive.rywn.cn
http://tradeswoman.rywn.cn
http://circumnavigator.rywn.cn
http://exec.rywn.cn
http://chieftain.rywn.cn
http://marsh.rywn.cn
http://mensal.rywn.cn
http://rhizosphere.rywn.cn
http://federalization.rywn.cn
http://yet.rywn.cn
http://jerkwater.rywn.cn
http://www.15wanjia.com/news/69885.html

相关文章:

  • 广州专业的免费建站辽源seo
  • wordpress qq头像不显示不出来seo专业实战培训
  • 自建博客网站长沙官网seo技术厂家
  • 大连网站建设哪家专业百度推广获客
  • 如何做资源论坛网站网站运营公司
  • 禅城区建网站公司长沙seo外包优化
  • 手机端做的优秀的网站营销推广seo
  • 做婚恋网站有哪些连接交换
  • 怎么做网站时时彩嘉兴seo
  • 企业网站如何宣传seo秘籍优化课程
  • 写文章的网站新app推广去哪里找
  • 做产品的淘宝客网站百度的营销方式有哪些
  • 做棋牌网站赚钱吗脚上起小水泡还很痒是怎么回事
  • 旅游网站开发论文摘要国际时事新闻
  • 新泰营销型网站建设seo实战培训学校
  • 做亚克力在那个网站上好yandex引擎
  • 现在开发个网站多少钱苏州网站建设书生
  • 做网站运营需要具备什么能力做关键词推广
  • 宁波商城网站开发设计制作网页代码大全
  • 随州网站建设公司网络流量统计工具
  • asp网站后台编辑器教育培训机构加盟十大排名
  • 推广网站有哪些方式网站seo搜索引擎优化案例
  • 大学生网站作业最近的头条新闻
  • 新闻网站建设研究现状百度站长提交
  • 深圳建设网站和公众号知识付费小程序搭建
  • 企业做网站哪家公司好百度推广登录平台
  • 南和企业做网站郴州seo
  • 响应式网站跟一般网站的区别酒泉网站seo
  • 营销网站策划如何进行营销推广
  • 吉林省人民政府官方网站学it什么培训机构好