sdt.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /* <sys/sdt.h> - Systemtap static probe definition macros.
  2. This file is dedicated to the public domain, pursuant to CC0
  3. (https://creativecommons.org/publicdomain/zero/1.0/)
  4. */
  5. #ifndef _SYS_SDT_H
  6. #define _SYS_SDT_H 1
  7. /*
  8. This file defines a family of macros
  9. STAP_PROBEn(op1, ..., opn)
  10. that emit a nop into the instruction stream, and some data into an auxiliary
  11. note section. The data in the note section describes the operands, in terms
  12. of size and location. Each location is encoded as assembler operand string.
  13. Consumer tools such as gdb or systemtap insert breakpoints on top of
  14. the nop, and decode the location operand-strings, like an assembler,
  15. to find the values being passed.
  16. The operand strings are selected by the compiler for each operand.
  17. They are constrained by gcc inline-assembler codes. The default is:
  18. #define STAP_SDT_ARG_CONSTRAINT nor
  19. This is a good default if the operands tend to be integral and
  20. moderate in number (smaller than number of registers). In other
  21. cases, the compiler may report "'asm' requires impossible reload" or
  22. similar. In this case, consider simplifying the macro call (fewer
  23. and simpler operands), reduce optimization, or override the default
  24. constraints string via:
  25. #define STAP_SDT_ARG_CONSTRAINT g
  26. #include <sys/sdt.h>
  27. See also:
  28. https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
  29. https://gcc.gnu.org/onlinedocs/gcc/Constraints.html
  30. */
  31. #ifdef __ASSEMBLER__
  32. # define _SDT_PROBE(provider, name, n, arglist) \
  33. _SDT_ASM_BODY(provider, name, _SDT_ASM_SUBSTR_1, (_SDT_DEPAREN_##n arglist)) \
  34. _SDT_ASM_BASE
  35. # define _SDT_ASM_1(x) x;
  36. # define _SDT_ASM_2(a, b) a,b;
  37. # define _SDT_ASM_3(a, b, c) a,b,c;
  38. # define _SDT_ASM_5(a, b, c, d, e) a,b,c,d,e;
  39. # define _SDT_ASM_STRING_1(x) .asciz #x;
  40. # define _SDT_ASM_SUBSTR_1(x) .ascii #x;
  41. # define _SDT_DEPAREN_0() /* empty */
  42. # define _SDT_DEPAREN_1(a) a
  43. # define _SDT_DEPAREN_2(a,b) a b
  44. # define _SDT_DEPAREN_3(a,b,c) a b c
  45. # define _SDT_DEPAREN_4(a,b,c,d) a b c d
  46. # define _SDT_DEPAREN_5(a,b,c,d,e) a b c d e
  47. # define _SDT_DEPAREN_6(a,b,c,d,e,f) a b c d e f
  48. # define _SDT_DEPAREN_7(a,b,c,d,e,f,g) a b c d e f g
  49. # define _SDT_DEPAREN_8(a,b,c,d,e,f,g,h) a b c d e f g h
  50. # define _SDT_DEPAREN_9(a,b,c,d,e,f,g,h,i) a b c d e f g h i
  51. # define _SDT_DEPAREN_10(a,b,c,d,e,f,g,h,i,j) a b c d e f g h i j
  52. # define _SDT_DEPAREN_11(a,b,c,d,e,f,g,h,i,j,k) a b c d e f g h i j k
  53. # define _SDT_DEPAREN_12(a,b,c,d,e,f,g,h,i,j,k,l) a b c d e f g h i j k l
  54. #else
  55. #if defined _SDT_HAS_SEMAPHORES
  56. #define _SDT_NOTE_SEMAPHORE_USE(provider, name) \
  57. __asm__ __volatile__ ("" :: "m" (provider##_##name##_semaphore));
  58. #else
  59. #define _SDT_NOTE_SEMAPHORE_USE(provider, name)
  60. #endif
  61. # define _SDT_PROBE(provider, name, n, arglist) \
  62. do { \
  63. _SDT_NOTE_SEMAPHORE_USE(provider, name); \
  64. __asm__ __volatile__ (_SDT_ASM_BODY(provider, name, _SDT_ASM_ARGS, (n)) \
  65. :: _SDT_ASM_OPERANDS_##n arglist); \
  66. __asm__ __volatile__ (_SDT_ASM_BASE); \
  67. } while (0)
  68. # define _SDT_S(x) #x
  69. # define _SDT_ASM_1(x) _SDT_S(x) "\n"
  70. # define _SDT_ASM_2(a, b) _SDT_S(a) "," _SDT_S(b) "\n"
  71. # define _SDT_ASM_3(a, b, c) _SDT_S(a) "," _SDT_S(b) "," \
  72. _SDT_S(c) "\n"
  73. # define _SDT_ASM_5(a, b, c, d, e) _SDT_S(a) "," _SDT_S(b) "," \
  74. _SDT_S(c) "," _SDT_S(d) "," \
  75. _SDT_S(e) "\n"
  76. # define _SDT_ASM_ARGS(n) _SDT_ASM_TEMPLATE_##n
  77. # define _SDT_ASM_STRING_1(x) _SDT_ASM_1(.asciz #x)
  78. # define _SDT_ASM_SUBSTR_1(x) _SDT_ASM_1(.ascii #x)
  79. # define _SDT_ARGFMT(no) _SDT_ASM_1(_SDT_SIGN %n[_SDT_S##no]) \
  80. _SDT_ASM_1(_SDT_SIZE %n[_SDT_S##no]) \
  81. _SDT_ASM_1(_SDT_TYPE %n[_SDT_S##no]) \
  82. _SDT_ASM_SUBSTR(_SDT_ARGTMPL(_SDT_A##no))
  83. # ifndef STAP_SDT_ARG_CONSTRAINT
  84. # if defined __powerpc__
  85. # define STAP_SDT_ARG_CONSTRAINT nZr
  86. # elif defined __arm__
  87. # define STAP_SDT_ARG_CONSTRAINT g
  88. # elif defined __loongarch__
  89. # define STAP_SDT_ARG_CONSTRAINT nmr
  90. # else
  91. # define STAP_SDT_ARG_CONSTRAINT nor
  92. # endif
  93. # endif
  94. # define _SDT_STRINGIFY(x) #x
  95. # define _SDT_ARG_CONSTRAINT_STRING(x) _SDT_STRINGIFY(x)
  96. /* _SDT_S encodes the size and type as 0xSSTT which is decoded by the assembler
  97. macros _SDT_SIZE and _SDT_TYPE */
  98. # define _SDT_ARG(n, x) \
  99. [_SDT_S##n] "n" ((_SDT_ARGSIGNED (x) ? (int)-1 : 1) * (-(((int) _SDT_ARGSIZE (x)) << 8) + (-(0x7f & __builtin_classify_type (x))))), \
  100. [_SDT_A##n] _SDT_ARG_CONSTRAINT_STRING (STAP_SDT_ARG_CONSTRAINT) (_SDT_ARGVAL (x))
  101. #endif
  102. #define _SDT_ASM_STRING(x) _SDT_ASM_STRING_1(x)
  103. #define _SDT_ASM_SUBSTR(x) _SDT_ASM_SUBSTR_1(x)
  104. #define _SDT_ARGARRAY(x) (__builtin_classify_type (x) == 14 \
  105. || __builtin_classify_type (x) == 5)
  106. #ifdef __cplusplus
  107. # define _SDT_ARGSIGNED(x) (!_SDT_ARGARRAY (x) \
  108. && __sdt_type<__typeof (x)>::__sdt_signed)
  109. # define _SDT_ARGSIZE(x) (_SDT_ARGARRAY (x) \
  110. ? sizeof (void *) : sizeof (x))
  111. # define _SDT_ARGVAL(x) (x)
  112. # include <cstddef>
  113. template<typename __sdt_T>
  114. struct __sdt_type
  115. {
  116. static const bool __sdt_signed = false;
  117. };
  118. #define __SDT_ALWAYS_SIGNED(T) \
  119. template<> struct __sdt_type<T> { static const bool __sdt_signed = true; };
  120. #define __SDT_COND_SIGNED(T,CT) \
  121. template<> struct __sdt_type<T> { static const bool __sdt_signed = ((CT)(-1) < 1); };
  122. __SDT_ALWAYS_SIGNED(signed char)
  123. __SDT_ALWAYS_SIGNED(short)
  124. __SDT_ALWAYS_SIGNED(int)
  125. __SDT_ALWAYS_SIGNED(long)
  126. __SDT_ALWAYS_SIGNED(long long)
  127. __SDT_ALWAYS_SIGNED(volatile signed char)
  128. __SDT_ALWAYS_SIGNED(volatile short)
  129. __SDT_ALWAYS_SIGNED(volatile int)
  130. __SDT_ALWAYS_SIGNED(volatile long)
  131. __SDT_ALWAYS_SIGNED(volatile long long)
  132. __SDT_ALWAYS_SIGNED(const signed char)
  133. __SDT_ALWAYS_SIGNED(const short)
  134. __SDT_ALWAYS_SIGNED(const int)
  135. __SDT_ALWAYS_SIGNED(const long)
  136. __SDT_ALWAYS_SIGNED(const long long)
  137. __SDT_ALWAYS_SIGNED(const volatile signed char)
  138. __SDT_ALWAYS_SIGNED(const volatile short)
  139. __SDT_ALWAYS_SIGNED(const volatile int)
  140. __SDT_ALWAYS_SIGNED(const volatile long)
  141. __SDT_ALWAYS_SIGNED(const volatile long long)
  142. __SDT_COND_SIGNED(char, char)
  143. __SDT_COND_SIGNED(wchar_t, wchar_t)
  144. __SDT_COND_SIGNED(volatile char, char)
  145. __SDT_COND_SIGNED(volatile wchar_t, wchar_t)
  146. __SDT_COND_SIGNED(const char, char)
  147. __SDT_COND_SIGNED(const wchar_t, wchar_t)
  148. __SDT_COND_SIGNED(const volatile char, char)
  149. __SDT_COND_SIGNED(const volatile wchar_t, wchar_t)
  150. #if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
  151. /* __SDT_COND_SIGNED(char16_t) */
  152. /* __SDT_COND_SIGNED(char32_t) */
  153. #endif
  154. template<typename __sdt_E>
  155. struct __sdt_type<__sdt_E[]> : public __sdt_type<__sdt_E *> {};
  156. template<typename __sdt_E, size_t __sdt_N>
  157. struct __sdt_type<__sdt_E[__sdt_N]> : public __sdt_type<__sdt_E *> {};
  158. #elif !defined(__ASSEMBLER__)
  159. __extension__ extern unsigned long long __sdt_unsp;
  160. # define _SDT_ARGINTTYPE(x) \
  161. __typeof (__builtin_choose_expr (((__builtin_classify_type (x) \
  162. + 3) & -4) == 4, (x), 0U))
  163. # define _SDT_ARGSIGNED(x) \
  164. (!__extension__ \
  165. (__builtin_constant_p ((((unsigned long long) \
  166. (_SDT_ARGINTTYPE (x)) __sdt_unsp) \
  167. & ((unsigned long long)1 << (sizeof (unsigned long long) \
  168. * __CHAR_BIT__ - 1))) == 0) \
  169. || (_SDT_ARGINTTYPE (x)) -1 > (_SDT_ARGINTTYPE (x)) 0))
  170. # define _SDT_ARGSIZE(x) \
  171. (_SDT_ARGARRAY (x) ? sizeof (void *) : sizeof (x))
  172. # define _SDT_ARGVAL(x) (x)
  173. #endif
  174. #if defined __powerpc__ || defined __powerpc64__
  175. # define _SDT_ARGTMPL(id) %I[id]%[id]
  176. #elif defined __i386__
  177. # define _SDT_ARGTMPL(id) %k[id] /* gcc.gnu.org/PR80115 sourceware.org/PR24541 */
  178. #else
  179. # define _SDT_ARGTMPL(id) %[id]
  180. #endif
  181. /* NB: gdb PR24541 highlighted an unspecified corner of the sdt.h
  182. operand note format.
  183. The named register may be a longer or shorter (!) alias for the
  184. storage where the value in question is found. For example, on
  185. i386, 64-bit value may be put in register pairs, and the register
  186. name stored would identify just one of them. Previously, gcc was
  187. asked to emit the %w[id] (16-bit alias of some registers holding
  188. operands), even when a wider 32-bit value was used.
  189. Bottom line: the byte-width given before the @ sign governs. If
  190. there is a mismatch between that width and that of the named
  191. register, then a sys/sdt.h note consumer may need to employ
  192. architecture-specific heuristics to figure out where the compiler
  193. has actually put the complete value.
  194. */
  195. #ifdef __LP64__
  196. # define _SDT_ASM_ADDR .8byte
  197. #else
  198. # define _SDT_ASM_ADDR .4byte
  199. #endif
  200. /* The ia64 and s390 nop instructions take an argument. */
  201. #if defined(__ia64__) || defined(__s390__) || defined(__s390x__)
  202. #define _SDT_NOP nop 0
  203. #else
  204. #define _SDT_NOP nop
  205. #endif
  206. #define _SDT_NOTE_NAME "stapsdt"
  207. #define _SDT_NOTE_TYPE 3
  208. /* If the assembler supports the necessary feature, then we can play
  209. nice with code in COMDAT sections, which comes up in C++ code.
  210. Without that assembler support, some combinations of probe placements
  211. in certain kinds of C++ code may produce link-time errors. */
  212. #include "sdt-config.h"
  213. #if _SDT_ASM_SECTION_AUTOGROUP_SUPPORT
  214. # define _SDT_ASM_AUTOGROUP "?"
  215. #else
  216. # define _SDT_ASM_AUTOGROUP ""
  217. #endif
  218. #define _SDT_DEF_MACROS \
  219. _SDT_ASM_1(.altmacro) \
  220. _SDT_ASM_1(.macro _SDT_SIGN x) \
  221. _SDT_ASM_3(.pushsection .note.stapsdt,"","note") \
  222. _SDT_ASM_1(.iflt \\x) \
  223. _SDT_ASM_1(.ascii "-") \
  224. _SDT_ASM_1(.endif) \
  225. _SDT_ASM_1(.popsection) \
  226. _SDT_ASM_1(.endm) \
  227. _SDT_ASM_1(.macro _SDT_SIZE_ x) \
  228. _SDT_ASM_3(.pushsection .note.stapsdt,"","note") \
  229. _SDT_ASM_1(.ascii "\x") \
  230. _SDT_ASM_1(.popsection) \
  231. _SDT_ASM_1(.endm) \
  232. _SDT_ASM_1(.macro _SDT_SIZE x) \
  233. _SDT_ASM_1(_SDT_SIZE_ %%((-(-\\x*((-\\x>0)-(-\\x<0))))>>8)) \
  234. _SDT_ASM_1(.endm) \
  235. _SDT_ASM_1(.macro _SDT_TYPE_ x) \
  236. _SDT_ASM_3(.pushsection .note.stapsdt,"","note") \
  237. _SDT_ASM_2(.ifc 8,\\x) \
  238. _SDT_ASM_1(.ascii "f") \
  239. _SDT_ASM_1(.endif) \
  240. _SDT_ASM_1(.ascii "@") \
  241. _SDT_ASM_1(.popsection) \
  242. _SDT_ASM_1(.endm) \
  243. _SDT_ASM_1(.macro _SDT_TYPE x) \
  244. _SDT_ASM_1(_SDT_TYPE_ %%((\\x)&(0xff))) \
  245. _SDT_ASM_1(.endm)
  246. #define _SDT_UNDEF_MACROS \
  247. _SDT_ASM_1(.purgem _SDT_SIGN) \
  248. _SDT_ASM_1(.purgem _SDT_SIZE_) \
  249. _SDT_ASM_1(.purgem _SDT_SIZE) \
  250. _SDT_ASM_1(.purgem _SDT_TYPE_) \
  251. _SDT_ASM_1(.purgem _SDT_TYPE)
  252. #define _SDT_ASM_BODY(provider, name, pack_args, args, ...) \
  253. _SDT_DEF_MACROS \
  254. _SDT_ASM_1(990: _SDT_NOP) \
  255. _SDT_ASM_3( .pushsection .note.stapsdt,_SDT_ASM_AUTOGROUP,"note") \
  256. _SDT_ASM_1( .balign 4) \
  257. _SDT_ASM_3( .4byte 992f-991f, 994f-993f, _SDT_NOTE_TYPE) \
  258. _SDT_ASM_1(991: .asciz _SDT_NOTE_NAME) \
  259. _SDT_ASM_1(992: .balign 4) \
  260. _SDT_ASM_1(993: _SDT_ASM_ADDR 990b) \
  261. _SDT_ASM_1( _SDT_ASM_ADDR _.stapsdt.base) \
  262. _SDT_SEMAPHORE(provider,name) \
  263. _SDT_ASM_STRING(provider) \
  264. _SDT_ASM_STRING(name) \
  265. pack_args args \
  266. _SDT_ASM_SUBSTR(\x00) \
  267. _SDT_UNDEF_MACROS \
  268. _SDT_ASM_1(994: .balign 4) \
  269. _SDT_ASM_1( .popsection)
  270. #define _SDT_ASM_BASE \
  271. _SDT_ASM_1(.ifndef _.stapsdt.base) \
  272. _SDT_ASM_5( .pushsection .stapsdt.base,"aG","progbits", \
  273. .stapsdt.base,comdat) \
  274. _SDT_ASM_1( .weak _.stapsdt.base) \
  275. _SDT_ASM_1( .hidden _.stapsdt.base) \
  276. _SDT_ASM_1( _.stapsdt.base: .space 1) \
  277. _SDT_ASM_2( .size _.stapsdt.base, 1) \
  278. _SDT_ASM_1( .popsection) \
  279. _SDT_ASM_1(.endif)
  280. #if defined _SDT_HAS_SEMAPHORES
  281. #define _SDT_SEMAPHORE(p,n) \
  282. _SDT_ASM_1( _SDT_ASM_ADDR p##_##n##_semaphore)
  283. #else
  284. #define _SDT_SEMAPHORE(p,n) _SDT_ASM_1( _SDT_ASM_ADDR 0)
  285. #endif
  286. #define _SDT_ASM_BLANK _SDT_ASM_SUBSTR(\x20)
  287. #define _SDT_ASM_TEMPLATE_0 /* no arguments */
  288. #define _SDT_ASM_TEMPLATE_1 _SDT_ARGFMT(1)
  289. #define _SDT_ASM_TEMPLATE_2 _SDT_ASM_TEMPLATE_1 _SDT_ASM_BLANK _SDT_ARGFMT(2)
  290. #define _SDT_ASM_TEMPLATE_3 _SDT_ASM_TEMPLATE_2 _SDT_ASM_BLANK _SDT_ARGFMT(3)
  291. #define _SDT_ASM_TEMPLATE_4 _SDT_ASM_TEMPLATE_3 _SDT_ASM_BLANK _SDT_ARGFMT(4)
  292. #define _SDT_ASM_TEMPLATE_5 _SDT_ASM_TEMPLATE_4 _SDT_ASM_BLANK _SDT_ARGFMT(5)
  293. #define _SDT_ASM_TEMPLATE_6 _SDT_ASM_TEMPLATE_5 _SDT_ASM_BLANK _SDT_ARGFMT(6)
  294. #define _SDT_ASM_TEMPLATE_7 _SDT_ASM_TEMPLATE_6 _SDT_ASM_BLANK _SDT_ARGFMT(7)
  295. #define _SDT_ASM_TEMPLATE_8 _SDT_ASM_TEMPLATE_7 _SDT_ASM_BLANK _SDT_ARGFMT(8)
  296. #define _SDT_ASM_TEMPLATE_9 _SDT_ASM_TEMPLATE_8 _SDT_ASM_BLANK _SDT_ARGFMT(9)
  297. #define _SDT_ASM_TEMPLATE_10 _SDT_ASM_TEMPLATE_9 _SDT_ASM_BLANK _SDT_ARGFMT(10)
  298. #define _SDT_ASM_TEMPLATE_11 _SDT_ASM_TEMPLATE_10 _SDT_ASM_BLANK _SDT_ARGFMT(11)
  299. #define _SDT_ASM_TEMPLATE_12 _SDT_ASM_TEMPLATE_11 _SDT_ASM_BLANK _SDT_ARGFMT(12)
  300. #define _SDT_ASM_OPERANDS_0() [__sdt_dummy] "g" (0)
  301. #define _SDT_ASM_OPERANDS_1(arg1) _SDT_ARG(1, arg1)
  302. #define _SDT_ASM_OPERANDS_2(arg1, arg2) \
  303. _SDT_ASM_OPERANDS_1(arg1), _SDT_ARG(2, arg2)
  304. #define _SDT_ASM_OPERANDS_3(arg1, arg2, arg3) \
  305. _SDT_ASM_OPERANDS_2(arg1, arg2), _SDT_ARG(3, arg3)
  306. #define _SDT_ASM_OPERANDS_4(arg1, arg2, arg3, arg4) \
  307. _SDT_ASM_OPERANDS_3(arg1, arg2, arg3), _SDT_ARG(4, arg4)
  308. #define _SDT_ASM_OPERANDS_5(arg1, arg2, arg3, arg4, arg5) \
  309. _SDT_ASM_OPERANDS_4(arg1, arg2, arg3, arg4), _SDT_ARG(5, arg5)
  310. #define _SDT_ASM_OPERANDS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
  311. _SDT_ASM_OPERANDS_5(arg1, arg2, arg3, arg4, arg5), _SDT_ARG(6, arg6)
  312. #define _SDT_ASM_OPERANDS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
  313. _SDT_ASM_OPERANDS_6(arg1, arg2, arg3, arg4, arg5, arg6), _SDT_ARG(7, arg7)
  314. #define _SDT_ASM_OPERANDS_8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
  315. _SDT_ASM_OPERANDS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7), \
  316. _SDT_ARG(8, arg8)
  317. #define _SDT_ASM_OPERANDS_9(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) \
  318. _SDT_ASM_OPERANDS_8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8), \
  319. _SDT_ARG(9, arg9)
  320. #define _SDT_ASM_OPERANDS_10(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
  321. _SDT_ASM_OPERANDS_9(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), \
  322. _SDT_ARG(10, arg10)
  323. #define _SDT_ASM_OPERANDS_11(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11) \
  324. _SDT_ASM_OPERANDS_10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10), \
  325. _SDT_ARG(11, arg11)
  326. #define _SDT_ASM_OPERANDS_12(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) \
  327. _SDT_ASM_OPERANDS_11(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11), \
  328. _SDT_ARG(12, arg12)
  329. /* These macros can be used in C, C++, or assembly code.
  330. In assembly code the arguments should use normal assembly operand syntax. */
  331. #define STAP_PROBE(provider, name) \
  332. _SDT_PROBE(provider, name, 0, ())
  333. #define STAP_PROBE1(provider, name, arg1) \
  334. _SDT_PROBE(provider, name, 1, (arg1))
  335. #define STAP_PROBE2(provider, name, arg1, arg2) \
  336. _SDT_PROBE(provider, name, 2, (arg1, arg2))
  337. #define STAP_PROBE3(provider, name, arg1, arg2, arg3) \
  338. _SDT_PROBE(provider, name, 3, (arg1, arg2, arg3))
  339. #define STAP_PROBE4(provider, name, arg1, arg2, arg3, arg4) \
  340. _SDT_PROBE(provider, name, 4, (arg1, arg2, arg3, arg4))
  341. #define STAP_PROBE5(provider, name, arg1, arg2, arg3, arg4, arg5) \
  342. _SDT_PROBE(provider, name, 5, (arg1, arg2, arg3, arg4, arg5))
  343. #define STAP_PROBE6(provider, name, arg1, arg2, arg3, arg4, arg5, arg6) \
  344. _SDT_PROBE(provider, name, 6, (arg1, arg2, arg3, arg4, arg5, arg6))
  345. #define STAP_PROBE7(provider, name, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
  346. _SDT_PROBE(provider, name, 7, (arg1, arg2, arg3, arg4, arg5, arg6, arg7))
  347. #define STAP_PROBE8(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) \
  348. _SDT_PROBE(provider, name, 8, (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8))
  349. #define STAP_PROBE9(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)\
  350. _SDT_PROBE(provider, name, 9, (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
  351. #define STAP_PROBE10(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \
  352. _SDT_PROBE(provider, name, 10, \
  353. (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10))
  354. #define STAP_PROBE11(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11) \
  355. _SDT_PROBE(provider, name, 11, \
  356. (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11))
  357. #define STAP_PROBE12(provider,name,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12) \
  358. _SDT_PROBE(provider, name, 12, \
  359. (arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12))
  360. /* This STAP_PROBEV macro can be used in variadic scenarios, where the
  361. number of probe arguments is not known until compile time. Since
  362. variadic macro support may vary with compiler options, you must
  363. pre-#define SDT_USE_VARIADIC to enable this type of probe.
  364. The trick to count __VA_ARGS__ was inspired by this post by
  365. Laurent Deniau <laurent.deniau@cern.ch>:
  366. http://groups.google.com/group/comp.std.c/msg/346fc464319b1ee5
  367. Note that our _SDT_NARG is called with an extra 0 arg that's not
  368. counted, so we don't have to worry about the behavior of macros
  369. called without any arguments. */
  370. #define _SDT_NARG(...) __SDT_NARG(__VA_ARGS__, 12,11,10,9,8,7,6,5,4,3,2,1,0)
  371. #define __SDT_NARG(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12, N, ...) N
  372. #ifdef SDT_USE_VARIADIC
  373. #define _SDT_PROBE_N(provider, name, N, ...) \
  374. _SDT_PROBE(provider, name, N, (__VA_ARGS__))
  375. #define STAP_PROBEV(provider, name, ...) \
  376. _SDT_PROBE_N(provider, name, _SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__)
  377. #endif
  378. /* These macros are for use in asm statements. You must compile
  379. with -std=gnu99 or -std=c99 to use the STAP_PROBE_ASM macro.
  380. The STAP_PROBE_ASM macro generates a quoted string to be used in the
  381. template portion of the asm statement, concatenated with strings that
  382. contain the actual assembly code around the probe site.
  383. For example:
  384. asm ("before\n"
  385. STAP_PROBE_ASM(provider, fooprobe, %eax 4(%esi))
  386. "after");
  387. emits the assembly code for "before\nafter", with a probe in between.
  388. The probe arguments are the %eax register, and the value of the memory
  389. word located 4 bytes past the address in the %esi register. Note that
  390. because this is a simple asm, not a GNU C extended asm statement, these
  391. % characters do not need to be doubled to generate literal %reg names.
  392. In a GNU C extended asm statement, the probe arguments can be specified
  393. using the macro STAP_PROBE_ASM_TEMPLATE(n) for n arguments. The paired
  394. macro STAP_PROBE_ASM_OPERANDS gives the C values of these probe arguments,
  395. and appears in the input operand list of the asm statement. For example:
  396. asm ("someinsn %0,%1\n" // %0 is output operand, %1 is input operand
  397. STAP_PROBE_ASM(provider, fooprobe, STAP_PROBE_ASM_TEMPLATE(3))
  398. "otherinsn %[namedarg]"
  399. : "r" (outvar)
  400. : "g" (some_value), [namedarg] "i" (1234),
  401. STAP_PROBE_ASM_OPERANDS(3, some_value, some_ptr->field, 1234));
  402. This is just like writing:
  403. STAP_PROBE3(provider, fooprobe, some_value, some_ptr->field, 1234));
  404. but the probe site is right between "someinsn" and "otherinsn".
  405. The probe arguments in STAP_PROBE_ASM can be given as assembly
  406. operands instead, even inside a GNU C extended asm statement.
  407. Note that these can use operand templates like %0 or %[name],
  408. and likewise they must write %%reg for a literal operand of %reg. */
  409. #define _SDT_ASM_BODY_1(p,n,...) _SDT_ASM_BODY(p,n,_SDT_ASM_SUBSTR,(__VA_ARGS__))
  410. #define _SDT_ASM_BODY_2(p,n,...) _SDT_ASM_BODY(p,n,/*_SDT_ASM_STRING */,__VA_ARGS__)
  411. #define _SDT_ASM_BODY_N2(p,n,no,...) _SDT_ASM_BODY_ ## no(p,n,__VA_ARGS__)
  412. #define _SDT_ASM_BODY_N1(p,n,no,...) _SDT_ASM_BODY_N2(p,n,no,__VA_ARGS__)
  413. #define _SDT_ASM_BODY_N(p,n,...) _SDT_ASM_BODY_N1(p,n,_SDT_NARG(0, __VA_ARGS__),__VA_ARGS__)
  414. #if __STDC_VERSION__ >= 199901L
  415. # define STAP_PROBE_ASM(provider, name, ...) \
  416. _SDT_ASM_BODY_N(provider, name, __VA_ARGS__) \
  417. _SDT_ASM_BASE
  418. # define STAP_PROBE_ASM_OPERANDS(n, ...) _SDT_ASM_OPERANDS_##n(__VA_ARGS__)
  419. #else
  420. # define STAP_PROBE_ASM(provider, name, args) \
  421. _SDT_ASM_BODY(provider, name, /* _SDT_ASM_STRING */, (args)) \
  422. _SDT_ASM_BASE
  423. #endif
  424. #define STAP_PROBE_ASM_TEMPLATE(n) _SDT_ASM_TEMPLATE_##n,"use _SDT_ASM_TEMPLATE_"
  425. /* DTrace compatible macro names. */
  426. #define DTRACE_PROBE(provider,probe) \
  427. STAP_PROBE(provider,probe)
  428. #define DTRACE_PROBE1(provider,probe,parm1) \
  429. STAP_PROBE1(provider,probe,parm1)
  430. #define DTRACE_PROBE2(provider,probe,parm1,parm2) \
  431. STAP_PROBE2(provider,probe,parm1,parm2)
  432. #define DTRACE_PROBE3(provider,probe,parm1,parm2,parm3) \
  433. STAP_PROBE3(provider,probe,parm1,parm2,parm3)
  434. #define DTRACE_PROBE4(provider,probe,parm1,parm2,parm3,parm4) \
  435. STAP_PROBE4(provider,probe,parm1,parm2,parm3,parm4)
  436. #define DTRACE_PROBE5(provider,probe,parm1,parm2,parm3,parm4,parm5) \
  437. STAP_PROBE5(provider,probe,parm1,parm2,parm3,parm4,parm5)
  438. #define DTRACE_PROBE6(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6) \
  439. STAP_PROBE6(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6)
  440. #define DTRACE_PROBE7(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7) \
  441. STAP_PROBE7(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7)
  442. #define DTRACE_PROBE8(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8) \
  443. STAP_PROBE8(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8)
  444. #define DTRACE_PROBE9(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9) \
  445. STAP_PROBE9(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9)
  446. #define DTRACE_PROBE10(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10) \
  447. STAP_PROBE10(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10)
  448. #define DTRACE_PROBE11(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,parm11) \
  449. STAP_PROBE11(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,parm11)
  450. #define DTRACE_PROBE12(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,parm11,parm12) \
  451. STAP_PROBE12(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,parm11,parm12)
  452. #endif /* sys/sdt.h */