]> granicus.if.org Git - strace/blob - process.c
2c619e7fe9abed81199097b42fa6c75c42f99d05
[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 #include <fcntl.h>
39 #include <sys/stat.h>
40 #include <sys/wait.h>
41 #include <sys/resource.h>
42 #include <sys/utsname.h>
43 #include <sys/user.h>
44 #ifdef HAVE_ELF_H
45 # include <elf.h>
46 #endif
47
48 #ifdef HAVE_SYS_REG_H
49 # include <sys/reg.h>
50 # ifndef PTRACE_PEEKUSR
51 #  define PTRACE_PEEKUSR PTRACE_PEEKUSER
52 # endif
53 # ifndef PTRACE_POKEUSR
54 #  define PTRACE_POKEUSR PTRACE_POKEUSER
55 # endif
56 #endif
57
58 #ifdef HAVE_LINUX_PTRACE_H
59 # undef PTRACE_SYSCALL
60 # ifdef HAVE_STRUCT_IA64_FPREG
61 #  define ia64_fpreg XXX_ia64_fpreg
62 # endif
63 # ifdef HAVE_STRUCT_PT_ALL_USER_REGS
64 #  define pt_all_user_regs XXX_pt_all_user_regs
65 # endif
66 # include <linux/ptrace.h>
67 # undef ia64_fpreg
68 # undef pt_all_user_regs
69 #endif
70
71 #if defined(SPARC64)
72 # define r_pc r_tpc
73 # undef PTRACE_GETREGS
74 # define PTRACE_GETREGS PTRACE_GETREGS64
75 # undef PTRACE_SETREGS
76 # define PTRACE_SETREGS PTRACE_SETREGS64
77 #endif
78
79 #ifdef HAVE_LINUX_FUTEX_H
80 # include <linux/futex.h>
81 #endif
82 #ifndef FUTEX_WAIT
83 # define FUTEX_WAIT 0
84 #endif
85 #ifndef FUTEX_WAKE
86 # define FUTEX_WAKE 1
87 #endif
88 #ifndef FUTEX_FD
89 # define FUTEX_FD 2
90 #endif
91 #ifndef FUTEX_REQUEUE
92 # define FUTEX_REQUEUE 3
93 #endif
94
95 #include <sched.h>
96 #include <asm/posix_types.h>
97 #undef GETGROUPS_T
98 #define GETGROUPS_T __kernel_gid_t
99 #undef GETGROUPS32_T
100 #define GETGROUPS32_T __kernel_gid32_t
101
102 #if defined(IA64)
103 # include <asm/ptrace_offsets.h>
104 # include <asm/rse.h>
105 #endif
106
107 #ifdef HAVE_PRCTL
108 # include <sys/prctl.h>
109
110 static const struct xlat prctl_options[] = {
111 #ifdef PR_MAXPROCS
112         { PR_MAXPROCS,          "PR_MAXPROCS"           },
113 #endif
114 #ifdef PR_ISBLOCKED
115         { PR_ISBLOCKED,         "PR_ISBLOCKED"          },
116 #endif
117 #ifdef PR_SETSTACKSIZE
118         { PR_SETSTACKSIZE,      "PR_SETSTACKSIZE"       },
119 #endif
120 #ifdef PR_GETSTACKSIZE
121         { PR_GETSTACKSIZE,      "PR_GETSTACKSIZE"       },
122 #endif
123 #ifdef PR_MAXPPROCS
124         { PR_MAXPPROCS,         "PR_MAXPPROCS"          },
125 #endif
126 #ifdef PR_UNBLKONEXEC
127         { PR_UNBLKONEXEC,       "PR_UNBLKONEXEC"        },
128 #endif
129 #ifdef PR_ATOMICSIM
130         { PR_ATOMICSIM,         "PR_ATOMICSIM"          },
131 #endif
132 #ifdef PR_SETEXITSIG
133         { PR_SETEXITSIG,        "PR_SETEXITSIG"         },
134 #endif
135 #ifdef PR_RESIDENT
136         { PR_RESIDENT,          "PR_RESIDENT"           },
137 #endif
138 #ifdef PR_ATTACHADDR
139         { PR_ATTACHADDR,        "PR_ATTACHADDR"         },
140 #endif
141 #ifdef PR_DETACHADDR
142         { PR_DETACHADDR,        "PR_DETACHADDR"         },
143 #endif
144 #ifdef PR_TERMCHILD
145         { PR_TERMCHILD,         "PR_TERMCHILD"          },
146 #endif
147 #ifdef PR_GETSHMASK
148         { PR_GETSHMASK,         "PR_GETSHMASK"          },
149 #endif
150 #ifdef PR_GETNSHARE
151         { PR_GETNSHARE,         "PR_GETNSHARE"          },
152 #endif
153 #ifdef PR_COREPID
154         { PR_COREPID,           "PR_COREPID"            },
155 #endif
156 #ifdef PR_ATTACHADDRPERM
157         { PR_ATTACHADDRPERM,    "PR_ATTACHADDRPERM"     },
158 #endif
159 #ifdef PR_PTHREADEXIT
160         { PR_PTHREADEXIT,       "PR_PTHREADEXIT"        },
161 #endif
162
163 #ifdef PR_SET_PDEATHSIG
164         { PR_SET_PDEATHSIG,     "PR_SET_PDEATHSIG"      },
165 #endif
166 #ifdef PR_GET_PDEATHSIG
167         { PR_GET_PDEATHSIG,     "PR_GET_PDEATHSIG"      },
168 #endif
169 #ifdef PR_GET_DUMPABLE
170         { PR_GET_DUMPABLE,      "PR_GET_DUMPABLE"       },
171 #endif
172 #ifdef PR_SET_DUMPABLE
173         { PR_SET_DUMPABLE,      "PR_SET_DUMPABLE"       },
174 #endif
175 #ifdef PR_GET_UNALIGN
176         { PR_GET_UNALIGN,       "PR_GET_UNALIGN"        },
177 #endif
178 #ifdef PR_SET_UNALIGN
179         { PR_SET_UNALIGN,       "PR_SET_UNALIGN"        },
180 #endif
181 #ifdef PR_GET_KEEPCAPS
182         { PR_GET_KEEPCAPS,      "PR_GET_KEEPCAPS"       },
183 #endif
184 #ifdef PR_SET_KEEPCAPS
185         { PR_SET_KEEPCAPS,      "PR_SET_KEEPCAPS"       },
186 #endif
187 #ifdef PR_GET_FPEMU
188         { PR_GET_FPEMU,         "PR_GET_FPEMU"          },
189 #endif
190 #ifdef PR_SET_FPEMU
191         { PR_SET_FPEMU,         "PR_SET_FPEMU"          },
192 #endif
193 #ifdef PR_GET_FPEXC
194         { PR_GET_FPEXC,         "PR_GET_FPEXC"          },
195 #endif
196 #ifdef PR_SET_FPEXC
197         { PR_SET_FPEXC,         "PR_SET_FPEXC"          },
198 #endif
199 #ifdef PR_GET_TIMING
200         { PR_GET_TIMING,        "PR_GET_TIMING"         },
201 #endif
202 #ifdef PR_SET_TIMING
203         { PR_SET_TIMING,        "PR_SET_TIMING"         },
204 #endif
205 #ifdef PR_SET_NAME
206         { PR_SET_NAME,          "PR_SET_NAME"           },
207 #endif
208 #ifdef PR_GET_NAME
209         { PR_GET_NAME,          "PR_GET_NAME"           },
210 #endif
211 #ifdef PR_GET_ENDIAN
212         { PR_GET_ENDIAN,        "PR_GET_ENDIAN"         },
213 #endif
214 #ifdef PR_SET_ENDIAN
215         { PR_SET_ENDIAN,        "PR_SET_ENDIAN"         },
216 #endif
217 #ifdef PR_GET_SECCOMP
218         { PR_GET_SECCOMP,       "PR_GET_SECCOMP"        },
219 #endif
220 #ifdef PR_SET_SECCOMP
221         { PR_SET_SECCOMP,       "PR_SET_SECCOMP"        },
222 #endif
223 #ifdef PR_CAPBSET_READ
224         { PR_CAPBSET_READ,      "PR_CAPBSET_READ"       },
225 #endif
226 #ifdef PR_CAPBSET_DROP
227         { PR_CAPBSET_DROP,      "PR_CAPBSET_DROP"       },
228 #endif
229 #ifdef PR_GET_TSC
230         { PR_GET_TSC,           "PR_GET_TSC"            },
231 #endif
232 #ifdef PR_SET_TSC
233         { PR_SET_TSC,           "PR_SET_TSC"            },
234 #endif
235 #ifdef PR_GET_SECUREBITS
236         { PR_GET_SECUREBITS,    "PR_GET_SECUREBITS"     },
237 #endif
238 #ifdef PR_SET_SECUREBITS
239         { PR_SET_SECUREBITS,    "PR_SET_SECUREBITS"     },
240 #endif
241 #ifdef PR_SET_TIMERSLACK
242         { PR_SET_TIMERSLACK,    "PR_SET_TIMERSLACK"     },
243 #endif
244 #ifdef PR_GET_TIMERSLACK
245         { PR_GET_TIMERSLACK,    "PR_GET_TIMERSLACK"     },
246 #endif
247 #ifdef PR_TASK_PERF_EVENTS_DISABLE
248         { PR_TASK_PERF_EVENTS_DISABLE,  "PR_TASK_PERF_EVENTS_DISABLE"   },
249 #endif
250 #ifdef PR_TASK_PERF_EVENTS_ENABLE
251         { PR_TASK_PERF_EVENTS_ENABLE,   "PR_TASK_PERF_EVENTS_ENABLE"    },
252 #endif
253 #ifdef PR_MCE_KILL
254         { PR_MCE_KILL,          "PR_MCE_KILL"           },
255 #endif
256 #ifdef PR_MCE_KILL_GET
257         { PR_MCE_KILL_GET,      "PR_MCE_KILL_GET"       },
258 #endif
259 #ifdef PR_SET_MM
260         { PR_SET_MM,            "PR_SET_MM"             },
261 #endif
262 #ifdef PR_SET_PTRACER
263         { PR_SET_PTRACER,       "PR_SET_PTRACER"        },
264 #endif
265 #ifdef PR_SET_CHILD_SUBREAPER
266         { PR_SET_CHILD_SUBREAPER,       "PR_SET_CHILD_SUBREAPER"        },
267 #endif
268 #ifdef PR_GET_CHILD_SUBREAPER
269         { PR_GET_CHILD_SUBREAPER,       "PR_GET_CHILD_SUBREAPER"        },
270 #endif
271 #ifdef PR_SET_NO_NEW_PRIVS
272         { PR_SET_NO_NEW_PRIVS,  "PR_SET_NO_NEW_PRIVS"   },
273 #endif
274 #ifdef PR_GET_NO_NEW_PRIVS
275         { PR_GET_NO_NEW_PRIVS,  "PR_GET_NO_NEW_PRIVS"   },
276 #endif
277 #ifdef PR_GET_TID_ADDRESS
278         { PR_GET_TID_ADDRESS,   "PR_GET_TID_ADDRESS"    },
279 #endif
280         { 0,                    NULL                    },
281 };
282
283 static const char *
284 unalignctl_string(unsigned int ctl)
285 {
286         static char buf[sizeof(int)*2 + 2];
287
288         switch (ctl) {
289 #ifdef PR_UNALIGN_NOPRINT
290                 case PR_UNALIGN_NOPRINT:
291                         return "NOPRINT";
292 #endif
293 #ifdef PR_UNALIGN_SIGBUS
294                 case PR_UNALIGN_SIGBUS:
295                         return "SIGBUS";
296 #endif
297                 default:
298                         break;
299         }
300         sprintf(buf, "%x", ctl);
301         return buf;
302 }
303
304 int
305 sys_prctl(struct tcb *tcp)
306 {
307         int i;
308
309         if (entering(tcp)) {
310                 printxval(prctl_options, tcp->u_arg[0], "PR_???");
311                 switch (tcp->u_arg[0]) {
312 #ifdef PR_GETNSHARE
313                 case PR_GETNSHARE:
314                         break;
315 #endif
316 #ifdef PR_SET_PDEATHSIG
317                 case PR_SET_PDEATHSIG:
318                         tprintf(", %lu", tcp->u_arg[1]);
319                         break;
320 #endif
321 #ifdef PR_GET_PDEATHSIG
322                 case PR_GET_PDEATHSIG:
323                         break;
324 #endif
325 #ifdef PR_SET_DUMPABLE
326                 case PR_SET_DUMPABLE:
327                         tprintf(", %lu", tcp->u_arg[1]);
328                         break;
329 #endif
330 #ifdef PR_GET_DUMPABLE
331                 case PR_GET_DUMPABLE:
332                         break;
333 #endif
334 #ifdef PR_SET_UNALIGN
335                 case PR_SET_UNALIGN:
336                         tprintf(", %s", unalignctl_string(tcp->u_arg[1]));
337                         break;
338 #endif
339 #ifdef PR_GET_UNALIGN
340                 case PR_GET_UNALIGN:
341                         tprintf(", %#lx", tcp->u_arg[1]);
342                         break;
343 #endif
344 #ifdef PR_SET_KEEPCAPS
345                 case PR_SET_KEEPCAPS:
346                         tprintf(", %lu", tcp->u_arg[1]);
347                         break;
348 #endif
349 #ifdef PR_GET_KEEPCAPS
350                 case PR_GET_KEEPCAPS:
351                         break;
352 #endif
353                 default:
354                         for (i = 1; i < tcp->s_ent->nargs; i++)
355                                 tprintf(", %#lx", tcp->u_arg[i]);
356                         break;
357                 }
358         } else {
359                 switch (tcp->u_arg[0]) {
360 #ifdef PR_GET_PDEATHSIG
361                 case PR_GET_PDEATHSIG:
362                         if (umove(tcp, tcp->u_arg[1], &i) < 0)
363                                 tprintf(", %#lx", tcp->u_arg[1]);
364                         else
365                                 tprintf(", {%u}", i);
366                         break;
367 #endif
368 #ifdef PR_GET_DUMPABLE
369                 case PR_GET_DUMPABLE:
370                         return RVAL_UDECIMAL;
371 #endif
372 #ifdef PR_GET_UNALIGN
373                 case PR_GET_UNALIGN:
374                         if (syserror(tcp) || umove(tcp, tcp->u_arg[1], &i) < 0)
375                                 break;
376                         tcp->auxstr = unalignctl_string(i);
377                         return RVAL_STR;
378 #endif
379 #ifdef PR_GET_KEEPCAPS
380                 case PR_GET_KEEPCAPS:
381                         return RVAL_UDECIMAL;
382 #endif
383                 default:
384                         break;
385                 }
386         }
387         return 0;
388 }
389 #endif /* HAVE_PRCTL */
390
391 int
392 sys_sethostname(struct tcb *tcp)
393 {
394         if (entering(tcp)) {
395                 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
396                 tprintf(", %lu", tcp->u_arg[1]);
397         }
398         return 0;
399 }
400
401 #if defined(ALPHA)
402 int
403 sys_gethostname(struct tcb *tcp)
404 {
405         if (exiting(tcp)) {
406                 if (syserror(tcp))
407                         tprintf("%#lx", tcp->u_arg[0]);
408                 else
409                         printpath(tcp, tcp->u_arg[0]);
410                 tprintf(", %lu", tcp->u_arg[1]);
411         }
412         return 0;
413 }
414 #endif
415
416 int
417 sys_setdomainname(struct tcb *tcp)
418 {
419         if (entering(tcp)) {
420                 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
421                 tprintf(", %lu", tcp->u_arg[1]);
422         }
423         return 0;
424 }
425
426 int
427 sys_exit(struct tcb *tcp)
428 {
429         if (exiting(tcp)) {
430                 fprintf(stderr, "_exit returned!\n");
431                 return -1;
432         }
433         /* special case: we stop tracing this process, finish line now */
434         tprintf("%ld) ", tcp->u_arg[0]);
435         tabto();
436         tprints("= ?\n");
437         line_ended();
438         return 0;
439 }
440
441 /* defines copied from linux/sched.h since we can't include that
442  * ourselves (it conflicts with *lots* of libc includes)
443  */
444 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
445 #define CLONE_VM        0x00000100      /* set if VM shared between processes */
446 #define CLONE_FS        0x00000200      /* set if fs info shared between processes */
447 #define CLONE_FILES     0x00000400      /* set if open files shared between processes */
448 #define CLONE_SIGHAND   0x00000800      /* set if signal handlers shared */
449 #define CLONE_IDLETASK  0x00001000      /* kernel-only flag */
450 #define CLONE_PTRACE    0x00002000      /* set if we want to let tracing continue on the child too */
451 #define CLONE_VFORK     0x00004000      /* set if the parent wants the child to wake it up on mm_release */
452 #define CLONE_PARENT    0x00008000      /* set if we want to have the same parent as the cloner */
453 #define CLONE_THREAD    0x00010000      /* Same thread group? */
454 #define CLONE_NEWNS     0x00020000      /* New namespace group? */
455 #define CLONE_SYSVSEM   0x00040000      /* share system V SEM_UNDO semantics */
456 #define CLONE_SETTLS    0x00080000      /* create a new TLS for the child */
457 #define CLONE_PARENT_SETTID     0x00100000      /* set the TID in the parent */
458 #define CLONE_CHILD_CLEARTID    0x00200000      /* clear the TID in the child */
459 #define CLONE_UNTRACED          0x00800000      /* set if the tracing process can't force CLONE_PTRACE on this clone */
460 #define CLONE_CHILD_SETTID      0x01000000      /* set the TID in the child */
461 #define CLONE_STOPPED           0x02000000      /* Start in stopped state */
462 #define CLONE_NEWUTS            0x04000000      /* New utsname group? */
463 #define CLONE_NEWIPC            0x08000000      /* New ipcs */
464 #define CLONE_NEWUSER           0x10000000      /* New user namespace */
465 #define CLONE_NEWPID            0x20000000      /* New pid namespace */
466 #define CLONE_NEWNET            0x40000000      /* New network namespace */
467 #define CLONE_IO                0x80000000      /* Clone io context */
468
469 static const struct xlat clone_flags[] = {
470         { CLONE_VM,             "CLONE_VM"      },
471         { CLONE_FS,             "CLONE_FS"      },
472         { CLONE_FILES,          "CLONE_FILES"   },
473         { CLONE_SIGHAND,        "CLONE_SIGHAND" },
474         { CLONE_IDLETASK,       "CLONE_IDLETASK" },
475         { CLONE_PTRACE,         "CLONE_PTRACE"  },
476         { CLONE_VFORK,          "CLONE_VFORK"   },
477         { CLONE_PARENT,         "CLONE_PARENT"  },
478         { CLONE_THREAD,         "CLONE_THREAD"  },
479         { CLONE_NEWNS,          "CLONE_NEWNS"   },
480         { CLONE_SYSVSEM,        "CLONE_SYSVSEM" },
481         { CLONE_SETTLS,         "CLONE_SETTLS"  },
482         { CLONE_PARENT_SETTID,  "CLONE_PARENT_SETTID" },
483         { CLONE_CHILD_CLEARTID, "CLONE_CHILD_CLEARTID" },
484         { CLONE_UNTRACED,       "CLONE_UNTRACED" },
485         { CLONE_CHILD_SETTID,   "CLONE_CHILD_SETTID" },
486         { CLONE_STOPPED,        "CLONE_STOPPED" },
487         { CLONE_NEWUTS,         "CLONE_NEWUTS"  },
488         { CLONE_NEWIPC,         "CLONE_NEWIPC"  },
489         { CLONE_NEWUSER,        "CLONE_NEWUSER" },
490         { CLONE_NEWPID,         "CLONE_NEWPID"  },
491         { CLONE_NEWNET,         "CLONE_NEWNET"  },
492         { CLONE_IO,             "CLONE_IO"      },
493         { 0,                    NULL            },
494 };
495
496 #ifdef I386
497 # include <asm/ldt.h>
498 #  ifdef HAVE_STRUCT_USER_DESC
499 #   define modify_ldt_ldt_s user_desc
500 #  endif
501 extern void print_ldt_entry();
502 #endif
503
504 #if defined IA64
505 # define ARG_FLAGS      0
506 # define ARG_STACK      1
507 # define ARG_STACKSIZE  (tcp->scno == SYS_clone2 ? 2 : -1)
508 # define ARG_PTID       (tcp->scno == SYS_clone2 ? 3 : 2)
509 # define ARG_CTID       (tcp->scno == SYS_clone2 ? 4 : 3)
510 # define ARG_TLS        (tcp->scno == SYS_clone2 ? 5 : 4)
511 #elif defined S390 || defined S390X || defined CRISV10 || defined CRISV32
512 # define ARG_STACK      0
513 # define ARG_FLAGS      1
514 # define ARG_PTID       2
515 # define ARG_CTID       3
516 # define ARG_TLS        4
517 #elif defined X86_64 || defined X32 || defined ALPHA || defined TILE \
518    || defined OR1K
519 # define ARG_FLAGS      0
520 # define ARG_STACK      1
521 # define ARG_PTID       2
522 # define ARG_CTID       3
523 # define ARG_TLS        4
524 #else
525 # define ARG_FLAGS      0
526 # define ARG_STACK      1
527 # define ARG_PTID       2
528 # define ARG_TLS        3
529 # define ARG_CTID       4
530 #endif
531
532 int
533 sys_clone(struct tcb *tcp)
534 {
535         if (exiting(tcp)) {
536                 const char *sep = "|";
537                 unsigned long flags = tcp->u_arg[ARG_FLAGS];
538                 tprintf("child_stack=%#lx, ", tcp->u_arg[ARG_STACK]);
539 #ifdef ARG_STACKSIZE
540                 if (ARG_STACKSIZE != -1)
541                         tprintf("stack_size=%#lx, ",
542                                 tcp->u_arg[ARG_STACKSIZE]);
543 #endif
544                 tprints("flags=");
545                 if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
546                         sep = "";
547                 if ((flags & CSIGNAL) != 0)
548                         tprintf("%s%s", sep, signame(flags & CSIGNAL));
549                 if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
550                               |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
551                         return 0;
552                 if (flags & CLONE_PARENT_SETTID)
553                         tprintf(", parent_tidptr=%#lx", tcp->u_arg[ARG_PTID]);
554                 if (flags & CLONE_SETTLS) {
555 #ifdef I386
556                         struct modify_ldt_ldt_s copy;
557                         if (umove(tcp, tcp->u_arg[ARG_TLS], &copy) != -1) {
558                                 tprintf(", {entry_number:%d, ",
559                                         copy.entry_number);
560                                 if (!verbose(tcp))
561                                         tprints("...}");
562                                 else
563                                         print_ldt_entry(&copy);
564                         }
565                         else
566 #endif
567                                 tprintf(", tls=%#lx", tcp->u_arg[ARG_TLS]);
568                 }
569                 if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID))
570                         tprintf(", child_tidptr=%#lx", tcp->u_arg[ARG_CTID]);
571         }
572         return 0;
573 }
574
575 int
576 sys_unshare(struct tcb *tcp)
577 {
578         if (entering(tcp))
579                 printflags(clone_flags, tcp->u_arg[0], "CLONE_???");
580         return 0;
581 }
582
583 int
584 sys_fork(struct tcb *tcp)
585 {
586         if (exiting(tcp))
587                 return RVAL_UDECIMAL;
588         return 0;
589 }
590
591 int
592 sys_vfork(struct tcb *tcp)
593 {
594         if (exiting(tcp))
595                 return RVAL_UDECIMAL;
596         return 0;
597 }
598
599 int sys_getuid(struct tcb *tcp)
600 {
601         if (exiting(tcp))
602                 tcp->u_rval = (uid_t) tcp->u_rval;
603         return RVAL_UDECIMAL;
604 }
605
606 int sys_setfsuid(struct tcb *tcp)
607 {
608         if (entering(tcp))
609                 tprintf("%u", (uid_t) tcp->u_arg[0]);
610         else
611                 tcp->u_rval = (uid_t) tcp->u_rval;
612         return RVAL_UDECIMAL;
613 }
614
615 int
616 sys_setuid(struct tcb *tcp)
617 {
618         if (entering(tcp)) {
619                 tprintf("%u", (uid_t) tcp->u_arg[0]);
620         }
621         return 0;
622 }
623
624 int
625 sys_getresuid(struct tcb *tcp)
626 {
627         if (exiting(tcp)) {
628                 __kernel_uid_t uid;
629                 if (syserror(tcp))
630                         tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
631                                 tcp->u_arg[1], tcp->u_arg[2]);
632                 else {
633                         if (umove(tcp, tcp->u_arg[0], &uid) < 0)
634                                 tprintf("%#lx, ", tcp->u_arg[0]);
635                         else
636                                 tprintf("[%lu], ", (unsigned long) uid);
637                         if (umove(tcp, tcp->u_arg[1], &uid) < 0)
638                                 tprintf("%#lx, ", tcp->u_arg[1]);
639                         else
640                                 tprintf("[%lu], ", (unsigned long) uid);
641                         if (umove(tcp, tcp->u_arg[2], &uid) < 0)
642                                 tprintf("%#lx", tcp->u_arg[2]);
643                         else
644                                 tprintf("[%lu]", (unsigned long) uid);
645                 }
646         }
647         return 0;
648 }
649
650 int
651 sys_setreuid(struct tcb *tcp)
652 {
653         if (entering(tcp)) {
654                 printuid("", tcp->u_arg[0]);
655                 printuid(", ", tcp->u_arg[1]);
656         }
657         return 0;
658 }
659
660 int
661 sys_setresuid(struct tcb *tcp)
662 {
663         if (entering(tcp)) {
664                 printuid("", tcp->u_arg[0]);
665                 printuid(", ", tcp->u_arg[1]);
666                 printuid(", ", tcp->u_arg[2]);
667         }
668         return 0;
669 }
670
671 int
672 sys_setgroups(struct tcb *tcp)
673 {
674         if (entering(tcp)) {
675                 unsigned long len, size, start, cur, end, abbrev_end;
676                 GETGROUPS_T gid;
677                 int failed = 0;
678
679                 len = tcp->u_arg[0];
680                 tprintf("%lu, ", len);
681                 if (len == 0) {
682                         tprints("[]");
683                         return 0;
684                 }
685                 start = tcp->u_arg[1];
686                 if (start == 0) {
687                         tprints("NULL");
688                         return 0;
689                 }
690                 size = len * sizeof(gid);
691                 end = start + size;
692                 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
693                         tprintf("%#lx", start);
694                         return 0;
695                 }
696                 if (abbrev(tcp)) {
697                         abbrev_end = start + max_strlen * sizeof(gid);
698                         if (abbrev_end < start)
699                                 abbrev_end = end;
700                 } else {
701                         abbrev_end = end;
702                 }
703                 tprints("[");
704                 for (cur = start; cur < end; cur += sizeof(gid)) {
705                         if (cur > start)
706                                 tprints(", ");
707                         if (cur >= abbrev_end) {
708                                 tprints("...");
709                                 break;
710                         }
711                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
712                                 tprints("?");
713                                 failed = 1;
714                                 break;
715                         }
716                         tprintf("%lu", (unsigned long) gid);
717                 }
718                 tprints("]");
719                 if (failed)
720                         tprintf(" %#lx", tcp->u_arg[1]);
721         }
722         return 0;
723 }
724
725 int
726 sys_getgroups(struct tcb *tcp)
727 {
728         unsigned long len;
729
730         if (entering(tcp)) {
731                 len = tcp->u_arg[0];
732                 tprintf("%lu, ", len);
733         } else {
734                 unsigned long size, start, cur, end, abbrev_end;
735                 GETGROUPS_T gid;
736                 int failed = 0;
737
738                 len = tcp->u_rval;
739                 if (len == 0) {
740                         tprints("[]");
741                         return 0;
742                 }
743                 start = tcp->u_arg[1];
744                 if (start == 0) {
745                         tprints("NULL");
746                         return 0;
747                 }
748                 if (tcp->u_arg[0] == 0) {
749                         tprintf("%#lx", start);
750                         return 0;
751                 }
752                 size = len * sizeof(gid);
753                 end = start + size;
754                 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
755                     size / sizeof(gid) != len || end < start) {
756                         tprintf("%#lx", start);
757                         return 0;
758                 }
759                 if (abbrev(tcp)) {
760                         abbrev_end = start + max_strlen * sizeof(gid);
761                         if (abbrev_end < start)
762                                 abbrev_end = end;
763                 } else {
764                         abbrev_end = end;
765                 }
766                 tprints("[");
767                 for (cur = start; cur < end; cur += sizeof(gid)) {
768                         if (cur > start)
769                                 tprints(", ");
770                         if (cur >= abbrev_end) {
771                                 tprints("...");
772                                 break;
773                         }
774                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
775                                 tprints("?");
776                                 failed = 1;
777                                 break;
778                         }
779                         tprintf("%lu", (unsigned long) gid);
780                 }
781                 tprints("]");
782                 if (failed)
783                         tprintf(" %#lx", tcp->u_arg[1]);
784         }
785         return 0;
786 }
787
788 int
789 sys_setgroups32(struct tcb *tcp)
790 {
791         if (entering(tcp)) {
792                 unsigned long len, size, start, cur, end, abbrev_end;
793                 GETGROUPS32_T gid;
794                 int failed = 0;
795
796                 len = tcp->u_arg[0];
797                 tprintf("%lu, ", len);
798                 if (len == 0) {
799                         tprints("[]");
800                         return 0;
801                 }
802                 start = tcp->u_arg[1];
803                 if (start == 0) {
804                         tprints("NULL");
805                         return 0;
806                 }
807                 size = len * sizeof(gid);
808                 end = start + size;
809                 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
810                         tprintf("%#lx", start);
811                         return 0;
812                 }
813                 if (abbrev(tcp)) {
814                         abbrev_end = start + max_strlen * sizeof(gid);
815                         if (abbrev_end < start)
816                                 abbrev_end = end;
817                 } else {
818                         abbrev_end = end;
819                 }
820                 tprints("[");
821                 for (cur = start; cur < end; cur += sizeof(gid)) {
822                         if (cur > start)
823                                 tprints(", ");
824                         if (cur >= abbrev_end) {
825                                 tprints("...");
826                                 break;
827                         }
828                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
829                                 tprints("?");
830                                 failed = 1;
831                                 break;
832                         }
833                         tprintf("%lu", (unsigned long) gid);
834                 }
835                 tprints("]");
836                 if (failed)
837                         tprintf(" %#lx", tcp->u_arg[1]);
838         }
839         return 0;
840 }
841
842 int
843 sys_getgroups32(struct tcb *tcp)
844 {
845         unsigned long len;
846
847         if (entering(tcp)) {
848                 len = tcp->u_arg[0];
849                 tprintf("%lu, ", len);
850         } else {
851                 unsigned long size, start, cur, end, abbrev_end;
852                 GETGROUPS32_T gid;
853                 int failed = 0;
854
855                 len = tcp->u_rval;
856                 if (len == 0) {
857                         tprints("[]");
858                         return 0;
859                 }
860                 start = tcp->u_arg[1];
861                 if (start == 0) {
862                         tprints("NULL");
863                         return 0;
864                 }
865                 size = len * sizeof(gid);
866                 end = start + size;
867                 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
868                     size / sizeof(gid) != len || end < start) {
869                         tprintf("%#lx", start);
870                         return 0;
871                 }
872                 if (abbrev(tcp)) {
873                         abbrev_end = start + max_strlen * sizeof(gid);
874                         if (abbrev_end < start)
875                                 abbrev_end = end;
876                 } else {
877                         abbrev_end = end;
878                 }
879                 tprints("[");
880                 for (cur = start; cur < end; cur += sizeof(gid)) {
881                         if (cur > start)
882                                 tprints(", ");
883                         if (cur >= abbrev_end) {
884                                 tprints("...");
885                                 break;
886                         }
887                         if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) {
888                                 tprints("?");
889                                 failed = 1;
890                                 break;
891                         }
892                         tprintf("%lu", (unsigned long) gid);
893                 }
894                 tprints("]");
895                 if (failed)
896                         tprintf(" %#lx", tcp->u_arg[1]);
897         }
898         return 0;
899 }
900
901 static void
902 printargv(struct tcb *tcp, long addr)
903 {
904         union {
905                 unsigned int p32;
906                 unsigned long p64;
907                 char data[sizeof(long)];
908         } cp;
909         const char *sep;
910         int n = 0;
911         unsigned wordsize = current_wordsize;
912
913         cp.p64 = 1;
914         for (sep = ""; !abbrev(tcp) || n < max_strlen / 2; sep = ", ", ++n) {
915                 if (umoven(tcp, addr, wordsize, cp.data) < 0) {
916                         tprintf("%#lx", addr);
917                         return;
918                 }
919                 if (wordsize == 4)
920                         cp.p64 = cp.p32;
921                 if (cp.p64 == 0)
922                         break;
923                 tprints(sep);
924                 printstr(tcp, cp.p64, -1);
925                 addr += wordsize;
926         }
927         if (cp.p64)
928                 tprintf("%s...", sep);
929 }
930
931 static void
932 printargc(const char *fmt, struct tcb *tcp, long addr)
933 {
934         int count;
935         char *cp;
936
937         for (count = 0; umove(tcp, addr, &cp) >= 0 && cp != NULL; count++) {
938                 addr += sizeof(char *);
939         }
940         tprintf(fmt, count, count == 1 ? "" : "s");
941 }
942
943 #if defined(SPARC) || defined(SPARC64)
944 int
945 sys_execv(struct tcb *tcp)
946 {
947         if (entering(tcp)) {
948                 printpath(tcp, tcp->u_arg[0]);
949                 if (!verbose(tcp))
950                         tprintf(", %#lx", tcp->u_arg[1]);
951                 else {
952                         tprints(", [");
953                         printargv(tcp, tcp->u_arg[1]);
954                         tprints("]");
955                 }
956         }
957         return 0;
958 }
959 #endif
960
961 int
962 sys_execve(struct tcb *tcp)
963 {
964         if (entering(tcp)) {
965                 printpath(tcp, tcp->u_arg[0]);
966                 if (!verbose(tcp))
967                         tprintf(", %#lx", tcp->u_arg[1]);
968                 else {
969                         tprints(", [");
970                         printargv(tcp, tcp->u_arg[1]);
971                         tprints("]");
972                 }
973                 if (!verbose(tcp))
974                         tprintf(", %#lx", tcp->u_arg[2]);
975                 else if (abbrev(tcp))
976                         printargc(", [/* %d var%s */]", tcp, tcp->u_arg[2]);
977                 else {
978                         tprints(", [");
979                         printargv(tcp, tcp->u_arg[2]);
980                         tprints("]");
981                 }
982         }
983         return 0;
984 }
985
986 #ifndef __WNOTHREAD
987 #define __WNOTHREAD     0x20000000
988 #endif
989 #ifndef __WALL
990 #define __WALL          0x40000000
991 #endif
992 #ifndef __WCLONE
993 #define __WCLONE        0x80000000
994 #endif
995
996 static const struct xlat wait4_options[] = {
997         { WNOHANG,      "WNOHANG"       },
998 #ifndef WSTOPPED
999         { WUNTRACED,    "WUNTRACED"     },
1000 #endif
1001 #ifdef WEXITED
1002         { WEXITED,      "WEXITED"       },
1003 #endif
1004 #ifdef WTRAPPED
1005         { WTRAPPED,     "WTRAPPED"      },
1006 #endif
1007 #ifdef WSTOPPED
1008         { WSTOPPED,     "WSTOPPED"      },
1009 #endif
1010 #ifdef WCONTINUED
1011         { WCONTINUED,   "WCONTINUED"    },
1012 #endif
1013 #ifdef WNOWAIT
1014         { WNOWAIT,      "WNOWAIT"       },
1015 #endif
1016 #ifdef __WCLONE
1017         { __WCLONE,     "__WCLONE"      },
1018 #endif
1019 #ifdef __WALL
1020         { __WALL,       "__WALL"        },
1021 #endif
1022 #ifdef __WNOTHREAD
1023         { __WNOTHREAD,  "__WNOTHREAD"   },
1024 #endif
1025         { 0,            NULL            },
1026 };
1027
1028 #if !defined WCOREFLAG && defined WCOREFLG
1029 # define WCOREFLAG WCOREFLG
1030 #endif
1031 #ifndef WCOREFLAG
1032 # define WCOREFLAG 0x80
1033 #endif
1034 #ifndef WCOREDUMP
1035 # define WCOREDUMP(status)  ((status) & 0200)
1036 #endif
1037 #ifndef W_STOPCODE
1038 # define W_STOPCODE(sig)  ((sig) << 8 | 0x7f)
1039 #endif
1040 #ifndef W_EXITCODE
1041 # define W_EXITCODE(ret, sig)  ((ret) << 8 | (sig))
1042 #endif
1043
1044 static int
1045 printstatus(int status)
1046 {
1047         int exited = 0;
1048
1049         /*
1050          * Here is a tricky presentation problem.  This solution
1051          * is still not entirely satisfactory but since there
1052          * are no wait status constructors it will have to do.
1053          */
1054         if (WIFSTOPPED(status)) {
1055                 tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s}",
1056                         signame(WSTOPSIG(status)));
1057                 status &= ~W_STOPCODE(WSTOPSIG(status));
1058         }
1059         else if (WIFSIGNALED(status)) {
1060                 tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
1061                         signame(WTERMSIG(status)),
1062                         WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
1063                 status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
1064         }
1065         else if (WIFEXITED(status)) {
1066                 tprintf("[{WIFEXITED(s) && WEXITSTATUS(s) == %d}",
1067                         WEXITSTATUS(status));
1068                 exited = 1;
1069                 status &= ~W_EXITCODE(WEXITSTATUS(status), 0);
1070         }
1071         else {
1072                 tprintf("[%#x]", status);
1073                 return 0;
1074         }
1075
1076         if (status == 0)
1077                 tprints("]");
1078         else
1079                 tprintf(" | %#x]", status);
1080
1081         return exited;
1082 }
1083
1084 static int
1085 printwaitn(struct tcb *tcp, int n, int bitness)
1086 {
1087         int status;
1088
1089         if (entering(tcp)) {
1090                 /* On Linux, kernel-side pid_t is typedef'ed to int
1091                  * on all arches. Also, glibc-2.8 truncates wait3 and wait4
1092                  * pid argument to int on 64bit arches, producing,
1093                  * for example, wait4(4294967295, ...) instead of -1
1094                  * in strace. We have to use int here, not long.
1095                  */
1096                 int pid = tcp->u_arg[0];
1097                 tprintf("%d, ", pid);
1098         } else {
1099                 /* status */
1100                 if (!tcp->u_arg[1])
1101                         tprints("NULL");
1102                 else if (syserror(tcp) || tcp->u_rval == 0)
1103                         tprintf("%#lx", tcp->u_arg[1]);
1104                 else if (umove(tcp, tcp->u_arg[1], &status) < 0)
1105                         tprints("[?]");
1106                 else
1107                         printstatus(status);
1108                 /* options */
1109                 tprints(", ");
1110                 printflags(wait4_options, tcp->u_arg[2], "W???");
1111                 if (n == 4) {
1112                         tprints(", ");
1113                         /* usage */
1114                         if (!tcp->u_arg[3])
1115                                 tprints("NULL");
1116                         else if (tcp->u_rval > 0) {
1117 #ifdef ALPHA
1118                                 if (bitness)
1119                                         printrusage32(tcp, tcp->u_arg[3]);
1120                                 else
1121 #endif
1122                                         printrusage(tcp, tcp->u_arg[3]);
1123                         }
1124                         else
1125                                 tprintf("%#lx", tcp->u_arg[3]);
1126                 }
1127         }
1128         return 0;
1129 }
1130
1131 int
1132 sys_waitpid(struct tcb *tcp)
1133 {
1134         return printwaitn(tcp, 3, 0);
1135 }
1136
1137 int
1138 sys_wait4(struct tcb *tcp)
1139 {
1140         return printwaitn(tcp, 4, 0);
1141 }
1142
1143 #ifdef ALPHA
1144 int
1145 sys_osf_wait4(struct tcb *tcp)
1146 {
1147         return printwaitn(tcp, 4, 1);
1148 }
1149 #endif
1150
1151 static const struct xlat waitid_types[] = {
1152         { P_PID,        "P_PID"         },
1153 #ifdef P_PPID
1154         { P_PPID,       "P_PPID"        },
1155 #endif
1156         { P_PGID,       "P_PGID"        },
1157 #ifdef P_SID
1158         { P_SID,        "P_SID"         },
1159 #endif
1160 #ifdef P_CID
1161         { P_CID,        "P_CID"         },
1162 #endif
1163 #ifdef P_UID
1164         { P_UID,        "P_UID"         },
1165 #endif
1166 #ifdef P_GID
1167         { P_GID,        "P_GID"         },
1168 #endif
1169         { P_ALL,        "P_ALL"         },
1170 #ifdef P_LWPID
1171         { P_LWPID,      "P_LWPID"       },
1172 #endif
1173         { 0,            NULL            },
1174 };
1175
1176 int
1177 sys_waitid(struct tcb *tcp)
1178 {
1179         if (entering(tcp)) {
1180                 printxval(waitid_types, tcp->u_arg[0], "P_???");
1181                 tprintf(", %ld, ", tcp->u_arg[1]);
1182         }
1183         else {
1184                 /* siginfo */
1185                 printsiginfo_at(tcp, tcp->u_arg[2]);
1186                 /* options */
1187                 tprints(", ");
1188                 printflags(wait4_options, tcp->u_arg[3], "W???");
1189                 if (tcp->s_ent->nargs > 4) {
1190                         /* usage */
1191                         tprints(", ");
1192                         if (!tcp->u_arg[4])
1193                                 tprints("NULL");
1194                         else if (tcp->u_error)
1195                                 tprintf("%#lx", tcp->u_arg[4]);
1196                         else
1197                                 printrusage(tcp, tcp->u_arg[4]);
1198                 }
1199         }
1200         return 0;
1201 }
1202
1203 int
1204 sys_uname(struct tcb *tcp)
1205 {
1206         struct utsname uname;
1207
1208         if (exiting(tcp)) {
1209                 if (syserror(tcp) || !verbose(tcp))
1210                         tprintf("%#lx", tcp->u_arg[0]);
1211                 else if (umove(tcp, tcp->u_arg[0], &uname) < 0)
1212                         tprints("{...}");
1213                 else if (!abbrev(tcp)) {
1214                         tprintf("{sysname=\"%s\", nodename=\"%s\", ",
1215                                 uname.sysname, uname.nodename);
1216                         tprintf("release=\"%s\", version=\"%s\", ",
1217                                 uname.release, uname.version);
1218                         tprintf("machine=\"%s\"", uname.machine);
1219 #ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
1220                         tprintf(", domainname=\"%s\"", uname.domainname);
1221 #endif
1222                         tprints("}");
1223                 }
1224                 else
1225                         tprintf("{sys=\"%s\", node=\"%s\", ...}",
1226                                 uname.sysname, uname.nodename);
1227         }
1228         return 0;
1229 }
1230
1231 static const struct xlat ptrace_cmds[] = {
1232         { PTRACE_TRACEME,       "PTRACE_TRACEME"        },
1233         { PTRACE_PEEKTEXT,      "PTRACE_PEEKTEXT"       },
1234         { PTRACE_PEEKDATA,      "PTRACE_PEEKDATA"       },
1235         { PTRACE_PEEKUSER,      "PTRACE_PEEKUSER"       },
1236         { PTRACE_POKETEXT,      "PTRACE_POKETEXT"       },
1237         { PTRACE_POKEDATA,      "PTRACE_POKEDATA"       },
1238         { PTRACE_POKEUSER,      "PTRACE_POKEUSER"       },
1239         { PTRACE_CONT,          "PTRACE_CONT"           },
1240         { PTRACE_KILL,          "PTRACE_KILL"           },
1241         { PTRACE_SINGLESTEP,    "PTRACE_SINGLESTEP"     },
1242         { PTRACE_ATTACH,        "PTRACE_ATTACH"         },
1243         { PTRACE_DETACH,        "PTRACE_DETACH"         },
1244 #ifdef PTRACE_GETREGS
1245         { PTRACE_GETREGS,       "PTRACE_GETREGS"        },
1246 #endif
1247 #ifdef PTRACE_SETREGS
1248         { PTRACE_SETREGS,       "PTRACE_SETREGS"        },
1249 #endif
1250 #ifdef PTRACE_GETFPREGS
1251         { PTRACE_GETFPREGS,     "PTRACE_GETFPREGS"      },
1252 #endif
1253 #ifdef PTRACE_SETFPREGS
1254         { PTRACE_SETFPREGS,     "PTRACE_SETFPREGS"      },
1255 #endif
1256 #ifdef PTRACE_GETFPXREGS
1257         { PTRACE_GETFPXREGS,    "PTRACE_GETFPXREGS"     },
1258 #endif
1259 #ifdef PTRACE_SETFPXREGS
1260         { PTRACE_SETFPXREGS,    "PTRACE_SETFPXREGS"     },
1261 #endif
1262 #ifdef PTRACE_GETVRREGS
1263         { PTRACE_GETVRREGS,     "PTRACE_GETVRREGS"      },
1264 #endif
1265 #ifdef PTRACE_SETVRREGS
1266         { PTRACE_SETVRREGS,     "PTRACE_SETVRREGS"      },
1267 #endif
1268 #ifdef PTRACE_SETOPTIONS
1269         { PTRACE_SETOPTIONS,    "PTRACE_SETOPTIONS"     },
1270 #endif
1271 #ifdef PTRACE_GETEVENTMSG
1272         { PTRACE_GETEVENTMSG,   "PTRACE_GETEVENTMSG"    },
1273 #endif
1274 #ifdef PTRACE_GETSIGINFO
1275         { PTRACE_GETSIGINFO,    "PTRACE_GETSIGINFO"     },
1276 #endif
1277 #ifdef PTRACE_SETSIGINFO
1278         { PTRACE_SETSIGINFO,    "PTRACE_SETSIGINFO"     },
1279 #endif
1280 #ifdef PTRACE_GETREGSET
1281         { PTRACE_GETREGSET,     "PTRACE_GETREGSET"      },
1282 #endif
1283 #ifdef PTRACE_SETREGSET
1284         { PTRACE_SETREGSET,     "PTRACE_SETREGSET"      },
1285 #endif
1286 #ifdef PTRACE_SET_SYSCALL
1287         { PTRACE_SET_SYSCALL,   "PTRACE_SET_SYSCALL"    },
1288 #endif
1289 #ifdef PTRACE_SEIZE
1290         { PTRACE_SEIZE,         "PTRACE_SEIZE"          },
1291 #endif
1292 #ifdef PTRACE_INTERRUPT
1293         { PTRACE_INTERRUPT,     "PTRACE_INTERRUPT"      },
1294 #endif
1295 #ifdef PTRACE_LISTEN
1296         { PTRACE_LISTEN,        "PTRACE_LISTEN"         },
1297 #endif
1298         { PTRACE_SYSCALL,       "PTRACE_SYSCALL"        },
1299
1300         { 0,                    NULL                    },
1301 };
1302
1303 #ifdef PTRACE_SETOPTIONS
1304 static const struct xlat ptrace_setoptions_flags[] = {
1305 # ifdef PTRACE_O_TRACESYSGOOD
1306         { PTRACE_O_TRACESYSGOOD,"PTRACE_O_TRACESYSGOOD" },
1307 # endif
1308 # ifdef PTRACE_O_TRACEFORK
1309         { PTRACE_O_TRACEFORK,   "PTRACE_O_TRACEFORK"    },
1310 # endif
1311 # ifdef PTRACE_O_TRACEVFORK
1312         { PTRACE_O_TRACEVFORK,  "PTRACE_O_TRACEVFORK"   },
1313 # endif
1314 # ifdef PTRACE_O_TRACECLONE
1315         { PTRACE_O_TRACECLONE,  "PTRACE_O_TRACECLONE"   },
1316 # endif
1317 # ifdef PTRACE_O_TRACEEXEC
1318         { PTRACE_O_TRACEEXEC,   "PTRACE_O_TRACEEXEC"    },
1319 # endif
1320 # ifdef PTRACE_O_TRACEVFORKDONE
1321         { PTRACE_O_TRACEVFORKDONE,"PTRACE_O_TRACEVFORKDONE"},
1322 # endif
1323 # ifdef PTRACE_O_TRACEEXIT
1324         { PTRACE_O_TRACEEXIT,   "PTRACE_O_TRACEEXIT"    },
1325 # endif
1326         { 0,                    NULL                    },
1327 };
1328 #endif /* PTRACE_SETOPTIONS */
1329
1330 static const struct xlat nt_descriptor_types[] = {
1331 #ifdef NT_PRSTATUS
1332         { NT_PRSTATUS,          "NT_PRSTATUS" },
1333 #endif
1334 #ifdef NT_FPREGSET
1335         { NT_FPREGSET,          "NT_FPREGSET" },
1336 #endif
1337 #ifdef NT_PRPSINFO
1338         { NT_PRPSINFO,          "NT_PRPSINFO" },
1339 #endif
1340 #ifdef NT_PRXREG
1341         { NT_PRXREG,            "NT_PRXREG" },
1342 #endif
1343 #ifdef NT_TASKSTRUCT
1344         { NT_TASKSTRUCT,        "NT_TASKSTRUCT" },
1345 #endif
1346 #ifdef NT_PLATFORM
1347         { NT_PLATFORM,          "NT_PLATFORM" },
1348 #endif
1349 #ifdef NT_AUXV
1350         { NT_AUXV,              "NT_AUXV" },
1351 #endif
1352 #ifdef NT_GWINDOWS
1353         { NT_GWINDOWS,          "NT_GWINDOWS" },
1354 #endif
1355 #ifdef NT_ASRS
1356         { NT_ASRS,              "NT_ASRS" },
1357 #endif
1358 #ifdef NT_PSTATUS
1359         { NT_PSTATUS,           "NT_PSTATUS" },
1360 #endif
1361 #ifdef NT_PSINFO
1362         { NT_PSINFO,            "NT_PSINFO" },
1363 #endif
1364 #ifdef NT_PRCRED
1365         { NT_PRCRED,            "NT_PRCRED" },
1366 #endif
1367 #ifdef NT_UTSNAME
1368         { NT_UTSNAME,           "NT_UTSNAME" },
1369 #endif
1370 #ifdef NT_LWPSTATUS
1371         { NT_LWPSTATUS,         "NT_LWPSTATUS" },
1372 #endif
1373 #ifdef NT_LWPSINFO
1374         { NT_LWPSINFO,          "NT_LWPSINFO" },
1375 #endif
1376 #ifdef NT_PRFPXREG
1377         { NT_PRFPXREG,          "NT_PRFPXREG" },
1378 #endif
1379 #ifdef NT_PRXFPREG
1380         { NT_PRXFPREG,          "NT_PRXFPREG" },
1381 #endif
1382 #ifdef NT_PPC_VMX
1383         { NT_PPC_VMX,           "NT_PPC_VMX" },
1384 #endif
1385 #ifdef NT_PPC_SPE
1386         { NT_PPC_SPE,           "NT_PPC_SPE" },
1387 #endif
1388 #ifdef NT_PPC_VSX
1389         { NT_PPC_VSX,           "NT_PPC_VSX" },
1390 #endif
1391 #ifdef NT_386_TLS
1392         { NT_386_TLS,           "NT_386_TLS" },
1393 #endif
1394 #ifdef NT_386_IOPERM
1395         { NT_386_IOPERM,        "NT_386_IOPERM" },
1396 #endif
1397 #ifdef NT_X86_XSTATE
1398         { NT_X86_XSTATE,        "NT_X86_XSTATE" },
1399 #endif
1400         { 0,                    NULL },
1401 };
1402
1403 #define uoff(member)    offsetof(struct user, member)
1404
1405 const struct xlat struct_user_offsets[] = {
1406 #if defined(S390) || defined(S390X)
1407         { PT_PSWMASK,           "psw_mask"                              },
1408         { PT_PSWADDR,           "psw_addr"                              },
1409         { PT_GPR0,              "gpr0"                                  },
1410         { PT_GPR1,              "gpr1"                                  },
1411         { PT_GPR2,              "gpr2"                                  },
1412         { PT_GPR3,              "gpr3"                                  },
1413         { PT_GPR4,              "gpr4"                                  },
1414         { PT_GPR5,              "gpr5"                                  },
1415         { PT_GPR6,              "gpr6"                                  },
1416         { PT_GPR7,              "gpr7"                                  },
1417         { PT_GPR8,              "gpr8"                                  },
1418         { PT_GPR9,              "gpr9"                                  },
1419         { PT_GPR10,             "gpr10"                                 },
1420         { PT_GPR11,             "gpr11"                                 },
1421         { PT_GPR12,             "gpr12"                                 },
1422         { PT_GPR13,             "gpr13"                                 },
1423         { PT_GPR14,             "gpr14"                                 },
1424         { PT_GPR15,             "gpr15"                                 },
1425         { PT_ACR0,              "acr0"                                  },
1426         { PT_ACR1,              "acr1"                                  },
1427         { PT_ACR2,              "acr2"                                  },
1428         { PT_ACR3,              "acr3"                                  },
1429         { PT_ACR4,              "acr4"                                  },
1430         { PT_ACR5,              "acr5"                                  },
1431         { PT_ACR6,              "acr6"                                  },
1432         { PT_ACR7,              "acr7"                                  },
1433         { PT_ACR8,              "acr8"                                  },
1434         { PT_ACR9,              "acr9"                                  },
1435         { PT_ACR10,             "acr10"                                 },
1436         { PT_ACR11,             "acr11"                                 },
1437         { PT_ACR12,             "acr12"                                 },
1438         { PT_ACR13,             "acr13"                                 },
1439         { PT_ACR14,             "acr14"                                 },
1440         { PT_ACR15,             "acr15"                                 },
1441         { PT_ORIGGPR2,          "orig_gpr2"                             },
1442         { PT_FPC,               "fpc"                                   },
1443 #if defined(S390)
1444         { PT_FPR0_HI,           "fpr0.hi"                               },
1445         { PT_FPR0_LO,           "fpr0.lo"                               },
1446         { PT_FPR1_HI,           "fpr1.hi"                               },
1447         { PT_FPR1_LO,           "fpr1.lo"                               },
1448         { PT_FPR2_HI,           "fpr2.hi"                               },
1449         { PT_FPR2_LO,           "fpr2.lo"                               },
1450         { PT_FPR3_HI,           "fpr3.hi"                               },
1451         { PT_FPR3_LO,           "fpr3.lo"                               },
1452         { PT_FPR4_HI,           "fpr4.hi"                               },
1453         { PT_FPR4_LO,           "fpr4.lo"                               },
1454         { PT_FPR5_HI,           "fpr5.hi"                               },
1455         { PT_FPR5_LO,           "fpr5.lo"                               },
1456         { PT_FPR6_HI,           "fpr6.hi"                               },
1457         { PT_FPR6_LO,           "fpr6.lo"                               },
1458         { PT_FPR7_HI,           "fpr7.hi"                               },
1459         { PT_FPR7_LO,           "fpr7.lo"                               },
1460         { PT_FPR8_HI,           "fpr8.hi"                               },
1461         { PT_FPR8_LO,           "fpr8.lo"                               },
1462         { PT_FPR9_HI,           "fpr9.hi"                               },
1463         { PT_FPR9_LO,           "fpr9.lo"                               },
1464         { PT_FPR10_HI,          "fpr10.hi"                              },
1465         { PT_FPR10_LO,          "fpr10.lo"                              },
1466         { PT_FPR11_HI,          "fpr11.hi"                              },
1467         { PT_FPR11_LO,          "fpr11.lo"                              },
1468         { PT_FPR12_HI,          "fpr12.hi"                              },
1469         { PT_FPR12_LO,          "fpr12.lo"                              },
1470         { PT_FPR13_HI,          "fpr13.hi"                              },
1471         { PT_FPR13_LO,          "fpr13.lo"                              },
1472         { PT_FPR14_HI,          "fpr14.hi"                              },
1473         { PT_FPR14_LO,          "fpr14.lo"                              },
1474         { PT_FPR15_HI,          "fpr15.hi"                              },
1475         { PT_FPR15_LO,          "fpr15.lo"                              },
1476 #endif
1477 #if defined(S390X)
1478         { PT_FPR0,              "fpr0"                                  },
1479         { PT_FPR1,              "fpr1"                                  },
1480         { PT_FPR2,              "fpr2"                                  },
1481         { PT_FPR3,              "fpr3"                                  },
1482         { PT_FPR4,              "fpr4"                                  },
1483         { PT_FPR5,              "fpr5"                                  },
1484         { PT_FPR6,              "fpr6"                                  },
1485         { PT_FPR7,              "fpr7"                                  },
1486         { PT_FPR8,              "fpr8"                                  },
1487         { PT_FPR9,              "fpr9"                                  },
1488         { PT_FPR10,             "fpr10"                                 },
1489         { PT_FPR11,             "fpr11"                                 },
1490         { PT_FPR12,             "fpr12"                                 },
1491         { PT_FPR13,             "fpr13"                                 },
1492         { PT_FPR14,             "fpr14"                                 },
1493         { PT_FPR15,             "fpr15"                                 },
1494 #endif
1495         { PT_CR_9,              "cr9"                                   },
1496         { PT_CR_10,             "cr10"                                  },
1497         { PT_CR_11,             "cr11"                                  },
1498         { PT_IEEE_IP,           "ieee_exception_ip"                     },
1499 #elif defined(SPARC)
1500         /* XXX No support for these offsets yet. */
1501 #elif defined(HPPA)
1502         /* XXX No support for these offsets yet. */
1503 #elif defined(POWERPC)
1504 # ifndef PT_ORIG_R3
1505 #  define PT_ORIG_R3 34
1506 # endif
1507 # define REGSIZE (sizeof(unsigned long))
1508         { REGSIZE*PT_R0,                "r0"                            },
1509         { REGSIZE*PT_R1,                "r1"                            },
1510         { REGSIZE*PT_R2,                "r2"                            },
1511         { REGSIZE*PT_R3,                "r3"                            },
1512         { REGSIZE*PT_R4,                "r4"                            },
1513         { REGSIZE*PT_R5,                "r5"                            },
1514         { REGSIZE*PT_R6,                "r6"                            },
1515         { REGSIZE*PT_R7,                "r7"                            },
1516         { REGSIZE*PT_R8,                "r8"                            },
1517         { REGSIZE*PT_R9,                "r9"                            },
1518         { REGSIZE*PT_R10,               "r10"                           },
1519         { REGSIZE*PT_R11,               "r11"                           },
1520         { REGSIZE*PT_R12,               "r12"                           },
1521         { REGSIZE*PT_R13,               "r13"                           },
1522         { REGSIZE*PT_R14,               "r14"                           },
1523         { REGSIZE*PT_R15,               "r15"                           },
1524         { REGSIZE*PT_R16,               "r16"                           },
1525         { REGSIZE*PT_R17,               "r17"                           },
1526         { REGSIZE*PT_R18,               "r18"                           },
1527         { REGSIZE*PT_R19,               "r19"                           },
1528         { REGSIZE*PT_R20,               "r20"                           },
1529         { REGSIZE*PT_R21,               "r21"                           },
1530         { REGSIZE*PT_R22,               "r22"                           },
1531         { REGSIZE*PT_R23,               "r23"                           },
1532         { REGSIZE*PT_R24,               "r24"                           },
1533         { REGSIZE*PT_R25,               "r25"                           },
1534         { REGSIZE*PT_R26,               "r26"                           },
1535         { REGSIZE*PT_R27,               "r27"                           },
1536         { REGSIZE*PT_R28,               "r28"                           },
1537         { REGSIZE*PT_R29,               "r29"                           },
1538         { REGSIZE*PT_R30,               "r30"                           },
1539         { REGSIZE*PT_R31,               "r31"                           },
1540         { REGSIZE*PT_NIP,               "NIP"                           },
1541         { REGSIZE*PT_MSR,               "MSR"                           },
1542         { REGSIZE*PT_ORIG_R3,           "ORIG_R3"                       },
1543         { REGSIZE*PT_CTR,               "CTR"                           },
1544         { REGSIZE*PT_LNK,               "LNK"                           },
1545         { REGSIZE*PT_XER,               "XER"                           },
1546         { REGSIZE*PT_CCR,               "CCR"                           },
1547         { REGSIZE*PT_FPR0,              "FPR0"                          },
1548 # undef REGSIZE
1549 #elif defined(ALPHA)
1550         { 0,                    "r0"                                    },
1551         { 1,                    "r1"                                    },
1552         { 2,                    "r2"                                    },
1553         { 3,                    "r3"                                    },
1554         { 4,                    "r4"                                    },
1555         { 5,                    "r5"                                    },
1556         { 6,                    "r6"                                    },
1557         { 7,                    "r7"                                    },
1558         { 8,                    "r8"                                    },
1559         { 9,                    "r9"                                    },
1560         { 10,                   "r10"                                   },
1561         { 11,                   "r11"                                   },
1562         { 12,                   "r12"                                   },
1563         { 13,                   "r13"                                   },
1564         { 14,                   "r14"                                   },
1565         { 15,                   "r15"                                   },
1566         { 16,                   "r16"                                   },
1567         { 17,                   "r17"                                   },
1568         { 18,                   "r18"                                   },
1569         { 19,                   "r19"                                   },
1570         { 20,                   "r20"                                   },
1571         { 21,                   "r21"                                   },
1572         { 22,                   "r22"                                   },
1573         { 23,                   "r23"                                   },
1574         { 24,                   "r24"                                   },
1575         { 25,                   "r25"                                   },
1576         { 26,                   "r26"                                   },
1577         { 27,                   "r27"                                   },
1578         { 28,                   "r28"                                   },
1579         { 29,                   "gp"                                    },
1580         { 30,                   "fp"                                    },
1581         { 31,                   "zero"                                  },
1582         { 32,                   "fp0"                                   },
1583         { 33,                   "fp"                                    },
1584         { 34,                   "fp2"                                   },
1585         { 35,                   "fp3"                                   },
1586         { 36,                   "fp4"                                   },
1587         { 37,                   "fp5"                                   },
1588         { 38,                   "fp6"                                   },
1589         { 39,                   "fp7"                                   },
1590         { 40,                   "fp8"                                   },
1591         { 41,                   "fp9"                                   },
1592         { 42,                   "fp10"                                  },
1593         { 43,                   "fp11"                                  },
1594         { 44,                   "fp12"                                  },
1595         { 45,                   "fp13"                                  },
1596         { 46,                   "fp14"                                  },
1597         { 47,                   "fp15"                                  },
1598         { 48,                   "fp16"                                  },
1599         { 49,                   "fp17"                                  },
1600         { 50,                   "fp18"                                  },
1601         { 51,                   "fp19"                                  },
1602         { 52,                   "fp20"                                  },
1603         { 53,                   "fp21"                                  },
1604         { 54,                   "fp22"                                  },
1605         { 55,                   "fp23"                                  },
1606         { 56,                   "fp24"                                  },
1607         { 57,                   "fp25"                                  },
1608         { 58,                   "fp26"                                  },
1609         { 59,                   "fp27"                                  },
1610         { 60,                   "fp28"                                  },
1611         { 61,                   "fp29"                                  },
1612         { 62,                   "fp30"                                  },
1613         { 63,                   "fp31"                                  },
1614         { 64,                   "pc"                                    },
1615 #elif defined(IA64)
1616         { PT_F32, "f32" }, { PT_F33, "f33" }, { PT_F34, "f34" },
1617         { PT_F35, "f35" }, { PT_F36, "f36" }, { PT_F37, "f37" },
1618         { PT_F38, "f38" }, { PT_F39, "f39" }, { PT_F40, "f40" },
1619         { PT_F41, "f41" }, { PT_F42, "f42" }, { PT_F43, "f43" },
1620         { PT_F44, "f44" }, { PT_F45, "f45" }, { PT_F46, "f46" },
1621         { PT_F47, "f47" }, { PT_F48, "f48" }, { PT_F49, "f49" },
1622         { PT_F50, "f50" }, { PT_F51, "f51" }, { PT_F52, "f52" },
1623         { PT_F53, "f53" }, { PT_F54, "f54" }, { PT_F55, "f55" },
1624         { PT_F56, "f56" }, { PT_F57, "f57" }, { PT_F58, "f58" },
1625         { PT_F59, "f59" }, { PT_F60, "f60" }, { PT_F61, "f61" },
1626         { PT_F62, "f62" }, { PT_F63, "f63" }, { PT_F64, "f64" },
1627         { PT_F65, "f65" }, { PT_F66, "f66" }, { PT_F67, "f67" },
1628         { PT_F68, "f68" }, { PT_F69, "f69" }, { PT_F70, "f70" },
1629         { PT_F71, "f71" }, { PT_F72, "f72" }, { PT_F73, "f73" },
1630         { PT_F74, "f74" }, { PT_F75, "f75" }, { PT_F76, "f76" },
1631         { PT_F77, "f77" }, { PT_F78, "f78" }, { PT_F79, "f79" },
1632         { PT_F80, "f80" }, { PT_F81, "f81" }, { PT_F82, "f82" },
1633         { PT_F83, "f83" }, { PT_F84, "f84" }, { PT_F85, "f85" },
1634         { PT_F86, "f86" }, { PT_F87, "f87" }, { PT_F88, "f88" },
1635         { PT_F89, "f89" }, { PT_F90, "f90" }, { PT_F91, "f91" },
1636         { PT_F92, "f92" }, { PT_F93, "f93" }, { PT_F94, "f94" },
1637         { PT_F95, "f95" }, { PT_F96, "f96" }, { PT_F97, "f97" },
1638         { PT_F98, "f98" }, { PT_F99, "f99" }, { PT_F100, "f100" },
1639         { PT_F101, "f101" }, { PT_F102, "f102" }, { PT_F103, "f103" },
1640         { PT_F104, "f104" }, { PT_F105, "f105" }, { PT_F106, "f106" },
1641         { PT_F107, "f107" }, { PT_F108, "f108" }, { PT_F109, "f109" },
1642         { PT_F110, "f110" }, { PT_F111, "f111" }, { PT_F112, "f112" },
1643         { PT_F113, "f113" }, { PT_F114, "f114" }, { PT_F115, "f115" },
1644         { PT_F116, "f116" }, { PT_F117, "f117" }, { PT_F118, "f118" },
1645         { PT_F119, "f119" }, { PT_F120, "f120" }, { PT_F121, "f121" },
1646         { PT_F122, "f122" }, { PT_F123, "f123" }, { PT_F124, "f124" },
1647         { PT_F125, "f125" }, { PT_F126, "f126" }, { PT_F127, "f127" },
1648         /* switch stack: */
1649         { PT_F2, "f2" }, { PT_F3, "f3" }, { PT_F4, "f4" },
1650         { PT_F5, "f5" }, { PT_F10, "f10" }, { PT_F11, "f11" },
1651         { PT_F12, "f12" }, { PT_F13, "f13" }, { PT_F14, "f14" },
1652         { PT_F15, "f15" }, { PT_F16, "f16" }, { PT_F17, "f17" },
1653         { PT_F18, "f18" }, { PT_F19, "f19" }, { PT_F20, "f20" },
1654         { PT_F21, "f21" }, { PT_F22, "f22" }, { PT_F23, "f23" },
1655         { PT_F24, "f24" }, { PT_F25, "f25" }, { PT_F26, "f26" },
1656         { PT_F27, "f27" }, { PT_F28, "f28" }, { PT_F29, "f29" },
1657         { PT_F30, "f30" }, { PT_F31, "f31" }, { PT_R4, "r4" },
1658         { PT_R5, "r5" }, { PT_R6, "r6" }, { PT_R7, "r7" },
1659         { PT_B1, "b1" }, { PT_B2, "b2" }, { PT_B3, "b3" },
1660         { PT_B4, "b4" }, { PT_B5, "b5" },
1661         { PT_AR_EC, "ar.ec" }, { PT_AR_LC, "ar.lc" },
1662         /* pt_regs */
1663         { PT_CR_IPSR, "psr" }, { PT_CR_IIP, "ip" },
1664         { PT_CFM, "cfm" }, { PT_AR_UNAT, "ar.unat" },
1665         { PT_AR_PFS, "ar.pfs" }, { PT_AR_RSC, "ar.rsc" },
1666         { PT_AR_RNAT, "ar.rnat" }, { PT_AR_BSPSTORE, "ar.bspstore" },
1667         { PT_PR, "pr" }, { PT_B6, "b6" }, { PT_AR_BSP, "ar.bsp" },
1668         { PT_R1, "r1" }, { PT_R2, "r2" }, { PT_R3, "r3" },
1669         { PT_R12, "r12" }, { PT_R13, "r13" }, { PT_R14, "r14" },
1670         { PT_R15, "r15" }, { PT_R8, "r8" }, { PT_R9, "r9" },
1671         { PT_R10, "r10" }, { PT_R11, "r11" }, { PT_R16, "r16" },
1672         { PT_R17, "r17" }, { PT_R18, "r18" }, { PT_R19, "r19" },
1673         { PT_R20, "r20" }, { PT_R21, "r21" }, { PT_R22, "r22" },
1674         { PT_R23, "r23" }, { PT_R24, "r24" }, { PT_R25, "r25" },
1675         { PT_R26, "r26" }, { PT_R27, "r27" }, { PT_R28, "r28" },
1676         { PT_R29, "r29" }, { PT_R30, "r30" }, { PT_R31, "r31" },
1677         { PT_AR_CCV, "ar.ccv" }, { PT_AR_FPSR, "ar.fpsr" },
1678         { PT_B0, "b0" }, { PT_B7, "b7" }, { PT_F6, "f6" },
1679         { PT_F7, "f7" }, { PT_F8, "f8" }, { PT_F9, "f9" },
1680 # ifdef PT_AR_CSD
1681         { PT_AR_CSD, "ar.csd" },
1682 # endif
1683 # ifdef PT_AR_SSD
1684         { PT_AR_SSD, "ar.ssd" },
1685 # endif
1686         { PT_DBR, "dbr" }, { PT_IBR, "ibr" }, { PT_PMD, "pmd" },
1687 #elif defined(I386)
1688         { 4*EBX,                "4*EBX"                                 },
1689         { 4*ECX,                "4*ECX"                                 },
1690         { 4*EDX,                "4*EDX"                                 },
1691         { 4*ESI,                "4*ESI"                                 },
1692         { 4*EDI,                "4*EDI"                                 },
1693         { 4*EBP,                "4*EBP"                                 },
1694         { 4*EAX,                "4*EAX"                                 },
1695         { 4*DS,                 "4*DS"                                  },
1696         { 4*ES,                 "4*ES"                                  },
1697         { 4*FS,                 "4*FS"                                  },
1698         { 4*GS,                 "4*GS"                                  },
1699         { 4*ORIG_EAX,           "4*ORIG_EAX"                            },
1700         { 4*EIP,                "4*EIP"                                 },
1701         { 4*CS,                 "4*CS"                                  },
1702         { 4*EFL,                "4*EFL"                                 },
1703         { 4*UESP,               "4*UESP"                                },
1704         { 4*SS,                 "4*SS"                                  },
1705 #elif defined(X86_64) || defined(X32)
1706         { 8*R15,                "8*R15"                                 },
1707         { 8*R14,                "8*R14"                                 },
1708         { 8*R13,                "8*R13"                                 },
1709         { 8*R12,                "8*R12"                                 },
1710         { 8*RBP,                "8*RBP"                                 },
1711         { 8*RBX,                "8*RBX"                                 },
1712         { 8*R11,                "8*R11"                                 },
1713         { 8*R10,                "8*R10"                                 },
1714         { 8*R9,                 "8*R9"                                  },
1715         { 8*R8,                 "8*R8"                                  },
1716         { 8*RAX,                "8*RAX"                                 },
1717         { 8*RCX,                "8*RCX"                                 },
1718         { 8*RDX,                "8*RDX"                                 },
1719         { 8*RSI,                "8*RSI"                                 },
1720         { 8*RDI,                "8*RDI"                                 },
1721         { 8*ORIG_RAX,           "8*ORIG_RAX"                            },
1722         { 8*RIP,                "8*RIP"                                 },
1723         { 8*CS,                 "8*CS"                                  },
1724         { 8*EFLAGS,             "8*EFL"                                 },
1725         { 8*RSP,                "8*RSP"                                 },
1726         { 8*SS,                 "8*SS"                                  },
1727 #elif defined(M68K)
1728         { 4*PT_D1,              "4*PT_D1"                               },
1729         { 4*PT_D2,              "4*PT_D2"                               },
1730         { 4*PT_D3,              "4*PT_D3"                               },
1731         { 4*PT_D4,              "4*PT_D4"                               },
1732         { 4*PT_D5,              "4*PT_D5"                               },
1733         { 4*PT_D6,              "4*PT_D6"                               },
1734         { 4*PT_D7,              "4*PT_D7"                               },
1735         { 4*PT_A0,              "4*PT_A0"                               },
1736         { 4*PT_A1,              "4*PT_A1"                               },
1737         { 4*PT_A2,              "4*PT_A2"                               },
1738         { 4*PT_A3,              "4*PT_A3"                               },
1739         { 4*PT_A4,              "4*PT_A4"                               },
1740         { 4*PT_A5,              "4*PT_A5"                               },
1741         { 4*PT_A6,              "4*PT_A6"                               },
1742         { 4*PT_D0,              "4*PT_D0"                               },
1743         { 4*PT_USP,             "4*PT_USP"                              },
1744         { 4*PT_ORIG_D0,         "4*PT_ORIG_D0"                          },
1745         { 4*PT_SR,              "4*PT_SR"                               },
1746         { 4*PT_PC,              "4*PT_PC"                               },
1747 #elif defined(SH)
1748         { 4*REG_REG0,           "4*REG_REG0"                            },
1749         { 4*(REG_REG0+1),       "4*REG_REG1"                            },
1750         { 4*(REG_REG0+2),       "4*REG_REG2"                            },
1751         { 4*(REG_REG0+3),       "4*REG_REG3"                            },
1752         { 4*(REG_REG0+4),       "4*REG_REG4"                            },
1753         { 4*(REG_REG0+5),       "4*REG_REG5"                            },
1754         { 4*(REG_REG0+6),       "4*REG_REG6"                            },
1755         { 4*(REG_REG0+7),       "4*REG_REG7"                            },
1756         { 4*(REG_REG0+8),       "4*REG_REG8"                            },
1757         { 4*(REG_REG0+9),       "4*REG_REG9"                            },
1758         { 4*(REG_REG0+10),      "4*REG_REG10"                           },
1759         { 4*(REG_REG0+11),      "4*REG_REG11"                           },
1760         { 4*(REG_REG0+12),      "4*REG_REG12"                           },
1761         { 4*(REG_REG0+13),      "4*REG_REG13"                           },
1762         { 4*(REG_REG0+14),      "4*REG_REG14"                           },
1763         { 4*REG_REG15,          "4*REG_REG15"                           },
1764         { 4*REG_PC,             "4*REG_PC"                              },
1765         { 4*REG_PR,             "4*REG_PR"                              },
1766         { 4*REG_SR,             "4*REG_SR"                              },
1767         { 4*REG_GBR,            "4*REG_GBR"                             },
1768         { 4*REG_MACH,           "4*REG_MACH"                            },
1769         { 4*REG_MACL,           "4*REG_MACL"                            },
1770         { 4*REG_SYSCALL,        "4*REG_SYSCALL"                         },
1771         { 4*REG_FPUL,           "4*REG_FPUL"                            },
1772         { 4*REG_FPREG0,         "4*REG_FPREG0"                          },
1773         { 4*(REG_FPREG0+1),     "4*REG_FPREG1"                          },
1774         { 4*(REG_FPREG0+2),     "4*REG_FPREG2"                          },
1775         { 4*(REG_FPREG0+3),     "4*REG_FPREG3"                          },
1776         { 4*(REG_FPREG0+4),     "4*REG_FPREG4"                          },
1777         { 4*(REG_FPREG0+5),     "4*REG_FPREG5"                          },
1778         { 4*(REG_FPREG0+6),     "4*REG_FPREG6"                          },
1779         { 4*(REG_FPREG0+7),     "4*REG_FPREG7"                          },
1780         { 4*(REG_FPREG0+8),     "4*REG_FPREG8"                          },
1781         { 4*(REG_FPREG0+9),     "4*REG_FPREG9"                          },
1782         { 4*(REG_FPREG0+10),    "4*REG_FPREG10"                         },
1783         { 4*(REG_FPREG0+11),    "4*REG_FPREG11"                         },
1784         { 4*(REG_FPREG0+12),    "4*REG_FPREG12"                         },
1785         { 4*(REG_FPREG0+13),    "4*REG_FPREG13"                         },
1786         { 4*(REG_FPREG0+14),    "4*REG_FPREG14"                         },
1787         { 4*REG_FPREG15,        "4*REG_FPREG15"                         },
1788 # ifdef REG_XDREG0
1789         { 4*REG_XDREG0,         "4*REG_XDREG0"                          },
1790         { 4*(REG_XDREG0+2),     "4*REG_XDREG2"                          },
1791         { 4*(REG_XDREG0+4),     "4*REG_XDREG4"                          },
1792         { 4*(REG_XDREG0+6),     "4*REG_XDREG6"                          },
1793         { 4*(REG_XDREG0+8),     "4*REG_XDREG8"                          },
1794         { 4*(REG_XDREG0+10),    "4*REG_XDREG10"                         },
1795         { 4*(REG_XDREG0+12),    "4*REG_XDREG12"                         },
1796         { 4*REG_XDREG14,        "4*REG_XDREG14"                         },
1797 # endif
1798         { 4*REG_FPSCR,          "4*REG_FPSCR"                           },
1799 #elif defined(SH64)
1800         { 0,                    "PC(L)"                                 },
1801         { 4,                    "PC(U)"                                 },
1802         { 8,                    "SR(L)"                                 },
1803         { 12,                   "SR(U)"                                 },
1804         { 16,                   "syscall no.(L)"                        },
1805         { 20,                   "syscall_no.(U)"                        },
1806         { 24,                   "R0(L)"                                 },
1807         { 28,                   "R0(U)"                                 },
1808         { 32,                   "R1(L)"                                 },
1809         { 36,                   "R1(U)"                                 },
1810         { 40,                   "R2(L)"                                 },
1811         { 44,                   "R2(U)"                                 },
1812         { 48,                   "R3(L)"                                 },
1813         { 52,                   "R3(U)"                                 },
1814         { 56,                   "R4(L)"                                 },
1815         { 60,                   "R4(U)"                                 },
1816         { 64,                   "R5(L)"                                 },
1817         { 68,                   "R5(U)"                                 },
1818         { 72,                   "R6(L)"                                 },
1819         { 76,                   "R6(U)"                                 },
1820         { 80,                   "R7(L)"                                 },
1821         { 84,                   "R7(U)"                                 },
1822         { 88,                   "R8(L)"                                 },
1823         { 92,                   "R8(U)"                                 },
1824         { 96,                   "R9(L)"                                 },
1825         { 100,                  "R9(U)"                                 },
1826         { 104,                  "R10(L)"                                },
1827         { 108,                  "R10(U)"                                },
1828         { 112,                  "R11(L)"                                },
1829         { 116,                  "R11(U)"                                },
1830         { 120,                  "R12(L)"                                },
1831         { 124,                  "R12(U)"                                },
1832         { 128,                  "R13(L)"                                },
1833         { 132,                  "R13(U)"                                },
1834         { 136,                  "R14(L)"                                },
1835         { 140,                  "R14(U)"                                },
1836         { 144,                  "R15(L)"                                },
1837         { 148,                  "R15(U)"                                },
1838         { 152,                  "R16(L)"                                },
1839         { 156,                  "R16(U)"                                },
1840         { 160,                  "R17(L)"                                },
1841         { 164,                  "R17(U)"                                },
1842         { 168,                  "R18(L)"                                },
1843         { 172,                  "R18(U)"                                },
1844         { 176,                  "R19(L)"                                },
1845         { 180,                  "R19(U)"                                },
1846         { 184,                  "R20(L)"                                },
1847         { 188,                  "R20(U)"                                },
1848         { 192,                  "R21(L)"                                },
1849         { 196,                  "R21(U)"                                },
1850         { 200,                  "R22(L)"                                },
1851         { 204,                  "R22(U)"                                },
1852         { 208,                  "R23(L)"                                },
1853         { 212,                  "R23(U)"                                },
1854         { 216,                  "R24(L)"                                },
1855         { 220,                  "R24(U)"                                },
1856         { 224,                  "R25(L)"                                },
1857         { 228,                  "R25(U)"                                },
1858         { 232,                  "R26(L)"                                },
1859         { 236,                  "R26(U)"                                },
1860         { 240,                  "R27(L)"                                },
1861         { 244,                  "R27(U)"                                },
1862         { 248,                  "R28(L)"                                },
1863         { 252,                  "R28(U)"                                },
1864         { 256,                  "R29(L)"                                },
1865         { 260,                  "R29(U)"                                },
1866         { 264,                  "R30(L)"                                },
1867         { 268,                  "R30(U)"                                },
1868         { 272,                  "R31(L)"                                },
1869         { 276,                  "R31(U)"                                },
1870         { 280,                  "R32(L)"                                },
1871         { 284,                  "R32(U)"                                },
1872         { 288,                  "R33(L)"                                },
1873         { 292,                  "R33(U)"                                },
1874         { 296,                  "R34(L)"                                },
1875         { 300,                  "R34(U)"                                },
1876         { 304,                  "R35(L)"                                },
1877         { 308,                  "R35(U)"                                },
1878         { 312,                  "R36(L)"                                },
1879         { 316,                  "R36(U)"                                },
1880         { 320,                  "R37(L)"                                },
1881         { 324,                  "R37(U)"                                },
1882         { 328,                  "R38(L)"                                },
1883         { 332,                  "R38(U)"                                },
1884         { 336,                  "R39(L)"                                },
1885         { 340,                  "R39(U)"                                },
1886         { 344,                  "R40(L)"                                },
1887         { 348,                  "R40(U)"                                },
1888         { 352,                  "R41(L)"                                },
1889         { 356,                  "R41(U)"                                },
1890         { 360,                  "R42(L)"                                },
1891         { 364,                  "R42(U)"                                },
1892         { 368,                  "R43(L)"                                },
1893         { 372,                  "R43(U)"                                },
1894         { 376,                  "R44(L)"                                },
1895         { 380,                  "R44(U)"                                },
1896         { 384,                  "R45(L)"                                },
1897         { 388,                  "R45(U)"                                },
1898         { 392,                  "R46(L)"                                },
1899         { 396,                  "R46(U)"                                },
1900         { 400,                  "R47(L)"                                },
1901         { 404,                  "R47(U)"                                },
1902         { 408,                  "R48(L)"                                },
1903         { 412,                  "R48(U)"                                },
1904         { 416,                  "R49(L)"                                },
1905         { 420,                  "R49(U)"                                },
1906         { 424,                  "R50(L)"                                },
1907         { 428,                  "R50(U)"                                },
1908         { 432,                  "R51(L)"                                },
1909         { 436,                  "R51(U)"                                },
1910         { 440,                  "R52(L)"                                },
1911         { 444,                  "R52(U)"                                },
1912         { 448,                  "R53(L)"                                },
1913         { 452,                  "R53(U)"                                },
1914         { 456,                  "R54(L)"                                },
1915         { 460,                  "R54(U)"                                },
1916         { 464,                  "R55(L)"                                },
1917         { 468,                  "R55(U)"                                },
1918         { 472,                  "R56(L)"                                },
1919         { 476,                  "R56(U)"                                },
1920         { 480,                  "R57(L)"                                },
1921         { 484,                  "R57(U)"                                },
1922         { 488,                  "R58(L)"                                },
1923         { 492,                  "R58(U)"                                },
1924         { 496,                  "R59(L)"                                },
1925         { 500,                  "R59(U)"                                },
1926         { 504,                  "R60(L)"                                },
1927         { 508,                  "R60(U)"                                },
1928         { 512,                  "R61(L)"                                },
1929         { 516,                  "R61(U)"                                },
1930         { 520,                  "R62(L)"                                },
1931         { 524,                  "R62(U)"                                },
1932         { 528,                  "TR0(L)"                                },
1933         { 532,                  "TR0(U)"                                },
1934         { 536,                  "TR1(L)"                                },
1935         { 540,                  "TR1(U)"                                },
1936         { 544,                  "TR2(L)"                                },
1937         { 548,                  "TR2(U)"                                },
1938         { 552,                  "TR3(L)"                                },
1939         { 556,                  "TR3(U)"                                },
1940         { 560,                  "TR4(L)"                                },
1941         { 564,                  "TR4(U)"                                },
1942         { 568,                  "TR5(L)"                                },
1943         { 572,                  "TR5(U)"                                },
1944         { 576,                  "TR6(L)"                                },
1945         { 580,                  "TR6(U)"                                },
1946         { 584,                  "TR7(L)"                                },
1947         { 588,                  "TR7(U)"                                },
1948         /* This entry is in case pt_regs contains dregs (depends on
1949            the kernel build options). */
1950         { uoff(regs),           "offsetof(struct user, regs)"           },
1951         { uoff(fpu),            "offsetof(struct user, fpu)"            },
1952 #elif defined(ARM)
1953         { uoff(regs.ARM_r0),    "r0"                                    },
1954         { uoff(regs.ARM_r1),    "r1"                                    },
1955         { uoff(regs.ARM_r2),    "r2"                                    },
1956         { uoff(regs.ARM_r3),    "r3"                                    },
1957         { uoff(regs.ARM_r4),    "r4"                                    },
1958         { uoff(regs.ARM_r5),    "r5"                                    },
1959         { uoff(regs.ARM_r6),    "r6"                                    },
1960         { uoff(regs.ARM_r7),    "r7"                                    },
1961         { uoff(regs.ARM_r8),    "r8"                                    },
1962         { uoff(regs.ARM_r9),    "r9"                                    },
1963         { uoff(regs.ARM_r10),   "r10"                                   },
1964         { uoff(regs.ARM_fp),    "fp"                                    },
1965         { uoff(regs.ARM_ip),    "ip"                                    },
1966         { uoff(regs.ARM_sp),    "sp"                                    },
1967         { uoff(regs.ARM_lr),    "lr"                                    },
1968         { uoff(regs.ARM_pc),    "pc"                                    },
1969         { uoff(regs.ARM_cpsr),  "cpsr"                                  },
1970 #elif defined(AVR32)
1971         { uoff(regs.sr),        "sr"                                    },
1972         { uoff(regs.pc),        "pc"                                    },
1973         { uoff(regs.lr),        "lr"                                    },
1974         { uoff(regs.sp),        "sp"                                    },
1975         { uoff(regs.r12),       "r12"                                   },
1976         { uoff(regs.r11),       "r11"                                   },
1977         { uoff(regs.r10),       "r10"                                   },
1978         { uoff(regs.r9),        "r9"                                    },
1979         { uoff(regs.r8),        "r8"                                    },
1980         { uoff(regs.r7),        "r7"                                    },
1981         { uoff(regs.r6),        "r6"                                    },
1982         { uoff(regs.r5),        "r5"                                    },
1983         { uoff(regs.r4),        "r4"                                    },
1984         { uoff(regs.r3),        "r3"                                    },
1985         { uoff(regs.r2),        "r2"                                    },
1986         { uoff(regs.r1),        "r1"                                    },
1987         { uoff(regs.r0),        "r0"                                    },
1988         { uoff(regs.r12_orig),  "orig_r12"                              },
1989 #elif defined(MIPS)
1990         { 0,                    "r0"                                    },
1991         { 1,                    "r1"                                    },
1992         { 2,                    "r2"                                    },
1993         { 3,                    "r3"                                    },
1994         { 4,                    "r4"                                    },
1995         { 5,                    "r5"                                    },
1996         { 6,                    "r6"                                    },
1997         { 7,                    "r7"                                    },
1998         { 8,                    "r8"                                    },
1999         { 9,                    "r9"                                    },
2000         { 10,                   "r10"                                   },
2001         { 11,                   "r11"                                   },
2002         { 12,                   "r12"                                   },
2003         { 13,                   "r13"                                   },
2004         { 14,                   "r14"                                   },
2005         { 15,                   "r15"                                   },
2006         { 16,                   "r16"                                   },
2007         { 17,                   "r17"                                   },
2008         { 18,                   "r18"                                   },
2009         { 19,                   "r19"                                   },
2010         { 20,                   "r20"                                   },
2011         { 21,                   "r21"                                   },
2012         { 22,                   "r22"                                   },
2013         { 23,                   "r23"                                   },
2014         { 24,                   "r24"                                   },
2015         { 25,                   "r25"                                   },
2016         { 26,                   "r26"                                   },
2017         { 27,                   "r27"                                   },
2018         { 28,                   "r28"                                   },
2019         { 29,                   "r29"                                   },
2020         { 30,                   "r30"                                   },
2021         { 31,                   "r31"                                   },
2022         { 32,                   "f0"                                    },
2023         { 33,                   "f1"                                    },
2024         { 34,                   "f2"                                    },
2025         { 35,                   "f3"                                    },
2026         { 36,                   "f4"                                    },
2027         { 37,                   "f5"                                    },
2028         { 38,                   "f6"                                    },
2029         { 39,                   "f7"                                    },
2030         { 40,                   "f8"                                    },
2031         { 41,                   "f9"                                    },
2032         { 42,                   "f10"                                   },
2033         { 43,                   "f11"                                   },
2034         { 44,                   "f12"                                   },
2035         { 45,                   "f13"                                   },
2036         { 46,                   "f14"                                   },
2037         { 47,                   "f15"                                   },
2038         { 48,                   "f16"                                   },
2039         { 49,                   "f17"                                   },
2040         { 50,                   "f18"                                   },
2041         { 51,                   "f19"                                   },
2042         { 52,                   "f20"                                   },
2043         { 53,                   "f21"                                   },
2044         { 54,                   "f22"                                   },
2045         { 55,                   "f23"                                   },
2046         { 56,                   "f24"                                   },
2047         { 57,                   "f25"                                   },
2048         { 58,                   "f26"                                   },
2049         { 59,                   "f27"                                   },
2050         { 60,                   "f28"                                   },
2051         { 61,                   "f29"                                   },
2052         { 62,                   "f30"                                   },
2053         { 63,                   "f31"                                   },
2054         { 64,                   "pc"                                    },
2055         { 65,                   "cause"                                 },
2056         { 66,                   "badvaddr"                              },
2057         { 67,                   "mmhi"                                  },
2058         { 68,                   "mmlo"                                  },
2059         { 69,                   "fpcsr"                                 },
2060         { 70,                   "fpeir"                                 },
2061 #elif defined(TILE)
2062         { PTREGS_OFFSET_REG(0),  "r0"  },
2063         { PTREGS_OFFSET_REG(1),  "r1"  },
2064         { PTREGS_OFFSET_REG(2),  "r2"  },
2065         { PTREGS_OFFSET_REG(3),  "r3"  },
2066         { PTREGS_OFFSET_REG(4),  "r4"  },
2067         { PTREGS_OFFSET_REG(5),  "r5"  },
2068         { PTREGS_OFFSET_REG(6),  "r6"  },
2069         { PTREGS_OFFSET_REG(7),  "r7"  },
2070         { PTREGS_OFFSET_REG(8),  "r8"  },
2071         { PTREGS_OFFSET_REG(9),  "r9"  },
2072         { PTREGS_OFFSET_REG(10), "r10" },
2073         { PTREGS_OFFSET_REG(11), "r11" },
2074         { PTREGS_OFFSET_REG(12), "r12" },
2075         { PTREGS_OFFSET_REG(13), "r13" },
2076         { PTREGS_OFFSET_REG(14), "r14" },
2077         { PTREGS_OFFSET_REG(15), "r15" },
2078         { PTREGS_OFFSET_REG(16), "r16" },
2079         { PTREGS_OFFSET_REG(17), "r17" },
2080         { PTREGS_OFFSET_REG(18), "r18" },
2081         { PTREGS_OFFSET_REG(19), "r19" },
2082         { PTREGS_OFFSET_REG(20), "r20" },
2083         { PTREGS_OFFSET_REG(21), "r21" },
2084         { PTREGS_OFFSET_REG(22), "r22" },
2085         { PTREGS_OFFSET_REG(23), "r23" },
2086         { PTREGS_OFFSET_REG(24), "r24" },
2087         { PTREGS_OFFSET_REG(25), "r25" },
2088         { PTREGS_OFFSET_REG(26), "r26" },
2089         { PTREGS_OFFSET_REG(27), "r27" },
2090         { PTREGS_OFFSET_REG(28), "r28" },
2091         { PTREGS_OFFSET_REG(29), "r29" },
2092         { PTREGS_OFFSET_REG(30), "r30" },
2093         { PTREGS_OFFSET_REG(31), "r31" },
2094         { PTREGS_OFFSET_REG(32), "r32" },
2095         { PTREGS_OFFSET_REG(33), "r33" },
2096         { PTREGS_OFFSET_REG(34), "r34" },
2097         { PTREGS_OFFSET_REG(35), "r35" },
2098         { PTREGS_OFFSET_REG(36), "r36" },
2099         { PTREGS_OFFSET_REG(37), "r37" },
2100         { PTREGS_OFFSET_REG(38), "r38" },
2101         { PTREGS_OFFSET_REG(39), "r39" },
2102         { PTREGS_OFFSET_REG(40), "r40" },
2103         { PTREGS_OFFSET_REG(41), "r41" },
2104         { PTREGS_OFFSET_REG(42), "r42" },
2105         { PTREGS_OFFSET_REG(43), "r43" },
2106         { PTREGS_OFFSET_REG(44), "r44" },
2107         { PTREGS_OFFSET_REG(45), "r45" },
2108         { PTREGS_OFFSET_REG(46), "r46" },
2109         { PTREGS_OFFSET_REG(47), "r47" },
2110         { PTREGS_OFFSET_REG(48), "r48" },
2111         { PTREGS_OFFSET_REG(49), "r49" },
2112         { PTREGS_OFFSET_REG(50), "r50" },
2113         { PTREGS_OFFSET_REG(51), "r51" },
2114         { PTREGS_OFFSET_REG(52), "r52" },
2115         { PTREGS_OFFSET_TP, "tp" },
2116         { PTREGS_OFFSET_SP, "sp" },
2117         { PTREGS_OFFSET_LR, "lr" },
2118         { PTREGS_OFFSET_PC, "pc" },
2119         { PTREGS_OFFSET_EX1, "ex1" },
2120         { PTREGS_OFFSET_FAULTNUM, "faultnum" },
2121         { PTREGS_OFFSET_ORIG_R0, "orig_r0" },
2122         { PTREGS_OFFSET_FLAGS, "flags" },
2123 #endif
2124 #ifdef CRISV10
2125         { 4*PT_FRAMETYPE, "4*PT_FRAMETYPE" },
2126         { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2127         { 4*PT_R13, "4*PT_R13" },
2128         { 4*PT_R12, "4*PT_R12" },
2129         { 4*PT_R11, "4*PT_R11" },
2130         { 4*PT_R10, "4*PT_R10" },
2131         { 4*PT_R9, "4*PT_R9" },
2132         { 4*PT_R8, "4*PT_R8" },
2133         { 4*PT_R7, "4*PT_R7" },
2134         { 4*PT_R6, "4*PT_R6" },
2135         { 4*PT_R5, "4*PT_R5" },
2136         { 4*PT_R4, "4*PT_R4" },
2137         { 4*PT_R3, "4*PT_R3" },
2138         { 4*PT_R2, "4*PT_R2" },
2139         { 4*PT_R1, "4*PT_R1" },
2140         { 4*PT_R0, "4*PT_R0" },
2141         { 4*PT_MOF, "4*PT_MOF" },
2142         { 4*PT_DCCR, "4*PT_DCCR" },
2143         { 4*PT_SRP, "4*PT_SRP" },
2144         { 4*PT_IRP, "4*PT_IRP" },
2145         { 4*PT_CSRINSTR, "4*PT_CSRINSTR" },
2146         { 4*PT_CSRADDR, "4*PT_CSRADDR" },
2147         { 4*PT_CSRDATA, "4*PT_CSRDATA" },
2148         { 4*PT_USP, "4*PT_USP" },
2149 #endif
2150 #ifdef CRISV32
2151         { 4*PT_ORIG_R10, "4*PT_ORIG_R10" },
2152         { 4*PT_R0, "4*PT_R0" },
2153         { 4*PT_R1, "4*PT_R1" },
2154         { 4*PT_R2, "4*PT_R2" },
2155         { 4*PT_R3, "4*PT_R3" },
2156         { 4*PT_R4, "4*PT_R4" },
2157         { 4*PT_R5, "4*PT_R5" },
2158         { 4*PT_R6, "4*PT_R6" },
2159         { 4*PT_R7, "4*PT_R7" },
2160         { 4*PT_R8, "4*PT_R8" },
2161         { 4*PT_R9, "4*PT_R9" },
2162         { 4*PT_R10, "4*PT_R10" },
2163         { 4*PT_R11, "4*PT_R11" },
2164         { 4*PT_R12, "4*PT_R12" },
2165         { 4*PT_R13, "4*PT_R13" },
2166         { 4*PT_ACR, "4*PT_ACR" },
2167         { 4*PT_SRS, "4*PT_SRS" },
2168         { 4*PT_MOF, "4*PT_MOF" },
2169         { 4*PT_SPC, "4*PT_SPC" },
2170         { 4*PT_CCS, "4*PT_CCS" },
2171         { 4*PT_SRP, "4*PT_SRP" },
2172         { 4*PT_ERP, "4*PT_ERP" },
2173         { 4*PT_EXS, "4*PT_EXS" },
2174         { 4*PT_EDA, "4*PT_EDA" },
2175         { 4*PT_USP, "4*PT_USP" },
2176         { 4*PT_PPC, "4*PT_PPC" },
2177         { 4*PT_BP_CTRL, "4*PT_BP_CTRL" },
2178         { 4*PT_BP+4, "4*PT_BP+4" },
2179         { 4*PT_BP+8, "4*PT_BP+8" },
2180         { 4*PT_BP+12, "4*PT_BP+12" },
2181         { 4*PT_BP+16, "4*PT_BP+16" },
2182         { 4*PT_BP+20, "4*PT_BP+20" },
2183         { 4*PT_BP+24, "4*PT_BP+24" },
2184         { 4*PT_BP+28, "4*PT_BP+28" },
2185         { 4*PT_BP+32, "4*PT_BP+32" },
2186         { 4*PT_BP+36, "4*PT_BP+36" },
2187         { 4*PT_BP+40, "4*PT_BP+40" },
2188         { 4*PT_BP+44, "4*PT_BP+44" },
2189         { 4*PT_BP+48, "4*PT_BP+48" },
2190         { 4*PT_BP+52, "4*PT_BP+52" },
2191         { 4*PT_BP+56, "4*PT_BP+56" },
2192 #endif
2193 #ifdef MICROBLAZE
2194         { PT_GPR(0),            "r0"                                    },
2195         { PT_GPR(1),            "r1"                                    },
2196         { PT_GPR(2),            "r2"                                    },
2197         { PT_GPR(3),            "r3"                                    },
2198         { PT_GPR(4),            "r4"                                    },
2199         { PT_GPR(5),            "r5"                                    },
2200         { PT_GPR(6),            "r6"                                    },
2201         { PT_GPR(7),            "r7"                                    },
2202         { PT_GPR(8),            "r8"                                    },
2203         { PT_GPR(9),            "r9"                                    },
2204         { PT_GPR(10),           "r10"                                   },
2205         { PT_GPR(11),           "r11"                                   },
2206         { PT_GPR(12),           "r12"                                   },
2207         { PT_GPR(13),           "r13"                                   },
2208         { PT_GPR(14),           "r14"                                   },
2209         { PT_GPR(15),           "r15"                                   },
2210         { PT_GPR(16),           "r16"                                   },
2211         { PT_GPR(17),           "r17"                                   },
2212         { PT_GPR(18),           "r18"                                   },
2213         { PT_GPR(19),           "r19"                                   },
2214         { PT_GPR(20),           "r20"                                   },
2215         { PT_GPR(21),           "r21"                                   },
2216         { PT_GPR(22),           "r22"                                   },
2217         { PT_GPR(23),           "r23"                                   },
2218         { PT_GPR(24),           "r24"                                   },
2219         { PT_GPR(25),           "r25"                                   },
2220         { PT_GPR(26),           "r26"                                   },
2221         { PT_GPR(27),           "r27"                                   },
2222         { PT_GPR(28),           "r28"                                   },
2223         { PT_GPR(29),           "r29"                                   },
2224         { PT_GPR(30),           "r30"                                   },
2225         { PT_GPR(31),           "r31"                                   },
2226         { PT_PC,                "rpc",                                  },
2227         { PT_MSR,               "rmsr",                                 },
2228         { PT_EAR,               "rear",                                 },
2229         { PT_ESR,               "resr",                                 },
2230         { PT_FSR,               "rfsr",                                 },
2231         { PT_KERNEL_MODE,       "kernel_mode",                          },
2232 #endif
2233 #ifdef OR1K
2234         { 4*0,  "r0" },
2235         { 4*1,  "r1" },
2236         { 4*2,  "r2" },
2237         { 4*3,  "r3" },
2238         { 4*4,  "r4" },
2239         { 4*5,  "r5" },
2240         { 4*6,  "r6" },
2241         { 4*7,  "r7" },
2242         { 4*8,  "r8" },
2243         { 4*9,  "r9" },
2244         { 4*10, "r10" },
2245         { 4*11, "r11" },
2246         { 4*12, "r12" },
2247         { 4*13, "r13" },
2248         { 4*14, "r14" },
2249         { 4*15, "r15" },
2250         { 4*16, "r16" },
2251         { 4*17, "r17" },
2252         { 4*18, "r18" },
2253         { 4*19, "r19" },
2254         { 4*20, "r20" },
2255         { 4*21, "r21" },
2256         { 4*22, "r22" },
2257         { 4*23, "r23" },
2258         { 4*24, "r24" },
2259         { 4*25, "r25" },
2260         { 4*26, "r26" },
2261         { 4*27, "r27" },
2262         { 4*28, "r28" },
2263         { 4*29, "r29" },
2264         { 4*30, "r30" },
2265         { 4*31, "r31" },
2266         { 4*32, "pc" },
2267         { 4*33, "sr" },
2268 #endif
2269 #ifdef XTENSA
2270         { SYSCALL_NR,           "syscall_nr"    },
2271         { REG_AR_BASE,          "ar0"           },
2272         { REG_AR_BASE+1,        "ar1"           },
2273         { REG_AR_BASE+2,        "ar2"           },
2274         { REG_AR_BASE+3,        "ar3"           },
2275         { REG_AR_BASE+4,        "ar4"           },
2276         { REG_AR_BASE+5,        "ar5"           },
2277         { REG_AR_BASE+6,        "ar6"           },
2278         { REG_AR_BASE+7,        "ar7"           },
2279         { REG_AR_BASE+8,        "ar8"           },
2280         { REG_AR_BASE+9,        "ar9"           },
2281         { REG_AR_BASE+10,       "ar10"          },
2282         { REG_AR_BASE+11,       "ar11"          },
2283         { REG_AR_BASE+12,       "ar12"          },
2284         { REG_AR_BASE+13,       "ar13"          },
2285         { REG_AR_BASE+14,       "ar14"          },
2286         { REG_AR_BASE+15,       "ar15"          },
2287         { REG_AR_BASE+16,       "ar16"          },
2288         { REG_AR_BASE+17,       "ar17"          },
2289         { REG_AR_BASE+18,       "ar18"          },
2290         { REG_AR_BASE+19,       "ar19"          },
2291         { REG_AR_BASE+20,       "ar20"          },
2292         { REG_AR_BASE+21,       "ar21"          },
2293         { REG_AR_BASE+22,       "ar22"          },
2294         { REG_AR_BASE+23,       "ar23"          },
2295         { REG_AR_BASE+24,       "ar24"          },
2296         { REG_AR_BASE+25,       "ar25"          },
2297         { REG_AR_BASE+26,       "ar26"          },
2298         { REG_AR_BASE+27,       "ar27"          },
2299         { REG_AR_BASE+28,       "ar28"          },
2300         { REG_AR_BASE+29,       "ar29"          },
2301         { REG_AR_BASE+30,       "ar30"          },
2302         { REG_AR_BASE+31,       "ar31"          },
2303         { REG_AR_BASE+32,       "ar32"          },
2304         { REG_AR_BASE+33,       "ar33"          },
2305         { REG_AR_BASE+34,       "ar34"          },
2306         { REG_AR_BASE+35,       "ar35"          },
2307         { REG_AR_BASE+36,       "ar36"          },
2308         { REG_AR_BASE+37,       "ar37"          },
2309         { REG_AR_BASE+38,       "ar38"          },
2310         { REG_AR_BASE+39,       "ar39"          },
2311         { REG_AR_BASE+40,       "ar40"          },
2312         { REG_AR_BASE+41,       "ar41"          },
2313         { REG_AR_BASE+42,       "ar42"          },
2314         { REG_AR_BASE+43,       "ar43"          },
2315         { REG_AR_BASE+44,       "ar44"          },
2316         { REG_AR_BASE+45,       "ar45"          },
2317         { REG_AR_BASE+46,       "ar46"          },
2318         { REG_AR_BASE+47,       "ar47"          },
2319         { REG_AR_BASE+48,       "ar48"          },
2320         { REG_AR_BASE+49,       "ar49"          },
2321         { REG_AR_BASE+50,       "ar50"          },
2322         { REG_AR_BASE+51,       "ar51"          },
2323         { REG_AR_BASE+52,       "ar52"          },
2324         { REG_AR_BASE+53,       "ar53"          },
2325         { REG_AR_BASE+54,       "ar54"          },
2326         { REG_AR_BASE+55,       "ar55"          },
2327         { REG_AR_BASE+56,       "ar56"          },
2328         { REG_AR_BASE+57,       "ar57"          },
2329         { REG_AR_BASE+58,       "ar58"          },
2330         { REG_AR_BASE+59,       "ar59"          },
2331         { REG_AR_BASE+60,       "ar60"          },
2332         { REG_AR_BASE+61,       "ar61"          },
2333         { REG_AR_BASE+62,       "ar62"          },
2334         { REG_AR_BASE+63,       "ar63"          },
2335         { REG_LBEG,             "lbeg"          },
2336         { REG_LEND,             "lend"          },
2337         { REG_LCOUNT,           "lcount"        },
2338         { REG_SAR,              "sar"           },
2339         { REG_WB,               "wb"            },
2340         { REG_WS,               "ws"            },
2341         { REG_PS,               "ps"            },
2342         { REG_PC,               "pc"            },
2343         { REG_A_BASE,           "a0"            },
2344         { REG_A_BASE+1,         "a1"            },
2345         { REG_A_BASE+2,         "a2"            },
2346         { REG_A_BASE+3,         "a3"            },
2347         { REG_A_BASE+4,         "a4"            },
2348         { REG_A_BASE+5,         "a5"            },
2349         { REG_A_BASE+6,         "a6"            },
2350         { REG_A_BASE+7,         "a7"            },
2351         { REG_A_BASE+8,         "a8"            },
2352         { REG_A_BASE+9,         "a9"            },
2353         { REG_A_BASE+10,        "a10"           },
2354         { REG_A_BASE+11,        "a11"           },
2355         { REG_A_BASE+12,        "a12"           },
2356         { REG_A_BASE+13,        "a13"           },
2357         { REG_A_BASE+14,        "a14"           },
2358         { REG_A_BASE+15,        "a15"           },
2359 #endif
2360
2361         /* Other fields in "struct user" */
2362 #if defined(S390) || defined(S390X)
2363         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2364         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2365         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2366         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2367         /* S390[X] has no start_data */
2368         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2369         { uoff(signal),         "offsetof(struct user, signal)"         },
2370         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2371         { uoff(magic),          "offsetof(struct user, magic)"          },
2372         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2373         { sizeof(struct user),  "sizeof(struct user)"                   },
2374 #elif defined(POWERPC)
2375         { sizeof(struct user),  "sizeof(struct user)"                   },
2376 #elif defined(I386) || defined(X86_64) || defined(X32)
2377         { uoff(u_fpvalid),      "offsetof(struct user, u_fpvalid)"      },
2378         { uoff(i387),           "offsetof(struct user, i387)"           },
2379         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2380         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2381         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2382         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2383         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2384         { uoff(signal),         "offsetof(struct user, signal)"         },
2385         { uoff(reserved),       "offsetof(struct user, reserved)"       },
2386         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2387         { uoff(u_fpstate),      "offsetof(struct user, u_fpstate)"      },
2388         { uoff(magic),          "offsetof(struct user, magic)"          },
2389         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2390         { uoff(u_debugreg),     "offsetof(struct user, u_debugreg)"     },
2391         { sizeof(struct user),  "sizeof(struct user)"                   },
2392 #elif defined(IA64)
2393         { sizeof(struct user),  "sizeof(struct user)"                   },
2394 #elif defined(ARM)
2395         { uoff(u_fpvalid),      "offsetof(struct user, u_fpvalid)"      },
2396         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2397         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2398         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2399         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2400         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2401         { uoff(signal),         "offsetof(struct user, signal)"         },
2402         { uoff(reserved),       "offsetof(struct user, reserved)"       },
2403         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2404         { uoff(magic),          "offsetof(struct user, magic)"          },
2405         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2406         { sizeof(struct user),  "sizeof(struct user)"                   },
2407 #elif defined(AARCH64)
2408         /* nothing */
2409 #elif defined(M68K)
2410         { uoff(u_fpvalid),      "offsetof(struct user, u_fpvalid)"      },
2411         { uoff(m68kfp),         "offsetof(struct user, m68kfp)"         },
2412         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2413         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2414         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2415         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2416         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2417         { uoff(signal),         "offsetof(struct user, signal)"         },
2418         { uoff(reserved),       "offsetof(struct user, reserved)"       },
2419         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2420         { uoff(u_fpstate),      "offsetof(struct user, u_fpstate)"      },
2421         { uoff(magic),          "offsetof(struct user, magic)"          },
2422         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2423         { sizeof(struct user),  "sizeof(struct user)"                   },
2424 #elif defined(MIPS) || defined(LINUX_MIPSN32)
2425         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2426         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2427         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2428         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2429         { uoff(start_data),     "offsetof(struct user, start_data)"     },
2430         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2431         { uoff(signal),         "offsetof(struct user, signal)"         },
2432         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2433         { uoff(magic),          "offsetof(struct user, magic)"          },
2434         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2435         { sizeof(struct user),  "sizeof(struct user)"                   },
2436 #elif defined(ALPHA)
2437         { sizeof(struct user),  "sizeof(struct user)"                   },
2438 #elif defined(SPARC)
2439         { sizeof(struct user),  "sizeof(struct user)"                   },
2440 #elif defined(SPARC64)
2441         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2442         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2443         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2444         { uoff(signal),         "offsetof(struct user, signal)"         },
2445         { uoff(magic),          "offsetof(struct user, magic)"          },
2446         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2447         { sizeof(struct user),  "sizeof(struct user)"                   },
2448 #elif defined(HPPA)
2449         /* nothing */
2450 #elif defined(SH) || defined(SH64)
2451         { uoff(u_fpvalid),      "offsetof(struct user, u_fpvalid)"      },
2452         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2453         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2454         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2455         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2456         { uoff(start_data),     "offsetof(struct user, start_data)"     },
2457         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2458         { uoff(signal),         "offsetof(struct user, signal)"         },
2459         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2460         { uoff(u_fpstate),      "offsetof(struct user, u_fpstate)"      },
2461         { uoff(magic),          "offsetof(struct user, magic)"          },
2462         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2463         { sizeof(struct user),  "sizeof(struct user)"                   },
2464 #elif defined(CRISV10) || defined(CRISV32)
2465         { sizeof(struct user),  "sizeof(struct user)"                   },
2466 #elif defined(TILE)
2467         /* nothing */
2468 #elif defined(MICROBLAZE)
2469         { sizeof(struct user),  "sizeof(struct user)"                   },
2470 #elif defined(AVR32)
2471         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2472         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2473         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2474         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2475         { uoff(start_data),     "offsetof(struct user, start_data)"     },
2476         { uoff(start_stack),    "offsetof(struct user, start_stack)"    },
2477         { uoff(signal),         "offsetof(struct user, signal)"         },
2478         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2479         { uoff(magic),          "offsetof(struct user, magic)"          },
2480         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2481         { sizeof(struct user),  "sizeof(struct user)"                   },
2482 #elif defined(BFIN)
2483         { uoff(u_tsize),        "offsetof(struct user, u_tsize)"        },
2484         { uoff(u_dsize),        "offsetof(struct user, u_dsize)"        },
2485         { uoff(u_ssize),        "offsetof(struct user, u_ssize)"        },
2486         { uoff(start_code),     "offsetof(struct user, start_code)"     },
2487         { uoff(signal),         "offsetof(struct user, signal)"         },
2488         { uoff(u_ar0),          "offsetof(struct user, u_ar0)"          },
2489         { uoff(magic),          "offsetof(struct user, magic)"          },
2490         { uoff(u_comm),         "offsetof(struct user, u_comm)"         },
2491         { sizeof(struct user),  "sizeof(struct user)"                   },
2492 #elif defined(OR1K)
2493         /* nothing */
2494 #elif defined(METAG)
2495         /* nothing */
2496 #elif defined(XTENSA)
2497         /* nothing */
2498 #endif
2499         { 0,                    NULL                                    },
2500 };
2501
2502 int
2503 sys_ptrace(struct tcb *tcp)
2504 {
2505         const struct xlat *x;
2506         long addr;
2507
2508         if (entering(tcp)) {
2509                 printxval(ptrace_cmds, tcp->u_arg[0], "PTRACE_???");
2510                 tprintf(", %lu, ", tcp->u_arg[1]);
2511
2512                 addr = tcp->u_arg[2];
2513                 if (tcp->u_arg[0] == PTRACE_PEEKUSER
2514                  || tcp->u_arg[0] == PTRACE_POKEUSER
2515                 ) {
2516                         for (x = struct_user_offsets; x->str; x++) {
2517                                 if (x->val >= addr)
2518                                         break;
2519                         }
2520                         if (!x->str)
2521                                 tprintf("%#lx, ", addr);
2522                         else if (x->val > addr && x != struct_user_offsets) {
2523                                 x--;
2524                                 tprintf("%s + %ld, ", x->str, addr - x->val);
2525                         }
2526                         else
2527                                 tprintf("%s, ", x->str);
2528                 } else
2529 #ifdef PTRACE_GETREGSET
2530                 if (tcp->u_arg[0] == PTRACE_GETREGSET
2531                  || tcp->u_arg[0] == PTRACE_SETREGSET
2532                 ) {
2533                         printxval(nt_descriptor_types, tcp->u_arg[2], "NT_???");
2534                         tprints(", ");
2535                 } else
2536 #endif
2537                         tprintf("%#lx, ", addr);
2538
2539
2540                 switch (tcp->u_arg[0]) {
2541 #ifndef IA64
2542                 case PTRACE_PEEKDATA:
2543                 case PTRACE_PEEKTEXT:
2544                 case PTRACE_PEEKUSER:
2545                         break;
2546 #endif
2547                 case PTRACE_CONT:
2548                 case PTRACE_SINGLESTEP:
2549                 case PTRACE_SYSCALL:
2550                 case PTRACE_DETACH:
2551                         printsignal(tcp->u_arg[3]);
2552                         break;
2553 #ifdef PTRACE_SETOPTIONS
2554                 case PTRACE_SETOPTIONS:
2555                         printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
2556                         break;
2557 #endif
2558 #ifdef PTRACE_SETSIGINFO
2559                 case PTRACE_SETSIGINFO: {
2560                         printsiginfo_at(tcp, tcp->u_arg[3]);
2561                         break;
2562                 }
2563 #endif
2564 #ifdef PTRACE_GETSIGINFO
2565                 case PTRACE_GETSIGINFO:
2566                         /* Don't print anything, do it at syscall return. */
2567                         break;
2568 #endif
2569 #ifdef PTRACE_GETREGSET
2570                 case PTRACE_GETREGSET:
2571                         break;
2572                 case PTRACE_SETREGSET:
2573                         tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
2574                         break;
2575 #endif
2576                 default:
2577                         tprintf("%#lx", tcp->u_arg[3]);
2578                         break;
2579                 }
2580         } else {
2581                 switch (tcp->u_arg[0]) {
2582                 case PTRACE_PEEKDATA:
2583                 case PTRACE_PEEKTEXT:
2584                 case PTRACE_PEEKUSER:
2585 #ifdef IA64
2586                         return RVAL_HEX;
2587 #else
2588                         printnum(tcp, tcp->u_arg[3], "%#lx");
2589                         break;
2590 #endif
2591 #ifdef PTRACE_GETSIGINFO
2592                 case PTRACE_GETSIGINFO: {
2593                         printsiginfo_at(tcp, tcp->u_arg[3]);
2594                         break;
2595                 }
2596 #endif
2597 #ifdef PTRACE_GETREGSET
2598                 case PTRACE_GETREGSET:
2599                         tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
2600                         break;
2601 #endif
2602                 }
2603         }
2604         return 0;
2605 }
2606
2607 #ifndef FUTEX_CMP_REQUEUE
2608 # define FUTEX_CMP_REQUEUE 4
2609 #endif
2610 #ifndef FUTEX_WAKE_OP
2611 # define FUTEX_WAKE_OP 5
2612 #endif
2613 #ifndef FUTEX_LOCK_PI
2614 # define FUTEX_LOCK_PI 6
2615 # define FUTEX_UNLOCK_PI 7
2616 # define FUTEX_TRYLOCK_PI 8
2617 #endif
2618 #ifndef FUTEX_WAIT_BITSET
2619 # define FUTEX_WAIT_BITSET 9
2620 #endif
2621 #ifndef FUTEX_WAKE_BITSET
2622 # define FUTEX_WAKE_BITSET 10
2623 #endif
2624 #ifndef FUTEX_WAIT_REQUEUE_PI
2625 # define FUTEX_WAIT_REQUEUE_PI 11
2626 #endif
2627 #ifndef FUTEX_CMP_REQUEUE_PI
2628 # define FUTEX_CMP_REQUEUE_PI 12
2629 #endif
2630 #ifndef FUTEX_PRIVATE_FLAG
2631 # define FUTEX_PRIVATE_FLAG 128
2632 #endif
2633 #ifndef FUTEX_CLOCK_REALTIME
2634 # define FUTEX_CLOCK_REALTIME 256
2635 #endif
2636 static const struct xlat futexops[] = {
2637         { FUTEX_WAIT,                                   "FUTEX_WAIT" },
2638         { FUTEX_WAKE,                                   "FUTEX_WAKE" },
2639         { FUTEX_FD,                                     "FUTEX_FD" },
2640         { FUTEX_REQUEUE,                                "FUTEX_REQUEUE" },
2641         { FUTEX_CMP_REQUEUE,                            "FUTEX_CMP_REQUEUE" },
2642         { FUTEX_WAKE_OP,                                "FUTEX_WAKE_OP" },
2643         { FUTEX_LOCK_PI,                                "FUTEX_LOCK_PI" },
2644         { FUTEX_UNLOCK_PI,                              "FUTEX_UNLOCK_PI" },
2645         { FUTEX_TRYLOCK_PI,                             "FUTEX_TRYLOCK_PI" },
2646         { FUTEX_WAIT_BITSET,                            "FUTEX_WAIT_BITSET" },
2647         { FUTEX_WAKE_BITSET,                            "FUTEX_WAKE_BITSET" },
2648         { FUTEX_WAIT_REQUEUE_PI,                        "FUTEX_WAIT_REQUEUE_PI" },
2649         { FUTEX_CMP_REQUEUE_PI,                         "FUTEX_CMP_REQUEUE_PI" },
2650         { FUTEX_WAIT|FUTEX_PRIVATE_FLAG,                "FUTEX_WAIT_PRIVATE" },
2651         { FUTEX_WAKE|FUTEX_PRIVATE_FLAG,                "FUTEX_WAKE_PRIVATE" },
2652         { FUTEX_FD|FUTEX_PRIVATE_FLAG,                  "FUTEX_FD_PRIVATE" },
2653         { FUTEX_REQUEUE|FUTEX_PRIVATE_FLAG,             "FUTEX_REQUEUE_PRIVATE" },
2654         { FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG,         "FUTEX_CMP_REQUEUE_PRIVATE" },
2655         { FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG,             "FUTEX_WAKE_OP_PRIVATE" },
2656         { FUTEX_LOCK_PI|FUTEX_PRIVATE_FLAG,             "FUTEX_LOCK_PI_PRIVATE" },
2657         { FUTEX_UNLOCK_PI|FUTEX_PRIVATE_FLAG,           "FUTEX_UNLOCK_PI_PRIVATE" },
2658         { FUTEX_TRYLOCK_PI|FUTEX_PRIVATE_FLAG,          "FUTEX_TRYLOCK_PI_PRIVATE" },
2659         { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG,         "FUTEX_WAIT_BITSET_PRIVATE" },
2660         { FUTEX_WAKE_BITSET|FUTEX_PRIVATE_FLAG,         "FUTEX_WAKE_BITSET_PRIVATE" },
2661         { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG,     "FUTEX_WAIT_REQUEUE_PI_PRIVATE" },
2662         { FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG,      "FUTEX_CMP_REQUEUE_PI_PRIVATE" },
2663         { FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME,       "FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME" },
2664         { FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME,    "FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME" },
2665         { FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME,   "FUTEX_WAIT_REQUEUE_PI|FUTEX_CLOCK_REALTIME" },
2666         { FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME,        "FUTEX_WAIT_REQUEUE_PI_PRIVATE|FUTEX_CLOCK_REALTIME" },
2667         { 0,                                            NULL }
2668 };
2669 #ifndef FUTEX_OP_SET
2670 # define FUTEX_OP_SET           0
2671 # define FUTEX_OP_ADD           1
2672 # define FUTEX_OP_OR            2
2673 # define FUTEX_OP_ANDN          3
2674 # define FUTEX_OP_XOR           4
2675 # define FUTEX_OP_CMP_EQ        0
2676 # define FUTEX_OP_CMP_NE        1
2677 # define FUTEX_OP_CMP_LT        2
2678 # define FUTEX_OP_CMP_LE        3
2679 # define FUTEX_OP_CMP_GT        4
2680 # define FUTEX_OP_CMP_GE        5
2681 #endif
2682 static const struct xlat futexwakeops[] = {
2683         { FUTEX_OP_SET,         "FUTEX_OP_SET" },
2684         { FUTEX_OP_ADD,         "FUTEX_OP_ADD" },
2685         { FUTEX_OP_OR,          "FUTEX_OP_OR" },
2686         { FUTEX_OP_ANDN,        "FUTEX_OP_ANDN" },
2687         { FUTEX_OP_XOR,         "FUTEX_OP_XOR" },
2688         { 0,                    NULL }
2689 };
2690 static const struct xlat futexwakecmps[] = {
2691         { FUTEX_OP_CMP_EQ,      "FUTEX_OP_CMP_EQ" },
2692         { FUTEX_OP_CMP_NE,      "FUTEX_OP_CMP_NE" },
2693         { FUTEX_OP_CMP_LT,      "FUTEX_OP_CMP_LT" },
2694         { FUTEX_OP_CMP_LE,      "FUTEX_OP_CMP_LE" },
2695         { FUTEX_OP_CMP_GT,      "FUTEX_OP_CMP_GT" },
2696         { FUTEX_OP_CMP_GE,      "FUTEX_OP_CMP_GE" },
2697         { 0,                    NULL }
2698 };
2699
2700 int
2701 sys_futex(struct tcb *tcp)
2702 {
2703         if (entering(tcp)) {
2704                 long int cmd = tcp->u_arg[1] & 127;
2705                 tprintf("%p, ", (void *) tcp->u_arg[0]);
2706                 printxval(futexops, tcp->u_arg[1], "FUTEX_???");
2707                 tprintf(", %ld", tcp->u_arg[2]);
2708                 if (cmd == FUTEX_WAKE_BITSET)
2709                         tprintf(", %lx", tcp->u_arg[5]);
2710                 else if (cmd == FUTEX_WAIT) {
2711                         tprints(", ");
2712                         printtv(tcp, tcp->u_arg[3]);
2713                 } else if (cmd == FUTEX_WAIT_BITSET) {
2714                         tprints(", ");
2715                         printtv(tcp, tcp->u_arg[3]);
2716                         tprintf(", %lx", tcp->u_arg[5]);
2717                 } else if (cmd == FUTEX_REQUEUE)
2718                         tprintf(", %ld, %p", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2719                 else if (cmd == FUTEX_CMP_REQUEUE || cmd == FUTEX_CMP_REQUEUE_PI)
2720                         tprintf(", %ld, %p, %ld", tcp->u_arg[3], (void *) tcp->u_arg[4], tcp->u_arg[5]);
2721                 else if (cmd == FUTEX_WAKE_OP) {
2722                         tprintf(", %ld, %p, {", tcp->u_arg[3], (void *) tcp->u_arg[4]);
2723                         if ((tcp->u_arg[5] >> 28) & 8)
2724                                 tprints("FUTEX_OP_OPARG_SHIFT|");
2725                         printxval(futexwakeops, (tcp->u_arg[5] >> 28) & 0x7, "FUTEX_OP_???");
2726                         tprintf(", %ld, ", (tcp->u_arg[5] >> 12) & 0xfff);
2727                         if ((tcp->u_arg[5] >> 24) & 8)
2728                                 tprints("FUTEX_OP_OPARG_SHIFT|");
2729                         printxval(futexwakecmps, (tcp->u_arg[5] >> 24) & 0x7, "FUTEX_OP_CMP_???");
2730                         tprintf(", %ld}", tcp->u_arg[5] & 0xfff);
2731                 } else if (cmd == FUTEX_WAIT_REQUEUE_PI) {
2732                         tprints(", ");
2733                         printtv(tcp, tcp->u_arg[3]);
2734                         tprintf(", %p", (void *) tcp->u_arg[4]);
2735                 }
2736         }
2737         return 0;
2738 }
2739
2740 static void
2741 print_affinitylist(struct tcb *tcp, long list, unsigned int len)
2742 {
2743         int first = 1;
2744         unsigned long w, min_len;
2745
2746         if (abbrev(tcp) && len / sizeof(w) > max_strlen)
2747                 min_len = len - max_strlen * sizeof(w);
2748         else
2749                 min_len = 0;
2750         for (; len >= sizeof(w) && len > min_len;
2751              len -= sizeof(w), list += sizeof(w)) {
2752                 if (umove(tcp, list, &w) < 0)
2753                         break;
2754                 if (first)
2755                         tprints("{");
2756                 else
2757                         tprints(", ");
2758                 first = 0;
2759                 tprintf("%lx", w);
2760         }
2761         if (len) {
2762                 if (first)
2763                         tprintf("%#lx", list);
2764                 else
2765                         tprintf(", %s}", (len >= sizeof(w) && len > min_len ?
2766                                 "???" : "..."));
2767         } else {
2768                 tprints(first ? "{}" : "}");
2769         }
2770 }
2771
2772 int
2773 sys_sched_setaffinity(struct tcb *tcp)
2774 {
2775         if (entering(tcp)) {
2776                 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2777                 print_affinitylist(tcp, tcp->u_arg[2], tcp->u_arg[1]);
2778         }
2779         return 0;
2780 }
2781
2782 int
2783 sys_sched_getaffinity(struct tcb *tcp)
2784 {
2785         if (entering(tcp)) {
2786                 tprintf("%ld, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
2787         } else {
2788                 if (tcp->u_rval == -1)
2789                         tprintf("%#lx", tcp->u_arg[2]);
2790                 else
2791                         print_affinitylist(tcp, tcp->u_arg[2], tcp->u_rval);
2792         }
2793         return 0;
2794 }
2795
2796 int
2797 sys_get_robust_list(struct tcb *tcp)
2798 {
2799         if (entering(tcp)) {
2800                 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2801         } else {
2802                 void *addr;
2803                 size_t len;
2804
2805                 if (syserror(tcp) ||
2806                     !tcp->u_arg[1] ||
2807                     umove(tcp, tcp->u_arg[1], &addr) < 0) {
2808                         tprintf("%#lx, ", tcp->u_arg[1]);
2809                 } else {
2810                         tprintf("[%p], ", addr);
2811                 }
2812
2813                 if (syserror(tcp) ||
2814                     !tcp->u_arg[2] ||
2815                     umove(tcp, tcp->u_arg[2], &len) < 0) {
2816                         tprintf("%#lx", tcp->u_arg[2]);
2817                 } else {
2818                         tprintf("[%lu]", (unsigned long) len);
2819                 }
2820         }
2821         return 0;
2822 }
2823
2824 static const struct xlat schedulers[] = {
2825         { SCHED_OTHER,  "SCHED_OTHER" },
2826         { SCHED_RR,     "SCHED_RR" },
2827         { SCHED_FIFO,   "SCHED_FIFO" },
2828         { 0,            NULL }
2829 };
2830
2831 int
2832 sys_sched_getscheduler(struct tcb *tcp)
2833 {
2834         if (entering(tcp)) {
2835                 tprintf("%d", (int) tcp->u_arg[0]);
2836         } else if (!syserror(tcp)) {
2837                 tcp->auxstr = xlookup(schedulers, tcp->u_rval);
2838                 if (tcp->auxstr != NULL)
2839                         return RVAL_STR;
2840         }
2841         return 0;
2842 }
2843
2844 int
2845 sys_sched_setscheduler(struct tcb *tcp)
2846 {
2847         if (entering(tcp)) {
2848                 struct sched_param p;
2849                 tprintf("%d, ", (int) tcp->u_arg[0]);
2850                 printxval(schedulers, tcp->u_arg[1], "SCHED_???");
2851                 if (umove(tcp, tcp->u_arg[2], &p) < 0)
2852                         tprintf(", %#lx", tcp->u_arg[2]);
2853                 else
2854                         tprintf(", { %d }", p.__sched_priority);
2855         }
2856         return 0;
2857 }
2858
2859 int
2860 sys_sched_getparam(struct tcb *tcp)
2861 {
2862         if (entering(tcp)) {
2863                 tprintf("%d, ", (int) tcp->u_arg[0]);
2864         } else {
2865                 struct sched_param p;
2866                 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2867                         tprintf("%#lx", tcp->u_arg[1]);
2868                 else
2869                         tprintf("{ %d }", p.__sched_priority);
2870         }
2871         return 0;
2872 }
2873
2874 int
2875 sys_sched_setparam(struct tcb *tcp)
2876 {
2877         if (entering(tcp)) {
2878                 struct sched_param p;
2879                 if (umove(tcp, tcp->u_arg[1], &p) < 0)
2880                         tprintf("%d, %#lx", (int) tcp->u_arg[0], tcp->u_arg[1]);
2881                 else
2882                         tprintf("%d, { %d }", (int) tcp->u_arg[0], p.__sched_priority);
2883         }
2884         return 0;
2885 }
2886
2887 int
2888 sys_sched_get_priority_min(struct tcb *tcp)
2889 {
2890         if (entering(tcp)) {
2891                 printxval(schedulers, tcp->u_arg[0], "SCHED_???");
2892         }
2893         return 0;
2894 }
2895
2896 int
2897 sys_sched_rr_get_interval(struct tcb *tcp)
2898 {
2899         if (entering(tcp)) {
2900                 tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]);
2901         } else {
2902                 if (syserror(tcp))
2903                         tprintf("%#lx", tcp->u_arg[1]);
2904                 else
2905                         print_timespec(tcp, tcp->u_arg[1]);
2906         }
2907         return 0;
2908 }
2909
2910 #if defined X86_64 || defined X32
2911 # include <asm/prctl.h>
2912
2913 static const struct xlat archvals[] = {
2914         { ARCH_SET_GS,          "ARCH_SET_GS"           },
2915         { ARCH_SET_FS,          "ARCH_SET_FS"           },
2916         { ARCH_GET_FS,          "ARCH_GET_FS"           },
2917         { ARCH_GET_GS,          "ARCH_GET_GS"           },
2918         { 0,                    NULL                    },
2919 };
2920
2921 int
2922 sys_arch_prctl(struct tcb *tcp)
2923 {
2924         if (entering(tcp)) {
2925                 printxval(archvals, tcp->u_arg[0], "ARCH_???");
2926                 if (tcp->u_arg[0] == ARCH_SET_GS
2927                  || tcp->u_arg[0] == ARCH_SET_FS
2928                 ) {
2929                         tprintf(", %#lx", tcp->u_arg[1]);
2930                 }
2931         } else {
2932                 if (tcp->u_arg[0] == ARCH_GET_GS
2933                  || tcp->u_arg[0] == ARCH_GET_FS
2934                 ) {
2935                         long int v;
2936                         if (!syserror(tcp) && umove(tcp, tcp->u_arg[1], &v) != -1)
2937                                 tprintf(", [%#lx]", v);
2938                         else
2939                                 tprintf(", %#lx", tcp->u_arg[1]);
2940                 }
2941         }
2942         return 0;
2943 }
2944 #endif /* X86_64 || X32 */
2945
2946 int
2947 sys_getcpu(struct tcb *tcp)
2948 {
2949         if (exiting(tcp)) {
2950                 unsigned u;
2951                 if (tcp->u_arg[0] == 0)
2952                         tprints("NULL, ");
2953                 else if (umove(tcp, tcp->u_arg[0], &u) < 0)
2954                         tprintf("%#lx, ", tcp->u_arg[0]);
2955                 else
2956                         tprintf("[%u], ", u);
2957                 if (tcp->u_arg[1] == 0)
2958                         tprints("NULL, ");
2959                 else if (umove(tcp, tcp->u_arg[1], &u) < 0)
2960                         tprintf("%#lx, ", tcp->u_arg[1]);
2961                 else
2962                         tprintf("[%u], ", u);
2963                 tprintf("%#lx", tcp->u_arg[2]);
2964         }
2965         return 0;
2966 }
2967
2968 int
2969 sys_process_vm_readv(struct tcb *tcp)
2970 {
2971         if (entering(tcp)) {
2972                 /* arg 1: pid */
2973                 tprintf("%ld, ", tcp->u_arg[0]);
2974         } else {
2975                 /* arg 2: local iov */
2976                 if (syserror(tcp)) {
2977                         tprintf("%#lx", tcp->u_arg[1]);
2978                 } else {
2979                         tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
2980                 }
2981                 /* arg 3: local iovcnt */
2982                 tprintf(", %lu, ", tcp->u_arg[2]);
2983                 /* arg 4: remote iov */
2984                 if (syserror(tcp)) {
2985                         tprintf("%#lx", tcp->u_arg[3]);
2986                 } else {
2987                         tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
2988                 }
2989                 /* arg 5: remote iovcnt */
2990                 /* arg 6: flags */
2991                 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
2992         }
2993         return 0;
2994 }
2995
2996 int
2997 sys_process_vm_writev(struct tcb *tcp)
2998 {
2999         if (entering(tcp)) {
3000                 /* arg 1: pid */
3001                 tprintf("%ld, ", tcp->u_arg[0]);
3002                 /* arg 2: local iov */
3003                 if (syserror(tcp))
3004                         tprintf("%#lx", tcp->u_arg[1]);
3005                 else
3006                         tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
3007                 /* arg 3: local iovcnt */
3008                 tprintf(", %lu, ", tcp->u_arg[2]);
3009                 /* arg 4: remote iov */
3010                 if (syserror(tcp))
3011                         tprintf("%#lx", tcp->u_arg[3]);
3012                 else
3013                         tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
3014                 /* arg 5: remote iovcnt */
3015                 /* arg 6: flags */
3016                 tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
3017         }
3018         return 0;
3019 }