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: extract debug logging to separate ...



details:   https://anonhg.NetBSD.org/src/rev/6c00961a0865
branches:  trunk
changeset: 1022654:6c00961a0865
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 31 18:16:42 2021 +0000

description:
lint: extract debug logging to separate file

Lint currently has several different kinds of debug log:

* The -DDEBUG log is controlled at compile time.
* The -d command line options enables some other debug logging.
* The -DYYDEBUG log for parsing is controlled at compile time.
* The -y command line option only has an effect in -DYYDEBUG mode.

Extracting the logging into a separate file is a first step towards
unifying these logs and making the code for debug logging stand out less
than the current #ifdef DEBUG.

No functional change.

diffstat:

 usr.bin/xlint/lint1/Makefile   |    4 +-
 usr.bin/xlint/lint1/debug.c    |  144 +++++++++++++++++++++++++++++++++++++++++
 usr.bin/xlint/lint1/externs1.h |   43 ++++++++++-
 usr.bin/xlint/lint1/init.c     |   80 +---------------------
 usr.bin/xlint/lint1/tree.c     |   44 +-----------
 5 files changed, 189 insertions(+), 126 deletions(-)

diffs (truncated from 408 to 300 lines):

diff -r 35befc58c5fb -r 6c00961a0865 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Sat Jul 31 17:09:21 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Sat Jul 31 18:16:42 2021 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.81 2021/07/31 17:09:21 rillig Exp $
+#      $NetBSD: Makefile,v 1.82 2021/07/31 18:16:42 rillig Exp $
 
 .include <bsd.own.mk>
 
 PROG=          lint1
 SRCS=          cgram.y \
-               ckbool.c ckctype.c ckgetopt.c \
+               ckbool.c ckctype.c ckgetopt.c debug.c \
                decl.c emit.c emit1.c err.c func.c init.c inittyp.c lex.c \
                main1.c mem.c mem1.c oper.c scan.l tree.c tyname.c
 
diff -r 35befc58c5fb -r 6c00961a0865 usr.bin/xlint/lint1/debug.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Jul 31 18:16:42 2021 +0000
@@ -0,0 +1,144 @@
+/* $NetBSD: debug.c,v 1.1 2021/07/31 18:16:42 rillig Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roland Illig <rillig%NetBSD.org@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: debug.c,v 1.1 2021/07/31 18:16:42 rillig Exp $");
+#endif
+
+#include "lint1.h"
+
+
+#ifdef DEBUG
+
+static int debug_indentation = 0;
+
+
+void __printflike(1, 2)
+debug_printf(const char *fmt, ...)
+{
+       va_list va;
+
+       va_start(va, fmt);
+       vfprintf(stdout, fmt, va);
+       va_end(va);
+}
+
+void
+debug_indent(void)
+{
+
+       debug_printf("%*s", 2 * debug_indentation, "");
+}
+
+void
+debug_indent_inc(void)
+{
+
+       debug_indentation++;
+}
+
+void
+debug_indent_dec(void)
+{
+
+       debug_indentation--;
+}
+
+void
+(debug_enter)(const char *func)
+{
+
+       printf("%*s+ %s\n", 2 * debug_indentation++, "", func);
+}
+
+void __printflike(1, 2)
+debug_step(const char *fmt, ...)
+{
+       va_list va;
+
+       debug_indent();
+       va_start(va, fmt);
+       vfprintf(stdout, fmt, va);
+       va_end(va);
+       printf("\n");
+}
+
+void
+(debug_leave)(const char *func)
+{
+
+       printf("%*s- %s\n", 2 * --debug_indentation, "", func);
+}
+
+void
+debug_node(const tnode_t *tn, int indent)
+{
+       op_t op;
+
+       if (tn == NULL) {
+               printf("%*s" "null\n", indent, "");
+               return;
+       }
+
+       op = tn->tn_op;
+       printf("%*s%s with type '%s'%s%s",
+           2 * indent, "",
+           op == CVT && !tn->tn_cast ? "convert" : modtab[op].m_name,
+           type_name(tn->tn_type), tn->tn_lvalue ? ", lvalue" : "",
+           tn->tn_parenthesized ? ", parenthesized" : "");
+
+       if (op == NAME)
+               printf(" %s\n", tn->tn_sym->s_name);
+       else if (op == CON && is_floating(tn->tn_type->t_tspec))
+               printf(", value %Lg", tn->tn_val->v_ldbl);
+       else if (op == CON && is_uinteger(tn->tn_type->t_tspec))
+               printf(", value %llu\n", (unsigned long long)tn->tn_val->v_quad);
+       else if (op == CON && is_integer(tn->tn_type->t_tspec))
+               printf(", value %lld\n", (long long)tn->tn_val->v_quad);
+       else if (op == CON)
+               printf(", unknown value\n");
+       else if (op == STRING)
+               printf(", length %zu\n", tn->tn_string->st_len);
+       else {
+               printf("\n");
+
+               debug_node(tn->tn_left, indent + 1);
+               if (modtab[op].m_binary || tn->tn_right != NULL)
+                       debug_node(tn->tn_right, indent + 1);
+       }
+}
+
+#endif
diff -r 35befc58c5fb -r 6c00961a0865 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Jul 31 17:09:21 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Jul 31 18:16:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.123 2021/07/31 17:09:21 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.124 2021/07/31 18:16:42 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -112,6 +112,42 @@
 extern void    expr_restore_memory(struct memory_block *);
 
 /*
+ * debug.c
+ */
+
+#ifdef DEBUG
+void   debug_node(const tnode_t *, int);
+void   debug_printf(const char *fmt, ...) __printflike(1, 2);
+void   debug_indent(void);
+void   debug_indent_inc(void);
+void   debug_indent_dec(void);
+void   debug_enter(const char *);
+void   debug_step(const char *fmt, ...) __printflike(1, 2);
+#define        debug_step0             debug_step
+#define        debug_step1             debug_step
+#define        debug_step2             debug_step
+void   debug_leave(const char *);
+#define        debug_enter()           (debug_enter)(__func__)
+#define        debug_leave()           (debug_leave)(__func__)
+#else
+#define        debug_noop()            do { } while (false)
+#define        debug_node(tn, indent) debug_noop()
+/* ARGSUSED */
+static inline void __printflike(1, 2) debug_printf(const char *fmt, ...) {}
+#define debug_indent()         debug_noop()
+/* ARGSUSED */
+static inline void __printflike(1, 2) debug_step(const char *fmt, ...) {}
+#define        debug_indent()          debug_noop()
+#define        debug_indent_inc()      debug_noop()
+#define        debug_indent_dec()      debug_noop()
+#define        debug_enter()           debug_noop()
+#define        debug_step0(fmt)        debug_noop()
+#define        debug_step1(fmt, arg0)  debug_noop()
+#define        debug_step2(fmt, arg1, arg2) debug_noop()
+#define        debug_leave()           debug_noop()
+#endif
+
+/*
  * err.c
  */
 extern int     nerr;
@@ -235,11 +271,6 @@
 extern bool    constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
 extern strg_t  *cat_strings(strg_t *, strg_t *);
 extern  int64_t type_size_in_bits(const type_t *);
-#ifdef DEBUG
-extern void    debug_node(const tnode_t *, int);
-#else
-#define debug_node(tn, indent) do { } while (false)
-#endif
 
 /*
  * func.c
diff -r 35befc58c5fb -r 6c00961a0865 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sat Jul 31 17:09:21 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Jul 31 18:16:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.205 2021/07/31 18:16:42 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.205 2021/07/31 18:16:42 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -172,74 +172,6 @@
 };
 
 
-#ifdef DEBUG
-static int debug_indentation = 0;
-#endif
-
-
-#ifdef DEBUG
-
-static void __printflike(1, 2)
-debug_printf(const char *fmt, ...)
-{
-       va_list va;
-
-       va_start(va, fmt);
-       vfprintf(stdout, fmt, va);
-       va_end(va);
-}
-
-static void
-debug_indent(void)
-{
-
-       debug_printf("%*s", 2 * debug_indentation, "");
-}
-
-static void
-debug_enter(const char *func)
-{
-
-       printf("%*s+ %s\n", 2 * debug_indentation++, "", func);
-}
-
-static void __printflike(1, 2)
-debug_step(const char *fmt, ...)
-{
-       va_list va;
-
-       debug_indent();
-       va_start(va, fmt);
-       vfprintf(stdout, fmt, va);
-       va_end(va);
-       printf("\n");
-}
-#define debug_step0            debug_step
-#define debug_step1            debug_step
-#define debug_step2            debug_step
-
-static void
-debug_leave(const char *func)
-{
-



Home | Main Index | Thread Index | Old Index