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 printaddr(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 tprints(x->str); 83 } else 84 if (tcp->u_arg[0] == PTRACE_GETREGSET 85 || tcp->u_arg[0] == PTRACE_SETREGSET) 86 printxval(nt_descriptor_types, tcp->u_arg[2], "NT_???"); 87 else 88 printaddr(addr); 89 tprints(", "); 90 91 switch (tcp->u_arg[0]) { 92 #ifndef IA64 93 case PTRACE_PEEKDATA: 94 case PTRACE_PEEKTEXT: 95 case PTRACE_PEEKUSER: 96 break; 97 #endif 98 case PTRACE_CONT: 99 case PTRACE_SINGLESTEP: 100 case PTRACE_SYSCALL: 101 case PTRACE_DETACH: 102 printsignal(tcp->u_arg[3]); 103 break; 104 case PTRACE_SETOPTIONS: 105 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???"); 106 break; 107 case PTRACE_SETSIGINFO: { 108 printsiginfo_at(tcp, tcp->u_arg[3]); 109 break; 110 } 111 case PTRACE_SETREGSET: 112 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0); 113 break; 114 case PTRACE_GETSIGINFO: 115 case PTRACE_GETREGSET: 116 /* Don't print anything, do it at syscall return. */ 117 break; 118 default: 119 printaddr(tcp->u_arg[3]); 120 break; 121 } 122 } else { 123 switch (tcp->u_arg[0]) { 124 case PTRACE_PEEKDATA: 125 case PTRACE_PEEKTEXT: 126 case PTRACE_PEEKUSER: 127 #ifdef IA64 128 return RVAL_HEX; 129 #else 130 printnum_ptr(tcp, tcp->u_arg[3]); 131 break; 132 #endif 133 case PTRACE_GETSIGINFO: { 134 printsiginfo_at(tcp, tcp->u_arg[3]); 135 break; 136 } 137 case PTRACE_GETREGSET: 138 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0); 139 break; 140 } 141 } 142 return 0; 143 } 144