Path: blob/21.2-virgl/src/gallium/frontends/nine/nine_debug.c
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#include "nine_debug.h"2324#include <ctype.h>25#include "c11/threads.h"2627static const struct debug_named_value nine_debug_flags[] = {28{ "unknown", DBG_UNKNOWN, "IUnknown implementation." },29{ "adapter", DBG_ADAPTER, "ID3D9Adapter implementation." },30{ "overlay", DBG_OVERLAYEXTENSION, "IDirect3D9ExOverlayExtension implementation." },31{ "auth", DBG_AUTHENTICATEDCHANNEL, "IDirect3DAuthenticatedChannel9 implementation." },32{ "basetex", DBG_BASETEXTURE, "IDirect3DBaseTexture9 implementation." },33{ "crypto", DBG_CRYPTOSESSION, "IDirect3DCryptoSession9 implementation." },34{ "cubetex", DBG_CUBETEXTURE, "IDirect3DCubeTexture9 implementation." },35{ "device", DBG_DEVICE, "IDirect3DDevice9(Ex) implementation." },36{ "video", DBG_DEVICEVIDEO, "IDirect3DDeviceVideo9 implementation." },37{ "ibuf", DBG_INDEXBUFFER, "IDirect3DIndexBuffer9 implementation." },38{ "ps", DBG_PIXELSHADER, "IDirect3DPixelShader9 implementation." },39{ "query", DBG_QUERY, "IDirect3DQuery9 implementation." },40{ "res", DBG_RESOURCE, "IDirect3DResource9 implementation." },41{ "state", DBG_STATEBLOCK, "IDirect3DStateBlock9 implementation." },42{ "surf", DBG_SURFACE, "IDirect3DSurface9 implementation." },43{ "swap", DBG_SWAPCHAIN, "IDirect3DSwapChain9(Ex) implementation." },44{ "tex", DBG_TEXTURE, "IDirect3DTexture9 implementation." },45{ "vbuf", DBG_VERTEXBUFFER, "IDirect3DVertexBuffer9 implementation." },46{ "vdecl", DBG_VERTEXDECLARATION, "IDirect3DVertexDeclaration9 implementation." },47{ "vs", DBG_VERTEXSHADER, "IDirect3DVertexShader9 implementation." },48{ "3dsurf", DBG_VOLUME, "IDirect3DVolume9 implementation." },49{ "3dtex", DBG_VOLUMETEXTURE, "IDirect3DVolumeTexture9 implementation." },50{ "shader", DBG_SHADER, "Shader token stream translator." },51{ "ff", DBG_FF, "Fixed function emulation." },52{ "user", DBG_USER, "User errors, both fixable and unfixable." },53{ "error", DBG_ERROR, "Driver errors, always visible." },54{ "warn", DBG_WARN, "Driver warnings, always visible in debug builds." },55{ "tid", DBG_TID, "Display thread-ids." },56DEBUG_NAMED_VALUE_END57};5859void60_nine_debug_printf( unsigned long flag,61const char *func,62const char *fmt,63... )64{65static boolean first = TRUE;66static unsigned long dbg_flags = DBG_ERROR | DBG_WARN;67unsigned long tid = 0;6869if (first) {70first = FALSE;71dbg_flags |= debug_get_flags_option("NINE_DEBUG", nine_debug_flags, 0);72}7374#if defined(HAVE_PTHREAD)75if (dbg_flags & DBG_TID)76tid = (unsigned long)pthread_self();77#endif7879if (dbg_flags & flag) {80const char *f = func ? strrchr(func, '_') : NULL;81va_list ap;82/* inside a class this will print nine:tid:classinlowercase:func: while83* outside a class (rarely used) it will just print nine:tid:func84* the reason for lower case is simply to match the filenames, as it85* will also strip off the "Nine" */86if (f && strncmp(func, "Nine", 4) == 0) {87char klass[96]; /* no class name is this long */88char *ptr = klass;89for (func += 4; func != f; ++func) { *ptr++ = tolower(*func); }90*ptr = '\0';91if (tid)92_debug_printf("nine:0x%08lx:%s:%s: ", tid, klass, ++f);93else94_debug_printf("nine:%s:%s: ", klass, ++f);95} else if (func) {96if (tid)97_debug_printf("nine:0x%08lx:%s ", tid, func);98else99_debug_printf("nine:%s ", func);100}101102va_start(ap, fmt);103_debug_vprintf(fmt, ap);104va_end(ap);105}106}107108void109_nine_stub( const char *file,110const char *func,111unsigned line )112{113const char *r = strrchr(file, '/');114if (r == NULL) { r = strrchr(file, '\\'); }115_debug_printf("nine:%s:%d: %s STUB!\n", r ? ++r : file, line, func);116}117118119