2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #define _GNU_SOURCE /* for RTLD_DEFAULT GNU extension */
22 #include <dlfcn.h> /* for dlsym */
23 #include <stdlib.h> /* for getenv */
24 #include <string.h> /* for strncmp */
26 #include "testpoint.h"
28 /* Environment variable used to enable the testpoints facilities. */
29 static const char *lttng_testpoint_env_var
= "LTTNG_TESTPOINT_ENABLE";
31 /* Testpoint toggle flag */
32 int lttng_testpoint_activated
;
35 * Toggle the support for testpoints on the application startup.
37 static void __attribute__((constructor
)) lttng_testpoint_check(void)
39 char *testpoint_env_val
= NULL
;
41 testpoint_env_val
= getenv(lttng_testpoint_env_var
);
42 if (testpoint_env_val
!= NULL
43 && (strncmp(testpoint_env_val
, "1", 1) == 0)) {
44 lttng_testpoint_activated
= 1;
49 * Lookup a symbol by name.
51 * Return the address where the symbol is loaded or NULL if the symbol was not
54 void *lttng_testpoint_lookup(const char *name
)
60 return dlsym(RTLD_DEFAULT
, name
);
63 #endif /* NTESTPOINT */