|
[code:1]
1 #include <stdio.h>
2 void my_print(char *);
3 void my_print2(char *);
4 main()
5 {
6 char my_string[]="hello oatt";
7 my_print(my_string);
8 my_print2(my_string);
9 }
10 void my_print(char *string)
11 {
12 printf("%s\n",string);
13 }
14 void my_print2(char *string)
15 {
16 char *string2;
17 int size,i;
18 int size2;
19 size = strlen(string);
20 size2 = size-1;
21 string2 = (char *)malloc(size+1);
22 for(i=0;i<size;i++)
23 string2[size2-i]=string[i];
24 string2[size+1]='\0';
25 printf("%s\n",string2);
26 }
[/code:1]
gcc -g -o greeting greeting.c
gdb greeting
break 23
Breakpoint 3 at 0x8048491: file greeting.c, line 23.
run
warning: cannot close "shared object read from target memory": 文件格式错误
Starting program: /home/oatt/program-gdb/greeting
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xffffe000
hello oatt
Breakpoint 3, my_print2 (string=0xbfc070b0 "hello oatt") at greeting.c:23
23 string2[size2-i]=string;
watch string2[size2-i]
Hardware watchpoint 4: string2[size2 - i]
next
warning: Could not remove hardware watchpoint 4.
Warning:
Could not insert hardware watchpoint 4.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.
为什么用watch string2[size2-i]不好使呢?
用print string2[size2-i]则可以正常显示变量的值. |
|