4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
15 #include "smatch_slist.h"
16 #include "smatch_extra.h"
19 static sqlite3
*mem_db
;
21 #define sql_insert(table, values...) \
25 char *err, *p = buf; \
28 p += snprintf(p, buf + sizeof(buf) - p, \
29 "insert into %s values (", #table); \
30 p += snprintf(p, buf + sizeof(buf) - p, values); \
31 p += snprintf(p, buf + sizeof(buf) - p, ");"); \
32 rc = sqlite3_exec(mem_db, buf, NULL, 0, &err); \
33 if (rc != SQLITE_OK) { \
34 fprintf(stderr, "SQL error #2: %s\n", err); \
35 fprintf(stderr, "SQL: '%s'\n", buf); \
41 sm_printf("SQL: insert into " #table " values (" values); \
48 void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
);
50 ALLOCATOR(def_callback
, "definition db hook callbacks");
51 DECLARE_PTR_LIST(callback_list
, struct def_callback
);
52 static struct callback_list
*callbacks
;
54 struct member_info_callback
{
56 void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
);
58 ALLOCATOR(member_info_callback
, "caller_info callbacks");
59 DECLARE_PTR_LIST(member_info_cb_list
, struct member_info_callback
);
60 static struct member_info_cb_list
*member_callbacks
;
62 struct returned_state_callback
{
63 void (*callback
)(int return_id
, char *return_ranges
, struct expression
*return_expr
, struct state_list
*slist
);
65 ALLOCATOR(returned_state_callback
, "returned state callbacks");
66 DECLARE_PTR_LIST(returned_state_cb_list
, struct returned_state_callback
);
67 static struct returned_state_cb_list
*returned_state_callbacks
;
69 struct returned_member_callback
{
71 void (*callback
)(int return_id
, char *return_ranges
, char *printed_name
, struct smatch_state
*state
);
73 ALLOCATOR(returned_member_callback
, "returned member callbacks");
74 DECLARE_PTR_LIST(returned_member_cb_list
, struct returned_member_callback
);
75 static struct returned_member_cb_list
*returned_member_callbacks
;
77 struct call_implies_callback
{
79 void (*callback
)(struct expression
*arg
, char *value
);
81 ALLOCATOR(call_implies_callback
, "call_implies callbacks");
82 DECLARE_PTR_LIST(call_implies_cb_list
, struct call_implies_callback
);
83 static struct call_implies_cb_list
*call_implies_cb_list
;
85 void sql_exec(int (*callback
)(void*, int, char**, char**), const char *sql
)
90 if (option_no_db
|| !db
)
93 rc
= sqlite3_exec(db
, sql
, callback
, 0, &err
);
94 if (rc
!= SQLITE_OK
) {
95 fprintf(stderr
, "SQL error #2: %s\n", err
);
96 fprintf(stderr
, "SQL: '%s'\n", sql
);
100 void sql_insert_return_states(int return_id
, const char *return_ranges
,
101 int type
, int param
, const char *key
, const char *value
)
103 sql_insert(return_states
, "'%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s'",
104 get_filename(), get_function(), return_id
, return_ranges
,
105 fn_static(), type
, param
, key
, value
);
108 void sql_insert_caller_info(struct expression
*call
, int type
,
109 int param
, const char *key
, const char *value
)
113 if (!option_info
&& !__inline_call
)
116 fn
= get_fnptr_name(call
->fn
);
125 snprintf(buf
, sizeof(buf
), "insert into caller_info values ("
126 "'%s', '%s', '%s', %lu, %d, %d, %d, '%s', '%s');",
127 get_filename(), get_function(), fn
,
128 (unsigned long)call
, is_static(call
->fn
), type
, param
,
130 rc
= sqlite3_exec(mem_db
, buf
, NULL
, 0, &err
);
131 if (rc
!= SQLITE_OK
) {
132 fprintf(stderr
, "SQL error #2: %s\n", err
);
133 fprintf(stderr
, "SQL: '%s'\n", buf
);
138 sm_msg("SQL_caller_info: insert into caller_info values ("
139 "'%s', '%s', '%s', %%FUNC_ID%%, %d, %d, %d, '%s', '%s');",
140 get_filename(), get_function(), fn
, is_static(call
->fn
),
141 type
, param
, key
, value
);
146 void sql_insert_function_ptr(const char *fn
, const char *struct_name
)
148 sql_insert(function_ptr
, "'%s', '%s', '%s'", get_filename(), fn
,
152 void sql_insert_return_values(const char *return_values
)
154 sql_insert(return_values
, "'%s', '%s', %d, '%s'", get_filename(),
155 get_function(), fn_static(), return_values
);
158 void sql_insert_call_implies(int type
, int param
, int value
)
160 sql_insert(call_implies
, "'%s', '%s', %d, %d, %d, %d", get_filename(),
161 get_function(), fn_static(), type
, param
, value
);
164 void sql_insert_type_size(const char *member
, int size
)
166 sql_insert(type_size
, "'%s', '%s', %d", get_filename(), member
, size
);
169 static char *get_static_filter(struct symbol
*sym
)
171 static char sql_filter
[1024];
173 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
174 snprintf(sql_filter
, sizeof(sql_filter
),
175 "file = '%s' and function = '%s' and static = '1';",
176 get_filename(), sym
->ident
->name
);
178 snprintf(sql_filter
, sizeof(sql_filter
),
179 "function = '%s' and static = '0';", sym
->ident
->name
);
185 void sql_select_return_states(const char *cols
, struct expression
*call
,
186 int (*callback
)(void*, int, char**, char**))
188 if (call
->fn
->type
!= EXPR_SYMBOL
|| !call
->fn
->symbol
)
191 run_sql(callback
, "select %s from return_states where %s",
192 cols
, get_static_filter(call
->fn
->symbol
));
195 void sql_select_return_values(const char *cols
, struct expression
*call
,
196 int (*callback
)(void*, int, char**, char**))
198 if (call
->fn
->type
!= EXPR_SYMBOL
|| !call
->fn
->symbol
)
201 run_sql(callback
, "select %s from return_values where %s",
202 cols
, get_static_filter(call
->fn
->symbol
));
205 void sql_select_caller_info(const char *cols
, struct symbol
*sym
,
206 int (*callback
)(void*, int, char**, char**))
209 "select %s from caller_info where %s order by function_id;",
210 cols
, get_static_filter(sym
));
213 void add_definition_db_callback(void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
), int type
)
215 struct def_callback
*def_callback
= __alloc_def_callback(0);
217 def_callback
->hook_type
= type
;
218 def_callback
->callback
= callback
;
219 add_ptr_list(&callbacks
, def_callback
);
223 * These call backs are used when the --info option is turned on to print struct
224 * member information. For example foo->bar could have a state in
225 * smatch_extra.c and also check_user.c.
227 void add_member_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
))
229 struct member_info_callback
*member_callback
= __alloc_member_info_callback(0);
231 member_callback
->owner
= owner
;
232 member_callback
->callback
= callback
;
233 add_ptr_list(&member_callbacks
, member_callback
);
236 void add_returned_state_callback(void (*fn
)(int return_id
, char *return_ranges
, struct expression
*returned_expr
, struct state_list
*slist
))
238 struct returned_state_callback
*callback
= __alloc_returned_state_callback(0);
240 callback
->callback
= fn
;
241 add_ptr_list(&returned_state_callbacks
, callback
);
244 void add_returned_member_callback(int owner
, void (*callback
)(int return_id
, char *return_ranges
, char *printed_name
, struct smatch_state
*state
))
246 struct returned_member_callback
*member_callback
= __alloc_returned_member_callback(0);
248 member_callback
->owner
= owner
;
249 member_callback
->callback
= callback
;
250 add_ptr_list(&returned_member_callbacks
, member_callback
);
253 void add_db_fn_call_callback(int type
, void (*callback
)(struct expression
*arg
, char *value
))
255 struct call_implies_callback
*cb
= __alloc_call_implies_callback(0);
258 cb
->callback
= callback
;
259 add_ptr_list(&call_implies_cb_list
, cb
);
262 static struct symbol
*return_type
;
263 static struct range_list
*return_range_list
;
264 static int db_return_callback(void *unused
, int argc
, char **argv
, char **azColName
)
269 sm_msg("return type %d", type_positive_bits(return_type
));
270 str_to_rl(return_type
, argv
[0], &return_range_list
);
274 struct range_list
*db_return_vals(struct expression
*expr
)
276 return_type
= get_type(expr
);
279 return_range_list
= NULL
;
280 sql_select_return_values("return", expr
, db_return_callback
);
281 return return_range_list
;
284 static void match_call_marker(struct expression
*expr
)
287 * we just want to record something in the database so that if we have
288 * two calls like: frob(4); frob(some_unkown); then on the receiving
289 * side we know that sometimes frob is called with unknown parameters.
292 sql_insert_caller_info(expr
, INTERNAL
, -1, "%call_marker%", "");
295 static void print_struct_members(struct expression
*call
, struct expression
*expr
, int param
, struct state_list
*slist
,
296 void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
))
302 char printed_name
[256];
305 expr
= strip_expr(expr
);
306 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '&') {
307 expr
= strip_expr(expr
->unop
);
311 name
= expr_to_var_sym(expr
, &sym
);
316 FOR_EACH_PTR(slist
, sm
) {
319 if (strncmp(name
, sm
->name
, len
) || sm
->name
[len
] == '\0')
322 snprintf(printed_name
, sizeof(printed_name
), "$$->%s", sm
->name
+ len
+ 1);
324 snprintf(printed_name
, sizeof(printed_name
), "$$%s", sm
->name
+ len
);
325 callback(call
, param
, printed_name
, sm
->state
);
326 } END_FOR_EACH_PTR(sm
);
331 static void match_call_info(struct expression
*call
)
333 struct member_info_callback
*cb
;
334 struct expression
*arg
;
335 struct state_list
*slist
;
339 name
= get_fnptr_name(call
->fn
);
343 FOR_EACH_PTR(member_callbacks
, cb
) {
344 slist
= get_all_states(cb
->owner
);
346 FOR_EACH_PTR(call
->args
, arg
) {
347 print_struct_members(call
, arg
, i
, slist
, cb
->callback
);
349 } END_FOR_EACH_PTR(arg
);
351 } END_FOR_EACH_PTR(cb
);
356 static int get_param(int param
, char **name
, struct symbol
**sym
)
362 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
364 * this is a temporary hack to work around a bug (I think in sparse?)
365 * 2.6.37-rc1:fs/reiserfs/journal.o
366 * If there is a function definition without parameter name found
367 * after a function implementation then it causes a crash.
371 if (arg
->ident
->name
< (char *)100)
373 if (i
== param
&& arg
->ident
->name
) {
374 *name
= arg
->ident
->name
;
379 } END_FOR_EACH_PTR(arg
);
384 static struct state_list
*final_states
;
385 static int prev_func_id
= -1;
386 static int db_callback(void *unused
, int argc
, char **argv
, char **azColName
)
392 struct symbol
*sym
= NULL
;
393 struct def_callback
*def_callback
;
398 func_id
= atoi(argv
[0]);
400 type
= strtol(argv
[1], NULL
, 10);
401 param
= strtol(argv
[2], NULL
, 10);
405 if (prev_func_id
== -1)
406 prev_func_id
= func_id
;
407 if (func_id
!= prev_func_id
) {
408 merge_slist(&final_states
, __pop_fake_cur_slist());
409 __push_fake_cur_slist();
411 prev_func_id
= func_id
;
414 if (type
== INTERNAL
)
416 if (param
>= 0 && !get_param(param
, &name
, &sym
))
419 FOR_EACH_PTR(callbacks
, def_callback
) {
420 if (def_callback
->hook_type
== type
)
421 def_callback
->callback(name
, sym
, argv
[3], argv
[4]);
422 } END_FOR_EACH_PTR(def_callback
);
427 static void get_direct_callers(struct symbol
*sym
)
429 sql_select_caller_info("function_id, type, parameter, key, value", sym
,
433 static char *ptr_name
;
435 static int get_ptr_name(void *unused
, int argc
, char **argv
, char **azColName
)
438 free_string(ptr_name
);
443 ptr_name
= alloc_string(argv
[0]);
447 static void get_function_pointer_callers(struct symbol
*sym
)
449 char sql_filter
[1024];
451 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
452 snprintf(sql_filter
, 1024, "file = '%s' and function = '%s';",
453 get_filename(), sym
->ident
->name
);
455 snprintf(sql_filter
, 1024, "function = '%s';",
461 run_sql(get_ptr_name
, "select ptr from function_ptr where %s", sql_filter
);
465 run_sql(db_callback
, "select function_id, type, parameter, key, value from caller_info"
466 " where function = '%s' order by function_id", ptr_name
);
468 free_string(ptr_name
);
471 static void match_data_from_db(struct symbol
*sym
)
475 if (!sym
|| !sym
->ident
|| !sym
->ident
->name
)
478 __push_fake_cur_slist();
482 get_direct_callers(sym
);
483 get_function_pointer_callers(sym
);
485 merge_slist(&final_states
, __pop_fake_cur_slist());
487 FOR_EACH_PTR(final_states
, sm
) {
489 } END_FOR_EACH_PTR(sm
);
491 free_slist(&final_states
);
494 static void match_function_assign(struct expression
*expr
)
496 struct expression
*right
= expr
->right
;
501 if (right
->type
== EXPR_PREOP
&& right
->op
== '&')
502 right
= strip_expr(right
->unop
);
503 if (right
->type
!= EXPR_SYMBOL
)
505 sym
= get_type(right
);
506 if (!sym
|| sym
->type
!= SYM_FN
)
509 fn_name
= expr_to_var(right
);
510 ptr_name
= get_fnptr_name(expr
->left
);
511 if (!fn_name
|| !ptr_name
)
514 sql_insert_function_ptr(fn_name
, ptr_name
);
517 free_string(fn_name
);
518 free_string(ptr_name
);
521 static struct expression
*call_implies_call_expr
;
522 static int call_implies_callbacks(void *unused
, int argc
, char **argv
, char **azColName
)
524 struct call_implies_callback
*cb
;
525 struct expression
*arg
= NULL
;
532 type
= atoi(argv
[1]);
533 param
= atoi(argv
[2]);
535 FOR_EACH_PTR(call_implies_cb_list
, cb
) {
536 if (cb
->type
!= type
)
539 arg
= get_argument_from_call_expr(call_implies_call_expr
->args
, param
);
543 cb
->callback(arg
, argv
[3]);
544 } END_FOR_EACH_PTR(cb
);
549 static void match_call_implies(struct expression
*expr
)
552 static char sql_filter
[1024];
554 if (expr
->fn
->type
!= EXPR_SYMBOL
)
556 sym
= expr
->fn
->symbol
;
560 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
561 snprintf(sql_filter
, 1024, "file = '%s' and function = '%s';",
562 get_filename(), sym
->ident
->name
);
564 snprintf(sql_filter
, 1024, "function = '%s' and static = 0;",
568 call_implies_call_expr
= expr
;
569 run_sql(call_implies_callbacks
,
570 "select function, type, parameter, value from call_implies where %s",
575 static void print_initializer_list(struct expression_list
*expr_list
,
576 struct symbol
*struct_type
)
578 struct expression
*expr
;
579 struct symbol
*base_type
;
580 char struct_name
[256];
582 FOR_EACH_PTR(expr_list
, expr
) {
583 if (expr
->type
== EXPR_INDEX
&& expr
->idx_expression
&& expr
->idx_expression
->type
== EXPR_INITIALIZER
) {
584 print_initializer_list(expr
->idx_expression
->expr_list
, struct_type
);
587 if (expr
->type
!= EXPR_IDENTIFIER
)
589 if (!expr
->expr_ident
)
591 if (!expr
->ident_expression
|| !expr
->ident_expression
->symbol_name
)
593 base_type
= get_type(expr
->ident_expression
);
594 if (!base_type
|| base_type
->type
!= SYM_FN
)
596 snprintf(struct_name
, sizeof(struct_name
), "(struct %s)->%s",
597 struct_type
->ident
->name
, expr
->expr_ident
->name
);
598 sql_insert_function_ptr(expr
->ident_expression
->symbol_name
->name
,
600 } END_FOR_EACH_PTR(expr
);
603 static void global_variable(struct symbol
*sym
)
605 struct symbol
*struct_type
;
609 if (!sym
->initializer
|| sym
->initializer
->type
!= EXPR_INITIALIZER
)
611 struct_type
= get_base_type(sym
);
614 if (struct_type
->type
== SYM_ARRAY
) {
615 struct_type
= get_base_type(struct_type
);
619 if (struct_type
->type
!= SYM_STRUCT
|| !struct_type
->ident
)
621 print_initializer_list(sym
->initializer
->expr_list
, struct_type
);
624 static void match_return_info(int return_id
, char *return_ranges
, struct expression
*expr
, struct state_list
*slist
)
626 sql_insert_return_states(return_id
, return_ranges
, INTERNAL
, -1, "", "");
629 static int return_id
;
630 static void match_function_def(struct symbol
*sym
)
635 static void call_return_state_hooks_compare(struct expression
*expr
)
637 struct returned_state_callback
*cb
;
638 struct state_list
*slist
;
640 int final_pass_orig
= final_pass
;
642 __push_fake_cur_slist();
645 __split_whole_condition(expr
);
646 final_pass
= final_pass_orig
;
648 return_ranges
= alloc_sname("1");
651 slist
= __get_cur_slist();
652 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
653 cb
->callback(return_id
, return_ranges
, expr
, slist
);
654 } END_FOR_EACH_PTR(cb
);
656 __push_true_states();
657 __use_false_states();
659 return_ranges
= alloc_sname("0");;
661 slist
= __get_cur_slist();
662 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
663 cb
->callback(return_id
, return_ranges
, expr
, slist
);
664 } END_FOR_EACH_PTR(cb
);
666 __merge_true_states();
667 __pop_fake_cur_slist();
670 static int call_return_state_hooks_split_possible(struct expression
*expr
)
672 struct returned_state_callback
*cb
;
673 struct state_list
*slist
;
674 struct range_list
*rl
;
677 struct sm_state
*tmp
;
679 int nr_possible
, nr_states
;
681 sm
= get_sm_state_expr(SMATCH_EXTRA
, expr
);
682 if (!sm
|| !sm
->merged
)
685 /* bail if it gets too complicated */
686 nr_possible
= ptr_list_size((struct ptr_list
*)sm
->possible
);
687 nr_states
= ptr_list_size((struct ptr_list
*)__get_cur_slist());
688 if (nr_possible
>= 100)
690 if (nr_states
* nr_possible
>= 1000)
693 FOR_EACH_PTR(sm
->possible
, tmp
) {
698 __push_fake_cur_slist();
700 overwrite_states_using_pool(tmp
);
702 rl
= cast_rl(cur_func_return_type(), estate_rl(tmp
->state
));
703 return_ranges
= show_rl(rl
);
706 slist
= __get_cur_slist();
707 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
708 cb
->callback(return_id
, return_ranges
, expr
, slist
);
709 } END_FOR_EACH_PTR(cb
);
711 __pop_fake_cur_slist();
712 } END_FOR_EACH_PTR(tmp
);
717 static void call_return_state_hooks(struct expression
*expr
)
719 struct returned_state_callback
*cb
;
720 struct state_list
*slist
;
721 struct range_list
*rl
;
725 expr
= strip_expr(expr
);
728 return_ranges
= alloc_sname("");
729 } else if (is_condition(expr
)) {
730 call_return_state_hooks_compare(expr
);
732 } else if (call_return_state_hooks_split_possible(expr
)) {
734 } else if (get_implied_rl(expr
, &rl
)) {
735 rl
= cast_rl(cur_func_return_type(), rl
);
736 return_ranges
= show_rl(rl
);
738 rl
= alloc_whole_rl(cur_func_return_type());
739 return_ranges
= show_rl(rl
);
743 slist
= __get_cur_slist();
744 nr_states
= ptr_list_size((struct ptr_list
*)__get_cur_slist());
745 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
746 if (nr_states
< 10000)
747 cb
->callback(return_id
, return_ranges
, expr
, slist
);
749 cb
->callback(return_id
, return_ranges
, expr
, NULL
);
750 } END_FOR_EACH_PTR(cb
);
753 static void print_returned_struct_members(int return_id
, char *return_ranges
, struct expression
*expr
, struct state_list
*slist
)
755 struct returned_member_callback
*cb
;
756 struct state_list
*my_slist
;
760 char member_name
[256];
763 type
= get_type(expr
);
764 if (!type
|| type
->type
!= SYM_PTR
)
766 type
= get_real_base_type(type
);
767 if (!type
|| type
->type
!= SYM_STRUCT
)
769 name
= expr_to_var(expr
);
773 member_name
[sizeof(member_name
) - 1] = '\0';
774 strcpy(member_name
, "$$");
777 FOR_EACH_PTR(returned_member_callbacks
, cb
) {
778 my_slist
= get_all_states_slist(cb
->owner
, slist
);
779 FOR_EACH_PTR(my_slist
, sm
) {
780 if (strncmp(sm
->name
, name
, len
) != 0)
782 if (strncmp(sm
->name
+ len
, "->", 2) != 0)
784 strncpy(member_name
+ 2, sm
->name
+ len
, sizeof(member_name
) - 2);
785 cb
->callback(return_id
, return_ranges
, member_name
, sm
->state
);
786 } END_FOR_EACH_PTR(sm
);
787 free_slist(&my_slist
);
788 } END_FOR_EACH_PTR(cb
);
793 static void match_end_func_info(struct symbol
*sym
)
795 if (__path_is_null())
797 call_return_state_hooks(NULL
);
800 static void init_memdb(void)
804 const char *schema_files
[] = {
806 "db/caller_info.schema",
807 "db/return_states.schema",
808 "db/type_size.schema",
809 "db/call_implies.schema",
810 "db/function_ptr.schema",
811 "db/return_values.schema",
813 static char buf
[4096];
818 rc
= sqlite3_open(":memory:", &mem_db
);
819 if (rc
!= SQLITE_OK
) {
820 printf("Error starting In-Memory database.");
824 for (i
= 0; i
< ARRAY_SIZE(schema_files
); i
++) {
825 fd
= open_data_file(schema_files
[i
]);
828 ret
= read(fd
, buf
, sizeof(buf
));
829 if (ret
== sizeof(buf
)) {
830 printf("Schema file too large: %s (limit %ld bytes)",
831 schema_files
[i
], sizeof(buf
));
834 rc
= sqlite3_exec(mem_db
, buf
, NULL
, 0, &err
);
835 if (rc
!= SQLITE_OK
) {
836 fprintf(stderr
, "SQL error #2: %s\n", err
);
837 fprintf(stderr
, "%s\n", buf
);
842 void open_smatch_db(void)
851 rc
= sqlite3_open_v2("smatch_db.sqlite", &db
, SQLITE_OPEN_READONLY
, NULL
);
852 if (rc
!= SQLITE_OK
) {
859 void register_definition_db_callbacks(int id
)
861 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
863 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
864 add_hook(&match_function_assign
, ASSIGNMENT_HOOK
);
865 add_hook(&match_function_assign
, GLOBAL_ASSIGNMENT_HOOK
);
866 add_hook(&global_variable
, BASE_HOOK
);
867 add_hook(&global_variable
, DECLARATION_HOOK
);
868 add_returned_state_callback(match_return_info
);
869 add_returned_state_callback(print_returned_struct_members
);
870 add_hook(&call_return_state_hooks
, RETURN_HOOK
);
871 add_hook(&match_end_func_info
, END_FUNC_HOOK
);
876 add_hook(&match_data_from_db
, FUNC_DEF_HOOK
);
877 add_hook(&match_call_implies
, FUNCTION_CALL_HOOK
);
880 void register_db_call_marker(int id
)
882 add_hook(&match_call_marker
, FUNCTION_CALL_HOOK
);
885 char *get_variable_from_key(struct expression
*arg
, char *key
, struct symbol
**sym
)
890 if (strcmp(key
, "$$") == 0)
891 return expr_to_var_sym(arg
, sym
);
893 if (strcmp(key
, "*$$") == 0) {
894 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&') {
895 arg
= strip_expr(arg
->unop
);
896 return expr_to_var_sym(arg
, sym
);
898 tmp
= expr_to_var_sym(arg
, sym
);
901 snprintf(buf
, sizeof(buf
), "*%s", tmp
);
903 return alloc_string(buf
);
907 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&') {
908 arg
= strip_expr(arg
->unop
);
909 tmp
= expr_to_var_sym(arg
, sym
);
912 snprintf(buf
, sizeof(buf
), "%s.%s", tmp
, key
+ 4);
913 return alloc_string(buf
);
916 tmp
= expr_to_var_sym(arg
, sym
);
919 snprintf(buf
, sizeof(buf
), "%s%s", tmp
, key
+ 2);
921 return alloc_string(buf
);