From d4a557d21805e473e6939b276744dc0bd5ba22e9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 19 Jan 2015 17:08:35 +0300 Subject: [PATCH] debug: introduce __smatch_known() Normally, you would use __smatch_implied(). This one will only print constant values and literals. Signed-off-by: Dan Carpenter --- check_debug.c | 20 ++++++++++++++++++++ check_debug.h | 1 + 2 files changed, 21 insertions(+) diff --git a/check_debug.c b/check_debug.c index 5a1bbd9e..98d464e7 100644 --- a/check_debug.c +++ b/check_debug.c @@ -109,6 +109,25 @@ static void match_print_value(const char *fn, struct expression *expr, void *inf } END_FOR_EACH_SM(tmp); } +static void match_print_known(const char *fn, struct expression *expr, void *info) +{ + struct expression *arg; + struct range_list *rl = NULL; + char *name; + int known = 0; + sval_t sval; + + arg = get_argument_from_call_expr(expr->args, 0); + if (get_value(arg, &sval)) + known = 1; + + get_implied_rl(arg, &rl); + + name = expr_to_str(arg); + sm_msg("known: '%s' = '%s'. implied = '%s'", name, known ? sval_to_str(sval) : "", show_rl(rl)); + free_string(name); +} + static void match_print_implied(const char *fn, struct expression *expr, void *info) { struct expression *arg; @@ -542,6 +561,7 @@ void check_debug(int id) add_function_hook("__smatch_state", &match_state, NULL); add_function_hook("__smatch_states", &match_states, NULL); add_function_hook("__smatch_value", &match_print_value, NULL); + add_function_hook("__smatch_known", &match_print_known, NULL); add_function_hook("__smatch_implied", &match_print_implied, NULL); add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL); add_function_hook("__smatch_implied_max", &match_print_implied_max, NULL); diff --git a/check_debug.h b/check_debug.h index c7ef6436..be6de6a8 100644 --- a/check_debug.h +++ b/check_debug.h @@ -8,6 +8,7 @@ static inline void __smatch_all_values(void){} static inline void __smatch_state(const char *check_name, const char *state_name){} static inline void __smatch_states(const char *check_name){} static inline void __smatch_value(const char *unused){} +static inline void __smatch_known(long long val){} static inline void __smatch_implied(long long val){} static inline void __smatch_implied_min(long long val){} static inline void __smatch_implied_max(long long val){} -- 2.11.4.GIT