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 memory manag...
details: https://anonhg.NetBSD.org/src/rev/e66e7dfc0a2f
branches: trunk
changeset: 377508:e66e7dfc0a2f
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 15 09:40:36 2023 +0000
description:
lint: add debug logging for memory management and the symbol table
diffstat:
tests/usr.bin/xlint/lint1/d_lint_assert.c | 22 +++++++++++++++++++++-
usr.bin/xlint/lint1/cgram.y | 8 ++++++--
usr.bin/xlint/lint1/decl.c | 7 ++++---
usr.bin/xlint/lint1/lex.c | 25 ++++++++++++++++---------
usr.bin/xlint/lint1/mem1.c | 6 ++++--
5 files changed, 51 insertions(+), 17 deletions(-)
diffs (232 lines):
diff -r fb94bfd5c58b -r e66e7dfc0a2f tests/usr.bin/xlint/lint1/d_lint_assert.c
--- a/tests/usr.bin/xlint/lint1/d_lint_assert.c Sat Jul 15 09:22:44 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_lint_assert.c Sat Jul 15 09:40:36 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_lint_assert.c,v 1.7 2023/03/28 14:44:34 rillig Exp $ */
+/* $NetBSD: d_lint_assert.c,v 1.8 2023/07/15 09:40:37 rillig Exp $ */
# 3 "d_lint_assert.c"
/*
@@ -23,3 +23,23 @@ enum {
*/
/* expect+1: warning: old-style declaration; add 'int' [1] */
c(void());
+
+
+// As of 2023-07-15, the following code leads to a crash, due to the word
+// 'unknown_type_modifier'. The parser then goes into error recovery mode and
+// discards the declaration in the 'for' loop. In the end, the symbol table
+// still contains symbols that were already freed when parsing the '}' from the
+// 'switch' statement. To reproduce the crash, run 'make -DDEBUG DBG="-O0 -g"'
+// and run with -Sy.
+//
+// static inline void
+// f(void)
+// {
+// int i = 3;
+//
+// for (unknown_type_modifier char *p = "";; ) {
+// switch (i) {
+// case 3:;
+// }
+// }
+// }
diff -r fb94bfd5c58b -r e66e7dfc0a2f usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Jul 15 09:22:44 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Jul 15 09:40:36 2023 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.461 2023/07/13 23:11:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.462 2023/07/15 09:40:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.461 2023/07/13 23:11:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.462 2023/07/15 09:40:36 rillig Exp $");
#endif
#include <limits.h>
@@ -1782,6 +1782,8 @@ compound_statement_lbrace:
T_LBRACE {
block_level++;
mem_block_level++;
+ debug_step("%s: mem_block_level = %zu",
+ "compound_statement_lbrace", mem_block_level);
begin_declaration_level(DLK_AUTO);
}
;
@@ -1791,6 +1793,8 @@ compound_statement_rbrace:
end_declaration_level();
level_free_all(mem_block_level);
mem_block_level--;
+ debug_step("%s: mem_block_level = %zu",
+ "compound_statement_rbrace", mem_block_level);
block_level--;
suppress_fallthrough = false;
}
diff -r fb94bfd5c58b -r e66e7dfc0a2f usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sat Jul 15 09:22:44 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sat Jul 15 09:40:36 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.356 2023/07/14 09:20:23 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.357 2023/07/15 09:40:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.356 2023/07/14 09:20:23 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.357 2023/07/15 09:40:36 rillig Exp $");
#endif
#include <sys/param.h>
@@ -521,7 +521,6 @@ end_declaration_level(void)
{
debug_dcs(true);
- debug_leave();
decl_level *dl = dcs;
dcs = dl->d_enclosing;
@@ -578,6 +577,7 @@ end_declaration_level(void)
lint_assert(/*CONSTCOND*/false);
}
free(dl);
+ debug_leave();
}
/*
@@ -2789,6 +2789,7 @@ global_clean_up(void)
clean_up_after_error();
block_level = 0;
mem_block_level = 0;
+ debug_step("%s: mem_block_level = %zu", __func__, mem_block_level);
global_clean_up_decl(true);
}
diff -r fb94bfd5c58b -r e66e7dfc0a2f usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Jul 15 09:22:44 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jul 15 09:40:36 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.186 2023/07/14 09:32:42 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.187 2023/07/15 09:40:36 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.186 2023/07/14 09:32:42 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.187 2023/07/15 09:40:36 rillig Exp $");
#endif
#include <ctype.h>
@@ -306,6 +306,7 @@ debug_symtab(void)
{
struct syms syms = { xcalloc(64, sizeof(syms.items[0])), 0, 64 };
+ debug_enter();
for (int level = -1;; level++) {
bool more = false;
size_t n = sizeof(symtab) / sizeof(symtab[0]);
@@ -323,7 +324,7 @@ debug_symtab(void)
}
if (syms.len > 0) {
- debug_printf("symbol table level %d\n", level);
+ debug_step("symbol table level %d", level);
debug_indent_inc();
qsort(syms.items, syms.len, sizeof(syms.items[0]),
sym_by_name);
@@ -337,6 +338,7 @@ debug_symtab(void)
if (!more)
break;
}
+ debug_leave();
free(syms.items);
}
@@ -1278,7 +1280,7 @@ lex_next_line(void)
{
curr_pos.p_line++;
curr_pos.p_uniq = 0;
- debug_step("parsing %s:%d", curr_pos.p_file, curr_pos.p_line);
+ debug_printf("parsing %s:%d\n", curr_pos.p_file, curr_pos.p_line);
if (curr_pos.p_file == csrc_pos.p_file) {
csrc_pos.p_line++;
csrc_pos.p_uniq = 0;
@@ -1423,12 +1425,16 @@ void
symtab_remove_level(sym_t *syms)
{
+ if (syms != NULL)
+ debug_step("%s %d", __func__, syms->s_block_level);
+
/* Note the use of s_level_next instead of s_symtab_next. */
for (sym_t *sym = syms; sym != NULL; sym = sym->s_level_next) {
if (sym->s_block_level != -1) {
- debug_step("symtab_remove_level '%s' %s '%s'",
+ debug_step("%s '%s' %s '%s' %d", __func__,
sym->s_name, symt_name(sym->s_kind),
- type_name(sym->s_type));
+ type_name(sym->s_type),
+ sym->s_block_level);
symtab_remove(sym);
sym->s_symtab_ref = NULL;
}
@@ -1440,10 +1446,11 @@ void
inssym(int level, sym_t *sym)
{
- debug_step("inssym '%s' %s '%s'",
- sym->s_name, symt_name(sym->s_kind), type_name(sym->s_type));
+ debug_step("%s '%s' %s '%s' %d", __func__,
+ sym->s_name, symt_name(sym->s_kind), type_name(sym->s_type),
+ level);
+ sym->s_block_level = level;
symtab_add(sym);
- sym->s_block_level = level;
/*
* Placing the inner symbols to the beginning of the list ensures
diff -r fb94bfd5c58b -r e66e7dfc0a2f usr.bin/xlint/lint1/mem1.c
--- a/usr.bin/xlint/lint1/mem1.c Sat Jul 15 09:22:44 2023 +0000
+++ b/usr.bin/xlint/lint1/mem1.c Sat Jul 15 09:40:36 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mem1.c,v 1.68 2023/07/13 08:40:38 rillig Exp $ */
+/* $NetBSD: mem1.c,v 1.69 2023/07/15 09:40:36 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: mem1.c,v 1.68 2023/07/13 08:40:38 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.69 2023/07/15 09:40:36 rillig Exp $");
#endif
#include <sys/param.h>
@@ -235,6 +235,7 @@ void
level_free_all(size_t level)
{
+ debug_step("%s %zu", __func__, level);
mpool_free(mpool_at(level));
}
@@ -283,6 +284,7 @@ void
expr_free_all(void)
{
+ debug_step("%s", __func__);
mpool_free(&expr_pool);
}
Home |
Main Index |
Thread Index |
Old Index