Matching against a declarer macro
Hi again,
I'm having a little trouble matching against this line of code:
RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);
This is especially tricky because it contains a lot of macro magic.
I think the biggest problem is the first argument, which is the keyword "static". What do I use to match against this? expression? identifier? symbol?
Also, the "augment_callbacks" is not really an identifier either, it just gets used to generate the function names. But what is it? An expression?
@@
typedef sector_t;
declarer name RB_DECLARE_CALLBACKS_MAX;
identifier augment_callbacks;
identifier rb;
identifier end;
identifier NODE_END;
@@
-RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);
Nothing I have tried has made it match yet.
Any ideas on how to solve this would be appreciated, thanks!
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 28 lines · Christoph Böhmwalder
Hi again,
I'm having a little trouble matching against this line of code:
RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);This is especially tricky because it contains a lot of macro magic. I think the biggest problem is the first argument, which is the keyword "static". What do I use to match against this? expression? identifier? symbol?
Also, the "
augment_callbacks" is not really an identifier either, it just gets used to generate the function names. But what is it? An expression?@@
typedefsector_t;
declarer nameRB_DECLARE_CALLBACKS_MAX;identifier
augment_callbacks;
identifier rb;
identifier end;
identifierNODE_END;
@@
-RB_DECLARE_CALLBACKS_MAX(static,augment_callbacks, structdrbd_interval, rb,sector_t, end,NODE_END);
Quoted 3 lines
Nothing I have tried has made it match yet.
Any ideas on how to solve this would be appreciated, thanks!
Are you sure that the C code is parsed successfully? I'm not at all sure that static is allowed in an argument list. Types are allowed, bu static is only part of a type.
For augment_callbacks, either identifier or expression would be fine. Coccinelle has no idea what is going to happen to augment_callbacks afterwards. It just sees a sequence of characters and classifies it as an identifier.
julia
Quoted 10 lines
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Am 27.03.20 um 16:47 schrieb Julia Lawall:> Are you sure that the C code is parsed successfully? I'm not at all sure
Quoted 2 lines
that static is allowed in an argument list. Types are allowed, bu static is only part of a type.
I'm pretty sure it is parsed successfully. At least spatch doesn't complain about it, no matter how many debug flags I specify.
I really only want to swap out the last parameter, but I'm having trouble coming up with the syntax. This should match, right?
@@
declarer name RB_DECLARE_CALLBACKS_MAX;
identifier NODE_END;
@@
RB_DECLARE_CALLBACKS_MAX(...,
- NODE_END
+ compute_subtree_last
);
Quoted 4 lines
For
augment_callbacks, either identifier or expression would be fine. Coccinelle has no idea what is going to happen toaugment_callbacksafterwards. It just sees a sequence of characters and classifies it as an identifier.
That's what I thought, thank you for confirming.
Quoted 1 line
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 7 lines · Christoph Böhmwalder
Am 27.03.20 um 16:47 schrieb Julia Lawall:> Are you sure that the C code is parsed successfully? I'm not at all sure
Quoted 2 lines
that static is allowed in an argument list. Types are allowed, bu static is only part of a type.
I'm pretty sure it is parsed successfully. At least spatch doesn't complain about it, no matter how many debug flags I specify.
Did you try spatch --parse-c file.c?
Quoted 4 lines
I really only want to swap out the last parameter, but I'm having trouble coming up with the syntax. This should match, right?
Quoted 8 lines
@@
declarer nameRB_DECLARE_CALLBACKS_MAX;
identifierNODE_END;
@@
RB_DECLARE_CALLBACKS_MAX(...,
-NODE_END
+compute_subtree_last
);
If the code is getting parsed, this should be fine.
Do you want to actually match NODE_END? If so, it shouldn't be declared as a metavariable.
julia
Quoted 9 lines
Quoted 4 lines
For
augment_callbacks, either identifier or expression would be fine. Coccinelle has no idea what is going to happen toaugment_callbacksafterwards. It just sees a sequence of characters and classifies it as an identifier.That's what I thought, thank you for confirming.
Quoted 1 line
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Am 27.03.20 um 17:15 schrieb Julia Lawall:
Quoted 13 lines · Christoph Böhmwalder
Quoted 8 lines
Am 27.03.20 um 16:47 schrieb Julia Lawall:> Are you sure that the C code is parsed successfully? I'm not at all sure
Quoted 2 lines
that static is allowed in an argument list. Types are allowed, bu static is only part of a type.
I'm pretty sure it is parsed successfully. At least spatch doesn't complain about it, no matter how many debug flags I specify.
Did you try spatch --parse-c
file.c?
It seems like RB_DECLARE_CALLBACKS_MAX is recognized as a "known macro"? Looks like it is able to parse this bit of code just fine:
$ spatch --parse-c drbd/drbd_interval.c --debug init_defs_builtins: /usr/local/bin/../lib/coccinelle/standard.h
PARSING: drbd/drbd_interval.c
parse error
= error in drbd/drbd_interval.h; set verbose_parsing for more info
badcount: 5
bad: unsigned int);
bad:
bad: #define drbd_for_each_overlap(i, root, sector, size) \ bad: for (i = drbd_find_overlap(root, sector, size); \ bad: i; \
BAD:!!!!! i = drbd_next_overlap(i, sector, size))
(ONCE) CPP-MACRO: found known macro = RB_DECLARE_CALLBACKS_MAX passed:static , augment_callbacks , struct drbd_interval , rb , passed:sector_t , end , NODE_END
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 160, nb passed = 2 =========> 1.23% passed
nb good = 160, nb bad = 0 =========> 100.00% good or passed
Quoted 2 lines
Do you want to actually match
NODE_END? If so, it shouldn't be declared as a metavariable.
Right, I do want to exactly match NODE_END, so I removed the declaration; still no match though. If it is detected as a known macro it should be able to be substituted, right?
Quoted 3 lines
julia
Thanks,
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 30 lines · Christoph Böhmwalder
Am 27.03.20 um 17:15 schrieb Julia Lawall:
Quoted 11 lines · Christoph Böhmwalder
Quoted 8 lines
Am 27.03.20 um 16:47 schrieb Julia Lawall:> Are you sure that the C code is
parsed successfully? I'm not at all sureQuoted 3 lines
that static is allowed in an argument list. Types are allowed, bu static
is only part of a type.Quoted 5 lines
Quoted 3 lines
I'm pretty sure it is parsed successfully. At least spatch doesn't complain
about it, no matter how many debug flags I specify.Did you try spatch --parse-c
file.c?It seems like
RB_DECLARE_CALLBACKS_MAXis recognized as a "known macro"? Looks like it is able to parse this bit of code just fine:$ spatch --parse-c drbd/drbd_interval.c --debug init_defs_builtins: /usr/local/bin/../lib/coccinelle/standard.hPARSING:
drbd/drbd_interval.c
parse error
= error indrbd/drbd_interval.h; setverbose_parsingfor more info
badcount: 5
bad: unsigned int);
bad:
Quoted 7 lines
bad: #define drbd_for_each_overlap(i, root, sector, size) \ bad: for (i = drbd_find_overlap(root, sector, size); \ bad: i; \BAD:!!!!! i =
drbd_next_overlap(i, sector, size))
(ONCE) CPP-MACRO: found known macro =RB_DECLARE_CALLBACKS_MAXpassed:static ,augment_callbacks, structdrbd_interval, rb , passed:sector_t , end ,NODE_END
It's not parsing anything. You can see that here. It is passing, ie ignoring, the entire command line.
I don't remember the exact situation with this code. Is there no semicolon at the end of the macro line?
julia
Quoted 16 lines
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 160, nb passed = 2 =========> 1.23% passed
nb good = 160, nb bad = 0 =========> 100.00% good or passedQuoted 2 lines
Do you want to actually match
NODE_END? If so, it shouldn't be declared as a metavariable.Right, I do want to exactly match
NODE_END, so I removed the declaration; still no match though. If it is detected as a known macro it should be able to be substituted, right?Quoted 1 line
Quoted 9 lines
Quoted 2 lines
julia
Thanks,
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Am 29.03.20 um 11:20 schrieb Julia Lawall>
Quoted 2 lines
It's not parsing anything. You can see that here. It is passing, ie ignoring, the entire command line.
Right, I misinterpreted that "passed" as "these parameters were passed to the macro:".
Quoted 3 lines
I don't remember the exact situation with this code. Is there no semicolon at the end of the macro line?
This is the exact piece of code:
RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);
Putting this (and only this) in a test.c file produces the same problem:
$ spatch --parse-c test.c --debug --verbose-parsing init_defs_builtins: /usr/local/bin/../lib/coccinelle/standard.h
PARSING: test.c
Warning: PARSING: type defaults to 'int'; value = [((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))]
ERROR-RECOV: end of file while in recovery mode
parsing pass2: try again
TYPEDEF:_handle_typedef=false. Not normal if don't come from exn
Warning: PARSING: type defaults to 'int'; value = [((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))]
ERROR-RECOV: end of file while in recovery mode
parsing pass3: try again
(ONCE) CPP-MACRO: found known macro = RB_DECLARE_CALLBACKS_MAX
TYPEDEF:_handle_typedef=false. Not normal if don't come from exn
Warning: PARSING: type defaults to 'int'; value = [[[0]]; ((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))] passed:static , augment_callbacks , struct drbd_interval , rb ,
passed:sector_t , end , NODE_END
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100%
nb good = 1, nb passed = 2 =========> 66.67% passed
nb good = 1, nb bad = 0 =========> 100.00% good or passed
Does this mean that this is just "unparseable"?
Quoted 30 lines
julia
Quoted 25 lines
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 160, nb passed = 2 =========> 1.23% passed
nb good = 160, nb bad = 0 =========> 100.00% good or passedQuoted 2 lines
Do you want to actually match
NODE_END? If so, it shouldn't be declared as a metavariable.Right, I do want to exactly match
NODE_END, so I removed the declaration; still no match though. If it is detected as a known macro it should be able to be substituted, right?Quoted 3 lines
julia
Thanks,
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 46 lines · Christoph Böhmwalder
Am 29.03.20 um 11:20 schrieb Julia Lawall>
Quoted 2 lines
It's not parsing anything. You can see that here. It is passing, ie ignoring, the entire command line.
Right, I misinterpreted that "passed" as "these parameters were passed to the macro:".
Quoted 3 lines
I don't remember the exact situation with this code. Is there no semicolon at the end of the macro line?
This is the exact piece of code:
RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);Putting this (and only this) in a
test.cfile produces the same problem:$ spatch --parse-c test.c --debug --verbose-parsing init_defs_builtins: /usr/local/bin/../lib/coccinelle/standard.hPARSING:
test.c
Warning: PARSING: type defaults to 'int'; value = [((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))]
ERROR-RECOV: end of file while in recovery mode
parsing pass2: try again
TYPEDEF:_handle_typedef=false. Not normal if don't come from exn
Warning: PARSING: type defaults to 'int'; value = [((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))]
ERROR-RECOV: end of file while in recovery mode
parsing pass3: try again
(ONCE) CPP-MACRO: found known macro =RB_DECLARE_CALLBACKS_MAXTYPEDEF:_handle_typedef=false. Not normal if don't come from exn
Warning: PARSING: type defaults to 'int'; value = [[[0]]; ((((0, 2)))); (Tag1 ("", (("", 0, 0, 0, ""), -1)), (0), ((0, 0, 0, 0)), 0, (3))] passed:static ,augment_callbacks, structdrbd_interval, rb , passed:sector_t , end ,NODE_END
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100% nb good = 1, nb passed = 2 =========> 66.67% passed
nb good = 1, nb bad = 0 =========> 100.00% good or passed
Quoted 1 line
Does this mean that this is just "unparseable"?
Everything would be fine if the "static" were not there.
Maybe you could use sed to replace (static by (STATIC in your code base, then run your script, and then use sed to go the other way...
I don't know if it could be possible to allow static in argument lists.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Am 29.03.20 um 13:24 schrieb Julia Lawall:
Quoted 4 lines
Everything would be fine if the "static" were not there.
Maybe you could use sed to replace (static by (STATIC in your code base, then run your script, and then use sed to go the other way...
The problem is that the scripts I'm writing here are called automatically as part of the build process, it's not just a one-shot replacement.
FWIW, this can not be parsed either:
RB_DECLARE_CALLBACKS_MAX(STATIC, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);
But this can:
RB_DECLARE_CALLBACKS_MAX(_STATIC, augment_callbacks, struct drbd_interval, rb, sector_t, end, NODE_END);
Maybe it would be possible to "#define _STATIC static" for this case -- spatch handles that just fine.
Quoted 1 line
I don't know if it could be possible to allow static in argument lists.
That would be amazing if it's easily possible. If not, I guess we can probably just live with the workaround.
Quoted 3 lines
julia
Thanks yet again for all your help.
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running DRBD HA — Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci