]> granicus.if.org Git - strace/blob - process.c
ptrace: do not print data argument of some requests on sparc
[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 unsigned 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                 /* request */
92                 printxval64(ptrace_cmds, request, "PTRACE_???");
93
94                 if (request == PTRACE_TRACEME) {
95                         /* pid, addr, and data are ignored. */
96                         return RVAL_DECODED;
97                 }
98
99                 /* pid */
100                 tprintf(", %d", pid);
101
102                 /* addr */
103                 switch (request) {
104                 case PTRACE_ATTACH:
105                 case PTRACE_INTERRUPT:
106                 case PTRACE_KILL:
107                 case PTRACE_LISTEN:
108                         /* addr and data are ignored */
109                         return RVAL_DECODED;
110                 case PTRACE_PEEKUSER:
111                 case PTRACE_POKEUSER:
112                         tprints(", ");
113                         print_user_offset_addr(addr);
114                         break;
115                 case PTRACE_GETREGSET:
116                 case PTRACE_SETREGSET:
117                         tprints(", ");
118                         printxval(nt_descriptor_types, addr, "NT_???");
119                         break;
120 #if defined SPARC || defined SPARC64
121                 case PTRACE_GETREGS:
122                 case PTRACE_SETREGS:
123                 case PTRACE_GETFPREGS:
124                 case PTRACE_SETFPREGS:
125                         tprints(", ");
126                         printaddr(addr);
127                         /* data is ignored */
128                         return RVAL_DECODED;
129 #endif
130                 default:
131                         tprints(", ");
132                         printaddr(addr);
133                 }
134
135                 tprints(", ");
136
137                 /* data */
138                 switch (request) {
139 #ifndef IA64
140                 case PTRACE_PEEKDATA:
141                 case PTRACE_PEEKTEXT:
142                 case PTRACE_PEEKUSER:
143                         break;
144 #endif
145                 case PTRACE_CONT:
146                 case PTRACE_SINGLESTEP:
147                 case PTRACE_SYSCALL:
148                 case PTRACE_DETACH:
149                         printsignal(data);
150                         break;
151                 case PTRACE_SETOPTIONS:
152                         printflags(ptrace_setoptions_flags, data, "PTRACE_O_???");
153                         break;
154                 case PTRACE_SETSIGINFO:
155                         printsiginfo_at(tcp, data);
156                         break;
157                 case PTRACE_SETREGSET:
158                         tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
159                         break;
160                 case PTRACE_GETSIGINFO:
161                 case PTRACE_GETREGSET:
162                         /* Don't print anything, do it at syscall return. */
163                         break;
164                 default:
165                         printaddr(data);
166                         break;
167                 }
168         } else {
169                 switch (request) {
170                 case PTRACE_PEEKDATA:
171                 case PTRACE_PEEKTEXT:
172                 case PTRACE_PEEKUSER:
173 #ifdef IA64
174                         return RVAL_HEX;
175 #else
176                         printnum_ptr(tcp, data);
177                         break;
178 #endif
179                 case PTRACE_GETSIGINFO:
180                         printsiginfo_at(tcp, data);
181                         break;
182                 case PTRACE_GETREGSET:
183                         tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
184                         break;
185                 }
186         }
187         return 0;
188 }