| 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 | #include <dlfcn.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <stdbool.h> |
| 15 | #include <stdint.h> |
| 16 | #include <stdio.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <sys/sdt.h> |
| 21 | |
| 22 | #include "foobar_provider.h" |
| 23 | #include "libfoo.h" |
| 24 | #include "sema.h" |
| 25 | |
| 26 | int main(int argc, char *argv[]) |
| 27 | { |
| 28 | void *handle; |
| 29 | void (*bar_function)(); |
| 30 | |
| 31 | FOOBAR_TP1(); |
| 32 | FOOBAR_TP2(); |
| 33 | /* |
| 34 | * This SDT tracepoint has an argument. Argument extraction is not support |
| 35 | * at the moment but tracing of the tracepoint should work. |
| 36 | */ |
| 37 | FOOBAR_TP_WITH_ARG(42); |
| 38 | |
| 39 | /* Call function containing an SDT tracepoint in shared object */ |
| 40 | foo_function(); |
| 41 | |
| 42 | /* |
| 43 | * Load a show shared object and call a function containing an SDT |
| 44 | * tracepoint |
| 45 | */ |
| 46 | handle = dlopen("libbar.so", RTLD_LAZY); |
| 47 | if (!handle) { |
| 48 | fprintf(stderr, "Can't dlopen libbar.so"); |
| 49 | return -1; |
| 50 | } |
| 51 | bar_function = (void (*)())dlsym(handle, "bar_function"); |
| 52 | bar_function(); |
| 53 | dlclose(handle); |
| 54 | |
| 55 | /* This tracepoint has 2 callsites in this binary */ |
| 56 | FOOBAR_TP2(); |
| 57 | |
| 58 | /* |
| 59 | * This function is defined in libfoo AND in libzzz. For a test, libzzz is |
| 60 | * LD_PRELOADed and should override this function |
| 61 | */ |
| 62 | overridable_function(); |
| 63 | |
| 64 | /* |
| 65 | * This function is calling a SDT tracepoint that is guarded by a |
| 66 | * semaphore. |
| 67 | */ |
| 68 | sema_function(); |
| 69 | return 0; |
| 70 | } |
| 71 | |