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