diff options
author | Alexey Gladkov <gladkov.alexey@gmail.com> | 2021-11-02 15:06:43 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-05-21 10:59:45 +0200 |
commit | 2a5afb6eafe9cd781f149ab53ee6ea8f23010ee5 (patch) | |
tree | 1912c23af26d651e38cf34839fe8c45469b09f3d | |
parent | c4706aa764f3ae68258ba60be6325a5662900362 (diff) | |
download | sparse-2a5afb6eafe9cd781f149ab53ee6ea8f23010ee5.tar.gz |
dissect: Allow to show all symbols
Currently dissect sees only used symbols. For indexing purposes, it is
useful to see all declared symbols.
$ nl -s\ -w2 ./z.c
1 struct foo {
2 int member;
3 };
4 #ifdef OPT
5 static void func1(void) {
6 struct foo *x;
7 return 0;
8 }
9 #endif
10 static inline void func2(void) { return; }
11 void func(void) { return; }
$ ./test-dissect ./z.c
FILE: ./z.c
11:6 def f func void ( ... )
$ ./test-dissect --param=dissect-show-all-symbols ./z.c
FILE: ./z.c
1:8 def s foo struct foo
2:13 def m foo.member int
10:20 def f func2 void ( ... )
11:6 def f func void ( ... )
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | dissect.c | 39 | ||||
-rw-r--r-- | options.c | 5 | ||||
-rw-r--r-- | options.h | 2 | ||||
-rw-r--r-- | semind.c | 1 |
4 files changed, 46 insertions, 1 deletions
@@ -652,9 +652,46 @@ static void do_sym_list(struct symbol_list *list) DO_LIST(list, sym, do_symbol(sym)); } +static inline bool valid_namespace(enum namespace ns) +{ + return (ns == NS_STRUCT || ns == NS_SYMBOL); +} + +static void do_file(char *file) +{ + struct symbol_list *res = sparse_keep_tokens(file); + + if (!dissect_show_all_symbols) { + do_sym_list(res); + goto end; + } + + DO_LIST(file_scope->symbols, sym, + if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) { + if (sym->type == SYM_STRUCT || sym->type == SYM_UNION) { + sym->ctype.base_type = sym; + examine_sym_node(sym, NULL); + continue; + } + + do_symbol(sym); + } + ); + + DO_LIST(global_scope->symbols, sym, + if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) { + do_symbol(sym); + } + ); + +end: + /* Drop the tokens for this file after parsing */ + clear_token_alloc(); +} + void dissect(struct reporter *rep, struct string_list *filelist) { reporter = rep; - DO_LIST(filelist, file, do_sym_list(__sparse(file))); + DO_LIST(filelist, file, do_file(file)); } @@ -70,6 +70,8 @@ int dbg_postorder = 0; int dump_macro_defs = 0; int dump_macros_only = 0; +int dissect_show_all_symbols = 0; + unsigned long fdump_ir; int fhosted = 1; unsigned int fmax_errors = 100; @@ -958,6 +960,9 @@ static char **handle_param(char *arg, char **next) if (!value) die("missing argument for --param option"); + if (!strcmp(value, "dissect-show-all-symbols")) + dissect_show_all_symbols = 1; + return next; } @@ -70,6 +70,8 @@ extern int dbg_postorder; extern int dump_macro_defs; extern int dump_macros_only; +extern int dissect_show_all_symbols; + extern unsigned long fdump_ir; extern int fhosted; extern unsigned int fmax_errors; @@ -329,6 +329,7 @@ done: optind--; sparse_initialize(argc - optind, argv + optind, &semind_filelist); + dissect_show_all_symbols = 1; } static void parse_cmdline_rm(int argc, char **argv) |