Why some changes are not done ?
Hi,
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
(
-EXTRACT_16BITS(E)
+EXTRACT_BE_16BITS(E)
|
-EXTRACT_32BITS(E)
+EXTRACT_BE_32BITS(E)
)
on the this source:
https://raw.githubusercontent.com/the-tcpdump-group/tcpdump/6151e2190b0b40bdb6cf56354eb016284762d27b/print-tcp.c
Most of the changes are done (20).
But 2 old macro names are left.
$ git grep -n -E 'EXTRACT_[0-9]+' print-tcp.c print-tcp.c:871: tlen = EXTRACT_16BITS(&ip->ip_len) - IP_HL(ip) * 4; print-tcp.c:878: len32 = htonl(EXTRACT_16BITS(&ip6->ip6_plen));
It seems that the problem is link to macro USES_APPLE_DEPRECATED_API on line 835. If I comment this macro, the changes are done.
On Apple systems:
#define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations) On other systems (like the one I use):
#define USES_APPLE_DEPRECATED_API
Did I miss something?
Signature · 1 line
Francois-Xavier
Quoted 24 lines · Francois-Xavier Le Bail
Hi,
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E))
on the this source:
https://raw.githubusercontent.com/the-tcpdump-group/tcpdump/6151e2190b0b40bdb6cf56354eb016284762d27b/print-tcp.cMost of the changes are done (20).
But 2 old macro names are left.$ git grep -n -E 'EXTRACT_[0-9]+' print-tcp.c print-tcp.c:871: tlen = EXTRACT_16BITS(&ip->ip_len) - IP_HL(ip) * 4; print-tcp.c:878: len32 = htonl(EXTRACT_16BITS(&ip6->ip6_plen));
Quoted 6 lines
It seems that the problem is link to macro
USES_APPLE_DEPRECATED_APIon line 835. If I comment this macro, the changes are done.
On Apple systems:
#defineUSES_APPLE_DEPRECATED_APIDIAG_OFF(deprecated-declarations)On other systems (like the one I use):
#defineUSES_APPLE_DEPRECATED_API
Just make a file macros.h and put in it
#define USES_APPLE_DEPRECATED_API
Then run spatch with --macro-file macros.h (or if that doesn't work then --macro-file-builtins macros.h). Then it will ignore this code.
julia
Quoted 9 lines
Did I miss something?
--
Francois-Xavier
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 21 lines · Julia Lawall
Quoted 10 lines · Francois-Xavier Le Bail
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E)Quoted 7 lines
)
[...]>> It seems that the problem is link to macroUSES_APPLE_DEPRECATED_APIon line 835. If I comment this macro, the changes are done.
On Apple systems:
#defineUSES_APPLE_DEPRECATED_APIDIAG_OFF(deprecated-declarations)
On other systems (like the one I use):
#defineUSES_APPLE_DEPRECATED_APIJust make a file
macros.hand put in it
Quoted 4 lines
#define
USES_APPLE_DEPRECATED_APIThen run spatch with --macro-file
macros.h(or if that doesn't work then --macro-file-builtinsmacros.h). Then it will ignore this code.
It works with '--macro-file macros.h', Thanks you !
Is there a way to have changes done also in macro definitions?
(like
#define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? EXTRACT_LE_16BITS(cp) : EXTRACT_16BITS(cp)))
Signature · 1 line
Francois-Xavier
Quoted 24 lines · Francois-Xavier Le Bail
Quoted 23 lines · Julia Lawall
Quoted 10 lines · Francois-Xavier Le Bail
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E)Quoted 7 lines
)
[...]>> It seems that the problem is link to macroUSES_APPLE_DEPRECATED_APIon line 835. If I comment this macro, the changes are done.
On Apple systems:
#defineUSES_APPLE_DEPRECATED_APIDIAG_OFF(deprecated-declarations)
On other systems (like the one I use):
#defineUSES_APPLE_DEPRECATED_APIJust make a file
macros.hand put in it#define
USES_APPLE_DEPRECATED_API
Quoted 8 lines
Quoted 2 lines
Then run spatch with --macro-file
macros.h(or if that doesn't work then --macro-file-builtinsmacros.h). Then it will ignore this code.It works with '--macro-file
macros.h', Thanks you !Is there a way to have changes done also in macro definitions?
(like
#defineKTOHSP(kp, cp)(IS_LENDIAN(kp)?EXTRACT_LE_16BITS(cp):EXTRACT_16BITS(cp)))
Normally changes should happen in macro definitions as well, but there may be a problem in parsing it due to some confusion about the parsing of a preceding macro. You can run spatch --parse-c file.c to see where there are parsing issues.
julia
Quoted 33 lines · Julia Lawall
Quoted 29 lines · Francois-Xavier Le Bail
Quoted 21 lines · Julia Lawall
Quoted 10 lines · Francois-Xavier Le Bail
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E)Quoted 7 lines
)
[...]>> It seems that the problem is link to macroUSES_APPLE_DEPRECATED_APIon line 835. If I comment this macro, the changes are done.
On Apple systems:
#defineUSES_APPLE_DEPRECATED_APIDIAG_OFF(deprecated-declarations)
On other systems (like the one I use):
#defineUSES_APPLE_DEPRECATED_APIJust make a file
macros.hand put in itQuoted 4 lines
#define
USES_APPLE_DEPRECATED_APIThen run spatch with --macro-file
macros.h(or if that doesn't work then --macro-file-builtinsmacros.h). Then it will ignore this code.It works with '--macro-file
macros.h', Thanks you !
Quoted 8 lines
Quoted 3 lines
Is there a way to have changes done also in macro definitions?
(like
#defineKTOHSP(kp, cp)(IS_LENDIAN(kp)?EXTRACT_LE_16BITS(cp):EXTRACT_16BITS(cp)))Normally changes should happen in macro definitions as well, but there may be a problem in parsing it due to some confusion about the parsing of a preceding macro. You can run spatch --parse-c
file.cto see where there are parsing issues.
The reason for this source is that the macro is defined in a function body. Why not applying change in that case?
Signature · 1 line
Francois-Xavier
Quoted 38 lines · Francois-Xavier Le Bail
Quoted 37 lines · Julia Lawall
Quoted 32 lines · Francois-Xavier Le Bail
Quoted 21 lines · Julia Lawall
Quoted 10 lines · Francois-Xavier Le Bail
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E)Quoted 7 lines
)
[...]>> It seems that the problem is link to macroUSES_APPLE_DEPRECATED_APIon line 835. If I comment this macro, the changes are done.
On Apple systems:
#defineUSES_APPLE_DEPRECATED_APIDIAG_OFF(deprecated-declarations)
On other systems (like the one I use):
#defineUSES_APPLE_DEPRECATED_APIJust make a file
macros.hand put in itQuoted 4 lines
#define
USES_APPLE_DEPRECATED_APIThen run spatch with --macro-file
macros.h(or if that doesn't work then --macro-file-builtinsmacros.h). Then it will ignore this code.It works with '--macro-file
macros.h', Thanks you !Is there a way to have changes done also in macro definitions?
(like
#defineKTOHSP(kp, cp)(IS_LENDIAN(kp)?EXTRACT_LE_16BITS(cp):EXTRACT_16BITS(cp)))
Quoted 7 lines
Quoted 4 lines
Normally changes should happen in macro definitions as well, but there may be a problem in parsing it due to some confusion about the parsing of a preceding macro. You can run spatch --parse-c
file.cto see where there are parsing issues.The reason for this source is that the macro is defined in a function body. Why not applying change in that case?
Macros defined in function bodies are ignored. Coccinelle works on a control-flow graph, and the #define is not part of the control-flow of the function. Since it's not clear what to do with it, it is just skipped.
julia
Quoted 25 lines · Julia Lawall
Quoted 7 lines · Francois-Xavier Le Bail
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Francois-Xavier Le Bail
Quoted 1 line · Julia Lawall
On Fri, 24 Nov 2017, Francois-Xavier Le Bail wrote:
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E))
The reason for this source is that the macro is defined in a function body. Why not applying change in that case?
Quoted 3 lines
Macros defined in function bodies are ignored. Coccinelle works on a control-flow graph, and the #define is not part of the control-flow of the function. Since it's not clear what to do with it, it is just skipped.
Ok, it is clear.
I have another macro definition case with no change, outside of all functions. I got "FLOW: cant jump to trunc: because we can't find this label"
Code:
#define VECOUT(MAX) { u_char *sp; \
u_char s[AFSNAMEMAX]; \
int k; \
if ((MAX) + 1 > sizeof(s)) \
goto trunc; \
ND_TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \
sp = s; \
for (k = 0; k < (MAX); k++) { \
*sp++ = (u_char) EXTRACT_32BITS(bp); \
bp += sizeof(int32_t); \
} \
s[(MAX)] = '\0'; \
ND_PRINT((ndo, " \"")); \
fn_print(ndo, s, NULL); \
ND_PRINT((ndo, "\"")); \
}Is there a solution for similar cases?
Signature · 1 line
Francois-Xavier
Quoted 53 lines · Francois-Xavier Le Bail
Quoted 25 lines · Julia Lawall
Quoted 7 lines · Francois-Xavier Le Bail
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Francois-Xavier Le Bail
Quoted 1 line · Julia Lawall
On Fri, 24 Nov 2017, Francois-Xavier Le Bail wrote:
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E))
The reason for this source is that the macro is defined in a function body. Why not applying change in that case?
Quoted 3 lines
Macros defined in function bodies are ignored. Coccinelle works on a control-flow graph, and the #define is not part of the control-flow of the function. Since it's not clear what to do with it, it is just skipped.
Ok, it is clear.
I have another macro definition case with no change, outside of all functions. I got "FLOW: cant jump to trunc: because we can't find this label"
Code:
#define VECOUT(MAX) { u_char *sp; \ u_char s[AFSNAMEMAX]; \ int k; \ if ((MAX) + 1 > sizeof(s)) \ goto trunc; \ ND_TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \ sp = s; \ for (k = 0; k < (MAX); k++) { \ *sp++ = (u_char) EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ } \ s[(MAX)] = '\0'; \ ND_PRINT((ndo, " \"")); \ fn_print(ndo, s, NULL); \ ND_PRINT((ndo, "\"")); \ }
Quoted 1 line
Is there a solution for similar cases?
No. It can't create a control-flow graph for the code if the goto destination is missing.
julia
Quoted 57 lines · Julia Lawall
Quoted 53 lines · Francois-Xavier Le Bail
Quoted 25 lines · Julia Lawall
Quoted 7 lines · Francois-Xavier Le Bail
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Francois-Xavier Le Bail
Quoted 1 line · Julia Lawall
On Fri, 24 Nov 2017, Francois-Xavier Le Bail wrote:
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
I use the following Coccinelle script to rename some macros:
@@
expression E;
@@
((quoted diff) +1
-1-EXTRACT_16BITS(E) +EXTRACT_BE_16BITS(E)|
(quoted diff) +1
-1-EXTRACT_32BITS(E) +EXTRACT_BE_32BITS(E))
The reason for this source is that the macro is defined in a function body. Why not applying change in that case?
Quoted 3 lines
Macros defined in function bodies are ignored. Coccinelle works on a control-flow graph, and the #define is not part of the control-flow of the function. Since it's not clear what to do with it, it is just skipped.
Ok, it is clear.
I have another macro definition case with no change, outside of all functions. I got "FLOW: cant jump to trunc: because we can't find this label"
Code:
#define VECOUT(MAX) { u_char *sp; \ u_char s[AFSNAMEMAX]; \ int k; \ if ((MAX) + 1 > sizeof(s)) \ goto trunc; \ ND_TCHECK2(bp[0], (MAX) * sizeof(int32_t)); \ sp = s; \ for (k = 0; k < (MAX); k++) { \ *sp++ = (u_char) EXTRACT_32BITS(bp); \ bp += sizeof(int32_t); \ } \ s[(MAX)] = '\0'; \ ND_PRINT((ndo, " \"")); \ fn_print(ndo, s, NULL); \ ND_PRINT((ndo, "\"")); \ }
Quoted 4 lines
Quoted 1 line
Is there a solution for similar cases?
No. It can't create a control-flow graph for the code if the goto destination is missing.
OK, thanks.
Signature · 1 line
Francois-Xavier