This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH doc/langref.tex] Add pointer typecasting information
On Thu, 3 Sep 2009, Josh Stone wrote:
What most people call PID and TID are respectively ->tgid and ->pid in
the task_struct, so this should probably be parent->tgid.
+In guru mode, the translator allows scripts to assign new values to
+members of typecasted pointers. Typecasting is also useful in the case
+of \texttt{void*} members whose type might be determinable at run
+time.
The two sentences of this paragraph are separate concepts, so this feels
a little scatter-brained. They're separate paragraphs in the manpage,
and in your first draft -- are you just merging singleton paragraphs?
Perhaps this needs to be reorganized a bit.
Thanks. Here's an updated patch.
Signed-off-by: Robb Romans <robb@linux.vnet.ibm.com>
---
doc/langref.tex | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 1 deletions(-)
diff --git a/doc/langref.tex b/doc/langref.tex
index eb5393b..9208173 100644
--- a/doc/langref.tex
+++ b/doc/langref.tex
@@ -1107,9 +1107,74 @@ read\_counter is a function passed to the handle for a perfmon probe. It
returns the current count for the event.
\end{comment}
-\section{Language elements\label{sec:Language-Elements}}
+\subsection{Pointer typecasting}
+\index{Pointer typecasting}
+
+\emph{Typecasting} is supported using the \texttt{@cast()} operator. A
+script can define a pointer type for a \emph{long} value, then access
+type members using the same syntax as with \texttt{\$target}
+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 \texttt{@cast()} operator tells the translator
+how to read a pointer.
+
+The following statement interprets \texttt{p} as a pointer to a struct
+or union named \texttt{type\_name} and dereferences the
+\texttt{member} value:
+\begin{vindent}
+\begin{verbatim}
+@cast(p, "type_name"[, "module"])->member
+\end{verbatim}
+\end{vindent}
+
+The optional \texttt{module} parameter tells the translator where to
+look for information about that type. You can specify multiple modules
+as a list with colon (\texttt{:}) separators. If you do not specify
+the module parameter, the translator defaults to either the probe
+module for dwarf probes or to \textit{kernel} for functions and all
+other probe types.
+
+The following statement retrieves the parent PID from a kernel
+task\_struct:
+\begin{vindent}
+\begin{verbatim}
+@cast(pointer, "task_struct", "kernel")->parent->tgid
+\end{verbatim}
+\end{vindent}
+The translator can create its own module with type information from a
+header surrounded by angle brackets (\texttt{< >}) if normal debugging
+information is not available. For kernel headers, prefix it with
+\texttt{kernel} to use the appropriate build system. All other
+headers are built with default GCC parameters into a user module. The
+following statements are examples.
+\begin{vindent}
+\begin{verbatim}
+@cast(tv, "timeval", "<sys/time.h>")->tv_sec
+@cast(task, "task_struct", "kernel<linux/sched.h>")->tgid
+\end{verbatim}
+\end{vindent}
+In guru mode, the translator allows scripts to assign new values to
+members of typecasted pointers.
+
+Typecasting is also useful in the case of \texttt{void*} members whose
+type might be determinable at run time.
+\begin{vindent}
+\begin{verbatim}
+probe foo {
+ if ($var->type == 1) {
+ value = @cast($var->data, "type1")->bar
+ } else {
+ value = @cast($var->data, "type2")->baz
+ }
+ print(value)
+}
+\end{verbatim}
+\end{vindent}
+
+
+\section{Language elements\label{sec:Language-Elements}}
\subsection{Identifiers}
\index{identifiers}
\emph{Identifiers} are used to name variables and functions. They are an
--
1.6.0.4
--
Robb Romans
IBM LTC Information Development
robb@linux.vnet.ibm.com