trace: redirect logs to trace based on policy

If trace is enabled for component than an attempt to put message into
trace buffer is performed using log_output policy. If it succeeds than
message is not put to logs using log service.

Fixes #3714
This commit is contained in:
Tomasz Gajewski 2020-04-07 23:47:31 +02:00 committed by Christian Helmuth
parent db8ec81e9f
commit 870d348d77
4 changed files with 35 additions and 1 deletions

View File

@ -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
*/

View File

@ -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
*/

View File

@ -98,7 +98,12 @@ void Genode::init_log(Parent &parent)
back_end_ptr = unmanaged_singleton<Back_end>(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<Log_session::MAX_STRING_LEN, Write_fn>
Buffered_log_output;

View File

@ -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)
{