From b69acaadf5a24f594153c28ee6fc8fb6d793f9eb Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Tue, 6 Mar 2018 21:33:33 +0100 Subject: [PATCH] Rust: add 'debug' feature The 'debug' feature is enabled if suricata was configured with the --enabled-debug' flag. If enabled, the SCLogDebug format and calls the logging function as usual. Otherwise, this macro is a no-op (similarly to the C code). --- rust/Cargo.toml.in | 1 + rust/Makefile.am | 4 ++++ rust/src/log.rs | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 1a0384cddc..9cd079f7a2 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -12,6 +12,7 @@ debug = true lua = [] experimental = ["ntp-parser"] strict = [] +debug = [] [dependencies] nom = "~3.2.1" diff --git a/rust/Makefile.am b/rust/Makefile.am index 776d86b77a..6bc8a7b018 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -29,6 +29,10 @@ if HAVE_RUST_EXTERNAL RUST_FEATURES += experimental endif +if DEBUG +RUST_FEATURES += debug +endif + all-local: if HAVE_PYTHON cd $(top_srcdir)/rust && \ diff --git a/rust/src/log.rs b/rust/src/log.rs index 018888ca5f..bdc4cc0e09 100644 --- a/rust/src/log.rs +++ b/rust/src/log.rs @@ -114,6 +114,8 @@ macro_rules!SCLogConfig { } } +// Debug mode: call C SCLogDebug +#[cfg(feature = "debug")] #[macro_export] macro_rules!SCLogDebug { ($($arg:tt)*) => { @@ -121,6 +123,15 @@ macro_rules!SCLogDebug { } } +// Release mode: ignore arguments +// Use a reference to avoid moving values. +#[cfg(not(feature = "debug"))] +#[macro_export] +macro_rules!SCLogDebug { + ($last:expr) => { let _ = &$last; let _ = Level::Debug; }; + ($one:expr, $($arg:tt)*) => { let _ = &$one; SCLogDebug!($($arg)*); }; +} + #[no_mangle] pub extern "C" fn rs_log_set_level(level: i32) { unsafe {