| 1 | /* |
| 2 | * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef _GNU_SOURCE |
| 9 | #define _GNU_SOURCE |
| 10 | #endif |
| 11 | |
| 12 | /* |
| 13 | * The order of inclusion is important here: including sdt.h _before_ the probe |
| 14 | * declarations ensures that semaphore-protected SDT probes (which we don't support) are not |
| 15 | * generated. See SYSTEMTAP(2) for more details. |
| 16 | */ |
| 17 | /* clang-format off */ |
| 18 | #include <sys/sdt.h> |
| 19 | #include "foobar_provider.h" |
| 20 | /* clang-format on */ |
| 21 | |
| 22 | #include "libfoo.h" |
| 23 | #include "sema.h" |
| 24 | |
| 25 | #include <dlfcn.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <stdbool.h> |
| 28 | #include <stdint.h> |
| 29 | #include <stdio.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/types.h> |
| 32 | |
| 33 | int main(int argc, char *argv[]) |
| 34 | { |
| 35 | void *handle; |
| 36 | void (*bar_function)(); |
| 37 | |
| 38 | FOOBAR_TP1(); |
| 39 | FOOBAR_TP2(); |
| 40 | /* |
| 41 | * This SDT tracepoint has an argument. Argument extraction is not supported |
| 42 | * at the moment, but tracing of the tracepoint should work. |
| 43 | */ |
| 44 | FOOBAR_TP_WITH_ARG(42); |
| 45 | |
| 46 | /* Call a function containing an SDT tracepoint in shared object. */ |
| 47 | foo_function(); |
| 48 | |
| 49 | /* |
| 50 | * Load a shared object and call a function containing an SDT |
| 51 | * tracepoint |
| 52 | */ |
| 53 | handle = dlopen("libbar.so", RTLD_LAZY); |
| 54 | if (!handle) { |
| 55 | fprintf(stderr, "Can't dlopen libbar.so"); |
| 56 | return -1; |
| 57 | } |
| 58 | bar_function = (void (*)()) dlsym(handle, "bar_function"); |
| 59 | bar_function(); |
| 60 | dlclose(handle); |
| 61 | |
| 62 | /* This tracepoint has 2 call sites in this binary. */ |
| 63 | FOOBAR_TP2(); |
| 64 | |
| 65 | /* |
| 66 | * This function is defined in libfoo and in libzzz. For a test, libzzz is |
| 67 | * LD_PRELOADed and should override this function. |
| 68 | */ |
| 69 | overridable_function(); |
| 70 | |
| 71 | /* |
| 72 | * This function is calling a SDT tracepoint that is guarded by a |
| 73 | * semaphore. |
| 74 | */ |
| 75 | sema_function(); |
| 76 | return 0; |
| 77 | } |