]>
sourceware.org Git - systemtap.git/blob - includes/sys/sdt.h
1 /* <sys/sdt.h> - Systemtap static probe definition macros.
2 Copyright (C) 2010 Red Hat Inc.
4 This file is part of systemtap, and is free software in the public domain.
11 # define _SDT_PROBE(provider, name, n, arglist) \
12 _SDT_ASM_BODY(provider, name, _SDT_ASM_STRING_1, (_SDT_DEPAREN_##n arglist))
13 # define _SDT_ASM_1(x) x;
14 # define _SDT_ASM_2(a, b) a,b;
15 # define _SDT_ASM_3(a, b, c) a,b,c;
16 # define _SDT_ASM_5(a, b, c, d, e) a,b,c,d,e;
17 # define _SDT_ASM_STRING_1(x) .asciz #x;
18 # define _SDT_DEPAREN_0() /* empty */
19 # define _SDT_DEPAREN_1(a) a
20 # define _SDT_DEPAREN_2(a,b) a b
21 # define _SDT_DEPAREN_3(a,b,c) a b c
22 # define _SDT_DEPAREN_4(a,b,c,d) a b c d
23 # define _SDT_DEPAREN_5(a,b,c,d,e) a b c d e
24 # define _SDT_DEPAREN_6(a,b,c,d,e,f) a b c d e f
25 # define _SDT_DEPAREN_7(a,b,c,d,e,f,g) a b c d e f g
26 # define _SDT_DEPAREN_8(a,b,c,d,e,f,g,h) a b c d e f g h
27 # define _SDT_DEPAREN_9(a,b,c,d,e,f,g,h,i) a b c d e f g h i
28 # define _SDT_DEPAREN_10(a,b,c,d,e,f,g,h,i,j) a b c d e f g h i j
31 # define _SDT_PROBE(provider, name, n, arglist) \
32 __asm__ __volatile__ (_SDT_ASM_BODY(provider, name, _SDT_ASM_ARGS, (n)) \
33 :: _SDT_ASM_OPERANDS_##n arglist)
35 # define _SDT_ASM_1(x) _SDT_S(x)"\n"
36 # define _SDT_ASM_2(a, b) _SDT_S(a)","_SDT_S(b)"\n"
37 # define _SDT_ASM_3(a, b, c) _SDT_S(a)","_SDT_S(b)","_SDT_S(c)"\n"
38 # define _SDT_ASM_5(a, b, c, d, e) _SDT_S(a)","_SDT_S(b)","_SDT_S(c)","\
39 _SDT_S(d)","_SDT_S(e)"\n"
40 # define _SDT_ASM_ARGS(n) _SDT_ASM_STRING(_SDT_ASM_TEMPLATE_##n)
41 # define _SDT_ASM_STRING_1(x) _SDT_ASM_1(.asciz #x)
43 # define _SDT_ARGFMT(n) %c[_SDT_S##n]@_SDT_ARGTMPL(_SDT_A##n)
44 # define _SDT_ARG(n, x) \
45 [_SDT_S##n] "n" (((__typeof((x) + 0)) -1L > (__typeof((x) + 0)) 0 \
47 * (int) sizeof ((x) + 0)), \
48 [_SDT_A##n] "nor" ((x) + 0)
50 #define _SDT_ASM_STRING(x) _SDT_ASM_STRING_1(x)
52 #if defined __powerpc__ || defined __powerpc64__
53 # define _SDT_ARGTMPL(id) %I[id]%[id]
55 # define _SDT_ARGTMPL(id) %[id]
59 # define _SDT_ASM_ADDR .8byte
61 # define _SDT_ASM_ADDR .4byte
64 /* The ia64 and s390 nop instructions take an argument. */
65 #if defined(__ia64__) || defined(__s390__) || defined(__s390x__)
66 #define _SDT_NOP nop 0
71 #define _SDT_NOTE_NAME "stapsdt"
72 #define _SDT_NOTE_TYPE 3
74 /* If the assembler supports the necessary feature, then we can play
75 nice with code in COMDAT sections, which comes up in C++ code.
76 Without that assembler support, some combinations of probe placements
77 in certain kinds of C++ code may produce link-time errors. */
78 #include "sdt-config.h"
79 #if _SDT_ASM_SECTION_AUTOGROUP_SUPPORT
80 # define _SDT_ASM_AUTOGROUP "?"
82 # define _SDT_ASM_AUTOGROUP ""
85 #define _SDT_ASM_BODY(provider, name, pack_args, args) \
86 _SDT_ASM_1(990: _SDT_NOP) \
87 _SDT_ASM_3( .pushsection .note.stapsdt,_SDT_ASM_AUTOGROUP,"note") \
88 _SDT_ASM_1( .balign 4) \
89 _SDT_ASM_3( .4byte 992f-991f, 994f-993f, _SDT_NOTE_TYPE) \
90 _SDT_ASM_1(991: .asciz _SDT_NOTE_NAME) \
91 _SDT_ASM_1(992: .balign 4) \
92 _SDT_ASM_1(993: _SDT_ASM_ADDR 990b) \
93 _SDT_ASM_1( _SDT_ASM_ADDR _.stapsdt.base) \
94 _SDT_SEMAPHORE(provider,name) \
95 _SDT_ASM_STRING(provider) \
96 _SDT_ASM_STRING(name) \
98 _SDT_ASM_1(994: .balign 4) \
99 _SDT_ASM_1( .popsection) \
100 _SDT_ASM_1(.ifndef _.stapsdt.base) \
101 _SDT_ASM_5( .pushsection .stapsdt.base,"aG","progbits", \
102 .stapsdt.base,comdat) \
103 _SDT_ASM_1( .weak _.stapsdt.base) \
104 _SDT_ASM_1( .hidden _.stapsdt.base) \
105 _SDT_ASM_1( _.stapsdt.base: .space 1) \
106 _SDT_ASM_2( .size _.stapsdt.base, 1) \
107 _SDT_ASM_1( .popsection) \
110 #if defined _SDT_HAS_SEMAPHORES
111 #define _SDT_SEMAPHORE(p,n) _SDT_ASM_1( _SDT_ASM_ADDR p##_##n##_semaphore)
113 #define _SDT_SEMAPHORE(p,n) _SDT_ASM_1( _SDT_ASM_ADDR 0)
116 #define _SDT_ASM_TEMPLATE_0 /* no arguments */
117 #define _SDT_ASM_TEMPLATE_1 _SDT_ARGFMT(1)
118 #define _SDT_ASM_TEMPLATE_2 _SDT_ASM_TEMPLATE_1 _SDT_ARGFMT(2)
119 #define _SDT_ASM_TEMPLATE_3 _SDT_ASM_TEMPLATE_2 _SDT_ARGFMT(3)
120 #define _SDT_ASM_TEMPLATE_4 _SDT_ASM_TEMPLATE_3 _SDT_ARGFMT(4)
121 #define _SDT_ASM_TEMPLATE_5 _SDT_ASM_TEMPLATE_4 _SDT_ARGFMT(5)
122 #define _SDT_ASM_TEMPLATE_6 _SDT_ASM_TEMPLATE_5 _SDT_ARGFMT(6)
123 #define _SDT_ASM_TEMPLATE_7 _SDT_ASM_TEMPLATE_6 _SDT_ARGFMT(7)
124 #define _SDT_ASM_TEMPLATE_8 _SDT_ASM_TEMPLATE_7 _SDT_ARGFMT(8)
125 #define _SDT_ASM_TEMPLATE_9 _SDT_ASM_TEMPLATE_8 _SDT_ARGFMT(9)
126 #define _SDT_ASM_TEMPLATE_10 _SDT_ASM_TEMPLATE_9 _SDT_ARGFMT(10)
127 #define _SDT_ASM_OPERANDS_0() [__sdt_dummy] "g" (0)
128 #define _SDT_ASM_OPERANDS_1(arg1) _SDT_ARG(1, arg1)
129 #define _SDT_ASM_OPERANDS_2(arg1, arg2) \
130 _SDT_ASM_OPERANDS_1(arg1), _SDT_ARG(2, arg2)
131 #define _SDT_ASM_OPERANDS_3(arg1, arg2, arg3) \
132 _SDT_ASM_OPERANDS_2(arg1, arg2), _SDT_ARG(3, arg3)
133 #define _SDT_ASM_OPERANDS_4(arg1, arg2, arg3, arg4) \
134 _SDT_ASM_OPERANDS_3(arg1, arg2, arg3), _SDT_ARG(4, arg4)
135 #define _SDT_ASM_OPERANDS_5(arg1, arg2, arg3, arg4, arg5) \
136 _SDT_ASM_OPERANDS_4(arg1, arg2, arg3, arg4), _SDT_ARG(5, arg5)
137 #define _SDT_ASM_OPERANDS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
138 _SDT_ASM_OPERANDS_5(arg1, arg2, arg3, arg4, arg5), _SDT_ARG(6, arg6)
139 #define _SDT_ASM_OPERANDS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
140 _SDT_ASM_OPERANDS_6(arg1, arg2, arg3, arg4, arg5, arg6), _SDT_ARG(7, arg7)
141 #define _SDT_ASM_OPERANDS_8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
142 _SDT_ASM_OPERANDS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7), \
144 #define _SDT_ASM_OPERANDS_9(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) \
145 _SDT_ASM_OPERANDS_8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), \
147 #define _SDT_ASM_OPERANDS_10(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
148 _SDT_ASM_OPERANDS_9(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), \
151 /* These macros can be used in C, C++, or assembly code.
152 In assembly code the arguments should use normal assembly operand syntax. */
154 #define STAP_PROBE(provider, name) \
155 _SDT_PROBE(provider, name, 0, ())
156 #define STAP_PROBE1(provider, name, arg1) \
157 _SDT_PROBE(provider, name, 1, (arg1))
158 #define STAP_PROBE2(provider, name, arg1, arg2) \
159 _SDT_PROBE(provider, name, 2, (arg1, arg2))
160 #define STAP_PROBE3(provider, name, arg1, arg2, arg3) \
161 _SDT_PROBE(provider, name, 3, (arg1, arg2, arg3))
162 #define STAP_PROBE4(provider, name, arg1, arg2, arg3, arg4) \
163 _SDT_PROBE(provider, name, 4, (arg1, arg2, arg3, arg4))
164 #define STAP_PROBE5(provider, name, arg1, arg2, arg3, arg4, arg5) \
165 _SDT_PROBE(provider, name, 5, (arg1, arg2, arg3, arg4, arg5))
166 #define STAP_PROBE6(provider, name, arg1, arg2, arg3, arg4, arg5, arg6) \
167 _SDT_PROBE(provider, name, 6, (arg1, arg2, arg3, arg4, arg5, arg6))
168 #define STAP_PROBE7(provider, name, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
169 _SDT_PROBE(provider, name, 7, (arg1, arg2, arg3, arg4, arg5, arg6, arg7))
170 #define STAP_PROBE8(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) \
171 _SDT_PROBE(provider, name, 8, (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8))
172 #define STAP_PROBE9(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
173 _SDT_PROBE(provider, name, 9, (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
174 #define STAP_PROBE10(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
175 _SDT_PROBE(provider, name, 10, \
176 (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10))
178 /* These macros are for use in asm statements. You must compile
179 with -std=gnu99 or -std=c99 to use the STAP_PROBE_ASM macro.
181 The STAP_PROBE_ASM macro generates a quoted string to be used in the
182 template portion of the asm statement, concatenated with strings that
183 contain the actual assembly code around the probe site.
188 STAP_PROBE_ASM(provider, fooprobe, %eax 4(%esi))
191 emits the assembly code for "before\nafter", with a probe in between.
192 The probe arguments are the %eax register, and the value of the memory
193 word located 4 bytes past the address in the %esi register. Note that
194 because this is a simple asm, not a GNU C extended asm statement, these
195 % characters do not need to be doubled to generate literal %reg names.
197 In a GNU C extended asm statement, the probe arguments can be specified
198 using the macro STAP_PROBE_ASM_TEMPLATE(n) for n arguments. The paired
199 macro STAP_PROBE_ASM_OPERANDS gives the C values of these probe arguments,
200 and appears in the input operand list of the asm statement. For example:
202 asm ("someinsn %0,%1\n" // %0 is output operand, %1 is input operand
203 STAP_PROBE_ASM(provider, fooprobe, STAP_PROBE_ASM_TEMPLATE(3))
204 "otherinsn %[namedarg]"
206 : "g" (some_value), [namedarg] "i" (1234),
207 STAP_PROBE_ASM_OPERANDS(3, some_value, some_ptr->field, 1234));
209 This is just like writing:
211 STAP_PROBE3(provider, fooprobe, some_value, some_ptr->field, 1234));
213 but the probe site is right between "someinsn" and "otherinsn".
215 The probe arguments in STAP_PROBE_ASM can be given as assembly
216 operands instead, even inside a GNU C extended asm statement.
217 Note that these can use operand templates like %0 or %[name],
218 and likewise they must write %%reg for a literal operand of %reg. */
220 #if __STDC_VERSION__ >= 199901L
221 # define STAP_PROBE_ASM(provider, name, ...) \
222 _SDT_ASM_BODY(provider, name, _SDT_ASM_STRING, (__VA_ARGS__))
223 # define STAP_PROBE_ASM_OPERANDS(n, ...) _SDT_ASM_OPERANDS_##n(__VA_ARGS__)
225 # define STAP_PROBE_ASM(provider, name, args) \
226 _SDT_ASM_BODY(provider, name, _SDT_ASM_STRING, (args))
228 #define STAP_PROBE_ASM_TEMPLATE(n) _SDT_ASM_TEMPLATE_##n
231 /* DTrace compatible macro names. */
232 #define DTRACE_PROBE(provider,probe) \
233 STAP_PROBE(provider,probe)
234 #define DTRACE_PROBE1(provider,probe,parm1) \
235 STAP_PROBE1(provider,probe,parm1)
236 #define DTRACE_PROBE2(provider,probe,parm1,parm2) \
237 STAP_PROBE2(provider,probe,parm1,parm2)
238 #define DTRACE_PROBE3(provider,probe,parm1,parm2,parm3) \
239 STAP_PROBE3(provider,probe,parm1,parm2,parm3)
240 #define DTRACE_PROBE4(provider,probe,parm1,parm2,parm3,parm4) \
241 STAP_PROBE4(provider,probe,parm1,parm2,parm3,parm4)
242 #define DTRACE_PROBE5(provider,probe,parm1,parm2,parm3,parm4,parm5) \
243 STAP_PROBE5(provider,probe,parm1,parm2,parm3,parm4,parm5)
244 #define DTRACE_PROBE6(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6) \
245 STAP_PROBE6(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6)
246 #define DTRACE_PROBE7(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7) \
247 STAP_PROBE7(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7)
248 #define DTRACE_PROBE8(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8) \
249 STAP_PROBE8(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8)
250 #define DTRACE_PROBE9(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9) \
251 STAP_PROBE9(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9)
252 #define DTRACE_PROBE10(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10) \
253 STAP_PROBE10(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10)
256 #endif /* sys/sdt.h */
This page took 0.046214 seconds and 6 git commands to generate.