lttng-ust.git
4 years agoFix: libc-wrapper: undef temporary token rather than value
Christophe Bedard [Mon, 1 Jun 2020 20:11:08 +0000 (16:11 -0400)] 
Fix: libc-wrapper: undef temporary token rather than value

The lttng-ust malloc wrapper defines pthread_mutex_lock/unlock
preprocessor tokens to ust_malloc_spin_lock/unlock around the definition
of a TLS variable, which uses pthread mutexes when relying on the
pthread key fallback. Undefining those tokens should be done on the
preprocessor token, rather than its value.

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I2053b79c88000e272c29b25ca105b1352ecfabd7

4 years agoFix: support compile units including 'sys/sdt.h' without defining SDT_USE_VARIADIC
Michael Jeanson [Fri, 26 Jun 2020 19:44:20 +0000 (15:44 -0400)] 
Fix: support compile units including 'sys/sdt.h' without defining SDT_USE_VARIADIC

Instead of using SDT_USE_VARIADIC from 'sys/sdt.h', use our own namespaced
macros since the instrumented application might already have included
'sys/sdt.h' without variadic support.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Idfece1a65a5296a90d33370bc8d73ea554c14b0f

4 years agoFix: event probes attached before event enabled
Francis Deslauriers [Tue, 5 May 2020 15:51:58 +0000 (11:51 -0400)] 
Fix: event probes attached before event enabled

Background
==========
When userspace events with exclusions are enabled by the CLI user, the
session daemon enables the events in a 3-steps process using the
following ustctl commands:
1. `LTTNG_UST_EVENT` to create an event and get an handle on it,
2. `LTTNG_UST_EXCLUSION` to attach exclusions, and
3. `LTTNG_UST_ENABLE` to activate the tracing of this event.

Also, the session daemon uses the `LTTNG_UST_SESSION_START` to start the
tracing of events. In various use cases, this can happen before OR after
the 3-steps process above.

Scenario
========
If the`LTTNG_UST_SESSION_START` is done before the 3-steps process the
tracer will end up not considering the exclusions and trace all events
matching the event name glob pattern provided at step #1.

This is due to the fact that when we do step #1, we end up calling
`lttng_session_lazy_sync_enablers()`. This function will sync the event
enablers if the session is active (which it is in our scenario because
of the _SESSION_START).
Syncing the enablers will then match event name glob patterns provided
by the user to the event descriptors of the tracepoints and attach
probes in their corresponding callsite on matches.

All of this is done before we even received the exclusions in step #2.

Problem
=======
The problem is that we attach probes to tracepoints before being sure we
received the entire description of the events.
Step #2 may reduced the set of tracepoints to trace so we must wait
until exclusions are all received to attached probes to tracepoints.

Solution
========
Only match event names and exclusions (and ultimately, register probes)
on enabled enablers to ensure that no other modifications will be
applied to the event.

Event enablers are enabled when at step #3.

Note
====
Filters are not causing problems here because adding a filter won't
change what tracepoints are to be traced.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id984f266d976f346b001db81cd8a2b74965b5ef2

4 years agoFix: agent: read: end of loop condition should exclude 0
Mathieu Desnoyers [Thu, 23 Apr 2020 16:51:40 +0000 (12:51 -0400)] 
Fix: agent: read: end of loop condition should exclude 0

Causes the agent to hang endlessly waiting for completion of the
loop.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agofix: Java examples CLASSPATH override
Michael Jeanson [Wed, 22 Apr 2020 20:32:51 +0000 (16:32 -0400)] 
fix: Java examples CLASSPATH override

Variables provided to make as arguments, called 'command variables' can't
be reassigned a new value in the Makefile. Since the CLASSPATH is now
passed this way in the glue between automake and the example makefiles,
use different names for the internal variables.

Change-Id: Id6289273f211f544a66d933a96f06df75243415f
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agofix: Add CLASSPATH to autoconf precious variables
Michael Jeanson [Wed, 22 Apr 2020 18:37:55 +0000 (14:37 -0400)] 
fix: Add CLASSPATH to autoconf precious variables

This will record the value of CLASSPATH in the autoconf cache and ensure
it's used when calling make even if it's not exported to the
environment.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ia06070dd352f9d3b6956a1ec0f4eb1d024f73179

4 years agoFix: Java agent: close session daemon socket on error
Mathieu Desnoyers [Wed, 22 Apr 2020 18:05:41 +0000 (14:05 -0400)] 
Fix: Java agent: close session daemon socket on error

When catching an error, close the socket used to communicate with the
session daemon rather than leaking it, before retrying to connect.

Also, when sleep is interrupted, there is no point in printing
out the stack trace. Just retry connection immediately.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: Java agent: handle partial payload read
Mathieu Desnoyers [Wed, 22 Apr 2020 17:30:40 +0000 (13:30 -0400)] 
Fix: Java agent: handle partial payload read

When reading from a TCP socket, there is no guarantee that the
read will return all the requested data. We need to loop and continue
reading until we gather all the expected data.

This fixes flakiness of the lttng-ust-java-tests.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoVersion 2.11.2 v2.11.2
Mathieu Desnoyers [Wed, 8 Apr 2020 13:44:49 +0000 (09:44 -0400)] 
Version 2.11.2

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: v.u.d might be uninitialized
Jonathan Rajotte [Mon, 9 Mar 2020 23:24:07 +0000 (19:24 -0400)] 
Fix: v.u.d might be uninitialized

lttng-filter-interpreter.c:301:17: warning: ‘v.u.d’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   ptr->u.d = v.u.d;

Indeed it seems that the value is never fetched if we compare to other
call sites and the dynamic call site further below.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I542d6db7514a2c39afe3613228577f34f194d672

4 years agoVersion 2.11.1 v2.11.1
Mathieu Desnoyers [Wed, 4 Mar 2020 21:08:35 +0000 (16:08 -0500)] 
Version 2.11.1

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: set FD_CLOEXEC on incoming FDs.
Jonathan Rajotte [Mon, 2 Mar 2020 19:21:33 +0000 (14:21 -0500)] 
Fix: set FD_CLOEXEC on incoming FDs.

The stream shm FDs are allocated by the consumer process, and then
passed to the applications over unix sockets. When opening those
file descriptors on reception, the FD_CLOEXEC flag is not set.

In a fork + exec scenario, parent process streams shm FDs and channel
wake FDs are present in the resulting child process.

Set FD_CLOEXEC on reception (ustcomm_recv_fds_unix_sock) to
prevent such scenario.

Change-Id: Id58077b272be9c1ab239846639ffd8103b3d50f1
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: tracepoint.h: Disable address sanitizer on pointer array section variables
Mathieu Desnoyers [Tue, 18 Feb 2020 00:25:01 +0000 (19:25 -0500)] 
Fix: tracepoint.h: Disable address sanitizer on pointer array section variables

The tracepoint header declares pointer global variables meant to be
placed contiguously within the __tracepoints_ptrs section, and then used
as an array of pointers when loading an executable or shared object.

Clang Address Sanitizer adds redzones around each variable, thus leading to
detection of a global buffer overflow.

Those redzones should not be placed within this section, because it
defeats its purpose. Therefore, teach asan not to add redzones
around those variables with an attribute.

Note that there does not appear to be any issue with gcc (tested with
gcc-8 with address sanitization enabled), and gcc ignores the
no_sanitize_address attribute when applied to a global variable.

Fixes: #1238
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoFix: jhash.h: remove out-of-bound reads
Mathieu Desnoyers [Tue, 18 Feb 2020 00:31:41 +0000 (19:31 -0500)] 
Fix: jhash.h: remove out-of-bound reads

jhash.h implements "special" code for valgrind because it reads memory
out-of-bound (and then applies a mask) when reading strings.

Considering that lttng-ust does not use jhash.h in a fast-path, remove
this "optimization" and use the verifiable VALGRIND code instead. This
fixes an ASan splat.

Fixes: #1238
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 years agoCleanup: remove trailing white spaces across project
Francis Deslauriers [Mon, 17 Feb 2020 15:46:45 +0000 (10:46 -0500)] 
Cleanup: remove trailing white spaces across project

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I15202338465ee56d33316cbc632d9e3bf44ee31e

4 years agoFix: lttng-ust-comm.c: return number of fd rather size of array
Francis Deslauriers [Tue, 26 Nov 2019 16:16:30 +0000 (11:16 -0500)] 
Fix: lttng-ust-comm.c: return number of fd rather size of array

There are two conflicting comments for this function. One says it
returns the size of the received data and the other says it returns the
number of fd received.

It's more useful to receive the number of fd.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I74084b461d396c3e623fa55100e6dd7e59dbea83

4 years agoliblttng-ust: exit loop early on event enabler match
Francis Deslauriers [Fri, 6 Dec 2019 22:49:35 +0000 (17:49 -0500)] 
liblttng-ust: exit loop early on event enabler match

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0fa3215f7cd6a2d32ac00d66cf5fc184abd14612

4 years agoAdd git-review config
Francis Deslauriers [Wed, 27 Nov 2019 20:16:06 +0000 (15:16 -0500)] 
Add git-review config

Add .gitreview for contributors wishing to use gerrit for patch
reviews.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I3ba853d0d68a660ac5d2d24c757e0f28b634977c

4 years agoFix: build with -fno-common
Michael Jeanson [Thu, 16 Jan 2020 15:59:14 +0000 (10:59 -0500)] 
Fix: build with -fno-common

GCC 10 will default to building with -fno-common, this inhibits the
linker from merging multiple tentative definitions of a symbol in an
archive. Keep only the declaration in the libustsnprintf.la convenience
library.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I8fb7c72811ce7e62f10342f55fcabeeabfdd4c67

5 years agoFix: uninitialized variable in lib_ring_buffer_reserve_committed
Mathieu Desnoyers [Tue, 22 Oct 2019 19:29:48 +0000 (15:29 -0400)] 
Fix: uninitialized variable in lib_ring_buffer_reserve_committed

This internal function implemented in libringbuffer is not used within
lttng-ust actually, but uses an uninitialized variable:

As reported by clang:

        ./frontend_internal.h:263:75: warning: variable 'idx' is uninitialized when used here [-Wuninitialized]
                struct commit_counters_hot *cc_hot = shmp_index(handle, buf->commit_hot, idx);
                                                                                         ^~~
        ./shm.h:74:86: note: expanded from macro 'shmp_index'
                        ____ptr_ret = (__typeof__(____ptr_ret)) _shmp_offset((handle)->table, &(ref)._ref, index, sizeof(*____ptr_ret));        \
                                                                                                           ^~~~~
        ./frontend_internal.h:262:27: note: initialize the variable 'idx' to silence this warning
                unsigned long offset, idx, commit_count;
                                         ^
                                          = 0
        In file included from ring_buffer_backend.c:29:
        In file included from ./backend.h:33:
        ./frontend_internal.h:263:75: warning: variable 'idx' is uninitialized when used here [-Wuninitialized]
                struct commit_counters_hot *cc_hot = shmp_index(handle, buf->commit_hot, idx);
                                                                                         ^~~
        ./shm.h:74:86: note: expanded from macro 'shmp_index'
                        ____ptr_ret = (__typeof__(____ptr_ret)) _shmp_offset((handle)->table, &(ref)._ref, index, sizeof(*____ptr_ret));        \
                                                                                                           ^~~~~
        ./frontend_internal.h:262:27: note: initialize the variable 'idx' to silence this warning
                unsigned long offset, idx, commit_count;
                                         ^
                                          = 0

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: document proper liburcu version dependency
Michael Jeanson [Mon, 21 Oct 2019 17:04:31 +0000 (13:04 -0400)] 
Fix: document proper liburcu version dependency

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: Add missing files to distribution
Michael Jeanson [Mon, 21 Oct 2019 17:04:14 +0000 (13:04 -0400)] 
Fix: Add missing files to distribution

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoVersion 2.11.0 v2.11.0
Mathieu Desnoyers [Thu, 17 Oct 2019 19:35:50 +0000 (15:35 -0400)] 
Version 2.11.0

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoVersion 2.11.0-rc5 v2.11.0-rc5
Mathieu Desnoyers [Fri, 11 Oct 2019 20:10:48 +0000 (16:10 -0400)] 
Version 2.11.0-rc5

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: lttng perf counter deadlock
Mathieu Desnoyers [Mon, 7 Oct 2019 19:45:46 +0000 (15:45 -0400)] 
Fix: lttng perf counter deadlock

Using the ust_lock() to lazily setup the perf counters introduces
a scenario where this lock is nested within the urcu-bp read-side
lock.

However, the LTTNG_UST_WAIT_QUIESCENT ust command requires that
urcu-bp synchronize_rcu() is performed with the ust_lock() held.

This inter-dependency introduces a deadlock:

Thread A                          Thread B

rcu_read_lock()
                                  ust_lock()
                                  synchronize_rcu() (blocked by rcu
                                                     read-side lock)
ust_lock()   <-- deadlock

Introduce a new lttng_perf_lock to protect the lttng perf context
data structures from concurrent modifications and from fork. This
lock can be nested within the ust_lock, but never the opposite.

This removes the circular locking dependency involving urcu bp.

Fixes: #1202
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoRevert "Fix: fd tracker: do not allow signal handlers to close lttng-ust FDs"
Mathieu Desnoyers [Fri, 11 Oct 2019 14:12:04 +0000 (10:12 -0400)] 
Revert "Fix: fd tracker: do not allow signal handlers to close lttng-ust FDs"

This reverts commit 01be959de2f1879fcd54a47a74ff443e2ef12f90.

Fixes: #1204
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: fd tracker: do not allow signal handlers to close lttng-ust FDs
Mathieu Desnoyers [Mon, 7 Oct 2019 19:41:10 +0000 (15:41 -0400)] 
Fix: fd tracker: do not allow signal handlers to close lttng-ust FDs

Split the thread_fd_tracking state from the ust_fd_mutex_nest used to
track whether a signal handler is nested over a fd tracker lock.

lttng-ust listener threads need to invoke
lttng_ust_fd_tracker_register_thread() so the fd tracker can
distinguish them from application threads.

Otherwise, using ust_fd_mutex_nest to try to distinguish between
ust and application threads makes it possible for signal handlers
to appear as if they are ust listener threads, and thus attempt to
close UST file descriptors.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fixes: #1199
5 years agoFix: fd tracker: provide async-signal-safety for close wrapper
Mathieu Desnoyers [Fri, 4 Oct 2019 19:04:13 +0000 (15:04 -0400)] 
Fix: fd tracker: provide async-signal-safety for close wrapper

close(3) is part of the async-signal-safe functions. Therefore, it is
expected that the close wrapper provided by liblttng-ust-fd-tracker
behaves in a async-signal-safe way.

Use a similar strategy as ust_lock() does: disable signals when taking
and releasing the lock, and keep track of nesting with a TLS variable.
This ensures signals are restored to their original state when close(3)
ends up being invoked.

Fixes: #1199
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: Disable cancellation around fd tracker lock
Mathieu Desnoyers [Fri, 4 Oct 2019 14:15:37 +0000 (10:15 -0400)] 
Fix: Disable cancellation around fd tracker lock

When using the ust fd tracker LD_PRELOAD library (liblttng-ust-fd.so),
cancelling other threads while they issue "close()" leads to deadlocks.

Fixes: #1201
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: Lock FD tracker across fork
Mathieu Desnoyers [Fri, 4 Oct 2019 14:07:03 +0000 (10:07 -0400)] 
Fix: Lock FD tracker across fork

If fork() is performed while other threads are holding the fd tracker
lock, it will stay in locked state in the child process and eventually
cause a deadlock.

One way to solve this is to hold the fd tracker lock across fork(), in
the same way we do for the ust_lock. This ensures no other threads are
holding that lock in the parent, and therefore provides a consistent
lock state in the child.

Fixes: #1199
Fixes: #1200
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agodoc/man: include build version in GitHub links
Philippe Proulx [Tue, 22 May 2018 15:47:07 +0000 (11:47 -0400)] 
doc/man: include build version in GitHub links

Linking to master branch files on GitHub is not safe because files could
be renamed, whereas the layout stays the same for a given version tag.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCheck if the AR environment variable exists for cross compilation
Maxime SORIN [Fri, 17 May 2019 12:30:01 +0000 (14:30 +0200)] 
Check if the AR environment variable exists for cross compilation

Signed-off-by: Maxime SORIN <msorin@msorin.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoVersion 2.11.0-rc4 v2.11.0-rc4
Mathieu Desnoyers [Sat, 7 Sep 2019 11:59:01 +0000 (12:59 +0100)] 
Version 2.11.0-rc4

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: don't wait for initial statedump when 0 session active
Mathieu Desnoyers [Fri, 2 Aug 2019 14:43:35 +0000 (10:43 -0400)] 
Fix: don't wait for initial statedump when 0 session active

commit eb0e6022d5e2 "Fix: wait for initial statedump before proceeding
to the main program"

introduced a regression when an application interacts with a session
daemon which has 0 session active.

An application linked against lttng-ust started with
LTTNG_UST_REGISTER_TIMEOUT=-1 hangs forever.

Fix this by decrementing the semaphore if no statedump was requested
when the registration done command is received.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: wait for initial statedump before proceeding to the main program
Gabriel-Andrew Pollo-Guilbert [Mon, 29 Jul 2019 22:05:35 +0000 (18:05 -0400)] 
Fix: wait for initial statedump before proceeding to the main program

In the case of short lived applications, the application may exit before
the initial statedump has completed.

Higher-level trace analysis features such as translating addresses to
symbols rely on statedump. That information is required for those
analyses to work on such short-lived applications.

Force the statedump to occur before handing the control to the
application.

Fixes #1190

Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabriel.pollo-guilbert@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoUse MAP_POPULATE to reduce pagefault when available
Jonathan Rajotte [Mon, 29 Jul 2019 18:49:59 +0000 (14:49 -0400)] 
Use MAP_POPULATE to reduce pagefault when available

Any ring buffer configuration bigger than PAGE_SIZE would result
in an increased latency for the first tracepoint hit (1200ns) landing on a
new PAGE_SIZE sized chunk of the mapped memory. This happens at least
for the first ring buffer traversal.

To alleviate this we can use MAP_POPULATE that will "prefault" the page
tables.

A similar flag seems to exist on freebsd (MAP_PREFAULT_READ) but I do
not have access to a system to test it and ensure it does indeed results
in the same effect. It mostly indicates that it prefaults for the
read case so I doubt it is the case.

Default to using MAP_POPULATE on Linux only for now. Support of
prefaulting on other platforms will be added as needed.

Link: https://lists.lttng.org/pipermail/lttng-dev/2019-July/029116.html
Link: https://lists.lttng.org/pipermail/lttng-dev/2019-July/029122.html
Tested-by: Yiteng Guo <guoyiteng@gmail.com>
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: remove uninitialised value
Gabriel-Andrew Pollo-Guilbert [Mon, 29 Jul 2019 15:14:26 +0000 (11:14 -0400)] 
Fix: remove uninitialised value

Commit 973eac638e4fd introduces an uninitialised value that may prevent
shared memory from being allocated. The compiler didn't give any warning
because the pointer to the value is sent to a function that don't do anything
with it. We simply pass NULL to that function.

Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabriel.pollo-guilbert@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: GCC unaligned pointer warnings
Gabriel-Andrew Pollo-Guilbert [Fri, 26 Jul 2019 22:00:07 +0000 (18:00 -0400)] 
Fix: GCC unaligned pointer warnings

The release of GCC 9 added the following warning:

-Waddress-of-packed-member, enabled by default, warns about an
unaligned pointer value from the address of a packed member of a
struct or union.

The warning is triggered in some place in LTTng-UST in cases where we
pass a pointer to get a result. Rather than passing the pointer directly
from the struct member, we get the result into a local storage, then
write into in the struct.

Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabriel.pollo-guilbert@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: do not use diagnostic pragma when GCC version is lower than 4.6.0
Jonathan Rajotte [Thu, 4 Jul 2019 18:51:37 +0000 (14:51 -0400)] 
Fix: do not use diagnostic pragma when GCC version is lower than 4.6.0

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: missing define when not building with gcc
Jonathan Rajotte [Thu, 4 Jul 2019 18:51:36 +0000 (14:51 -0400)] 
Fix: missing define when not building with gcc

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: client_sequence_number may dereference NULL pointer
Mathieu Desnoyers [Tue, 4 Jun 2019 18:36:44 +0000 (14:36 -0400)] 
Fix: client_sequence_number may dereference NULL pointer

Found by Coverity:
CID 1400710 (#1 of 1): Dereference null return value (NULL_RETURNS)
3. dereference: Dereferencing a null pointer header.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: namespace our gettid wrapper
Michael Jeanson [Mon, 3 Jun 2019 19:25:32 +0000 (15:25 -0400)] 
Fix: namespace our gettid wrapper

Since glibc 2.30, a gettid wrapper was added that conflicts with our
static declaration. Namespace our wrapper so there is no conflict,
we'll add support for the glibc provided wrapper in a further commit.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoVersion 2.11.0-rc3 v2.11.0-rc3
Mathieu Desnoyers [Fri, 24 May 2019 20:29:16 +0000 (16:29 -0400)] 
Version 2.11.0-rc3

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoCleanup: bitfields: streamline use of underscores
Mathieu Desnoyers [Fri, 17 May 2019 13:55:23 +0000 (09:55 -0400)] 
Cleanup: bitfields: streamline use of underscores

Do not prefix macro arguments with underscores. Use one leading
underscore as prefix for local variables defined within macros.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoSilence compiler "always false comparison" warning
Mathieu Desnoyers [Tue, 14 May 2019 14:49:37 +0000 (10:49 -0400)] 
Silence compiler "always false comparison" warning

Compiling the bitfield test with gcc -Wextra generates those warnings:

 ../../include/babeltrace/bitfield-internal.h:38:45: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
 #define _bt_is_signed_type(type) ((type) -1 < (type) 0)

This is the intent of the macro. Disable compiler warnings around use of
that macro.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com
5 years agoFix: bitfield: shift undefined/implementation defined behaviors
Mathieu Desnoyers [Tue, 14 May 2019 14:48:15 +0000 (10:48 -0400)] 
Fix: bitfield: shift undefined/implementation defined behaviors

bitfield.h uses the left shift operator with a left operand which
may be negative. The C99 standard states that shifting a negative
value is undefined.

When building with -Wshift-negative-value, we get this gcc warning:

In file included from /home/smarchi/src/babeltrace/include/babeltrace/ctfser-internal.h:44:0,
                 from /home/smarchi/src/babeltrace/ctfser/ctfser.c:42:
/home/smarchi/src/babeltrace/include/babeltrace/ctfser-internal.h: In function ‘bt_ctfser_write_unsigned_int’:
/home/smarchi/src/babeltrace/include/babeltrace/bitfield-internal.h:116:24: error: left shift of negative value [-Werror=shift-negative-value]
   mask = ~((~(type) 0) << (__start % ts));  \
                        ^
/home/smarchi/src/babeltrace/include/babeltrace/bitfield-internal.h:222:2: note: in expansion of macro ‘_bt_bitfield_write_le’
  _bt_bitfield_write_le(ptr, type, _start, _length, _v)
  ^~~~~~~~~~~~~~~~~~~~~
/home/smarchi/src/babeltrace/include/babeltrace/ctfser-internal.h:418:3: note: in expansion of macro ‘bt_bitfield_write_le’
   bt_bitfield_write_le(mmap_align_addr(ctfser->base_mma) +
   ^~~~~~~~~~~~~~~~~~~~

This boils down to the fact that the expression ~((uint8_t)0) has type
"signed int", which is used as an operand of the left shift.  This is due
to the integer promotion rules of C99 (6.3.3.1):

    If an int can represent all values of the original type, the value is
    converted to an int; otherwise, it is converted to an unsigned int.
    These are called the integer promotions. All other types are unchanged
    by the integer promotions.

We also need to cast the result explicitly into the left hand
side type to deal with:

warning: large integer implicitly truncated to unsigned type [-Woverflow]

The C99 standard states that a right shift has implementation-defined
behavior when shifting a signed negative value. Add a preprocessor check
that the compiler provides the expected behavior, else provide an
alternative implementation which guarantees the intended behavior.

A preprocessor check is also added to ensure that the compiler
representation for signed values is two's complement, which is expected
by this header.

Document that this header strictly respects the C99 standard, with
the exception of its use of __typeof__.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: Update coding style link
Stefan Wallentowitz [Fri, 10 May 2019 14:00:58 +0000 (16:00 +0200)] 
Fix: Update coding style link

The documentation at kernel.org changed and the coding style has
moved.

Signed-off-by: Stefan Wallentowitz <stefan@wallentowitz.de>
5 years agoFix: alignment of ring buffer shm space reservation
Mathieu Desnoyers [Fri, 10 May 2019 15:51:10 +0000 (11:51 -0400)] 
Fix: alignment of ring buffer shm space reservation

commit a9ff648cc "Implement file-backed ring buffer" changes the order
of backend fields with respect to the frontend per-subbuffer
commit_counters_hot and commit_counters_cold arrays, but does not change
that order when calculating the space needed in the initial pass.

This discrepancy can be an issue for field alignment calculation.
Let's analyse the situation. If the incorrect position of alignment
calculation leads to a larger space reserved than the actual
allocations, no ill effect will be perceived by the user. However,
if space calculation is less than the allocations, it will cause the
ring buffer (and thus channel) creation to fail.

The fields that are incorrectly misplaced in size calculation (in
officially released versions) are:

* struct commit_counters_hot is aligned on CAA_CACHE_LINE_SIZE,
* struct commit_counters_cold is aligned on CAA_CACHE_LINE_SIZE,

Those are placed after (should be before) the backend fields:

* struct lttng_ust_lib_ring_buffer_backend_pages_shmp aligned on the
  natural alignment of ssize_t,
* alignment on page size,
* struct lttng_ust_lib_ring_buffer_backend_pages, aligned on the natural
  alignment of ssize_t,
* struct lttng_ust_lib_ring_buffer_backend_subbuffer, aligned on natural
  alignment of unsigned long,
* struct lttng_ust_lib_ring_buffer_backend_counts, aligned on natural
  alignment of uint64_t.

The largest alignment is the alignment on page size in the backend
fields. If we have a channel configured within specific ranges of
sub-buffer count, we should reach commit counters array dimensions
which cause the page size alignment to be lower than it should be in
the space calculation, and therefore leads to a problematic scenario
where space allocation will fail, thus leading to channel creation
failures.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: allocate ts_end in ringbuffer shared memory
Gabriel-Andrew Pollo-Guilbert [Fri, 10 May 2019 15:26:32 +0000 (11:26 -0400)] 
Fix: allocate ts_end in ringbuffer shared memory

Allocate the memory used by the ts_end field added by commit 6c737d05.
When allocating lots of subbuffer for a channel (512 or more),
zalloc_shm() will fail to allocate all the objects because the allocated
memory map didn't take account the newly added field.

With lttng-tools version: b14f53d4 (2.12.0-pre)

Steps to reproduce the bug:

1. lttng-sessiond -vvv --verbose-consumer
2. start a traced application
3. lttng create "test-sesssion"
4. lttng enable-channel --userspace --num-subbuf 512 \
                                --subbuf-size 8k --overwrite channel
5. lttng enable-event -u -a -c channel
6. lttng start

After these steps, the following error message show should be thrown:

Error: ask_channel_creation consumer command failed
Error: Error creating UST channel "channel" on the consumer daemon

Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabriel.pollo-guilbert@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: timestamp_end field should include all events within sub-buffer
Mathieu Desnoyers [Tue, 30 Apr 2019 15:23:44 +0000 (11:23 -0400)] 
Fix: timestamp_end field should include all events within sub-buffer

Fix for timestamp_end not including all events within sub-buffer. This
happens if a thread is preempted/interrupted for a long time between
reserve and commit (e.g. in the middle of a packet), which causes the
timestamp used for timestamp_end field of the packet header to be lower
than the timestamp of the last events in the buffer (those following the
event that was preempted/interrupted between reserve and commit).

The fix involves sampling the timestamp when doing the last space
reservation in a sub-buffer (which necessarily happens before doing the
delivery after its last commit). Save this timestamp temporarily in a
per-sub-buffer control area (we have exclusive access to that area until
we increment the commit counter).

Then, that timestamp value will be read when delivering the sub-buffer,
whichever event or switch happens to be the last to increment the commit
counter to perform delivery. The timestamp value can be read without
worrying about concurrent access, because at that point sub-buffer
delivery has exclusive access to the sub-buffer.

This ensures the timestamp_end value is always larger or equal to the
timestamp of the last event, always below or equal the timestamp_begin
of the following packet, and always below or equal the timestamp of the
first event in the following packet.

This changes the layout of the ring buffer shared memory area, so we
need to bump the LTTNG_UST_ABI version from 7.2 to 8.0, thus requiring
locked-step upgrade between liblttng-ust in applications, session
daemon, and consumer daemon. This fix therefore cannot be backported
to existing stable releases.

Fixes: #1183
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoust-ctl API: clarify getter usage requirements
Mathieu Desnoyers [Wed, 10 Apr 2019 15:14:03 +0000 (11:14 -0400)] 
ust-ctl API: clarify getter usage requirements

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: don't access packet header for stream_id and stream_instance_id getters
Mathieu Desnoyers [Wed, 10 Apr 2019 14:31:47 +0000 (10:31 -0400)] 
Fix: don't access packet header for stream_id and stream_instance_id getters

The stream ID and stream instance ID are invariant for a stream, so
there is no point reading them from the packet header currently owned by
the consumer (between get/put subbuf).

Actually, the consumer try to access the stream_id from the live timer
when sending a live beacon without getting the reader subbuffer first.
Doing so is racy against producers. In typical live scenarios
(non-overwrite channels), the producers will always write the same
stream id and stream instance id values at the same header offsets,
which will "work", except for the initial state of an empty buffer:
the value "0" will be returned (erroneously).

For the less frequently used scenario of a live session with "overwrite"
channels, this is handled by issuing a CHAN_WARN_ON, which disables
tracing for the channel, and prints warning to the consumerd console
when running consumerd with LTTNG_UST_DEBUG=1.

In the case where a ring buffer does not have any data ready, it makes
no sense to try to get a subbuffer for reading anyway, so the approach
was broken.

So return the stream id and stream instance id from the internal
data structures rather than reading it from the ring buffer.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agocompat: work around broken _SC_NPROCESSORS_CONF on MUSL libc
Michael Jeanson [Wed, 20 Mar 2019 15:07:35 +0000 (11:07 -0400)] 
compat: work around broken _SC_NPROCESSORS_CONF on MUSL libc

On MUSL libc the _SC_NPROCESSORS_CONF sysconf will report the number of
CPUs allocated to the task based on the affinity mask instead of the
total number of CPUs configured on the system.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agodoc: remove repeated word in coding style
Sebastien Boisvert [Thu, 14 Mar 2019 12:56:15 +0000 (08:56 -0400)] 
doc: remove repeated word in coding style

Signed-off-by: Sebastien Boisvert <seb@boisvert.info>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agotap-driver.sh: flush stdout after each test result
Michael Jeanson [Thu, 14 Mar 2019 15:39:59 +0000 (11:39 -0400)] 
tap-driver.sh: flush stdout after each test result

This is useful in a CI system where stdout is fully buffered and you
look at the console output to see which test is hanging.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoMove wait_shm_mmap initialization to library constructor
Jonathan Rajotte [Fri, 8 Mar 2019 15:01:12 +0000 (10:01 -0500)] 
Move wait_shm_mmap initialization to library constructor

Prevent us from deadlocking ourself if some glibc implementation
decide to hold the dl_load_* locks on fork operation.

This happens on Yocto Rocko and up when performing python tracing (import
lttngust). Why Yocto decided to patch glibc this way is a mystery
(ongoing effort) [1][2][3].

Anyhow, we can prevent this by moving the initialization of the
wait_shm_mmap to the library constructor since the dl_load_* locks are
nestable mutex.

Nothing in the git log for the wait_shm_mmap indicate a specific reason
to why it was done inside the listener thread. Doing it inside
wait_for_sessiond can help in some corner cases were /dev/shm
(or the shm path) files are unlinked. This is not much of an advantage.

[1] From yocto master branch: ee9db1a9152e8757ce4d831ff9f4472ff5a57dad
[2] From OE-Core: f2e586ebf59a9b7d5b216fc92aeb892069a4b0c1
[3] https://www.mail-archive.com/openembedded-core@lists.openembedded.org/msg101186.html

This was tested on a Yocto Rocko qemu x86-64 image with python agent
enabled.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoVersion 2.11.0-rc2 v2.11.0-rc2
Mathieu Desnoyers [Fri, 25 Jan 2019 22:41:08 +0000 (17:41 -0500)] 
Version 2.11.0-rc2

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 years agoFix: Initialize fd field of struct lttng_ust_elf to -1 at allocation
Jonathan Rajotte [Wed, 14 Nov 2018 19:38:37 +0000 (14:38 -0500)] 
Fix: Initialize fd field of struct lttng_ust_elf to -1 at allocation

In rare cases when the executable cannot be open, using a default value
of zero lead to invalid close call and fd tracker removal.

fixes #1171

Reported-by: Stefan Palade <stefan.palade@windriver.com>
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoClarify lib_ring_buffer_switch_slow() requirements
Mathieu Desnoyers [Thu, 8 Nov 2018 17:42:29 +0000 (12:42 -0500)] 
Clarify lib_ring_buffer_switch_slow() requirements

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: address shellcheck warnings/errors in example scripts
Omair Majid [Thu, 11 Oct 2018 18:28:49 +0000 (14:28 -0400)] 
Fix: address shellcheck warnings/errors in example scripts

ShellCheck points out a number of warnings in the example scripts. In
particular, a number of normal and special shell variables are not
quoted correctly.

Signed-off-by: Omair Majid <omajid@redhat.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: check for event class/instance prototype mismatch
Mathieu Desnoyers [Thu, 27 Sep 2018 19:21:16 +0000 (15:21 -0400)] 
Fix: check for event class/instance prototype mismatch

The TP_ARGS() for an event instance belonging to an event class
must have compatible types with the event class TP_ARGS().

Failure to follow this rule leads to a prototype mismatch between the
tracepoint call site and the probe function. A common effect perceived
is that events with prototype mismatch between call site and probe
function are never traced.

Fix this by enforcing a compile-time check of the event instance and
class prototypes, similarly to what is done in LTTng modules.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: race between statedump and library destructor
Mathieu Desnoyers [Thu, 20 Sep 2018 18:11:17 +0000 (14:11 -0400)] 
Fix: race between statedump and library destructor

The locking scheme for ust_lock() returns a teardown state (variable
lttng_ust_comm_should_quit) which is set by library destructor with lock
held.

It requires that when ust listener threads use this lock to protect
against concurrent accesses to a data structure, in addition to take
the lock, they need to check the return value of ust_lock() and
skip their critical section entirely if the return value indicates
that teardown is ongoing.

Iteration over all loaded libraries by lttng_ust_dl_update() starts by
iter_begin which grabs the lock, and sets data->cancel state
appropriately if teardown is ongoing. Then extract_bin_info_events()
uses the data->cancel state to skip over use of the protected structures
as needed, but iter_end() fails to take this data->cancel state into
account. Therefore, it can access data structures concurrently while
their teardown is ongoing which leads to crashes.

Fixes: #1169
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: reset procname on fork in child process
Mathieu Desnoyers [Fri, 7 Sep 2018 15:28:51 +0000 (11:28 -0400)] 
Fix: reset procname on fork in child process

lttng-ust(3) documents:

   procname
      Thread name, as set by exec(3) or prctl(2). It is recommended
      that programs set their thread name with prctl(2) before
      hitting the first tracepoint for that thread.

We can rightfully expect that this applies to the first thread created
within a child process upon fork. Reset the procname cache in the child
on fork.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoVersion 2.11.0-rc1 v2.11.0-rc1
Mathieu Desnoyers [Thu, 6 Sep 2018 15:32:24 +0000 (11:32 -0400)] 
Version 2.11.0-rc1

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: add missing stdbool.h include
Michael Jeanson [Wed, 5 Sep 2018 19:56:59 +0000 (15:56 -0400)] 
Fix: add missing stdbool.h include

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoMove symbol preventing unloading of probe providers
Francis Deslauriers [Tue, 4 Sep 2018 21:05:14 +0000 (17:05 -0400)] 
Move symbol preventing unloading of probe providers

Issue
=====
Calling dlclose on the probe provider library that first loaded
__tracepoints__disable_destructors in the symbol table does not
unregister the probes from the callsites as the destructors are not
executed.

The __tracepoints__disable_destructors weak symbol is exposed by probe
providers, liblttng-ust.so and liblttng-ust-tracepoint.so libraries. If
a probe provider is loaded first into the address space, its definition
is bound to the symbol. All the subsequent loaded libraries using the
symbol will use the existing definition of the symbol, thus creating a
situation where liblttng-ust.so or liblttng-ust-tracepoint.so depend on
the probe provider library.

This prevents the dynamic loader from unloading the library as it is
still in use by other libraries. Because of this, the execution of its
destructors and the unregistration of the probes is postponed. Since the
unregistration of the probes is postponed, event will be generated if
the callsite is executed even though the probes should not be loaded.

Solution
========
To overcome this issue, we no longer expose this symbol in the
tracepoint.h file to remove the explicit dependency of the probe
provider on the symbol. We instead use the existing dlopen handle on
liblttng-ust-tracepoint.so and use dlsym to get handles on functions
that disable and get the state of the destructors.

Version compatibility
=====================
- This change is backward compatible with UST applications and libraries
  built on lttng-ust version before 2.11. Those applications will use
  the __tracepoints__disable_destructors symbol that is now exposed
  as a weak symbol in the liblttng-ust-tracepoint.so library. This
  symbol is alway checked in 2.11 in case an old app is running.

- Applications built with this change will also work in older versions
  of lttng-ust as there is a check to see if the new destructor state
  checking method should be used, if it is not we fallback to a
  compatibility method. To ensure compatibility in this case, we also
  look up and keep up-to-date the __tracepoints__disable_destructors
  value using the dlopen-dlsym combo.

- A mix of applications/probes builds in part against 2.10 and 2.11
  also work. When setting the destructor state from a binary built
  against 2.11 headers, both old/new states are set, so a binary built
  against 2.10 will correctly see the old state. When querying the state
  from a binary built against 2.11 headers, both old and new states are
  queried, so if the state has been set from a binary built against
  2.10 headers, the old state will be set.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: Remove unused line from liblttng-ust-fd makefile
Mathieu Desnoyers [Mon, 20 Aug 2018 21:20:05 +0000 (17:20 -0400)] 
Fix: Remove unused line from liblttng-ust-fd makefile

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: add liblttng-ust dependency to liblttng-ust-fd
Vitaly Lipatov [Sat, 30 Jun 2018 09:07:34 +0000 (12:07 +0300)] 
Fix: add liblttng-ust dependency to liblttng-ust-fd

Signed-off-by: Vitaly Lipatov <lav@etersoft.ru>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: use LIBDL/LIBC_DL to select either libdl or libc
Vitaly Lipatov [Sat, 30 Jun 2018 09:07:21 +0000 (12:07 +0300)] 
Fix: use LIBDL/LIBC_DL to select either libdl or libc

Use LTTNG_UST_BUILD_WITH_LIBDL/LIBC_DL variables to choose between -ldl
and -lc.

Add a missing direct dependency against -ldl or -lc to
liblttng_ust_tracepoint_la_LIBADD.

Signed-off-by: Vitaly Lipatov <lav@etersoft.ru>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: lttng filter validator ERANGE error handling
Mathieu Desnoyers [Thu, 7 Jun 2018 16:11:03 +0000 (12:11 -0400)] 
Fix: lttng filter validator ERANGE error handling

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFilter: implement dynamic typing for load object
Mathieu Desnoyers [Mon, 25 Sep 2017 20:24:02 +0000 (16:24 -0400)] 
Filter: implement dynamic typing for load object

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFilter: add FILTER_OP_RETURN_S64 instruction
Mathieu Desnoyers [Mon, 25 Sep 2017 15:37:28 +0000 (11:37 -0400)] 
Filter: add FILTER_OP_RETURN_S64 instruction

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoPerform bitwise ops on unsigned types
Mathieu Desnoyers [Fri, 22 Sep 2017 21:03:48 +0000 (17:03 -0400)] 
Perform bitwise ops on unsigned types

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFilter: catch shift undefined behavior
Mathieu Desnoyers [Fri, 22 Sep 2017 20:00:29 +0000 (16:00 -0400)] 
Filter: catch shift undefined behavior

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFilter: implement bitwise lshift, rshift, not
Mathieu Desnoyers [Thu, 21 Sep 2017 23:43:10 +0000 (19:43 -0400)] 
Filter: implement bitwise lshift, rshift, not

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFilter: index array, sequences, implement bitwise binary operators
Mathieu Desnoyers [Thu, 22 Jun 2017 22:00:39 +0000 (18:00 -0400)] 
Filter: index array, sequences, implement bitwise binary operators

Implement indexing of array and sequence of integers, as well as bitwise
binary operators &, |, ^.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: AM_CONDITIONAL should be outside AS_IF block
Mathieu Desnoyers [Thu, 3 May 2018 19:58:44 +0000 (15:58 -0400)] 
Fix: AM_CONDITIONAL should be outside AS_IF block

Fixes:

configure: error: conditional "HAVE_JAVAH" was never defined.
Usually this means the macro was only invoked conditionally

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: build jni libs with openjdk >= 10
Michael Jeanson [Thu, 3 May 2018 19:42:54 +0000 (15:42 -0400)] 
Fix: build jni libs with openjdk >= 10

In openjdk 10, the "javah" utility used to generate c headers from java
classes was removed and replaced with an option of "javac".

When we detect "javac" but no "javah", assume we are working with
openjdk >= 10 and configure the build system to use the proper tool and
switches.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: ustfork: save and restore errno in syscall wrappers
Michael Jeanson [Mon, 5 Mar 2018 21:09:07 +0000 (16:09 -0500)] 
Fix: ustfork: save and restore errno in syscall wrappers

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: cache the result of getpid() internally
Michael Jeanson [Fri, 2 Mar 2018 22:36:26 +0000 (17:36 -0500)] 
Fix: cache the result of getpid() internally

On Linux we called getpid() directly on each tracepoint and relied on
the glibc pid cache. However, in glibc 2.25, released on 2017-02-05, the
pid cache was removed which results in a getpid syscall on each event
when the vpid context is enabled.

Remove the Linux specific case and use our internal cache all the time.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: reset cached vpid context on fork
Michael Jeanson [Fri, 2 Mar 2018 22:36:25 +0000 (17:36 -0500)] 
Fix: reset cached vpid context on fork

We currently reset the cached vtid on fork but not the vpid. This is not
a problem on Linux because we don't cache the vpid internally but call
getpid() directly and rely on the glibc pid cache.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: build example SO when PIE is enabled
Michael Jeanson [Wed, 25 Oct 2017 18:28:04 +0000 (14:28 -0400)] 
Fix: build example SO when PIE is enabled

In the example Makefiles, when building shared object libraires, make sure
we set the custom linker options after the CFLAGS/LDFLAGS so that it
overrides them. This is useful when the build system set some hardening
features like PIE in the CFLAGS.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: string comparison on incorrect length in context provider
Mathieu Desnoyers [Tue, 20 Feb 2018 14:27:23 +0000 (09:27 -0500)] 
Fix: string comparison on incorrect length in context provider

Fixes: #1154
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoSupport unloading of probe providers
Francis Deslauriers [Fri, 9 Feb 2018 20:15:25 +0000 (15:15 -0500)] 
Support unloading of probe providers

With this commit, it's now possible to dlclose() a library containing an
actively used probe provider.

The destructor of such library will now iterate over all the sessions
and over all probe definitions to unregister them from the respective
callsites in the process.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoRename lttng_ust_enum_get to lttng_ust_enum_get_from_desc
Francis Deslauriers [Fri, 9 Feb 2018 20:15:24 +0000 (15:15 -0500)] 
Rename lttng_ust_enum_get to lttng_ust_enum_get_from_desc

Change the prototype to take a descriptor instead of a char *.
Now that provider names can have duplicates enum names are not
necessarily unique.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agodlopen() liblttng-ust.so from constructor to prevent unloading
Francis Deslauriers [Fri, 9 Feb 2018 20:15:23 +0000 (15:15 -0500)] 
dlopen() liblttng-ust.so from constructor to prevent unloading

The support of probe provider dlclose() allows for the following
problematic scenario:
- Application is not linked against the liblttng-ust.so
- Application dlopen() a probe provider library that is linked against
  liblttng-ust.so
- Application dlclose() the probe provider

In this scenario, the probe provider has a dependency on
liblttng-ust.so, so when it's loaded by the application, liblttng-ust.so
is loaded too. The probe provider library now has the only reference to
the liblttng-ust.so library.  When the application calls dlclose() on
it, all its references are dropped, thus triggering the unloading of
both the probe provider library and liblttng-ust.so.

This scenario is problematic because lttng ust_listener_threads are in
DETACHED state. We cannot join them and therefore we cannot unload the
library containing the code they run. Only the operating system can free
those resources.

The reason why those threads are in DETACHED state is to quickly
teardown applications on process exit.

A possible solution to investigate: if we can determine whether
liblttng-ust.so is being dlopen (directly or undirectly) or it's linked
against the application, we could set the detached state accordingly.

To prevent that unloading, we pin it in memory by grabbing an extra
reference on the library, with a RTLD_NODELETE flag. This will prevent
the dynamic loader from ever removing the liblttng-ust.so library from
the process' address space.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoAdd probe provider unregister function
Francis Deslauriers [Fri, 9 Feb 2018 20:15:22 +0000 (15:15 -0500)] 
Add probe provider unregister function

Also, ensure that enumerations and events are removed from their
respective hashtables when _lttng_{event, enum}_destroy functions are
called.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoCleanup: Move version numbers in separate variables in configure script
Francis Deslauriers [Fri, 9 Feb 2018 20:15:21 +0000 (15:15 -0500)] 
Cleanup: Move version numbers in separate variables in configure script

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoRemove duplicate provider name checks
Mathieu Desnoyers [Fri, 9 Feb 2018 20:15:20 +0000 (15:15 -0500)] 
Remove duplicate provider name checks

It's now possible to register a probe provider with a name that has
already been registered. This is useful when wanting to load a new
version of a shared library on a already running process.

Changes are necessary in the lttng-session daemon to support cases where
the newly register event has a different probe payload.

Taking a simple case where a probe provider is registered twice, the
tracepoint call site will have two probes registered to it and thus will
generate two events in the trace.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: remove for() loop initial declarations
Mathieu Desnoyers [Tue, 6 Feb 2018 13:58:59 +0000 (08:58 -0500)] 
Fix: remove for() loop initial declarations

Breaks sles12sp2 builds:

08:51:35 lttng-ust-fd-tracker.c: In function 'dup_std_fd':
08:51:35 lttng-ust-fd-tracker.c:174:2: error: 'for' loop initial
declarations are only allowed in C99 mode
08:51:35   for (int i = 0; i < STDERR_FILENO + 1; i++) {
08:51:35   ^
08:51:35 lttng-ust-fd-tracker.c:174:2: note: use option -std=c99 or
-std=gnu99 to compile your code
08:51:35 lttng-ust-fd-tracker.c:195:11: error: redefinition of 'i'
08:51:35   for (int i = 0; i < fd_to_close_count; i++) {
08:51:35            ^
08:51:35 lttng-ust-fd-tracker.c:174:11: note: previous definition of 'i'
was here
08:51:35   for (int i = 0; i < STDERR_FILENO + 1; i++) {
08:51:35            ^
08:51:35 lttng-ust-fd-tracker.c:195:2: error: 'for' loop initial
declarations are only allowed in C99 mode
08:51:35   for (int i = 0; i < fd_to_close_count; i++) {
08:51:35   ^
08:51:35 Makefile:412: recipe for target 'lttng-ust-fd-tracker.lo'
failed
08:51:35 make[2]: *** [lttng-ust-fd-tracker.lo] Error 1
08:51:35 make[2]: *** Waiting for unfinished jobs....

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoUse ust_lock during sock_info operations for atomicity against fork
Jonathan Rajotte [Mon, 5 Feb 2018 22:58:19 +0000 (17:58 -0500)] 
Use ust_lock during sock_info operations for atomicity against fork

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoForce tracked fd to be bigger than STDERR_FILENO
Jonathan Rajotte [Mon, 5 Feb 2018 22:58:18 +0000 (17:58 -0500)] 
Force tracked fd to be bigger than STDERR_FILENO

This allow ust to be proactive regarding std* fd manipulation done by
external source.

A good example of this is the "daemon" function that can dup2 statically
the std* fd and close them silently if the were already used.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 years agoFix: numa: dynamically check that numa is available
Mathieu Desnoyers [Tue, 5 Dec 2017 16:55:07 +0000 (11:55 -0500)] 
Fix: numa: dynamically check that numa is available

Kernels with CONFIG_NUMA=n cause libnuma to print those messages:

"set_mempolicy: Function not implemented".

Check for numa availability before using it.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoFix: specify SONAME in python-lttngust LoadLibrary
Michael Jeanson [Tue, 21 Nov 2017 16:11:15 +0000 (11:11 -0500)] 
Fix: specify SONAME in python-lttngust LoadLibrary

When loading the python agent library with ctypes in the python
bindings, specify the SONAME. This will make sure we load the proper
library in the event of a SONAME bump and the bindings will work without
having to install the "dev" package which in most distros contains the
non-versionned ".so".

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoFix: ensure fd tracker is initialized when called from constructors
Mathieu Desnoyers [Sun, 12 Nov 2017 19:51:24 +0000 (14:51 -0500)] 
Fix: ensure fd tracker is initialized when called from constructors

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoFix: fd of an elf object must be registered to the fd tracker
Jonathan Rajotte [Fri, 10 Nov 2017 16:06:41 +0000 (11:06 -0500)] 
Fix: fd of an elf object must be registered to the fd tracker

The open call take place inside ust, it must be tracked to prevent external
closing.

The bug can be hit during tracing of an application for which the probe
provider is loaded using LD_PRELOAD in combination with the fd utility
shared object. The application is responsible for closing all possible fd.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoCleanup: clock description for metadata was moved to lttng-sessiond
Jonathan Rajotte [Thu, 9 Nov 2017 22:37:14 +0000 (17:37 -0500)] 
Cleanup: clock description for metadata was moved to lttng-sessiond

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoFix: liblttng-ust-fd.so: override fclose symbol
Mathieu Desnoyers [Tue, 7 Nov 2017 20:33:40 +0000 (15:33 -0500)] 
Fix: liblttng-ust-fd.so: override fclose symbol

fclose() invoked from application or libraries end up calling close()
from within the libc, which bypasses our file descriptor tracking.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoRevert "Use initial-exec TLS model"
Mathieu Desnoyers [Tue, 7 Nov 2017 14:38:18 +0000 (09:38 -0500)] 
Revert "Use initial-exec TLS model"

This reverts commit 553bbf7f38652084ed7966c7817b8ccb372b14e1.

The initial-exec model seems to behave differently than global-dynamic
with respect to lazy initialization, causing locks to be taken then
first time each thread touch the TLS. This introduces deadlocks with
library constructors waiting on other threads.

This will require further investigation.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 years agoRevert "Fix: typo: DECLARE_URCU_TLS_IE -> DEFINE_URCU_TLS_IE"
Mathieu Desnoyers [Tue, 7 Nov 2017 14:37:46 +0000 (09:37 -0500)] 
Revert "Fix: typo: DECLARE_URCU_TLS_IE -> DEFINE_URCU_TLS_IE"

This reverts commit 364979886a80f7c993b3210af48a93f7d65f4530.

The initial-exec model seems to behave differently than global-dynamic
with respect to lazy initialization, causing locks to be taken then
first time each thread touch the TLS. This introduces deadlocks with
library constructors waiting on other threads.

This will require further investigation.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
This page took 0.047989 seconds and 4 git commands to generate.