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