关于使用gdb的一些建议
2011-10-01 19:49
260 查看
参考:《Linux® Debugging and Performance Tuning: Tips and Techniques》 chapter 3
1. 测试程序
2. build with debug info increase the executable size.
/home/a/j/nomad2:ls -lrt a.out
-rwxr-xr-x 1 nomad2 member 11341 Oct 1 19:34 a.out
/home/a/j/nomad2:strip --strip-debug a.out
/home/a/j/nomad2:ls -lrt a.out
-rwxr-xr-x 1 nomad2 member 7522 Oct 1 19:42 a.out
3. 关于调试:
1). When debugging, it is often a good practice to stop program execution at the bottom of a function so that a print or multiple displays can be done to see the current values stored in the data the function has altered.
list <func name>
break <line of }>
2). When gdb is used, the print command must
be invoked to display the variable's value. The user can see much more information at one time.
1. 测试程序
/home/a/j/nomad2:cat gdb_sample2.c #include <stdio.h> #include <pthread.h> #include <unistd.h> void* Thread_function1(void * arg) { unsigned int i=1; while(i < 11) { printf("Child Thread Iteration %d\n",i); i++; if(i%2) sleep(2); else sleep(1); } return arg; } void* Thread_function2(void * arg) { unsigned int i=1; while(i < 11) { printf("Child Thread 2 Iteration %d\n",i); i++; if(i%2) sleep(2); else sleep(1); } return arg; } int main (int argc, char *argv[]) { pthread_t thread; pthread_t thread2; if(pthread_create(&thread,NULL,Thread_function1,NULL)) { return(1); } if(pthread_create(&thread2,NULL,Thread_function2,NULL)) { return(1); } unsigned int i = 1; while(i < 11) { printf("Main Loop Iteration %d\n",i); i++; if(i%2) sleep(1); else sleep(2); } return 0; }
2. build with debug info increase the executable size.
/home/a/j/nomad2:ls -lrt a.out
-rwxr-xr-x 1 nomad2 member 11341 Oct 1 19:34 a.out
/home/a/j/nomad2:strip --strip-debug a.out
/home/a/j/nomad2:ls -lrt a.out
-rwxr-xr-x 1 nomad2 member 7522 Oct 1 19:42 a.out
3. 关于调试:
1). When debugging, it is often a good practice to stop program execution at the bottom of a function so that a print or multiple displays can be done to see the current values stored in the data the function has altered.
list <func name>
break <line of }>
2). When gdb is used, the print command must
be invoked to display the variable's value. The user can see much more information at one time.
相关文章推荐
- 关于sqlserver xml使用上的一些建议(摘录于sqlserver bible 2k8)
- 关于如何更好地使用Github的一些建议
- 关于如何更好地使用Github的一些建议
- 一些关于gdb的命令使用
- 关于一些core dump的问题,makefile以及gdb的使用问题
- 关于一些core dump的问题,makefile以及gdb的使用问题
- 一些关于javascript、jQuery使用时的建议
- 教程:关于Google Play无法正常使用解决方法的一些指导建议.
- 关于VS 使用GDB工具调试ADT下JNI时遇到的一些问题的解决
- 关于andorid开发中的一些适配,屏幕适配,版本适配,语言适配.9图片的使用要求
- 收藏一些关于KVM使用的链接
- 关于java中synchronized的迷思,建议只作为函数修饰符使用
- 关于oracle中LONG数据类型使用上的一些总结
- 关于使用GHOST进行磁盘对拷整盘镜像以及镜像恢复的一些注意事项
- 关于在Android studio 中的DDMS打不开data的一些建议
- 关于python venv的一些使用体验
- 关于pthread里面一些函数的使用心得! http://blog.csdn.net/lishuhuakai/article/details/12010229
- 关于使用OpenLayers的透明图层叠加的一些问题
- 关于使用VF的一些问题
- ubuntu关于驱动模块命令的一些使用