1e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata/* 2e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This file is part of ltrace. 344ae188c8dcd2727e383dcac0d46c3f784d0da5fPetr Machata * Copyright (C) 2013 Petr Machata, Red Hat Inc. 4e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * Copyright (C) 2004,2008,2009 Juan Cespedes 5e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * Copyright (C) 2006 Ian Wienand 6e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * 7e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This program is free software; you can redistribute it and/or 8e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * modify it under the terms of the GNU General Public License as 9e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * published by the Free Software Foundation; either version 2 of the 10e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * License, or (at your option) any later version. 11e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * 12e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This program is distributed in the hope that it will be useful, but 13e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of 14e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * General Public License for more details. 16e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * 17e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * You should have received a copy of the GNU General Public License 18e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * along with this program; if not, write to the Free Software 19e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * 02110-1301 USA 21e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata */ 22e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata 235c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes#include "config.h" 245c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes 255c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes#include <sys/types.h> 265c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes#include "ptrace.h" 27366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "proc.h" 28f728123bd75a65a6a1536e198c3c30719e494e71Juan Cespedes#include "common.h" 295c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes 30f13505251e6402460f6cc7ec84e0d8ca91607b4fJuan Cespedesvoid * 31929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataget_instruction_pointer(struct process *proc) 32929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata{ 332d45b1a8e26a36a9f85dc49e721c4390ca93dc40Ian Wienand proc_archdep *a = (proc_archdep *) (proc->arch_ptr); 345c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes if (a->valid) 353458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes return (void *)a->regs.pc; 365c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes return (void *)-1; 375c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes} 385c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes 39f13505251e6402460f6cc7ec84e0d8ca91607b4fJuan Cespedesvoid 40929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataset_instruction_pointer(struct process *proc, void *addr) 41929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata{ 422d45b1a8e26a36a9f85dc49e721c4390ca93dc40Ian Wienand proc_archdep *a = (proc_archdep *) (proc->arch_ptr); 435c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes if (a->valid) 443458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes a->regs.pc = (long)addr; 455c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes} 465c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes 47f13505251e6402460f6cc7ec84e0d8ca91607b4fJuan Cespedesvoid * 48929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataget_stack_pointer(struct process *proc) 49929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata{ 502d45b1a8e26a36a9f85dc49e721c4390ca93dc40Ian Wienand proc_archdep *a = (proc_archdep *) (proc->arch_ptr); 515c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes if (a->valid) 523458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes return (void *)a->regs.u_regs[UREG_I5]; 535c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes return (void *)-1; 545c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes} 555c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes 56f13505251e6402460f6cc7ec84e0d8ca91607b4fJuan Cespedesvoid * 57929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataget_return_addr(struct process *proc, void *stack_pointer) 58929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata{ 592d45b1a8e26a36a9f85dc49e721c4390ca93dc40Ian Wienand proc_archdep *a = (proc_archdep *) (proc->arch_ptr); 605c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes unsigned int t; 615c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes if (!a->valid) 625c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes return (void *)-1; 635c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes /* Work around structure returns */ 643458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes t = ptrace(PTRACE_PEEKTEXT, proc->pid, a->regs.u_regs[UREG_I6] + 8, 0); 655c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes if (t < 0x400000) 663458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes return (void *)a->regs.u_regs[UREG_I6] + 12; 673458456ffbf0b6d85e1818dea7cbeacc8b1d2298Juan Cespedes return (void *)a->regs.u_regs[UREG_I6] + 8; 685c3fe0697b202cc7d95e90459de0fb312b297b27Juan Cespedes} 69