1 # This file is part of ltrace.
2 # Copyright (C) 2012 Petr Machata, Red Hat Inc.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 set trivial [ltraceCompile {} [ltraceSource c {
23 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
26 typedef bbb = struct(aa);
27 }] -- $trivial] "error" == 0
29 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
32 }] -- $trivial] "error" != 0
34 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
37 }] -- $trivial] "error" != 0
39 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
41 typedef aa = struct(int);
42 typedef aa = struct(int);
43 }] -- $trivial] "error" != 0
45 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
47 typedef aa = struct();
48 typedef aa = struct();
49 }] -- $trivial] "error" != 0
51 ltraceMatch1 [ltraceRun -L -F [ltraceSource conf {
52 typedef aa = struct(int, struct;);
53 }] -- $trivial] "error" != 0
55 set libll [ltraceCompile libll.so [ltraceSource c {
57 void ll(struct xxx *xxx) {}
60 set conf [ltraceSource conf {
62 typedef xxx = struct(int, xxx*);
66 ltraceMatch [ltraceRun -F $conf -e ll [ltraceCompile {} $libll [ltraceSource c {
72 void ll (struct xxx *xxx);
73 int main (int argc, char *argv[])
75 struct xxx a = { 1, 0 };
76 struct xxx b = { 2, &a };
77 struct xxx c = { 3, &b };
78 struct xxx d = { 4, &c };
81 struct xxx e = { 1, 0 };
82 struct xxx f = { 2, &e };
86 struct xxx g = { 1, &g };
92 {{->ll\({ 4, { 3, { 2, { 1, nil } } } }\) *= <void>} == 1}
93 {{->ll\({ 2, { 1, recurse\^ } }\) *= <void>} == 1}
94 {{->ll\({ 1, recurse }\) *= <void>} == 1}
97 ltraceMatch1 [ltraceRun -F $conf -e ll -A 5 \
98 -- [ltraceCompile ll $libll [ltraceSource c {
105 void ll (struct ble *ble);
106 int main (int argc, char *argv[])
108 struct ble *b = NULL;
110 for (i = 0; i < 10; ++i) {
111 struct ble *n = malloc(sizeof(*n));
120 }]]] {->ll\({ 9, { 8, { 7, { 6, { 5, \.\.\. } } } } }\) *= <void>} == 1
122 proc ltraceParamTest {conf cdecl libcode maincode match {params ""}} {
123 set conffile [ltraceSource conf $conf]
124 set lib [ltraceCompile liblib.so [ltraceSource c [concat $cdecl $libcode]]]
125 set bin [ltraceCompile {} $lib \
127 [concat $cdecl "int main(void) {" $maincode "}"]]]
129 set command [concat "ltraceRun -F $conffile " $params "-- $bin"]
130 return [ltraceMatch [eval $command] $match]
133 # Test using lens in typedef.
136 typedef hexptr = hex(uint*);
139 void fun(unsigned *arg);
141 void fun(unsigned *arg) {}
146 {{fun\(0x123\) *= <void>} == 1}
149 # Test support for bitvec lens.
152 void fun(bitvec(uint));
153 void fun2(bitvec(array(char, 32)*));
155 void fun(unsigned i);
156 void fun2(unsigned char *arr);
158 void fun(unsigned i) {}
159 void fun2(unsigned char *arr) {}
166 unsigned char bytes[32] = {0x00};
171 {{fun\(<>\) *= <void>} == 1}
172 {{fun\(<0-1,5,8>\) *= <void>} == 1}
173 {{fun\(~<0>\) *= <void>} == 1}
174 {{fun\(~<>\) *= <void>} == 1}
175 {{fun2\(<8-15,255>\) *= <void>} == 1}
178 # Test support for hex(float), hex(double).
181 hex(float) hex_float(hex(float));
182 hex(double) hex_double(hex(double));
184 float hex_float(float f);
185 double hex_double(double d);
187 float hex_float(float f) { return f + 1; }
188 double hex_double(double d) { return d + 1; }
193 {{hex_float\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
194 {{hex_double\(0x1.8p\+0\) *= 0x1.4p\+1} == 1}
197 # Test that -x fun can find "fun" prototype even if "fun" is in a
206 void libfun(void) { fun(); }