2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
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.
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.
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
26 /* The structure param holds information about a parameter of a
27 * function. It's used to configure a function prototype. There are
28 * two flavors of parameters:
33 * Parameter packs are used to describe various vararg constructs.
34 * They themselves are parametrized by ltrace expressions. Those will
35 * typically be references to other arguments, but constants might
36 * also make sense, and it principle, anything can be used. */
42 /* This is for emitting arguments in two bunches. This is
43 * where we should stop emitting "left" bunch. All that's
44 * after this parameter should be emitted in the "right"
49 enum param_pack_flavor {
50 /* This parameter pack expands to a list of ordinary
51 * arguments. For example if the last argument is sometimes
52 * ignored, that would be described by a PARAM_PACK_ARGS
53 * parameter pack. ioctl or ptrace are two examples that
54 * would benefit from this. */
57 /* This parameter pack represents a vararg argument. */
62 PPCB_ERR = -1, /* An error occurred. */
63 PPCB_STOP, /* Stop fetching the arguments. */
64 PPCB_CONT, /* Display this argument and keep going. */
67 /* Each parameter enumerator defines its own context object.
68 * Definitions of these are in respective .c files of each
73 enum param_flavor flavor;
76 struct arg_type_info *type;
80 struct expr_node *args;
83 enum param_pack_flavor ppflavor;
85 struct param_enum *(*init)(struct value *cb_args,
87 struct value_dict *arguments);
88 int (*next)(struct param_enum *self,
89 struct arg_type_info *info,
91 enum param_status (*stop)(struct param_enum *self,
93 void (*done)(struct param_enum *self);
98 /* Initialize simple type parameter. TYPE is owned and released by
99 * PARAM if OWN_TYPE. */
100 void param_init_type(struct param *param,
101 struct arg_type_info *type, int own_type);
103 /* Initialize a stop. */
104 void param_init_stop(struct param *param);
106 /* Initialize parameter pack PARAM. ARGS is an array of expressions
107 * with parameters. ARGS is owned and released by the pack if
108 * OWN_ARGS. NARGS is number of ARGS.
110 * When the parameter pack should be expanded, those expressions are
111 * evaluated and passed to the INIT callback. This has to return a
112 * non-NULL context object.
114 * The NEXT callback is then called repeatedly, and should initialize
115 * its INFOP argument to a type of the next parameter in the pack.
116 * When there are no more parameters in the pack, the NEXT callback
117 * will set INFOP to a VOID parameter. If the callback sets
118 * INSERT_STOP to a non-zero value, a stop parameter shall be inserted
119 * before this actual parameter.
121 * Core then uses the passed-in type to fetch the next argument, which
122 * is in turn passed to STOP callback. This callback then tells
123 * ltrace core what to do next: whether there are more arguments, and
124 * if not, whether this argument should be displayed.
126 * After the enumeration is ended, DONE callback is called. */
127 void param_init_pack(struct param *param, enum param_pack_flavor ppflavor,
128 struct expr_node *args, size_t nargs, int own_args,
129 struct param_enum *(*init)(struct value *cb_args,
131 struct value_dict *arguments),
132 int (*next)(struct param_enum *self,
133 struct arg_type_info *infop,
135 enum param_status (*stop)(struct param_enum *self,
136 struct value *value),
137 void (*done)(struct param_enum *self));
139 /* Start enumerating types in parameter pack. This evaluates the
140 * parameter the pack arguments and calls the init callback. See the
141 * documentation of param_init_pack for details. */
142 struct param_enum *param_pack_init(struct param *param,
143 struct value_dict *fargs);
145 /* Ask for next type in enumeration. See the documentation of
146 * param_init_pack for details. */
147 int param_pack_next(struct param *param, struct param_enum *self,
148 struct arg_type_info *infop, int *insert_stop);
150 /* Ask whether we should stop enumerating. See the documentation of
151 * param_init_pack for details. */
152 enum param_status param_pack_stop(struct param *param,
153 struct param_enum *self, struct value *value);
155 /* Finish enumerating types in parameter pack. See the documentation
156 * of param_init_pack for details. */
157 void param_pack_done(struct param *param, struct param_enum *self);
159 /* Destroy data held by PARAM, but not the PARAM pointer itself. */
160 void param_destroy(struct param *param);