backend.h revision 6dfc544b6aa6703d2292be34470aebf874d78452
1642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* 2642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * This file is part of ltrace. 3642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * Copyright (C) 2012 Petr Machata, Red Hat Inc. 4642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 5642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * This program is free software; you can redistribute it and/or 6642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * modify it under the terms of the GNU General Public License as 7642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * published by the Free Software Foundation; either version 2 of the 8642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * License, or (at your option) any later version. 9642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 10642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * This program is distributed in the hope that it will be useful, but 11642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of 12642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * General Public License for more details. 14642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 15642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * You should have received a copy of the GNU General Public License 16642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * along with this program; if not, write to the Free Software 17642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 02110-1301 USA 19642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata */ 20642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 21642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata#ifndef BACKEND_H 22642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata#define BACKEND_H 23642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 24642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata#include "forward.h" 25bac2da505ee174b7fb984b975c5938f88f0dbab2Petr Machata#include "sysdep.h" 26bac2da505ee174b7fb984b975c5938f88f0dbab2Petr Machata 27ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata#include <gelf.h> 28ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata 29ba1664b062414481d0f37d06bb01a19874c8d481Petr Machataenum process_status { 306dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_INVALID, /* Failure. */ 316dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_STOP, /* Job-control stop. */ 326dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_TRACING_STOP, 336dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_SLEEPING, 346dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_ZOMBIE, 356dfc544b6aa6703d2292be34470aebf874d78452Petr Machata PS_OTHER, /* Necessary other states can be added as needed. */ 36ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata}; 37ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata 38642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* 39642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * This file contains documentation of back end interface. Some of 40642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * these may be implemented on an OS level (i.e. they are the same 41642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * e.g. on all Linux architectures), some may differ per architecture 42642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * on the same OS (e.g. a way to insert a breakpoint into the process 43642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * image is a likely candidate). 44642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata */ 45642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 46642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Convert a PID to a path to the corresponding binary. */ 47642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatachar *pid2name(pid_t pid); 48642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 49642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Given a PID, find a leader of thread group. */ 50642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatapid_t process_leader(pid_t pid); 51642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 52642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Given a PID of leader thread, fill in PIDs of all the tasks. The 53642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * function will initialize the pointer *RET_TASKS to a 54642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * newly-allocated array, and will store number of elements in that 55642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * array to *RET_N. You have to free that buffer when you don't need 56642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * it anymore. */ 57642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint process_tasks(pid_t pid, pid_t **ret_tasks, size_t *ret_n); 58642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 59642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Answer whether the process PID is stopped. Returns 0 when not 60642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * stopped, 1 when stopped, or -1 when there was an error. */ 61642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint process_stopped(pid_t pid); 62642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 63642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Answer a status of the task PID. See enum process_status. */ 64642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataenum process_status process_status(pid_t pid); 65642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 66642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Wait for PID to be ready for tracing. */ 67ba1664b062414481d0f37d06bb01a19874c8d481Petr Machataint wait_for_proc(pid_t pid); 68642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 69642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Send a signal SIG to the task PID. */ 70642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint task_kill(pid_t pid, int sig); 71642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 72642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after PID is attached, but before it is continued. */ 73929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid trace_set_options(struct process *proc); 74642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 75642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after ltrace forks. Should attach the newly created child, 76642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * in whose context this function is called. */ 77642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid trace_me(void); 78642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 79642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called when ltrace needs to attach to PID, such as when it attaches 80642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * to a running process, whose PID is given on the command line. */ 81642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint trace_pid(pid_t pid); 82642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 83642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Stop tracing PID. */ 84642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid untrace_pid(pid_t pid); 85642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 86642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* The back end may need to store arbitrary data to a process. This 87642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * is a place where it can initialize PROC->arch_dep. XXX this should 88642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * be dropped in favor of arhc_process_init on pmachata/libs. */ 89929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid get_arch_dep(struct process *proc); 90642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 91642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Return current instruction pointer of PROC. 92642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 93642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * XXX note that the IP must fit into an arch pointer. This prevents 94642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * us to use 32-bit ltrace to trace 64-bit process, even on arches 95ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata * that would otherwise support this. Above we have a definition of 96bac2da505ee174b7fb984b975c5938f88f0dbab2Petr Machata * arch_addr_t. This should be converted to an integral type and 97642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * used for target addresses throughout. */ 98929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *get_instruction_pointer(struct process *proc); 99642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 100642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Set instruction pointer of PROC to ADDR. XXX see above. */ 101929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid set_instruction_pointer(struct process *proc, void *addr); 102642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 103642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Return current stack pointer of PROC. XXX see above. */ 104929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *get_stack_pointer(struct process *proc); 105642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 106642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Find and return caller address, i.e. the address where the current 107642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * function returns. */ 108929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *get_return_addr(struct process *proc, void *stack_pointer); 109642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 110642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Adjust PROC so that when the current function returns, it returns 111642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * to ADDR. */ 112929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid set_return_addr(struct process *proc, void *addr); 113642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 114642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Enable breakpoint SBP in process PROC. */ 115929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid enable_breakpoint(struct process *proc, struct breakpoint *sbp); 116642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 117642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Disable breakpoint SBP in process PROC. */ 118929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid disable_breakpoint(struct process *proc, struct breakpoint *sbp); 119642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 120642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Determine whether the event that we have just seen (and that is 121642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * recorded in STATUS) was a syscall. If it was, return 1. If it was 122642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * a return from syscall, return 2. In both cases, set *SYSNUM to the 123642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * number of said syscall. If it wasn't a syscall, return 0. If 124642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * there was an error, return -1. */ 125929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint syscall_p(struct process *proc, int status, int *sysnum); 126642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 127642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Continue execution of the process with given PID. */ 128642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid continue_process(pid_t pid); 129642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 130642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a signal SIGNUM. Should do whatever 131642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * book-keeping is necessary and continue the process if 132642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * necessary. */ 133642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid continue_after_signal(pid_t pid, int signum); 134642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 135642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a system call SYSNUM. RET_P is 0 if this 136642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * is system call, otherwise it's return from a system call. The 137642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * callback should do whatever book-keeping is necessary and continue 138642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * the process if necessary. */ 139929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_syscall(struct process *proc, int sysnum, int ret_p); 140642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 141642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we hit a breakpoint SBP. Should do whatever 142642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * book-keeping is necessary and then continue the process. */ 143929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_breakpoint(struct process *proc, struct breakpoint *sbp); 144642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 145642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a vfork. Should do whatever book-keeping 146642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * is necessary and continue the process if necessary. N.B. right 147642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * now, with Linux/GNU the only back end, this is not necessary. I 148642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * imagine other systems may be different. */ 149929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_vfork(struct process *proc); 150642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 151642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called when trace_me or primary trace_pid fail. This may plug in 152642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * any platform-specific knowledge of why it could be so. */ 153642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid trace_fail_warning(pid_t pid); 154642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 155642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* A pair of functions called to initiate a detachment request when 156642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * ltrace is about to exit. Their job is to undo any effects that 157642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * tracing had and eventually detach process, perhaps by way of 158642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * installing a process handler. 159642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 160642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * OS_LTRACE_EXITING_SIGHANDLER is called from a signal handler 161642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * context right after the signal was captured. It returns 1 if the 162642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * request was handled or 0 if it wasn't. 163642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 164642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * If the call to OS_LTRACE_EXITING_SIGHANDLER didn't handle the 165642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * request, OS_LTRACE_EXITING is called when the next event is 166642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * generated. Therefore it's called in "safe" context, without 167642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * re-entrancy concerns, but it's only called after an even is 168642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * generated. */ 169642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint os_ltrace_exiting_sighandler(void); 170642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid os_ltrace_exiting(void); 171642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 172642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Should copy COUNT bytes from address ADDR of process PROC to local 173642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * buffer BUF. */ 174929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatasize_t umovebytes(struct process *proc, void *addr, void *buf, size_t count); 175642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 176642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Find out an address of symbol SYM in process PROC, and return. 177642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * Returning NULL delays breakpoint insertion and enables heaps of 178642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * arch-specific black magic that we should clean up some day. 179642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 180642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * XXX the same points as for get_instruction_pointer apply. */ 181929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *sym2addr(struct process *proc, struct library_symbol *sym); 182642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 183311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* Obtain address of PLT entry corresponding to relocation RELA in 184311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * file LTE. This is NDX-th PLT entry in the file. 185311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 186311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * XXX should this return arch_addr_t? */ 187311358a1cac22781ecffe697a808bd43eac73bcePetr MachataGElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela *rela); 188311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 189642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called at some point after we have attached to PROC. This callback 190ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata * should insert an introspection breakpoint for handling dynamic 191ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata * linker library loads. */ 192929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint linkmap_init(struct process *proc, arch_addr_t dyn_addr); 193642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 194642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* This should produce and return the next event of one of the traced 195642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * processes. The returned pointer will not be freed by the core and 196642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * should be either statically allocated, or the management should be 197642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * done some other way. */ 198642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatastruct Event *next_event(void); 199642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 200642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called when process PROC was removed. */ 201929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid process_removed(struct process *proc); 202642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 203311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* This should extract entry point address and interpreter (dynamic 204311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * linker) bias if possible. Returns 0 if there were no errors, -1 205311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * otherwise. Sets *ENTRYP and *INTERP_BIASP to non-zero values if 206da69ed0785ff0a9790f8edadb73fe21013aa118bPetr Machata * the corresponding value is known, or zero otherwise; this is not 207da69ed0785ff0a9790f8edadb73fe21013aa118bPetr Machata * done for pointers that are NULL. */ 208929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_get_entry(struct process *proc, 209311358a1cac22781ecffe697a808bd43eac73bcePetr Machata arch_addr_t *entryp, 210311358a1cac22781ecffe697a808bd43eac73bcePetr Machata arch_addr_t *interp_biasp); 211311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 212311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 213311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* Optional callbacks 214311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 215311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * Some callbacks are only available if backend (arch.h) has a certain 216311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * define. If such a define is not present, default implementation 217311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * (most often doing nothing at all) us used instead. This is used 218311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * for gradual extensions of ltrace, so that backends that are not 219311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * fully up to date, or that don't need certain functionality, keep 220311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * working, while other backends take advantage of the optional 221311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * features. */ 222311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 223311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 224311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LTELF_DATA. Those are used to init and destroy 225311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * LTE->arch. arch_elf_init returns 0 on success or a negative value 226311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * on failure. */ 227642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_elf_init(struct ltelf *lte, struct library *lib); 228642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_elf_destroy(struct ltelf *lte); 229642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 230311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 231311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_BREAKPOINT_DATA. Those are used to init, 232311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * destroy, and clone SBP->arch. arch_breakpoint_init and 233311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_breakpoint_clone return 0 on success or a negative value on 234311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * failure. */ 235929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_breakpoint_init(struct process *proc, struct breakpoint *sbp); 236642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_breakpoint_destroy(struct breakpoint *sbp); 237642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_breakpoint_clone(struct breakpoint *retp, struct breakpoint *sbp); 238642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 239311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 240311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LIBRARY_DATA. Those are used to init, destroy 241311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * and clone LIB->arch. */ 242642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_init(struct library *lib); 243642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_destroy(struct library *lib); 244642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_clone(struct library *retp, struct library *lib); 245642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 246311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 247311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LIBRARY_SYMBOL_DATA. Those are used to init, 248311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * destroy and clone LIBSYM->arch. arch_library_symbol_init and 249311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_library_symbol_clone return 0 on success or a negative value 250311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * on failure. */ 251642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_library_symbol_init(struct library_symbol *libsym); 252642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_symbol_destroy(struct library_symbol *libsym); 253642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_library_symbol_clone(struct library_symbol *retp, 254642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata struct library_symbol *libsym); 255642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 256311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 257311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_PROCESS_DATA. Those are used to init, destroy 258311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * and clone PROC->arch. arch_process_exec is called to update 259311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * PROC->arch in case that PROC underwent an exec. See notes at 260311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * process_init, process_destroy, process_clone and process_exec in 261311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * proc.h. */ 262929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_init(struct process *proc); 263929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_process_destroy(struct process *proc); 264929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_clone(struct process *retp, struct process *proc); 265929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_exec(struct process *proc); 266642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 2670f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata/* The following callbacks have to be implemented in OS backend if 2680f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata * os.h defines OS_HAVE_PROCESS_DATA. The protocol is same as for, 2690f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata * respectively, arch_process_init, arch_process_destroy, 2700f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata * arch_process_clone and arch_process_exec. */ 271929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint os_process_init(struct process *proc); 272929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid os_process_destroy(struct process *proc); 273929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint os_process_clone(struct process *retp, struct process *proc); 274929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint os_process_exec(struct process *proc); 2750f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata 276b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias/* The following callback has to be implemented in backend if arch.h 277b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * defines ARCH_HAVE_GET_SYM_INFO. 278b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * 279b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * This is called for every PLT relocation R in ELF file LTE, that 280b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * ltrace is about to add to it's internal representation of the 281b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * program under trace. 282b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * The corresponding PLT entry is for SYM_INDEX-th relocation in the file. 283b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * 284b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * The callback is responsible for initializing RELA and SYM. 285b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * 286b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * Return 0 if OK. 287b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * Return a negative value if this symbol (SYM_INDEX) should be ignored. */ 288b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesiasint arch_get_sym_info(struct ltelf *lte, const char *filename, 289b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias size_t sym_index, GElf_Rela *rela, GElf_Sym *sym); 290b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias 291311358a1cac22781ecffe697a808bd43eac73bcePetr Machataenum plt_status { 292311358a1cac22781ecffe697a808bd43eac73bcePetr Machata plt_fail, 293311358a1cac22781ecffe697a808bd43eac73bcePetr Machata plt_ok, 294311358a1cac22781ecffe697a808bd43eac73bcePetr Machata plt_default, 295311358a1cac22781ecffe697a808bd43eac73bcePetr Machata}; 296642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 297311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callback has to be implemented in backend if arch.h 298311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_ADD_PLT_ENTRY. 299311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 300311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * This is called for every PLT relocation R in ELF file LTE, that 301311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ltrace is about to add to a library constructed in process PROC. 302311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * The corresponding PLT entry is for symbol called NAME, and it's 303311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * I-th relocation in the file. 304311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 305311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * If this function returns plt_default, PLT address is obtained by 306311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * calling arch_plt_sym_val, and symbol is allocated. If plt_ok or 307311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * plt_default are returned, the chain of symbols passed back in RET 308311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * is added to library under construction. */ 309929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataenum plt_status arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte, 310311358a1cac22781ecffe697a808bd43eac73bcePetr Machata const char *name, GElf_Rela *rela, 311311358a1cac22781ecffe697a808bd43eac73bcePetr Machata size_t i, struct library_symbol **ret); 312311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 313311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* This callback needs to be implemented if arch.h defines 314311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ARCH_HAVE_DYNLINK_DONE. It is called after the dynamic linker is 315311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * done with the process startup. */ 316929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_dynlink_done(struct process *proc); 317642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 3183a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias/* This callback needs to be implemented if arch.h defines 3193a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias * ARCH_HAVE_SYMBOL_RET. It is called after a traced call returns. */ 320929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_symbol_ret(struct process *proc, struct library_symbol *libsym); 3213a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias 32211c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias 32311c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias/* This callback needs to be implemented if arch.h defines 32411c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * ARCH_HAVE_FIND_DL_DEBUG. 32511c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * It is called by generic code to find the address of the dynamic 32611c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * linkers debug structure. 32711c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * DYN_ADDR holds the address of the dynamic section. 32811c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * If the debug area is found, return 0 and fill in the address in *RET. 32911c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * If the debug area is not found, return a negative value. */ 330929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_find_dl_debug(struct process *proc, arch_addr_t dyn_addr, 33111c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias arch_addr_t *ret); 33211c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias 333311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* If arch.h defines ARCH_HAVE_FETCH_ARG, the following callbacks have 334311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * to be implemented: arch_fetch_arg_init, arch_fetch_arg_clone, 335311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_fetch_arg_done, arch_fetch_arg_next and arch_fetch_retval. 336311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * See fetch.h for details. */ 337311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 338311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* If arch.h defines both ARCH_HAVE_FETCH_ARG and 339311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ARCH_HAVE_FETCH_PACK, the following callbacks have to be 340311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * implemented: arch_fetch_param_pack_start, 341311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_fetch_param_pack_end. See fetch.h for details. */ 342311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 343642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata#endif /* BACKEND_H */ 344