This is the mail archive of the mailing list for the systemtap project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Language Reference, updated

Frank Ch. Eigler wrote:
    MM> Section 3.6 Mention use of the deref() macro in embedded C for
    MM> safety.  Give an example.

I could use a little help with this. Would anyone be able to provide a
good working example?

There are examples in the tapset. Josh switched us over to the "kread" function:

function _struct_timeval:string(addr:long)
%{ /* pure */
        struct timeval *tv = (struct timeval *)(unsigned long)THIS->addr;

        if (tv == NULL)
                strlcpy (THIS->__retvalue, "NULL", MAXSTRINGLEN);
                snprintf(THIS->__retvalue, MAXSTRINGLEN, "[%ld.%06ld]",
                                kread(&(tv->tv_sec)), kread(&(tv->tv_usec)));

(However, it is not clear that the NULL-handling case is relevant or
appropriate.  If the timeval* coming in from the application is
permitted to be NULL, fine, but if it's meant as a crash-prevention
mechanism in this embedded-C routine, then it's not right.)

What's the right thing to do if NULL isn't permitted? Should we let kread() report the error or do something else?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]