linux C- gdb调试、Makefile.doc_第1页
linux C- gdb调试、Makefile.doc_第2页
linux C- gdb调试、Makefile.doc_第3页
linux C- gdb调试、Makefile.doc_第4页
linux C- gdb调试、Makefile.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

linux C gdb调试、Makefilegcc可以编译c, c+, object-c, java等众多的语言程序 g+则是专注于和C+。gdb调试GDB 调试器是一个功能强大的工具,它可以做很多的调试工作,如断点,单步跟踪等。 相关命令:下面演示两个例子,追踪快速排序的过程和查看优化后的gcd()算法(方法来自编程之美)观察快速排序:打印数组,查看快速排序中各个元素的位置变化源码:#include #include using namespace std;int partion(int a,int start,int end) int i=start,j=end; int temp=astart; while(ij) while(i=temp) j-; ai=aj; / i are more while(ij & ai=temp) i+; aj=ai; / j are more ai=temp; / at end , i=j return i;void Qsort(int a,int start,int end) if(startend) int d=partion(a,start,end); Qsort(a,start,d); Qsort(a,d+1,end); int main() int a10=3,2,7,5,1,0,9,6,4,11; Qsort(a,0,9); for(int i=0;i10;i+) printf(%d ,ai); printf(n); return 0;指令:edemonlinux:$ g+ -g -o exe main.cppedemonlinux:$ gdb exe(gdb) break 17Breakpoint 1 at 0x4006f4: file main.cpp, line 17.(gdb) runBreakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=9) at main.cpp:1717 if(startend)(gdb) p *a10$2 = 3, 2, 7, 5, 1, 0, 9, 6, 4, 11(gdb) continueBreakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=3) at main.cpp:1717 if(startend)(gdb) p *a10$3 = 0, 2, 1, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=0) at main.cpp:1717 if(startend)(gdb) p *a10$4 = 0, 2, 1, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=3) at main.cpp:1717 if(startend)(gdb) p *a10$5 = 0, 2, 1, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=2) at main.cpp:1717 if(startend)(gdb) p *a10$6 = 0, 1, 2, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=1) at main.cpp:1717 if(startend)(gdb) p *a10$7 = 0, 1, 2, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=2, end=2) at main.cpp:1717 if(startend)(gdb) p *a10$8 = 0, 1, 2, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=3, end=3) at main.cpp:1717 if(startend)(gdb) p *a10$9 = 0, 1, 2, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=4, end=9) at main.cpp:1717 if(startend)(gdb) p *a10$10 = 0, 1, 2, 3, 5, 7, 9, 6, 4, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=4, end=5) at main.cpp:1717 if(startend)(gdb) p *a10$11 = 0, 1, 2, 3, 4, 5, 9, 6, 7, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=4, end=4) at main.cpp:1717 if(startend)(gdb) p *a10$12 = 0, 1, 2, 3, 4, 5, 9, 6, 7, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=5, end=5) at main.cpp:1717 if(startend)(gdb) p *a10$13 = 0, 1, 2, 3, 4, 5, 9, 6, 7, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=6, end=9) at main.cpp:1717 if(startend)(gdb) p *a10$14 = 0, 1, 2, 3, 4, 5, 9, 6, 7, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=6, end=8) at main.cpp:1717 if(startend)(gdb) p *a10$15 = 0, 1, 2, 3, 4, 5, 7, 6, 9, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=6, end=7) at main.cpp:1717 if(startend)(gdb) p *a10$16 = 0, 1, 2, 3, 4, 5, 6, 7, 9, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=6, end=6) at main.cpp:1717 if(startend)(gdb) p *a10$17 = 0, 1, 2, 3, 4, 5, 6, 7, 9, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=7, end=7) at main.cpp:1717 if(startend)(gdb) p *a10$18 = 0, 1, 2, 3, 4, 5, 6, 7, 9, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=8, end=8) at main.cpp:1717 if(startend)(gdb) p *a10$19 = 0, 1, 2, 3, 4, 5, 6, 7, 9, 11(gdb) continueContinuing.Breakpoint 1, Qsort (a=0x7fffffffdda0, start=9, end=9) at main.cpp:1717 if(startend)(gdb) p *a10$20 = 0, 1, 2, 3, 4, 5, 6, 7, 9, 11(gdb) continueContinuing.0 1 2 3 4 5 6 7 9 11 Inferior 1 (process 7467) exited normally计算24, 26的最大公约数:使用gdb查看递归情况,a和是怎样变化的。 源码:#include #include #include using namespace std;typedef long long LL;const LL N=1e5+10;LL odd(LL a) return a&(1LL);LL gcd(LL a,LL b) if(ab) swap(a,b); if(a=0) return b; if(odd(a) & odd(b) return gcd(b-a,a); if(!odd(a) & odd(b) return gcd(a1,b); if(odd(a) & !odd(b) return gcd(a,b1); if(!odd(a) & !odd(b) return gcd(a1,b1)1;int main() coutgcd(24,26)b) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=12, b=13) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=6, b=13) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=3, b=13) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=10, b=3) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=3, b=5) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=2, b=3) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=1, b=3) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=2, b=1) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=1, b=1) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.Breakpoint 1, gcd (a=0, b=1) at main.cpp:1010 if(ab) swap(a,b);(gdb) continueContinuing.makefileLinux中的make工具提供了一种管理工程的功能, 编写Makefile文件,通过make命令将多个文件编译为可执行文件 例如: main.c t1.c /output “hello world” t2.c /output “Im learning linux c” action.haction.h:#ifdef _ACTION_H_#define _ACTION_H_extern void action1();extern void action2();#endif main.c#include action.hint main() action1(); action2(); return 0;t1.c:#include void action1() printf(hello worldn);t2.c:#include void action2() printf(Im learning linux Cn);Makefile:exe:action1.o action2.o main.o action.h gcc -o exe action1.o action2.o main.o gcc -c -o action1.o t1.caction1.o:action.h t1.caction2.o:action.h t2.c gcc -c -o action2.o t2.cmain.o:ion.h main.cclean: rm -f exe action1.o action2.o main.oedemonlinux:/media/edemon/document/program/prodoc/contest/newpra/makeFile$ makegcc -c -o action2.o t2.ccc -c -o main.o main.cmain.c: In function main:main.c:3:5: warning: implicit declaration of func

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论