From 10f7b6ea2b1eaec2e9a6ec95de754098d0ac9ff9 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 10 May 2017 16:32:49 +0300 Subject: [PATCH] project: create a way to generate smatch_data for a new project Edit the Makefile to set CC to cgcc then run smatch_scripts/build_generic_info.sh There are a bunch of other small changes to make this slightly cleaner. One thing is that now we prefer smatch_data/ in the CWD if it exists instead of the one that ships with the smatch binary. Signed-off-by: Dan Carpenter --- smatch.c | 7 +++- smatch_data/db/remove_mixed_up_pointer_params.pl | 3 ++ smatch_project.c | 5 +-- smatch_scripts/build_generic_info.sh | 52 ++++++++++++++++++++++++ smatch_scripts/gen_no_return_funcs.sh | 2 +- smatch_scripts/gen_sizeof_param.sh | 2 +- 6 files changed, 64 insertions(+), 7 deletions(-) create mode 100755 smatch_scripts/build_generic_info.sh diff --git a/smatch.c b/smatch.c index a56d097c..891db900 100644 --- a/smatch.c +++ b/smatch.c @@ -22,7 +22,7 @@ #include "check_list.h" char *option_debug_check = (char *)""; -char *option_project_str = (char *)""; +char *option_project_str = (char *)"smatch_generic"; enum project_type option_project = PROJ_NONE; char *data_dir; int option_no_data = 0; @@ -250,6 +250,11 @@ static char *get_data_dir(char *arg0) return alloc_string(option_datadir_str); } + strncpy(buf, "smatch_data/", sizeof(buf)); + dir = alloc_string(buf); + if (!access(dir, R_OK)) + return dir; + orig = alloc_string(arg0); bin_dir = dirname(orig); strncpy(buf, bin_dir, 254); diff --git a/smatch_data/db/remove_mixed_up_pointer_params.pl b/smatch_data/db/remove_mixed_up_pointer_params.pl index 02458ad2..1e7a89ab 100755 --- a/smatch_data/db/remove_mixed_up_pointer_params.pl +++ b/smatch_data/db/remove_mixed_up_pointer_params.pl @@ -33,6 +33,9 @@ while (($file, $caller, $function, $param, $value) = $select->fetchrow_array()) $select_type->execute($file, $caller, $src_param); $type = $select_type->fetchrow_array(); + if (!$type) { + next; + } #FIXME: Why is this extra fetch() needed??? $select_type->fetch(); diff --git a/smatch_project.c b/smatch_project.c index 53937bca..b2fa3ce6 100644 --- a/smatch_project.c +++ b/smatch_project.c @@ -56,10 +56,7 @@ static void register_no_return_funcs(void) const char *func; char name[256]; - if (option_project == PROJ_NONE) - strcpy(name, "no_return_funcs"); - else - snprintf(name, 256, "%s.no_return_funcs", option_project_str); + snprintf(name, 256, "%s.no_return_funcs", option_project_str); token = get_tokens_file(name); if (!token) diff --git a/smatch_scripts/build_generic_info.sh b/smatch_scripts/build_generic_info.sh new file mode 100755 index 00000000..edea7f1d --- /dev/null +++ b/smatch_scripts/build_generic_info.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# This is a generic script to parse --info output. For the kernel, don't use +# this script, use build_kernel_data.sh instead. + +SCRIPT_DIR=$(dirname $0) +DATA_DIR=smatch_data +PROJECT=smatch_generic + +function usage { + echo + echo "Usage: $0" + echo "Updates the smatch_data/ directory and builds the smatch database" + echo + exit 1 +} + +if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then + usage; +fi + +if [ -e $SCRIPT_DIR/../smatch ] ; then + BIN_DIR=$SCRIPT_DIR/../ +else + echo "This script should be located in the smatch_scripts/ subdirectory of the smatch source." + exit 1 +fi + +# If someone is building the database for the first time then make sure all the +# required packages are installed +if [ ! -e smatch_db.sqlite ] ; then + [ -e smatch_warns.txt ] || touch smatch_warns.txt + if ! $SCRIPT_DIR/../smatch_data/db/create_db.sh -p=kernel smatch_warns.txt ; then + echo "Hm... Not working. Make sure you have all the sqlite3 packages" + echo "And the sqlite3 libraries for Perl and Python" + exit 1 + fi +fi + +make CHECK="$BIN_DIR/smatch --call-tree --info --param-mapper --spammy --file-output" + +find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > smatch_warns.txt + +for i in $SCRIPT_DIR/gen_* ; do + $i smatch_warns.txt -p=${PROJECT} +done + +mkdir -p $DATA_DIR +mv $PROJECT.* $DATA_DIR + +$SCRIPT_DIR/../smatch_data/db/create_db.sh smatch_warns.txt + diff --git a/smatch_scripts/gen_no_return_funcs.sh b/smatch_scripts/gen_no_return_funcs.sh index bdf78eb2..713456c0 100755 --- a/smatch_scripts/gen_no_return_funcs.sh +++ b/smatch_scripts/gen_no_return_funcs.sh @@ -18,7 +18,7 @@ tmp2=$(mktemp /tmp/smatch.XXXX) echo "// list of functions which don't return." > $outfile echo '// generated by `gen_no_return_funcs.sh`' >> $outfile cat $(echo ${bin_dir}/../smatch_data/no_return_funcs) >> $outfile -cat $add_file >> $outfile +cat $add_file >> $outfile 2> /dev/null grep no_return_funcs $file | cut -d ' ' -f 2 | cut -d '(' -f 1 > $tmp diff --git a/smatch_scripts/gen_sizeof_param.sh b/smatch_scripts/gen_sizeof_param.sh index 3ff90600..21bc7e4a 100755 --- a/smatch_scripts/gen_sizeof_param.sh +++ b/smatch_scripts/gen_sizeof_param.sh @@ -20,7 +20,7 @@ echo '// generated by `gen_sizeof_param.sh`' >> $outfile grep sizeof_param $file | grep '[0-9] [0-9]$' | cut -d ' ' -f 5- | \ sort -u | sed -e "s/'//g" > $tmp -grep -f $remove $tmp >> $tmp2 +grep -f $remove $tmp >> $tmp2 2> /dev/null cat $tmp $tmp2 2> /dev/null | sort | uniq -u >> $outfile rm $tmp rm $tmp2 -- 2.11.4.GIT