clang-tidy: add Chrome-inspired checks
[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
28ab034a
JG
11#include "testpoint.hpp"
12
13#include <dlfcn.h> /* for dlsym */
6242251b
CB
14#include <stdlib.h> /* for getenv */
15#include <string.h> /* for strncmp */
16
6242251b
CB
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 */
cd9adb8b 26static void __attribute__((constructor)) lttng_testpoint_check()
6242251b 27{
cd9adb8b 28 char *testpoint_env_val = nullptr;
6242251b
CB
29
30 testpoint_env_val = getenv(lttng_testpoint_env_var);
cd9adb8b 31 if (testpoint_env_val != nullptr && (strncmp(testpoint_env_val, "1", 1) == 0)) {
6242251b
CB
32 lttng_testpoint_activated = 1;
33 }
34}
35
36/*
37 * Lookup a symbol by name.
38 *
39 * Return the address where the symbol is loaded or NULL if the symbol was not
40 * found.
41 */
42void *lttng_testpoint_lookup(const char *name)
43{
44 if (!name) {
cd9adb8b 45 return nullptr;
6242251b
CB
46 }
47
48 return dlsym(RTLD_DEFAULT, name);
49}
50
51#endif /* NTESTPOINT */
This page took 0.067197 seconds and 4 git commands to generate.