genode/repos/os/include/monitor/string.h
Norman Feske 6a57683e52 New debug monitor
The new monitor component at os/src/monitor is the designated successor
of the gdb_monitor. This initial version, however, implements only the
subset needed to inspect the memory of the monitored component(s).

In contrast to the gdb_monitor, the new component supports the monitoring
of multiple components, leveraging the sandbox API. It can therefore be
used as a drop-in replacement for the init component. Like the gdb_monitor,
the new monitor speaks the GDB protocol over Genode's terminal session.
But the protocol implementation does not re-use any gdbserver code,
sidestepping the complexities of POSIX.

There exist two run scripts illustrating the new component. The
os/run/monitor.run script exercises memory inspection via the 'm' command
by letting a test program monitor itself. The os/run/monitor_gdb.run
script allows for the interactive use of GDB to interact with monitored
components.

Issue #4917
2023-06-16 11:24:26 +02:00

77 lines
2.0 KiB
C++

/*
* \brief Parsing utilities
* \author Norman Feske
* \date 2023-06-06
*/
/*
* Copyright (C) 2023 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _MONITOR__STRING_H_
#define _MONITOR__STRING_H_
#include <util/string.h>
namespace Genode {
static void with_max_bytes(Const_byte_range_ptr const &bytes,
size_t const max, auto const &fn)
{
fn(Const_byte_range_ptr { bytes.start, min(max, bytes.num_bytes) });
}
static void with_skipped_bytes(Const_byte_range_ptr const &bytes,
size_t const n, auto const &fn)
{
if (bytes.num_bytes < n)
return;
Const_byte_range_ptr const remainder { bytes.start + n,
bytes.num_bytes - n };
fn(remainder);
}
static void with_skipped_prefix(Const_byte_range_ptr const &bytes,
Const_byte_range_ptr const &prefix,
auto const &fn)
{
if (bytes.num_bytes < prefix.num_bytes)
return;
if (strcmp(prefix.start, bytes.start, prefix.num_bytes) != 0)
return;
with_skipped_bytes(bytes, prefix.num_bytes, fn);
}
static void with_skipped_prefix(Const_byte_range_ptr const &bytes,
char const *prefix, auto const &fn)
{
with_skipped_prefix(bytes, Const_byte_range_ptr { prefix, strlen(prefix) }, fn);
}
template <size_t N>
static void with_skipped_prefix(Const_byte_range_ptr const &bytes,
String<N> const &prefix, auto const &fn)
{
with_skipped_prefix(bytes, prefix.string(), fn);
}
/**
* Return true if 'bytes' equals the null-terminated string 'str'
*/
static inline bool equal(Const_byte_range_ptr const &bytes, char const *str)
{
size_t const len = strlen(str);
return (len == bytes.num_bytes) && (strcmp(bytes.start, str, len) == 0);
}
}
#endif /* _MONITOR__STRING_H_ */