From b331cdf010c3e457de6a99f2d1a6327ad0999685 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 11 Feb 2013 14:53:42 +0300 Subject: [PATCH] db: tools for printing raw SQL instead of human readable info for the db The plan is that, instead of printing human readable output that no one actually reads, we can just print SQL. This will mean we don't need the smatch_scripts/db/fill_*.pl scripts so it adding new stuff to the database easier. It eliminates a layer where bugs can be introduced. But also, more importantly, once everything is moved to the new format, I want to change how inline functions are handled. I'll create a in memory database and load the call information there and delete it after it has been used. I have created the fn_static() function which returns 1 if the current function being parsed is static or 0 if not. It's like global_static() but without the human readable intermediate step. Signed-off-by: Dan Carpenter --- smatch.h | 4 ++++ smatch_db.c | 17 +++++++++++++++++ smatch_scripts/db/fill_db_sql.pl | 32 ++++++++++++++++++++++++++++++++ smatch_type.c | 5 +++++ 4 files changed, 58 insertions(+) create mode 100755 smatch_scripts/db/fill_db_sql.pl diff --git a/smatch.h b/smatch.h index 77f236db..39c5c4ca 100644 --- a/smatch.h +++ b/smatch.h @@ -288,6 +288,7 @@ int is_void_pointer(struct expression *expr); int is_char_pointer(struct expression *expr); int is_static(struct expression *expr); int types_equiv(struct symbol *one, struct symbol *two); +int fn_static(void); const char *global_static(); struct symbol *cur_func_return_type(void); struct symbol *get_arg_type(struct expression *fn, int arg); @@ -497,6 +498,9 @@ do { \ sql_exec(call_back, sql_txt); \ } while (0) +void sql_insert_return_states(int return_id, const char *return_ranges, + int type, int param, const char *key, const char *value); + void sql_exec(int (*callback)(void*, int, char**, char**), const char *sql); void open_smatch_db(void); diff --git a/smatch_db.c b/smatch_db.c index 0f859add..da9de6d0 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -14,6 +14,15 @@ #include "smatch_slist.h" #include "smatch_extra.h" +#define sql_insert(table, values...) \ +do { \ + if (option_info) { \ + sm_prefix(); \ + sm_printf("SQL: insert into " #table " values (" values); \ + sm_printf(");\n"); \ + } \ +} while (0) + static sqlite3 *db; struct def_callback { @@ -70,6 +79,14 @@ void sql_exec(int (*callback)(void*, int, char**, char**), const char *sql) } } +void sql_insert_return_states(int return_id, const char *return_ranges, + int type, int param, const char *key, const char *value) +{ + sql_insert(return_states, "'%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s'", + get_filename(), get_function(), return_id, return_ranges, + fn_static(), type, param, key, value); +} + void add_definition_db_callback(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type) { struct def_callback *def_callback = __alloc_def_callback(0); diff --git a/smatch_scripts/db/fill_db_sql.pl b/smatch_scripts/db/fill_db_sql.pl new file mode 100755 index 00000000..5752d10b --- /dev/null +++ b/smatch_scripts/db/fill_db_sql.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl -w + +use strict; +use DBI; + +my $warns = shift; + +if (!defined($warns)) { + print "usage: $0 \n"; + exit(1); +} + +my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit => 0}); +$db->do("PRAGMA synchronous = OFF"); +$db->do("PRAGMA cache_size = 800000"); +$db->do("PRAGMA journal_mode = OFF"); + +my ($dummy, $sql); + +open(WARNS, "<$warns"); +while () { + + if (!($_ =~ /^.*? \w+\(\) SQL: /)) { + next; + } + ($dummy, $dummy, $sql) = split(/:/); + + $db->do($sql); +} + +$db->commit(); +$db->disconnect(); diff --git a/smatch_type.c b/smatch_type.c index e640b404..f9c4b782 100644 --- a/smatch_type.c +++ b/smatch_type.c @@ -398,6 +398,11 @@ int types_equiv(struct symbol *one, struct symbol *two) return 1; } +int fn_static(void) +{ + return !!(cur_func_sym->ctype.modifiers & MOD_STATIC); +} + const char *global_static() { if (cur_func_sym->ctype.modifiers & MOD_STATIC) -- 2.11.4.GIT