Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [lttng-dev] LTTng c++ loglevel not being set
@ 2015-06-25  1:42 Jeffrey Chen
  2015-06-25  5:55 ` Zifei Tong
  0 siblings, 1 reply; 2+ messages in thread
From: Jeffrey Chen @ 2015-06-25  1:42 UTC (permalink / raw)


I noticed a macro issue with LTTng under C++. The TRACEPOINT_LOGLEVEL would be ignored.

Here are my steps to repro the issue. My .tp file has the TRACEPOINT_LOGLEVEL macro set.
1. I generated the hello-tp.c file from the hello-tp.tp file using the lttng-gen-tp tool.
2. I renamed the generated .c file into .cpp and compiled with `g++ -c -I. hello-tp.cpp`
3. I wrote my c++ code called and call tracepoint macro, saved to hello.cpp, compiled with `g++ -c -I. hello.cpp`
4. I compile to an executable with `g++ -o hello hello.o hello-tp.o -llttng-ust -ldl`
5. I run the executable, and noticed the loglevel I set in the .tp file is not working. All the traces are still being written as default loglevel TRACE_DEBUG_LINE.

I tried confirming it by using `lttng list --userspace` command and I see "hello_world:my_first_tracepoint (loglevel: TRACE_DEBUG_LINE (13)) (type: tracepoint)"
You could see the loglevel was not set.

I tried the same steps without renaming to cpp files and build with `gcc` command and it works fine. I also tried without renaming to cpp files but compiled with `g++` command, but it also does not work. It seems to have something to do with c++ name mangling. Anyone noticed this issue? Thanks.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150624/b5e0e989/attachment.html>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [lttng-dev] LTTng c++ loglevel not being set
  2015-06-25  1:42 [lttng-dev] LTTng c++ loglevel not being set Jeffrey Chen
@ 2015-06-25  5:55 ` Zifei Tong
  0 siblings, 0 replies; 2+ messages in thread
From: Zifei Tong @ 2015-06-25  5:55 UTC (permalink / raw)


Hi,

I can confirm this issue (w/ lttng master HEAD + gcc 5.1).

In include/lttng/ust-tracepoint-event.h, we have
#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args)          \
static const int *                                                             \
        __ref_loglevel___##_provider##___##_name                               \
        __attribute__((weakref ("_loglevel___" #_provider "___" #_name)));     \
static const char *                                                            \
        __ref_model_emf_uri___##_provider##___##_name                          \
        __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\

I think the weakref attributes used here should use mangled symbol
name when compiling with C++.

A workaround is attached. However, I don't know how to disable symbol
mangling for a static variable, therefore the 'static' attribute is
dropped. I am not sure whether exporting the symbol will cause other
issues.

diff --git a/include/lttng/ust-tracepoint-event.h
b/include/lttng/ust-tracepoint-event.h
index 6632f67..7356451 100644
--- a/include/lttng/ust-tracepoint-event.h
+++ b/include/lttng/ust-tracepoint-event.h
@@ -676,9 +676,14 @@ const char
__tp_event_signature___##_provider##___##_name[] =              \
 #include <lttng/ust-tracepoint-event-reset.h>

 #undef TRACEPOINT_LOGLEVEL
+
+#ifdef __cplusplus
+#define DISABLE_MANGLING extern "C"
+#endif
+
 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel)               \
 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
-static const int *_loglevel___##__provider##___##__name =                 \
+DISABLE_MANGLING const int *_loglevel___##__provider##___##__name =
            \
                &_loglevel_value___##__provider##___##__name;

 #include TRACEPOINT_INCLUDE

Thanks,
Zifei

On Thu, Jun 25, 2015 at 9:42 AM, Jeffrey Chen <cpthk at hotmail.com> wrote:
>
> I noticed a macro issue with LTTng under C++. The TRACEPOINT_LOGLEVEL would be ignored.
>
> Here are my steps to repro the issue. My .tp file has the TRACEPOINT_LOGLEVEL macro set.
> 1. I generated the hello-tp.c file from the hello-tp.tp file using the lttng-gen-tp tool.
> 2. I renamed the generated .c file into .cpp and compiled with `g++ -c -I. hello-tp.cpp`
> 3. I wrote my c++ code called and call tracepoint macro, saved to hello.cpp, compiled with `g++ -c -I. hello.cpp`
> 4. I compile to an executable with `g++ -o hello hello.o hello-tp.o -llttng-ust -ldl`
> 5. I run the executable, and noticed the loglevel I set in the .tp file is not working. All the traces are still being written as default loglevel TRACE_DEBUG_LINE.
>
> I tried confirming it by using `lttng list --userspace` command and I see "hello_world:my_first_tracepoint (loglevel: TRACE_DEBUG_LINE (13)) (type: tracepoint)"
> You could see the loglevel was not set.
>
> I tried the same steps without renaming to cpp files and build with `gcc` command and it works fine. I also tried without renaming to cpp files but compiled with `g++` command, but it also does not work. It seems to have something to do with c++ name mangling. Anyone noticed this issue? Thanks.
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-25  5:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25  1:42 [lttng-dev] LTTng c++ loglevel not being set Jeffrey Chen
2015-06-25  5:55 ` Zifei Tong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox