3 This file is part of gldbg
4 Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
14 #define INTERNAL __attribute__((visibility("internal")))
16 INTERNAL inline const char *get_lib_names(void)
18 const char *env = getenv("GLWRAP_LIBS");
24 INTERNAL inline void *glsym(const char *name)
26 static void **gl_libs = NULL;
31 char *lib_names = strdup(get_lib_names());
35 for(i=0; lib_names[i]; ++i)
39 gl_libs = (void **)malloc((n_libs+1)*sizeof(void *));
44 if(lib_names[j]==':' || lib_names[j]==0)
46 int at_end = (lib_names[j]==0);
49 gl_libs[n_libs] = dlopen(lib_names+i, RTLD_NOW);
52 fprintf(stderr, "Could not open %s: %s\n", lib_names+i, dlerror());
68 for(i=0; gl_libs[i]; ++i)
70 void *sym = dlsym(gl_libs[i], name);
78 INTERNAL char *buffer = 0;
79 INTERNAL char *write_pos;
80 INTERNAL struct iovec *iovecs = 0;
81 INTERNAL struct iovec *cur_vec;
82 INTERNAL unsigned length;
84 INTERNAL inline void next_vec(void)
86 if(write_pos!=cur_vec->iov_base)
88 cur_vec->iov_len = write_pos-(char *)cur_vec->iov_base;
89 length += cur_vec->iov_len;
91 cur_vec->iov_base = write_pos;
95 INTERNAL inline void write_bytes(const char *ptr, unsigned size)
99 *write_pos++ = *ptr++;
102 INTERNAL inline void write_char(char v)
107 INTERNAL inline void write_short(short v)
109 write_bytes((char *)&v, sizeof(short));
112 INTERNAL inline void write_int(int v)
114 write_bytes((char *)&v, sizeof(int));
117 INTERNAL inline void write_long(long v)
119 write_bytes((char *)&v, sizeof(long));
122 INTERNAL inline void write_long_long(long long v)
124 write_bytes((char *)&v, sizeof(long long));
127 INTERNAL inline void write_float(float v)
129 write_bytes((char *)&v, sizeof(float));
132 INTERNAL inline void write_double(double v)
134 write_bytes((char *)&v, sizeof(double));
137 INTERNAL inline void write_pointer(const void *p)
139 write_bytes((char *)&p, sizeof(void *));
142 INTERNAL inline void write_data(const void *data, unsigned size)
148 cur_vec->iov_base = (void *)data;
149 cur_vec->iov_len = size;
152 cur_vec->iov_base = write_pos;
158 INTERNAL inline void write_string(const char *s)
160 write_data(s, strlen(s)+1);
163 INTERNAL inline void write_string_array(const char **sa, unsigned size)
166 size /= sizeof(const char *);
168 for(i=0; i<size; ++i)
172 INTERNAL inline void begin_packet(int func)
175 buffer = (char *)malloc(1024);
177 iovecs = (struct iovec *)malloc(16*sizeof(struct iovec));
180 cur_vec->iov_base = write_pos;
186 INTERNAL inline void send_packet(void)
191 const char *var = getenv("GLWRAP_FD");
193 fd = strtol(var, NULL, 0);
200 writev(fd, iovecs, cur_vec-iovecs);