linux C- gdb调试、Makefile.doc

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
linux C- gdb调试、Makefile

linux C- gdb调试、Makefile gcc可以编译c, c++, object-c, java等众多的语言程序 g++则是专注于C和C++。 gdb调试 GDB 调试器是一个功能强大的工具,它可以做很多的调试工作,如断点,单步跟踪等。 相关命令: 下面演示两个例子,追踪快速排序的过程和查看优化后的gcd()算法(方法来自编程之美) 观察快速排序: 打印数组,查看快速排序中各个元素的位置变化 源码: #include stdio.h #include algorithm using namespace std; int partion(int a[],int start,int end){ int i=start,j=end; int temp=a[start]; while(ij){ while(ij a[j]=temp) j--; a[i]=a[j]; // i are more while(ij a[i]=temp) i++; a[j]=a[i]; // j are more } a[i]=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 a[10]={3,2,7,5,1,0,9,6,4,11}; Qsort(a,0,9); for(int i=0;i10;i++) printf(%d ,a[i]); printf(\n); return 0; } 指令: edemon@linux:~$ g++ -g -o exe main.cpp edemon@linux:~$ gdb exe (gdb) break 17 Breakpoint 1 at 0x4006f4: file main.cpp, line 17. (gdb) run Breakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=9) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $2 = {3, 2, 7, 5, 1, 0, 9, 6, 4, 11} (gdb) continue Breakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=3) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $3 = {0, 2, 1, 3, 5, 7, 9, 6, 4, 11} (gdb) continue Continuing. Breakpoint 1, Qsort (a=0x7fffffffdda0, start=0, end=0) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $4 = {0, 2, 1, 3, 5, 7, 9, 6, 4, 11} (gdb) continue Continuing. Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=3) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $5 = {0, 2, 1, 3, 5, 7, 9, 6, 4, 11} (gdb) continue Continuing. Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=2) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $6 = {0, 1, 2, 3, 5, 7, 9, 6, 4, 11} (gdb) continue Continuing. Breakpoint 1, Qsort (a=0x7fffffffdda0, start=1, end=1) at main.cpp:17 17 if(startend){ (gdb) p *a@10 $7 = {0, 1, 2, 3, 5, 7, 9, 6, 4, 11} (gdb) continue Conti

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档