]>
Commit | Line | Data |
---|---|---|
8db29d88 | 1 | /* The library used by gdb. |
83ffe9cd | 2 | Copyright (C) 2014-2023 Free Software Foundation, Inc. |
8db29d88 AO |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include <cc1plugin-config.h> | |
21 | #include <vector> | |
22 | #include <string> | |
23 | #include <sys/socket.h> | |
24 | #include <sys/types.h> | |
25 | #include <unistd.h> | |
26 | #include <sys/wait.h> | |
27 | #include <stdio.h> | |
28 | #include <errno.h> | |
29 | #include <sys/stat.h> | |
30 | #include <stdlib.h> | |
8db29d88 AO |
31 | #include "marshall-cp.hh" |
32 | #include "rpc.hh" | |
33 | #include "connection.hh" | |
34 | #include "names.hh" | |
35 | #include "callbacks.hh" | |
36 | #include "libiberty.h" | |
9d99775c | 37 | #include "compiler-name.hh" |
1d9c9726 | 38 | #include "compiler.hh" |
1a51cb29 | 39 | #include "gdbctx.hh" |
8db29d88 AO |
40 | |
41 | // The C compiler context that we hand back to our caller. | |
1a51cb29 | 42 | struct libcp1 : public cc1_plugin::base_gdb_plugin<gcc_cp_context> |
8db29d88 | 43 | { |
a8deb832 TT |
44 | explicit libcp1 (const gcc_cp_fe_vtable *); |
45 | ||
46 | void add_callbacks () override; | |
8db29d88 | 47 | |
1a51cb29 TT |
48 | gcc_cp_oracle_function *binding_oracle = nullptr; |
49 | gcc_cp_symbol_address_function *address_oracle = nullptr; | |
50 | gcc_cp_enter_leave_user_expr_scope_function *enter_scope = nullptr; | |
51 | gcc_cp_enter_leave_user_expr_scope_function *leave_scope = nullptr; | |
52 | void *oracle_datum = nullptr; | |
8db29d88 AO |
53 | }; |
54 | ||
a8deb832 TT |
55 | libcp1::libcp1 (const gcc_cp_fe_vtable *cv) |
56 | : cc1_plugin::base_gdb_plugin<gcc_cp_context> ("libcp1plugin", | |
57 | CP_COMPILER_NAME, | |
58 | GCC_CP_FE_VERSION_0) | |
8db29d88 | 59 | { |
8db29d88 AO |
60 | cp_ops = cv; |
61 | } | |
62 | ||
8db29d88 AO |
63 | \f |
64 | ||
65 | // Enclose these functions in an anonymous namespace because they | |
66 | // shouldn't be exported, but they can't be static because they're | |
67 | // used as template arguments. | |
68 | namespace { | |
69 | // This is a wrapper function that is called by the RPC system and | |
70 | // that then forwards the call to the library user. Note that the | |
71 | // return value is not used; the type cannot be 'void' due to | |
72 | // limitations in our simple RPC. | |
73 | int | |
74 | cp_call_binding_oracle (cc1_plugin::connection *conn, | |
75 | enum gcc_cp_oracle_request request, | |
76 | const char *identifier) | |
77 | { | |
1a51cb29 | 78 | libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr); |
8db29d88 AO |
79 | |
80 | self->binding_oracle (self->oracle_datum, self, request, identifier); | |
81 | return 1; | |
82 | } | |
83 | ||
84 | // This is a wrapper function that is called by the RPC system and | |
85 | // that then forwards the call to the library user. | |
86 | gcc_address | |
87 | cp_call_symbol_address (cc1_plugin::connection *conn, const char *identifier) | |
88 | { | |
1a51cb29 | 89 | libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr); |
8db29d88 AO |
90 | |
91 | return self->address_oracle (self->oracle_datum, self, identifier); | |
92 | } | |
93 | ||
94 | int | |
95 | cp_call_enter_scope (cc1_plugin::connection *conn) | |
96 | { | |
1a51cb29 | 97 | libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr); |
8db29d88 AO |
98 | |
99 | self->enter_scope (self->oracle_datum, self); | |
100 | return 1; | |
101 | } | |
102 | ||
103 | int | |
104 | cp_call_leave_scope (cc1_plugin::connection *conn) | |
105 | { | |
1a51cb29 | 106 | libcp1 *self = (libcp1 *) (((libcp1::local_connection *) conn)->back_ptr); |
8db29d88 AO |
107 | |
108 | self->leave_scope (self->oracle_datum, self); | |
109 | return 1; | |
110 | } | |
111 | } /* anonymous namespace */ | |
112 | ||
113 | \f | |
114 | ||
115 | static void | |
116 | set_callbacks (struct gcc_cp_context *s, | |
117 | gcc_cp_oracle_function *binding_oracle, | |
118 | gcc_cp_symbol_address_function *address_oracle, | |
119 | gcc_cp_enter_leave_user_expr_scope_function *enter_scope, | |
120 | gcc_cp_enter_leave_user_expr_scope_function *leave_scope, | |
121 | void *datum) | |
122 | { | |
123 | libcp1 *self = (libcp1 *) s; | |
124 | ||
125 | self->binding_oracle = binding_oracle; | |
126 | self->address_oracle = address_oracle; | |
127 | self->enter_scope = enter_scope; | |
128 | self->leave_scope = leave_scope; | |
129 | self->oracle_datum = datum; | |
130 | } | |
131 | ||
8db29d88 AO |
132 | static const struct gcc_cp_fe_vtable cp_vtable = |
133 | { | |
134 | GCC_CP_FE_VERSION_0, | |
135 | set_callbacks, | |
136 | ||
137 | #define GCC_METHOD0(R, N) \ | |
1a51cb29 | 138 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N>, |
8db29d88 | 139 | #define GCC_METHOD1(R, N, A) \ |
1a51cb29 | 140 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A>, |
8db29d88 | 141 | #define GCC_METHOD2(R, N, A, B) \ |
1a51cb29 | 142 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B>, |
8db29d88 | 143 | #define GCC_METHOD3(R, N, A, B, C) \ |
1a51cb29 | 144 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C>, |
8db29d88 | 145 | #define GCC_METHOD4(R, N, A, B, C, D) \ |
1a51cb29 | 146 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D>, |
8db29d88 | 147 | #define GCC_METHOD5(R, N, A, B, C, D, E) \ |
1a51cb29 | 148 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E>, |
8db29d88 | 149 | #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ |
1a51cb29 | 150 | cc1_plugin::rpc<gcc_cp_context, R, cc1_plugin::cp::N, A, B, C, D, E, F, G>, |
8db29d88 AO |
151 | |
152 | #include "gcc-cp-fe.def" | |
153 | ||
154 | #undef GCC_METHOD0 | |
155 | #undef GCC_METHOD1 | |
156 | #undef GCC_METHOD2 | |
157 | #undef GCC_METHOD3 | |
158 | #undef GCC_METHOD4 | |
159 | #undef GCC_METHOD5 | |
160 | #undef GCC_METHOD7 | |
161 | }; | |
162 | ||
163 | \f | |
164 | ||
a8deb832 TT |
165 | void |
166 | libcp1::add_callbacks () | |
8db29d88 | 167 | { |
8db29d88 | 168 | cc1_plugin::callback_ftype *fun |
8fdffa48 TT |
169 | = cc1_plugin::invoker<int, enum gcc_cp_oracle_request, |
170 | const char *>::invoke<cp_call_binding_oracle>; | |
a8deb832 | 171 | connection->add_callback ("binding_oracle", fun); |
8db29d88 | 172 | |
8fdffa48 TT |
173 | fun = cc1_plugin::invoker<gcc_address, |
174 | const char *>::invoke<cp_call_symbol_address>; | |
a8deb832 | 175 | connection->add_callback ("address_oracle", fun); |
8db29d88 | 176 | |
8fdffa48 | 177 | fun = cc1_plugin::invoker<int>::invoke<cp_call_enter_scope>; |
a8deb832 | 178 | connection->add_callback ("enter_scope", fun); |
8db29d88 | 179 | |
8fdffa48 | 180 | fun = cc1_plugin::invoker<int>::invoke<cp_call_leave_scope>; |
a8deb832 | 181 | connection->add_callback ("leave_scope", fun); |
8db29d88 AO |
182 | } |
183 | ||
8db29d88 AO |
184 | extern "C" gcc_cp_fe_context_function gcc_cp_fe_context; |
185 | ||
186 | #ifdef __GNUC__ | |
187 | #pragma GCC visibility push(default) | |
188 | #endif | |
189 | ||
190 | extern "C" | |
191 | struct gcc_cp_context * | |
192 | gcc_cp_fe_context (enum gcc_base_api_version base_version, | |
193 | enum gcc_cp_api_version cp_version) | |
194 | { | |
195 | if ((base_version != GCC_FE_VERSION_0 && base_version != GCC_FE_VERSION_1) | |
196 | || cp_version != GCC_CP_FE_VERSION_0) | |
197 | return NULL; | |
198 | ||
a8deb832 | 199 | return new libcp1 (&cp_vtable); |
8db29d88 | 200 | } |