19573673dSchristos /* Interface between GCC C FE and GDB 29573673dSchristos 3*cb63e24eSchristos Copyright (C) 2014-2024 Free Software Foundation, Inc. 49573673dSchristos 59573673dSchristos This file is part of GCC. 69573673dSchristos 79573673dSchristos This program is free software; you can redistribute it and/or modify 89573673dSchristos it under the terms of the GNU General Public License as published by 99573673dSchristos the Free Software Foundation; either version 3 of the License, or 109573673dSchristos (at your option) any later version. 119573673dSchristos 129573673dSchristos This program is distributed in the hope that it will be useful, 139573673dSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 149573673dSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 159573673dSchristos GNU General Public License for more details. 169573673dSchristos 179573673dSchristos You should have received a copy of the GNU General Public License 189573673dSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 199573673dSchristos 209573673dSchristos #ifndef GCC_C_INTERFACE_H 219573673dSchristos #define GCC_C_INTERFACE_H 229573673dSchristos 239573673dSchristos #include "gcc-interface.h" 249573673dSchristos 259573673dSchristos /* This header defines the interface to the GCC API. It must be both 269573673dSchristos valid C and valid C++, because it is included by both programs. */ 279573673dSchristos 289573673dSchristos #ifdef __cplusplus 299573673dSchristos extern "C" { 309573673dSchristos #endif 319573673dSchristos 329573673dSchristos /* Forward declaration. */ 339573673dSchristos 349573673dSchristos struct gcc_c_context; 359573673dSchristos 369573673dSchristos /* 379573673dSchristos * Definitions and declarations for the C front end. 389573673dSchristos */ 399573673dSchristos 409573673dSchristos /* Defined versions of the C front-end API. */ 419573673dSchristos 429573673dSchristos enum gcc_c_api_version 439573673dSchristos { 44fc4f4269Schristos GCC_C_FE_VERSION_0 = 0, 45fc4f4269Schristos 46fc4f4269Schristos /* Added char_type. Added new version of int_type and float_type, 47fc4f4269Schristos deprecated int_type_v0 and float_type_v0. */ 48fc4f4269Schristos GCC_C_FE_VERSION_1 = 1 499573673dSchristos }; 509573673dSchristos 519573673dSchristos /* Qualifiers. */ 529573673dSchristos 539573673dSchristos enum gcc_qualifiers 549573673dSchristos { 559573673dSchristos GCC_QUALIFIER_CONST = 1, 569573673dSchristos GCC_QUALIFIER_VOLATILE = 2, 579573673dSchristos GCC_QUALIFIER_RESTRICT = 4 589573673dSchristos }; 599573673dSchristos 609573673dSchristos /* This enumerates the kinds of decls that GDB can create. */ 619573673dSchristos 629573673dSchristos enum gcc_c_symbol_kind 639573673dSchristos { 649573673dSchristos /* A function. */ 659573673dSchristos 669573673dSchristos GCC_C_SYMBOL_FUNCTION, 679573673dSchristos 689573673dSchristos /* A variable. */ 699573673dSchristos 709573673dSchristos GCC_C_SYMBOL_VARIABLE, 719573673dSchristos 729573673dSchristos /* A typedef. */ 739573673dSchristos 749573673dSchristos GCC_C_SYMBOL_TYPEDEF, 759573673dSchristos 769573673dSchristos /* A label. */ 779573673dSchristos 789573673dSchristos GCC_C_SYMBOL_LABEL 799573673dSchristos }; 809573673dSchristos 819573673dSchristos /* This enumerates the types of symbols that GCC might request from 829573673dSchristos GDB. */ 839573673dSchristos 849573673dSchristos enum gcc_c_oracle_request 859573673dSchristos { 869573673dSchristos /* An ordinary symbol -- a variable, function, typedef, or enum 879573673dSchristos constant. */ 889573673dSchristos 899573673dSchristos GCC_C_ORACLE_SYMBOL, 909573673dSchristos 919573673dSchristos /* A struct, union, or enum tag. */ 929573673dSchristos 939573673dSchristos GCC_C_ORACLE_TAG, 949573673dSchristos 959573673dSchristos /* A label. */ 969573673dSchristos 979573673dSchristos GCC_C_ORACLE_LABEL 989573673dSchristos }; 999573673dSchristos 1009573673dSchristos /* The type of the function called by GCC to ask GDB for a symbol's 1019573673dSchristos definition. DATUM is an arbitrary value supplied when the oracle 1029573673dSchristos function is registered. CONTEXT is the GCC context in which the 1039573673dSchristos request is being made. REQUEST specifies what sort of symbol is 1049573673dSchristos being requested, and IDENTIFIER is the name of the symbol. */ 1059573673dSchristos 1069573673dSchristos typedef void gcc_c_oracle_function (void *datum, 1079573673dSchristos struct gcc_c_context *context, 1089573673dSchristos enum gcc_c_oracle_request request, 1099573673dSchristos const char *identifier); 1109573673dSchristos 1119573673dSchristos /* The type of the function called by GCC to ask GDB for a symbol's 1129573673dSchristos address. This should return 0 if the address is not known. */ 1139573673dSchristos 1149573673dSchristos typedef gcc_address gcc_c_symbol_address_function (void *datum, 1159573673dSchristos struct gcc_c_context *ctxt, 1169573673dSchristos const char *identifier); 1179573673dSchristos 1189573673dSchristos /* The vtable used by the C front end. */ 1199573673dSchristos 1209573673dSchristos struct gcc_c_fe_vtable 1219573673dSchristos { 1229573673dSchristos /* The version of the C interface. The value is one of the 1239573673dSchristos gcc_c_api_version constants. */ 1249573673dSchristos 1259573673dSchristos unsigned int c_version; 1269573673dSchristos 1279573673dSchristos /* Set the callbacks for this context. 1289573673dSchristos 1299573673dSchristos The binding oracle is called whenever the C parser needs to look 1309573673dSchristos up a symbol. This gives the caller a chance to lazily 1319573673dSchristos instantiate symbols using other parts of the gcc_c_fe_interface 1329573673dSchristos API. 1339573673dSchristos 1349573673dSchristos The address oracle is called whenever the C parser needs to look 1359573673dSchristos up a symbol. This is only called for symbols not provided by the 1369573673dSchristos symbol oracle -- that is, just built-in functions where GCC 1379573673dSchristos provides the declaration. 1389573673dSchristos 1399573673dSchristos DATUM is an arbitrary piece of data that is passed back verbatim 140fc4f4269Schristos to the callbacks in requests. */ 1419573673dSchristos 1429573673dSchristos void (*set_callbacks) (struct gcc_c_context *self, 1439573673dSchristos gcc_c_oracle_function *binding_oracle, 1449573673dSchristos gcc_c_symbol_address_function *address_oracle, 1459573673dSchristos void *datum); 1469573673dSchristos 1479573673dSchristos #define GCC_METHOD0(R, N) \ 1489573673dSchristos R (*N) (struct gcc_c_context *); 1499573673dSchristos #define GCC_METHOD1(R, N, A) \ 1509573673dSchristos R (*N) (struct gcc_c_context *, A); 1519573673dSchristos #define GCC_METHOD2(R, N, A, B) \ 1529573673dSchristos R (*N) (struct gcc_c_context *, A, B); 1539573673dSchristos #define GCC_METHOD3(R, N, A, B, C) \ 1549573673dSchristos R (*N) (struct gcc_c_context *, A, B, C); 1559573673dSchristos #define GCC_METHOD4(R, N, A, B, C, D) \ 1569573673dSchristos R (*N) (struct gcc_c_context *, A, B, C, D); 1579573673dSchristos #define GCC_METHOD5(R, N, A, B, C, D, E) \ 1589573673dSchristos R (*N) (struct gcc_c_context *, A, B, C, D, E); 1599573673dSchristos #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ 1609573673dSchristos R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G); 1619573673dSchristos 1629573673dSchristos #include "gcc-c-fe.def" 1639573673dSchristos 1649573673dSchristos #undef GCC_METHOD0 1659573673dSchristos #undef GCC_METHOD1 1669573673dSchristos #undef GCC_METHOD2 1679573673dSchristos #undef GCC_METHOD3 1689573673dSchristos #undef GCC_METHOD4 1699573673dSchristos #undef GCC_METHOD5 1709573673dSchristos #undef GCC_METHOD7 1719573673dSchristos 1729573673dSchristos }; 1739573673dSchristos 1749573673dSchristos /* The C front end object. */ 1759573673dSchristos 1769573673dSchristos struct gcc_c_context 1779573673dSchristos { 1789573673dSchristos /* Base class. */ 1799573673dSchristos 1809573673dSchristos struct gcc_base_context base; 1819573673dSchristos 1829573673dSchristos /* Our vtable. This is a separate field because this is simpler 1839573673dSchristos than implementing a vtable inheritance scheme in C. */ 1849573673dSchristos 1859573673dSchristos const struct gcc_c_fe_vtable *c_ops; 1869573673dSchristos }; 1879573673dSchristos 1889573673dSchristos /* The name of the .so that the compiler builds. We dlopen this 1899573673dSchristos later. */ 1909573673dSchristos 1919573673dSchristos #define GCC_C_FE_LIBCC libcc1.so 1929573673dSchristos 1939573673dSchristos /* The compiler exports a single initialization function. This macro 1949573673dSchristos holds its name as a symbol. */ 1959573673dSchristos 1969573673dSchristos #define GCC_C_FE_CONTEXT gcc_c_fe_context 1979573673dSchristos 1989573673dSchristos /* The type of the initialization function. The caller passes in the 1999573673dSchristos desired base version and desired C-specific version. If the 2009573673dSchristos request can be satisfied, a compatible gcc_context object will be 2019573673dSchristos returned. Otherwise, the function returns NULL. */ 2029573673dSchristos 2039573673dSchristos typedef struct gcc_c_context *gcc_c_fe_context_function 2049573673dSchristos (enum gcc_base_api_version, 2059573673dSchristos enum gcc_c_api_version); 2069573673dSchristos 2079573673dSchristos #ifdef __cplusplus 2089573673dSchristos } 2099573673dSchristos #endif 2109573673dSchristos 2119573673dSchristos #endif /* GCC_C_INTERFACE_H */ 212