2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012 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);
74 /* Initialize INFO so it becomes ARGTYPE_STRUCT. The created
75 * structure contains no fields. Use type_struct_add to populate the
77 void type_init_struct(struct arg_type_info *info);
79 /* Add a new field of type FIELD_INFO to a structure INFO. If OWN,
80 * the field type is owned and destroyed together with INFO. */
81 int type_struct_add(struct arg_type_info *info,
82 struct arg_type_info *field_info, int own);
84 /* Get IDX-th field of structure type INFO. */
85 struct arg_type_info *type_struct_get(struct arg_type_info *info, size_t idx);
87 /* Return number of fields of structure type INFO. */
88 size_t type_struct_size(struct arg_type_info *info);
90 /* Return number of elements of an aggregate type INFO. This can be
91 * either ARGTYPE_STRUCT or ARGTYPE_ARRAY of constant length. If
92 * ARGTYPE_ARRAY does not have a constant length, this returns -1. */
93 size_t type_aggregate_size(struct arg_type_info *info);
95 /* Initialize INFO so it becomes ARGTYPE_ARRAY. The element type is
96 * passed in ELEMENT_INFO, and array length in LENGTH_EXPR. If,
97 * respectively, OWN_INFO and OWN_LENGTH are true, the pointee and
98 * length are owned and destroyed together with INFO. */
99 void type_init_array(struct arg_type_info *info,
100 struct arg_type_info *element_info, int own_info,
101 struct expr_node *length_expr, int own_length);
103 /* Initialize INFO so it becomes ARGTYPE_POINTER. The pointee type is
104 * passed in POINTEE_INFO. If OWN_INFO, the pointee type is owned and
105 * destroyed together with INFO. */
106 void type_init_pointer(struct arg_type_info *info,
107 struct arg_type_info *pointee_info, int own_info);
109 /* Release any memory associated with INFO. Doesn't free INFO
111 void type_destroy(struct arg_type_info *info);
113 /* Compute a size of given type. Return (size_t)-1 for error. */
114 size_t type_sizeof(struct Process *proc, struct arg_type_info *type);
116 /* Compute an alignment necessary for elements of this type. Return
117 * (size_t)-1 for error. */
118 size_t type_alignof(struct Process *proc, struct arg_type_info *type);
120 /* Align value SZ to ALIGNMENT and return the result. */
121 size_t align(size_t sz, size_t alignment);
123 /* Return ELT-th element of compound type TYPE. This is useful for
124 * arrays and structures. */
125 struct arg_type_info *type_element(struct arg_type_info *type, size_t elt);
127 /* Compute an offset of EMT-th element of type TYPE. This works for
128 * arrays and structures. Return (size_t)-1 for error. */
129 size_t type_offsetof(struct Process *proc,
130 struct arg_type_info *type, size_t elt);
132 /* Whether TYPE is an integral type as defined by the C standard. */
133 int type_is_integral(enum arg_type type);
135 /* Whether TYPE, which shall be integral, is a signed type. */
136 int type_is_signed(enum arg_type type);
138 /* If INFO is floating point equivalent type, return the corresponding
139 * floating point type. Otherwise return NULL. Floating point
140 * equivalent types are either ARGTYPE_FLOAT, or ARGTYPE_DOUBLE, or
141 * ARGTYPE_STRUCT whose sole member is a floating point equivalent
143 struct arg_type_info *type_get_fp_equivalent(struct arg_type_info *info);