Embedded C; Embedded C Functions - Red Hat ENTERPRISE LINUX 5.4 - SYSTEMTAP LANGUAGE Reference Manual

Systemtap language reference
Hide thumbs Also See for ENTERPRISE LINUX 5.4 - SYSTEMTAP LANGUAGE:
Table of Contents

Advertisement

Chapter 3. Components of a SystemTap script
function <name>[:<type>] ( <arg1>[:<type>], ... ) { <stmts> }
SystemTap scripts may define subroutines to factor out common work. Functions may take any
number of scalar arguments, and must return a single scalar value. Scalars in this context are
Section 3.3, "Variables"
integers or strings. For more information on scalars, see Section
and Section
Section 5.2, "Data
types". The following is an example function declaration.
function thisfn (arg1, arg2) {
return arg1 + arg2
}
Note the general absence of type declarations, which are inferred by the translator. If desired, a
function definition may include explicit type declarations for its return value, its arguments, or both.
This is helpful for embedded-C functions. In the following example, the type inference engine need
only infer the type of arg2, a string.
function thatfn:string(arg1:long, arg2) {
return sprintf("%d%s", arg1, arg2)
}
Functions may call others or themselves recursively, up to a fixed nesting limit. See Section
Section 1.6, "Safety and
security".

3.5. Embedded C

SystemTap supports a guru mode
where script safety features such as code and data memory reference protection are removed.
Guru mode is set by passing the "-g" flag to the stap command. When in guru mode, the translator
accepts embedded code enclosed between "%{" and "%}" markers in the script file. Embedded code is
transcribed verbatim, without analysis, in sequence, into generated C code. At the outermost level of
a script, guru mode may be useful to add #include instructions, or any auxiliary definitions for use by
other embedded code.

3.6. Embedded C functions

General syntax:
function <name>:<type> ( <arg1>:<type>, ... ) %{ <C_stmts> %}
Embedded code is permitted in a function body. In that case, the script language body is replaced
entirely by a piece of C code enclosed between %{ and %} markers. The enclosed code may do
anything reasonable and safe as allowed by the parser.
There are a number of undocumented but complex safety constraints on concurrency, resource
consumption and runtime limits that are applied to code written in the SystemTap language. These
constraints are not applied to embedded C code, so use such code with caution as it is used verbatim.
Be especially careful when dereferencing pointers. Use the kread() macro to dereference any pointers
12

Advertisement

Table of Contents
loading

Table of Contents