]> granicus.if.org Git - strace/blob - process.c
Show f_flags field in printstatfs
[strace] / process.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7  *                     Linux for s390 port by D.J. Barrow
8  *                    <barrow_dj@mail.yahoo.com,djbarrow@de.ibm.com>
9  * Copyright (c) 2000 PocketPenguins Inc.  Linux for Hitachi SuperH
10  *                    port by Greg Banks <gbanks@pocketpenguins.com>
11  *
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. The name of the author may not be used to endorse or promote products
23  *    derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include "defs.h"
38
39 #ifdef HAVE_ELF_H
40 # include <elf.h>
41 #endif
42
43 #include "xlat/nt_descriptor_types.h"
44
45 #include "regs.h"
46 #include "ptrace.h"
47 #include "xlat/ptrace_cmds.h"
48 #include "xlat/ptrace_setoptions_flags.h"
49
50 #define uoff(member)    offsetof(struct user, member)
51 #define XLAT_UOFF(member)       { uoff(member), "offsetof(struct user, " #member ")" }
52
53 static const struct xlat struct_user_offsets[] = {
54 #include "userent.h"
55         XLAT_END
56 };
57
58 int
59 sys_ptrace(struct tcb *tcp)
60 {
61         const struct xlat *x;
62         unsigned long addr;
63
64         if (entering(tcp)) {
65                 printxval(ptrace_cmds, tcp->u_arg[0], "PTRACE_???");
66                 tprintf(", %lu, ", tcp->u_arg[1]);
67
68                 addr = tcp->u_arg[2];
69                 if (tcp->u_arg[0] == PTRACE_PEEKUSER
70                  || tcp->u_arg[0] == PTRACE_POKEUSER
71                 ) {
72                         for (x = struct_user_offsets; x->str; x++) {
73                                 if (x->val >= addr)
74                                         break;
75                         }
76                         if (!x->str)
77                                 tprintf("%#lx, ", addr);
78                         else if (x->val > addr && x != struct_user_offsets) {
79                                 x--;
80                                 tprintf("%s + %ld, ", x->str, addr - x->val);
81                         }
82                         else
83                                 tprintf("%s, ", x->str);
84                 } else
85                 if (tcp->u_arg[0] == PTRACE_GETREGSET
86                  || tcp->u_arg[0] == PTRACE_SETREGSET
87                 ) {
88                         printxval(nt_descriptor_types, tcp->u_arg[2], "NT_???");
89                         tprints(", ");
90                 } else
91                         tprintf("%#lx, ", addr);
92
93
94                 switch (tcp->u_arg[0]) {
95 #ifndef IA64
96                 case PTRACE_PEEKDATA:
97                 case PTRACE_PEEKTEXT:
98                 case PTRACE_PEEKUSER:
99                         break;
100 #endif
101                 case PTRACE_CONT:
102                 case PTRACE_SINGLESTEP:
103                 case PTRACE_SYSCALL:
104                 case PTRACE_DETACH:
105                         printsignal(tcp->u_arg[3]);
106                         break;
107                 case PTRACE_SETOPTIONS:
108                         printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
109                         break;
110                 case PTRACE_SETSIGINFO: {
111                         printsiginfo_at(tcp, tcp->u_arg[3]);
112                         break;
113                 }
114                 case PTRACE_SETREGSET:
115                         tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
116                         break;
117                 case PTRACE_GETSIGINFO:
118                 case PTRACE_GETREGSET:
119                         /* Don't print anything, do it at syscall return. */
120                         break;
121                 default:
122                         tprintf("%#lx", tcp->u_arg[3]);
123                         break;
124                 }
125         } else {
126                 switch (tcp->u_arg[0]) {
127                 case PTRACE_PEEKDATA:
128                 case PTRACE_PEEKTEXT:
129                 case PTRACE_PEEKUSER:
130 #ifdef IA64
131                         return RVAL_HEX;
132 #else
133                         printnum_long(tcp, tcp->u_arg[3], "%#lx");
134                         break;
135 #endif
136                 case PTRACE_GETSIGINFO: {
137                         printsiginfo_at(tcp, tcp->u_arg[3]);
138                         break;
139                 }
140                 case PTRACE_GETREGSET:
141                         tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
142                         break;
143                 }
144         }
145         return 0;
146 }