14d5abbe8Smrg /* Interface between GCC C FE and GDB 24d5abbe8Smrg 3*b1e83836Smrg Copyright (C) 2014-2022 Free Software Foundation, Inc. 44d5abbe8Smrg 54d5abbe8Smrg This file is part of GCC. 64d5abbe8Smrg 74d5abbe8Smrg This program is free software; you can redistribute it and/or modify 84d5abbe8Smrg it under the terms of the GNU General Public License as published by 94d5abbe8Smrg the Free Software Foundation; either version 3 of the License, or 104d5abbe8Smrg (at your option) any later version. 114d5abbe8Smrg 124d5abbe8Smrg This program is distributed in the hope that it will be useful, 134d5abbe8Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of 144d5abbe8Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 154d5abbe8Smrg GNU General Public License for more details. 164d5abbe8Smrg 174d5abbe8Smrg You should have received a copy of the GNU General Public License 184d5abbe8Smrg along with this program. If not, see <http://www.gnu.org/licenses/>. */ 194d5abbe8Smrg 204d5abbe8Smrg #ifndef GCC_C_INTERFACE_H 214d5abbe8Smrg #define GCC_C_INTERFACE_H 224d5abbe8Smrg 234d5abbe8Smrg #include "gcc-interface.h" 244d5abbe8Smrg 254d5abbe8Smrg /* This header defines the interface to the GCC API. It must be both 264d5abbe8Smrg valid C and valid C++, because it is included by both programs. */ 274d5abbe8Smrg 284d5abbe8Smrg #ifdef __cplusplus 294d5abbe8Smrg extern "C" { 304d5abbe8Smrg #endif 314d5abbe8Smrg 324d5abbe8Smrg /* Forward declaration. */ 334d5abbe8Smrg 344d5abbe8Smrg struct gcc_c_context; 354d5abbe8Smrg 364d5abbe8Smrg /* 374d5abbe8Smrg * Definitions and declarations for the C front end. 384d5abbe8Smrg */ 394d5abbe8Smrg 404d5abbe8Smrg /* Defined versions of the C front-end API. */ 414d5abbe8Smrg 424d5abbe8Smrg enum gcc_c_api_version 434d5abbe8Smrg { 44b17d1066Smrg GCC_C_FE_VERSION_0 = 0, 45b17d1066Smrg 46b17d1066Smrg /* Added char_type. Added new version of int_type and float_type, 47b17d1066Smrg deprecated int_type_v0 and float_type_v0. */ 48b17d1066Smrg GCC_C_FE_VERSION_1 = 1 494d5abbe8Smrg }; 504d5abbe8Smrg 514d5abbe8Smrg /* Qualifiers. */ 524d5abbe8Smrg 534d5abbe8Smrg enum gcc_qualifiers 544d5abbe8Smrg { 554d5abbe8Smrg GCC_QUALIFIER_CONST = 1, 564d5abbe8Smrg GCC_QUALIFIER_VOLATILE = 2, 574d5abbe8Smrg GCC_QUALIFIER_RESTRICT = 4 584d5abbe8Smrg }; 594d5abbe8Smrg 604d5abbe8Smrg /* This enumerates the kinds of decls that GDB can create. */ 614d5abbe8Smrg 624d5abbe8Smrg enum gcc_c_symbol_kind 634d5abbe8Smrg { 644d5abbe8Smrg /* A function. */ 654d5abbe8Smrg 664d5abbe8Smrg GCC_C_SYMBOL_FUNCTION, 674d5abbe8Smrg 684d5abbe8Smrg /* A variable. */ 694d5abbe8Smrg 704d5abbe8Smrg GCC_C_SYMBOL_VARIABLE, 714d5abbe8Smrg 724d5abbe8Smrg /* A typedef. */ 734d5abbe8Smrg 744d5abbe8Smrg GCC_C_SYMBOL_TYPEDEF, 754d5abbe8Smrg 764d5abbe8Smrg /* A label. */ 774d5abbe8Smrg 784d5abbe8Smrg GCC_C_SYMBOL_LABEL 794d5abbe8Smrg }; 804d5abbe8Smrg 814d5abbe8Smrg /* This enumerates the types of symbols that GCC might request from 824d5abbe8Smrg GDB. */ 834d5abbe8Smrg 844d5abbe8Smrg enum gcc_c_oracle_request 854d5abbe8Smrg { 864d5abbe8Smrg /* An ordinary symbol -- a variable, function, typedef, or enum 874d5abbe8Smrg constant. */ 884d5abbe8Smrg 894d5abbe8Smrg GCC_C_ORACLE_SYMBOL, 904d5abbe8Smrg 914d5abbe8Smrg /* A struct, union, or enum tag. */ 924d5abbe8Smrg 934d5abbe8Smrg GCC_C_ORACLE_TAG, 944d5abbe8Smrg 954d5abbe8Smrg /* A label. */ 964d5abbe8Smrg 974d5abbe8Smrg GCC_C_ORACLE_LABEL 984d5abbe8Smrg }; 994d5abbe8Smrg 1004d5abbe8Smrg /* The type of the function called by GCC to ask GDB for a symbol's 1014d5abbe8Smrg definition. DATUM is an arbitrary value supplied when the oracle 1024d5abbe8Smrg function is registered. CONTEXT is the GCC context in which the 1034d5abbe8Smrg request is being made. REQUEST specifies what sort of symbol is 1044d5abbe8Smrg being requested, and IDENTIFIER is the name of the symbol. */ 1054d5abbe8Smrg 1064d5abbe8Smrg typedef void gcc_c_oracle_function (void *datum, 1074d5abbe8Smrg struct gcc_c_context *context, 1084d5abbe8Smrg enum gcc_c_oracle_request request, 1094d5abbe8Smrg const char *identifier); 1104d5abbe8Smrg 1114d5abbe8Smrg /* The type of the function called by GCC to ask GDB for a symbol's 1124d5abbe8Smrg address. This should return 0 if the address is not known. */ 1134d5abbe8Smrg 1144d5abbe8Smrg typedef gcc_address gcc_c_symbol_address_function (void *datum, 1154d5abbe8Smrg struct gcc_c_context *ctxt, 1164d5abbe8Smrg const char *identifier); 1174d5abbe8Smrg 1184d5abbe8Smrg /* The vtable used by the C front end. */ 1194d5abbe8Smrg 1204d5abbe8Smrg struct gcc_c_fe_vtable 1214d5abbe8Smrg { 1224d5abbe8Smrg /* The version of the C interface. The value is one of the 1234d5abbe8Smrg gcc_c_api_version constants. */ 1244d5abbe8Smrg 1254d5abbe8Smrg unsigned int c_version; 1264d5abbe8Smrg 1274d5abbe8Smrg /* Set the callbacks for this context. 1284d5abbe8Smrg 1294d5abbe8Smrg The binding oracle is called whenever the C parser needs to look 1304d5abbe8Smrg up a symbol. This gives the caller a chance to lazily 1314d5abbe8Smrg instantiate symbols using other parts of the gcc_c_fe_interface 1324d5abbe8Smrg API. 1334d5abbe8Smrg 1344d5abbe8Smrg The address oracle is called whenever the C parser needs to look 1354d5abbe8Smrg up a symbol. This is only called for symbols not provided by the 1364d5abbe8Smrg symbol oracle -- that is, just built-in functions where GCC 1374d5abbe8Smrg provides the declaration. 1384d5abbe8Smrg 1394d5abbe8Smrg DATUM is an arbitrary piece of data that is passed back verbatim 140b17d1066Smrg to the callbacks in requests. */ 1414d5abbe8Smrg 1424d5abbe8Smrg void (*set_callbacks) (struct gcc_c_context *self, 1434d5abbe8Smrg gcc_c_oracle_function *binding_oracle, 1444d5abbe8Smrg gcc_c_symbol_address_function *address_oracle, 1454d5abbe8Smrg void *datum); 1464d5abbe8Smrg 1474d5abbe8Smrg #define GCC_METHOD0(R, N) \ 1484d5abbe8Smrg R (*N) (struct gcc_c_context *); 1494d5abbe8Smrg #define GCC_METHOD1(R, N, A) \ 1504d5abbe8Smrg R (*N) (struct gcc_c_context *, A); 1514d5abbe8Smrg #define GCC_METHOD2(R, N, A, B) \ 1524d5abbe8Smrg R (*N) (struct gcc_c_context *, A, B); 1534d5abbe8Smrg #define GCC_METHOD3(R, N, A, B, C) \ 1544d5abbe8Smrg R (*N) (struct gcc_c_context *, A, B, C); 1554d5abbe8Smrg #define GCC_METHOD4(R, N, A, B, C, D) \ 1564d5abbe8Smrg R (*N) (struct gcc_c_context *, A, B, C, D); 1574d5abbe8Smrg #define GCC_METHOD5(R, N, A, B, C, D, E) \ 1584d5abbe8Smrg R (*N) (struct gcc_c_context *, A, B, C, D, E); 1594d5abbe8Smrg #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \ 1604d5abbe8Smrg R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G); 1614d5abbe8Smrg 1624d5abbe8Smrg #include "gcc-c-fe.def" 1634d5abbe8Smrg 1644d5abbe8Smrg #undef GCC_METHOD0 1654d5abbe8Smrg #undef GCC_METHOD1 1664d5abbe8Smrg #undef GCC_METHOD2 1674d5abbe8Smrg #undef GCC_METHOD3 1684d5abbe8Smrg #undef GCC_METHOD4 1694d5abbe8Smrg #undef GCC_METHOD5 1704d5abbe8Smrg #undef GCC_METHOD7 1714d5abbe8Smrg 1724d5abbe8Smrg }; 1734d5abbe8Smrg 1744d5abbe8Smrg /* The C front end object. */ 1754d5abbe8Smrg 1764d5abbe8Smrg struct gcc_c_context 1774d5abbe8Smrg { 1784d5abbe8Smrg /* Base class. */ 1794d5abbe8Smrg 1804d5abbe8Smrg struct gcc_base_context base; 1814d5abbe8Smrg 1824d5abbe8Smrg /* Our vtable. This is a separate field because this is simpler 1834d5abbe8Smrg than implementing a vtable inheritance scheme in C. */ 1844d5abbe8Smrg 1854d5abbe8Smrg const struct gcc_c_fe_vtable *c_ops; 1864d5abbe8Smrg }; 1874d5abbe8Smrg 1884d5abbe8Smrg /* The name of the .so that the compiler builds. We dlopen this 1894d5abbe8Smrg later. */ 1904d5abbe8Smrg 1914d5abbe8Smrg #define GCC_C_FE_LIBCC libcc1.so 1924d5abbe8Smrg 1934d5abbe8Smrg /* The compiler exports a single initialization function. This macro 1944d5abbe8Smrg holds its name as a symbol. */ 1954d5abbe8Smrg 1964d5abbe8Smrg #define GCC_C_FE_CONTEXT gcc_c_fe_context 1974d5abbe8Smrg 1984d5abbe8Smrg /* The type of the initialization function. The caller passes in the 1994d5abbe8Smrg desired base version and desired C-specific version. If the 2004d5abbe8Smrg request can be satisfied, a compatible gcc_context object will be 2014d5abbe8Smrg returned. Otherwise, the function returns NULL. */ 2024d5abbe8Smrg 2034d5abbe8Smrg typedef struct gcc_c_context *gcc_c_fe_context_function 2044d5abbe8Smrg (enum gcc_base_api_version, 2054d5abbe8Smrg enum gcc_c_api_version); 2064d5abbe8Smrg 2074d5abbe8Smrg #ifdef __cplusplus 2084d5abbe8Smrg } 2094d5abbe8Smrg #endif 2104d5abbe8Smrg 2114d5abbe8Smrg #endif /* GCC_C_INTERFACE_H */ 212