* problem about tapset script
@ 2012-03-20 8:07 ch huang
2012-03-20 8:19 ` Adrien Kunysz
2012-03-20 8:21 ` Mark Wielaard
0 siblings, 2 replies; 3+ messages in thread
From: ch huang @ 2012-03-20 8:07 UTC (permalink / raw)
To: systemtap
i read tcp.stp script and see the following code ,this is Embedded C
code ,i do not know why each function has THIS->xxx and
CATCH_DEREF_FAULT()
and i can not find the explain in systemtap language reference
document ,any one can help?
%{ /* pure */
struct sock *sk = (struct sock *)(long) THIS->sock;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
struct tcp_opt *tp = tcp_sk(sk);
THIS->__retvalue = (int64_t) jiffies_to_usecs(kread(&(tp->rto)));
#else
const struct inet_connection_sock *icsk = inet_csk(sk);
THIS->__retvalue = (int64_t) jiffies_to_usecs(kread(&(icsk->icsk_rto)));
#endif
CATCH_DEREF_FAULT();
%}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: problem about tapset script
2012-03-20 8:07 problem about tapset script ch huang
@ 2012-03-20 8:19 ` Adrien Kunysz
2012-03-20 8:21 ` Mark Wielaard
1 sibling, 0 replies; 3+ messages in thread
From: Adrien Kunysz @ 2012-03-20 8:19 UTC (permalink / raw)
To: ch huang; +Cc: systemtap
[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]
On Tue, Mar 20, 2012 at 04:07:22PM +0800, ch huang wrote:
> i read tcp.stp script and see the following code ,this is Embedded C
> code ,i do not know why each function has THIS->xxx and
> CATCH_DEREF_FAULT()
> and i can not find the explain in systemtap language reference
> document ,any one can help?
THIS is to access arguments and return value as documented in the
SystemTap Language Reference: http://sourceware.org/systemtap/langref/Components_SystemTap_script.html#SECTION00046000000000000000
The CATCH_DEREF_FAULT macro is defined and documented in runtime/loc2c-runtime.h:
58 /* The deref and store_deref macros are called to safely access addresses
59 in the probe context. These macros are used only for kernel addresses.
60 The macros must handle bogus addresses here gracefully (as from
61 corrupted data structures, stale pointers, etc), by doing a "goto
62 deref_fault".
..
979 #define CATCH_DEREF_FAULT() \
980 if (0) { \
981 deref_fault: ; \
982 }
> %{ /* pure */
> struct sock *sk = (struct sock *)(long) THIS->sock;
> #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
> struct tcp_opt *tp = tcp_sk(sk);
> THIS->__retvalue = (int64_t) jiffies_to_usecs(kread(&(tp->rto)));
> #else
> const struct inet_connection_sock *icsk = inet_csk(sk);
> THIS->__retvalue = (int64_t) jiffies_to_usecs(kread(&(icsk->icsk_rto)));
> #endif
> CATCH_DEREF_FAULT();
> %}
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: problem about tapset script
2012-03-20 8:07 problem about tapset script ch huang
2012-03-20 8:19 ` Adrien Kunysz
@ 2012-03-20 8:21 ` Mark Wielaard
1 sibling, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2012-03-20 8:21 UTC (permalink / raw)
To: ch huang; +Cc: systemtap
On Tue, Mar 20, 2012 at 04:07:22PM +0800, ch huang wrote:
> i read tcp.stp script and see the following code ,this is Embedded C
> code ,i do not know why each function has THIS->xxx and
> CATCH_DEREF_FAULT()
> and i can not find the explain in systemtap language reference
> document ,any one can help?
There is some explanation in the language reference guide:
http://sourceware.org/systemtap/langref/Components_SystemTap_script.html#SECTION00045000000000000000
Some more in the tutorial:
http://sourceware.org/systemtap/tutorial/Tapsets.html#SECTION00053000000000000000
And a tiny bit on Embedded C & Safety in the tapset/DEVGUIDE:
http://sourceware.org/git/?p=systemtap.git;a=blob_plain;f=tapset/DEVGUIDE;hb=HEAD
But mainly follow the examples already in the code and in doubt ask
on the list.
Basically whenever you use kread or kwrite in embedded C code you must
add a DEREF_FAULT at the end (defined in runtime/loc2c-runtime.h) to
make sure a failure is reported and causes the script to error out.
Cheers,
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-20 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-20 8:07 problem about tapset script ch huang
2012-03-20 8:19 ` Adrien Kunysz
2012-03-20 8:21 ` Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).