X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftestpoint%2Ftestpoint.c;fp=src%2Fcommon%2Ftestpoint%2Ftestpoint.c;h=6893a4112c55ce302a9b4436a1f00c958f84599c;hb=6242251b39f531a2485b758edcb455e220267fdd;hp=0000000000000000000000000000000000000000;hpb=db8870edf473e2a2f69e488375d32405ea324017;p=lttng-tools.git diff --git a/src/common/testpoint/testpoint.c b/src/common/testpoint/testpoint.c new file mode 100644 index 000000000..6893a4112 --- /dev/null +++ b/src/common/testpoint/testpoint.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2012 - Christian Babeux + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef NTESTPOINT + +#define _GNU_SOURCE /* for RTLD_DEFAULT GNU extension */ +#include /* for dlsym */ +#include /* for getenv */ +#include /* for strncmp */ + +#include "testpoint.h" + +/* Environment variable used to enable the testpoints facilities. */ +static const char *lttng_testpoint_env_var = "LTTNG_TESTPOINT_ENABLE"; + +/* Testpoint toggle flag */ +int lttng_testpoint_activated; + +/* + * Toggle the support for testpoints on the application startup. + */ +static void __attribute__((constructor)) lttng_testpoint_check(void) +{ + char *testpoint_env_val = NULL; + + testpoint_env_val = getenv(lttng_testpoint_env_var); + if (testpoint_env_val != NULL + && (strncmp(testpoint_env_val, "1", 1) == 0)) { + lttng_testpoint_activated = 1; + } +} + +/* + * Lookup a symbol by name. + * + * Return the address where the symbol is loaded or NULL if the symbol was not + * found. + */ +void *lttng_testpoint_lookup(const char *name) +{ + if (!name) { + return NULL; + } + + return dlsym(RTLD_DEFAULT, name); +} + +#endif /* NTESTPOINT */