关于使用gdb的一些建议
来源:互联网 发布:人工智能伏羲觉醒2电影 编辑:程序博客网 时间:2024/06/05 02:57
参考:《Linux® Debugging and Performance Tuning: Tips and Techniques》 chapter 3
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.
- 关于使用gdb的一些建议
- 一些关于gdb的命令使用
- 关于gdb的一些用法
- 关于gdb的使用
- 关于gdb的使用
- 一些关于javascript、jQuery使用时的建议
- 关于如何更好地使用Github的一些建议
- 关于学习的一些建议
- 关于答辩的一些建议
- 关于单片机的一些建议
- gdb的一些常规使用
- gdb的一些常规使用
- GDB的一些命令使用
- 使用const的一些建议
- docker使用的一些建议
- docker使用的一些建议
- 关于gcc、g++、gdb的一些知识
- 关于Ubuntu gdb的使用
- flex中dictionary跟Object的区别与遍历
- Linux下vmstat调优工具的深入分析
- SPOJ 1793. Text Generater II
- 关于位运算的重要应用
- 数据算法--八种排序
- 关于使用gdb的一些建议
- A Little About Digital Audio and Linear PCM
- Android Bluetooth 串口通信
- Linux下core文件的演示分析
- 我咯自学之路重新开启
- Debian系统Flash缺字问题解决
- 浅析Linux下core文件
- Linux调优工具gprof和gcov的演示分析
- linux下的调试工具ltrace与strace