175fd0b74Schristos /* Interface between GCC C FE and GDB 275fd0b74Schristos 3*e992f068Schristos Copyright (C) 2014-2022 Free Software Foundation, Inc. 475fd0b74Schristos 575fd0b74Schristos This file is part of GCC. 675fd0b74Schristos 775fd0b74Schristos This program is free software; you can redistribute it and/or modify 875fd0b74Schristos it under the terms of the GNU General Public License as published by 975fd0b74Schristos the Free Software Foundation; either version 3 of the License, or 1075fd0b74Schristos (at your option) any later version. 1175fd0b74Schristos 1275fd0b74Schristos This program is distributed in the hope that it will be useful, 1375fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1475fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1575fd0b74Schristos GNU General Public License for more details. 1675fd0b74Schristos 1775fd0b74Schristos You should have received a copy of the GNU General Public License 1875fd0b74Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1975fd0b74Schristos 2075fd0b74Schristos #ifndef GCC_C_INTERFACE_H 2175fd0b74Schristos #define GCC_C_INTERFACE_H 2275fd0b74Schristos 2375fd0b74Schristos #include "gcc-interface.h" 2475fd0b74Schristos 2575fd0b74Schristos /* This header defines the interface to the GCC API. It must be both 2675fd0b74Schristos valid C and valid C++, because it is included by both programs. */ 2775fd0b74Schristos 2875fd0b74Schristos #ifdef __cplusplus 2975fd0b74Schristos extern "C" { 3075fd0b74Schristos #endif 3175fd0b74Schristos 3275fd0b74Schristos /* Forward declaration. */ 3375fd0b74Schristos 3475fd0b74Schristos struct gcc_c_context; 3575fd0b74Schristos 3675fd0b74Schristos /* 3775fd0b74Schristos * Definitions and declarations for the C front end. 3875fd0b74Schristos */ 3975fd0b74Schristos 4075fd0b74Schristos /* Defined versions of the C front-end API. */ 4175fd0b74Schristos 4275fd0b74Schristos enum gcc_c_api_version 4375fd0b74Schristos { 44ede78133Schristos GCC_C_FE_VERSION_0 = 0, 45ede78133Schristos 46ede78133Schristos /* Added char_type. Added new version of int_type and float_type, 47ede78133Schristos deprecated int_type_v0 and float_type_v0. */ 48ede78133Schristos GCC_C_FE_VERSION_1 = 1 4975fd0b74Schristos }; 5075fd0b74Schristos 5175fd0b74Schristos /* Qualifiers. */ 5275fd0b74Schristos 5375fd0b74Schristos enum gcc_qualifiers 5475fd0b74Schristos { 5575fd0b74Schristos GCC_QUALIFIER_CONST = 1, 5675fd0b74Schristos GCC_QUALIFIER_VOLATILE = 2, 5775fd0b74Schristos GCC_QUALIFIER_RESTRICT = 4 5875fd0b74Schristos }; 5975fd0b74Schristos 6075fd0b74Schristos /* This enumerates the kinds of decls that GDB can create. */ 6175fd0b74Schristos 6275fd0b74Schristos enum gcc_c_symbol_kind 6375fd0b74Schristos { 6475fd0b74Schristos /* A function. */ 6575fd0b74Schristos 6675fd0b74Schristos GCC_C_SYMBOL_FUNCTION, 6775fd0b74Schristos 6875fd0b74Schristos /* A variable. */ 6975fd0b74Schristos 7075fd0b74Schristos GCC_C_SYMBOL_VARIABLE, 7175fd0b74Schristos 7275fd0b74Schristos /* A typedef. */ 7375fd0b74Schristos 7475fd0b74Schristos GCC_C_SYMBOL_TYPEDEF, 7575fd0b74Schristos 7675fd0b74Schristos /* A label. */ 7775fd0b74Schristos 7875fd0b74Schristos GCC_C_SYMBOL_LABEL 7975fd0b74Schristos }; 8075fd0b74Schristos 8175fd0b74Schristos /* This enumerates the types of symbols that GCC might request from 8275fd0b74Schristos GDB. */ 8375fd0b74Schristos 8475fd0b74Schristos enum gcc_c_oracle_request 8575fd0b74Schristos { 8675fd0b74Schristos /* An ordinary symbol -- a variable, function, typedef, or enum 8775fd0b74Schristos constant. */ 8875fd0b74Schristos 8975fd0b74Schristos GCC_C_ORACLE_SYMBOL, 9075fd0b74Schristos 9175fd0b74Schristos /* A struct, union, or enum tag. */ 9275fd0b74Schristos 9375fd0b74Schristos GCC_C_ORACLE_TAG, 9475fd0b74Schristos 9575fd0b74Schristos /* A label. */ 9675fd0b74Schristos 9775fd0b74Schristos GCC_C_ORACLE_LABEL 9875fd0b74Schristos }; 9975fd0b74Schristos 10075fd0b74Schristos /* The type of the function called by GCC to ask GDB for a symbol's 10175fd0b74Schristos definition. DATUM is an arbitrary value supplied when the oracle 10275fd0b74Schristos function is registered. CONTEXT is the GCC context in which the 10375fd0b74Schristos request is being made. REQUEST specifies what sort of symbol is 10475fd0b74Schristos being requested, and IDENTIFIER is the name of the symbol. */ 10575fd0b74Schristos 10675fd0b74Schristos typedef void gcc_c_oracle_function (void *datum, 10775fd0b74Schristos struct gcc_c_context *context, 10875fd0b74Schristos enum gcc_c_oracle_request request, 10975fd0b74Schristos const char *identifier); 11075fd0b74Schristos 11175fd0b74Schristos /* The type of the function called by GCC to ask GDB for a symbol's 11275fd0b74Schristos address. This should return 0 if the address is not known. */ 11375fd0b74Schristos 11475fd0b74Schristos typedef gcc_address gcc_c_symbol_address_function (void *datum, 11575fd0b74Schristos struct gcc_c_context *ctxt, 11675fd0b74Schristos const char *identifier); 11775fd0b74Schristos 11875fd0b74Schristos /* The vtable used by the C front end. */ 11975fd0b74Schristos 12075fd0b74Schristos struct gcc_c_fe_vtable 12175fd0b74Schristos { 12275fd0b74Schristos /* The version of the C interface. The value is one of the 12375fd0b74Schristos gcc_c_api_version constants. */ 12475fd0b74Schristos 12575fd0b74Schristos unsigned int c_version; 12675fd0b74Schristos 12775fd0b74Schristos /* Set the callbacks for this context. 12875fd0b74Schristos 12975fd0b74Schristos The binding oracle is called whenever the C parser needs to look 13075fd0b74Schristos up a symbol. This gives the caller a chance to lazily 13175fd0b74Schristos instantiate symbols using other parts of the gcc_c_fe_interface 13275fd0b74Schristos API. 13375fd0b74Schristos 13475fd0b74Schristos The address oracle is called whenever the C parser needs to look 13575fd0b74Schristos up a symbol. This is only called for symbols not provided by the 13675fd0b74Schristos symbol oracle -- that is, just built-in functions where GCC 13775fd0b74Schristos provides the declaration. 13875fd0b74Schristos 13975fd0b74Schristos DATUM is an arbitrary piece of data that is passed back verbatim 140ede78133Schristos to the callbacks in requests. */ 14175fd0b74Schristos 14275fd0b74Schristos void (*set_callbacks) (struct gcc_c_context *self, 14375fd0b74Schristos gcc_c_oracle_function *binding_oracle, 14475fd0b74Schristos gcc_c_symbol_address_function *address_oracle, 14575fd0b74Schristos void *datum); 14675fd0b74Schristos 14775fd0b74Schristos #define GCC_METHOD0(R, N) \ 14875fd0b74Schristos R (*N) (struct gcc_c_context *); 14975fd0b74Schristos #define GCC_METHOD1(R, N, A) \ 15075fd0b74Schristos R (*N) (struct gcc_c_context *, A); 15175fd0b74Schristos #define GCC_METHOD2(R, N, A, B) \ 15275fd0b74Schristos R (*N) (struct gcc_c_context *, A, B); 15375fd0b74Schristos #define GCC_METHOD3(R, N, A, B, C) \ 15475fd0b74Schristos R (*N) (struct gcc_c_context *, A, B, C); 15575fd0b74Schristos #define GCC_METHOD4(R, N, A, B, C, D) \ 15675fd0b74Schristos R (*N) (struct gcc_c_context *, A, B, C, D); 15775fd0b74Schristos #define GCC_METHOD5(R, N, A, B, C, D, E) \ 15875fd0b74Schristos R (*N) (struct gcc_c_context *, A, B, C, D, E); 15975fd0b74Schristos #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ 16075fd0b74Schristos R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G); 16175fd0b74Schristos 16275fd0b74Schristos #include "gcc-c-fe.def" 16375fd0b74Schristos 16475fd0b74Schristos #undef GCC_METHOD0 16575fd0b74Schristos #undef GCC_METHOD1 16675fd0b74Schristos #undef GCC_METHOD2 16775fd0b74Schristos #undef GCC_METHOD3 16875fd0b74Schristos #undef GCC_METHOD4 16975fd0b74Schristos #undef GCC_METHOD5 17075fd0b74Schristos #undef GCC_METHOD7 17175fd0b74Schristos 17275fd0b74Schristos }; 17375fd0b74Schristos 17475fd0b74Schristos /* The C front end object. */ 17575fd0b74Schristos 17675fd0b74Schristos struct gcc_c_context 17775fd0b74Schristos { 17875fd0b74Schristos /* Base class. */ 17975fd0b74Schristos 18075fd0b74Schristos struct gcc_base_context base; 18175fd0b74Schristos 18275fd0b74Schristos /* Our vtable. This is a separate field because this is simpler 18375fd0b74Schristos than implementing a vtable inheritance scheme in C. */ 18475fd0b74Schristos 18575fd0b74Schristos const struct gcc_c_fe_vtable *c_ops; 18675fd0b74Schristos }; 18775fd0b74Schristos 18875fd0b74Schristos /* The name of the .so that the compiler builds. We dlopen this 18975fd0b74Schristos later. */ 19075fd0b74Schristos 19175fd0b74Schristos #define GCC_C_FE_LIBCC libcc1.so 19275fd0b74Schristos 19375fd0b74Schristos /* The compiler exports a single initialization function. This macro 19475fd0b74Schristos holds its name as a symbol. */ 19575fd0b74Schristos 19675fd0b74Schristos #define GCC_C_FE_CONTEXT gcc_c_fe_context 19775fd0b74Schristos 19875fd0b74Schristos /* The type of the initialization function. The caller passes in the 19975fd0b74Schristos desired base version and desired C-specific version. If the 20075fd0b74Schristos request can be satisfied, a compatible gcc_context object will be 20175fd0b74Schristos returned. Otherwise, the function returns NULL. */ 20275fd0b74Schristos 20375fd0b74Schristos typedef struct gcc_c_context *gcc_c_fe_context_function 20475fd0b74Schristos (enum gcc_base_api_version, 20575fd0b74Schristos enum gcc_c_api_version); 20675fd0b74Schristos 20775fd0b74Schristos #ifdef __cplusplus 20875fd0b74Schristos } 20975fd0b74Schristos #endif 21075fd0b74Schristos 21175fd0b74Schristos #endif /* GCC_C_INTERFACE_H */ 212