Philippe Gerum wrote:
>>> (*) You could avoid passing the function name in the systrace calls, by
>>> relying on the value of __FUNCTION__, with a small hack to trimm the
>>> __wrap_ prefix when needed. Making tracepoints less hairy would ease my
>>> pain reading this stuff.
>> OK, but let's not spend brain cycles on this until we know if and how we
>> can separate the entry/exit tracing from the traced service. If we could
>> leave existing lib code untouched, I would be happier as well.
> It does matter because it reduce visual clutter, and that's a
> prerequisite for merging, that's why I'm suggesting it.
> We already have an automated instrumentation tool for the simulator, but
> I'm not sure automatically inserted tracepoints would always be relevant
> in all cases.

Doesn't it rely on a patched gcc? Here is a suggestion for an
instrumentation procedure based on standard tools:

int my_lib_func(int arg1, const char *arg2);

int my_lib_func(int arg1, const char *arg2)
        return 13;

#include <stdio.h>
#include "lib.h"
        printf("my_lib_func = %d\n",
               my_lib_func(1, "hello"));

So far, so ordinary. Now we add entry/exit tracing for my_lib_func:

#include <stdio.h>
#include "lib.h"
int __trace_my_lib_func(int arg1, const char *arg2)
        int ret;
        printf("entry: arg1 = %d, arg2 = %s\n", arg1, arg2);
        ret = my_lib_func(arg1, arg2);
        printf("exit: ret = %d\n", ret);
        return ret;

ifneq (,$(TRACE))

main: main.c lib.o

lib.o: lib.c $(TRACELIB)
        gcc -c -o $@ $<
ifneq (,$(TRACE))
        ld -r -o [EMAIL PROTECTED] $@ $(TRACELIB)
        objcopy --redefine-sym my_lib_func=__orig_my_lib_func \
                --redefine-sym __trace_my_lib_func=my_lib_func [EMAIL 
        rm -f [EMAIL PROTECTED]

        rm -f *.o main

Build with "make TRACE=1" to get the traced variant, or call "make" for
non-traced mode.

This means we have a switch in the build process, we don't need to touch
the library sources. We only have to add a __trace_xxx() version for
every xxx() that can even use original headers to call into the original
service. Converting the Makefile stuff into something more handy for
autotools shouldn't be tricky.

There is just one no-go: functions with variable argument lists.
Fortunately, the only one that comes into my mind right now,
[rtdm_]ioctl(), has a single well-known "unknown" argument and needs to
be unrolled unconditionally anyway.

What do you think?


Attachment: signature.asc
Description: OpenPGP digital signature

Xenomai-core mailing list

Reply via email to