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