user_data2: handle "if (untrusted != trusted) {"
[smatch.git] / smatch_scripts / trace_params.pl
blobf97ae4cac3129a15d02824c101ea1b803143beef
1 #!/usr/bin/perl
3 # This script is supposed to help use the param_mapper output.
4 # Give it a function and parameter and it lists the functions
5 # and parameters which are basically equivalent.
7 use strict;
9 sub usage()
11 print ("trace_params.pl <smatch output file> <function> <parameter>\n");
12 exit(1);
15 my %param_map;
17 my $UNKNOWN = 1;
18 my $NOTFOUND = 2;
19 my $FOUND = 3;
21 sub recurse($$)
23 my $link = shift;
24 my $target = shift;
25 my $found = 0;
27 if ($link =~ /$target/) {
28 $param_map{$link}->{found} = $FOUND;
29 return 1;
32 if ($param_map{$link}->{found} == $FOUND) {
33 return 1;
35 if ($param_map{$link}->{found} == $NOTFOUND) {
36 return 0;
39 $param_map{$link}->{found} = $NOTFOUND;
40 foreach my $l (@{$param_map{$link}->{links}}){
41 $found = recurse($l, $target);
42 if ($found) {
43 $param_map{$link}->{found} = $FOUND;
44 return 1;
48 return 0;
51 sub compress_all($$)
53 my $f = shift;
54 my $p = shift;
55 my $target = "$f%$p";
57 foreach my $link (keys %param_map){
58 recurse($link, $target);
62 sub add_link($$)
64 my $one = shift;
65 my $two = shift;
67 if (!defined($param_map{$one})) {
68 $param_map{$one} = {found => $UNKNOWN, links => []};
70 push @{$param_map{$one}->{links}}, $two;
73 sub load_all($)
75 my $file = shift;
77 open(FILE, "<$file");
78 while (<FILE>) {
79 if (/.*?:\d+ (.*?)\(\) info: param_mapper (\d+) => (.*?) (\d+)/) {
80 add_link("$1%$2", "$3%$4");
85 sub print_found()
87 foreach my $func (keys %param_map){
88 my $tmp = $param_map{$func};
90 if ($tmp->{found} == $FOUND) {
91 my ($f, $p) = split(/%/, $func);
92 print("$f $p\n");
97 my $file = shift();
98 my $func = shift();
99 my $param = shift();
101 if (!$file or !$func or !defined($param)) {
102 usage();
105 if (! -e $file) {
106 printf("Error: $file does not exist.\n");
107 exit(1);
110 load_all($file);
111 compress_all($func, $param);
112 print_found();