debug: Fix printing of new ids

The client side closure traces have incorrect object ids for new server
generated objects. This is because create_proxies() overwrites the id in
'n' type arguments by storing a pointer to the actual object in the 'o'
field of the union.

Getting back to an id from this pointer requires accessing a structure
that isn't visible outside of wayland-client.c.

Add a function pointer to fish the correct value out of the argument and
pass it to wl_closure_print.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2021-08-24 17:08:51 -05:00 committed by Daniel Stone
parent 9c05e6c475
commit ca893075ef
4 changed files with 29 additions and 9 deletions

View file

@ -1264,13 +1264,14 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection)
void void
wl_closure_print(struct wl_closure *closure, struct wl_object *target, wl_closure_print(struct wl_closure *closure, struct wl_object *target,
int send, int discarded) int send, int discarded, uint32_t (*n_parse)(union wl_argument *arg))
{ {
int i; int i;
struct argument_details arg; struct argument_details arg;
const char *signature = closure->message->signature; const char *signature = closure->message->signature;
struct timespec tp; struct timespec tp;
unsigned int time; unsigned int time;
uint32_t nval;
clock_gettime(CLOCK_REALTIME, &tp); clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
@ -1322,12 +1323,17 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
fprintf(stderr, "nil"); fprintf(stderr, "nil");
break; break;
case 'n': case 'n':
if (n_parse)
nval = n_parse(&closure->args[i]);
else
nval = closure->args[i].n;
fprintf(stderr, "new id %s@", fprintf(stderr, "new id %s@",
(closure->message->types[i]) ? (closure->message->types[i]) ?
closure->message->types[i]->name : closure->message->types[i]->name :
"[unknown]"); "[unknown]");
if (closure->args[i].n != 0) if (nval != 0)
fprintf(stderr, "%u", closure->args[i].n); fprintf(stderr, "%u", nval);
else else
fprintf(stderr, "nil"); fprintf(stderr, "nil");
break; break;

View file

@ -847,7 +847,7 @@ wl_proxy_marshal_array_flags(struct wl_proxy *proxy, uint32_t opcode,
} }
if (debug_client) if (debug_client)
wl_closure_print(closure, &proxy->object, true, false); wl_closure_print(closure, &proxy->object, true, false, NULL);
if (wl_closure_send(closure, proxy->display->connection)) { if (wl_closure_send(closure, proxy->display->connection)) {
wl_log("Error sending request: %s\n", strerror(errno)); wl_log("Error sending request: %s\n", strerror(errno));
@ -1531,6 +1531,19 @@ queue_event(struct wl_display *display, int len)
return size; return size;
} }
static uint32_t
id_from_object(union wl_argument *arg)
{
struct wl_proxy *proxy;
if (arg->o) {
proxy = (struct wl_proxy *)arg->o;
return proxy->object.id;
}
return 0;
}
static void static void
dispatch_event(struct wl_display *display, struct wl_event_queue *queue) dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
{ {
@ -1550,7 +1563,7 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED); proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED);
if (proxy_destroyed) { if (proxy_destroyed) {
if (debug_client) if (debug_client)
wl_closure_print(closure, &proxy->object, false, true); wl_closure_print(closure, &proxy->object, false, true, id_from_object);
destroy_queued_closure(closure); destroy_queued_closure(closure);
return; return;
} }
@ -1559,13 +1572,13 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
if (proxy->dispatcher) { if (proxy->dispatcher) {
if (debug_client) if (debug_client)
wl_closure_print(closure, &proxy->object, false, false); wl_closure_print(closure, &proxy->object, false, false, id_from_object);
wl_closure_dispatch(closure, proxy->dispatcher, wl_closure_dispatch(closure, proxy->dispatcher,
&proxy->object, opcode); &proxy->object, opcode);
} else if (proxy->object.implementation) { } else if (proxy->object.implementation) {
if (debug_client) if (debug_client)
wl_closure_print(closure, &proxy->object, false, false); wl_closure_print(closure, &proxy->object, false, false, id_from_object);
wl_closure_invoke(closure, WL_CLOSURE_INVOKE_CLIENT, wl_closure_invoke(closure, WL_CLOSURE_INVOKE_CLIENT,
&proxy->object, opcode, proxy->user_data); &proxy->object, opcode, proxy->user_data);

View file

@ -211,7 +211,8 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection);
void void
wl_closure_print(struct wl_closure *closure, wl_closure_print(struct wl_closure *closure,
struct wl_object *target, int send, int discarded); struct wl_object *target, int send, int discarded,
uint32_t (*n_parse)(union wl_argument *arg));
void void
wl_closure_destroy(struct wl_closure *closure); wl_closure_destroy(struct wl_closure *closure);

View file

@ -156,7 +156,7 @@ log_closure(struct wl_resource *resource,
struct wl_protocol_logger_message message; struct wl_protocol_logger_message message;
if (debug_server) if (debug_server)
wl_closure_print(closure, object, send, false); wl_closure_print(closure, object, send, false, NULL);
if (!wl_list_empty(&display->protocol_loggers)) { if (!wl_list_empty(&display->protocol_loggers)) {
message.resource = resource; message.resource = resource;