* [lttng-dev] [RFC PATCH lttng-ust] Fix: don't generate 0-len array in tracepoint probes
@ 2016-05-30 16:56 Mathieu Desnoyers
0 siblings, 0 replies; 3+ messages in thread
From: Mathieu Desnoyers @ 2016-05-30 16:56 UTC (permalink / raw)
It is forbidden by C99, and gcc/g++ in pedantic mode generates errors
for e.g. field-less events.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
include/lttng/ust-tracepoint-event.h | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h
index 645c566..d9801a8 100644
--- a/include/lttng/ust-tracepoint-event.h
+++ b/include/lttng/ust-tracepoint-event.h
@@ -169,6 +169,7 @@ static const char \
#define TRACEPOINT_ENUM(_provider, _name, _values) \
const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
_values \
+ ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
};
#include TRACEPOINT_INCLUDE
@@ -290,6 +291,7 @@ static const char \
#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
_fields \
+ ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
};
#undef TRACEPOINT_ENUM
@@ -297,7 +299,7 @@ static const char \
static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
.name = #_provider "_" #_name, \
.entries = __enum_values__##_provider##_##_name, \
- .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name), \
+ .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
};
#include TRACEPOINT_INCLUDE
@@ -735,8 +737,8 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
size_t __event_len, __event_align; \
size_t __dynamic_len_idx = 0; \
union { \
- size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
- char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
+ size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
+ char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
} __stackvar; \
int __ret; \
\
@@ -869,7 +871,7 @@ static const struct lttng_event_desc __event_desc___##_provider##_##_name = {
.probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
.ctx = NULL, \
.fields = __event_fields___##_provider##___##_template, \
- .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
+ .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
.loglevel = &__ref_loglevel___##_provider##___##_name, \
.signature = __tp_event_signature___##_provider##___##_template, \
.u = { \
@@ -896,6 +898,7 @@ static const struct lttng_event_desc __event_desc___##_provider##_##_name = {
static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
#include TRACEPOINT_INCLUDE
+ NULL, /* Dummy, C99 forbids 0-len array. */
};
@@ -909,7 +912,7 @@ static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEP
static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
.provider = __tp_stringify(TRACEPOINT_PROVIDER),
.event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
- .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
+ .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
.head = { NULL, NULL },
.lazy_init_head = { NULL, NULL },
.lazy = 0,
--
2.1.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [lttng-dev] [RFC PATCH lttng-ust] Fix: don't generate 0-len array in tracepoint probes
2016-05-30 18:08 Sebastien Boisvert
@ 2016-05-31 9:36 ` Mathieu Desnoyers
0 siblings, 0 replies; 3+ messages in thread
From: Mathieu Desnoyers @ 2016-05-31 9:36 UTC (permalink / raw)
----- On May 30, 2016, at 8:08 PM, Sebastien Boisvert sboisvert at gydle.com wrote:
> Greetings,
>
> This is a response to the message
> https://lists.lttng.org/pipermail/lttng-dev/2016-May/026066.html
>
> The builds below were generated with:
>
> lttng-ust ba5b4491f94109eaca10b2c285f8d1f116a38e5c
> gcc 4.9.3-8ubuntu2~14.04
>
> First, I compiled lttng-ust with the "-pedantic" option of gcc to verify that
> this causes an array
> of compilation errors.
>
> sboisvert at Z1:~/lttng-ust$ ./bootstrap
> sboisvert at Z1:~/lttng-ust$ ./configure --prefix=$HOME/lttng-ust.build
> sboisvert at Z1:~/lttng-ust$ make CFLAGS="-pedantic" &> log
> sboisvert at Z1:~/lttng-ust$ grep error log
> //#error UST_COMPONENT is undefined
> ../include/lttng/ust-tracepoint-event.h:291:40: error: zero or negative size
> array '__event_fields___lttng_ust_statedump___start'
> ../include/lttng/ust-tracepoint-event.h:291:40: error: zero or negative size
> array '__event_fields___lttng_ust_statedump___end'
>
>
> I applied the patch that Mathieu provided, and built the project and ran the
> tests.
>
> sboisvert at Z1:~/lttng-ust$ patch -p1 < ~/lttng-ust-empty-array.patch
> patching file include/lttng/ust-tracepoint-event.h
>
> sboisvert at Z1:~/lttng-ust$ make CFLAGS="-pedantic" &> log
> sboisvert at Z1:~/lttng-ust$ cd tests
>
> ============================================================================
> Testsuite summary for lttng-ust 2.9.0-pre
> ============================================================================
> # TOTAL: 51
> # PASS: 51
> # SKIP: 0
> # XFAIL: 0
> # FAIL: 0
> # XPASS: 0
> # ERROR: 0
> ============================================================================
>
>
> So, this patch improves the user experience when one is using advanced linting
> flags as well as
> tracepoint event probes with no arguments, and it does not break the envelope of
> known behaviour.
>
>
> +1
Great! I have run the make check tests from lttng-tools also
with the patch applied, and they also all pass. So I am merging
this into master, 2.8, 2.7 of lttng-ust.
Thanks for helping us improve LTTng!
Mathieu
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [lttng-dev] [RFC PATCH lttng-ust] Fix: don't generate 0-len array in tracepoint probes
@ 2016-05-30 18:08 Sebastien Boisvert
2016-05-31 9:36 ` Mathieu Desnoyers
0 siblings, 1 reply; 3+ messages in thread
From: Sebastien Boisvert @ 2016-05-30 18:08 UTC (permalink / raw)
Greetings,
This is a response to the message https://lists.lttng.org/pipermail/lttng-dev/2016-May/026066.html
The builds below were generated with:
lttng-ust ba5b4491f94109eaca10b2c285f8d1f116a38e5c
gcc 4.9.3-8ubuntu2~14.04
First, I compiled lttng-ust with the "-pedantic" option of gcc to verify that this causes an array
of compilation errors.
sboisvert at Z1:~/lttng-ust$ ./bootstrap
sboisvert at Z1:~/lttng-ust$ ./configure --prefix=$HOME/lttng-ust.build
sboisvert at Z1:~/lttng-ust$ make CFLAGS="-pedantic" &> log
sboisvert at Z1:~/lttng-ust$ grep error log
//#error UST_COMPONENT is undefined
../include/lttng/ust-tracepoint-event.h:291:40: error: zero or negative size array '__event_fields___lttng_ust_statedump___start'
../include/lttng/ust-tracepoint-event.h:291:40: error: zero or negative size array '__event_fields___lttng_ust_statedump___end'
I applied the patch that Mathieu provided, and built the project and ran the tests.
sboisvert at Z1:~/lttng-ust$ patch -p1 < ~/lttng-ust-empty-array.patch
patching file include/lttng/ust-tracepoint-event.h
sboisvert at Z1:~/lttng-ust$ make CFLAGS="-pedantic" &> log
sboisvert at Z1:~/lttng-ust$ cd tests
============================================================================
Testsuite summary for lttng-ust 2.9.0-pre
============================================================================
# TOTAL: 51
# PASS: 51
# SKIP: 0
# XFAIL: 0
# FAIL: 0
# XPASS: 0
# ERROR: 0
============================================================================
So, this patch improves the user experience when one is using advanced linting flags as well as
tracepoint event probes with no arguments, and it does not break the envelope of known behaviour.
+1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-31 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30 16:56 [lttng-dev] [RFC PATCH lttng-ust] Fix: don't generate 0-len array in tracepoint probes Mathieu Desnoyers
2016-05-30 18:08 Sebastien Boisvert
2016-05-31 9:36 ` Mathieu Desnoyers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox