debug: Use a function to print output that can be replaced by a different callback

This patch adds the infrastructure and replaces the debug calls to fprintf
by calls to vrend_printf that internally may be redirected.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Gert Wollny 6 years ago committed by Dave Airlie
parent 3e87ee63f7
commit 87a21038f7
  1. 26
      src/vrend_debug.c
  2. 9
      src/vrend_debug.h
  3. 2
      src/vrend_decode.c
  4. 14
      src/vrend_renderer.c

@ -162,3 +162,29 @@ int vrend_debug_can_override(void)
{ {
return vrend_debug_flags & dbg_allow_guest_override; return vrend_debug_flags & dbg_allow_guest_override;
} }
static
void vrend_default_debug_callback(const char *fmt, va_list va)
{
vfprintf(stderr, fmt, va);
}
static virgl_debug_callback_type debug_callback = vrend_default_debug_callback;
void vrend_printf(const char *fmt, ...)
{
if (debug_callback) {
va_list va;
va_start(va, fmt);
debug_callback(fmt, va);
va_end(va);
}
}
virgl_debug_callback_type vrend_set_debug_callback(virgl_debug_callback_type cb)
{
virgl_debug_callback_type retval = debug_callback;
debug_callback = cb;
return retval;
}

@ -26,6 +26,7 @@
#define vrend_debug_h #define vrend_debug_h
#include "virgl_protocol.h" #include "virgl_protocol.h"
#include <stdarg.h>
struct vrend_context; struct vrend_context;
void vrend_print_context_name(struct vrend_context *ctx); void vrend_print_context_name(struct vrend_context *ctx);
@ -63,12 +64,18 @@ unsigned vrend_debug(struct vrend_context *ctx, enum virgl_debug_flags flag);
void vrend_debug_add_flag(enum virgl_debug_flags flag); void vrend_debug_add_flag(enum virgl_debug_flags flag);
void vrend_printf(const char *fmt, ...);
typedef void (*virgl_debug_callback_type)(const char *fmt, va_list ap);
virgl_debug_callback_type vrend_set_debug_callback(virgl_debug_callback_type cb);
#ifndef NDEBUG #ifndef NDEBUG
#define VREND_DEBUG(flag, ctx, ...) \ #define VREND_DEBUG(flag, ctx, ...) \
if (vrend_debug(ctx, flag)) \ if (vrend_debug(ctx, flag)) \
do { \ do { \
vrend_print_context_name(ctx); \ vrend_print_context_name(ctx); \
fprintf(stderr, __VA_ARGS__); \ vrend_printf(__VA_ARGS__); \
} while (0) } while (0)
#define VREND_DEBUG_EXT(flag, ctx, X) \ #define VREND_DEBUG_EXT(flag, ctx, X) \

@ -796,7 +796,7 @@ static int vrend_decode_destroy_object(struct vrend_decode_ctx *ctx, int length)
VREND_DEBUG_EXT(dbg_object, ctx->grctx, VREND_DEBUG_EXT(dbg_object, ctx->grctx,
uint32_t obj = (get_buf_entry(ctx, 0) >> 8) & 0xFF; uint32_t obj = (get_buf_entry(ctx, 0) >> 8) & 0xFF;
fprintf(stderr, " DESTROY %-17s handle:0x%x\n", vrend_printf(" DESTROY %-17s handle:0x%x\n",
vrend_get_object_type_name(obj), handle)); vrend_get_object_type_name(obj), handle));
vrend_renderer_object_destroy(ctx->grctx, handle); vrend_renderer_object_destroy(ctx->grctx, handle);

@ -1894,7 +1894,7 @@ void debug_texture(const char *f, const struct vrend_resource *gt)
const struct pipe_resource *pr = &gt->base; const struct pipe_resource *pr = &gt->base;
#define PRINT_TARGET(X) case X: fprintf(stderr, #X); break #define PRINT_TARGET(X) case X: fprintf(stderr, #X); break
VREND_DEBUG_EXT(dbg_tex, NULL, VREND_DEBUG_EXT(dbg_tex, NULL,
fprintf(stderr, "%s: ", f); vrend_printf("%s: ", f);
switch (tgsitargettogltarget(pr->target, pr->nr_samples)) { switch (tgsitargettogltarget(pr->target, pr->nr_samples)) {
PRINT_TARGET(GL_TEXTURE_RECTANGLE_NV); PRINT_TARGET(GL_TEXTURE_RECTANGLE_NV);
PRINT_TARGET(GL_TEXTURE_1D); PRINT_TARGET(GL_TEXTURE_1D);
@ -1906,11 +1906,11 @@ void debug_texture(const char *f, const struct vrend_resource *gt)
PRINT_TARGET(GL_TEXTURE_CUBE_MAP); PRINT_TARGET(GL_TEXTURE_CUBE_MAP);
PRINT_TARGET(GL_TEXTURE_CUBE_MAP_ARRAY); PRINT_TARGET(GL_TEXTURE_CUBE_MAP_ARRAY);
default: default:
fprintf(stderr, "UNKNOWN"); vrend_printf("UNKNOWN");
} }
fprintf(stderr, " id:%d pipe_type:%d ms:%d format:%s size: %dx%dx%d mip:%d\n", vrend_printf(" id:%d pipe_type:%d ms:%d format:%s size: %dx%dx%d mip:%d\n",
gt->id, pr->target, pr->nr_samples, util_format_name(pr->format), gt->id, pr->target, pr->nr_samples, util_format_name(pr->format),
pr->width0, pr->height0, pr->depth0, pr->last_level); pr->width0, pr->height0, pr->depth0, pr->last_level);
); );
#undef PRINT_TARGET #undef PRINT_TARGET
} }
@ -8886,9 +8886,9 @@ unsigned vrend_context_has_debug_flag(struct vrend_context *ctx, enum virgl_debu
void vrend_print_context_name(struct vrend_context *ctx) void vrend_print_context_name(struct vrend_context *ctx)
{ {
if (ctx) if (ctx)
fprintf(stderr, "%s: ", ctx->debug_name); vrend_printf("%s: ", ctx->debug_name);
else else
fprintf(stderr, "HOST: "); vrend_printf("HOST: ");
} }
void vrend_renderer_destroy_sub_ctx(struct vrend_context *ctx, int sub_ctx_id) void vrend_renderer_destroy_sub_ctx(struct vrend_context *ctx, int sub_ctx_id)

Loading…
Cancel
Save