X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglwrap.c;h=c70b308384b339888dc4ab4527fc7a86df4fa4dc;hb=ea3d851aa52e999b1c5a5fa52c97ff5019756c0e;hp=52c6552e1f5c0c007939e62f07a31e233ba8e587;hpb=03c86c2f632b642aa94f721e326787e91aa69c25;p=gldbg.git diff --git a/source/glwrap.c b/source/glwrap.c index 52c6552..c70b308 100644 --- a/source/glwrap.c +++ b/source/glwrap.c @@ -8,20 +8,27 @@ Distributed under the GPL #include #include #include +#include #include -#include +#include +#include +#include "breakpoint.h" +#include "functions.h" +#include "packet.h" -#define INTERNAL __attribute__((visibility("internal"))) +static unsigned char breakpoints[N_FUNCS] = { }; +static char break_any = 0; +static char hold = 0; -INTERNAL inline const char *get_lib_names(void) +static const char *get_lib_names(void) { const char *env = getenv("GLWRAP_LIBS"); if(env) return env; - return "libGL.so"; + return "libGL.so.1"; } -INTERNAL inline void *glsym(const char *name) +void *glsym(const char *name) { static void **gl_libs = NULL; unsigned i; @@ -75,127 +82,114 @@ INTERNAL inline void *glsym(const char *name) return NULL; } -INTERNAL char *buffer = 0; -INTERNAL char *write_pos; -INTERNAL struct iovec *iovecs = 0; -INTERNAL struct iovec *cur_vec; -INTERNAL unsigned length; - -INTERNAL inline void next_vec(void) +int get_out_fd(void) { - if(write_pos!=cur_vec->iov_base) + static int fd = -1; + + if(fd<0) { - cur_vec->iov_len = write_pos-(char *)cur_vec->iov_base; - length += cur_vec->iov_len; - ++cur_vec; - cur_vec->iov_base = write_pos; + const char *var = getenv("GLWRAP_FD"); + if(var) + fd = strtol(var, NULL, 0); + else + { + var = getenv("GLWRAP_FILE"); + if(var) + { + fd = open(var, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if(fd==-1) + { + fprintf(stderr, "Couldn't open dumpfile %s for output: %s", var, strerror(errno)); + abort(); + } + } + else + fd = 2; + } } -} -INTERNAL inline void write_bytes(const char *ptr, unsigned size) -{ - unsigned i; - for(i=0; iiov_base = (void *)data; - cur_vec->iov_len = size; - length += size; - ++cur_vec; - cur_vec->iov_base = write_pos; + unsigned short func; + + packet_read_short(pkt, (short *)&func); + switch(func) + { + case FUNC_GLDBREAK: receive_gldBreak(pkt); break; + case FUNC_GLDHOLD: receive_gldHold(pkt); break; + default:; + } } - else - write_int(0); } -INTERNAL inline void write_string(const char *s) +void tracepoint(unsigned short func, int flag) { - write_data(s, strlen(s)+1); -} + receive(); -INTERNAL inline void write_string_array(const char **sa, unsigned size) -{ - unsigned i; - size /= sizeof(const char *); - write_int(size); - for(i=0; iiov_base = write_pos; - length = 0; - write_int(0); - write_short(func); -} + pkt = packet_begin(FUNC_GLDBREAK); + packet_write_short(pkt, func); + packet_send(pkt, get_out_fd()); -INTERNAL inline void send_packet(void) -{ - static int fd = -1; - if(fd<0) - { - const char *var = getenv("GLWRAP_FD"); - if(var) - fd = strtol(var, NULL, 0); - else - fd = 2; + break_any = 0; + + while(1) + { + hold = 0; + raise(SIGTRAP); + receive(); + if(!hold) + break; + } } - next_vec(); - write_pos = buffer; - write_int(length); - writev(fd, iovecs, cur_vec-iovecs); }