common: compile libtestpoint as C++
[lttng-tools.git] / src / common / testpoint / testpoint.cpp
CommitLineData
6242251b 1/*
ab5be9fa 2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
6242251b 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
6242251b 5 *
6242251b
CB
6 */
7
8#ifndef NTESTPOINT
9
6c1c0768 10#define _LGPL_SOURCE
6242251b
CB
11#include <dlfcn.h> /* for dlsym */
12#include <stdlib.h> /* for getenv */
13#include <string.h> /* for strncmp */
14
15#include "testpoint.h"
16
17/* Environment variable used to enable the testpoints facilities. */
18static const char *lttng_testpoint_env_var = "LTTNG_TESTPOINT_ENABLE";
19
20/* Testpoint toggle flag */
21int lttng_testpoint_activated;
22
23/*
24 * Toggle the support for testpoints on the application startup.
25 */
26static void __attribute__((constructor)) lttng_testpoint_check(void)
27{
28 char *testpoint_env_val = NULL;
29
30 testpoint_env_val = getenv(lttng_testpoint_env_var);
31 if (testpoint_env_val != NULL
32 && (strncmp(testpoint_env_val, "1", 1) == 0)) {
33 lttng_testpoint_activated = 1;
34 }
35}
36
37/*
38 * Lookup a symbol by name.
39 *
40 * Return the address where the symbol is loaded or NULL if the symbol was not
41 * found.
42 */
43void *lttng_testpoint_lookup(const char *name)
44{
45 if (!name) {
46 return NULL;
47 }
48
49 return dlsym(RTLD_DEFAULT, name);
50}
51
52#endif /* NTESTPOINT */
This page took 0.055652 seconds and 4 git commands to generate.