修改Linux操作系统下22端口两种方法介绍
作者 佚名技术
来源 Linux系统
浏览
发布时间 2012-05-07
源程序:tst.c 1 #include 2 3 int func(int n) 4 { 5 int sum=0,i; 6 for(i=0; i 7 { 8 sum =i; 9 } 10 return sum; 11 } 12 13 14 main() 15 { 16 int i; 17 long result = 0; 18 for(i=1; i<=100; i ) 19 { 20 result = i; 21 } 22 23 printf("result[1-100] = %d n", result ); 24 printf("result[1-250] = %d n", func(250) ); 25 } 编译生成执行文件:(Linux下) hchen/test>; cc -g tst.c -o tst 使用GDB调试: hchen/test>; gdb tst <---------- 启动GDB GNU gdb 5.1.1 Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-suse-linux"... (gdb) l <-------------------- l命令相当于list,从第一行开始例出原码. 1 #include 2 3 int func(int n) 4 { 5 int sum=0,i; 6 for(i=0; i 7 { 8 sum =i; 9 } 10 return sum; (gdb) <-------------------- 直接回车表示,重复上一次命令 11 } 12 13 14 main() 15 { 16 int i; 17 long result = 0; 18 for(i=1; i<=100; i ) 19 { 20 result = i; (gdb) break 16 <-------------------- 设置断点,在源程序第16行处. Breakpoint 1 at 0x8048496: file tst.c, line 16. (gdb) break func <-------------------- 设置断点,在函数func()入口处. Breakpoint 2 at 0x8048456: file tst.c, line 5. (gdb) info break <-------------------- 查看断点信息. Num Type Disp Enb Address What 1 breakpoint keep y 0x08048496 in main at tst.c:16 2 breakpoint keep y 0x08048456 in func at tst.c:5 (gdb) r <--------------------- 运行程序,run命令简写 Starting program: /home/hchen/test/tst Breakpoint 1, main () at tst.c:17 <---------- 在断点处停住. 17 long result = 0; (gdb) n <--------------------- 单条语句执行,next命令简写. 18 for(i=1; i<=100; i ) (gdb) n 20 result = i; (gdb) n 18 for(i=1; i<=100; i ) (gdb) n 20 result = i; (gdb) c <--------------------- 继续运行程序,continue命令简写. Continuing. result[1-100] = 5050 <----------程序输出. Breakpoint 2, func (n=250) at tst.c:5 5 int sum=0,i; (gdb) n 6 for(i=1; i<=n; i ) (gdb) p i <--------------------- 打印变量i的值,print命令简写. $1 = 134513808 (gdb) n 8 sum =i; (gdb) n 6 for(i=1; i<=n; i ) (gdb) p sum $2 = 1 (gdb) n 8 sum =i; (gdb) p i $3 = 2 (gdb) n 6 for(i=1; i<=n; i ) (gdb) p sum $4 = 3 (gdb) bt <--------------------- 查看函数堆栈. #0 func (n=250) at tst.c:5 #1 0x080484e4 in main () at tst.c:24 #2 0x400409ed in __libc_start_main () from /lib/libc.so.6 (gdb) finish <--------------------- 退出函数. Run till exit from #0 func (n=250) at tst.c:5 0x080484e4 in main () at tst.c:24 24 printf("result[1-250] = %d n", func(250) ); Value returned is $6 = 31375 (gdb) c <--------------------- 继续运行. Continuing. result[1-250] = 31375 <----------程序输出. Program exited with |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: Linux下Fdisk的小知识下一篇: 学会linux中使用gdb调试程序
关于修改Linux操作系统下22端口两种方法介绍的所有评论