1642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* 2642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * This file is part of ltrace. 3693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * Copyright (C) 2012,2013 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/* Enable breakpoint SBP in process PROC. */ 111929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid enable_breakpoint(struct process *proc, struct breakpoint *sbp); 112642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 113642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Disable breakpoint SBP in process PROC. */ 114929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid disable_breakpoint(struct process *proc, struct breakpoint *sbp); 115642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 116642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Determine whether the event that we have just seen (and that is 117642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * recorded in STATUS) was a syscall. If it was, return 1. If it was 118642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * a return from syscall, return 2. In both cases, set *SYSNUM to the 119642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * number of said syscall. If it wasn't a syscall, return 0. If 120642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * there was an error, return -1. */ 121929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint syscall_p(struct process *proc, int status, int *sysnum); 122642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 123642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Continue execution of the process with given PID. */ 124642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid continue_process(pid_t pid); 125642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 126642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a signal SIGNUM. Should do whatever 127642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * book-keeping is necessary and continue the process if 128642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * necessary. */ 129642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid continue_after_signal(pid_t pid, int signum); 130642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 131642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a system call SYSNUM. RET_P is 0 if this 132642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * is system call, otherwise it's return from a system call. The 133642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * callback should do whatever book-keeping is necessary and continue 134642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * the process if necessary. */ 135929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_syscall(struct process *proc, int sysnum, int ret_p); 136642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 137642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we hit a breakpoint SBP. Should do whatever 138642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * book-keeping is necessary and then continue the process. */ 139929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_breakpoint(struct process *proc, struct breakpoint *sbp); 140642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 141642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called after we received a vfork. Should do whatever book-keeping 142642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * is necessary and continue the process if necessary. N.B. right 143642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * now, with Linux/GNU the only back end, this is not necessary. I 144642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * imagine other systems may be different. */ 145929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid continue_after_vfork(struct process *proc); 146642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 147057caa59fc0063bd73568b0ae19bbf668b572737Petr Machata/* Called after the process exec's. Should do whatever book-keeping 148057caa59fc0063bd73568b0ae19bbf668b572737Petr Machata * is necessary and then continue the process. */ 149057caa59fc0063bd73568b0ae19bbf668b572737Petr Machatavoid continue_after_exec(struct process *proc); 150057caa59fc0063bd73568b0ae19bbf668b572737Petr 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. */ 17479e64bcb176442b0eef89764d5ea7f07972dd240Petr Machatasize_t umovebytes(struct process *proc, arch_addr_t addr, 17579e64bcb176442b0eef89764d5ea7f07972dd240Petr Machata void *buf, size_t count); 176642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 177642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Find out an address of symbol SYM in process PROC, and return. 178642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * Returning NULL delays breakpoint insertion and enables heaps of 179642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * arch-specific black magic that we should clean up some day. 180642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * 181642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * XXX the same points as for get_instruction_pointer apply. */ 182929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *sym2addr(struct process *proc, struct library_symbol *sym); 183642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 184311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* Obtain address of PLT entry corresponding to relocation RELA in 185311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * file LTE. This is NDX-th PLT entry in the file. 186311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 187311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * XXX should this return arch_addr_t? */ 188311358a1cac22781ecffe697a808bd43eac73bcePetr MachataGElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela *rela); 189311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 190642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called at some point after we have attached to PROC. This callback 191ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata * should insert an introspection breakpoint for handling dynamic 192ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata * linker library loads. */ 193929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint linkmap_init(struct process *proc, arch_addr_t dyn_addr); 194642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 195642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* This should produce and return the next event of one of the traced 196642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * processes. The returned pointer will not be freed by the core and 197642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * should be either statically allocated, or the management should be 198642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata * done some other way. */ 199642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatastruct Event *next_event(void); 200642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 201642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata/* Called when process PROC was removed. */ 202929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid process_removed(struct process *proc); 203642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 204311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* This should extract entry point address and interpreter (dynamic 205311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * linker) bias if possible. Returns 0 if there were no errors, -1 206311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * otherwise. Sets *ENTRYP and *INTERP_BIASP to non-zero values if 207da69ed0785ff0a9790f8edadb73fe21013aa118bPetr Machata * the corresponding value is known, or zero otherwise; this is not 208da69ed0785ff0a9790f8edadb73fe21013aa118bPetr Machata * done for pointers that are NULL. */ 209929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_get_entry(struct process *proc, 210311358a1cac22781ecffe697a808bd43eac73bcePetr Machata arch_addr_t *entryp, 211311358a1cac22781ecffe697a808bd43eac73bcePetr Machata arch_addr_t *interp_biasp); 212311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 213311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 214311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* Optional callbacks 215311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 216311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * Some callbacks are only available if backend (arch.h) has a certain 217311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * define. If such a define is not present, default implementation 218311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * (most often doing nothing at all) us used instead. This is used 219311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * for gradual extensions of ltrace, so that backends that are not 220311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * fully up to date, or that don't need certain functionality, keep 221311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * working, while other backends take advantage of the optional 222311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * features. */ 223311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 224311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 225311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LTELF_DATA. Those are used to init and destroy 226311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * LTE->arch. arch_elf_init returns 0 on success or a negative value 227311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * on failure. */ 228642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_elf_init(struct ltelf *lte, struct library *lib); 229642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_elf_destroy(struct ltelf *lte); 230642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 2319f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata/* The following callbacks have to be implemented in OS backend if 2329f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata * os.h defines OS_HAVE_BREAKPOINT_DATA. Those are used to init, 2339f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata * destroy, and clone SBP->os. os_breakpoint_init and 2349f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata * os_breakpoint_clone return 0 on success or a negative value on 2359f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata * failure. */ 2369f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machataint os_breakpoint_init(struct process *proc, struct breakpoint *sbp); 2379f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machatavoid os_breakpoint_destroy(struct breakpoint *sbp); 2389f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machataint os_breakpoint_clone(struct breakpoint *retp, struct breakpoint *sbp); 2399f819d5747dc2b8e0f7ac54b38dc321115de6ddaPetr Machata 240311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 241311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_BREAKPOINT_DATA. Those are used to init, 242311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * destroy, and clone SBP->arch. arch_breakpoint_init and 243311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_breakpoint_clone return 0 on success or a negative value on 244311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * failure. */ 245929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_breakpoint_init(struct process *proc, struct breakpoint *sbp); 246642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_breakpoint_destroy(struct breakpoint *sbp); 247642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_breakpoint_clone(struct breakpoint *retp, struct breakpoint *sbp); 248642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 2498fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata/* The following callbacks have to be implemented in OS backend if 2508fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * os.h defines OS_HAVE_LIBRARY_DATA. Those are used to init, destroy 2518fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * and clone LIB->os. os_library_init and os_library_clone return 0 2528fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * on success or a negative value on failure. */ 2538fdd09b028426f92df614d6ebe5c56d99877febfPetr Machataint os_library_init(struct library *lib); 2548fdd09b028426f92df614d6ebe5c56d99877febfPetr Machatavoid os_library_destroy(struct library *lib); 2558fdd09b028426f92df614d6ebe5c56d99877febfPetr Machataint os_library_clone(struct library *retp, struct library *lib); 2568fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata 257311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 258311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LIBRARY_DATA. Those are used to init, destroy 2597287166e8fd5949ffcf8eb1f3d378b5ea538915ePetr Machata * and clone LIB->arch. arch_library_init and arch_library_clone 2607287166e8fd5949ffcf8eb1f3d378b5ea538915ePetr Machata * return 0 on success or a negative value on failure. */ 2617287166e8fd5949ffcf8eb1f3d378b5ea538915ePetr Machataint arch_library_init(struct library *lib); 262642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_destroy(struct library *lib); 2637287166e8fd5949ffcf8eb1f3d378b5ea538915ePetr Machataint arch_library_clone(struct library *retp, struct library *lib); 264642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 2658fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata/* The following callbacks have to be implemented in OS backend if 2668fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * os.h defines OS_HAVE_LIBRARY_SYMBOL_DATA. Those are used to init, 2678fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * destroy and clone LIBSYM->os. os_library_symbol_init and 2688fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * os_library_symbol_clone return 0 on success or a negative value on 2698fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata * failure. */ 2708fdd09b028426f92df614d6ebe5c56d99877febfPetr Machataint os_library_symbol_init(struct library_symbol *libsym); 2718fdd09b028426f92df614d6ebe5c56d99877febfPetr Machatavoid os_library_symbol_destroy(struct library_symbol *libsym); 2728fdd09b028426f92df614d6ebe5c56d99877febfPetr Machataint os_library_symbol_clone(struct library_symbol *retp, 2738fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata struct library_symbol *libsym); 2748fdd09b028426f92df614d6ebe5c56d99877febfPetr Machata 275311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 276311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_LIBRARY_SYMBOL_DATA. Those are used to init, 277311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * destroy and clone LIBSYM->arch. arch_library_symbol_init and 278311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_library_symbol_clone return 0 on success or a negative value 279311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * on failure. */ 280642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_library_symbol_init(struct library_symbol *libsym); 281642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machatavoid arch_library_symbol_destroy(struct library_symbol *libsym); 282642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machataint arch_library_symbol_clone(struct library_symbol *retp, 283642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata struct library_symbol *libsym); 284642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 28523124cc5c33c6b7a547eb1008505f60590f67593Petr Machata/* The following callbacks have to be implemented in OS backend if 28623124cc5c33c6b7a547eb1008505f60590f67593Petr Machata * os.h defines OS_HAVE_PROCESS_DATA. The protocol is same as for, 28723124cc5c33c6b7a547eb1008505f60590f67593Petr Machata * respectively, arch_process_init, arch_process_destroy, 28823124cc5c33c6b7a547eb1008505f60590f67593Petr Machata * arch_process_clone and arch_process_exec. */ 28923124cc5c33c6b7a547eb1008505f60590f67593Petr Machataint os_process_init(struct process *proc); 29023124cc5c33c6b7a547eb1008505f60590f67593Petr Machatavoid os_process_destroy(struct process *proc); 29123124cc5c33c6b7a547eb1008505f60590f67593Petr Machataint os_process_clone(struct process *retp, struct process *proc); 29223124cc5c33c6b7a547eb1008505f60590f67593Petr Machataint os_process_exec(struct process *proc); 29323124cc5c33c6b7a547eb1008505f60590f67593Petr Machata 294311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* The following callbacks have to be implemented in backend if arch.h 295311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * defines ARCH_HAVE_PROCESS_DATA. Those are used to init, destroy 296311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * and clone PROC->arch. arch_process_exec is called to update 297311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * PROC->arch in case that PROC underwent an exec. See notes at 298311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * process_init, process_destroy, process_clone and process_exec in 299311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * proc.h. */ 300929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_init(struct process *proc); 301929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_process_destroy(struct process *proc); 302929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_clone(struct process *retp, struct process *proc); 303929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_process_exec(struct process *proc); 304642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 305b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias/* The following callback has to be implemented in backend if arch.h 306b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * defines ARCH_HAVE_GET_SYM_INFO. 307b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias * 308552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata * This is called for every PLT relocation RELA in ELF file LTE (which 309552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata * is named FILENAME), that ltrace is about to add. The corresponding 310552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata * PLT entry is for SYM_INDEX-th relocation in the file. This call is 311552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata * supposed to initialize SYM and RELA. It returns 0 if there were no 312552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata * errors and given symbol should be used, 1 if the symbol should not 313673ff510953b65b844a58478aa434120f457c014Petr Machata * be used, or a negative value if there were errors. */ 314552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machataint arch_get_sym_info(struct ltelf *lte, const char *filename, size_t sym_index, 315552d75e2a226782cc9ecf966e6e343af8f51031fPetr Machata GElf_Rela *rela, GElf_Sym *sym); 316b5920d12ceb3dec3d359d8b2972fd22a30c72a66Edgar E. Iglesias 317311358a1cac22781ecffe697a808bd43eac73bcePetr Machataenum plt_status { 318ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata PLT_FAIL, 319ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata PLT_OK, 320ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata PLT_DEFAULT, 321311358a1cac22781ecffe697a808bd43eac73bcePetr Machata}; 322642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 32397d13666cd84589135ba593fa43a800d098026d0Petr Machata/* The following callback has to be implemented in OS backend if os.h 32497d13666cd84589135ba593fa43a800d098026d0Petr Machata * defines OS_HAVE_ADD_PLT_ENTRY. 325311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 326311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * This is called for every PLT relocation R in ELF file LTE, that 327311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ltrace is about to add to a library constructed in process PROC. 328311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * The corresponding PLT entry is for symbol called NAME, and it's 329311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * I-th relocation in the file. 330311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * 331ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata * If this function returns PLT_DEFAULT, PLT address is obtained by 332ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata * calling arch_plt_sym_val, and symbol is allocated. If PLT_OK or 333ade3b9798fbc62becbe1b4854f7a2d106498167aPetr Machata * PLT_DEFAULT are returned, the chain of symbols passed back in RET 334311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * is added to library under construction. */ 33597d13666cd84589135ba593fa43a800d098026d0Petr Machataenum plt_status os_elf_add_plt_entry(struct process *proc, struct ltelf *lte, 33697d13666cd84589135ba593fa43a800d098026d0Petr Machata const char *name, GElf_Rela *rela, 33797d13666cd84589135ba593fa43a800d098026d0Petr Machata size_t i, struct library_symbol **ret); 33897d13666cd84589135ba593fa43a800d098026d0Petr Machata 33997d13666cd84589135ba593fa43a800d098026d0Petr Machata/* Like os_elf_add_plt_entry, but tied to ARCH_HAVE_ADD_PLT_ENTRY in 34097d13666cd84589135ba593fa43a800d098026d0Petr Machata * arch.h. The arch callback is called first. If it returns 34197d13666cd84589135ba593fa43a800d098026d0Petr Machata * PLT_DEFAULT, the os callback is called next. */ 342929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataenum plt_status arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte, 343311358a1cac22781ecffe697a808bd43eac73bcePetr Machata const char *name, GElf_Rela *rela, 344311358a1cac22781ecffe697a808bd43eac73bcePetr Machata size_t i, struct library_symbol **ret); 345311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 34697d13666cd84589135ba593fa43a800d098026d0Petr Machata/* The following callback has to be implemented in OS backend if os.h 347a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * defines OS_HAVE_ADD_FUNC_ENTRY. 348a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * 349a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * This is called for every symbol in ltrace is about to add to the 350a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * library constructed for LTE in process PROC. 351a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * 352a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * If this function returns PLT_DEFAULT, then if there is a 353a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * pre-existing symbol, its name may be updated if the newly-found 354a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * name is shorter. Otherwise a new symbol is created. 355a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * 356a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * If PLT_OK or PLT_DEFAULT are returned, the chain of symbols passed 357a186b0e5c469156b9af66e88dca12d208418195cPetr Machata * back in RET is added to library under construction. */ 358a186b0e5c469156b9af66e88dca12d208418195cPetr Machataenum plt_status os_elf_add_func_entry(struct process *proc, struct ltelf *lte, 359a186b0e5c469156b9af66e88dca12d208418195cPetr Machata const GElf_Sym *sym, 360a186b0e5c469156b9af66e88dca12d208418195cPetr Machata arch_addr_t addr, const char *name, 361a186b0e5c469156b9af66e88dca12d208418195cPetr Machata struct library_symbol **ret); 362a186b0e5c469156b9af66e88dca12d208418195cPetr Machata 36397d13666cd84589135ba593fa43a800d098026d0Petr Machata/* Like os_elf_add_func_entry, but tied to ARCH_HAVE_ADD_FUNC_ENTRY in 36497d13666cd84589135ba593fa43a800d098026d0Petr Machata * arch.h. The arch callback is called first. If it returns 36597d13666cd84589135ba593fa43a800d098026d0Petr Machata * PLT_DEFAULT, the os callback is called next. */ 36697d13666cd84589135ba593fa43a800d098026d0Petr Machataenum plt_status arch_elf_add_func_entry(struct process *proc, struct ltelf *lte, 36797d13666cd84589135ba593fa43a800d098026d0Petr Machata const GElf_Sym *sym, 36897d13666cd84589135ba593fa43a800d098026d0Petr Machata arch_addr_t addr, const char *name, 36997d13666cd84589135ba593fa43a800d098026d0Petr Machata struct library_symbol **ret); 37097d13666cd84589135ba593fa43a800d098026d0Petr Machata 371311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* This callback needs to be implemented if arch.h defines 372311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ARCH_HAVE_DYNLINK_DONE. It is called after the dynamic linker is 3739af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * done with the process start-up. */ 374929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_dynlink_done(struct process *proc); 375642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata 3763a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias/* This callback needs to be implemented if arch.h defines 3773a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias * ARCH_HAVE_SYMBOL_RET. It is called after a traced call returns. */ 378929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid arch_symbol_ret(struct process *proc, struct library_symbol *libsym); 3793a1806db0ecaa4364e51b4822d66d05f4acd87a9Edgar E. Iglesias 38011c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias 38111c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias/* This callback needs to be implemented if arch.h defines 38211c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * ARCH_HAVE_FIND_DL_DEBUG. 38311c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * It is called by generic code to find the address of the dynamic 38411c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * linkers debug structure. 38511c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * DYN_ADDR holds the address of the dynamic section. 38611c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * If the debug area is found, return 0 and fill in the address in *RET. 38711c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias * If the debug area is not found, return a negative value. */ 388929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint arch_find_dl_debug(struct process *proc, arch_addr_t dyn_addr, 38911c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias arch_addr_t *ret); 39011c3c3e28461886bb16c69c745b1fefa946c4d9fEdgar E. Iglesias 3919af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata/* This is called to obtain a list of directories to search when 3929af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * loading config files. The callback sets *RETP to a pointer to the 3939af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * first element of a NULL-terminated array of directory names. It's 3949af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * legitimate to set *RETP to NULL to indicate there are no 3959af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * directories. The function returns 0 on success or a negative value 3969af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * on a failure. 3979af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * 3989af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * If PRIVATE is set, the list in *RETP should contain only user's own 3999af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * directories (presumably under HOME if there's any such thing on the 4009af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * given OS). Otherwise only system directories should be reported. 4019af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * 4029af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * The directories don't have to exist. Directories passed in -F are 4039af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * handled separately by the caller and this callback shouldn't 4049af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata * concern itself with it. */ 4059af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machataint os_get_config_dirs(int private, const char ***retp); 4069af3f3ab7a8c44d94f944f15ece10109e6492930Petr Machata 407aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata/* This is called to obtain list of legacy config files to import, if 408aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * any. A reference to initialized vector of char* is passed in. 409aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * 410aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * This returns 0 on success, in which case strings from *RETP (if 411aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * any) are interpreted as files names. These files belong to the 412aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * caller and will eventually be freed. 413aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * 414aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * Returns a negative value for failure, in which case *RETP contents 415aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machata * are not consulted in any way. */ 416aa3db6b1234da0e542ba7782849cf200d0d91c1cPetr Machataint os_get_ltrace_conf_filenames(struct vect *retp); 417364753a1cfe46998946a42badd9099591a00325aPetr Machata 418311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* If arch.h defines ARCH_HAVE_FETCH_ARG, the following callbacks have 419311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * to be implemented: arch_fetch_arg_init, arch_fetch_arg_clone, 420311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_fetch_arg_done, arch_fetch_arg_next and arch_fetch_retval. 421311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * See fetch.h for details. */ 422311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 423311358a1cac22781ecffe697a808bd43eac73bcePetr Machata/* If arch.h defines both ARCH_HAVE_FETCH_ARG and 424311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * ARCH_HAVE_FETCH_PACK, the following callbacks have to be 425311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * implemented: arch_fetch_param_pack_start, 426311358a1cac22781ecffe697a808bd43eac73bcePetr Machata * arch_fetch_param_pack_end. See fetch.h for details. */ 427311358a1cac22781ecffe697a808bd43eac73bcePetr Machata 428693dfad9c1b121cf079a3082866daa2225df1797Petr Machataenum sw_singlestep_status { 429693dfad9c1b121cf079a3082866daa2225df1797Petr Machata SWS_FAIL, 430693dfad9c1b121cf079a3082866daa2225df1797Petr Machata SWS_OK, 431693dfad9c1b121cf079a3082866daa2225df1797Petr Machata SWS_HW, 432693dfad9c1b121cf079a3082866daa2225df1797Petr Machata}; 433693dfad9c1b121cf079a3082866daa2225df1797Petr Machatastruct sw_singlestep_data; 434693dfad9c1b121cf079a3082866daa2225df1797Petr Machata 435693dfad9c1b121cf079a3082866daa2225df1797Petr Machata/* The following callback has to be implemented in backend if arch.h 436693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * defines ARCH_HAVE_SW_SINGLESTEP. 437693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * 438693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * This is called before the OS backend requests hardware singlestep. 439693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * arch_sw_singlestep should consider whether a singlestep needs to be 440693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * done in software. If not, it returns SWS_HW. Otherwise it needs 441693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * to add one or several breakpoints by calling ADD_CB. When it is 442693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * done, it continues the process as appropriate, and answers either 443693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * SWS_OK, or SWS_FAIL, depending on how it went. 444693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * 445693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * PROC is the process that should perform the singlestep, BP the 446693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * breakpoint that we are singlestepping over. ADD_CB is a callback 447693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * to request adding breakpoints that should trap the process after 448693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * it's continued. The arguments to ADD_CB are the address where the 449693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * breakpoint should be added, and DATA. ADD_CB returns 0 on success 450693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * or a negative value on failure. It is expected that 451693dfad9c1b121cf079a3082866daa2225df1797Petr Machata * arch_sw_singlestep returns SWS_FAIL if ADD_CB returns error. */ 452693dfad9c1b121cf079a3082866daa2225df1797Petr Machataenum sw_singlestep_status arch_sw_singlestep(struct process *proc, 453693dfad9c1b121cf079a3082866daa2225df1797Petr Machata struct breakpoint *bp, 454693dfad9c1b121cf079a3082866daa2225df1797Petr Machata int (*add_cb)(arch_addr_t addr, 455693dfad9c1b121cf079a3082866daa2225df1797Petr Machata struct sw_singlestep_data *), 456693dfad9c1b121cf079a3082866daa2225df1797Petr Machata struct sw_singlestep_data *data); 457693dfad9c1b121cf079a3082866daa2225df1797Petr Machata 458642626096a694c6af279d25d2b1b2fba5b10ddfbPetr Machata#endif /* BACKEND_H */ 459