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 detailed logging for finding m...
details: https://anonhg.NetBSD.org/src/rev/4900bef70199
branches: trunk
changeset: 377511:4900bef70199
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 15 13:35:24 2023 +0000
description:
lint: add detailed logging for finding memory allocation bugs
diffstat:
usr.bin/xlint/lint1/cgram.y | 8 ++--
usr.bin/xlint/lint1/decl.c | 31 +++++++++-------
usr.bin/xlint/lint1/externs1.h | 14 ++++++-
usr.bin/xlint/lint1/func.c | 6 +-
usr.bin/xlint/lint1/init.c | 6 +-
usr.bin/xlint/lint1/lex.c | 20 +++++-----
usr.bin/xlint/lint1/lint1.h | 10 ++++-
usr.bin/xlint/lint1/mem1.c | 79 ++++++++++++++++++++++++++++++++++-------
usr.bin/xlint/lint1/tree.c | 19 +++++----
9 files changed, 133 insertions(+), 60 deletions(-)
diffs (truncated from 567 to 300 lines):
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Jul 15 13:35:24 2023 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.462 2023/07/15 09:40:36 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.463 2023/07/15 13:35:24 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.462 2023/07/15 09:40:36 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.463 2023/07/15 13:35:24 rillig Exp $");
#endif
#include <limits.h>
@@ -520,12 +520,12 @@ generic_assoc_list:
/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
generic_association:
type_name T_COLON assignment_expression {
- $$ = block_zero_alloc(sizeof(*$$));
+ $$ = block_zero_alloc(sizeof(*$$), "generic");
$$->ga_arg = $1;
$$->ga_result = $3;
}
| T_DEFAULT T_COLON assignment_expression {
- $$ = block_zero_alloc(sizeof(*$$));
+ $$ = block_zero_alloc(sizeof(*$$), "generic");
$$->ga_arg = NULL;
$$->ga_result = $3;
}
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sat Jul 15 13:35:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.357 2023/07/15 09:40:36 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.358 2023/07/15 13:35:24 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.357 2023/07/15 09:40:36 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.358 2023/07/15 13:35:24 rillig Exp $");
#endif
#include <sys/param.h>
@@ -138,7 +138,7 @@ type_t *
block_dup_type(const type_t *tp)
{
- type_t *ntp = block_zero_alloc(sizeof(*ntp));
+ type_t *ntp = block_zero_alloc(sizeof(*ntp), "type");
*ntp = *tp;
return ntp;
}
@@ -148,7 +148,7 @@ type_t *
expr_dup_type(const type_t *tp)
{
- type_t *ntp = expr_zero_alloc(sizeof(*ntp));
+ type_t *ntp = expr_zero_alloc(sizeof(*ntp), "type");
*ntp = *tp;
return ntp;
}
@@ -163,7 +163,7 @@ type_t *
expr_unqualified_type(const type_t *tp)
{
- type_t *ntp = expr_zero_alloc(sizeof(*ntp));
+ type_t *ntp = expr_zero_alloc(sizeof(*ntp), "type");
*ntp = *tp;
ntp->t_const = false;
ntp->t_volatile = false;
@@ -1042,7 +1042,7 @@ sym_t *
declare_unnamed_member(void)
{
- sym_t *mem = block_zero_alloc(sizeof(*mem));
+ sym_t *mem = block_zero_alloc(sizeof(*mem), "sym");
mem->s_name = unnamed;
mem->s_kind = FMEMBER;
mem->s_scl = STRUCT_MEMBER;
@@ -1123,7 +1123,7 @@ set_bit_field_width(sym_t *dsym, int bit
{
if (dsym == NULL) {
- dsym = block_zero_alloc(sizeof(*dsym));
+ dsym = block_zero_alloc(sizeof(*dsym), "sym");
dsym->s_name = unnamed;
dsym->s_kind = FMEMBER;
dsym->s_scl = STRUCT_MEMBER;
@@ -1568,19 +1568,20 @@ make_tag_type(sym_t *tag, tspec_t kind,
}
if (tag->s_scl == NOSCL) {
tag->s_scl = scl;
- tag->s_type = tp = block_zero_alloc(sizeof(*tp));
+ tag->s_type = tp =
+ block_zero_alloc(sizeof(*tp), "type");
tp->t_packed = dcs->d_packed;
} else
tp = tag->s_type;
} else {
- tag = block_zero_alloc(sizeof(*tag));
+ tag = block_zero_alloc(sizeof(*tag), "sym");
tag->s_name = unnamed;
tag->s_def_pos = unique_curr_pos();
tag->s_kind = FTAG;
tag->s_scl = scl;
tag->s_block_level = -1;
- tag->s_type = tp = block_zero_alloc(sizeof(*tp));
+ tag->s_type = tp = block_zero_alloc(sizeof(*tp), "type");
tp->t_packed = dcs->d_packed;
dcs->d_enclosing->d_nonempty_decl = true;
}
@@ -1588,13 +1589,15 @@ make_tag_type(sym_t *tag, tspec_t kind,
if (tp->t_tspec == NO_TSPEC) {
tp->t_tspec = kind;
if (kind != ENUM) {
- tp->t_sou = block_zero_alloc(sizeof(*tp->t_sou));
+ tp->t_sou = block_zero_alloc(sizeof(*tp->t_sou),
+ "struct_or_union");
tp->t_sou->sou_align_in_bits = CHAR_SIZE;
tp->t_sou->sou_tag = tag;
tp->t_sou->sou_incomplete = true;
} else {
tp->t_is_enum = true;
- tp->t_enum = block_zero_alloc(sizeof(*tp->t_enum));
+ tp->t_enum = block_zero_alloc(sizeof(*tp->t_enum),
+ "enumeration");
tp->t_enum->en_tag = tag;
tp->t_enum->en_incomplete = true;
}
@@ -1823,7 +1826,7 @@ declare_extern(sym_t *dsym, bool has_ini
if (renaming != NULL) {
lint_assert(dsym->s_rename == NULL);
- char *s = level_zero_alloc(1, renaming->sb_len + 1);
+ char *s = level_zero_alloc(1, renaming->sb_len + 1, "string");
(void)memcpy(s, renaming->sb_name, renaming->sb_len + 1);
dsym->s_rename = s;
}
@@ -2754,7 +2757,7 @@ abstract_name(void)
lint_assert(dcs->d_kind == DLK_ABSTRACT
|| dcs->d_kind == DLK_PROTO_PARAMS);
- sym_t *sym = block_zero_alloc(sizeof(*sym));
+ sym_t *sym = block_zero_alloc(sizeof(*sym), "sym");
sym->s_name = unnamed;
sym->s_def = DEF;
sym->s_scl = ABSTRACT;
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sat Jul 15 13:35:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.195 2023/07/13 23:11:11 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.196 2023/07/15 13:35:24 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -104,11 +104,23 @@ int get_filename_id(const char *);
void add_directory_replacement(char *);
const char *transform_filename(const char *, size_t);
+#ifdef DEBUG_MEM
+void *block_zero_alloc(size_t, const char *);
+void *level_zero_alloc(size_t, size_t, const char *);
+#else
void *block_zero_alloc(size_t);
void *level_zero_alloc(size_t, size_t);
+#define block_zero_alloc(size, descr) (block_zero_alloc)(size)
+#define level_zero_alloc(level, size, descr) (level_zero_alloc)(level, size)
+#endif
void level_free_all(size_t);
+#ifdef DEBUG_MEM
+void *expr_zero_alloc(size_t, const char *);
+#else
void *expr_zero_alloc(size_t);
+#define expr_zero_alloc(size, descr) (expr_zero_alloc)(size)
+#endif
tnode_t *expr_alloc_tnode(void);
void expr_free_all(void);
memory_pool expr_save_memory(void);
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c Sat Jul 15 13:35:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.170 2023/07/13 08:40:38 rillig Exp $ */
+/* $NetBSD: func.c,v 1.171 2023/07/15 13:35:24 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.170 2023/07/13 08:40:38 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.171 2023/07/15 13:35:24 rillig Exp $");
#endif
#include <stdlib.h>
@@ -1010,7 +1010,7 @@ check_return_value(bool sys, tnode_t *tn
}
/* Create a temporary node for the left side */
- tnode_t *ln = expr_zero_alloc(sizeof(*ln));
+ tnode_t *ln = expr_zero_alloc(sizeof(*ln), "tnode");
ln->tn_op = NAME;
ln->tn_type = expr_unqualified_type(funcsym->s_type->t_subt);
ln->tn_lvalue = true;
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/init.c Sat Jul 15 13:35:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.246 2023/07/13 08:40:38 rillig Exp $ */
+/* $NetBSD: init.c,v 1.247 2023/07/15 13:35:24 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.246 2023/07/13 08:40:38 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.247 2023/07/15 13:35:24 rillig Exp $");
#endif
#include <stdlib.h>
@@ -304,7 +304,7 @@ check_init_expr(const type_t *ltp, sym_t
type_t *lutp = expr_unqualified_type(ltp);
/* Create a temporary node for the left side. */
- tnode_t *ln = expr_zero_alloc(sizeof(*ln));
+ tnode_t *ln = expr_zero_alloc(sizeof(*ln), "tnode");
ln->tn_op = NAME;
ln->tn_type = lutp;
ln->tn_lvalue = true;
diff -r b6b6e3b490b1 -r 4900bef70199 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Jul 15 12:24:57 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jul 15 13:35:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.187 2023/07/15 09:40:36 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.188 2023/07/15 13:35:24 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.187 2023/07/15 09:40:36 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.188 2023/07/15 13:35:24 rillig Exp $");
#endif
#include <ctype.h>
@@ -358,7 +358,7 @@ add_keyword(const struct keyword *kw, bo
name = xstrdup(buf);
}
- sym_t *sym = block_zero_alloc(sizeof(*sym));
+ sym_t *sym = block_zero_alloc(sizeof(*sym), "sym");
sym->s_name = name;
sym->s_keyword = kw;
int tok = kw->kw_token;
@@ -481,7 +481,7 @@ lex_name(const char *yytext, size_t yyle
return sym->s_scl == TYPEDEF ? T_TYPENAME : T_NAME;
}
- char *name = block_zero_alloc(yyleng + 1);
+ char *name = block_zero_alloc(yyleng + 1, "string");
(void)memcpy(name, yytext, yyleng + 1);
sb->sb_name = name;
return T_NAME;
@@ -1336,8 +1336,8 @@ getsym(sbuf_t *sb)
/* labels must always be allocated at level 1 (outermost block) */
decl_level *dl;
if (symtyp == FLABEL) {
- sym = level_zero_alloc(1, sizeof(*sym));
- char *s = level_zero_alloc(1, sb->sb_len + 1);
+ sym = level_zero_alloc(1, sizeof(*sym), "sym");
+ char *s = level_zero_alloc(1, sb->sb_len + 1, "string");
(void)memcpy(s, sb->sb_name, sb->sb_len + 1);
sym->s_name = s;
sym->s_block_level = 1;
@@ -1347,7 +1347,7 @@ getsym(sbuf_t *sb)
dl = dl->d_enclosing;
lint_assert(dl->d_kind == DLK_AUTO);
} else {
- sym = block_zero_alloc(sizeof(*sym));
+ sym = block_zero_alloc(sizeof(*sym), "sym");
sym->s_name = sb->sb_name;
sym->s_block_level = block_level;
dl = dcs;
Home |
Main Index |
Thread Index |
Old Index