<div dir="ltr"><div class="gmail_default" style="font-size:small">I found a solution, but my offer to send a pull request adding wl_object_get_class() and wl_object_get_id() still stands. Let me know!<br><br>To recap, my key question was: "The wl_protocol_logger API exposes a wl_object struct. How can I get the object class and ID from a wl_object?"<br><br>To answer my own question: wl_object is actually declared here, behind an #ifndef: <a href="https://gitlab.freedesktop.org/wayland/wayland/-/blob/69633202180acce9d0d5ab4037d80291c71b2307/src/wayland-server.h#L58">https://gitlab.freedesktop.org/wayland/wayland/-/blob/69633202180acce9d0d5ab4037d80291c71b2307/src/wayland-server.h#L58</a><br><br>The declaration is deprecated, though. I'm using it anyway for now, but I think accessor functions would be better so that I can treat wl_object as opaque. I'm happy to contribute if desired.<br><br>Best regards,<br>Chloe</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 16, 2024 at 10:56 AM Chloe Pelling <<a href="mailto:cpelling@google.com">cpelling@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I'm attempting to use the wl_protocol_logger API to replicate the<br>
functionality of WAYLAND_DEBUG=1 in my project, but logging to<br>
<a href="https://perfetto.dev/" rel="noreferrer" target="_blank">https://perfetto.dev/</a> rather than stderr. I'm having some trouble<br>
decoding message arguments of type object, since `wl_object` is an<br>
opaque struct and there doesn't appear to be a "blessed" way to<br>
interrogate it. In particular, there's no API to access<br>
`wl_object::id`.<br>
<br>
Am I missing something? Would a patch adding wl_object_get_id() and<br>
wl_object_get_class() functions be welcome?<br>
<br>
Here's what I've figured out so far:<br>
<br>
* Decoding the arguments requires inspecting the wl_argument unions in<br>
`wl_protocol_logger_message::arguments`, according to the type<br>
indications in `wl_protocol_logger_message::message->signature`.<br>
<br>
* Object arguments are denoted by "o" in the signature, indicating we<br>
should examine `wl_argument::o` of type wl_object.<br>
<br>
* wl_object is an opaque struct, and there are no<br>
wl_object_get_class() or wl_object_get_id() functions.<br>
<br>
* I can work around the lack of wl_object_get_class() by inspecting<br>
wl_protocol_logger_message::message->types[i] for argument<br>
wl_protocol_logger_message::arguments[i]. However, no such workaround<br>
exists to retrieve the wl_object's id.<br>
<br>
* <a href="https://github.com/KDAB/GammaRay" rel="noreferrer" target="_blank">https://github.com/KDAB/GammaRay</a> works around this problem by<br>
casting wl_argument::o to wl_resource* and using<br>
wl_resource_get_class() and wl_resource_get_id().<br>
<br>
    * This works because wl_resource's first member is wl_object, and<br>
wl_resource_get_class() and wl_resource_get_id() are implemented only<br>
by accessing that first member.<br>
    *  While comments in wl_resource indicate that the struct layout<br>
cannot be changed. It's unclear if that will be true forever.<br>
    * There is no guarantee that wl_resource_get_class() and<br>
wl_resource_get_id() won't start accessing members of wl_resource<br>
other than `object`. If they did, this technique could cause invalid<br>
memory access due to overflowing the size of wl_object.<br>
<br>
I believe these are my current options:<br>
<br>
A) Cast wl_object* to wl_resource* like GammaRay does. I'm<br>
uncomfortable with this, for the reasons above.<br>
<br>
B) Copy the definition of `struct wl_object` from wayland-private.h<br>
into my project and access `id` directly. This might be safer than (A)<br>
in practice, but I still don't like it.<br>
<br>
C) Submit a patch adding wl_object_get_class() and wl_object_get_id()<br>
accessor functions.<br>
<br>
Have I missed something? Any advice would be helpful.<br>
<br>
Best regards,<br>
Chloe<br>
</blockquote></div>