]>
Commit | Line | Data |
---|---|---|
ddc8de03 | 1 | /* The library used by gdb. |
83ffe9cd | 2 | Copyright (C) 2014-2023 Free Software Foundation, Inc. |
ddc8de03 PM |
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> | |
25d1a6ec | 31 | #include "marshall.hh" |
ddc8de03 PM |
32 | #include "rpc.hh" |
33 | #include "connection.hh" | |
34 | #include "names.hh" | |
35 | #include "callbacks.hh" | |
ddc8de03 | 36 | #include "libiberty.h" |
9d99775c | 37 | #include "compiler-name.hh" |
25d1a6ec | 38 | #include "gcc-c-interface.h" |
1d9c9726 | 39 | #include "compiler.hh" |
1a51cb29 | 40 | #include "gdbctx.hh" |
ddc8de03 PM |
41 | |
42 | // The C compiler context that we hand back to our caller. | |
1a51cb29 | 43 | struct libcc1 : public cc1_plugin::base_gdb_plugin<gcc_c_context> |
ddc8de03 | 44 | { |
a8deb832 TT |
45 | explicit libcc1 (const gcc_c_fe_vtable *); |
46 | ||
47 | void add_callbacks () override; | |
ddc8de03 | 48 | |
1a51cb29 TT |
49 | gcc_c_oracle_function *binding_oracle = nullptr; |
50 | gcc_c_symbol_address_function *address_oracle = nullptr; | |
51 | void *oracle_datum = nullptr; | |
ddc8de03 PM |
52 | }; |
53 | ||
a8deb832 TT |
54 | libcc1::libcc1 (const gcc_c_fe_vtable *cv) |
55 | : cc1_plugin::base_gdb_plugin<gcc_c_context> ("libcc1plugin", | |
56 | C_COMPILER_NAME, | |
57 | GCC_C_FE_VERSION_1) | |
ddc8de03 | 58 | { |
ddc8de03 PM |
59 | c_ops = cv; |
60 | } | |
61 | ||
ddc8de03 PM |
62 | \f |
63 | ||
8db29d88 AO |
64 | // Enclose these functions in an anonymous namespace because they |
65 | // shouldn't be exported, but they can't be static because they're | |
66 | // used as template arguments. | |
67 | namespace { | |
68 | // This is a wrapper function that is called by the RPC system and | |
69 | // that then forwards the call to the library user. Note that the | |
70 | // return value is not used; the type cannot be 'void' due to | |
71 | // limitations in our simple RPC. | |
72 | int | |
73 | c_call_binding_oracle (cc1_plugin::connection *conn, | |
74 | enum gcc_c_oracle_request request, | |
75 | const char *identifier) | |
76 | { | |
1a51cb29 | 77 | libcc1 *self = (libcc1 *) (((libcc1::local_connection *) conn)->back_ptr); |
ddc8de03 | 78 | |
8db29d88 AO |
79 | self->binding_oracle (self->oracle_datum, self, request, identifier); |
80 | return 1; | |
81 | } | |
ddc8de03 | 82 | |
8db29d88 AO |
83 | // This is a wrapper function that is called by the RPC system and |
84 | // that then forwards the call to the library user. | |
85 | gcc_address | |
86 | c_call_symbol_address (cc1_plugin::connection *conn, const char *identifier) | |
87 | { | |
1a51cb29 | 88 | libcc1 *self = (libcc1 *) (((libcc1::local_connection *) conn)->back_ptr); |
ddc8de03 | 89 | |
8db29d88 AO |
90 | return self->address_oracle (self->oracle_datum, self, identifier); |
91 | } | |
92 | } /* anonymous namespace */ | |
ddc8de03 PM |
93 | |
94 | \f | |
95 | ||
96 | static void | |
97 | set_callbacks (struct gcc_c_context *s, | |
98 | gcc_c_oracle_function *binding_oracle, | |
99 | gcc_c_symbol_address_function *address_oracle, | |
100 | void *datum) | |
101 | { | |
102 | libcc1 *self = (libcc1 *) s; | |
103 | ||
104 | self->binding_oracle = binding_oracle; | |
105 | self->address_oracle = address_oracle; | |
106 | self->oracle_datum = datum; | |
107 | } | |
108 | ||
ddc8de03 PM |
109 | static const struct gcc_c_fe_vtable c_vtable = |
110 | { | |
111 | GCC_C_FE_VERSION_0, | |
112 | set_callbacks, | |
113 | ||
114 | #define GCC_METHOD0(R, N) \ | |
1a51cb29 | 115 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N>, |
ddc8de03 | 116 | #define GCC_METHOD1(R, N, A) \ |
1a51cb29 | 117 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A>, |
ddc8de03 | 118 | #define GCC_METHOD2(R, N, A, B) \ |
1a51cb29 | 119 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A, B>, |
ddc8de03 | 120 | #define GCC_METHOD3(R, N, A, B, C) \ |
1a51cb29 | 121 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A, B, C>, |
ddc8de03 | 122 | #define GCC_METHOD4(R, N, A, B, C, D) \ |
1a51cb29 | 123 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A, B, C, D>, |
ddc8de03 | 124 | #define GCC_METHOD5(R, N, A, B, C, D, E) \ |
1a51cb29 | 125 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A, B, C, D, E>, |
ddc8de03 | 126 | #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ |
1a51cb29 | 127 | cc1_plugin::rpc<gcc_c_context, R, cc1_plugin::c::N, A, B, C, D, E, F, G>, |
ddc8de03 PM |
128 | |
129 | #include "gcc-c-fe.def" | |
130 | ||
131 | #undef GCC_METHOD0 | |
132 | #undef GCC_METHOD1 | |
133 | #undef GCC_METHOD2 | |
134 | #undef GCC_METHOD3 | |
135 | #undef GCC_METHOD4 | |
136 | #undef GCC_METHOD5 | |
137 | #undef GCC_METHOD7 | |
138 | }; | |
139 | ||
140 | \f | |
141 | ||
a8deb832 TT |
142 | void |
143 | libcc1::add_callbacks () | |
5d1b2443 | 144 | { |
ddc8de03 | 145 | cc1_plugin::callback_ftype *fun |
8fdffa48 TT |
146 | = cc1_plugin::invoker<int, |
147 | enum gcc_c_oracle_request, | |
148 | const char *>::invoke<c_call_binding_oracle>; | |
a8deb832 | 149 | connection->add_callback ("binding_oracle", fun); |
ddc8de03 | 150 | |
8fdffa48 TT |
151 | fun = cc1_plugin::invoker<gcc_address, |
152 | const char *>::invoke<c_call_symbol_address>; | |
a8deb832 | 153 | connection->add_callback ("address_oracle", fun); |
3b5c1072 JK |
154 | } |
155 | ||
ddc8de03 PM |
156 | extern "C" gcc_c_fe_context_function gcc_c_fe_context; |
157 | ||
158 | #ifdef __GNUC__ | |
159 | #pragma GCC visibility push(default) | |
160 | #endif | |
161 | ||
162 | extern "C" | |
163 | struct gcc_c_context * | |
164 | gcc_c_fe_context (enum gcc_base_api_version base_version, | |
165 | enum gcc_c_api_version c_version) | |
166 | { | |
023721aa | 167 | if ((base_version != GCC_FE_VERSION_0 && base_version != GCC_FE_VERSION_1) |
8db29d88 | 168 | || (c_version != GCC_C_FE_VERSION_0 && c_version != GCC_C_FE_VERSION_1)) |
ddc8de03 PM |
169 | return NULL; |
170 | ||
a8deb832 | 171 | return new libcc1 (&c_vtable); |
ddc8de03 | 172 | } |