- 论坛徽章:
- 0
|
入门的第一个c程序调试问题
我写了一个最简单的c程序,也出现同样的问题
代码如下:
main()
{
char *str;
int size = 10;
int i;
str = (char*)malloc(size);
for (i = size; i >; 1; i--)
str[size - i] = '*';
str[size - 1] = '\0';
printf("str=%s\n", str);
}
编译
gcc -g -o test test.c
调试
gdb test
(gdb) b 10
Breakpoint 1 at 0x80483e0: file test.c, line 10.
(gdb) r
Starting program: /root/tmp/test
Breakpoint 1, main() at test.c:10
10 str[size - i] = '*';
(gdb) watch str[size - i]
Hardware watchpoint 2: str[size - i]
(gdb) n
warning: Could not remove hardware watchpoint 2.
Warning:
Could not insert hardware watchpoint 2.
Could not insert hardware breakpoints:
You may have requested too may hardware breakpoints/watchpoints.
同样在其它版本的linux下,就能正确监视str[size-i]。
在多台fedora core 3上,都有同样的问题。
大家再帮忙分析一下,多谢!! |
|