From: Oleg Nesterov <oleg@redhat.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Alexey Gladkov <gladkov.alexey@gmail.com>, linux-sparse@vger.kernel.org
Subject: [PATCH] dissect: introduce sym_is_local() for reporter
Date: Tue, 11 Feb 2020 17:01:36 +0100 [thread overview]
Message-ID: <20200211160136.GA14027@redhat.com> (raw)
Can be used to filter out the usage of local variables.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 2 +-
dissect.h | 5 +++++
test-dissect.c | 18 ++++++++++++++----
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/dissect.c b/dissect.c
index d9ca142..823a348 100644
--- a/dissect.c
+++ b/dissect.c
@@ -165,7 +165,7 @@ static inline struct symbol *expr_symbol(struct expression *expr)
if (!sym) {
sym = alloc_symbol(expr->pos, SYM_BAD);
bind_symbol(sym, expr->symbol_name, NS_SYMBOL);
- sym->ctype.modifiers = MOD_EXTERN;
+ sym->ctype.modifiers = MOD_EXTERN | MOD_TOPLEVEL;
sym->kind = expr->op ?: 'v'; /* see EXPR_CALL */
}
}
diff --git a/dissect.h b/dissect.h
index efe2c0b..178dba5 100644
--- a/dissect.h
+++ b/dissect.h
@@ -27,6 +27,11 @@ struct reporter
extern struct symbol *dissect_ctx;
+static inline bool sym_is_local(struct symbol *sym)
+{
+ return sym->kind == 'v' && !(sym->ctype.modifiers & MOD_TOPLEVEL);
+}
+
extern void dissect(struct symbol_list *, struct reporter *);
#endif
diff --git a/test-dissect.c b/test-dissect.c
index ece2253..c4b454c 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -37,6 +37,16 @@ static void print_usage(struct position *pos, struct symbol *sym, unsigned mode)
}
+static char symscope(struct symbol *sym)
+{
+ if (sym_is_local(sym)) {
+ if (!dissect_ctx)
+ warning(sym->pos, "no context");
+ return '.';
+ }
+ return ' ';
+}
+
static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
{
print_usage(pos, sym, mode);
@@ -44,8 +54,8 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
if (!sym->ident)
sym->ident = built_in_ident("__asm__");
- printf("%c %-32.*s %s\n",
- sym->kind, sym->ident->len, sym->ident->name,
+ printf("%c %c %-32.*s %s\n",
+ symscope(sym), sym->kind, sym->ident->len, sym->ident->name,
show_typename(sym->ctype.base_type));
switch (sym->kind) {
@@ -80,8 +90,8 @@ static void r_member(unsigned mode, struct position *pos, struct symbol *sym, st
/* mem == NULL means entire struct accessed */
mi = mem ? mem->ident : built_in_ident("*");
- printf("m %.*s.%-*.*s %s\n",
- si->len, si->name,
+ printf("%c m %.*s.%-*.*s %s\n",
+ symscope(sym), si->len, si->name,
32-1 - si->len, mi->len, mi->name,
show_typename(mem ? mem->ctype.base_type : sym));
--
2.5.0
next reply other threads:[~2020-02-11 16:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 16:01 Oleg Nesterov [this message]
2020-02-12 0:41 ` [PATCH] dissect: introduce sym_is_local() for reporter Luc Van Oostenryck
2020-02-12 9:06 ` Oleg Nesterov
2020-02-13 17:41 ` Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200211160136.GA14027@redhat.com \
--to=oleg@redhat.com \
--cc=gladkov.alexey@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox