Index: tools/fxt-tools.h =================================================================== --- tools/fxt-tools.h (revision 572) +++ tools/fxt-tools.h (working copy) @@ -53,6 +53,18 @@ (value) = (typeof(value)) __val; \ } while (0) +#define FREADRAW(file, n,value) do { \ + uint##n##_t __val; \ + int res; \ + res = fread( (void *)&__val, sizeof(__val), 1, file); \ + if (res < 0) return -1; \ + if (res < 1) { \ + errno = EINVAL; \ + return -1; \ + } \ + (value) = (typeof(value)) __val; \ + } while (0) + extern void unsupported_swap(void); #define DO_SWAP(n, var) { \ uint##n##_t ___val = (var); \ @@ -110,4 +122,17 @@ (value) = (typeof(value)) __val; \ } while (0) +#define FREAD(file, n,value) do { \ + uint##n##_t __val; \ + int res; \ + res = fread((void *)&__val, sizeof(__val), 1, file); \ + if (res < 0) return -1; \ + if (res < 1) { \ + errno = EINVAL; \ + return -1; \ + } \ + SWAP(n,__val); \ + (value) = (typeof(value)) __val; \ + } while (0) + #endif /* __FXT_TOOLS_H__ */ Index: tools/ev.c =================================================================== --- tools/ev.c (revision 572) +++ tools/ev.c (working copy) @@ -85,11 +85,12 @@ return -1; } + fxt->fstream = fdopen(fd, "r"); switch (evs->type) { case FXT_TRACE_KERNEL_RAW32: case FXT_TRACE_KERNEL_RAW64: - READ(64, offset); + READ(64, offset); /* Fall thru */ case FXT_TRACE_USER_RAW32: case FXT_TRACE_USER_RAW64: @@ -143,12 +144,13 @@ int ret=0; struct fxt_ev_64 e; -#define READEV_VAR(size, var) \ - { READ(size, var); \ - size_ev += size/8 ; \ - } +#define READEV_VAR(size, var) \ + { FREAD(fxt->fstream, size, var); \ + size_ev += size/8 ; \ + } + #define READEV(size, field) \ - READEV_VAR(size, e.field) + READEV_VAR(size, e.field) switch (evs->type) { case FXT_TRACE_KERNEL_RAW32: @@ -206,55 +208,30 @@ /* L'événement est présent, on peut le lire dans 'e' */ switch (evs->type) { case FXT_TRACE_KERNEL_RAW32: - case FXT_TRACE_KERNEL_RAW64: READEV(32,time); - break; - case FXT_TRACE_USER_RAW32: - case FXT_TRACE_USER_RAW64: - READEV(64,time); - break; - default: - NOT_MANAGED; - } - - switch (evs->type) { - case FXT_TRACE_KERNEL_RAW32: READEV(16, kernel.pid); + READEV(16, cpu); + READEV(32, code); break; - case FXT_TRACE_USER_RAW32: - READEV(32, user.tid); - break; - case FXT_TRACE_USER_RAW64: - READEV(64, user.tid); - break; - default: - NOT_MANAGED; - } - switch (evs->type) { - case FXT_TRACE_KERNEL_RAW32: - READEV(16, cpu); + case FXT_TRACE_KERNEL_RAW64: + READEV(32,time); + READEV(64, code); break; case FXT_TRACE_USER_RAW32: - case FXT_TRACE_USER_RAW64: - break; - default: - NOT_MANAGED; - } - - switch (evs->type) { - case FXT_TRACE_KERNEL_RAW32: - case FXT_TRACE_USER_RAW32: + READEV(64,time); + READEV(32, user.tid); READEV(32, code); break; - case FXT_TRACE_KERNEL_RAW64: case FXT_TRACE_USER_RAW64: + READEV(64,time); + READEV(64, user.tid); READEV(64, code); break; default: NOT_MANAGED; } - + /* calcul du nombre de paramètres */ switch (evs->type) { case FXT_TRACE_KERNEL_RAW32: @@ -300,7 +277,7 @@ case FXT_TRACE_KERNEL_RAW32: case FXT_TRACE_USER_RAW32: { uint32_t param; - READRAW(32,param); + FREADRAW(fxt->fstream, 32,param); if ((i+1)*4<=FXT_MAX_DATA) memcpy(&e.raw[i*4],¶m,4); if (ifstream, 64,param); if ((i+1)*8<=FXT_MAX_DATA) memcpy(&e.raw[i*8],¶m,8); if (iblock.start != lseek(evs->fxt->fd, - evs->block.start,SEEK_SET)) { + if (evs->block.start != fseek(evs->fxt->fstream, + evs->block.start,SEEK_SET)) { perror("seeking to start of events"); return -1; } Index: tools/fxt_internal.h =================================================================== --- tools/fxt_internal.h (revision 572) +++ tools/fxt_internal.h (working copy) @@ -21,6 +21,7 @@ #include #include +#include #include "fxt-tools.h" struct fxt_block { @@ -86,6 +87,7 @@ /* opened file */ int fd; + FILE* fstream; struct fxt_block events_block; /* lwp status */