LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: dengshiyou

gdb新手上路,懂的请帮忙!

[复制链接]
 楼主| 发表于 2005-12-11 20:28:58 | 显示全部楼层
谢谢各位,我搞定了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-12-13 20:20:41 | 显示全部楼层
又一新问题;请帮忙
(gdb) l
1       #include<stdio.h>
2       main()
3       {
4         char my_string[]="hello there";
5         my_print(my_string);
6         my_print2(my_string);
7       }
8
9       void my_print(char *string)
10      {
(gdb) l
11      printf("The string is %s\n",string);
12      }
13
14      void my_print2(char *string)
15      {
16      char *string2;
17      int size,i;
18      size=strlen(string);
19      string2=(char *)malloc(size+1);
20      for(i=0;i<size;i++)
(gdb) l
21      string2[size-i]=string;
22      string2[size+1]='\0';
23      printf("The string printed backward is %s\n",string2);
24      }
25
26
27
28
(gdb) break 21
Breakpoint 1 at 0x804845c: file test.c, line 21.
(gdb) run
Starting program: /root/myc/tmp/test
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x1a3000
The string is hello there

Breakpoint 1, my_print2 (string=0xbf8fc4d4 "hello there") at test.c:21
21      string2[size-i]=string;
(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.

(gdb)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-12-13 20:21:35 | 显示全部楼层
又一新问题;请帮忙
(gdb) l
1       #include<stdio.h>
2       main()
3       {
4         char my_string[]="hello there";
5         my_print(my_string);
6         my_print2(my_string);
7       }
8
9       void my_print(char *string)
10      {
(gdb) l
11      printf("The string is %s\n",string);
12      }
13
14      void my_print2(char *string)
15      {
16      char *string2;
17      int size,i;
18      size=strlen(string);
19      string2=(char *)malloc(size+1);
20      for(i=0;i<size;i++)
(gdb) l
21      string2[size-i]=string;
22      string2[size+1]='\0';
23      printf("The string printed backward is %s\n",string2);
24      }
25
26
27
28
(gdb) break 21
Breakpoint 1 at 0x804845c: file test.c, line 21.
(gdb) run
Starting program: /root/myc/tmp/test
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0x1a3000
The string is hello there

Breakpoint 1, my_print2 (string=0xbf8fc4d4 "hello there") at test.c:21
21      string2[size-i]=string;
(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.

(gdb)
回复 支持 反对

使用道具 举报

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

本版积分规则

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