Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/check_debug.c
+++ new/usr/src/tools/smatch/src/check_debug.c
1 1 /*
2 2 * Copyright (C) 2009 Dan Carpenter.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 #include "smatch.h"
19 19 #include "smatch_slist.h"
20 20 #include "smatch_extra.h"
21 21
22 +void show_sname_alloc(void);
23 +void show_data_range_alloc(void);
24 +void show_ptrlist_alloc(void);
25 +void show_sm_state_alloc(void);
26 +
22 27 int local_debug;
23 28 static int my_id;
24 29 char *trace_variable;
25 30
26 31 static void match_all_values(const char *fn, struct expression *expr, void *info)
27 32 {
28 33 struct stree *stree;
29 34
30 35 stree = get_all_states_stree(SMATCH_EXTRA);
31 36 __print_stree(stree);
32 37 free_stree(&stree);
33 38 }
34 39
35 40 static void match_cur_stree(const char *fn, struct expression *expr, void *info)
36 41 {
37 42 __print_cur_stree();
38 43 }
39 44
40 45 static void match_state(const char *fn, struct expression *expr, void *info)
41 46 {
42 47 struct expression *check_arg, *state_arg;
43 48 struct sm_state *sm;
44 49 int found = 0;
45 50
46 51 check_arg = get_argument_from_call_expr(expr->args, 0);
47 52 if (check_arg->type != EXPR_STRING) {
48 53 sm_error("the check_name argument to %s is supposed to be a string literal", fn);
49 54 return;
50 55 }
51 56 state_arg = get_argument_from_call_expr(expr->args, 1);
52 57 if (!state_arg || state_arg->type != EXPR_STRING) {
53 58 sm_error("the state_name argument to %s is supposed to be a string literal", fn);
54 59 return;
55 60 }
56 61
57 62 FOR_EACH_SM(__get_cur_stree(), sm) {
58 63 if (strcmp(check_name(sm->owner), check_arg->string->data) != 0)
59 64 continue;
60 65 if (strcmp(sm->name, state_arg->string->data) != 0)
61 66 continue;
62 67 sm_msg("'%s' = '%s'", sm->name, sm->state->name);
63 68 found = 1;
64 69 } END_FOR_EACH_SM(sm);
65 70
66 71 if (!found)
67 72 sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data);
68 73 }
69 74
70 75 static void match_states(const char *fn, struct expression *expr, void *info)
71 76 {
72 77 struct expression *check_arg;
73 78 struct sm_state *sm;
74 79 int found = 0;
75 80
76 81 check_arg = get_argument_from_call_expr(expr->args, 0);
77 82 if (check_arg->type != EXPR_STRING) {
78 83 sm_error("the check_name argument to %s is supposed to be a string literal", fn);
79 84 return;
80 85 }
81 86
82 87 FOR_EACH_SM(__get_cur_stree(), sm) {
83 88 if (strcmp(check_name(sm->owner), check_arg->string->data) != 0)
84 89 continue;
85 90 sm_msg("%s", show_sm(sm));
86 91 found = 1;
87 92 } END_FOR_EACH_SM(sm);
88 93
89 94 if (found)
90 95 return;
91 96
92 97 if (!id_from_name(check_arg->string->data))
93 98 sm_msg("invalid check name '%s'", check_arg->string->data);
94 99 else
95 100 sm_msg("%s: no states", check_arg->string->data);
96 101 }
97 102
98 103 static void match_print_value(const char *fn, struct expression *expr, void *info)
99 104 {
100 105 struct stree *stree;
101 106 struct sm_state *tmp;
102 107 struct expression *arg_expr;
103 108
104 109 arg_expr = get_argument_from_call_expr(expr->args, 0);
105 110 if (arg_expr->type != EXPR_STRING) {
106 111 sm_error("the argument to %s is supposed to be a string literal", fn);
107 112 return;
108 113 }
109 114
110 115 stree = __get_cur_stree();
111 116 FOR_EACH_MY_SM(SMATCH_EXTRA, stree, tmp) {
112 117 if (!strcmp(tmp->name, arg_expr->string->data))
113 118 sm_msg("%s = %s", tmp->name, tmp->state->name);
114 119 } END_FOR_EACH_SM(tmp);
115 120 }
116 121
117 122 static void match_print_known(const char *fn, struct expression *expr, void *info)
118 123 {
119 124 struct expression *arg;
120 125 struct range_list *rl = NULL;
121 126 char *name;
122 127 int known = 0;
123 128 sval_t sval;
124 129
125 130 arg = get_argument_from_call_expr(expr->args, 0);
126 131 if (get_value(arg, &sval))
127 132 known = 1;
128 133
129 134 get_implied_rl(arg, &rl);
130 135
131 136 name = expr_to_str(arg);
132 137 sm_msg("known: '%s' = '%s'. implied = '%s'", name, known ? sval_to_str(sval) : "<unknown>", show_rl(rl));
133 138 free_string(name);
134 139 }
135 140
136 141 static void match_print_implied(const char *fn, struct expression *expr, void *info)
137 142 {
138 143 struct expression *arg;
139 144 struct range_list *rl = NULL;
140 145 char *name;
141 146
142 147 arg = get_argument_from_call_expr(expr->args, 0);
143 148 get_implied_rl(arg, &rl);
144 149
145 150 name = expr_to_str(arg);
146 151 sm_msg("implied: %s = '%s'", name, show_rl(rl));
147 152 free_string(name);
148 153 }
149 154
150 155 static void match_real_absolute(const char *fn, struct expression *expr, void *info)
151 156 {
152 157 struct expression *arg;
153 158 struct range_list *rl = NULL;
154 159 char *name;
155 160
156 161 arg = get_argument_from_call_expr(expr->args, 0);
157 162 get_real_absolute_rl(arg, &rl);
158 163
159 164 name = expr_to_str(arg);
160 165 sm_msg("real absolute: %s = '%s'", name, show_rl(rl));
161 166 free_string(name);
162 167 }
163 168
164 169 static void match_print_implied_min(const char *fn, struct expression *expr, void *info)
165 170 {
166 171 struct expression *arg;
167 172 sval_t sval;
168 173 char *name;
169 174
170 175 arg = get_argument_from_call_expr(expr->args, 0);
171 176 name = expr_to_str(arg);
172 177
173 178 if (get_implied_min(arg, &sval))
174 179 sm_msg("implied min: %s = %s", name, sval_to_str(sval));
175 180 else
176 181 sm_msg("implied min: %s = <unknown>", name);
177 182
178 183 free_string(name);
179 184 }
180 185
181 186 static void match_print_implied_max(const char *fn, struct expression *expr, void *info)
182 187 {
183 188 struct expression *arg;
184 189 sval_t sval;
185 190 char *name;
186 191
187 192 arg = get_argument_from_call_expr(expr->args, 0);
188 193 name = expr_to_str(arg);
189 194
190 195 if (get_implied_max(arg, &sval))
↓ open down ↓ |
159 lines elided |
↑ open up ↑ |
191 196 sm_msg("implied max: %s = %s", name, sval_to_str(sval));
192 197 else
193 198 sm_msg("implied max: %s = <unknown>", name);
194 199
195 200 free_string(name);
196 201 }
197 202
198 203 static void match_user_rl(const char *fn, struct expression *expr, void *info)
199 204 {
200 205 struct expression *arg;
201 - struct range_list *rl;
206 + struct range_list *rl = NULL;
202 207 char *name;
203 208
204 209 arg = get_argument_from_call_expr(expr->args, 0);
205 210 name = expr_to_str(arg);
206 211
207 212 get_user_rl(arg, &rl);
208 213 sm_msg("user rl: '%s' = '%s'", name, show_rl(rl));
209 214
210 215 free_string(name);
211 216 }
212 217
213 218 static void match_capped(const char *fn, struct expression *expr, void *info)
214 219 {
215 220 struct expression *arg;
216 221 char *name;
217 222
218 223 arg = get_argument_from_call_expr(expr->args, 0);
219 224 name = expr_to_str(arg);
220 225 sm_msg("'%s' = '%s'", name, is_capped(arg) ? "capped" : "not capped");
221 226 free_string(name);
222 227 }
223 228
224 229 static void match_print_hard_max(const char *fn, struct expression *expr, void *info)
225 230 {
226 231 struct expression *arg;
227 232 sval_t sval;
228 233 char *name;
229 234
230 235 arg = get_argument_from_call_expr(expr->args, 0);
231 236 name = expr_to_str(arg);
232 237
233 238 if (get_hard_max(arg, &sval))
234 239 sm_msg("hard max: %s = %s", name, sval_to_str(sval));
235 240 else
236 241 sm_msg("hard max: %s = <unknown>", name);
237 242
238 243 free_string(name);
239 244 }
240 245
241 246 static void match_print_fuzzy_max(const char *fn, struct expression *expr, void *info)
242 247 {
243 248 struct expression *arg;
244 249 sval_t sval;
245 250 char *name;
246 251
247 252 arg = get_argument_from_call_expr(expr->args, 0);
248 253 name = expr_to_str(arg);
249 254
250 255 if (get_fuzzy_max(arg, &sval))
251 256 sm_msg("fuzzy max: %s = %s", name, sval_to_str(sval));
252 257 else
253 258 sm_msg("fuzzy max: %s = <unknown>", name);
254 259
255 260 free_string(name);
256 261 }
257 262
258 263 static void match_print_absolute(const char *fn, struct expression *expr, void *info)
259 264 {
260 265 struct expression *arg;
261 266 struct range_list *rl;
262 267 char *name;
263 268
264 269 arg = get_argument_from_call_expr(expr->args, 0);
265 270 name = expr_to_str(arg);
266 271
267 272 get_absolute_rl(arg, &rl);
268 273 sm_msg("absolute: %s = %s", name, show_rl(rl));
269 274
270 275 free_string(name);
271 276 }
272 277
273 278 static void match_print_absolute_min(const char *fn, struct expression *expr, void *info)
274 279 {
275 280 struct expression *arg;
276 281 sval_t sval;
277 282 char *name;
278 283
279 284 arg = get_argument_from_call_expr(expr->args, 0);
280 285 name = expr_to_str(arg);
281 286
282 287 if (get_absolute_min(arg, &sval))
283 288 sm_msg("absolute min: %s = %s", name, sval_to_str(sval));
284 289 else
285 290 sm_msg("absolute min: %s = <unknown>", name);
286 291
287 292 free_string(name);
288 293 }
289 294
290 295 static void match_print_absolute_max(const char *fn, struct expression *expr, void *info)
291 296 {
292 297 struct expression *arg;
293 298 sval_t sval;
294 299 char *name;
295 300
296 301 arg = get_argument_from_call_expr(expr->args, 0);
297 302 get_absolute_max(arg, &sval);
298 303
299 304 name = expr_to_str(arg);
300 305 sm_msg("absolute max: %s = %s", name, sval_to_str(sval));
301 306 free_string(name);
302 307 }
303 308
304 309 static void match_sval_info(const char *fn, struct expression *expr, void *info)
305 310 {
306 311 struct expression *arg;
307 312 sval_t sval;
308 313 char *name;
309 314
310 315 arg = get_argument_from_call_expr(expr->args, 0);
311 316 name = expr_to_str(arg);
312 317
313 318 if (!get_implied_value(arg, &sval)) {
314 319 sm_msg("no sval for '%s'", name);
315 320 goto free;
316 321 }
317 322
318 323 sm_msg("implied: %s %c%d ->value = %llx", name, sval_unsigned(sval) ? 'u' : 's', sval_bits(sval), sval.value);
319 324 free:
320 325 free_string(name);
321 326 }
322 327
323 328 static void match_member_name(const char *fn, struct expression *expr, void *info)
324 329 {
325 330 struct expression *arg;
326 331 char *name, *member_name;
327 332
328 333 arg = get_argument_from_call_expr(expr->args, 0);
329 334 name = expr_to_str(arg);
330 335 member_name = get_member_name(arg);
331 336 sm_msg("member name: '%s => %s'", name, member_name);
332 337 free_string(member_name);
333 338 free_string(name);
334 339 }
335 340
336 341 static void print_possible(struct sm_state *sm)
337 342 {
338 343 struct sm_state *tmp;
339 344
340 345 sm_msg("Possible values for %s", sm->name);
341 346 FOR_EACH_PTR(sm->possible, tmp) {
342 347 printf("%s\n", tmp->state->name);
343 348 } END_FOR_EACH_PTR(tmp);
344 349 sm_msg("===");
345 350 }
346 351
347 352 static void match_possible(const char *fn, struct expression *expr, void *info)
348 353 {
349 354 struct stree *stree;
350 355 struct sm_state *tmp;
351 356 struct expression *arg_expr;
352 357
353 358 arg_expr = get_argument_from_call_expr(expr->args, 0);
354 359 if (arg_expr->type != EXPR_STRING) {
355 360 sm_error("the argument to %s is supposed to be a string literal", fn);
356 361 return;
357 362 }
358 363
359 364 stree = __get_cur_stree();
360 365 FOR_EACH_MY_SM(SMATCH_EXTRA, stree, tmp) {
361 366 if (!strcmp(tmp->name, arg_expr->string->data))
362 367 print_possible(tmp);
363 368 } END_FOR_EACH_SM(tmp);
364 369 }
365 370
366 371 static void match_strlen(const char *fn, struct expression *expr, void *info)
367 372 {
368 373 struct expression *arg;
369 374 struct range_list *rl;
370 375 char *name;
371 376
372 377 arg = get_argument_from_call_expr(expr->args, 0);
373 378 get_implied_strlen(arg, &rl);
374 379
375 380 name = expr_to_str(arg);
376 381 sm_msg("strlen: '%s' %s characters", name, show_rl(rl));
↓ open down ↓ |
165 lines elided |
↑ open up ↑ |
377 382 free_string(name);
378 383 }
379 384
380 385 static void match_buf_size(const char *fn, struct expression *expr, void *info)
381 386 {
382 387 struct expression *arg, *comp;
383 388 struct range_list *rl;
384 389 int elements, bytes;
385 390 char *name;
386 391 char buf[256] = "";
392 + int limit_type;
387 393 int n;
388 394 sval_t sval;
389 395
390 396 arg = get_argument_from_call_expr(expr->args, 0);
391 397
392 398 elements = get_array_size(arg);
393 399 bytes = get_array_size_bytes_max(arg);
394 400 rl = get_array_size_bytes_rl(arg);
395 - comp = get_size_variable(arg);
401 + comp = get_size_variable(arg, &limit_type);
396 402
397 403 name = expr_to_str(arg);
398 404 n = snprintf(buf, sizeof(buf), "buf size: '%s' %d elements, %d bytes", name, elements, bytes);
399 405 free_string(name);
400 406
401 407 if (!rl_to_sval(rl, &sval))
402 408 n += snprintf(buf + n, sizeof(buf) - n, " (rl = %s)", show_rl(rl));
403 409
404 410 if (comp) {
405 411 name = expr_to_str(comp);
406 - snprintf(buf + n, sizeof(buf) - n, "[size_var=%s]", name);
412 + snprintf(buf + n, sizeof(buf) - n, "[size_var=%s %s]", limit_type_str(limit_type), name);
407 413 free_string(name);
408 414 }
409 415 sm_msg("%s", buf);
410 416 }
411 417
412 418 static void match_note(const char *fn, struct expression *expr, void *info)
413 419 {
414 420 struct expression *arg_expr;
415 421
416 422 arg_expr = get_argument_from_call_expr(expr->args, 0);
417 423 if (arg_expr->type != EXPR_STRING) {
418 424 sm_error("the argument to %s is supposed to be a string literal", fn);
419 425 return;
420 426 }
421 427 sm_msg("%s", arg_expr->string->data);
422 428 }
423 429
424 430 static void print_related(struct sm_state *sm)
425 431 {
426 432 struct relation *rel;
427 433
428 434 if (!estate_related(sm->state))
429 435 return;
430 436
431 437 sm_prefix();
432 438 sm_printf("%s: ", sm->name);
433 439 FOR_EACH_PTR(estate_related(sm->state), rel) {
434 440 sm_printf("%s ", rel->name);
435 441 } END_FOR_EACH_PTR(rel);
436 442 sm_printf("\n");
437 443 }
438 444
439 445 static void match_dump_related(const char *fn, struct expression *expr, void *info)
440 446 {
441 447 struct stree *stree;
442 448 struct sm_state *tmp;
443 449
444 450 stree = __get_cur_stree();
445 451 FOR_EACH_MY_SM(SMATCH_EXTRA, stree, tmp) {
446 452 print_related(tmp);
447 453 } END_FOR_EACH_SM(tmp);
448 454 }
449 455
450 456 static void match_compare(const char *fn, struct expression *expr, void *info)
451 457 {
452 458 struct expression *one, *two;
453 459 char *one_name, *two_name;
454 460 int comparison;
455 461 char buf[16];
456 462
457 463 one = get_argument_from_call_expr(expr->args, 0);
458 464 two = get_argument_from_call_expr(expr->args, 1);
459 465
460 466 comparison = get_comparison(one, two);
461 467 if (!comparison)
462 468 snprintf(buf, sizeof(buf), "<none>");
463 469 else
464 470 snprintf(buf, sizeof(buf), "%s", show_special(comparison));
465 471
466 472 one_name = expr_to_str(one);
467 473 two_name = expr_to_str(two);
468 474
469 475 sm_msg("%s %s %s", one_name, buf, two_name);
470 476
471 477 free_string(one_name);
472 478 free_string(two_name);
473 479 }
474 480
475 481 static void match_debug_on(const char *fn, struct expression *expr, void *info)
476 482 {
477 483 option_debug = 1;
478 484 }
479 485
480 486 static void match_debug_check(const char *fn, struct expression *expr, void *info)
481 487 {
482 488 struct expression *arg;
483 489
484 490 arg = get_argument_from_call_expr(expr->args, 0);
485 491 if (!arg || arg->type != EXPR_STRING)
486 492 return;
487 493 option_debug_check = arg->string->data;
488 494 sm_msg("arg = '%s'", option_debug_check);
489 495 }
490 496
491 497 static void match_debug_off(const char *fn, struct expression *expr, void *info)
492 498 {
493 499 option_debug_check = (char *)"";
494 500 option_debug = 0;
495 501 }
496 502
↓ open down ↓ |
80 lines elided |
↑ open up ↑ |
497 503 static void match_local_debug_on(const char *fn, struct expression *expr, void *info)
498 504 {
499 505 local_debug = 1;
500 506 }
501 507
502 508 static void match_local_debug_off(const char *fn, struct expression *expr, void *info)
503 509 {
504 510 local_debug = 0;
505 511 }
506 512
507 -static void match_debug_implied_on(const char *fn, struct expression *expr, void *info)
508 -{
509 - option_debug_implied = 1;
510 -}
511 -
512 -static void match_debug_implied_off(const char *fn, struct expression *expr, void *info)
513 -{
514 - option_debug_implied = 0;
515 -}
516 -
517 513 static void match_about(const char *fn, struct expression *expr, void *info)
518 514 {
519 515 struct expression *arg;
520 516 struct sm_state *sm;
521 517 char *name;
522 518
523 519 sm_msg("---- about ----");
524 520 match_print_implied(fn, expr, NULL);
525 521 match_buf_size(fn, expr, NULL);
526 522 match_strlen(fn, expr, NULL);
527 523 match_real_absolute(fn, expr, NULL);
528 524
529 525 arg = get_argument_from_call_expr(expr->args, 0);
530 526 name = expr_to_str(arg);
531 527 if (!name) {
532 528 sm_msg("info: not a straight forward variable.");
533 529 return;
534 530 }
535 531
536 532 FOR_EACH_SM(__get_cur_stree(), sm) {
537 533 if (strcmp(sm->name, name) != 0)
538 534 continue;
539 535 sm_msg("%s", show_sm(sm));
540 536 } END_FOR_EACH_SM(sm);
541 537 }
542 538
543 539 static void match_intersection(const char *fn, struct expression *expr, void *info)
544 540 {
545 541 struct expression *one, *two;
546 542 struct range_list *one_rl, *two_rl;
547 543 struct range_list *res;
548 544
549 545 one = get_argument_from_call_expr(expr->args, 0);
550 546 two = get_argument_from_call_expr(expr->args, 1);
551 547
552 548 get_absolute_rl(one, &one_rl);
553 549 get_absolute_rl(two, &two_rl);
554 550
555 551 res = rl_intersection(one_rl, two_rl);
556 552 sm_msg("'%s' intersect '%s' is '%s'", show_rl(one_rl), show_rl(two_rl), show_rl(res));
557 553 }
558 554
559 555 static void match_type(const char *fn, struct expression *expr, void *info)
560 556 {
561 557 struct expression *one;
562 558 struct symbol *type;
563 559 char *name;
564 560
565 561 one = get_argument_from_call_expr(expr->args, 0);
566 562 type = get_type(one);
567 563 name = expr_to_str(one);
568 564 sm_msg("type of '%s' is: '%s'", name, type_to_str(type));
569 565 free_string(name);
570 566 }
571 567
572 568 static int match_type_rl_return(struct expression *call, void *unused, struct range_list **rl)
573 569 {
574 570 struct expression *one, *two;
575 571 struct symbol *type;
576 572
577 573 one = get_argument_from_call_expr(call->args, 0);
578 574 type = get_type(one);
579 575
580 576 two = get_argument_from_call_expr(call->args, 1);
581 577 if (!two || two->type != EXPR_STRING) {
582 578 sm_msg("expected: __smatch_type_rl(type, \"string\")");
583 579 return 0;
584 580 }
585 581 call_results_to_rl(call, type, two->string->data, rl);
586 582 return 1;
587 583 }
588 584
589 585 static void print_left_right(struct sm_state *sm)
590 586 {
591 587 if (!sm)
592 588 return;
593 589 if (!sm->left && !sm->right)
594 590 return;
595 591
596 592 sm_printf("[ ");
597 593 if (sm->left)
598 594 sm_printf("(%d: %s->'%s')", get_stree_id(sm->left->pool), sm->left->name, sm->left->state->name);
599 595 else
600 596 sm_printf(" - ");
601 597
602 598
603 599 print_left_right(sm->left);
604 600
605 601 if (sm->right)
606 602 sm_printf("(%d: %s->'%s')", get_stree_id(sm->right->pool), sm->right->name, sm->right->state->name);
607 603 else
608 604 sm_printf(" - ");
609 605
610 606 print_left_right(sm->right);
611 607 }
612 608
613 609 static void match_print_merge_tree(const char *fn, struct expression *expr, void *info)
614 610 {
615 611 struct sm_state *sm;
616 612 struct expression *arg;
617 613 char *name;
618 614
619 615 arg = get_argument_from_call_expr(expr->args, 0);
620 616 name = expr_to_str(arg);
621 617
622 618 sm = get_sm_state_expr(SMATCH_EXTRA, arg);
623 619 if (!sm) {
624 620 sm_msg("no sm state for '%s'", name);
625 621 goto free;
626 622 }
627 623
628 624 sm_prefix();
629 625 sm_printf("merge tree: %s -> %s", name, sm->state->name);
630 626 print_left_right(sm);
631 627 sm_printf("\n");
632 628
633 629 free:
634 630 free_string(name);
635 631 }
636 632
↓ open down ↓ |
110 lines elided |
↑ open up ↑ |
637 633 static void match_print_stree_id(const char *fn, struct expression *expr, void *info)
638 634 {
639 635 sm_msg("stree_id %d", __stree_id);
640 636 }
641 637
642 638 static void match_mtag(const char *fn, struct expression *expr, void *info)
643 639 {
644 640 struct expression *arg;
645 641 char *name;
646 642 mtag_t tag = 0;
643 + int offset = 0;
647 644
648 645 arg = get_argument_from_call_expr(expr->args, 0);
649 646 name = expr_to_str(arg);
650 - get_mtag(arg, &tag);
651 - sm_msg("mtag: '%s' => tag: %lld", name, tag);
647 + expr_to_mtag_offset(arg, &tag, &offset);
648 + sm_msg("mtag: '%s' => tag: %llu %d", name, tag, offset);
652 649 free_string(name);
653 650 }
654 651
655 652 static void match_mtag_data_offset(const char *fn, struct expression *expr, void *info)
656 653 {
657 654 struct expression *arg;
658 655 char *name;
659 656 mtag_t tag = 0;
660 657 int offset = -1;
661 658
662 659 arg = get_argument_from_call_expr(expr->args, 0);
663 660 name = expr_to_str(arg);
664 661 expr_to_mtag_offset(arg, &tag, &offset);
665 662 sm_msg("mtag: '%s' => tag: %lld, offset: %d", name, tag, offset);
666 663 free_string(name);
667 664 }
668 665
666 +static void match_container(const char *fn, struct expression *expr, void *info)
667 +{
668 + struct expression *container, *x;
669 + char *cont, *name, *str;
670 +
671 + container = get_argument_from_call_expr(expr->args, 0);
672 + x = get_argument_from_call_expr(expr->args, 1);
673 +
674 + str = get_container_name(container, x);
675 + cont = expr_to_str(container);
676 + name = expr_to_str(x);
677 + sm_msg("container: '%s' vs '%s' --> '%s'", cont, name, str);
678 + free_string(cont);
679 + free_string(name);
680 +}
681 +
669 682 static void match_state_count(const char *fn, struct expression *expr, void *info)
670 683 {
671 684 sm_msg("state_count = %d\n", sm_state_counter);
672 685 }
673 686
674 687 static void match_mem(const char *fn, struct expression *expr, void *info)
675 688 {
676 689 show_sname_alloc();
677 690 show_ptrlist_alloc();
678 691 sm_msg("%lu pools", get_pool_count());
679 692 sm_msg("%d strees", unfree_stree);
680 693 show_smatch_state_alloc();
681 694 show_sm_state_alloc();
682 695 }
683 696
684 697 static void match_exit(const char *fn, struct expression *expr, void *info)
685 698 {
686 699 exit(0);
687 700 }
688 701
689 702 static struct stree *old_stree;
690 703 static void trace_var(struct statement *stmt)
691 704 {
692 705 struct sm_state *sm, *old;
693 706 int printed = 0;
694 707
695 708 if (!trace_variable)
696 709 return;
697 710 if (__inline_fn)
698 711 return;
699 712
700 713 FOR_EACH_SM(__get_cur_stree(), sm) {
701 714 if (strcmp(sm->name, trace_variable) != 0)
702 715 continue;
703 716 old = get_sm_state_stree(old_stree, sm->owner, sm->name, sm->sym);
704 717 if (old && old->state == sm->state)
705 718 continue;
706 719 sm_msg("[%d] %s '%s': '%s' => '%s'", stmt->type,
707 720 check_name(sm->owner),
708 721 sm->name, old ? old->state->name : "<none>", sm->state->name);
709 722 printed = 1;
710 723 } END_FOR_EACH_SM(sm);
711 724
712 725 if (printed) {
713 726 free_stree(&old_stree);
714 727 old_stree = clone_stree(__get_cur_stree());
715 728 }
716 729 }
717 730
718 731 static void free_old_stree(struct symbol *sym)
719 732 {
720 733 free_stree(&old_stree);
721 734 }
722 735
723 736 void check_debug(int id)
724 737 {
725 738 my_id = id;
726 739 add_function_hook("__smatch_about", &match_about, NULL);
727 740 add_function_hook("__smatch_all_values", &match_all_values, NULL);
728 741 add_function_hook("__smatch_state", &match_state, NULL);
729 742 add_function_hook("__smatch_states", &match_states, NULL);
730 743 add_function_hook("__smatch_value", &match_print_value, NULL);
731 744 add_function_hook("__smatch_known", &match_print_known, NULL);
732 745 add_function_hook("__smatch_implied", &match_print_implied, NULL);
733 746 add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL);
734 747 add_function_hook("__smatch_implied_max", &match_print_implied_max, NULL);
735 748 add_function_hook("__smatch_user_rl", &match_user_rl, NULL);
736 749 add_function_hook("__smatch_capped", &match_capped, NULL);
737 750 add_function_hook("__smatch_hard_max", &match_print_hard_max, NULL);
738 751 add_function_hook("__smatch_fuzzy_max", &match_print_fuzzy_max, NULL);
739 752 add_function_hook("__smatch_absolute", &match_print_absolute, NULL);
740 753 add_function_hook("__smatch_absolute_min", &match_print_absolute_min, NULL);
741 754 add_function_hook("__smatch_absolute_max", &match_print_absolute_max, NULL);
742 755 add_function_hook("__smatch_real_absolute", &match_real_absolute, NULL);
743 756 add_function_hook("__smatch_sval_info", &match_sval_info, NULL);
744 757 add_function_hook("__smatch_member_name", &match_member_name, NULL);
745 758 add_function_hook("__smatch_possible", &match_possible, NULL);
746 759 add_function_hook("__smatch_cur_stree", &match_cur_stree, NULL);
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
747 760 add_function_hook("__smatch_strlen", &match_strlen, NULL);
748 761 add_function_hook("__smatch_buf_size", &match_buf_size, NULL);
749 762 add_function_hook("__smatch_note", &match_note, NULL);
750 763 add_function_hook("__smatch_dump_related", &match_dump_related, NULL);
751 764 add_function_hook("__smatch_compare", &match_compare, NULL);
752 765 add_function_hook("__smatch_debug_on", &match_debug_on, NULL);
753 766 add_function_hook("__smatch_debug_check", &match_debug_check, NULL);
754 767 add_function_hook("__smatch_debug_off", &match_debug_off, NULL);
755 768 add_function_hook("__smatch_local_debug_on", &match_local_debug_on, NULL);
756 769 add_function_hook("__smatch_local_debug_off", &match_local_debug_off, NULL);
757 - add_function_hook("__smatch_debug_implied_on", &match_debug_implied_on, NULL);
758 - add_function_hook("__smatch_debug_implied_off", &match_debug_implied_off, NULL);
759 770 add_function_hook("__smatch_intersection", &match_intersection, NULL);
760 771 add_function_hook("__smatch_type", &match_type, NULL);
761 772 add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL);
762 773 add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL);
763 774 add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL);
764 775 add_function_hook("__smatch_mtag", &match_mtag, NULL);
765 776 add_function_hook("__smatch_mtag_data", &match_mtag_data_offset, NULL);
766 777 add_function_hook("__smatch_state_count", &match_state_count, NULL);
767 778 add_function_hook("__smatch_mem", &match_mem, NULL);
768 779 add_function_hook("__smatch_exit", &match_exit, NULL);
780 + add_function_hook("__smatch_container", &match_container, NULL);
769 781
770 782 add_hook(free_old_stree, AFTER_FUNC_HOOK);
771 783 add_hook(trace_var, STMT_HOOK_AFTER);
772 784 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX