|

楼主 |
发表于 2004-10-3 10:28:38
|
显示全部楼层
- cd /home/funshine/c/ # -*-compilation-*-
- Entering directory `/home/funshine/c/'
- make -k
- make: “greeting”是最新的。
- Compilation finished at Sun Oct 3 10:25:22
- Current directory is /home/funshine/c/
- GNU gdb 6.1-debian
- Copyright 2004 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-linux"...Using host libthread_db library "/lib/libthread_db.so.1".
- (gdb) run
- Starting program: /home/funshine/c/greeting
- 你好,你现在使用的是gcc编译器!
- The string is hello there
- The string printed backward is ereht olleh
- Program exited with code 053.
- (gdb) l
- 1 #include <stdio.h>
- 2
- 3 void my_print(char *string);
- 4 void my_print2(char *string);
- 5
- 6 int main()
- 7 {
- 8 printf("你好,你现在使用的是gcc编译器!\n");
- 9 char my_string[]="hello there";
- 10 my_print(my_string);
- (gdb)
- 11 my_print2(my_string);
- 12 }
- 13 void my_print(char *string)
- 14 {
- 15 printf("The string is %s\n",string);
- 16 }
- 17
- 18 void my_print2(char *string)
- 19 {
- 20 char *string2;
- (gdb)
- 21 int size,size2,i;
- 22
- 23 size=strlen(string);
- 24 size2=size-1;
- 25 string2=(char *)malloc(size+1);
- 26 for(i=0;i<size;i++)
- 27 string2[size2-i]=string[i];
- 28 string2[size]='\0';
- 29 printf("The string printed backward is %s\n",string2);
- 30 }
- (gdb) break 27
- Breakpoint 1 at 0x8048466: file greeting.c, line 27.
- (gdb) run
- Starting program: /home/funshine/c/greeting
- 你好,你现在使用的是gcc编译器!
- The string is hello there
- Breakpoint 1, my_print2 (string=0xbffffc10 "hello there") at greeting.c:27
- 27 string2[size2-i]=string[i];
- (gdb) watch string2[size2-i]
- Hardware watchpoint 2: string2[size2 - i]
- (gdb) next
- warning: Could not remove hardware watchpoint 2.
- Warning:
- Could not insert hardware watchpoint 2.
- Could not insert hardware breakpoints:
- You may have requested too many hardware breakpoints/watchpoints.
- (gdb)
复制代码 |
|