diff --git a/repos/base/include/base/thread.h b/repos/base/include/base/thread.h index 8d75e53a0f..3e3331ffad 100644 --- a/repos/base/include/base/thread.h +++ b/repos/base/include/base/thread.h @@ -417,6 +417,16 @@ class Genode::Thread _logger()->log(cstring, strlen(cstring)); } + /** + * Log null-terminated string as trace event using log_output policy + * + * \return true if trace is really put to buffer + */ + static bool trace_captured(char const *cstring) + { + return _logger()->log_captured(cstring, strlen(cstring)); + } + /** * Log binary data as trace event */ diff --git a/repos/base/include/base/trace/logger.h b/repos/base/include/base/trace/logger.h index f5ffe2cf60..73e93bb4b6 100644 --- a/repos/base/include/base/trace/logger.h +++ b/repos/base/include/base/trace/logger.h @@ -67,6 +67,13 @@ struct Genode::Trace::Logger */ void log(char const *, size_t); + /** + * Log binary data to trace buffer using log_output policy + * + * \return true if log is really put to buffer + */ + bool log_captured(char const *, size_t); + /** * Log event to trace buffer */ diff --git a/repos/base/src/lib/base/default_log.cc b/repos/base/src/lib/base/default_log.cc index 4da0808fb7..2da61f31bb 100644 --- a/repos/base/src/lib/base/default_log.cc +++ b/repos/base/src/lib/base/default_log.cc @@ -98,7 +98,12 @@ void Genode::init_log(Parent &parent) back_end_ptr = unmanaged_singleton(parent); - struct Write_fn { void operator () (char const *s) { back_end_ptr->write(s); } }; + struct Write_fn { + void operator () (char const *s) { + if (Thread::trace_captured(s)) return; + back_end_ptr->write(s); + } + }; typedef Buffered_output Buffered_log_output; diff --git a/repos/base/src/lib/base/trace.cc b/repos/base/src/lib/base/trace.cc index 9a38743a54..6c597b5571 100644 --- a/repos/base/src/lib/base/trace.cc +++ b/repos/base/src/lib/base/trace.cc @@ -157,6 +157,18 @@ void Trace::Logger::log(char const *msg, size_t len) } +__attribute__((optimize("-fno-delete-null-pointer-checks"))) +bool Trace::Logger::log_captured(char const *msg, size_t len) +{ + if (!this || !_evaluate_control()) return false; + + len = policy_module->log_output(buffer->reserve(len), msg, len); + buffer->commit(len); + + return len != 0; +} + + void Trace::Logger::init(Thread_capability thread, Cpu_session *cpu_session, Trace::Control *attached_control) {