14d5abbe8Smrg /* Generic interface between GCC 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_INTERFACE_H 214d5abbe8Smrg #define GCC_INTERFACE_H 224d5abbe8Smrg 234d5abbe8Smrg /* This header defines the interface to the GCC API. It must be both 244d5abbe8Smrg valid C and valid C++, because it is included by both programs. */ 254d5abbe8Smrg 264d5abbe8Smrg #ifdef __cplusplus 274d5abbe8Smrg extern "C" { 284d5abbe8Smrg #endif 294d5abbe8Smrg 304d5abbe8Smrg /* Opaque typedefs for objects passed through the interface. */ 314d5abbe8Smrg 324d5abbe8Smrg typedef unsigned long long gcc_type; 334d5abbe8Smrg typedef unsigned long long gcc_decl; 344d5abbe8Smrg 354d5abbe8Smrg /* An address in the inferior. */ 364d5abbe8Smrg 374d5abbe8Smrg typedef unsigned long long gcc_address; 384d5abbe8Smrg 394d5abbe8Smrg /* Forward declaration. */ 404d5abbe8Smrg 414d5abbe8Smrg struct gcc_base_context; 424d5abbe8Smrg 434d5abbe8Smrg /* Defined versions of the generic API. */ 444d5abbe8Smrg 454d5abbe8Smrg enum gcc_base_api_version 464d5abbe8Smrg { 47b17d1066Smrg GCC_FE_VERSION_0 = 0, 48b17d1066Smrg 49b17d1066Smrg /* Deprecated methods set_arguments_v0 and compile_v0. Added methods 50b17d1066Smrg set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and 51b17d1066Smrg compile. */ 52b17d1066Smrg GCC_FE_VERSION_1 = 1, 534d5abbe8Smrg }; 544d5abbe8Smrg 554d5abbe8Smrg /* The operations defined by the GCC base API. This is the vtable for 564d5abbe8Smrg the real context structure which is passed around. 574d5abbe8Smrg 584d5abbe8Smrg The "base" API is concerned with basics shared by all compiler 594d5abbe8Smrg front ends: setting command-line arguments, the file names, etc. 604d5abbe8Smrg 614d5abbe8Smrg Front-end-specific interfaces inherit from this one. */ 624d5abbe8Smrg 634d5abbe8Smrg struct gcc_base_vtable 644d5abbe8Smrg { 654d5abbe8Smrg /* The actual version implemented in this interface. This field can 664d5abbe8Smrg be relied on not to move, so users can always check it if they 674d5abbe8Smrg desire. The value is one of the gcc_base_api_version constants. 684d5abbe8Smrg */ 694d5abbe8Smrg 704d5abbe8Smrg unsigned int version; 714d5abbe8Smrg 72b17d1066Smrg /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 73b17d1066Smrg methods set_triplet_regexp and set_arguments. */ 744d5abbe8Smrg 75b17d1066Smrg char *(*set_arguments_v0) (struct gcc_base_context *self, 764d5abbe8Smrg const char *triplet_regexp, 774d5abbe8Smrg int argc, char **argv); 784d5abbe8Smrg 794d5abbe8Smrg /* Set the file name of the program to compile. The string is 804d5abbe8Smrg copied by the method implementation, but the caller must 814d5abbe8Smrg guarantee that the file exists through the compilation. */ 824d5abbe8Smrg 834d5abbe8Smrg void (*set_source_file) (struct gcc_base_context *self, const char *file); 844d5abbe8Smrg 854d5abbe8Smrg /* Set a callback to use for printing error messages. DATUM is 864d5abbe8Smrg passed through to the callback unchanged. */ 874d5abbe8Smrg 884d5abbe8Smrg void (*set_print_callback) (struct gcc_base_context *self, 894d5abbe8Smrg void (*print_function) (void *datum, 904d5abbe8Smrg const char *message), 914d5abbe8Smrg void *datum); 924d5abbe8Smrg 93b17d1066Smrg /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 94b17d1066Smrg compile method. GCC_FE_VERSION_0 version verbose parameter has 95b17d1066Smrg been replaced by the set_verbose method. */ 964d5abbe8Smrg 97b17d1066Smrg int /* bool */ (*compile_v0) (struct gcc_base_context *self, 984d5abbe8Smrg const char *filename, 994d5abbe8Smrg int /* bool */ verbose); 1004d5abbe8Smrg 1014d5abbe8Smrg /* Destroy this object. */ 1024d5abbe8Smrg 1034d5abbe8Smrg void (*destroy) (struct gcc_base_context *self); 104b17d1066Smrg 105b17d1066Smrg /* VERBOSE can be set to non-zero to cause GCC to print some 106b17d1066Smrg information as it works. Calling this method overrides its 107b17d1066Smrg possible previous calls. 108b17d1066Smrg 109b17d1066Smrg This method is only available since GCC_FE_VERSION_1. */ 110b17d1066Smrg 111b17d1066Smrg void (*set_verbose) (struct gcc_base_context *self, 112b17d1066Smrg int /* bool */ verbose); 113b17d1066Smrg 114b17d1066Smrg /* Perform the compilation. FILENAME is the name of the resulting 115b17d1066Smrg object file. Either set_triplet_regexp or set_driver_filename must 116b17d1066Smrg be called before. Returns true on success, false on error. 117b17d1066Smrg 118b17d1066Smrg This method is only available since GCC_FE_VERSION_1. */ 119b17d1066Smrg 120b17d1066Smrg int /* bool */ (*compile) (struct gcc_base_context *self, 121b17d1066Smrg const char *filename); 122b17d1066Smrg 123b17d1066Smrg /* Set the compiler's command-line options for the next compilation. 124b17d1066Smrg The arguments are copied by GCC. ARGV need not be 125b17d1066Smrg NULL-terminated. The arguments must be set separately for each 126b17d1066Smrg compilation; that is, after a compile is requested, the 127b17d1066Smrg previously-set arguments cannot be reused. 128b17d1066Smrg 129b17d1066Smrg This returns NULL on success. On failure, returns a malloc()d 130b17d1066Smrg error message. The caller is responsible for freeing it. 131b17d1066Smrg 132b17d1066Smrg This method is only available since GCC_FE_VERSION_1. */ 133b17d1066Smrg 134b17d1066Smrg char *(*set_arguments) (struct gcc_base_context *self, 135b17d1066Smrg int argc, char **argv); 136b17d1066Smrg 137b17d1066Smrg /* Set TRIPLET_REGEXP as a regular expression that is used to match 138b17d1066Smrg the configury triplet prefix to the compiler. Calling this method 139b17d1066Smrg overrides possible previous call of itself or set_driver_filename. 140b17d1066Smrg 141b17d1066Smrg This returns NULL on success. On failure, returns a malloc()d 142b17d1066Smrg error message. The caller is responsible for freeing it. 143b17d1066Smrg 144b17d1066Smrg This method is only available since GCC_FE_VERSION_1. */ 145b17d1066Smrg 146b17d1066Smrg char *(*set_triplet_regexp) (struct gcc_base_context *self, 147b17d1066Smrg const char *triplet_regexp); 148b17d1066Smrg 149b17d1066Smrg /* DRIVER_FILENAME should be filename of the gcc compiler driver 150b17d1066Smrg program. It will be searched in PATH components like 151b17d1066Smrg TRIPLET_REGEXP. Calling this method overrides possible previous 152b17d1066Smrg call of itself or set_triplet_regexp. 153b17d1066Smrg 154b17d1066Smrg This returns NULL on success. On failure, returns a malloc()d 155b17d1066Smrg error message. The caller is responsible for freeing it. 156b17d1066Smrg 157b17d1066Smrg This method is only available since GCC_FE_VERSION_1. */ 158b17d1066Smrg 159b17d1066Smrg char *(*set_driver_filename) (struct gcc_base_context *self, 160b17d1066Smrg const char *driver_filename); 1614d5abbe8Smrg }; 1624d5abbe8Smrg 1634d5abbe8Smrg /* The GCC object. */ 1644d5abbe8Smrg 1654d5abbe8Smrg struct gcc_base_context 1664d5abbe8Smrg { 1674d5abbe8Smrg /* The virtual table. */ 1684d5abbe8Smrg 1694d5abbe8Smrg const struct gcc_base_vtable *ops; 1704d5abbe8Smrg }; 1714d5abbe8Smrg 172b17d1066Smrg /* An array of types used for creating function types in multiple 173b17d1066Smrg languages. */ 174b17d1066Smrg 175b17d1066Smrg struct gcc_type_array 176b17d1066Smrg { 177b17d1066Smrg /* Number of elements. */ 178b17d1066Smrg 179b17d1066Smrg int n_elements; 180b17d1066Smrg 181b17d1066Smrg /* The elements. */ 182b17d1066Smrg 183b17d1066Smrg gcc_type *elements; 184b17d1066Smrg }; 185b17d1066Smrg 1864d5abbe8Smrg /* The name of the dummy wrapper function generated by gdb. */ 1874d5abbe8Smrg 1884d5abbe8Smrg #define GCC_FE_WRAPPER_FUNCTION "_gdb_expr" 1894d5abbe8Smrg 1904d5abbe8Smrg #ifdef __cplusplus 1914d5abbe8Smrg } 1924d5abbe8Smrg #endif 1934d5abbe8Smrg 1944d5abbe8Smrg #endif /* GCC_INTERFACE_H */ 195