Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] SystemTAP support in tracepoints
@ 2011-04-10 17:44 Mathieu Desnoyers
  2011-04-11 21:19 ` Josh Stone
  0 siblings, 1 reply; 14+ messages in thread
From: Mathieu Desnoyers @ 2011-04-10 17:44 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-04-13 17:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-10 17:44 [ltt-dev] SystemTAP support in tracepoints Mathieu Desnoyers
2011-04-11 21:19 ` Josh Stone
2011-04-11 22:29   ` Josh Stone
2011-04-12 16:57     ` Frank Ch. Eigler
2011-04-12 18:35     ` Mathieu Desnoyers
2011-04-12 18:45       ` Frank Ch. Eigler
2011-04-12 18:48         ` Mathieu Desnoyers
2011-04-12 18:59           ` Frank Ch. Eigler
2011-04-12 19:12           ` Mark Wielaard
2011-04-13 15:38             ` Mathieu Desnoyers
     [not found]             ` <BLU0-SMTP42E61B0C2D4283651878B896AA0@phx.gbl>
2011-04-13 16:17               ` Mark Wielaard
2011-04-13 16:58                 ` Mathieu Desnoyers
2011-04-13 17:24                   ` Josh Stone
2011-04-13 17:29                   ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox