| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658  | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html > <head><title>Language elements</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="generator" content="TeX4ht (https://tug.org/tex4ht/)"> <meta name="originator" content="TeX4ht (https://tug.org/tex4ht/)"> <!-- html,2 --> <meta name="src" content="langref.tex"> <link rel="stylesheet" type="text/css" href="langref.css"> </head><body > <!--l. 1863--><div class="crosslinks"><p class="noindent">[<a href="langrefse6.html" >next</a>] [<a href="langrefse4.html" >prev</a>] [<a href="langrefse4.html#taillangrefse4.html" >prev-tail</a>] [<a href="#taillangrefse5.html">tail</a>] [<a href="langref.html#langrefse5.html" >up</a>] </p></div> <h3 class="sectionHead"><span class="titlemark">5 </span> <a id="x7-620005"></a>Language elements</h3> <!--l. 1864--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.1 </span> <a id="x7-630005.1"></a>Identifiers</h4> <a id="dx7-63001"></a> <!--l. 1866--><p class="noindent" ><span class="cmti-10">Identifiers </span>are used to name variables and functions. They are an alphanumeric sequence that may include the underscore (_) and dollar sign (<span class="tcrm-1000">$</span>) characters. They have the same syntax as C identifiers, except that the dollar sign is also a legal character. Identifiers that begin with a dollar sign are interpreted as references to variables in the target software, rather than to SystemTap script variables. Identifiers may not start with a plain digit. <!--l. 1875--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.2 </span> <a id="x7-640005.2"></a>Data types</h4> <a id="dx7-64001"></a> <!--l. 1877--><p class="noindent" >The SystemTap language includes a small number of data types, but no type declarations. A variable’s type is inferred<a id="dx7-64002"></a> from its use. To support this inference, the translator enforces consistent typing of function arguments and return values, array indices and values. There are no implicit type conversions between strings and numbers. Inconsistent type-related use of an identifier signals an error. <!--l. 1885--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.2.1 </span> <a id="x7-650005.2.1"></a>Literals</h5> <a id="dx7-65001"></a> <!--l. 1887--><p class="noindent" >Literals are either strings or integers. Literal integers can be expressed as decimal, octal, or hexadecimal, using C notation. Type suffixes (e.g., <span class="cmti-10">L </span>or <span class="cmti-10">U</span>) are not used. <!--l. 1893--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.2.2 </span> <a id="x7-660005.2.2"></a>Integers</h5> <a id="dx7-66001"></a> <a id="dx7-66002"></a> <!--l. 1895--><p class="noindent" >Integers are decimal, hexadecimal, or octal, and use the same notation as in C. Integers are 64-bit signed quantities, although the parser also accepts (and wraps around) values above positive 2<sup><span class="cmr-7">63</span></sup> but below 2<sup><span class="cmr-7">64</span></sup>. <!--l. 1900--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.2.3 </span> <a id="x7-670005.2.3"></a>Strings</h5> <a id="dx7-67001"></a> <!--l. 1903--><p class="noindent" >Strings are enclosed in quotation marks (“string”), and pass through standard C escape codes with backslashes. A string literal may be split into several pieces, which are glued together, as follows. <!--l. 1907--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 1907--><p class="indent" > <pre class="verbatim" id="verbatim-69"> str1 = "foo" "bar"   /* --> becomes "foobar" */ str2 = "a good way to do a multi-line\n"        "string literal"   /* --> becomes "a good way to do a multi-line\nstring literal" */ str3 = "also a good way to " @1 " splice command line args"   /* --> becomes "also a good way to foo splice command line args",      assuming @1 is given as foo on the command line */ </pre> <!--l. 1919--><p class="nopar" ></dd></dl> <!--l. 1922--><p class="noindent" >Observe that script arguments can also be glued into a string literal. <!--l. 1924--><p class="noindent" >Strings are limited in length to MAXSTRINGLEN. For more information about this and other limits, see Section <a href="langrefse1.html#x3-110001.6">1.6<!--tex4ht:ref: sub:SystemTap-safety --></a>. <!--l. 1928--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.2.4 </span> <a id="x7-680005.2.4"></a>Associative arrays</h5> <!--l. 1930--><p class="noindent" >See Section <a href="langrefse7.html#x9-1140007">7<!--tex4ht:ref: sec:Associative-Arrays --></a> <!--l. 1933--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.2.5 </span> <a id="x7-690005.2.5"></a>Statistics</h5> <!--l. 1935--><p class="noindent" >See Section <a href="langrefse8.html#x10-1210008">8<!--tex4ht:ref: sec:Statistics --></a> <!--l. 1938--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.3 </span> <a id="x7-700005.3"></a>Semicolons</h4> <a id="dx7-70001"></a> <!--l. 1940--><p class="noindent" >The semicolon is the null statement, or do nothing statement. It is optional, and useful as a separator between statements to improve detection of syntax errors and to reduce ambiguities in grammar. <!--l. 1945--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.4 </span> <a id="x7-710005.4"></a>Comments</h4> <a id="dx7-71001"></a> <!--l. 1947--><p class="noindent" >Three forms of comments are supported, as follows. <!--l. 1949--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 1949--><p class="indent" > <pre class="verbatim" id="verbatim-70"> # ... shell style, to the end of line // ... C++ style, to the end of line /* ... C style ... */ </pre> <!--l. 1954--><p class="nopar" ></dd></dl> <!--l. 1957--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.5 </span> <a id="x7-720005.5"></a>Whitespace</h4> <a id="dx7-72001"></a> <!--l. 1959--><p class="noindent" >As in C, spaces, tabs, returns, newlines, and comments are treated as whitespace. Whitespace is ignored by the parser. <!--l. 1963--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.6 </span> <a id="x7-730005.6"></a>Expressions</h4> <a id="dx7-73001"></a> <!--l. 1965--><p class="noindent" >SystemTap supports a number of operators that use the same general syntax, semantics, and precedence as in C and awk. Arithmetic is performed per C rules for signed integers. If the parser detects division by zero or an overflow, it generates an error. The following subsections list these operators. <!--l. 1970--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.1 </span> <a id="x7-740005.6.1"></a>Binary numeric operators</h5> <a id="dx7-74001"></a> <!--l. 1973--><p class="noindent" ><span class="cmtt-10">* / % + - >> >>> << & ^ | && ||</span> <!--l. 1975--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.2 </span> <a id="x7-750005.6.2"></a>Binary string operators</h5> <a id="dx7-75001"></a> <!--l. 1977--><p class="noindent" ><span class="cmtt-10">. </span>(string concatenation) <!--l. 1979--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.3 </span> <a id="x7-760005.6.3"></a>Numeric assignment operators</h5> <a id="dx7-76001"></a> <!--l. 1982--><p class="noindent" ><span class="cmtt-10">= *= /= %= += -= >>= <<= &= ^= |=</span> <!--l. 1984--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.4 </span> <a id="x7-770005.6.4"></a>String assignment operators</h5> <!--l. 1986--><p class="noindent" ><span class="cmtt-10">= .=</span> <!--l. 1988--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.5 </span> <a id="x7-780005.6.5"></a>Unary numeric operators</h5> <a id="dx7-78001"></a> <!--l. 1990--><p class="noindent" ><span class="cmtt-10">+ - ! ~ ++ --</span> <!--l. 1992--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.6 </span> <a id="x7-790005.6.6"></a>Numeric & string comparison, regular expression matching operators</h5> <a id="dx7-79001"></a> <!--l. 1994--><p class="noindent" ><span class="cmtt-10">< > <= >= == != </span><span class="obeylines-h"><span class="verb"><span class="cmtt-10">=~</span></span></span> <span class="obeylines-h"><span class="verb"><span class="cmtt-10">!~</span></span></span> <!--l. 1996--><p class="noindent" >The <span class="obeylines-h"><span class="verb"><span class="cmtt-10">=~</span></span></span> and <span class="obeylines-h"><span class="verb"><span class="cmtt-10">!~</span></span></span> operators perform regular expression matching. The second operand must be a string literal containing a syntactically valid regular expression. The <span class="obeylines-h"><span class="verb"><span class="cmtt-10">=~</span></span></span> operator returns <span class="cmtt-10">1 </span>on a successful match and <span class="cmtt-10">0 </span>on a failed match. The <span class="obeylines-h"><span class="verb"><span class="cmtt-10">!~</span></span></span> operator returns <span class="cmtt-10">1 </span>on a failed match. The regular expression syntax supports most of the features of POSIX Extended Regular Expressions, except for subexpression reuse (<span class="obeylines-h"><span class="verb"><span class="cmtt-10">\1</span></span></span>) functionality. After a successful match, the matched substring and subexpressions can be extracted using the <span class="cmtt-10">matched </span>tapset function. The <span class="cmtt-10">ngroups </span>tapset function returns the number of subexpressions in the last successfully matched regular expression. <!--l. 2006--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.7 </span> <a id="x7-800005.6.7"></a>Ternary operator</h5> <a id="dx7-80001"></a> <!--l. 2008--><p class="noindent" ><span class="cmtt-10">cond ? exp1 : exp2</span> <!--l. 2011--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.8 </span> <a id="x7-810005.6.8"></a>Grouping operator</h5> <a id="dx7-81001"></a> <!--l. 2013--><p class="noindent" ><span class="cmtt-10">( exp )</span> <!--l. 2016--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.9 </span> <a id="x7-820005.6.9"></a>Function call</h5> <a id="dx7-82001"></a> <!--l. 2018--><p class="noindent" >General syntax: <!--l. 2020--><p class="noindent" ><span class="cmtt-10">fn ([ arg1, arg2, ... ])</span> <!--l. 2023--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.10 </span> <a id="x7-830005.6.10"></a><span class="tcrm-1000">$</span>ptr-<span class="cmmi-10">></span>member</h5> <a id="dx7-83001"></a> <!--l. 2025--><p class="noindent" ><span class="cmtt-10">ptr </span>is a kernel pointer available in a probed context. <!--l. 2028--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.11 </span> <a id="x7-840005.6.11"></a>Pointer typecasting</h5> <a id="dx7-84001"></a> <!--l. 2031--><p class="noindent" ><span class="cmti-10">Typecasting </span>is supported using the <span class="cmtt-10">@cast() </span>operator. A script can define a pointer type for a <span class="cmti-10">long </span>value, then access type members using the same syntax as with <span class="tctt-1000">$</span><span class="cmtt-10">target </span>variables. After a pointer is saved into a script integer variable, the translator loses the necessary type information to access members from that pointer. The <span class="cmtt-10">@cast()</span> operator tells the translator how to read a pointer. <!--l. 2039--><p class="noindent" >The following statement interprets <span class="cmtt-10">p </span>as a pointer to a struct or union named <span class="cmtt-10">type</span><span class="cmtt-10">_name </span>and dereferences the <span class="cmtt-10">member </span>value: <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2042--><p class="indent" > <pre class="verbatim" id="verbatim-71"> @cast(p, "type_name"[, "module"])->member </pre> <!--l. 2045--><p class="nopar" ></dd></dl> <!--l. 2048--><p class="noindent" >The optional <span class="cmtt-10">module </span>parameter tells the translator where to look for information about that type. You can specify multiple modules as a list with colon (<span class="cmtt-10">:</span>) separators. If you do not specify the module parameter, the translator defaults to either the probe module for dwarf probes or to <span class="cmti-10">kernel </span>for functions and all other probe types. <!--l. 2055--><p class="noindent" >The following statement retrieves the parent PID from a kernel task_struct: <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2057--><p class="indent" > <pre class="verbatim" id="verbatim-72"> @cast(pointer, "task_struct", "kernel")->parent->tgid </pre> <!--l. 2060--><p class="nopar" ></dd></dl> <!--l. 2063--><p class="noindent" >The translator can create its own module with type information from a header surrounded by angle brackets (<span class="cmtt-10">< ></span>) if normal debugging information is not available. For kernel headers, prefix it with <span class="cmtt-10">kernel </span>to use the appropriate build system. All other headers are built with default GCC parameters into a user module. The following statements are examples. <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2069--><p class="indent" > <pre class="verbatim" id="verbatim-73"> @cast(tv, "timeval", "<sys/time.h>")->tv_sec @cast(task, "task_struct", "kernel<linux/sched.h>")->tgid </pre> <!--l. 2073--><p class="nopar" ></dd></dl> <!--l. 2076--><p class="noindent" >In guru mode, the translator allows scripts to assign new values to members of typecasted pointers. <!--l. 2079--><p class="noindent" >Typecasting is also useful in the case of <span class="cmtt-10">void* </span>members whose type might be determinable at run time. <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2081--><p class="indent" > <pre class="verbatim" id="verbatim-74"> probe foo {    if ($var->type == 1) {       value = @cast($var->data, "type1")->bar    } else {       value = @cast($var->data, "type2")->baz    }    print(value) } </pre> <!--l. 2091--><p class="nopar" ></dd></dl> <!--l. 2095--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.12 </span> <a id="x7-850005.6.12"></a><span class="cmmi-10"><</span>value<span class="cmmi-10">></span> in <span class="cmmi-10"><</span>array_name<span class="cmmi-10">></span></h5> <a id="dx7-85001"></a> <!--l. 2097--><p class="noindent" >This expression evaluates to true if the array contains an element with the specified index. <!--l. 2101--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.6.13 </span> <a id="x7-860005.6.13"></a>[ <span class="cmmi-10"><</span>value<span class="cmmi-10">></span>, ... ] in <span class="cmmi-10"><</span>array_name<span class="cmmi-10">></span></h5> <!--l. 2103--><p class="noindent" >The number of index values must match the number of indexes previously specified. <!--l. 2105--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.7 </span> <a id="x7-870005.7"></a>Literals passed in from the stap command line</h4> <a id="dx7-87001"></a> <!--l. 2107--><p class="noindent" ><span class="cmti-10">Literals </span>are either strings enclosed in double quotes (” ”) or integers. For information about integers, see Section <a href="#x7-660005.2.2">5.2.2<!--tex4ht:ref: sub:Integers --></a>. For information about strings, see Section <a href="#x7-670005.2.3">5.2.3<!--tex4ht:ref: sub:Strings --></a>. <!--l. 2111--><p class="noindent" >Script arguments at the end of a command line are expanded as literals. You can use these in all contexts where literals are accepted. A reference to a nonexistent argument number is an error. <!--l. 2116--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.7.1 </span> <a id="x7-880005.7.1"></a><span class="tcrm-1000">$</span>1 … <span class="tcrm-1000">$</span><span class="cmmi-10"><</span>NN<span class="cmmi-10">></span> for literal pasting</h5> <a id="dx7-88001"></a> <!--l. 2118--><p class="noindent" >Use <span class="tctt-1000">$</span><span class="cmtt-10">1 </span><span class="cmtt-10">… </span><span class="tctt-1000">$</span><span class="cmtt-10"><NN> </span>for pasting the entire argument string into the input stream, which will be further lexically tokenized. <!--l. 2121--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.7.2 </span> <a id="x7-890005.7.2"></a>@1 … @<span class="cmmi-10"><</span>NN<span class="cmmi-10">></span> for strings</h5> <!--l. 2123--><p class="noindent" >Use <span class="cmtt-10">@1 </span><span class="cmtt-10">… @<NN> </span>for casting an entire argument as a string literal. <!--l. 2126--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.7.3 </span> <a id="x7-900005.7.3"></a>Examples</h5> <!--l. 2128--><p class="noindent" >For example, if the following script named example.stp <!--l. 2130--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2130--><p class="indent" > <pre class="verbatim" id="verbatim-75"> probe begin { printf("%d, %s\n", $1, @2) } </pre> <!--l. 2133--><p class="nopar" ></dd></dl> <!--l. 2135--><p class="noindent" >is invoked as follows <!--l. 2137--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2137--><p class="indent" > <pre class="verbatim" id="verbatim-76"> # stap example.stp ’5+5’ mystring </pre> <!--l. 2140--><p class="nopar" ></dd></dl> <!--l. 2142--><p class="noindent" >then 5+5 is substituted for <span class="tcrm-1000">$</span>1 and ”mystring” for @2. The output will be <!--l. 2145--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2145--><p class="indent" > <pre class="verbatim" id="verbatim-77"> 10, mystring </pre> <!--l. 2148--><p class="nopar" ></dd></dl> <!--l. 2152--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.8 </span> <a id="x7-910005.8"></a>Conditional compilation</h4> <!--l. 2155--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.1 </span> <a id="x7-920005.8.1"></a>Conditions</h5> <a id="dx7-92001"></a> <!--l. 2157--><p class="noindent" >One of the steps of parsing is a simple preprocessing stage. The preprocessor supports conditionals with a general form similar to the ternary operator (Section <a href="#x7-800005.6.7">5.6.7<!--tex4ht:ref: sub:Ternary-operator --></a>). <!--l. 2161--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2161--><p class="indent" > <pre class="verbatim" id="verbatim-78"> %( CONDITION %? TRUE-TOKENS %) %( CONDITION %? TRUE-TOKENS %: FALSE-TOKENS %) </pre> <!--l. 2165--><p class="nopar" ></dd></dl> <!--l. 2167--><p class="noindent" >The CONDITION is a limited expression whose format is determined by its first keyword. The following is the general syntax. <!--l. 2170--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2170--><p class="indent" > <pre class="verbatim" id="verbatim-79"> %( <condition> %? <code> [ %: <code> ] %) </pre> <!--l. 2173--><p class="nopar" ></dd></dl> <!--l. 2176--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.2 </span> <a id="x7-930005.8.2"></a>Conditions based on available target variables</h5> <a id="dx7-93001"></a> <!--l. 2178--><p class="noindent" >The predicate @defined() is available for testing whether a particular <span class="tcrm-1000">$</span>variable/expression is resolvable at translation time. The following is an example of its use: <!--l. 2182--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2182--><p class="indent" > <pre class="verbatim" id="verbatim-80">   probe foo { if (@defined($bar)) log ("$bar is available here") } </pre> <!--l. 2185--><p class="nopar" ></dd></dl> <!--l. 2189--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.3 </span> <a id="x7-940005.8.3"></a>Conditions based on kernel version: kernel_v, kernel_vr</h5> <a id="dx7-94001"></a> <a id="dx7-94002"></a> <a id="dx7-94003"></a> <!--l. 2193--><p class="noindent" >If the first part of a conditional expression is the identifier <span class="cmtt-10">kernel</span><span class="cmtt-10">_v </span>or <span class="cmtt-10">kernel</span><span class="cmtt-10">_vr</span>, the second part must be one of six standard numeric comparison operators “<span class="cmmi-10"><</span>”, “<span class="cmmi-10"><</span>=”, “==”, “!=”, “<span class="cmmi-10">></span>”, or “<span class="cmmi-10">></span>=”, and the third part must be a string literal that contains an RPM-style version-release value. The condition returns true if the version of the target kernel (as optionally overridden by the <span class="cmbx-10">-r </span>option) matches the given version string. The comparison is performed by the glibc function strverscmp. <!--l. 2202--><p class="noindent" ><span class="cmtt-10">kernel</span><span class="cmtt-10">_v </span>refers to the kernel version number only, such as “2.6.13”. <!--l. 2204--><p class="noindent" ><span class="cmtt-10">kernel</span><span class="cmtt-10">_vr </span>refers to the kernel version number including the release code suffix, such as “2.6.13-1.322FC3smp”. <!--l. 2208--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.4 </span> <a id="x7-950005.8.4"></a>Conditions based on architecture: arch</h5> <a id="dx7-95001"></a> <!--l. 2210--><p class="noindent" >If the first part of the conditional expression is the identifier <span class="cmtt-10">arch </span>which refers to the processor architecture, then the second part is a string comparison operator ”==” or ”!=”, and the third part is a string literal for matching it. This comparison is a simple string equality or inequality. The currently supported architecture strings are i386, i686, x86_64, ia64, s390, and powerpc. <!--l. 2217--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.5 </span> <a id="x7-960005.8.5"></a>Conditions based on privilege level: systemtap_privilege</h5> <a id="dx7-96001"></a> <!--l. 2220--><p class="noindent" >If the first part of the conditional expression is the identifier <span class="cmtt-10">systemtap</span><span class="cmtt-10">_privilege </span>which refers to the privilege level the systemtap script is being compiled with, then the second part is a string comparison operator ”==” or ”!=”, and the third part is a string literal for matching it. This comparison is a simple string equality or inequality. The possible privilege strings to consider are <span class="obeylines-h"><span class="verb"><span class="cmtt-10">"stapusr"</span></span></span> for unprivileged scripts, and <span class="obeylines-h"><span class="verb"><span class="cmtt-10">"stapsys"</span></span></span> or <span class="obeylines-h"><span class="verb"><span class="cmtt-10">"stapdev"</span></span></span> for privileged scripts. (In general, to test for a privileged script it is best to use <span class="obeylines-h"><span class="verb"><span class="cmtt-10">!=</span><span class="cmtt-10"> "stapusr"</span></span></span>.) <!--l. 2230--><p class="noindent" >This condition can be used to write scripts that can be run in both privileged and unprivileged modes, with additional functionality made available in the privileged case. <!--l. 2234--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.8.6 </span> <a id="x7-970005.8.6"></a>True and False Tokens</h5> <a id="dx7-97001"></a> <!--l. 2236--><p class="noindent" >TRUE-TOKENS and FALSE-TOKENS are zero or more general parser tokens, possibly including nested preprocessor conditionals, that are pasted into the input stream if the condition is true or false. For example, the following code induces a parse error unless the target kernel version is newer than 2.6.5. <!--l. 2241--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2241--><p class="indent" > <pre class="verbatim" id="verbatim-81"> %( kernel_v <= "2.6.5" %? **ERROR** %) # invalid token sequence </pre> <!--l. 2244--><p class="nopar" ></dd></dl> <!--l. 2246--><p class="noindent" >The following code adapts to hypothetical kernel version drift. <!--l. 2248--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2248--><p class="indent" > <pre class="verbatim" id="verbatim-82"> probe kernel.function (     %( kernel_v <= "2.6.12" %? "__mm_do_fault" %:         %( kernel_vr == "2.6.13-1.8273FC3smp" %? "do_page_fault" %: UNSUPPORTED %)     %)) { /* ... */ } %( arch == "ia64" %?     probe syscall.vliw = kernel.function("vliw_widget") {} %) </pre> <!--l. 2259--><p class="nopar" ></dd></dl> <!--l. 2262--><p class="noindent" >The following code adapts to the presence of a kernel CONFIG option. <!--l. 2264--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2264--><p class="indent" > <pre class="verbatim" id="verbatim-83"> %( CONFIG_UPROBE == "y" %?     probe process.syscall {} %) </pre> <!--l. 2269--><p class="nopar" ></dd></dl> <!--l. 2273--><p class="noindent" > <h4 class="subsectionHead"><span class="titlemark">5.9 </span> <a id="x7-980005.9"></a>Preprocessor macros</h4> <!--l. 2275--><p class="noindent" >This feature lets scripts eliminate some types of repetition. <!--l. 2277--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.9.1 </span> <a id="x7-990005.9.1"></a>Local macros</h5> <!--l. 2279--><p class="noindent" >The preprocessor also supports a simple macro facility. <!--l. 2281--><p class="noindent" >Macros taking zero or more arguments are defined using the following construct: <!--l. 2284--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2284--><p class="indent" > <pre class="verbatim" id="verbatim-84"> @define NAME %( BODY %) @define NAME(PARAM_1, PARAM_2, ...) %( BODY %) </pre> <!--l. 2288--><p class="nopar" ></dd></dl> <!--l. 2291--><p class="noindent" >Macro arguments are referred to in the body by prefixing the argument name with an <span class="cmtt-10">@ </span>symbol. Likewise, once defined, macros are invoked by prefixing the macro name with an <span class="cmtt-10">@ </span>symbol: <!--l. 2295--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2295--><p class="indent" > <pre class="verbatim" id="verbatim-85"> @define foo %( x %) @define add(a,b) %( ((@a)+(@b)) %)    @foo = @add(2,2) </pre> <!--l. 2301--><p class="nopar" ></dd></dl> <!--l. 2304--><p class="noindent" >Macro expansion is currently performed in a separate pass before conditional compilation. Therefore, both TRUE- and FALSE-tokens in conditional expressions will be macroexpanded regardless of how the condition is evaluated. This can sometimes lead to errors: <!--l. 2309--><p class="noindent" > <dl class="list1"><dt class="list"> </dt><dd class="list"> <!--l. 2309--><p class="indent" > <pre class="verbatim" id="verbatim-86"> // The following results in a conflict: %( CONFIG_UPROBE == "y" %?     @define foo %( process.syscall %) %:     @define foo %( **ERROR** %) %) // The following works properly as expected: @define foo %(   %( CONFIG_UPROBE == "y" %? process.syscall %: **ERROR** %) %) </pre> <!--l. 2322--><p class="nopar" ></dd></dl> <!--l. 2325--><p class="noindent" >The first example is incorrect because both <span class="cmtt-10">@define</span>s are evaluated in a pass prior to the conditional being evaluated. <!--l. 2328--><p class="noindent" > <h5 class="subsubsectionHead"><span class="titlemark">5.9.2 </span> <a id="x7-1000005.9.2"></a>Library macros</h5> <!--l. 2330--><p class="noindent" >Normally, a macro definition is local to the file it occurs in. Thus, defining a macro in a tapset does not make it available to the user of the tapset. <!--l. 2334--><p class="noindent" >Publically available library macros can be defined by including <span class="cmtt-10">.stpm </span>files on the tapset search path. These files may only contain <span class="cmtt-10">@define </span>constructs, which become visible across all tapsets and user scripts. <!--l. 2339--><div class="crosslinks"><p class="noindent">[<a href="langrefse6.html" >next</a>] [<a href="langrefse4.html" >prev</a>] [<a href="langrefse4.html#taillangrefse4.html" >prev-tail</a>] [<a href="langrefse5.html" >front</a>] [<a href="langref.html#langrefse5.html" >up</a>] </p></div> <!--l. 2339--><p class="noindent" ><a id="taillangrefse5.html"></a> </body></html> 
 |