[ltt-dev] SystemTAP support in tracepoints

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Sun Apr 10 13:44:44 EDT 2011


Hi Josh,

Following our discussion, I started to think about how we could be
support the systemtap breakpoint approach in UST tracepoints. I created
the following prototype that should let us handle a variable number of
arguments. The "args" I get here from the args... parameter would be
taken from the "TP_ARGS()" declaration in the TRACE_EVENT header. The
code below is really just to see if it is doable at all.

Comments are welcome,

Thanks,

Mathieu


#include <stdio.h>

#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))

#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)

#undef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

/* for x86 64 */
#define _ASM_PTR ".quad "

#define A(first, args...)				\
	"g" (first)
#define B(first, args...)				\
	"g" (first), A(args, 0)
#define C(first, args...)				\
	"g" (first), B(args, 0)
#define D(first, args...)				\
	"g" (first), C(args, 0)
#define E(first, args...)				\
	"g" (first), D(args, 0)

#define NARGS(args...)					\
	(sizeof(struct { unsigned char args; }) / sizeof(unsigned char))

#define _TRACE_GET_IP()					\
	".section __tracepoint_ip\"aw\"\n\t"		\
	_ASM_PTR "(1f)\n\t"				\
	".previous\n\t"					\
	"1:\n\t"

#define trace(name, args...)				\
do {							\
	__builtin_choose_expr((NARGS(args) == 0), 0, 0); \
	__builtin_choose_expr((NARGS(args) == 1), ({ asm volatile (_TRACE_GET_IP() : : A(args, 0) : "memory"); 0; }), 0); \
	__builtin_choose_expr((NARGS(args) == 2), ({ asm volatile (_TRACE_GET_IP() : : B(args, 0) : "memory"); 0; }), 0); \
	__builtin_choose_expr((NARGS(args) == 3), ({ asm volatile (_TRACE_GET_IP() : : C(args, 0) : "memory"); 0; }), 0); \
	__builtin_choose_expr((NARGS(args) == 4), ({ asm volatile (_TRACE_GET_IP() : : D(args, 0) : "memory"); 0; }), 0); \
	__builtin_choose_expr((NARGS(args) == 5), ({ asm volatile (_TRACE_GET_IP() : : E(args, 0) : "memory"); 0; }), 0); \
	BUILD_BUG_ON(NARGS(args) > 5); \
} while (0)

int main(int argc, char **argv)
{
	int one, two, three, four;
	unsigned long long five;

	trace(name, one, two, three, four, five);
	trace(name, one, two, three);
	trace(name, one);

	// error trace(name, one, two, three, four, five, six);
	// error trace(name, one, two, three, four, noexist);

	return 0;
}



-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list