| 1 | /* |
| 2 | * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | #ifndef _GNU_SOURCE |
| 19 | #define _GNU_SOURCE |
| 20 | #endif |
| 21 | |
| 22 | #include <dlfcn.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <stdbool.h> |
| 25 | #include <stdint.h> |
| 26 | #include <stdio.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/types.h> |
| 29 | |
| 30 | #include <sys/sdt.h> |
| 31 | |
| 32 | #include "foobar_provider.h" |
| 33 | #include "libfoo.h" |
| 34 | #include "sema.h" |
| 35 | |
| 36 | int main(int argc, char *argv[]) |
| 37 | { |
| 38 | void *handle; |
| 39 | void (*bar_function)(); |
| 40 | |
| 41 | FOOBAR_TP1(); |
| 42 | FOOBAR_TP2(); |
| 43 | /* |
| 44 | * This SDT tracepoint has an argument. Argument extraction is not support |
| 45 | * at the moment but tracing of the tracepoint should work. |
| 46 | */ |
| 47 | FOOBAR_TP_WITH_ARG(42); |
| 48 | |
| 49 | /* Call function containing an SDT tracepoint in shared object */ |
| 50 | foo_function(); |
| 51 | |
| 52 | /* |
| 53 | * Load a show shared object and call a function containing an SDT |
| 54 | * tracepoint |
| 55 | */ |
| 56 | handle = dlopen("libbar.so", RTLD_LAZY); |
| 57 | if (!handle) { |
| 58 | fprintf(stderr, "Can't dlopen libbar.so"); |
| 59 | return -1; |
| 60 | } |
| 61 | bar_function = (void (*)())dlsym(handle, "bar_function"); |
| 62 | bar_function(); |
| 63 | dlclose(handle); |
| 64 | |
| 65 | /* This tracepoint has 2 callsites in this binary */ |
| 66 | FOOBAR_TP2(); |
| 67 | |
| 68 | /* |
| 69 | * This function is defined in libfoo AND in libzzz. For a test, libzzz is |
| 70 | * LD_PRELOADed and should override this function |
| 71 | */ |
| 72 | overridable_function(); |
| 73 | |
| 74 | /* |
| 75 | * This function is calling a SDT tracepoint that is guarded by a |
| 76 | * semaphore. |
| 77 | */ |
| 78 | sema_function(); |
| 79 | return 0; |
| 80 | } |
| 81 | |