18,777
社区成员
发帖
与我相关
我的任务
分享
14 const char *const filename = "./A-small-practice.in";
15
16 void change_a(int *num)
17 {
18 *num = 8;
19 }
20
21 char ch;
22
23 int main()
24 {
25 int fd;
26 int a;
27 a = 12;
28 a = 10;
29 a = 9;
30
31 change_a(&a);
32 a = 7;
33
34 fd = open(filename, O_RDONLY);
35
36 read(fd, &ch, 1); /* 1 */
37 printf ("%c\n", ch);
38
39 read(fd, &ch, 1); /* 0 */
40 printf ("%c\n", ch);
41
42 read(fd, &ch, 1); /* \n */
43 printf ("%c\n", ch);
44
45 read(fd, &ch, 1); /* 1 */
46 printf ("%c\n", ch);
47
48 read(fd, &ch, 1); /* 0 */
49 printf ("%c\n", ch);
50
51 printf ("\n");
52 close (fd);
53
54 return 0;
55 }
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
const char *const filename = "/etc/passwd";
int main(void)
{
int fd;
char ch;
ch=1; // 这样的语句也是数据断点吧?
fd = open(filename, O_RDONLY);
read(fd, &ch, sizeof(char));
printf ("%d\n", ch);
close (fd);
return 0;
}
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/zodiac1111/tmp/a.out...done.
(gdb) b main
Breakpoint 1 at 0x80484b5: file 1.c, line 11.
(gdb) r
Starting program: /home/zodiac1111/tmp/a.out
Breakpoint 1, main () at 1.c:11
11 ch=1;
(gdb) wa ch
Hardware watchpoint 2: ch
(gdb) c
Continuing.
114
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
ch被捕获:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
const char *const filename = "/etc/passwd";
int main(void)
{
int fd;
char ch;
fd=1; //就增加这句
ch=1;
fd = open(filename, O_RDONLY);
read(fd, &ch, sizeof(char));
printf ("%d\n", ch);
close (fd);
return 0;
}
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/zodiac1111/tmp/a.out...done.
(gdb) b main
Breakpoint 1 at 0x80484b5: file 1.c, line 11.
(gdb) r
Starting program: /home/zodiac1111/tmp/a.out
Breakpoint 1, main () at 1.c:11
11 fd=1;
(gdb) wa ch
Hardware watchpoint 2: ch
(gdb) wa fd
Hardware watchpoint 3: fd
(gdb) c
Continuing.
Hardware watchpoint 2: ch
Old value = 8 '\b'
New value = 1 '\001'
main () at 1.c:13
13 fd = open(filename, O_RDONLY);
(gdb) c
Continuing.
Hardware watchpoint 3: fd
Old value = -1208221708
New value = 7
main () at 1.c:14
14 read(fd, &ch, sizeof(char));
(gdb) c
Continuing.
114
Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
Watchpoint 3 deleted because the program has left the block in
which its expression is valid.