aboutsummaryrefslogtreecommitdiff
path: root/testsuite/ltrace.main/parameters2.exp
blob: c200e369c01b1939d961f1b05eb5ef6682da90c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# This file is part of ltrace.
# Copyright (C) 2012 Petr Machata, Red Hat Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA

set trivial [ltraceCompile {} [ltraceSource c {
    int main(void) {}
}]]

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = int;
    typedef aaa = int;
    typedef bbb = struct(aa);
}] -- $trivial] "error" == 0

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = int;
    typedef aa = int;
}] -- $trivial] "error" != 0

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = struct;
    typedef aa = int;
}] -- $trivial] "error" != 0

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = struct;
    typedef aa = struct(int);
    typedef aa = struct(int);
}] -- $trivial] "error" != 0

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = struct;
    typedef aa = struct();
    typedef aa = struct();
}] -- $trivial] "error" != 0

ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
    typedef aa = struct(int, struct;);
}] -- $trivial] "error" != 0

set libll [ltraceCompile libll.so [ltraceSource c {
    struct xxx;
    void ll(struct xxx *xxx) {}
}]]

set conf [ltraceSource conf {
    typedef xxx = struct;
    typedef xxx = struct(int, xxx*);
    void ll(xxx*);
}]

ltraceMatch [ltraceRun -F $conf -e ll [ltraceCompile {} $libll [ltraceSource c {
    struct xxx {
	int i;
	struct xxx *next;
    };

    void ll (struct xxx *xxx);
    int main (int argc, char *argv[])
    {
	struct xxx a = { 1, 0 };
	struct xxx b = { 2, &a };
	struct xxx c = { 3, &b };
	struct xxx d = { 4, &c };
	ll (&d);

	struct xxx e = { 1, 0 };
	struct xxx f = { 2, &e };
	e.next = &f;
	ll (&f);

	struct xxx g = { 1, &g };
	ll (&g);

	return 0;
    }
}]]] {
    {{->ll\({ 4, { 3, { 2, { 1, nil } } } }\) *= <void>} == 1}
    {{->ll\({ 2, { 1, recurse\^ } }\) *= <void>} == 1}
    {{->ll\({ 1, recurse }\) *= <void>} == 1}
}

ltraceMatch1 [ltraceRun -F $conf -e ll -A 5 \
-- [ltraceCompile ll $libll [ltraceSource c {
    #include <stdlib.h>
    struct ble {
	int i;
	struct ble *next;
    };

    void ll (struct ble *ble);
    int main (int argc, char *argv[])
    {
	struct ble *b = NULL;
	int i;
	for (i = 0; i < 10; ++i) {
	    struct ble *n = malloc(sizeof(*n));
	    n->i = i;
	    n->next = b;
	    b = n;
	}
	ll (b);

	return 0;
    }
}]]] {->ll\({ 9, { 8, { 7, { 6, { 5, \.\.\. } } } } }\) *= <void>} == 1

# Test using lens in typedef.

ltraceMatch1 [ltraceLibTest {
    typedef hexptr = hex(uint*);
    void fun(hexptr);
} {
    void fun(unsigned *arg);
} {
    void fun(unsigned *arg) {}
} {
    unsigned u = 0x123;
    fun(&u);
}] {fun\(0x123\) *= <void>} == 1

# Test support for bitvec lens.

ltraceMatch [ltraceLibTest {
    void fun(bitvec(uint));
    void fun2(bitvec(array(char, 32)*));
} {
    void fun(unsigned i);
    void fun2(unsigned char *arr);
} {
    void fun(unsigned i) {}
    void fun2(unsigned char *arr) {}
} {
    fun(0);
    fun(0x123);
    fun(0xfffffffe);
    fun(0xffffffff);

    unsigned char bytes[32] = {0x00};
    bytes[1] = 0xff;
    bytes[31] = 0x80;
    fun2(bytes);
}] {
    {{fun\(<>\) *= <void>} == 1}
    {{fun\(<0-1,5,8>\) *= <void>} == 1}
    {{fun\(~<0>\) *= <void>} == 1}
    {{fun\(~<>\) *= <void>} == 1}
    {{fun2\(<8-15,255>\) *= <void>} == 1}
}

# Test support for hex(float), hex(double).

ltraceMatch [ltraceLibTest {
    hex(float) hex_float(hex(float));
    hex(double) hex_double(hex(double));
} {
    float hex_float(float f);
    double hex_double(double d);
} {
    float hex_float(float f) { return f + 1; }
    double hex_double(double d) { return d + 1; }
} {
    hex_float(1.5);
    hex_double(1.5);
}] {
    {{hex_float\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
    {{hex_double\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
}

# Test that "addr" is recognized.

ltraceMatch1 [ltraceLibTest {
    void fun(addr);
} {
    #include <stdint.h>
    void fun(uintptr_t u);
} {
    void fun(uintptr_t u) {}
} {
    fun(0x1234);
}] {fun\(0x1234\) *= <void>} == 1

# Test that -x fun can find "fun" prototype even if "fun" is in a
# library.

ltraceMatch1 [ltraceLibTest {
    void fun();
} {
    void libfun(void);
} {
    void fun(void) {}
    void libfun(void) { fun(); }
} {
    libfun();
} {
    -L -x fun
}] {fun@.*\(\)} == 1

ltraceDone