e65d4a4906c3529bde5d37a432316030683e6e54
[binutils-gdb.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 #include <sched.h>
15
16 /* These are the syscalls numbers used by the test. */
17
18 int close_syscall = SYS_close;
19 int chroot_syscall = SYS_chroot;
20 /* GDB had a bug where it couldn't catch syscall number 0 (PR 16297).
21 In most GNU/Linux architectures, syscall number 0 is
22 restart_syscall, which can't be called from userspace. However,
23 the "read" syscall is zero on x86_64. */
24 int read_syscall = SYS_read;
25 #ifdef SYS_pipe
26 int pipe_syscall = SYS_pipe;
27 #else
28 int pipe2_syscall = SYS_pipe2;
29 #endif
30 int write_syscall = SYS_write;
31 int unknown_syscall = 123456789;
32 int exit_group_syscall = SYS_exit_group;
33
34 int
35 main (void)
36 {
37 int fd[2];
38 char buf1[2] = "a";
39 char buf2[2];
40
41 /* A close() with a wrong argument. We are only
42 interested in the syscall. */
43 close (-1);
44
45 chroot (".");
46
47 pipe (fd);
48
49 write (fd[1], buf1, sizeof (buf1));
50 read (fd[0], buf2, sizeof (buf2));
51
52 /* Test vfork-event interactions. Child exits immediately.
53 (Plain fork won't work on no-mmu kernel configurations.) */
54 if (vfork () == 0)
55 _exit (0);
56
57 /* Trigger an intentional ENOSYS. */
58 syscall (unknown_syscall);
59
60 /* The last syscall. Do not change this. */
61 _exit (0);
62 }