forked from auracaster/openocd
configure.ac: Replace --enable-malloc-logging with a new runtime log level.
About why the new log level LOG_LVL_DEBUG_USB has the same value a LOG_LVL_DEBUG_MALLOC, see the mailing list discussion starting here: Replacing --enable-verbose-usb-comms in configure.ac https://sourceforge.net/p/openocd/mailman/message/59215751/ Other minor fixes included here which are probably not worth submmitting in separate patches: - In error message "level must be between -3 and 4", increase 4 to 5. - LOG_DEBUG_IO was passing LOG_LVL_DEBUG instead of LOG_LVL_DEBUG_IO. Change-Id: I71440bbabe4785338c0a27562cc76fa1b7d54bf5 Signed-off-by: R. Diez <rdiez-2006@rd10.de> Reviewed-on: https://review.openocd.org/c/openocd/+/9432 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
19
configure.ac
19
configure.ac
@@ -96,8 +96,8 @@ AC_CHECK_FUNCS([strnlen])
|
||||
AC_CHECK_FUNCS([gettimeofday])
|
||||
AC_CHECK_FUNCS([usleep])
|
||||
AC_CHECK_FUNCS([realpath])
|
||||
AC_CHECK_FUNCS([mallinfo], [has_at_least_one_mallinfo=yes])
|
||||
AC_CHECK_FUNCS([mallinfo2], [has_at_least_one_mallinfo=yes])
|
||||
AC_CHECK_FUNCS([mallinfo])
|
||||
AC_CHECK_FUNCS([mallinfo2])
|
||||
|
||||
# guess-rev.sh only exists in the repository, not in the released archives
|
||||
AC_MSG_CHECKING([whether to build a release])
|
||||
@@ -264,21 +264,6 @@ AS_IF([test "x$enable_gcov" = "xyes"], [
|
||||
AC_DEFINE([USE_GCOV], [0], [0 to leave coverage collection disabled.])
|
||||
])
|
||||
|
||||
debug_malloc=no
|
||||
AC_ARG_ENABLE([malloc_logging],
|
||||
AS_HELP_STRING([--enable-malloc-logging],
|
||||
[Include free space in logging messages (requires malloc.h).]),
|
||||
[debug_malloc=$enableval], [])
|
||||
|
||||
AC_MSG_CHECKING([whether to enable malloc free space logging]);
|
||||
AC_MSG_RESULT([$debug_malloc])
|
||||
AS_IF([test "x$debug_malloc" = "xyes"], [
|
||||
AS_IF([test "x$has_at_least_one_mallinfo" != "xyes"], [
|
||||
AC_MSG_ERROR([Option --enable-malloc-logging needs a libc with mallinfo or mallinfo2.])
|
||||
])
|
||||
AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging])
|
||||
])
|
||||
|
||||
m4_define([AC_ARG_ADAPTERS], [
|
||||
m4_foreach([adapter_driver], [$1],
|
||||
[AC_ARG_ENABLE(ADAPTER_OPT([adapter_driver]),
|
||||
|
||||
@@ -9589,7 +9589,8 @@ level 1 adds warnings;
|
||||
level 2 adds informational messages;
|
||||
level 3 adds debugging messages;
|
||||
level 4 adds verbose low-level debug messages;
|
||||
and level 5 adds USB communication messages.
|
||||
and level 5 adds USB communication messages
|
||||
and amount of free heap space if mallinfo is available.
|
||||
The default is level 2, but that can be overridden on
|
||||
the command line along with the location of that log
|
||||
file (which is normally the server's standard output).
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
#include <malloc.h> // For mallinfo/mallinfo2.
|
||||
#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
int debug_level = LOG_LVL_INFO;
|
||||
@@ -101,30 +101,35 @@ static void log_puts(enum log_levels level,
|
||||
if (LOG_LEVEL_IS(LOG_LVL_DEBUG)) {
|
||||
/* print with count and time information */
|
||||
int64_t t = timeval_ms() - start;
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
|
||||
#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
|
||||
const int should_use_mallinfo = LOG_LEVEL_IS(LOG_LVL_DEBUG_MALLOC);
|
||||
|
||||
if (should_use_mallinfo) {
|
||||
#ifdef HAVE_MALLINFO2
|
||||
struct mallinfo2 info = mallinfo2();
|
||||
#elif defined(HAVE_MALLINFO)
|
||||
struct mallinfo info = mallinfo();
|
||||
#else
|
||||
#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
|
||||
#endif
|
||||
struct mallinfo info = mallinfo();
|
||||
#endif
|
||||
|
||||
fprintf(log_output, "%s%u %" PRId64 " %s:%d %s()"
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
#ifdef HAVE_MALLINFO2
|
||||
" %zu"
|
||||
#elif defined(HAVE_MALLINFO)
|
||||
" %d"
|
||||
#else
|
||||
#error "Configuration error: Neither mallinfo() nor mallinfo2() are available."
|
||||
#endif
|
||||
" %d"
|
||||
#endif
|
||||
": %s", log_strings[level + 1], count, t, file, line, function,
|
||||
#ifdef _DEBUG_FREE_SPACE_
|
||||
info.fordblks,
|
||||
#endif
|
||||
string);
|
||||
}
|
||||
#else
|
||||
const int should_use_mallinfo = 0;
|
||||
#endif
|
||||
if (!should_use_mallinfo) {
|
||||
fprintf(log_output, "%s%u %" PRId64 " %s:%d %s()"
|
||||
": %s", log_strings[level + 1], count, t, file, line, function,
|
||||
string);
|
||||
}
|
||||
} else {
|
||||
/* if we are using gdb through pipes then we do not want any output
|
||||
* to the pipe otherwise we get repeated strings */
|
||||
@@ -211,7 +216,7 @@ COMMAND_HANDLER(handle_debug_level_command)
|
||||
int new_level;
|
||||
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], new_level);
|
||||
if (new_level > LOG_LVL_DEBUG_USB || new_level < LOG_LVL_SILENT) {
|
||||
command_print(CMD, "level must be between %d and %d", LOG_LVL_SILENT, LOG_LVL_DEBUG_IO);
|
||||
command_print(CMD, "level must be between %d and %d", LOG_LVL_SILENT, LOG_LVL_DEBUG_USB);
|
||||
return ERROR_COMMAND_ARGUMENT_INVALID;
|
||||
}
|
||||
debug_level = new_level;
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
* LOG_LVL_DEBUG_USB - verbose USB trace
|
||||
* In the past this corresponded to build configuration options
|
||||
--enable-verbose and --enable-verbose-usb-comms.
|
||||
* LOG_LVL_DEBUG_MALLOC - log messages will include the amount of free heap space
|
||||
* maintained by malloc in its free list, if mallinfo is available.
|
||||
* In the past this corresponded to build configuration
|
||||
* option --enable-malloc-logging.
|
||||
*/
|
||||
enum log_levels {
|
||||
LOG_LVL_SILENT = -3,
|
||||
@@ -50,7 +54,10 @@ enum log_levels {
|
||||
LOG_LVL_INFO = 2,
|
||||
LOG_LVL_DEBUG = 3,
|
||||
LOG_LVL_DEBUG_IO = 4,
|
||||
// LOG_LVL_DEBUG_USB and LOG_LVL_DEBUG_MALLOC have the same value at the moment.
|
||||
// In the future, these logging categories will be individually switchable.
|
||||
LOG_LVL_DEBUG_USB = 5,
|
||||
LOG_LVL_DEBUG_MALLOC = 5,
|
||||
};
|
||||
|
||||
void log_printf(enum log_levels level, const char *file, unsigned int line,
|
||||
@@ -109,7 +116,7 @@ extern int debug_level;
|
||||
#define LOG_DEBUG_IO(expr ...) \
|
||||
do { \
|
||||
if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) \
|
||||
log_printf_lf(LOG_LVL_DEBUG, \
|
||||
log_printf_lf(LOG_LVL_DEBUG_IO, \
|
||||
__FILE__, __LINE__, __func__, \
|
||||
expr); \
|
||||
} while (0)
|
||||
|
||||
Reference in New Issue
Block a user