- 论坛徽章:
- 0
|
2.6.11-1.1369_FC4
这是程序:
- #include <stdio.h>
- #include <string.h>
- void my_print(char *);
- void my_print2(char *);
- int main(int argc ,char *argv[])
- {
- char my_string[]="hello there";
- my_print(my_string);
- my_print2(my_string);
- return 0;
- }
- void my_print(char *string)
- {
- printf("the string is :%s\n",string);
- }
- void my_print2(char *string)
- {
- char *string2;
- int size,i;
- size=strlen(string);
- string2=(char *)malloc((size+1)*sizeof(char *));
- for(i=0;i<size;i++)
- string2[size-i]=string[i]; /*backword string*/
- string2[size+1]='\0';
- printf("the string backword is :%s\n",string2);
- }
复制代码
然后编译:
- [root@localhost code]# gcc -o greeting -g greeting.c
- greeting.c: 在函数 ‘my_print2’ 中:
- greeting.c:21: 警告:内建函数 ‘malloc’ 不兼容的隐式声明
- [root@localhost code]# ./greeting
- the string is :hello there
- the string backword is :
- [root@localhost code]#
复制代码
然后GDB
[code]
[root@localhost code]# gdb greeting
GNU gdb Red Hat Linux (6.3.0.0-1.21rh)
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-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) list
1 #include <stdio.h>
2 #include <string.h>
3 void my_print(char *);
4 void my_print2(char *);
5 int main(int argc ,char *argv[])
6 {
7 char my_string[]="hello there";
8 my_print(my_string);
9 my_print2(my_string);
10 return 0;
(gdb) list
11 }
12 void my_print(char *string)
13 {
14 printf("the string is :%s\n",string);
15 }
16 void my_print2(char *string)
17 {
18 char *string2;
19 int size,i;
20 size=strlen(string);
(gdb) list
21 string2=(char *)malloc((size+1)*sizeof(char *));
22 for(i=0;i<size;i++)
23 string2[size-i]=string; /*backword string*/
24 string2[size+1]='\0';
25 printf("the string backword is :%s\n",string2);
26 }
(gdb) break 23
Breakpoint 1 at 0x8048466: file greeting.c, line 23.
(gdb) run
Starting program: /root/code/greeting
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x336000
the string is :hello there
Breakpoint 1, my_print2 (string=0xbf9450d4 "hello there") at greeting.c:23
23 string2[size-i]=string; /*backword string*/
(gdb) watch string2[size-i]
Hardware watchpoint 2: string2[size - 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)
红色部分就是出现的问题,无法继续下去
[ 本帖最后由 rainballdh 于 2005-11-8 21:50 编辑 ] |
|