aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexey Gladkov <gladkov.alexey@gmail.com>2021-11-02 15:06:44 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2022-05-21 10:59:45 +0200
commit99fe3982ff45fc0bef5e5e414b85f87143e71ce5 (patch)
tree74d6d4ee443f368620fd22383205358831953690
parent2a5afb6eafe9cd781f149ab53ee6ea8f23010ee5 (diff)
downloadsparse-99fe3982ff45fc0bef5e5e414b85f87143e71ce5.tar.gz
dissect: Show macro definitions
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> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--dissect.c13
-rw-r--r--test-dissect.c3
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;