gdb调试(一)
对于gdb是什么,这里就不多说了,只要是程序员一般都听说过,像java开发会用到集成开发工具eclipse,里面调试起来非常方便,全是可视化的,但是如果在linux下编写的c程序,用可视化的调试就没这么方便了,这时就得用gdb了,当程序比较大时,在开发肯定会出现很多bug,对于怎么调试这些bug就显得非常重要了,所以下面来详细的学习这一调试工具,进入正题:





















#include <stdio.h>
#include <stdlib.h> long func(int n); int main(int argc, char *argv[])
{
printf("Entering main ...\n");
int i;
for (i=0; i<argc; ++i)
{
printf("%s ", argv[i]);
}
printf("\n");//将传过来的参数打印出来
long result = ;
for (i=; i<=; ++i)
{
result += i;
}
printf("result[1-100] = %ld\n", result);
printf("result[1-10] = %ld\n", func()); printf("Exiting main ...\n");
return ;
} long func(int n)
{
long sum = ;
int i;
for (i=; i<=n; ++i)
{
sum += i;
} return sum;
}
这时编译并运行看下效果,这次不用gcc单独来敲了,而直接用make,因为已经编写好了Makefile:
#include <stdio.h>
#include "search.h" int main(int argc, char *argv[])
{
printf("Entering main ...\n");
int i;
for (i=; i<argc; i++)
{
printf("%s ",argv[i]);
}
printf("\n");
int a[] = {, , , , , , , , , };
int key = ;
int pos;
int count = ; pos = ;
while ((pos=seq_search(a, pos, 10, key)) != -)
{
count++;
pos++;
} printf("%d occurs %d times in the list\n", key, count);
printf("Exiting main ...\n");
return ;
}
#ifndef _SEARCH_H_
#define _SERACH_H_ int seq_search(int list[], int start, int n, int key); #endif // _SERACH_H_
#include "search.h" int seq_search(int list[], int start, int n, int key)
{
int i;
for (i=start; i<n; ++i)
{
if (list[i] == key)
return i;
} return -;
}
其中main.c中的seq_search函数的实现是在search.c文件中。














































gdb调试(一)的更多相关文章
- GDB调试命令小结
1.启动调试 前置条件:编译生成执行码时带上 -g,如果使用Makefile,通过给CFLAGS指定-g选项,否则调试时没有符号信息.gdb program //最常用的用gdb启动程序,开始调试的方 ...
- GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 分析过程 这是我的C源文件:click here 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb ...
- gdb调试器的使用
想要使用gdb调试程序的话,首先需要gcc -g main.c -o test 然后运行gdb test对程序进行调试 l (小写的l,是list的首字母),用以列出程序 回车 是运行上一个命令 ...
- 20145212——GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 测试代码 #include <stdio.h> short val = 1; int vv = 2; int g(int xxx) { return xxx + ...
- gdb调试PHP扩展错误
有时候,使用PHP的第三方扩展之后,可能会发生一些错误,这个时候,可能就需要更底层的方式追踪调试程序发生错误的地方和原因,熟悉linux下C编程的肯定不陌生gdb 首先,使用ulimit -c命令,查 ...
- gdb调试汇编堆栈过程的学习
gdb调试汇编堆栈过程的学习 以下为C源文件 使用gcc - g code.c -o code -m32指令在64位的机器上产生32位汇编,然后使用gdb example指令进入gdb调试器: 进入之 ...
- gdb调试
·代码(实验楼中的代码,改了部分数值)命名为test.c int g(int x) { return x + 7; } int f(int x) { return g(x); } int main(v ...
- 20145223《信息安全系统设计基础》 GDB调试汇编堆栈过程分析
20145223<信息安全系统设计基础> GDB调试汇编堆栈过程分析 分析的c语言源码 生成汇编代码--命令:gcc -g example.c -o example -m32 进入gdb调 ...
- GDB调试汇编堆栈
GDB调试汇编堆栈 分析过程 C语言源代码 int g(int x) { return x+6; } int f(int x) { return g(x+1); } int main(void) { ...
- 赵文豪 GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb example指令进入gdb调试器: 使用gdb调 ...
随机推荐
- [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- [LeetCode] 460. LFU Cache 最近最不常用页面置换缓存器
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the f ...
- 通过ip远程控制电脑
现在,很多人都用了不止一台电脑,而同时操作两台电脑是一件比较麻烦的事情,所以,如果能够使用一台电脑的鼠标键盘显示器,去远程控制另一台电脑,那就方便多了. 远程计算机设置 1.先确保本地计算机和远程计算 ...
- nginx下只能通过域名,禁止使用ip访问
今天来了一个需求,ip访问返回500,域名访问正常,只需在nginx.conf中添加 server { listen 80 default; #default 必须加的 return 500; } 也 ...
- nrm -- npm镜像源管理
nrm nrm(npm registry manager )是npm的镜像源管理工具,有时候国外资源太慢,使用这个就可以快速地在 npm 源间切换 安装nrm 在命令行执行命令,npm install ...
- python面试题300道
本文截取了一些面试题及解决方案: Python 基础 文件操作 模块与包 数据类型 企业面试题 Python 高级 设计模式 系统编程 Python 基础 什么是 Python?根据Python 创建 ...
- Linux交换分区内存优化
swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,swappiness=100的时候表示积极的使用 ...
- PHP_MySQL高并发加锁事务处理
1.背景: 现在有这样的需求,插入数据时,判断test表有无username为‘mraz’的数据,无则插入,有则提示“已插入”,目的就是想只插入一条username为‘mraz’的记录. 2.一般程序 ...
- dockfile构建自己的tomcat
touch Dockerfile 在Dockerfile中输入以下内容 FROM centosMAINTAINER Irish<3395327965@qq.com>#把宿主机当前上下文的 ...
- [转帖]DCEP:中国自己的数字货币
DCEP:中国自己的数字货币 https://cloud.tencent.com/developer/news/435883 前面我们讨论了Libra的革命性和局限性,接下来我想跟你聊一件重要的事,那 ...