From 73a71e701bf61a0babe06ee2d3422ada4f4d96ff Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 12 Oct 2011 17:03:37 +0300 Subject: [PATCH] extra, db: record a dummy output for every function call The smatch_extra.c had a dummy function call to mark calls where nothing was known. Smatch extra tried to only print it out where it was needed, but that gets trickier when you have a bunch of scripts writing to the db. The new way is to just do it in smatch_db.c. Do it unconditionally. I made some related changes to ensure that it would cause a merge_slist() like it's supposed to. Signed-off-by: Dan Carpenter --- smatch_db.c | 30 +++++++++++++++++++++++++----- smatch_extra.c | 15 +++------------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/smatch_db.c b/smatch_db.c index 9d0b5b41..7625d4f0 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -48,6 +48,25 @@ void add_definition_db_callback(void (*callback)(const char *name, struct symbol add_ptr_list(&callbacks, def_callback); } +static void match_call_hack(struct expression *expr) +{ + char *name; + + /* + * we just want to record something in the database so that if we have + * two calls like: frob(4); frob(some_unkown); then on the recieving + * side we know that sometimes frob is called with unknown parameters. + */ + + name = get_fnptr_name(expr->fn); + if (!name) + return; + if (ptr_list_empty(expr->args)) + return; + sm_msg("info: passes param_value '%s' -1 '$$' min-max", name); + free_string(name); +} + static unsigned long call_count; static int db_count_callback(void *unused, int argc, char **argv, char **azColName) { @@ -88,8 +107,8 @@ static int prev_func_id = -1; static int db_callback(void *unused, int argc, char **argv, char **azColName) { int func_id; - int type; - unsigned long param; + long type; + long param; char *name; struct symbol *sym; struct def_callback *def_callback; @@ -98,9 +117,9 @@ static int db_callback(void *unused, int argc, char **argv, char **azColName) return 0; func_id = atoi(argv[0]); - type = atoi(argv[1]); errno = 0; - param = strtoul(argv[2], NULL, 10); + type = strtol(argv[1], NULL, 10); + param = strtol(argv[2], NULL, 10); if (errno) return 0; @@ -112,7 +131,7 @@ static int db_callback(void *unused, int argc, char **argv, char **azColName) prev_func_id = func_id; } - if (!get_param(param, &name, &sym)) + if (param == -1 || !get_param(param, &name, &sym)) return 0; FOR_EACH_PTR(callbacks, def_callback) { @@ -270,6 +289,7 @@ void open_smatch_db(void) void register_definition_db_callbacks(int id) { if (option_info) { + add_hook(&match_call_hack, FUNCTION_CALL_HOOK); add_hook(&match_function_assign, ASSIGNMENT_HOOK); add_hook(&global_variable, BASE_HOOK); add_hook(&global_variable, DECLARATION_HOOK); diff --git a/smatch_extra.c b/smatch_extra.c index 6988df00..8024bb88 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -984,7 +984,7 @@ int is_whole_range(struct smatch_state *state) return 0; } -static int print_param_info(char *fn, struct expression *expr, int param, struct state_list *slist) +static void print_param_info(char *fn, struct expression *expr, int param, struct state_list *slist) { struct range_list *rl = NULL; struct sm_state *sm; @@ -992,12 +992,10 @@ static int print_param_info(char *fn, struct expression *expr, int param, struct struct symbol *sym; int len; char *msg; - int ret = 0; if (get_implied_range_list(expr, &rl) && ! is_whole_range_rl(rl)) { msg = show_ranges(rl); sm_msg("info: passes param_value '%s' %d '$$' %s", fn, param, msg); - ret = 1; } name = get_variable_from_expr(expr, &sym); @@ -1013,11 +1011,9 @@ static int print_param_info(char *fn, struct expression *expr, int param, struct if (strncmp(name, sm->name, len) || sm->name[len] == '\0') continue; sm_msg("info: passes param_value '%s' %d '$$%s' %s", fn, param, sm->name + len, sm->state->name); - ret = 1; } END_FOR_EACH_PTR(sm); free: free_string(name); - return ret; } static void match_call_info(struct expression *expr) @@ -1025,7 +1021,6 @@ static void match_call_info(struct expression *expr) struct expression *arg; struct state_list *slist; char *name; - int count = 0; int i = 0; name = get_fnptr_name(expr->fn); @@ -1034,14 +1029,10 @@ static void match_call_info(struct expression *expr) slist = get_all_states(SMATCH_EXTRA); FOR_EACH_PTR(expr->args, arg) { - count += print_param_info(name, arg, i, slist); + print_param_info(name, arg, i, slist); i++; } END_FOR_EACH_PTR(arg); - if (i && !count) { - /* we want to record something here to mark that nothing is known - about this call */ - sm_msg("info: passes param_value '%s' 0 '$$' min-max", name); - } + free_string(name); free_slist(&slist); } -- 2.11.4.GIT