Add a cmake option

This commit is contained in:
mio 2024-09-21 22:16:02 +08:00
parent 80f0898740
commit d87791329f
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
3 changed files with 11 additions and 4 deletions

View File

@ -64,6 +64,7 @@ include(cmake/bundle_static.cmake)
# compatability.
option(BUILD_SHARED_LIBS "Build shared instead of static library" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_FUZZ "Enable fuzzing" OFF)
option(UNICORN_LOGGING "Enable logging" OFF)
option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL})
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore" CACHE STRING "Enabled unicorn architectures")
@ -92,6 +93,11 @@ include_directories(
qemu/tcg
)
# QEMU logging facility
if (UNICORN_LOGGING)
add_compile_options(-DUNICORN_LOGGING)
endif()
# Some distributions on some rare architecures don't auto link atomic for us and
# we do this manually by adding flags.
set(ATOMIC_LINKAGE_FIX FALSE)

View File

@ -134,7 +134,7 @@ However, the qemu logs are partially commented-out and incomplete, but give it a
You might want to dig deeper - and add your own log messages where you expect or try to find the bug.
See the `unicorn/qemu/include/qemu/log.h` file for details.
To enable logs, you must recompile Unicorn with the enabled `LOGGING_ENABLED` define.
To enable logs, you must recompile Unicorn with the enabled `UNICORN_LOGGING` define.
Logs are written in different log levels, which might result into a very verbose logging if enabled.
To control the log level information, two environment variables could be used.

View File

@ -31,15 +31,16 @@
/* Logging functions: */
/* To verbose logging, enable the next line. */
//#define LOGGING_ENABLED // to enable logging
//#define UNICORN_LOGGING // to enable logging
#ifdef LOGGING_ENABLED
#ifdef UNICORN_LOGGING
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
/**
* Reads the @p env_name and tries to parse the value into an uint32_t.
@ -222,7 +223,7 @@ static inline bool is_log_level_active(uint32_t level)
return false;
}
#endif /* LOGGING_ENABLED */
#endif /* UNICORN_LOGGING */
/**
* Logs only if the right log level is set.