* [lttng-dev] Printing bit fields with LTTng
@ 2015-06-10 21:16 Chidhu R
2015-06-10 21:28 ` Simon Marchi
0 siblings, 1 reply; 4+ messages in thread
From: Chidhu R @ 2015-06-10 21:16 UTC (permalink / raw)
Hello,
I am getting compilation issues while trying to print bit field values with
LTTng.
Error:
hello.c: In function ?main?:
hello.c:36:1: error: ?typeof? applied to a bit-field
hello.c:36:1: error: ?typeof? applied to a bit-field
hello.c:36:1: error: ?typeof? applied to a bit-field
hello.c:36:1: error: ?sizeof? applied to a bit-field
Snippet:
struct abc{
int a:16;
int b:8;
};
Line 36: tracepoint(hello_world, my_third_tracepoint, aa.a, "welcome");
Line 37: printf("val = %x\n",aa.a);
tracepoint line results in compilation error.
printf succeeds.
Tp definition looks like this.
TRACEPOINT_EVENT(
hello_world,
my_third_tracepoint,
TP_ARGS(
uint32_t, arg,
const char * , my_string_arg
),
TP_FIELDS(
ctf_integer_hex(uint32_t, my_arg, arg)
ctf_string(field, my_string_arg)
)
)
How to print bit field values?
Thanks
Chid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150610/07bce60e/attachment.html>
^ permalink raw reply [flat|nested] 4+ messages in thread* [lttng-dev] Printing bit fields with LTTng 2015-06-10 21:16 [lttng-dev] Printing bit fields with LTTng Chidhu R @ 2015-06-10 21:28 ` Simon Marchi 2015-06-10 22:20 ` Simon Marchi 0 siblings, 1 reply; 4+ messages in thread From: Simon Marchi @ 2015-06-10 21:28 UTC (permalink / raw) On 10 June 2015 at 17:16, Chidhu R <chid1989 at gmail.com> wrote: > Hello, > > I am getting compilation issues while trying to print bit field values with > LTTng. > > Error: > > hello.c: In function ?main?: > hello.c:36:1: error: ?typeof? applied to a bit-field > hello.c:36:1: error: ?typeof? applied to a bit-field > hello.c:36:1: error: ?typeof? applied to a bit-field > hello.c:36:1: error: ?sizeof? applied to a bit-field > > Snippet: > > struct abc{ > int a:16; > int b:8; > }; > > Line 36: tracepoint(hello_world, my_third_tracepoint, aa.a, "welcome"); > Line 37: printf("val = %x\n",aa.a); > > tracepoint line results in compilation error. > printf succeeds. > > Tp definition looks like this. > > TRACEPOINT_EVENT( > hello_world, > my_third_tracepoint, > TP_ARGS( > uint32_t, arg, > const char * , my_string_arg > ), > TP_FIELDS( > ctf_integer_hex(uint32_t, my_arg, arg) > ctf_string(field, my_string_arg) > ) > ) > > How to print bit field values? > > Thanks > Chid I have no idea what the right fix would be, but an easy workaround could be to add 0 to your value: tracepoint(hello_world, my_third_tracepoint, aa.a + 0, "welcome"); I just tried it and it works. Simon ^ permalink raw reply [flat|nested] 4+ messages in thread
* [lttng-dev] Printing bit fields with LTTng 2015-06-10 21:28 ` Simon Marchi @ 2015-06-10 22:20 ` Simon Marchi 2015-06-11 18:11 ` Chidhu R 0 siblings, 1 reply; 4+ messages in thread From: Simon Marchi @ 2015-06-10 22:20 UTC (permalink / raw) On 10 June 2015 at 17:28, Simon Marchi <simon.marchi at polymtl.ca> wrote: > On 10 June 2015 at 17:16, Chidhu R <chid1989 at gmail.com> wrote: >> Hello, >> >> I am getting compilation issues while trying to print bit field values with >> LTTng. >> >> Error: >> >> hello.c: In function ?main?: >> hello.c:36:1: error: ?typeof? applied to a bit-field >> hello.c:36:1: error: ?typeof? applied to a bit-field >> hello.c:36:1: error: ?typeof? applied to a bit-field >> hello.c:36:1: error: ?sizeof? applied to a bit-field >> >> Snippet: >> >> struct abc{ >> int a:16; >> int b:8; >> }; >> >> Line 36: tracepoint(hello_world, my_third_tracepoint, aa.a, "welcome"); >> Line 37: printf("val = %x\n",aa.a); >> >> tracepoint line results in compilation error. >> printf succeeds. >> >> Tp definition looks like this. >> >> TRACEPOINT_EVENT( >> hello_world, >> my_third_tracepoint, >> TP_ARGS( >> uint32_t, arg, >> const char * , my_string_arg >> ), >> TP_FIELDS( >> ctf_integer_hex(uint32_t, my_arg, arg) >> ctf_string(field, my_string_arg) >> ) >> ) >> >> How to print bit field values? >> >> Thanks >> Chid > > I have no idea what the right fix would be, but an easy workaround > could be to add 0 to your value: > > tracepoint(hello_world, my_third_tracepoint, aa.a + 0, "welcome"); > > I just tried it and it works. > > Simon Alright, after a bit more investigation (thanks to Philippe Proulx), we found that this is caused by the SystemTap integration. If the SystemTap integration is enabled, each LTTng tracepoint also defines a SystemTap tracepoint. SystemTap uses sizeof() on the tracepoint's input arguments to find their sizes and typeof() to find their signedness. It encodes this info into a special section that then allows tools like gdb to re-use the tracepoints and get the argument values. For more information, look at the definitions of _SDT_ARGSIZE and _SDT_ARGSIGNED in /usr/include/sys/sdt.h. Pragmatically, I think that the "+ 0" trick is good enough, since it pleases SystemTap and is otherwise harmless. You could get the same result by casting your value to an integer type. However, you would need to carefully choose the size and signedness of the type you cast to, or it might alter your value. With + 0, it should work with any type. Thanks for raising this, I learned something new today. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [lttng-dev] Printing bit fields with LTTng 2015-06-10 22:20 ` Simon Marchi @ 2015-06-11 18:11 ` Chidhu R 0 siblings, 0 replies; 4+ messages in thread From: Chidhu R @ 2015-06-11 18:11 UTC (permalink / raw) Great. Thanks for sharing your inputs. I too learned something new. On Wed, Jun 10, 2015 at 3:20 PM, Simon Marchi <simon.marchi at polymtl.ca> wrote: > On 10 June 2015 at 17:28, Simon Marchi <simon.marchi at polymtl.ca> wrote: > > On 10 June 2015 at 17:16, Chidhu R <chid1989 at gmail.com> wrote: > >> Hello, > >> > >> I am getting compilation issues while trying to print bit field values > with > >> LTTng. > >> > >> Error: > >> > >> hello.c: In function ?main?: > >> hello.c:36:1: error: ?typeof? applied to a bit-field > >> hello.c:36:1: error: ?typeof? applied to a bit-field > >> hello.c:36:1: error: ?typeof? applied to a bit-field > >> hello.c:36:1: error: ?sizeof? applied to a bit-field > >> > >> Snippet: > >> > >> struct abc{ > >> int a:16; > >> int b:8; > >> }; > >> > >> Line 36: tracepoint(hello_world, my_third_tracepoint, aa.a, "welcome"); > >> Line 37: printf("val = %x\n",aa.a); > >> > >> tracepoint line results in compilation error. > >> printf succeeds. > >> > >> Tp definition looks like this. > >> > >> TRACEPOINT_EVENT( > >> hello_world, > >> my_third_tracepoint, > >> TP_ARGS( > >> uint32_t, arg, > >> const char * , my_string_arg > >> ), > >> TP_FIELDS( > >> ctf_integer_hex(uint32_t, my_arg, arg) > >> ctf_string(field, my_string_arg) > >> ) > >> ) > >> > >> How to print bit field values? > >> > >> Thanks > >> Chid > > > > I have no idea what the right fix would be, but an easy workaround > > could be to add 0 to your value: > > > > tracepoint(hello_world, my_third_tracepoint, aa.a + 0, "welcome"); > > > > I just tried it and it works. > > > > Simon > > Alright, after a bit more investigation (thanks to Philippe Proulx), > we found that this is caused by the SystemTap integration. If the > SystemTap integration is enabled, each LTTng tracepoint also defines a > SystemTap tracepoint. > > SystemTap uses sizeof() on the tracepoint's input arguments to find > their sizes and typeof() to find their signedness. It encodes this > info into a special section that then allows tools like gdb to re-use > the tracepoints and get the argument values. For more information, > look at the definitions of _SDT_ARGSIZE and _SDT_ARGSIGNED in > /usr/include/sys/sdt.h. > > Pragmatically, I think that the "+ 0" trick is good enough, since it > pleases SystemTap and is otherwise harmless. You could get the same > result by casting your value to an integer type. However, you would > need to carefully choose the size and signedness of the type you cast > to, or it might alter your value. With + 0, it should work with any > type. > > Thanks for raising this, I learned something new today. > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150611/a9964e3b/attachment.html> ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-11 18:11 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-06-10 21:16 [lttng-dev] Printing bit fields with LTTng Chidhu R 2015-06-10 21:28 ` Simon Marchi 2015-06-10 22:20 ` Simon Marchi 2015-06-11 18:11 ` Chidhu R
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox