trace.c revision e99af270a60891e68d465c4cd97dbe29cd1a05e4
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 1998,2001,2004,2008,2009 Juan Cespedes 4 * Copyright (C) 2009 Juan Cespedes 5 * Copyright (C) 2006 Ian Wienand 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA 21 */ 22 23#include "config.h" 24 25#include <sys/types.h> 26#include <sys/wait.h> 27#include <signal.h> 28#include <sys/ptrace.h> 29#include <asm/ptrace.h> 30 31#include "proc.h" 32#include "common.h" 33 34#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 35# define PTRACE_PEEKUSER PTRACE_PEEKUSR 36#endif 37 38#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 39# define PTRACE_POKEUSER PTRACE_POKEUSR 40#endif 41 42void 43get_arch_dep(Process *proc) { 44} 45 46/* Returns 1 if syscall, 2 if sysret, 0 otherwise. 47 */ 48int 49syscall_p(Process *proc, int status, int *sysnum) { 50 int depth; 51 52 if (WIFSTOPPED(status) 53 && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { 54 *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_ORIG_D0, 0); 55 if (*sysnum == -1) 56 return 0; 57 if (*sysnum >= 0) { 58 depth = proc->callstack_depth; 59 if (depth > 0 && 60 proc->callstack[depth - 1].is_syscall && 61 proc->callstack[depth - 1].c_un.syscall == *sysnum) { 62 return 2; 63 } else { 64 return 1; 65 } 66 } 67 } 68 return 0; 69} 70