blob: bb888ce89a011f00bbb8db3950ea69b072df79f8 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * 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>
Wichert Akkermanccef6372002-05-01 16:39:22 +00009 * Copyright (c) 2000 PocketPenguins Inc. Linux for Hitachi SuperH
10 * port by Greg Banks <gbanks@pocketpenguins.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000011 *
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000012 * 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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035 */
36
37#include "defs.h"
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000038
Dmitry V. Levinc41808b2013-03-18 00:52:29 +000039#ifdef HAVE_ELF_H
40# include <elf.h>
41#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000043#include "xlat/nt_descriptor_types.h"
44
45#include <sys/user.h>
Wichert Akkerman36915a11999-07-13 15:45:02 +000046#ifdef HAVE_SYS_REG_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047# include <sys/reg.h>
Wichert Akkerman15dea971999-10-06 13:06:34 +000048#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049
Roland McGrath5bd7cf82003-01-24 04:31:18 +000050#ifdef HAVE_LINUX_PTRACE_H
Denys Vlasenko84703742012-02-25 02:38:52 +010051# undef PTRACE_SYSCALL
Roland McGrathfb1bc072004-03-01 21:29:24 +000052# ifdef HAVE_STRUCT_IA64_FPREG
53# define ia64_fpreg XXX_ia64_fpreg
54# endif
55# ifdef HAVE_STRUCT_PT_ALL_USER_REGS
56# define pt_all_user_regs XXX_pt_all_user_regs
57# endif
Ali Polatel0b4060f2013-09-24 20:04:32 +030058# ifdef HAVE_STRUCT_PTRACE_PEEKSIGINFO_ARGS
59# define ptrace_peeksiginfo_args XXX_ptrace_peeksiginfo_args
60# endif
Denys Vlasenko84703742012-02-25 02:38:52 +010061# include <linux/ptrace.h>
Ali Polatel0b4060f2013-09-24 20:04:32 +030062# undef ptrace_peeksiginfo_args
Roland McGrathfb1bc072004-03-01 21:29:24 +000063# undef ia64_fpreg
64# undef pt_all_user_regs
Roland McGrath5bd7cf82003-01-24 04:31:18 +000065#endif
66
Denys Vlasenko84703742012-02-25 02:38:52 +010067#if defined(SPARC64)
Roland McGrath6d1a65c2004-07-12 07:44:08 +000068# define r_pc r_tpc
69# undef PTRACE_GETREGS
70# define PTRACE_GETREGS PTRACE_GETREGS64
71# undef PTRACE_SETREGS
72# define PTRACE_SETREGS PTRACE_SETREGS64
Denys Vlasenko84703742012-02-25 02:38:52 +010073#endif
Roland McGrath6d1a65c2004-07-12 07:44:08 +000074
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000075#include "xlat/ptrace_cmds.h"
76#include "xlat/ptrace_setoptions_flags.h"
77
Denys Vlasenko84703742012-02-25 02:38:52 +010078#if defined(IA64)
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +000079# include <asm/ptrace_offsets.h>
80# include <asm/rse.h>
81#endif
82
Denys Vlasenko513e9c22012-03-21 14:39:22 +010083#define uoff(member) offsetof(struct user, member)
Dmitry V. Levinc6ce4fd2014-12-11 19:25:02 +000084#define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
Denys Vlasenko513e9c22012-03-21 14:39:22 +010085
Dmitry V. Levin8c0ef942014-12-11 19:25:02 +000086static const struct xlat struct_user_offsets[] = {
Dmitry V. Levinfced7b02014-12-11 19:25:02 +000087#include "userent.h"
Dmitry V. Levin59452732014-02-05 02:20:51 +000088 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000089};
90
91int
Denys Vlasenkoc7e83712009-02-24 12:59:47 +000092sys_ptrace(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093{
Roland McGrathd9f816f2004-09-04 03:39:20 +000094 const struct xlat *x;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +000095 unsigned long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097 if (entering(tcp)) {
Denys Vlasenkob7a6dae2012-03-20 16:48:35 +010098 printxval(ptrace_cmds, tcp->u_arg[0], "PTRACE_???");
Roland McGrathbf621d42003-01-14 09:46:21 +000099 tprintf(", %lu, ", tcp->u_arg[1]);
Denys Vlasenkobe994972013-02-13 16:10:10 +0100100
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101 addr = tcp->u_arg[2];
102 if (tcp->u_arg[0] == PTRACE_PEEKUSER
Denys Vlasenkobe994972013-02-13 16:10:10 +0100103 || tcp->u_arg[0] == PTRACE_POKEUSER
104 ) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105 for (x = struct_user_offsets; x->str; x++) {
106 if (x->val >= addr)
107 break;
108 }
109 if (!x->str)
110 tprintf("%#lx, ", addr);
111 else if (x->val > addr && x != struct_user_offsets) {
112 x--;
113 tprintf("%s + %ld, ", x->str, addr - x->val);
114 }
115 else
116 tprintf("%s, ", x->str);
Denys Vlasenkobe994972013-02-13 16:10:10 +0100117 } else
118#ifdef PTRACE_GETREGSET
Dmitry V. Levinc41808b2013-03-18 00:52:29 +0000119 if (tcp->u_arg[0] == PTRACE_GETREGSET
120 || tcp->u_arg[0] == PTRACE_SETREGSET
121 ) {
122 printxval(nt_descriptor_types, tcp->u_arg[2], "NT_???");
123 tprints(", ");
124 } else
Denys Vlasenkobe994972013-02-13 16:10:10 +0100125#endif
126 tprintf("%#lx, ", addr);
127
128
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129 switch (tcp->u_arg[0]) {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100130#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131 case PTRACE_PEEKDATA:
132 case PTRACE_PEEKTEXT:
133 case PTRACE_PEEKUSER:
134 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100135#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136 case PTRACE_CONT:
137 case PTRACE_SINGLESTEP:
138 case PTRACE_SYSCALL:
139 case PTRACE_DETACH:
140 printsignal(tcp->u_arg[3]);
141 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100142#ifdef PTRACE_SETOPTIONS
Denys Vlasenkof535b542009-01-13 18:30:55 +0000143 case PTRACE_SETOPTIONS:
144 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
145 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100146#endif
147#ifdef PTRACE_SETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +0000148 case PTRACE_SETSIGINFO: {
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100149 printsiginfo_at(tcp, tcp->u_arg[3]);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000150 break;
151 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100152#endif
153#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +0000154 case PTRACE_GETSIGINFO:
155 /* Don't print anything, do it at syscall return. */
156 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100157#endif
Denys Vlasenkobe994972013-02-13 16:10:10 +0100158#ifdef PTRACE_GETREGSET
159 case PTRACE_GETREGSET:
160 break;
161 case PTRACE_SETREGSET:
162 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
163 break;
164#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165 default:
166 tprintf("%#lx", tcp->u_arg[3]);
167 break;
168 }
169 } else {
170 switch (tcp->u_arg[0]) {
171 case PTRACE_PEEKDATA:
172 case PTRACE_PEEKTEXT:
173 case PTRACE_PEEKUSER:
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100174#ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +0000175 return RVAL_HEX;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100176#else
Roland McGratheb285352003-01-14 09:59:00 +0000177 printnum(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100179#endif
180#ifdef PTRACE_GETSIGINFO
Denys Vlasenkof535b542009-01-13 18:30:55 +0000181 case PTRACE_GETSIGINFO: {
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100182 printsiginfo_at(tcp, tcp->u_arg[3]);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000183 break;
184 }
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100185#endif
Denys Vlasenkobe994972013-02-13 16:10:10 +0100186#ifdef PTRACE_GETREGSET
187 case PTRACE_GETREGSET:
188 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
189 break;
190#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 }
192 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193 return 0;
194}