Fix PR breakpoints/16297: catch syscall with syscall 0
[external/binutils.git] / gdb / testsuite / gdb.base / catch-syscall.c
1 /* This file is used to test the 'catch syscall' feature on GDB.
2  
3    Please, if you are going to edit this file DO NOT change the syscalls
4    being called (nor the order of them).  If you really must do this, then
5    take a look at catch-syscall.exp and modify there too.
6
7    Written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
8    September, 2008 */
9
10 #include <unistd.h>
11 #include <sys/syscall.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14
15 /* These are the syscalls numbers used by the test.  */
16
17 static int close_syscall = SYS_close;
18 static int chroot_syscall = SYS_chroot;
19 /* GDB had a bug where it couldn't catch syscall number 0 (PR 16297).
20    In most GNU/Linux architectures, syscall number 0 is
21    restart_syscall, which can't be called from userspace.  However,
22    the "read" syscall is zero on x86_64.  */
23 static int read_syscall = SYS_read;
24 static int pipe_syscall = SYS_pipe;
25 static int write_syscall = SYS_write;
26 static int exit_group_syscall = SYS_exit_group;
27
28 int
29 main (void)
30 {
31         int fd[2];
32         char buf1[2] = "a";
33         char buf2[2];
34
35         /* A close() with a wrong argument.  We are only
36            interested in the syscall.  */
37         close (-1);
38
39         chroot (".");
40
41         pipe (fd);
42
43         write (fd[1], buf1, sizeof (buf1));
44         read (fd[0], buf2, sizeof (buf2));
45
46         /* The last syscall.  Do not change this.  */
47         _exit (0);
48 }