From: Mikko Rasa Date: Wed, 24 Nov 2010 15:03:17 +0000 (+0000) Subject: Add gldBreak callback to gldecoder X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=17fa41a4dfef75ce671bf71306929d1f5b91025a;p=gldbg.git Add gldBreak callback to gldecoder Add a callback for otherwise unhandled functions --- diff --git a/source/gldecoder.c b/source/gldecoder.c index f5540c0..81b1a43 100644 --- a/source/gldecoder.c +++ b/source/gldecoder.c @@ -44,17 +44,14 @@ int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len) packet_read_short(pkt, (short *)&func); - if(dec) - { - int ret = 0; - - if(func&0x8000) - ret = decode_gldfunc(dec, func, pkt); - else - ret = decode_func(dec, func, pkt); - if(ret<0) - return -1; - } + int ret = 0; + + if(func&0x8000) + ret = decode_gldfunc(dec, func, pkt); + else + ret = decode_func(dec, func, pkt); + if(ret<0) + return -1; return len; } @@ -70,6 +67,18 @@ static void decode_gldError(GlDecoder *dec, GlPacket *pkt) packet_read_int(pkt, (int *)&code); if(dec->gldError) dec->gldError(dec->user_data, code); + else if(dec->unhandled) + dec->unhandled(dec->user_data, FUNC_GLDERROR); +} + +static void decode_gldBreak(GlDecoder *dec, GlPacket *pkt) +{ + unsigned short func; + packet_read_short(pkt, (short *)&func); + if(dec->gldBreak) + dec->gldBreak(dec->user_data, func); + else if(dec->unhandled) + dec->unhandled(dec->user_data, FUNC_GLDBREAK); } static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt) @@ -77,6 +86,7 @@ static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt) switch(func) { case FUNC_GLDERROR: decode_gldError(dec, pkt); break; + case FUNC_GLDBREAK: decode_gldBreak(dec, pkt); break; default: return -1; } return 0; diff --git a/source/gldecoder.funcs.t b/source/gldecoder.funcs.t index d4433aa..98add04 100644 --- a/source/gldecoder.funcs.t +++ b/source/gldecoder.funcs.t @@ -24,6 +24,8 @@ if ret.ctype!="void": for p in params: w(', p_%s', p.name) wl(');') +wl(' else if(dec->unhandled)') +wl(' dec->unhandled(dec->user_data, FUNC_%s);', func.name.upper()) wl(' return 0;') wl('}') :static int decode_func(GlDecoder *dec, unsigned short func, GlPacket *pkt) diff --git a/source/gldecoder.struct.t b/source/gldecoder.struct.t index 5b46aca..cc146cc 100644 --- a/source/gldecoder.struct.t +++ b/source/gldecoder.struct.t @@ -10,4 +10,6 @@ for p in params: w(', %s', p.ctype) wl(');') : void (*gldError)(void *, GLenum); +: void (*gldBreak)(void *, unsigned short); +: void (*unhandled)(void *, unsigned short); :} GlDecoder; diff --git a/source/glprint.c b/source/glprint.c index 8dacdb3..e90c0e3 100644 --- a/source/glprint.c +++ b/source/glprint.c @@ -24,6 +24,7 @@ typedef struct sGlPrintData static void init_print(GlDecoder *); static void glprint_free(void *); static void print_gldError(void *, GLenum); +static void print_unhandled(void *, unsigned short); GlDecoder *glprint_new(char *buffer, unsigned bufsize) { @@ -45,6 +46,7 @@ GlDecoder *glprint_new(char *buffer, unsigned bufsize) init_print(dec); dec->gldError = print_gldError; + dec->unhandled = print_unhandled; return dec; } @@ -136,3 +138,9 @@ static void print_gldError(void *user_data, GLenum code) GlPrintData *gpd = (GlPrintData *)user_data; snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode")); } + +static void print_unhandled(void *user_data, unsigned short func) +{ + GlPrintData *gpd = (GlPrintData *)user_data; + gpd->buffer[0] = 0; +} diff --git a/source/tracer.cpp b/source/tracer.cpp index 8aa12de..9f703f1 100644 --- a/source/tracer.cpp +++ b/source/tracer.cpp @@ -54,7 +54,11 @@ void Tracer::decode(const char *data, unsigned len) int ret = glprint->decode(data, len); if(ret>=0) - IO::print(*out, "%s\n", glprint->get_buffer()); + { + const char *buf = glprint->get_buffer(); + if(buf[0]) + IO::print(*out, "%s\n", buf); + } } void Tracer::cmd_trace(const string &args)