]> granicus.if.org Git - strace/blob - process.c
statfs: don't quote f_type macro names
[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 static void
59 print_user_offset_addr(const unsigned long addr)
60 {
61         const struct xlat *x;
62
63         for (x = struct_user_offsets; x->str; ++x) {
64                 if (x->val >= addr)
65                         break;
66         }
67
68         if (!x->str) {
69                 printaddr(addr);
70         } else if (x->val > addr) {
71                 if (x == struct_user_offsets) {
72                         printaddr(addr);
73                 } else {
74                         --x;
75                         tprintf("%s + %lu",
76                                 x->str, addr - (unsigned long) x->val);
77                 }
78         } else {
79                 tprints(x->str);
80         }
81 }
82
83 SYS_FUNC(ptrace)
84 {
85         const long request = tcp->u_arg[0];
86         const int pid = tcp->u_arg[1];
87         const unsigned long addr = tcp->u_arg[2];
88         const unsigned long data = tcp->u_arg[3];
89
90         if (entering(tcp)) {
91                 printxval(ptrace_cmds, request, "PTRACE_???");
92                 tprintf(", %d, ", pid);
93
94                 switch (request) {
95                 case PTRACE_PEEKUSER:
96                 case PTRACE_POKEUSER:
97                         print_user_offset_addr(addr);
98                         break;
99                 case PTRACE_GETREGSET:
100                 case PTRACE_SETREGSET:
101                         printxval(nt_descriptor_types, addr, "NT_???");
102                         break;
103                 default:
104                         printaddr(addr);
105                 }
106
107                 tprints(", ");
108
109                 switch (request) {
110 #ifndef IA64
111                 case PTRACE_PEEKDATA:
112                 case PTRACE_PEEKTEXT:
113                 case PTRACE_PEEKUSER:
114                         break;
115 #endif
116                 case PTRACE_CONT:
117                 case PTRACE_SINGLESTEP:
118                 case PTRACE_SYSCALL:
119                 case PTRACE_DETACH:
120                         printsignal(data);
121                         break;
122                 case PTRACE_SETOPTIONS:
123                         printflags(ptrace_setoptions_flags, data, "PTRACE_O_???");
124                         break;
125                 case PTRACE_SETSIGINFO:
126                         printsiginfo_at(tcp, data);
127                         break;
128                 case PTRACE_SETREGSET:
129                         tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
130                         break;
131                 case PTRACE_GETSIGINFO:
132                 case PTRACE_GETREGSET:
133                         /* Don't print anything, do it at syscall return. */
134                         break;
135                 default:
136                         printaddr(data);
137                         break;
138                 }
139         } else {
140                 switch (request) {
141                 case PTRACE_PEEKDATA:
142                 case PTRACE_PEEKTEXT:
143                 case PTRACE_PEEKUSER:
144 #ifdef IA64
145                         return RVAL_HEX;
146 #else
147                         printnum_ptr(tcp, data);
148                         break;
149 #endif
150                 case PTRACE_GETSIGINFO:
151                         printsiginfo_at(tcp, data);
152                         break;
153                 case PTRACE_GETREGSET:
154                         tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
155                         break;
156                 }
157         }
158         return 0;
159 }