Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [ltt-dev] SystemTAP support in tracepoints
Date: Sun, 10 Apr 2011 13:44:44 -0400	[thread overview]
Message-ID: <20110410174444.GA30466@Krystal> (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




             reply	other threads:[~2011-04-10 17:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-10 17:44 Mathieu Desnoyers [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110410174444.GA30466@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox