Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_data_source.c
+++ new/usr/src/tools/smatch/src/smatch_data_source.c
1 1 /*
2 2 * Copyright (C) 2013 Oracle.
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 */
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17
18 18 #include "smatch.h"
19 19 #include "smatch_slist.h"
20 20 #include "smatch_extra.h"
21 21
22 22 static int my_id;
23 23
24 24 static char *get_source_parameter(struct expression *expr)
25 25 {
26 26 struct expression *tmp;
27 + const char *param_name;
27 28 struct symbol *sym;
28 29 char *name;
29 30 int param;
30 31 char *ret = NULL;
31 32 char buf[32];
32 33 int cnt = 0;
34 + bool modified = false;
33 35
34 36 tmp = expr;
35 37 while ((tmp = get_assigned_expr(tmp))) {
36 38 expr = tmp;
37 39 if (cnt++ > 3)
38 40 break;
39 41 }
40 42
41 43 expr = strip_expr(expr);
42 44 if (expr->type != EXPR_SYMBOL)
43 45 return NULL;
44 46
45 47 name = expr_to_var_sym(expr, &sym);
46 48 if (!name || !sym)
47 49 goto free;
48 50 param = get_param_num_from_sym(sym);
49 51 if (param < 0)
50 52 goto free;
51 - if (param_was_set(expr))
53 + param_name = get_param_name_var_sym(name, sym);
54 + if (!param_name)
52 55 goto free;
56 + if (param_was_set_var_sym(name, sym))
57 + modified = true;
53 58
54 - snprintf(buf, sizeof(buf), "p %d", param);
59 + snprintf(buf, sizeof(buf), "$%d%s%s", param, param_name + 1,
60 + modified ? " [m]" : "");
55 61 ret = alloc_string(buf);
56 62
57 63 free:
58 64 free_string(name);
59 65 return ret;
60 66 }
61 67
62 68 static char *get_source_assignment(struct expression *expr)
63 69 {
64 70 struct expression *right;
65 71 char *name;
66 72 char buf[64];
67 73 char *ret;
68 74
69 75 right = get_assigned_expr(expr);
70 76 right = strip_expr(right);
71 77 if (!right)
72 78 return NULL;
73 79 if (right->type != EXPR_CALL || right->fn->type != EXPR_SYMBOL)
74 80 return NULL;
75 81 if (is_fake_call(right))
76 82 return NULL;
77 83 name = expr_to_str(right->fn);
78 84 if (!name)
79 85 return NULL;
80 86 snprintf(buf, sizeof(buf), "r %s", name);
81 87 ret = alloc_string(buf);
82 88 free_string(name);
83 89 return ret;
84 90 }
85 91
86 92 static char *get_source_str(struct expression *arg)
87 93 {
88 94 char *source;
89 95
90 96 source = get_source_parameter(arg);
91 97 if (source)
92 98 return source;
93 99 return get_source_assignment(arg);
94 100 }
95 101
96 102 static void match_caller_info(struct expression *expr)
97 103 {
98 104 struct expression *arg;
99 105 char *source;
100 106 int i;
101 107
102 108 i = -1;
103 109 FOR_EACH_PTR(expr->args, arg) {
104 110 i++;
105 111 source = get_source_str(arg);
106 112 if (!source)
107 113 continue;
108 114 sql_insert_caller_info(expr, DATA_SOURCE, i, "$", source);
109 115 free_string(source);
110 116 } END_FOR_EACH_PTR(arg);
111 117 }
112 118
113 119 void register_data_source(int id)
114 120 {
115 121 // if (!option_info)
116 122 // return;
117 123 my_id = id;
118 124 add_hook(&match_caller_info, FUNCTION_CALL_HOOK);
119 125 }
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX