1 /* 2 * This file is part of ltrace. 3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 * 02110-1301 USA 19 */ 20 21 #ifndef FETCH_H 22 #define FETCH_H 23 24 #include "forward.h" 25 #include "param.h" 26 27 /* XXX isn't SYSCALL TOF just a different ABI? Maybe we needed to 28 * support variant ABIs all along. */ 29 enum tof { 30 LT_TOF_FUNCTION, /* A real library function */ 31 LT_TOF_FUNCTIONR, /* Return from a real library function */ 32 LT_TOF_SYSCALL, /* A syscall */ 33 LT_TOF_SYSCALLR, /* Return from a syscall */ 34 }; 35 36 /* The contents of the structure is defined by the back end. */ 37 struct fetch_context; 38 39 /* Initialize argument fetching. Returns NULL on failure. RET_INFO 40 * is the return type of the function. */ 41 struct fetch_context *fetch_arg_init(enum tof type, struct process *proc, 42 struct arg_type_info *ret_info); 43 44 /* Make a clone of context. */ 45 struct fetch_context *fetch_arg_clone(struct process *proc, 46 struct fetch_context *context); 47 48 /* Load next argument. The function returns 0 on success or a 49 * negative value on failure. The extracted value is stored in 50 * *VALUEP. */ 51 int fetch_arg_next(struct fetch_context *context, enum tof type, 52 struct process *proc, 53 struct arg_type_info *info, struct value *valuep); 54 55 /* Load return value. The function returns 0 on success or a negative 56 * value on failure. The extracted value is stored in *VALUEP. */ 57 int fetch_retval(struct fetch_context *context, enum tof type, 58 struct process *proc, 59 struct arg_type_info *info, struct value *valuep); 60 61 /* Destroy fetch context. CONTEXT shall be the same memory location 62 * that was passed to fetch_arg_next. */ 63 void fetch_arg_done(struct fetch_context *context); 64 65 /* Called before fetching arguments that come from parameter packs. 66 * Returns 0 on success or a negative value on failure. */ 67 int fetch_param_pack_start(struct fetch_context *context, 68 enum param_pack_flavor ppflavor); 69 70 /* Called after a parameter pack has been fetched. */ 71 void fetch_param_pack_end(struct fetch_context *context); 72 73 74 /* The following callbacks have to be implemented in backend if arch.h 76 * defines ARCH_HAVE_FETCH_ARG. These backend callbacks correspond to 77 * above functions. */ 78 struct fetch_context *arch_fetch_arg_init(enum tof type, struct process *proc, 79 struct arg_type_info *ret_info); 80 struct fetch_context *arch_fetch_arg_clone(struct process *proc, 81 struct fetch_context *context); 82 int arch_fetch_arg_next(struct fetch_context *ctx, enum tof type, 83 struct process *proc, struct arg_type_info *info, 84 struct value *valuep); 85 int arch_fetch_retval(struct fetch_context *ctx, enum tof type, 86 struct process *proc, struct arg_type_info *info, 87 struct value *valuep); 88 void arch_fetch_arg_done(struct fetch_context *context); 89 90 /* The following callbacks have to be implemented in backend if arch.h 91 * defines ARCH_HAVE_FETCH_ARG and ARCH_HAVE_FETCH_PACK. */ 92 int arch_fetch_param_pack_start(struct fetch_context *context, 93 enum param_pack_flavor ppflavor); 94 void arch_fetch_param_pack_end(struct fetch_context *context); 95 96 #endif /* FETCH_H */ 97