parameters2.exp revision e8701b4cc4333dbc5e3c683468fa8fb077977ba6
1# This file is part of ltrace. 2# Copyright (C) 2012 Petr Machata, Red Hat Inc. 3# 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. 8# 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. 13# 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 17# 02110-1301 USA 18 19set trivial [ltraceCompile {} [ltraceSource c { 20 int main(void) {} 21}]] 22 23ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 24 typedef aa = int; 25 typedef aaa = int; 26 typedef bbb = struct(aa); 27}] -- $trivial] "error" == 0 28 29ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 30 typedef aa = int; 31 typedef aa = int; 32}] -- $trivial] "error" != 0 33 34ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 35 typedef aa = struct; 36 typedef aa = int; 37}] -- $trivial] "error" != 0 38 39ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 40 typedef aa = struct; 41 typedef aa = struct(int); 42 typedef aa = struct(int); 43}] -- $trivial] "error" != 0 44 45ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 46 typedef aa = struct; 47 typedef aa = struct(); 48 typedef aa = struct(); 49}] -- $trivial] "error" != 0 50 51ltraceMatch1 [ltraceRun -L -F [ltraceSource conf { 52 typedef aa = struct(int, struct;); 53}] -- $trivial] "error" != 0 54 55set libll [ltraceCompile libll.so [ltraceSource c { 56 struct xxx; 57 void ll(struct xxx *xxx) {} 58}]] 59 60set conf [ltraceSource conf { 61 typedef xxx = struct; 62 typedef xxx = struct(int, xxx*); 63 void ll(xxx*); 64}] 65 66ltraceMatch [ltraceRun -F $conf -e ll [ltraceCompile {} $libll [ltraceSource c { 67 struct xxx { 68 int i; 69 struct xxx *next; 70 }; 71 72 void ll (struct xxx *xxx); 73 int main (int argc, char *argv[]) 74 { 75 struct xxx a = { 1, 0 }; 76 struct xxx b = { 2, &a }; 77 struct xxx c = { 3, &b }; 78 struct xxx d = { 4, &c }; 79 ll (&d); 80 81 struct xxx e = { 1, 0 }; 82 struct xxx f = { 2, &e }; 83 e.next = &f; 84 ll (&f); 85 86 struct xxx g = { 1, &g }; 87 ll (&g); 88 89 return 0; 90 } 91}]]] { 92 {{->ll\({ 4, { 3, { 2, { 1, nil } } } }\) *= <void>} == 1} 93 {{->ll\({ 2, { 1, recurse\^ } }\) *= <void>} == 1} 94 {{->ll\({ 1, recurse }\) *= <void>} == 1} 95} 96 97ltraceMatch1 [ltraceRun -F $conf -e ll -A 5 \ 98-- [ltraceCompile ll $libll [ltraceSource c { 99 #include <stdlib.h> 100 struct ble { 101 int i; 102 struct ble *next; 103 }; 104 105 void ll (struct ble *ble); 106 int main (int argc, char *argv[]) 107 { 108 struct ble *b = NULL; 109 int i; 110 for (i = 0; i < 10; ++i) { 111 struct ble *n = malloc(sizeof(*n)); 112 n->i = i; 113 n->next = b; 114 b = n; 115 } 116 ll (b); 117 118 return 0; 119 } 120}]]] {->ll\({ 9, { 8, { 7, { 6, { 5, \.\.\. } } } } }\) *= <void>} == 1 121 122# Test using lens in typedef. 123 124ltraceMatch1 [ltraceLibTest { 125 typedef hexptr = hex(uint*); 126 void fun(hexptr); 127} { 128 void fun(unsigned *arg); 129} { 130 void fun(unsigned *arg) {} 131} { 132 unsigned u = 0x123; 133 fun(&u); 134}] {fun\(0x123\) *= <void>} == 1 135 136# Test support for bitvec lens. 137 138ltraceMatch [ltraceLibTest { 139 void fun(bitvec(uint)); 140 void fun2(bitvec(array(char, 32)*)); 141} { 142 void fun(unsigned i); 143 void fun2(unsigned char *arr); 144} { 145 void fun(unsigned i) {} 146 void fun2(unsigned char *arr) {} 147} { 148 fun(0); 149 fun(0x123); 150 fun(0xfffffffe); 151 fun(0xffffffff); 152 153 unsigned char bytes[32] = {0x00}; 154 bytes[1] = 0xff; 155 bytes[31] = 0x80; 156 fun2(bytes); 157}] { 158 {{fun\(<>\) *= <void>} == 1} 159 {{fun\(<0-1,5,8>\) *= <void>} == 1} 160 {{fun\(~<0>\) *= <void>} == 1} 161 {{fun\(~<>\) *= <void>} == 1} 162 {{fun2\(<8-15,255>\) *= <void>} == 1} 163} 164 165# Test support for hex(float), hex(double). 166 167ltraceMatch [ltraceLibTest { 168 hex(float) hex_float(hex(float)); 169 hex(double) hex_double(hex(double)); 170} { 171 float hex_float(float f); 172 double hex_double(double d); 173} { 174 float hex_float(float f) { return f + 1; } 175 double hex_double(double d) { return d + 1; } 176} { 177 hex_float(1.5); 178 hex_double(1.5); 179}] { 180 {{hex_float\(0x1.8p\+0\) *= 0x1.4p\+1} == 1} 181 {{hex_double\(0x1.8p\+0\) *= 0x1.4p\+1} == 1} 182} 183 184# Test that "addr" is recognized. 185 186ltraceMatch1 [ltraceLibTest { 187 void fun(addr); 188} { 189 #include <stdint.h> 190 void fun(uintptr_t u); 191} { 192 void fun(uintptr_t u) {} 193} { 194 fun(0x1234); 195}] {fun\(0x1234\) *= <void>} == 1 196 197# Test that -x fun can find "fun" prototype even if "fun" is in a 198# library. 199 200ltraceMatch1 [ltraceLibTest { 201 void fun(); 202} { 203 void libfun(void); 204} { 205 void fun(void) {} 206 void libfun(void) { fun(); } 207} { 208 libfun(); 209} { 210 -L -x fun 211}] {fun@.*\(\)} == 1 212 213ltraceDone 214