all: libmallocwrap.so
libmallocwrap.so: mallocwrap.c
- gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl $(CFLAGS) -ldl -lmarkers -o libmallocwrap.so mallocwrap.c
+ gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl $(CFLAGS) -ldl -lmarkers -ltracectl -ltracing -o libmallocwrap.so mallocwrap.c
.PHONY: libmallocwrap.so
#include "marker.h"
-void *(*plibc_malloc)(size_t size) = NULL;
+//INTERCEPT_PROTOTYPE(void, malloc, size_t size)
+//INTERCEPT_TRACE("size %d", size)
+//INTERCEPT_CALL_ARGS(size)
+//INTERCEPT()
+//
+//#define INTERCEPT_FUNC(type, name, args...) \
+//__I_FUNC_TYPE(type) \
+//__I_FUNC_NAME(name) \
+//__I_FUNC_ARGS(args)
+//
+//#define INTERCEPT_TRACE(fmt, args...) \
+//#define __I_TRACE_FMT fmt \
+//#define __I_TRACE_ARGS args
+//
+//#define INTERCEPT_CALL_ARGS(args...) \
+//#define __I_CALL_ARGS args
+//
+//#define INTERCEPT() \
+//__I_FUNC_TYPE __I_FUNC_NAME(__I_FUNC_ARGS) \
+//{ \
+// static __I_FUNC_TYPE (*plibc_ ## __I_FUNC_NAME)(args) = NULL; \
+// \
+// if(plibc_ ## __I_FUNC_NAME == NULL) { \
+// plibc_ ## __I_FUNC_NAME = dlsym(RTLD_NEXT, "malloc"); \
+// if(plibc_ ## __I_FUNC_NAME == NULL) { \
+// fprintf(stderr, "mallocwrap: unable to find malloc\n"); \
+// return NULL; \
+// } \
+// } \
+// \
+// trace_mark(ust, __I_FUNC_NAME, __I_TRACE_FMT, __I_TRACE_ARGS); \
+// \
+// return plibc_ ## __I_FUNC_NAME (__I_CALL_ARGS); \
+//}
void *malloc(size_t size)
{
+ static void *(*plibc_malloc)(size_t size) = NULL;
+
+ void *retval;
+
if(plibc_malloc == NULL) {
plibc_malloc = dlsym(RTLD_NEXT, "malloc");
if(plibc_malloc == NULL) {
}
}
- trace_mark(ust, malloc, "%d", (int)size);
+ retval = plibc_malloc(size);
+
+ trace_mark(ust, malloc, "size %d ptr %p", (int)size, retval);
+
+ return retval;
+}
+
+void free(void *ptr)
+{
+ static void *(*plibc_free)(void *ptr) = NULL;
+
+ if(plibc_free == NULL) {
+ plibc_free = dlsym(RTLD_NEXT, "free");
+ if(plibc_free == NULL) {
+ fprintf(stderr, "mallocwrap: unable to find free\n");
+ return NULL;
+ }
+ }
+
+ trace_mark(ust, free, "%p", ptr);
- fprintf(stderr, "mallocating size %d\n", size);
- return plibc_malloc(size);
+ return plibc_free(ptr);
}
MARKER_LIB
/* FIXME: update just the loaded lib */
lib_update_markers();
- printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count);
+ DBG("just registered a markers section from %p and having %d markers", markers_start, markers_count);
return 0;
}
#define SOCKETDIRLEN sizeof(SOCKETDIR)
#define USTSIGNAL SIGIO
-#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args)
-#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args)
-#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args); fflush(stderr)
-#define PERROR(call) perror("usertrace: ERROR: " call)
-
#define MAX_MSG_SIZE (100)
#define MSG_NOTIF 1
#define MSG_REGISTER_NOTIF 2
consumer_channels[i].chan = chan;
- snprintf(tmp, sizeof(tmp), "trace/%s", chan->channel_name);
+ snprintf(tmp, sizeof(tmp), "trace/%s_0", chan->channel_name);
result = consumer_channels[i].fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00644);
if(result == -1) {
perror("open");
result = ltt_do_get_subbuf(rbuf, lttbuf, &consumed_old);
if(result < 0) {
- CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result));
+ DBG("ltt_do_get_subbuf: error: %s", strerror(-result));
}
else {
- CPRINTF("success!");
+ DBG("success!");
result = write(consumer_channels[i].fd, rbuf->buf_data + (consumed_old & (2 * 4096-1)), 4096);
ltt_do_put_subbuf(rbuf, lttbuf, consumed_old);
}
/* FIXME: wait for the consumer to be done */
- sleep(10);
+ sleep(3);
destroy_socket();
}
#ifndef USTERR_H
#define USTERR_H
-#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args)
-#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args)
-#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args)
-#define BUG(fmt, args...) fprintf(stderr, "usertrace: BUG: " fmt "\n", ## args)
+#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args); fflush(stderr)
+#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args); fflush(stderr)
+#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args); fflush(stderr)
+#define BUG(fmt, args...) fprintf(stderr, "usertrace: BUG: " fmt "\n", ## args); fflush(stderr)
#define PERROR(call) perror("usertrace: ERROR: " call)
#define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0)