| 1 | /* Header file for GDB compile command and supporting functions. |
| 2 | Copyright (C) 2014-2015 Free Software Foundation, Inc. |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | |
| 17 | #ifndef GDB_COMPILE_INTERNAL_H |
| 18 | #define GDB_COMPILE_INTERNAL_H |
| 19 | |
| 20 | #include "hashtab.h" |
| 21 | #include "gcc-c-interface.h" |
| 22 | |
| 23 | /* Debugging flag for the "compile" family of commands. */ |
| 24 | |
| 25 | extern int compile_debug; |
| 26 | |
| 27 | struct block; |
| 28 | |
| 29 | /* An object of this type holds state associated with a given |
| 30 | compilation job. */ |
| 31 | |
| 32 | struct compile_instance |
| 33 | { |
| 34 | /* The GCC front end. */ |
| 35 | |
| 36 | struct gcc_base_context *fe; |
| 37 | |
| 38 | /* The "scope" of this compilation. */ |
| 39 | |
| 40 | enum compile_i_scope_types scope; |
| 41 | |
| 42 | /* The block in which an expression is being parsed. */ |
| 43 | |
| 44 | const struct block *block; |
| 45 | |
| 46 | /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put |
| 47 | after CU's DW_AT_producer compilation options to override them. */ |
| 48 | |
| 49 | const char *gcc_target_options; |
| 50 | |
| 51 | /* How to destroy this object. */ |
| 52 | |
| 53 | void (*destroy) (struct compile_instance *); |
| 54 | }; |
| 55 | |
| 56 | /* A subclass of compile_instance that is specific to the C front |
| 57 | end. */ |
| 58 | struct compile_c_instance |
| 59 | { |
| 60 | /* Base class. Note that the base class vtable actually points to a |
| 61 | gcc_c_fe_vtable. */ |
| 62 | |
| 63 | struct compile_instance base; |
| 64 | |
| 65 | /* Map from gdb types to gcc types. */ |
| 66 | |
| 67 | htab_t type_map; |
| 68 | |
| 69 | /* Map from gdb symbols to gcc error messages to emit. */ |
| 70 | |
| 71 | htab_t symbol_err_map; |
| 72 | }; |
| 73 | |
| 74 | /* A helper macro that takes a compile_c_instance and returns its |
| 75 | corresponding gcc_c_context. */ |
| 76 | |
| 77 | #define C_CTX(I) ((struct gcc_c_context *) ((I)->base.fe)) |
| 78 | |
| 79 | /* Define header and footers for different scopes. */ |
| 80 | |
| 81 | /* A simple scope just declares a function named "_gdb_expr", takes no |
| 82 | arguments and returns no value. */ |
| 83 | |
| 84 | #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs" |
| 85 | #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs" |
| 86 | #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy" |
| 87 | |
| 88 | /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result |
| 89 | to a form suitable for the compiler source. The register names |
| 90 | should not clash with inferior defined macros. Returned pointer is |
| 91 | never NULL. Returned pointer needs to be deallocated by xfree. */ |
| 92 | |
| 93 | extern char *compile_register_name_mangled (struct gdbarch *gdbarch, |
| 94 | int regnum); |
| 95 | |
| 96 | /* Convert compiler source register name to register number of |
| 97 | GDBARCH. Returned value is always >= 0, function throws an error |
| 98 | for non-matching REG_NAME. */ |
| 99 | |
| 100 | extern int compile_register_name_demangle (struct gdbarch *gdbarch, |
| 101 | const char *reg_name); |
| 102 | |
| 103 | /* Convert a gdb type, TYPE, to a GCC type. CONTEXT is used to do the |
| 104 | actual conversion. The new GCC type is returned. */ |
| 105 | |
| 106 | struct type; |
| 107 | extern gcc_type convert_type (struct compile_c_instance *context, |
| 108 | struct type *type); |
| 109 | |
| 110 | /* A callback suitable for use as the GCC C symbol oracle. */ |
| 111 | |
| 112 | extern gcc_c_oracle_function gcc_convert_symbol; |
| 113 | |
| 114 | /* A callback suitable for use as the GCC C address oracle. */ |
| 115 | |
| 116 | extern gcc_c_symbol_address_function gcc_symbol_address; |
| 117 | |
| 118 | /* Instantiate a GDB object holding state for the GCC context FE. The |
| 119 | new object is returned. */ |
| 120 | |
| 121 | extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe); |
| 122 | |
| 123 | /* Emit code to compute the address for all the local variables in |
| 124 | scope at PC in BLOCK. Returns a malloc'd vector, indexed by gdb |
| 125 | register number, where each element indicates if the corresponding |
| 126 | register is needed to compute a local variable. */ |
| 127 | |
| 128 | extern unsigned char *generate_c_for_variable_locations |
| 129 | (struct compile_c_instance *compiler, |
| 130 | struct ui_file *stream, |
| 131 | struct gdbarch *gdbarch, |
| 132 | const struct block *block, |
| 133 | CORE_ADDR pc); |
| 134 | |
| 135 | /* Get the GCC mode attribute value for a given type size. */ |
| 136 | |
| 137 | extern const char *c_get_mode_for_size (int size); |
| 138 | |
| 139 | /* Given a dynamic property, return an xmallocd name that is used to |
| 140 | represent its size. The result must be freed by the caller. The |
| 141 | contents of the resulting string will be the same each time for |
| 142 | each call with the same argument. */ |
| 143 | |
| 144 | struct dynamic_prop; |
| 145 | extern char *c_get_range_decl_name (const struct dynamic_prop *prop); |
| 146 | |
| 147 | #endif /* GDB_COMPILE_INTERNAL_H */ |