blob: 73092a22c216ff95893218aa6907ac88fce68842 [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
Dmitry V. Levin7211dbc2015-02-28 12:20:21 +000045#include "regs.h"
Dmitry V. Levinfadf3792015-02-13 00:26:38 +000046#include "ptrace.h"
Dmitry V. Levin6eee4e02014-12-11 19:25:02 +000047#include "xlat/ptrace_cmds.h"
48#include "xlat/ptrace_setoptions_flags.h"
49
Denys Vlasenko513e9c22012-03-21 14:39:22 +010050#define uoff(member) offsetof(struct user, member)
Dmitry V. Levinc6ce4fd2014-12-11 19:25:02 +000051#define XLAT_UOFF(member) { uoff(member), "offsetof(struct user, " #member ")" }
Denys Vlasenko513e9c22012-03-21 14:39:22 +010052
Dmitry V. Levin8c0ef942014-12-11 19:25:02 +000053static const struct xlat struct_user_offsets[] = {
Dmitry V. Levinfced7b02014-12-11 19:25:02 +000054#include "userent.h"
Dmitry V. Levin59452732014-02-05 02:20:51 +000055 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056};
57
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000058SYS_FUNC(ptrace)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059{
Roland McGrathd9f816f2004-09-04 03:39:20 +000060 const struct xlat *x;
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +000061 unsigned long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063 if (entering(tcp)) {
Denys Vlasenkob7a6dae2012-03-20 16:48:35 +010064 printxval(ptrace_cmds, tcp->u_arg[0], "PTRACE_???");
Roland McGrathbf621d42003-01-14 09:46:21 +000065 tprintf(", %lu, ", tcp->u_arg[1]);
Denys Vlasenkobe994972013-02-13 16:10:10 +010066
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067 addr = tcp->u_arg[2];
68 if (tcp->u_arg[0] == PTRACE_PEEKUSER
Denys Vlasenkobe994972013-02-13 16:10:10 +010069 || tcp->u_arg[0] == PTRACE_POKEUSER
70 ) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071 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);
Denys Vlasenkobe994972013-02-13 16:10:10 +010083 } else
Dmitry V. Levinc41808b2013-03-18 00:52:29 +000084 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
Denys Vlasenkobe994972013-02-13 16:10:10 +010090 tprintf("%#lx, ", addr);
91
92
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093 switch (tcp->u_arg[0]) {
Denys Vlasenko3e3490a2012-03-17 01:27:37 +010094#ifndef IA64
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095 case PTRACE_PEEKDATA:
96 case PTRACE_PEEKTEXT:
97 case PTRACE_PEEKUSER:
98 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +010099#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100 case PTRACE_CONT:
101 case PTRACE_SINGLESTEP:
102 case PTRACE_SYSCALL:
103 case PTRACE_DETACH:
104 printsignal(tcp->u_arg[3]);
105 break;
Denys Vlasenkof535b542009-01-13 18:30:55 +0000106 case PTRACE_SETOPTIONS:
107 printflags(ptrace_setoptions_flags, tcp->u_arg[3], "PTRACE_O_???");
108 break;
Denys Vlasenkof535b542009-01-13 18:30:55 +0000109 case PTRACE_SETSIGINFO: {
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100110 printsiginfo_at(tcp, tcp->u_arg[3]);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000111 break;
112 }
Denys Vlasenkobe994972013-02-13 16:10:10 +0100113 case PTRACE_SETREGSET:
114 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
115 break;
Dmitry V. Levinfadf3792015-02-13 00:26:38 +0000116 case PTRACE_GETSIGINFO:
117 case PTRACE_GETREGSET:
118 /* Don't print anything, do it at syscall return. */
119 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120 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:
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100129#ifdef IA64
Roland McGrath1e868062007-11-19 22:11:45 +0000130 return RVAL_HEX;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100131#else
Dmitry V. Levin1c603a92015-02-17 22:03:17 +0000132 printnum_long(tcp, tcp->u_arg[3], "%#lx");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133 break;
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100134#endif
Denys Vlasenkof535b542009-01-13 18:30:55 +0000135 case PTRACE_GETSIGINFO: {
Denys Vlasenkod4d3ede2013-02-13 16:31:32 +0100136 printsiginfo_at(tcp, tcp->u_arg[3]);
Denys Vlasenkof535b542009-01-13 18:30:55 +0000137 break;
138 }
Denys Vlasenkobe994972013-02-13 16:10:10 +0100139 case PTRACE_GETREGSET:
140 tprint_iov(tcp, /*len:*/ 1, tcp->u_arg[3], /*as string:*/ 0);
141 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142 }
143 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144 return 0;
145}