Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: add debug logging for the declarat...



details:   https://anonhg.NetBSD.org/src/rev/4dcf8392705b
branches:  trunk
changeset: 364640:4dcf8392705b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 02 12:24:54 2022 +0000

description:
lint: add debug logging for the declaration stack

To track down the wrong edge cases in decl_direct_abstract.c.

diffstat:

 usr.bin/xlint/lint1/debug.c    |  88 ++++++++++++++++++++++++++++++++++++++---
 usr.bin/xlint/lint1/decl.c     |  20 ++++++++-
 usr.bin/xlint/lint1/externs1.h |   8 ++-
 usr.bin/xlint/lint1/lex.c      |   6 +-
 usr.bin/xlint/lint1/tree.c     |   5 +-
 5 files changed, 109 insertions(+), 18 deletions(-)

diffs (292 lines):

diff -r 367ef4e99fdc -r 4dcf8392705b usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Apr 02 11:16:06 2022 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Apr 02 12:24:54 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.9 2022/03/01 00:17:12 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.10 2022/04/02 12:24:54 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.9 2022/03/01 00:17:12 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.10 2022/04/02 12:24:54 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -55,7 +55,7 @@
        va_list va;
 
        va_start(va, fmt);
-       vfprintf(stdout, fmt, va);
+       (void)vfprintf(stdout, fmt, va);
        va_end(va);
 }
 
@@ -94,7 +94,7 @@
 
        debug_print_indent();
        va_start(va, fmt);
-       vfprintf(stdout, fmt, va);
+       (void)vfprintf(stdout, fmt, va);
        va_end(va);
        printf("\n");
 }
@@ -107,7 +107,7 @@
 }
 
 void
-debug_node(const tnode_t *tn)
+debug_node(const tnode_t *tn) // NOLINT(misc-no-recursion)
 {
        op_t op;
 
@@ -236,11 +236,11 @@
 }
 
 void
-debug_sym(const sym_t *sym)
+debug_sym(const char *prefix, const sym_t *sym, const char *suffix)
 {
 
        debug_print_indent();
-       debug_printf("%s", sym->s_name);
+       debug_printf("%s%s", prefix, sym->s_name);
        if (sym->s_type != NULL)
                debug_printf(" type='%s'", type_name(sym->s_type));
        if (sym->s_rename != NULL)
@@ -294,7 +294,79 @@
 
        debug_word(sym->s_osdef && sym->s_args != NULL, "old-style-args");
 
-       debug_printf("\n");
+       debug_printf("%s", suffix);
 }
 
+void
+debug_dinfo(const dinfo_t *d) // NOLINT(misc-no-recursion)
+{
+
+       debug_print_indent();
+       debug_printf("dinfo: %s", scl_name(d->d_ctx));
+       if (d->d_scl != NOSCL)
+               debug_printf(" %s", scl_name(d->d_scl));
+       if (d->d_type != NULL) {
+               debug_printf(" '%s'", type_name(d->d_type));
+       } else {
+               if (d->d_abstract_type != NOTSPEC)
+                       debug_printf(" %s", tspec_name(d->d_abstract_type));
+               if (d->d_complex_mod != NOTSPEC)
+                       debug_printf(" %s", tspec_name(d->d_complex_mod));
+               if (d->d_sign_mod != NOTSPEC)
+                       debug_printf(" %s", tspec_name(d->d_sign_mod));
+               if (d->d_rank_mod != NOTSPEC)
+                       debug_printf(" %s", tspec_name(d->d_rank_mod));
+       }
+       if (d->d_redeclared_symbol != NULL)
+               debug_sym(" redeclared=(", d->d_redeclared_symbol, ")");
+       if (d->d_offset != 0)
+               debug_printf(" offset=%u", d->d_offset);
+       if (d->d_sou_align_in_bits != 0)
+               debug_printf(" align=%u", (unsigned)d->d_sou_align_in_bits);
+
+       if (d->d_const)
+               debug_printf(" const");
+       if (d->d_volatile)
+               debug_printf(" volatile");
+       if (d->d_inline)
+               debug_printf(" inline");
+       if (d->d_multiple_storage_classes)
+               debug_printf(" multiple_storage_classes");
+       if (d->d_invalid_type_combination)
+               debug_printf(" invalid_type_combination");
+       if (d->d_nonempty_decl)
+               debug_printf(" nonempty_decl");
+       if (d->d_vararg)
+               debug_printf(" vararg");
+       if (d->d_proto)
+               debug_printf(" prototype");
+       if (d->d_notyp)
+               debug_printf(" no_type_specifier");
+       if (d->d_asm)
+               debug_printf(" asm");
+       if (d->d_packed)
+               debug_printf(" packed");
+       if (d->d_used)
+               debug_printf(" used");
+
+       if (d->d_tagtyp != NULL)
+               debug_printf(" tagtyp='%s'", type_name(d->d_tagtyp));
+       for (const sym_t *arg = d->d_func_args;
+            arg != NULL; arg = arg->s_next)
+               debug_sym(" arg(", arg, ")");
+       if (d->d_func_def_pos.p_file != NULL)
+               debug_printf(" func_def_pos=%s:%d:%d",
+                   d->d_func_def_pos.p_file, d->d_func_def_pos.p_line,
+                   d->d_func_def_pos.p_uniq);
+       for (const sym_t *sym = d->d_func_proto_syms;
+            sym != NULL; sym = sym->s_next)
+               debug_sym("func_proto_sym(", sym, ")");
+       debug_printf("\n");
+
+       if (d->d_next != NULL) {
+               debug_indent_inc();
+               debug_dinfo(d->d_next);
+               debug_indent_dec();
+       }
+}
 #endif
diff -r 367ef4e99fdc -r 4dcf8392705b usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 02 11:16:06 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 02 12:24:54 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.258 2022/04/02 12:24:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.258 2022/04/02 12:24:54 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1303,6 +1303,8 @@
        type_t **tpp, *tp;
        qual_ptr *next;
 
+       debug_dinfo(dcs);
+
        tpp = &decl->s_type;
        while (*tpp != NULL && *tpp != dcs->d_type)
                tpp = &(*tpp)->t_subt;
@@ -1335,6 +1337,8 @@
 {
        type_t  **tpp, *tp;
 
+       debug_dinfo(dcs);
+
        tpp = &decl->s_type;
        while (*tpp != NULL && *tpp != dcs->d_type)
                tpp = &(*tpp)->t_subt;
@@ -1369,6 +1373,14 @@
 {
        type_t  **tpp, *tp;
 
+       debug_enter();
+       debug_dinfo(dcs);
+       debug_sym("decl: ", decl, "\n");
+#ifdef DEBUG
+       for (const sym_t *arg = args; arg != NULL; arg = arg->s_next)
+               debug_sym("arg: ", arg, "\n");
+#endif
+
        if (dcs->d_proto) {
                if (tflag)
                        /* function prototypes are illegal in traditional C */
@@ -1410,6 +1422,7 @@
        if (*tpp == NULL) {
                debug_step("add_function: unchanged '%s'",
                    type_name(decl->s_type));
+               debug_leave();
                return decl;    /* see msg_347 */
        }
 
@@ -1420,7 +1433,8 @@
                tp->t_args = args;
        tp->t_vararg = dcs->d_vararg;
 
-       debug_step("add_function: '%s'", type_name(decl->s_type));
+       debug_step("add_function: '%s'", type_name(tp));
+       debug_leave();
        return decl;
 }
 
diff -r 367ef4e99fdc -r 4dcf8392705b usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Apr 02 11:16:06 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Apr 02 12:24:54 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.150 2022/03/13 14:40:36 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.151 2022/04/02 12:24:55 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -118,8 +118,9 @@
 const char *scl_name(scl_t);
 const char *symt_name(symt_t);
 const char *tqual_name(tqual_t);
+void   debug_dinfo(const dinfo_t *);
 void   debug_node(const tnode_t *);
-void   debug_sym(const sym_t *);
+void   debug_sym(const char *, const sym_t *, const char *);
 void   debug_symtab(void);
 void   debug_printf(const char *fmt, ...) __printflike(1, 2);
 void   debug_print_indent(void);
@@ -132,6 +133,9 @@
 #define        debug_leave()           (debug_leave)(__func__)
 #else
 #define        debug_noop()            do { } while (false)
+#define        debug_dinfo(d)          debug_noop()
+#define        debug_sym(p, sym, s)    debug_noop()
+#define        debug_symtab()          debug_noop()
 #define        debug_node(tn)          debug_noop()
 #define        debug_printf(...)       debug_noop()
 #define        debug_print_indent()    debug_noop()
diff -r 367ef4e99fdc -r 4dcf8392705b usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Apr 02 11:16:06 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Apr 02 12:24:54 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.113 2022/03/13 15:20:50 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.114 2022/04/02 12:24:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.113 2022/03/13 15:20:50 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.114 2022/04/02 12:24:55 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -361,7 +361,7 @@
                        qsort(syms.items, syms.len, sizeof(syms.items[0]),
                            sym_by_name);
                        for (size_t i = 0; i < syms.len; i++)
-                               debug_sym(syms.items[i]);
+                               debug_sym("", syms.items[i], "\n");
                        debug_indent_dec();
 
                        lint_assert(level != -1);
diff -r 367ef4e99fdc -r 4dcf8392705b usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Apr 02 11:16:06 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Apr 02 12:24:54 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.414 2022/04/01 23:16:32 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.415 2022/04/02 12:24:55 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.414 2022/04/01 23:16:32 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.415 2022/04/02 12:24:55 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3441,6 +3441,7 @@
        unsigned int size_in_bytes = type_size_in_bits(tp) / CHAR_SIZE;
        tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, size_in_bytes);
        tn->tn_system_dependent = true;
+       debug_step("build_sizeof '%s' = %u", type_name(tp), size_in_bytes);
        return tn;
 }
 



Home | Main Index | Thread Index | Old Index