2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc.
4 * Copyright (C) 1997-2009 Juan Cespedes
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
40 ARGTYPE_ARRAY, /* Series of values in memory */
41 ARGTYPE_STRUCT, /* Structure of values */
42 ARGTYPE_POINTER, /* Pointer to some other type */
45 struct arg_type_info {
52 struct arg_type_info *elt_type;
53 struct expr_node *length;
60 struct arg_type_info *info;
69 /* Return a type info for simple type TYPE (which shall not be array,
70 * struct, or pointer. Each call with the same TYPE yields the same
71 * arg_type_info pointer. */
72 struct arg_type_info *type_get_simple(enum arg_type type);
73 struct arg_type_info *type_get_voidptr(void);
75 /* Initialize INFO so it becomes ARGTYPE_STRUCT. The created
76 * structure contains no fields. Use type_struct_add to populate the
78 void type_init_struct(struct arg_type_info *info);
80 /* Add a new field of type FIELD_INFO to a structure INFO. If OWN,
81 * the field type is owned and destroyed together with INFO. */
82 int type_struct_add(struct arg_type_info *info,
83 struct arg_type_info *field_info, int own);
85 /* Get IDX-th field of structure type INFO. */
86 struct arg_type_info *type_struct_get(struct arg_type_info *info, size_t idx);
88 /* Return number of fields of structure type INFO. */
89 size_t type_struct_size(struct arg_type_info *info);
91 /* Return number of elements of an aggregate type INFO. This can be
92 * either ARGTYPE_STRUCT or ARGTYPE_ARRAY of constant length. If
93 * ARGTYPE_ARRAY does not have a constant length, this returns -1. */
94 size_t type_aggregate_size(struct arg_type_info *info);
96 /* Initialize INFO so it becomes ARGTYPE_ARRAY. The element type is
97 * passed in ELEMENT_INFO, and array length in LENGTH_EXPR. If,
98 * respectively, OWN_INFO and OWN_LENGTH are true, the pointee and
99 * length are owned and destroyed together with INFO. */
100 void type_init_array(struct arg_type_info *info,
101 struct arg_type_info *element_info, int own_info,
102 struct expr_node *length_expr, int own_length);
104 /* Initialize INFO so it becomes ARGTYPE_POINTER. The pointee type is
105 * passed in POINTEE_INFO. If OWN_INFO, the pointee type is owned and
106 * destroyed together with INFO. */
107 void type_init_pointer(struct arg_type_info *info,
108 struct arg_type_info *pointee_info, int own_info);
110 /* Release any memory associated with INFO. Doesn't free INFO
112 void type_destroy(struct arg_type_info *info);
114 /* Copy type INFO into the area pointed to by RETP. Return 0 on
115 * success or a negative value on failure. */
116 int type_clone(struct arg_type_info *retp, const struct arg_type_info *info);
118 /* Compute a size of given type. Return (size_t)-1 for error. */
119 size_t type_sizeof(struct process *proc, struct arg_type_info *type);
121 /* Compute an alignment necessary for elements of this type. Return
122 * (size_t)-1 for error. */
123 size_t type_alignof(struct process *proc, struct arg_type_info *type);
125 /* Align value SZ to ALIGNMENT and return the result. */
126 size_t align(size_t sz, size_t alignment);
128 /* Return ELT-th element of compound type TYPE. This is useful for
129 * arrays and structures. */
130 struct arg_type_info *type_element(struct arg_type_info *type, size_t elt);
132 /* Compute an offset of EMT-th element of type TYPE. This works for
133 * arrays and structures. Return (size_t)-1 for error. */
134 size_t type_offsetof(struct process *proc,
135 struct arg_type_info *type, size_t elt);
137 /* Whether TYPE is an integral type as defined by the C standard. */
138 int type_is_integral(enum arg_type type);
140 /* Whether TYPE, which shall be integral, is a signed type. */
141 int type_is_signed(enum arg_type type);
143 /* If INFO is floating point equivalent type, return the corresponding
144 * floating point type. Otherwise return NULL. Floating point
145 * equivalent types are either ARGTYPE_FLOAT, or ARGTYPE_DOUBLE, or
146 * ARGTYPE_STRUCT whose sole member is a floating point equivalent
148 struct arg_type_info *type_get_fp_equivalent(struct arg_type_info *info);
150 /* If INFO is homogeneous floating-point aggregate, return the
151 * corresponding floating point type, and set *COUNTP to number of
152 * fields of the structure. Otherwise return NULL. INFO is a HFA if
153 * it's an aggregate whose each field is either a HFA, or a
154 * floating-point type. */
155 struct arg_type_info *type_get_hfa_type(struct arg_type_info *info,