Fedora Core 3 下gdb调试问题

bluerockey 2006-03-08 09:29:16
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.


//////////////////////////////////////////////
到这个地方就出现错误,请问是怎么回事呢?
...全文
83 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fierygnu 2006-03-08
  • 打赏
  • 举报
回复
在$HOME/.gdbinit里设置。直接写入该命令即可。
关了之后有watch点时性能下降。
bluerockey 2006-03-08
  • 打赏
  • 举报
回复
是不是每次调试程序都要关掉?这样有点麻烦。
有没有一个方法关掉下次也可以继续用
如果关掉有什么坏处吗?
fierygnu 2006-03-08
  • 打赏
  • 举报
回复
关闭hardware watchpoint
set can-use-hw-watchpoints 0

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧