debug-channel: add child channels

This commit is contained in:
Kirill Zhumarin 2026-11-05 02:03:28 +03:00
parent 2cb93acd9a
commit ecbf030c14
4 changed files with 67 additions and 3 deletions

View file

@ -46,6 +46,7 @@ void debug_io_print_context(const DebugIoAccess *io, GString *out);
struct DebugChannel {
uint8_t flags;
char *name;
const DebugChannelInfo *info;
const DebugIoFormat *io_format;
const void *io_format_opaque;
const char *(*get_reg_suffix)(const DebugChannel *ch, uint64_t offset);
@ -71,6 +72,8 @@ void debug_channels_reset(void);
void debug_channel_init(DebugChannel *ch, const DebugChannelInfo *info,
const char *instance);
void debug_channel_init_child(DebugChannel *ch, const DebugChannel *parent,
const char *name);
void debug_channel_cleanup(DebugChannel *ch);
static inline bool debug_channel_is_enabled(const DebugChannel *ch,

View file

@ -5156,9 +5156,11 @@ SRST
A channel name is a pattern with ``*`` and ``?`` that matches a device
id, a channel name (the QOM type for a device) or a parent QOM type of
a device, as in ``log=*,-dsp_*`` or ``io=pmb887x-i2c-*,USART*``. Names
are case insensitive and applied in order; ``-`` turns the channels
off. Repeated keys and options add to the list. A name that matches no
a device. Parts of a device that are not QOM objects have subchannels
named after the device id, such as ``dsp0.timer1``. Examples:
``log=*,-dsp0.*`` or ``io=pl011,*i2c*,uart*``. Names are case
insensitive and applied in order; ``-`` turns the channels off.
Repeated keys and options add to the list. A name that matches no
channel, device id or QOM type stops QEMU after machine creation.
ERST

View file

@ -127,6 +127,33 @@ static void test_instances(void)
g_assert_cmpint(flags_of(&usart_info, NULL), ==, 0);
}
static void test_child(void)
{
DebugChannel parent;
DebugChannel child;
debug_channels_reset();
parse_ok("pmb887x-lcd", DEBUG_CH_LOG);
debug_channel_init(&parent, &jbt6k71_info, "LCD0");
debug_channel_init_child(&child, &parent, "OSC");
g_assert_cmpstr(child.name, ==, "LCD0.OSC");
g_assert_cmpstr(child.info->name, ==, "jbt6k71.osc");
g_assert_cmpint(parent.flags, ==, DEBUG_CH_LOG);
g_assert_cmpint(child.flags, ==, 0);
debug_channel_cleanup(&child);
debug_channel_cleanup(&parent);
debug_channels_reset();
parse_ok("DSP.*", DEBUG_CH_LOG);
debug_channel_init(&parent, &dsp_info, "DSP");
debug_channel_init_child(&child, &parent, "TMR1");
g_assert_cmpstr(child.name, ==, "DSP.TMR1");
g_assert_cmpint(child.flags, ==, DEBUG_CH_LOG);
g_assert_cmpint(parent.flags, ==, 0);
debug_channel_cleanup(&child);
debug_channel_cleanup(&parent);
}
static void test_instance_name(void)
{
DebugChannel ch;
@ -262,6 +289,7 @@ int main(int argc, char **argv)
test_flags_are_independent);
g_test_add_func("/debug-channel/instances", test_instances);
g_test_add_func("/debug-channel/instance-name", test_instance_name);
g_test_add_func("/debug-channel/child", test_child);
g_test_add_func("/debug-channel/whitespace-and-empty",
test_whitespace_and_empty);
g_test_add_func("/debug-channel/lone-sign-fails", test_lone_sign_fails);

View file

@ -13,6 +13,7 @@ typedef struct DebugSpecItem {
} DebugSpecItem;
static GPtrArray *debug_infos;
static GHashTable *debug_child_infos;
static GPtrArray *debug_spec;
static bool debug_has_enabled;
@ -218,6 +219,7 @@ void debug_channel_init(DebugChannel *ch, const DebugChannelInfo *info,
{
*ch = (DebugChannel) {
.name = g_strdup(instance ?: info->name),
.info = info,
};
for (guint i = 0; debug_spec && i < debug_spec->len; i++) {
@ -238,6 +240,35 @@ void debug_channel_init(DebugChannel *ch, const DebugChannelInfo *info,
debug_has_enabled |= ch->flags != 0;
}
static const DebugChannelInfo *debug_child_info(const char *name)
{
if (!debug_child_infos) {
debug_child_infos = g_hash_table_new(g_str_hash, g_str_equal);
}
DebugChannelInfo *info = g_hash_table_lookup(debug_child_infos, name);
if (info) {
return info;
}
info = g_new0(DebugChannelInfo, 1);
info->name = g_strdup(name);
debug_channel_info_register(info);
g_hash_table_insert(debug_child_infos, (gpointer) info->name, info);
return info;
}
void debug_channel_init_child(DebugChannel *ch, const DebugChannel *parent,
const char *name)
{
g_autofree char *lower_name = g_ascii_strdown(name, -1);
g_autofree char *info_name = g_strdup_printf("%s.%s", parent->info->name,
lower_name);
g_autofree char *instance = g_strdup_printf("%s.%s", parent->name, name);
debug_channel_init(ch, debug_child_info(info_name), instance);
}
void debug_channel_cleanup(DebugChannel *ch)
{
/* Queued records, guest errors included, still point at the name */