Fedora Core 3 下gdb调试问题
test.c源程序如下:
#include <stdio.h>
void my_print(char *string);
void my_print2(char *string);
main()
{
char my_string[] = "hello there";
my_print(my_string);
my_print2(my_string);
}
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);
for(i = 0; i < size; i++)
{
string2[size-i] = string[i];
}
string2[size + 1] = '\0';
printf("The string printed backward is %s\n", string2);
}
在debug时总不成功,过程如下:
////////////////////////////////////////////////////////////////
[root@localhost rockey]# gcc -g -o test test.c
[root@localhost rockey]# gdb test
GNU gdb Red Hat Linux (6.1post-1.20040607.41rh)
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/tls/libthread_db.so.1".
(gdb) l
1 #include <stdio.h>
2 void my_print(char *string);
3 void my_print2(char *string);
4
5 main()
6 {
7 char my_string[] = "hello there";
8 my_print(my_string);
9 my_print2(my_string);
10
(gdb)
11 }
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, i;
22
23 size = strlen(string);
24 string2 = (char*)malloc(size+1);
25 for(i = 0; i < size; i++)
26 {
27 string2[size-i] = string[i];
28 }
29 string2[size + 1] = '\0';
30 printf("The string printed backward is %s\n", string2);
(gdb)
31
32 }
(gdb) break 27
Breakpoint 1 at 0x804847c: file test.c, line 27.
(gdb) r
Starting program: /usr/rockey/test
The string is hello there
Breakpoint 1, my_print2 (string=0xfeee0db0 "hello there") at test.c:27
27 string2[size-i] = string[i];
(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.
//////////////////////////////////////////////
到这个地方就出现错误,请问是怎么回事呢?