GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.base / catch-syscall.c
blob070c0122e4577157bba8894b8247c5ce490786d9
1 /* This file is used to test the 'catch syscall' feature on GDB.
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.
7 Written by Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
8 September, 2008 */
10 #include <unistd.h>
11 #include <sys/syscall.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include <sched.h>
16 /* These are the syscalls numbers used by the test. */
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 #endif
28 #ifdef SYS_pipe2
29 int pipe2_syscall = SYS_pipe2;
30 #endif
31 int write_syscall = SYS_write;
32 #if defined(__arm__)
33 /* Although 123456789 is an illegal syscall umber on arm linux, kernel
34 sends SIGILL rather than returns -ENOSYS. However, arm linux kernel
35 returns -ENOSYS if syscall number is within 0xf0001..0xf07ff, so we
36 can use 0xf07ff for unknown_syscall in test. */
37 int unknown_syscall = 0x0f07ff;
38 #else
39 int unknown_syscall = 123456789;
40 #endif
41 #ifdef SYS_exit_group
42 int exit_group_syscall = SYS_exit_group;
43 #else
44 int exit_syscall = SYS_exit;
45 #endif
47 /* Set by the test when it wants execve. */
48 int do_execve = 0;
50 int
51 main (int argc, char *const argv[])
53 int fd[2];
54 char buf1[2] = "a";
55 char buf2[2];
57 /* Test a simple self-exec, but only on request. */
58 if (do_execve)
59 execv (*argv, argv);
61 /* A close() with a wrong argument. We are only
62 interested in the syscall. */
63 close (-1);
65 chroot (".");
67 pipe (fd);
69 write (fd[1], buf1, sizeof (buf1));
70 read (fd[0], buf2, sizeof (buf2));
72 /* Test vfork-event interactions. Child exits immediately.
73 (Plain fork won't work on no-mmu kernel configurations.) */
74 if (vfork () == 0)
75 _exit (0);
77 /* Trigger an intentional ENOSYS. */
78 syscall (unknown_syscall);
80 /* The last syscall. Do not change this. */
81 _exit (0);