All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] semind: Index more symbols
@ 2021-11-02 14:06 Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 1/3] dissect: Allow to show all symbols Alexey Gladkov
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Alexey Gladkov @ 2021-11-02 14:06 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov, Alexey Gladkov

Greetings!

For indexing purposes, macros definitions and typedefs are added to the
semind database. Functions that are not used in the code are also indexed.

Alexey Gladkov (3):
  dissect: Allow to show all symbols
  dissect: Show macro definitions
  dissect: Show typedefs

 dissect.c      | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
 options.c      |  5 +++++
 options.h      |  2 ++
 semind.c       |  1 +
 test-dissect.c |  5 ++++-
 5 files changed, 72 insertions(+), 2 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] dissect: Allow to show all symbols
  2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
@ 2021-11-02 14:06 ` Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 2/3] dissect: Show macro definitions Alexey Gladkov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Alexey Gladkov @ 2021-11-02 14:06 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov, Alexey Gladkov

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>
---
 dissect.c | 39 ++++++++++++++++++++++++++++++++++++++-
 options.c |  5 +++++
 options.h |  2 ++
 semind.c  |  1 +
 4 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/dissect.c b/dissect.c
index 582e8fc3..0d6c3288 100644
--- a/dissect.c
+++ b/dissect.c
@@ -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));
 }
diff --git a/options.c b/options.c
index 6704fc8d..b4684357 100644
--- a/options.c
+++ b/options.c
@@ -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;
 }
 
diff --git a/options.h b/options.h
index 0aec8764..c2a9551a 100644
--- a/options.h
+++ b/options.h
@@ -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;
diff --git a/semind.c b/semind.c
index 911fc747..ad8003ba 100644
--- a/semind.c
+++ b/semind.c
@@ -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)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] dissect: Show macro definitions
  2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 1/3] dissect: Allow to show all symbols Alexey Gladkov
@ 2021-11-02 14:06 ` Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 3/3] dissect: Show typedefs Alexey Gladkov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Alexey Gladkov @ 2021-11-02 14:06 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov, Alexey Gladkov

Add the ability to dissect to see macro definitions. The patch does not
add full support for the usage of macros, but only their definitions.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 dissect.c      | 13 ++++++++++++-
 test-dissect.c |  3 ++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/dissect.c b/dissect.c
index 0d6c3288..7d5d92c9 100644
--- a/dissect.c
+++ b/dissect.c
@@ -610,6 +610,11 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp
 	return type;
 }
 
+static inline bool is_macro(struct symbol *sym)
+{
+	return (sym->namespace == NS_MACRO || sym->namespace == NS_UNDEF);
+}
+
 static inline struct symbol *do_symbol(struct symbol *sym)
 {
 	struct symbol *type = base_type(sym);
@@ -654,7 +659,7 @@ static void do_sym_list(struct symbol_list *list)
 
 static inline bool valid_namespace(enum namespace ns)
 {
-	return (ns == NS_STRUCT || ns == NS_SYMBOL);
+	return (ns == NS_MACRO || ns == NS_UNDEF || ns == NS_STRUCT || ns == NS_SYMBOL);
 }
 
 static void do_file(char *file)
@@ -668,6 +673,12 @@ static void do_file(char *file)
 
 	DO_LIST(file_scope->symbols, sym,
 		if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) {
+			if (is_macro(sym)) {
+				sym->kind = 'd';
+				reporter->r_symdef(sym);
+				continue;
+			}
+
 			if (sym->type == SYM_STRUCT || sym->type == SYM_UNION) {
 				sym->ctype.base_type = sym;
 				examine_sym_node(sym, NULL);
diff --git a/test-dissect.c b/test-dissect.c
index 58b3e633..3d870a97 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -57,11 +57,12 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
 		show_typename(sym->ctype.base_type));
 
 	switch (sym->kind) {
+	case 'd':
+		break;
 	case 's':
 		if (sym->type == SYM_STRUCT || sym->type == SYM_UNION)
 			break;
 		goto err;
-
 	case 'f':
 		if (sym->type != SYM_BAD && sym->ctype.base_type->type != SYM_FN)
 			goto err;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] dissect: Show typedefs
  2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 1/3] dissect: Allow to show all symbols Alexey Gladkov
  2021-11-02 14:06 ` [PATCH 2/3] dissect: Show macro definitions Alexey Gladkov
@ 2021-11-02 14:06 ` Alexey Gladkov
  2021-12-14 15:16 ` [PATCH 0/3] semind: Index more symbols Alexey Gladkov
  2022-05-21  9:46 ` Luc Van Oostenryck
  4 siblings, 0 replies; 7+ messages in thread
From: Alexey Gladkov @ 2021-11-02 14:06 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov, Alexey Gladkov

For indexing purposes, it is useful to see type definitions.

$ semind search __kernel_ulong_t
(def) include/uapi/asm-generic/posix_types.h 16 23 typedef unsigned long   __kernel_ulong_t;

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 dissect.c      | 13 ++++++++++++-
 test-dissect.c |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/dissect.c b/dissect.c
index 7d5d92c9..300d5ca9 100644
--- a/dissect.c
+++ b/dissect.c
@@ -615,6 +615,11 @@ static inline bool is_macro(struct symbol *sym)
 	return (sym->namespace == NS_MACRO || sym->namespace == NS_UNDEF);
 }
 
+static inline bool is_typedef(struct symbol *sym)
+{
+	return (sym->namespace == NS_TYPEDEF);
+}
+
 static inline struct symbol *do_symbol(struct symbol *sym)
 {
 	struct symbol *type = base_type(sym);
@@ -659,7 +664,7 @@ static void do_sym_list(struct symbol_list *list)
 
 static inline bool valid_namespace(enum namespace ns)
 {
-	return (ns == NS_MACRO || ns == NS_UNDEF || ns == NS_STRUCT || ns == NS_SYMBOL);
+	return (ns == NS_TYPEDEF || ns == NS_MACRO || ns == NS_UNDEF || ns == NS_STRUCT || ns == NS_SYMBOL);
 }
 
 static void do_file(char *file)
@@ -673,6 +678,12 @@ static void do_file(char *file)
 
 	DO_LIST(file_scope->symbols, sym,
 		if (input_streams[sym->pos.stream].fd != -1 && valid_namespace(sym->namespace)) {
+			if (is_typedef(sym)) {
+				sym->kind = 't';
+				reporter->r_symdef(sym);
+				continue;
+			}
+
 			if (is_macro(sym)) {
 				sym->kind = 'd';
 				reporter->r_symdef(sym);
diff --git a/test-dissect.c b/test-dissect.c
index 3d870a97..65b205f8 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -63,6 +63,8 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
 		if (sym->type == SYM_STRUCT || sym->type == SYM_UNION)
 			break;
 		goto err;
+	case 't':
+		break;
 	case 'f':
 		if (sym->type != SYM_BAD && sym->ctype.base_type->type != SYM_FN)
 			goto err;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] semind: Index more symbols
  2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
                   ` (2 preceding siblings ...)
  2021-11-02 14:06 ` [PATCH 3/3] dissect: Show typedefs Alexey Gladkov
@ 2021-12-14 15:16 ` Alexey Gladkov
  2022-05-21  9:46 ` Luc Van Oostenryck
  4 siblings, 0 replies; 7+ messages in thread
From: Alexey Gladkov @ 2021-12-14 15:16 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov

On Tue, Nov 02, 2021 at 03:06:42PM +0100, Alexey Gladkov wrote:
> Greetings!
> 
> For indexing purposes, macros definitions and typedefs are added to the
> semind database. Functions that are not used in the code are also indexed.

careful ping.

> Alexey Gladkov (3):
>   dissect: Allow to show all symbols
>   dissect: Show macro definitions
>   dissect: Show typedefs
> 
>  dissect.c      | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  options.c      |  5 +++++
>  options.h      |  2 ++
>  semind.c       |  1 +
>  test-dissect.c |  5 ++++-
>  5 files changed, 72 insertions(+), 2 deletions(-)
> 
> -- 
> 2.33.0
> 

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] semind: Index more symbols
  2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
                   ` (3 preceding siblings ...)
  2021-12-14 15:16 ` [PATCH 0/3] semind: Index more symbols Alexey Gladkov
@ 2022-05-21  9:46 ` Luc Van Oostenryck
  2022-05-23 12:45   ` Alexey Gladkov
  4 siblings, 1 reply; 7+ messages in thread
From: Luc Van Oostenryck @ 2022-05-21  9:46 UTC (permalink / raw)
  To: Alexey Gladkov; +Cc: linux-sparse, Oleg Nesterov

On Tue, Nov 02, 2021 at 03:06:42PM +0100, Alexey Gladkov wrote:
> Greetings!
> 
> For indexing purposes, macros definitions and typedefs are added to the
> semind database. Functions that are not used in the code are also indexed.

Thank you very much, pushed now, an ... apologies for this huge delay.

-- Luc

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] semind: Index more symbols
  2022-05-21  9:46 ` Luc Van Oostenryck
@ 2022-05-23 12:45   ` Alexey Gladkov
  0 siblings, 0 replies; 7+ messages in thread
From: Alexey Gladkov @ 2022-05-23 12:45 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: linux-sparse, Oleg Nesterov

On Sat, May 21, 2022 at 11:46:22AM +0200, Luc Van Oostenryck wrote:
> On Tue, Nov 02, 2021 at 03:06:42PM +0100, Alexey Gladkov wrote:
> > Greetings!
> > 
> > For indexing purposes, macros definitions and typedefs are added to the
> > semind database. Functions that are not used in the code are also indexed.
> 
> Thank you very much, pushed now, an ... apologies for this huge delay.

Looks like I'm the only one using this indexer at work. But in case anyone
is interested, I have a vim plugin for semind [1].

[1] https://github.com/legionus/vim-semind

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-23 12:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 14:06 [PATCH 0/3] semind: Index more symbols Alexey Gladkov
2021-11-02 14:06 ` [PATCH 1/3] dissect: Allow to show all symbols Alexey Gladkov
2021-11-02 14:06 ` [PATCH 2/3] dissect: Show macro definitions Alexey Gladkov
2021-11-02 14:06 ` [PATCH 3/3] dissect: Show typedefs Alexey Gladkov
2021-12-14 15:16 ` [PATCH 0/3] semind: Index more symbols Alexey Gladkov
2022-05-21  9:46 ` Luc Van Oostenryck
2022-05-23 12:45   ` Alexey Gladkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.