mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Improve debugging.
* Replace remaining NDEBUG blocks with the more granular DEBUG_UNIT. * Remove some debug memset() calls in MemContext since valgrind is more useful for these checks.
This commit is contained in:
parent
cced6ec03a
commit
4b6cd92a4c
@ -84,7 +84,7 @@
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <code>ASSERT_DEBUG()</code> macro for debugging and replace all current <code>assert()</code> calls except in tests that can't use the debug code.</p>
|
||||
<p>Improve debugging. Add <code>ASSERT_DEBUG()</code> macro for debugging and replace all current <code>assert()</code> calls except in tests that can't use the debug code. Replace remaining NDEBUG blocks with the more granular DEBUG_UNIT. Remove some debug <code>memset()</code> calls in <code>MemContext</code> since valgrind is more useful for these checks.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
|
@ -15,6 +15,9 @@ NDEBUG indicates to C library routines that debugging is off -- set a more reada
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Assert Macros
|
||||
|
||||
Used for assertions that should only be run when debugging. Ideal for conditions that are not likely to happen in production but
|
||||
could occur during development.
|
||||
***********************************************************************************************************************************/
|
||||
#ifdef DEBUG
|
||||
#define ASSERT_DEBUG(condition) \
|
||||
@ -26,4 +29,14 @@ Assert Macros
|
||||
#define ASSERT_DEBUG(condition)
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Extern variables that are needed for unit testing
|
||||
***********************************************************************************************************************************/
|
||||
#ifdef DEBUG_UNIT
|
||||
#define DEBUG_UNIT_EXTERN
|
||||
#else
|
||||
#define DEBUG_UNIT_EXTERN \
|
||||
static
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -18,20 +18,20 @@ Log Handler
|
||||
Module variables
|
||||
***********************************************************************************************************************************/
|
||||
// Log levels
|
||||
LogLevel logLevelStdOut = logLevelError;
|
||||
LogLevel logLevelStdErr = logLevelError;
|
||||
LogLevel logLevelFile = logLevelOff;
|
||||
DEBUG_UNIT_EXTERN LogLevel logLevelStdOut = logLevelError;
|
||||
DEBUG_UNIT_EXTERN LogLevel logLevelStdErr = logLevelError;
|
||||
DEBUG_UNIT_EXTERN LogLevel logLevelFile = logLevelOff;
|
||||
|
||||
// Log file handles
|
||||
int logHandleStdOut = STDOUT_FILENO;
|
||||
int logHandleStdErr = STDERR_FILENO;
|
||||
int logHandleFile = -1;
|
||||
DEBUG_UNIT_EXTERN int logHandleStdOut = STDOUT_FILENO;
|
||||
DEBUG_UNIT_EXTERN int logHandleStdErr = STDERR_FILENO;
|
||||
DEBUG_UNIT_EXTERN int logHandleFile = -1;
|
||||
|
||||
// Has the log file banner been written yet?
|
||||
bool logFileBanner = false;
|
||||
static bool logFileBanner = false;
|
||||
|
||||
// Is the timestamp printed in the log?
|
||||
bool logTimestamp = false;
|
||||
static bool logTimestamp = false;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Debug Asserts
|
||||
|
@ -23,9 +23,9 @@ typedef enum
|
||||
} LogLevel;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Expose internal data for debugging/testing
|
||||
Expose internal data for unit testing/debugging
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG_UNIT
|
||||
extern LogLevel logLevelStdOut;
|
||||
extern LogLevel logLevelStdErr;
|
||||
extern LogLevel logLevelFile;
|
||||
@ -33,8 +33,6 @@ Expose internal data for debugging/testing
|
||||
extern int logHandleStdOut;
|
||||
extern int logHandleStdErr;
|
||||
extern int logHandleFile;
|
||||
|
||||
extern bool logTimestamp;
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -325,11 +325,6 @@ memFree(void *buffer)
|
||||
// Find the allocation
|
||||
MemContextAlloc *alloc = &(memContextCurrent()->allocList[memFind(buffer)]);
|
||||
|
||||
// DEBUG: zero buffer to make it more obvious that it was freed if there are still references to it
|
||||
#ifndef NDEBUG
|
||||
memset(alloc->buffer, 0, alloc->size);
|
||||
#endif
|
||||
|
||||
// Free the buffer
|
||||
memFreeInternal(alloc->buffer);
|
||||
alloc->active = false;
|
||||
@ -433,14 +428,7 @@ memContextFree(MemContext *this)
|
||||
MemContextAlloc *alloc = &(this->allocList[allocIdx]);
|
||||
|
||||
if (alloc->active)
|
||||
{
|
||||
// DEBUG: zero buffer to make it more obvious that it was freed if there are still references to it
|
||||
#ifndef NDEBUG
|
||||
memset(alloc->buffer, 0, alloc->size);
|
||||
#endif
|
||||
|
||||
memFreeInternal(alloc->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
memFreeInternal(this->allocList);
|
||||
|
@ -344,7 +344,7 @@ sub run
|
||||
" `perl -MExtUtils::Embed -e ccopts`\n" .
|
||||
"LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) ? " -lgcov" : '') .
|
||||
" `perl -MExtUtils::Embed -e ldopts`\n" .
|
||||
'TESTFLAGS=' . ($self->{oTest}->{&TEST_CDEF} ? "$self->{oTest}->{&TEST_CDEF}" : '') .
|
||||
'TESTFLAGS=-DDEBUG_UNIT' . ($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') .
|
||||
"\n" .
|
||||
"\nSRCS=" . join(' ', @stryCFile) . "\n" .
|
||||
"OBJS=\$(SRCS:.c=.o)\n" .
|
||||
|
Loading…
Reference in New Issue
Block a user