From a14a6881538229cd938282bd56c7f0d12a089be6 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 30 May 2018 12:32:31 +0300 Subject: Drop debugging hooks The hooks were introduced as a temporary tool in de7834e9. They did their job and are not necessary any more. --- src/bucket.c | 17 +++---- src/debug.c | 137 -------------------------------------------------------- src/falloc.c | 18 +++----- src/findkey.c | 12 ++--- src/gdbmdefs.h | 14 ------ src/gdbmopen.c | 8 ++-- src/gdbmstore.c | 10 ++--- src/lex.l | 2 - src/update.c | 12 ++--- tests/gtload.c | 68 ---------------------------- 10 files changed, 26 insertions(+), 272 deletions(-) diff --git a/src/bucket.c b/src/bucket.c index c75db42..2289594 100644 --- a/src/bucket.c +++ b/src/bucket.c @@ -112,8 +112,7 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) /* It is not in the cache, read it from the disk. */ /* Position the file pointer */ - file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_get_bucket:seek-failure", - __lseek (dbf, bucket_adr, SEEK_SET)); + file_pos = __lseek (dbf, bucket_adr, SEEK_SET); if (file_pos != bucket_adr) { GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); @@ -131,9 +130,8 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index) _gdbm_cache_entry_invalidate (dbf, lru); /* Read the bucket. */ - rc = GDBM_DEBUG_OVERRIDE ("_gdbm_get_bucket:read-failure", - _gdbm_full_read (dbf, dbf->bucket_cache[lru].ca_bucket, - dbf->header->bucket_size)); + rc = _gdbm_full_read (dbf, dbf->bucket_cache[lru].ca_bucket, + dbf->header->bucket_size); if (rc) { GDBM_DEBUG (GDBM_DEBUG_ERR, @@ -302,8 +300,7 @@ _gdbm_split_bucket (GDBM_FILE dbf, int next_insert) dir_adr = _gdbm_alloc (dbf, dir_size); if (dir_adr == 0) return -1; - new_dir = GDBM_DEBUG_ALLOC ("_gdbm_split_bucket:malloc-failure", - malloc (dir_size)); + new_dir = malloc (dir_size); if (new_dir == NULL) { GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); @@ -435,16 +432,14 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry) int rc; off_t file_pos; /* The return value for lseek. */ - file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_write_bucket:seek-failure", - __lseek (dbf, ca_entry->ca_adr, SEEK_SET)); + file_pos = __lseek (dbf, ca_entry->ca_adr, SEEK_SET); if (file_pos != ca_entry->ca_adr) { GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); _gdbm_fatal (dbf, _("lseek error")); return -1; } - rc = GDBM_DEBUG_OVERRIDE ("_gdbm_write_bucket:write-failure", - _gdbm_full_write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size)); + rc = _gdbm_full_write (dbf, ca_entry->ca_bucket, dbf->header->bucket_size); if (rc) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, diff --git a/src/debug.c b/src/debug.c index 00f568c..08957ed 100644 --- a/src/debug.c +++ b/src/debug.c @@ -136,140 +136,3 @@ gdbm_debug_datum (datum dat, char const *pfx) } } - -struct hook_list -{ - struct hook_list *next; - struct hook_list *prev; - char *id; - gdbm_debug_hook hook; - void *data; - int retval; -}; - -static struct hook_list *hook_head, *hook_tail; -static struct hook_list *hook_recent; - -static struct hook_list * -hook_lookup_or_install (char const *id, int install) -{ - struct hook_list *p; - - for (p = hook_head; p; p = p->next) - { - int res = strcmp (p->id, id); - if (res == 0) - return p; - if (res > 0) - break; - } - - if (install) - { - struct hook_list *elt = malloc (sizeof *elt); - if (!elt) - return NULL; - elt->id = strdup (id); - if (!elt->id) - { - SAVE_ERRNO (free (elt)); - return NULL; - } - elt->hook = NULL; - elt->next = p; - if (p) - { - if (p->prev) - p->prev->next = elt; - else - hook_head = elt; - elt->prev = p->prev; - } - else - { - elt->prev = hook_tail; - if (hook_tail) - hook_tail->next = elt; - else - hook_head = elt; - hook_tail = elt; - } - return elt; - } - - return NULL; -} - -static struct hook_list * -hook_lookup (char const *id) -{ - if (!(hook_recent && strcmp (hook_recent->id, id) == 0)) - hook_recent = hook_lookup_or_install (id, FALSE); - return hook_recent; -} - -static void -hook_remove (char const *id) -{ - struct hook_list *p; - - p = hook_lookup (id); - if (!p) - return; - - hook_recent = NULL; - - if (p->prev) - p->prev->next = p->next; - else - hook_head = p->next; - - if (p->next) - p->next->prev = p->prev; - else - hook_tail = p->prev; - - free (p->id); - free (p); -} - -static int -default_hook (char const *file, int line, char const *id, void *data) -{ - fprintf (stderr, "%s:%d: hit debug hook %s\n", file, line, id); - return 1; -} - -void -_gdbm_debug_hook_install (char const *id, gdbm_debug_hook hook, void *data) -{ - struct hook_list *p; - - p = hook_lookup_or_install (id, TRUE); - p->hook = hook ? hook : default_hook; - p->data = data; -} - -void -_gdbm_debug_hook_remove (char const *id) -{ - hook_remove (id); -} - -int -_gdbm_debug_hook_check (char const *file, int line, char const *id) -{ - struct hook_list *p = hook_lookup (id); - if (p) - return p->retval = p->hook (file, line, id, p->data); - return 0; -} - -int -_gdbm_debug_hook_val (char const *id) -{ - struct hook_list *p = hook_lookup (id); - if (p) - return p->retval; - return 0; -} diff --git a/src/falloc.c b/src/falloc.c index c3bd145..13ee0ed 100644 --- a/src/falloc.c +++ b/src/falloc.c @@ -182,8 +182,7 @@ pop_avail_block (GDBM_FILE dbf) + sizeof (avail_block)); /* Allocate space for the block. */ - new_blk = GDBM_DEBUG_ALLOC ("pop_avail_block:malloc-failure", - malloc (new_el.av_size)); + new_blk = malloc (new_el.av_size); if (new_blk == NULL) { GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); @@ -192,8 +191,7 @@ pop_avail_block (GDBM_FILE dbf) } /* Read the block. */ - file_pos = GDBM_DEBUG_OVERRIDE ("pop_avail_block:lseek-failure", - __lseek (dbf, new_el.av_adr, SEEK_SET)); + file_pos = __lseek (dbf, new_el.av_adr, SEEK_SET); if (file_pos != new_el.av_adr) { GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); @@ -202,8 +200,7 @@ pop_avail_block (GDBM_FILE dbf) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("pop_avail_block:read-failure", - _gdbm_full_read (dbf, new_blk, new_el.av_size)); + rc = _gdbm_full_read (dbf, new_blk, new_el.av_size); if (rc) { free (new_blk); @@ -295,8 +292,7 @@ push_avail_block (GDBM_FILE dbf) av_adr = new_loc.av_adr; /* Split the header block. */ - temp = GDBM_DEBUG_ALLOC ("push_avail_block:malloc-failure", - malloc (av_size)); + temp = malloc (av_size); if (temp == NULL) { GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); @@ -325,8 +321,7 @@ push_avail_block (GDBM_FILE dbf) _gdbm_free (dbf, new_loc.av_adr, new_loc.av_size); /* Update the disk. */ - file_pos = GDBM_DEBUG_OVERRIDE ("push_avail_block:lseek-failure", - __lseek (dbf, av_adr, SEEK_SET)); + file_pos = __lseek (dbf, av_adr, SEEK_SET); if (file_pos != av_adr) { GDBM_SET_ERRNO (dbf, GDBM_FILE_SEEK_ERROR, TRUE); @@ -334,8 +329,7 @@ push_avail_block (GDBM_FILE dbf) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("push_avail_block:write-failure", - _gdbm_full_write (dbf, temp, av_size)); + rc = _gdbm_full_write (dbf, temp, av_size); if (rc) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, diff --git a/src/findkey.c b/src/findkey.c index bd9fd83..9bb4553 100644 --- a/src/findkey.c +++ b/src/findkey.c @@ -71,9 +71,7 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) data_ca->elem_loc = elem_loc; data_ca->hash_val = dbf->bucket->h_table[elem_loc].hash_value; - if (GDBM_DEBUG_HOOK ("_gdbm_read_entry:malloc-failure")) - data_ca->dptr = NULL; - else if (key_size + data_size == 0) + if (key_size + data_size == 0) data_ca->dptr = (char *) malloc (1); else data_ca->dptr = (char *) malloc (key_size + data_size); @@ -85,9 +83,8 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) } /* Read into the cache. */ - file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_read_entry:lseek-failure", - __lseek (dbf, dbf->bucket->h_table[elem_loc].data_pointer, - SEEK_SET)); + file_pos = __lseek (dbf, dbf->bucket->h_table[elem_loc].data_pointer, + SEEK_SET); if (file_pos != dbf->bucket->h_table[elem_loc].data_pointer) { GDBM_SET_ERRNO2 (dbf, GDBM_FILE_SEEK_ERROR, TRUE, GDBM_DEBUG_LOOKUP); @@ -95,8 +92,7 @@ _gdbm_read_entry (GDBM_FILE dbf, int elem_loc) return NULL; } - rc = GDBM_DEBUG_OVERRIDE ("_gdbm_read_entry:read-failure", - _gdbm_full_read (dbf, data_ca->dptr, key_size+data_size)); + rc = _gdbm_full_read (dbf, data_ca->dptr, key_size+data_size); if (rc) { GDBM_DEBUG (GDBM_DEBUG_ERR|GDBM_DEBUG_LOOKUP|GDBM_DEBUG_READ, diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h index d940c5d..4ae646f 100644 --- a/src/gdbmdefs.h +++ b/src/gdbmdefs.h @@ -325,23 +325,9 @@ struct gdbm_file_info gdbm_set_errno(dbf, ec, fatal); \ } \ while (0) - -typedef int (*gdbm_debug_hook) (char const *, int, char const *, void *); -extern void _gdbm_debug_hook_install (char const *, gdbm_debug_hook, void *); -extern void _gdbm_debug_hook_remove (char const *); -extern int _gdbm_debug_hook_check (char const *, int, char const *); -extern int _gdbm_debug_hook_val (char const *); -# define GDBM_DEBUG_HOOK(id) _gdbm_debug_hook_check(__FILE__,__LINE__,id) -# define GDBM_DEBUG_OVERRIDE(id, stmt) \ - (GDBM_DEBUG_HOOK(id) ? _gdbm_debug_hook_val(id) : (stmt)) -# define GDBM_DEBUG_ALLOC(id, stmt) \ - (GDBM_DEBUG_HOOK(id) ? NULL : (stmt)) #else # define GDBM_DEBUG(flags, fmt, ...) # define GDBM_DEBUG_DATUM(flags, dat, fmt, ...) -# define GDBM_DEBUG_HOOK(id) 0 -# define GDBM_DEBUG_OVERRIDE(id, stmt) (stmt) -# define GDBM_DEBUG_ALLOC(id, stmt) (stmt) # define GDBM_SET_ERRNO2(dbf, ec, fatal, m) gdbm_set_errno (dbf, ec, fatal) #endif diff --git a/src/gdbmopen.c b/src/gdbmopen.c index 9c10d3d..22e7ca6 100644 --- a/src/gdbmopen.c +++ b/src/gdbmopen.c @@ -634,8 +634,7 @@ _gdbm_init_cache (GDBM_FILE dbf, size_t size) if (dbf->bucket_cache == NULL) { - dbf->bucket_cache = GDBM_DEBUG_ALLOC ("_gdbm_init_cache:malloc-failure", - calloc (size, sizeof(cache_elem))); + dbf->bucket_cache = calloc (size, sizeof(cache_elem)); if (dbf->bucket_cache == NULL) { GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); @@ -645,9 +644,8 @@ _gdbm_init_cache (GDBM_FILE dbf, size_t size) for (index = 0; index < size; index++) { - (dbf->bucket_cache[index]).ca_bucket = - GDBM_DEBUG_ALLOC ("_gdbm_init_cache:bucket-malloc-failure", - malloc (dbf->header->bucket_size)); + (dbf->bucket_cache[index]).ca_bucket = + malloc (dbf->header->bucket_size); if ((dbf->bucket_cache[index]).ca_bucket == NULL) { GDBM_SET_ERRNO (dbf, GDBM_MALLOC_ERROR, TRUE); diff --git a/src/gdbmstore.c b/src/gdbmstore.c index 2ed1616..6b498b2 100644 --- a/src/gdbmstore.c +++ b/src/gdbmstore.c @@ -160,8 +160,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags) dbf->bucket->h_table[elem_loc].data_size = content.dsize; /* Write the data to the file. */ - file_pos = GDBM_DEBUG_OVERRIDE ("gdbm_store:seek-failure", - __lseek (dbf, file_adr, SEEK_SET)); + file_pos = __lseek (dbf, file_adr, SEEK_SET); if (file_pos != file_adr) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, @@ -171,8 +170,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("gdbm_store:write-1-failure", - _gdbm_full_write (dbf, key.dptr, key.dsize)); + rc = _gdbm_full_write (dbf, key.dptr, key.dsize); if (rc) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, @@ -182,9 +180,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("gdbm_store:write-2-failure", - _gdbm_full_write (dbf, - content.dptr, content.dsize)); + rc = _gdbm_full_write (dbf, content.dptr, content.dsize); if (rc) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, diff --git a/src/lex.l b/src/lex.l index eff2ec7..0318031 100644 --- a/src/lex.l +++ b/src/lex.l @@ -121,9 +121,7 @@ input_context_push (instream_t input) void lex_trace (int n) { -#if GDBMTOOL_DEBUG yy_flex_debug = n; -#endif } int diff --git a/src/update.c b/src/update.c index 63c6c95..f4b8b78 100644 --- a/src/update.c +++ b/src/update.c @@ -30,8 +30,7 @@ write_header (GDBM_FILE dbf) off_t file_pos; /* Return value for lseek. */ int rc; - file_pos = GDBM_DEBUG_OVERRIDE ("write_header:lseek-failure", - __lseek (dbf, 0L, SEEK_SET)); + file_pos = __lseek (dbf, 0L, SEEK_SET); if (file_pos != 0) { GDBM_SET_ERRNO2 (dbf, GDBM_FILE_SEEK_ERROR, TRUE, GDBM_DEBUG_STORE); @@ -39,8 +38,7 @@ write_header (GDBM_FILE dbf) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("write_header:write-failure", - _gdbm_full_write (dbf, dbf->header, dbf->header->block_size)); + rc = _gdbm_full_write (dbf, dbf->header, dbf->header->block_size); if (rc) { @@ -96,8 +94,7 @@ _gdbm_end_update (GDBM_FILE dbf) /* Write the directory. */ if (dbf->directory_changed) { - file_pos = GDBM_DEBUG_OVERRIDE ("_gdbm_end_update:lseek-failure", - __lseek (dbf, dbf->header->dir, SEEK_SET)); + file_pos = __lseek (dbf, dbf->header->dir, SEEK_SET); if (file_pos != dbf->header->dir) { GDBM_SET_ERRNO2 (dbf, GDBM_FILE_SEEK_ERROR, TRUE, GDBM_DEBUG_STORE); @@ -105,8 +102,7 @@ _gdbm_end_update (GDBM_FILE dbf) return -1; } - rc = GDBM_DEBUG_OVERRIDE ("_gdbm_end_update:write-dir-failure", - _gdbm_full_write (dbf, dbf->dir, dbf->header->dir_size)); + rc = _gdbm_full_write (dbf, dbf->dir, dbf->header->dir_size); if (rc) { GDBM_DEBUG (GDBM_DEBUG_STORE|GDBM_DEBUG_ERR, diff --git a/tests/gtload.c b/tests/gtload.c index 273ebbe..21c89b2 100644 --- a/tests/gtload.c +++ b/tests/gtload.c @@ -39,36 +39,6 @@ err_printer (void *data, char const *fmt, ...) fprintf (stderr, "\n"); } -struct hook_closure -{ - unsigned skip; - unsigned hits; - int disabled; -}; - -static int -hookfn (char const *file, int line, char const *id, void *data) -{ - struct hook_closure *clos = data; - - if (clos->disabled) - return 0; - if (clos->skip) - { - --clos->skip; - return 0; - } - if (clos->hits) - { - if (--clos->hits == 0) - clos->disabled = 1; - } - - if (verbose) - fprintf (stderr, "%s:%d: hit debug hook %s\n", file, line, id); - return -1; -} - size_t read_size (char const *arg) { @@ -94,37 +64,6 @@ read_size (char const *arg) return ret; } -void -install_hook (char *id) -{ - char *p = strchr (id, ';'); - struct hook_closure *clos = malloc (sizeof (*clos)); - assert (clos != NULL); - memset (clos, 0, sizeof (*clos)); - if (p) - { - char *q; - - *p++ = 0; - for (q = strtok (p, ";"); q; q = strtok (NULL, ";")) - { - if (strncmp (q, "skip=", 5) == 0) - clos->skip = strtoul (q + 5, NULL, 10); - else if (strncmp (q, "hits=", 5) == 0) - clos->hits = strtoul (q + 5, NULL, 10); - else - { - fprintf (stderr, "%s: unknown parameter for hook %s: %s", - progname, id, q); - exit (1); - } - } - } -#ifdef GDBM_DEBUG_ENABLE - _gdbm_debug_hook_install (id, hookfn, clos); -#endif -} - #ifdef GDBM_DEBUG_ENABLE void debug_printer (char const *fmt, ...) @@ -195,13 +134,6 @@ main (int argc, char **argv) mapped_size_max = read_size (arg + 8); else if (strncmp (arg, "-delim=", 7) == 0) delim = arg[7]; -#if GDBM_DEBUG_ENABLE - else if (strncmp (arg, "-hook=", 6) == 0) - { - install_hook (arg + 6); - recover = 1; - } -#endif else if (strcmp (arg, "-recover") == 0) recover = 1; else if (strcmp (arg, "-verbose") == 0) -- cgit v1.2.1