From 2bc69fcaa76cdb856db1ee43deedcc0dd7b2a467 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 11 Feb 2013 17:14:57 +0300 Subject: [PATCH] db: move function_ptr to raw SQL Instead of printing human readable text and parsing it with fill_db_function_ptr.pl, just print raw SQL and parse it with fill_db_sql.pl. Signed-off-by: Dan Carpenter --- smatch.h | 1 + smatch_db.c | 16 +++++++--- smatch_scripts/db/fill_db_function_ptr.pl | 51 ------------------------------- 3 files changed, 13 insertions(+), 55 deletions(-) delete mode 100755 smatch_scripts/db/fill_db_function_ptr.pl diff --git a/smatch.h b/smatch.h index 39c5c4ca..7f7a84ac 100644 --- a/smatch.h +++ b/smatch.h @@ -500,6 +500,7 @@ do { \ void sql_insert_return_states(int return_id, const char *return_ranges, int type, int param, const char *key, const char *value); +void sql_insert_function_ptr(const char *fn, const char *struct_name); 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 eb8f8343..23926e99 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -87,6 +87,12 @@ void sql_insert_return_states(int return_id, const char *return_ranges, fn_static(), type, param, key, value); } +void sql_insert_function_ptr(const char *fn, const char *struct_name) +{ + sql_insert(function_ptr, "'%s', '%s', '%s'", get_filename(), fn, + struct_name); +} + 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); @@ -425,7 +431,7 @@ static void match_function_assign(struct expression *expr) if (!fn_name || !ptr_name) goto free; - sm_msg("info: sets_fn_ptr '%s' '%s'", ptr_name, fn_name); + sql_insert_function_ptr(fn_name, ptr_name); free: free_string(fn_name); @@ -491,6 +497,7 @@ static void print_initializer_list(struct expression_list *expr_list, { struct expression *expr; struct symbol *base_type; + char struct_name[256]; FOR_EACH_PTR(expr_list, expr) { if (expr->type == EXPR_INDEX && expr->idx_expression && expr->idx_expression->type == EXPR_INITIALIZER) { @@ -506,9 +513,10 @@ static void print_initializer_list(struct expression_list *expr_list, base_type = get_type(expr->ident_expression); if (!base_type || base_type->type != SYM_FN) continue; - sm_msg("info: sets_fn_ptr '(struct %s)->%s' '%s'", struct_type->ident->name, - expr->expr_ident->name, - expr->ident_expression->symbol_name->name); + snprintf(struct_name, sizeof(struct_name), "(struct %s)->%s", + struct_type->ident->name, expr->expr_ident->name); + sql_insert_function_ptr(expr->ident_expression->symbol_name->name, + struct_name); } END_FOR_EACH_PTR(expr); } diff --git a/smatch_scripts/db/fill_db_function_ptr.pl b/smatch_scripts/db/fill_db_function_ptr.pl deleted file mode 100755 index 825a497c..00000000 --- a/smatch_scripts/db/fill_db_function_ptr.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/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"); - -$db->do("delete from function_ptr;"); - -open(WARNS, "<$warns"); -while () { - if (!($_ =~ /info: sets_fn_ptr /)) { - next; - } - - # kernel/ksysfs.c +87 (null)(87) info: sets_fn_ptr '(struct kobj_attribute)->show' 'profiling_show' - - s/\n//; - - my ($file_and_line, $file, $dummy, $struct_bit, $func, $ptr); - ($file_and_line, $dummy, $dummy, $dummy, $struct_bit, $ptr, $func) = split(/ /, $_); - ($file, $dummy) = split(/:/, $file_and_line); - - if (!defined($func)) { - next; - } - if (!($struct_bit =~ /^'\(struct$/)) { - next; - } - if (!($func =~ /^'[\w_]+'$/)) { - next; - } - - $struct_bit =~ s/'//; - $ptr =~ s/'//; - $func =~ s/'//g; - - $db->do("insert into function_ptr values ('$file', '$func', '$struct_bit $ptr')\n"); -} -$db->commit(); -$db->disconnect(); -- 2.11.4.GIT