arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / gprofng / libcollector / collectorAPI.c
blob449bbbaab6574af58186717157dc20834dd16c51
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 /* C and Fortran stubs for collector API */
23 #include "config.h"
24 #include <dlfcn.h>
25 #include "gp-defs.h"
26 #include "collectorAPI.h"
27 #include "gp-experiment.h"
29 static void (*__real_collector_sample)(const char *) = NULL;
30 static void (*__real_collector_pause)() = NULL;
31 static void (*__real_collector_resume)() = NULL;
32 static void (*__real_collector_terminate_expt)() = NULL;
33 static void (*__real_collector_func_load)(const char *, const char *,
34 const char *, void *, int, int, Lineno *) = NULL;
35 static void (*__real_collector_func_unload)(void *) = NULL;
37 #define INIT_API if (init_API == 0) collectorAPI_initAPI()
38 #define NULL_PTR(x) (__real_##x == NULL)
39 #define CALL_REAL(x) (__real_##x)
40 #define CALL_IF_REAL(x) INIT_API; if (!NULL_PTR(x)) CALL_REAL(x)
42 static int init_API = 0;
44 void
45 collectorAPI_initAPI (void)
47 void *libcollector = dlopen (SP_LIBCOLLECTOR_NAME, RTLD_NOLOAD);
48 if (libcollector == NULL)
49 libcollector = RTLD_DEFAULT;
50 __real_collector_sample = dlsym (libcollector, "__collector_sample");
51 __real_collector_pause = dlsym (libcollector, "__collector_pause");
52 __real_collector_resume = dlsym (libcollector, "__collector_resume");
53 __real_collector_terminate_expt = dlsym (libcollector, "__collector_terminate_expt");
54 __real_collector_func_load = dlsym (libcollector, "__collector_func_load");
55 __real_collector_func_unload = dlsym (libcollector, "__collector_func_unload");
56 init_API = 1;
59 /* initialization -- init section routine */
60 static void collectorAPI_init () __attribute__ ((constructor));
62 static void
63 collectorAPI_init (void)
65 collectorAPI_initAPI ();
68 /* C API */
69 void
70 collector_pause (void)
72 CALL_IF_REAL (collector_pause)();
75 void
76 collector_resume (void)
78 CALL_IF_REAL (collector_resume)();
81 void
82 collector_sample (const char *name)
84 CALL_IF_REAL (collector_sample)(name);
87 void
88 collector_terminate_expt (void)
90 CALL_IF_REAL (collector_terminate_expt)();
93 void
94 collector_func_load (const char *name, const char *alias, const char *sourcename,
95 void *vaddr, int size, int lntsize, Lineno *lntable)
97 CALL_IF_REAL (collector_func_load)(name, alias, sourcename,
98 vaddr, size, lntsize, lntable);
101 void
102 collector_func_unload (void *vaddr)
104 CALL_IF_REAL (collector_func_unload)(vaddr);
107 /* Fortran API */
108 void
109 collector_pause_ (void)
111 CALL_IF_REAL (collector_pause)();
114 void
115 collector_resume_ (void)
117 CALL_IF_REAL (collector_resume)();
120 void
121 collector_terminate_expt_ (void)
123 CALL_IF_REAL (collector_terminate_expt)();
126 void
127 collector_sample_ (char *name, long name_length)
129 INIT_API;
130 if (!NULL_PTR (collector_sample))
132 char name_string[256];
133 long length = sizeof (name_string) - 1;
134 if (name_length < length)
135 length = name_length;
136 for (long i = 0; i < length; i++)
137 name_string[i] = name[i];
138 name_string[length] = '\0';
139 CALL_REAL (collector_sample)(name_string);