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