找回密码
 注册
查看: 3405|回复: 2

此例中gdb中的watch要怎么用?

[复制链接]
发表于 2006-5-7 22:37:22 | 显示全部楼层 |阅读模式
[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]则可以正常显示变量的值.
 楼主| 发表于 2006-5-7 22:46:26 | 显示全部楼层
运行run时提示的文件格式错误是什么意思 ?
最后运行next时所提示的那些怎么理解 ?
回复

使用道具 举报

发表于 2006-5-8 09:27:15 | 显示全部楼层
watch string2[size2-数字]应该是没问题的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-7 01:20 , Processed in 0.021142 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表