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 hierarchical debug logging for...
details: https://anonhg.NetBSD.org/src/rev/8ad161e8d643
branches: trunk
changeset: 980840:8ad161e8d643
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Feb 20 15:23:07 2021 +0000
description:
lint: add hierarchical debug logging for initializations
No functional change for default mode.
diffstat:
usr.bin/xlint/lint1/init.c | 220 +++++++++++++++++++++++++++++++-------------
1 files changed, 154 insertions(+), 66 deletions(-)
diffs (truncated from 576 to 300 lines):
diff -r b099df0ee8e3 -r 8ad161e8d643 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sat Feb 20 14:51:06 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sat Feb 20 15:23:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.67 2021/02/19 22:16:12 rillig Exp $ */
+/* $NetBSD: init.c,v 1.68 2021/02/20 15:23:07 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.67 2021/02/19 22:16:12 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.68 2021/02/20 15:23:07 rillig Exp $");
#endif
#include <stdlib.h>
@@ -113,9 +113,57 @@
static bool initstack_string(tnode_t *);
#ifndef DEBUG
-#define DPRINTF(a)
+#define debug_printf(fmt, ...) (void)0
+#define debug_indent() (void)0
+#define debug_enter(a) (void)0
+#define debug_step(fmt, ...) (void)0
+#define debug_leave(a) (void)0
#else
-#define DPRINTF(a) printf a
+static int debug_ind = 0;
+
+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_ind, "");
+}
+
+static void
+debug_enter(const char *func)
+{
+ printf("%*s+ %s\n", 2 * debug_ind++, "", func);
+}
+
+static void __printflike(1, 2)
+debug_step(const char *fmt, ...)
+{
+ va_list va;
+
+ printf("%*s", 2 * debug_ind, "");
+ va_start(va, fmt);
+ vfprintf(stdout, fmt, va);
+ va_end(va);
+ printf("\n");
+}
+
+static void
+debug_leave(const char *func)
+{
+ printf("%*s- %s\n", 2 * --debug_ind, "", func);
+}
+
+#define debug_enter() debug_enter(__func__)
+#define debug_leave() debug_leave(__func__)
+
#endif
void
@@ -123,7 +171,7 @@
{
namlist_t *nam = xcalloc(1, sizeof (namlist_t));
nam->n_name = sb->sb_name;
- DPRINTF(("%s: %s %p\n", __func__, nam->n_name, nam));
+ debug_step("%s: %s %p", __func__, nam->n_name, nam);
if (namedmem == NULL) {
/*
* XXX: Why is this a circular list?
@@ -143,7 +191,7 @@
static void
pop_member(void)
{
- DPRINTF(("%s: %s %p\n", __func__, namedmem->n_name, namedmem));
+ debug_step("%s: %s %p", __func__, namedmem->n_name, namedmem);
if (namedmem->n_next == namedmem) {
free(namedmem);
namedmem = NULL;
@@ -157,19 +205,20 @@
}
static void
-named_member_dprint(void)
+debug_named_member(void)
{
namlist_t *name;
if (namedmem == NULL)
return;
name = namedmem;
- DPRINTF(("named member:"));
+ debug_indent();
+ debug_printf("named member:");
do {
- DPRINTF((" %s", name->n_name));
+ debug_printf(" %s", name->n_name);
name = name->n_next;
} while (name != namedmem);
- DPRINTF(("\n"));
+ debug_printf("\n");
}
/*
@@ -190,7 +239,7 @@
free(istk);
}
- DPRINTF(("%s\n", __func__));
+ debug_step("%s", __func__);
/*
* If the type which is to be initialized is an incomplete type,
@@ -210,50 +259,54 @@
istk_t *istk;
sym_t *m;
+ debug_enter();
+
istk = initstk;
- DPRINTF(("%s: pop type=%s, brace=%d remaining=%d named=%d\n", __func__,
+ debug_step("pop type=%s, brace=%d remaining=%d named=%d",
type_name(istk->i_type ? istk->i_type : istk->i_subt),
- istk->i_brace, istk->i_remaining, istk->i_namedmem));
+ istk->i_brace, istk->i_remaining, istk->i_namedmem);
initstk = istk->i_next;
free(istk);
istk = initstk;
lint_assert(istk != NULL);
- DPRINTF(("%s: top type=%s, brace=%d remaining=%d named=%d\n", __func__,
+ debug_step("top type=%s, brace=%d remaining=%d named=%d",
type_name(istk->i_type ? istk->i_type : istk->i_subt),
- istk->i_brace, istk->i_remaining, istk->i_namedmem));
+ istk->i_brace, istk->i_remaining, istk->i_namedmem);
istk->i_remaining--;
lint_assert(istk->i_remaining >= 0);
- DPRINTF(("%s: top remaining=%d rhs.name=%s\n", __func__,
- istk->i_remaining, namedmem ? namedmem->n_name : "*null*"));
+ debug_step("top remaining=%d rhs.name=%s",
+ istk->i_remaining, namedmem ? namedmem->n_name : "*null*");
if (istk->i_remaining >= 0 && namedmem != NULL) {
- DPRINTF(("%s: named remaining=%d type=%s, rhs.name=%s\n",
- __func__, istk->i_remaining,
- type_name(istk->i_type), namedmem->n_name));
+ debug_step("named remaining=%d type=%s, rhs.name=%s",
+ istk->i_remaining, type_name(istk->i_type),
+ namedmem->n_name);
for (m = istk->i_type->t_str->sou_first_member;
m != NULL; m = m->s_next) {
- DPRINTF(("%s: pop lhs.name=%s rhs.name=%s\n", __func__,
- m->s_name, namedmem->n_name));
+ debug_step("pop lhs.name=%s rhs.name=%s",
+ m->s_name, namedmem->n_name);
if (m->s_bitfield && m->s_name == unnamed)
continue;
if (strcmp(m->s_name, namedmem->n_name) == 0) {
istk->i_subt = m->s_type;
istk->i_remaining++;
pop_member();
+ debug_leave();
return;
}
}
/* undefined struct/union member: %s */
error(101, namedmem->n_name);
- DPRINTF(("%s: end rhs.name=%s\n", __func__, namedmem->n_name));
+ debug_step("end rhs.name=%s", namedmem->n_name);
pop_member();
istk->i_namedmem = true;
+ debug_leave();
return;
}
/*
@@ -265,10 +318,11 @@
do {
m = istk->i_mem = istk->i_mem->s_next;
lint_assert(m != NULL);
- DPRINTF(("%s: pop %s\n", __func__, m->s_name));
+ debug_step("pop %s", m->s_name);
} while (m->s_bitfield && m->s_name == unnamed);
istk->i_subt = m->s_type;
}
+ debug_leave();
}
/*
@@ -280,13 +334,13 @@
{
bool brace;
- DPRINTF(("%s\n", __func__));
+ debug_enter();
do {
brace = initstk->i_brace;
- DPRINTF(("%s: loop brace=%d\n", __func__, brace));
+ debug_step("loop brace=%d", brace);
initstack_pop_item();
} while (!brace);
- DPRINTF(("%s: done\n", __func__));
+ debug_leave();
}
/*
@@ -297,11 +351,11 @@
initstack_pop_nobrace(void)
{
- DPRINTF(("%s\n", __func__));
+ debug_enter();
while (!initstk->i_brace && initstk->i_remaining == 0 &&
!initstk->i_nolimit)
initstack_pop_item();
- DPRINTF(("%s: done\n", __func__));
+ debug_leave();
}
static void
@@ -311,11 +365,13 @@
int cnt;
sym_t *m;
+ debug_enter();
+
istk = initstk;
/* Extend an incomplete array type by one element */
if (istk->i_remaining == 0) {
- DPRINTF(("%s(extend) %s\n", __func__, type_name(istk->i_type)));
+ debug_step("(extend) %s", type_name(istk->i_type));
/*
* Inside of other aggregate types must not be an incomplete
* type.
@@ -338,17 +394,17 @@
again:
istk = initstk;
- DPRINTF(("%s(%s)\n", __func__, type_name(istk->i_type)));
+ debug_step("typename %s", type_name(istk->i_type));
switch (istk->i_type->t_tspec) {
case ARRAY:
if (namedmem != NULL) {
- DPRINTF(("%s: ARRAY %s brace=%d\n", __func__,
- namedmem->n_name, istk->i_brace));
+ debug_step("ARRAY %s brace=%d",
+ namedmem->n_name, istk->i_brace);
goto pop;
} else if (istk->i_next->i_namedmem) {
istk->i_brace = true;
- DPRINTF(("%s ARRAY brace=%d, namedmem=%d\n", __func__,
- istk->i_brace, istk->i_next->i_namedmem));
+ debug_step("ARRAY brace=%d, namedmem=%d",
+ istk->i_brace, istk->i_next->i_namedmem);
}
if (is_incomplete(istk->i_type) &&
@@ -356,14 +412,15 @@
/* initialisation of an incomplete type */
error(175);
initerr = true;
+ debug_leave();
return;
}
istk->i_subt = istk->i_type->t_subt;
istk->i_nolimit = is_incomplete(istk->i_type);
istk->i_remaining = istk->i_type->t_dim;
- DPRINTF(("%s: elements array %s[%d] %s\n", __func__,
+ debug_step("elements array %s[%d] %s",
type_name(istk->i_subt), istk->i_remaining,
- namedmem ? namedmem->n_name : "*none*"));
+ namedmem ? namedmem->n_name : "*none*");
break;
case UNION:
if (tflag)
@@ -375,19 +432,20 @@
/* initialisation of an incomplete type */
error(175);
Home |
Main Index |
Thread Index |
Old Index