Commit | Line | Data |
---|---|---|
bb2ec1b3 | 1 | /* Header file for GDB compile command and supporting functions. |
e2882c85 | 2 | Copyright (C) 2014-2018 Free Software Foundation, Inc. |
bb2ec1b3 TT |
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 | ||
bb2ec1b3 TT |
20 | #include "gcc-c-interface.h" |
21 | ||
22 | /* Debugging flag for the "compile" family of commands. */ | |
23 | ||
24 | extern int compile_debug; | |
25 | ||
26 | struct block; | |
27 | ||
946d3d10 KS |
28 | /* An object that maps a gdb type to a gcc type. */ |
29 | ||
30 | struct type_map_instance | |
31 | { | |
32 | /* The gdb type. */ | |
33 | ||
34 | struct type *type; | |
35 | ||
36 | /* The corresponding gcc type handle. */ | |
37 | ||
38 | gcc_type gcc_type_handle; | |
39 | }; | |
40 | ||
bb2ec1b3 TT |
41 | /* An object of this type holds state associated with a given |
42 | compilation job. */ | |
43 | ||
9cdfd9a2 | 44 | class compile_instance |
bb2ec1b3 | 45 | { |
9cdfd9a2 KS |
46 | public: |
47 | compile_instance (struct gcc_base_context *gcc_fe, const char *options); | |
bb2ec1b3 | 48 | |
9cdfd9a2 KS |
49 | virtual ~compile_instance () |
50 | { | |
51 | m_gcc_fe->ops->destroy (m_gcc_fe); | |
52 | htab_delete (m_type_map); | |
53 | if (m_symbol_err_map != NULL) | |
54 | htab_delete (m_symbol_err_map); | |
55 | } | |
bb2ec1b3 | 56 | |
9cdfd9a2 KS |
57 | /* Returns the GCC options to be passed during compilation. */ |
58 | const std::string &gcc_target_options () const | |
59 | { | |
60 | return m_gcc_target_options; | |
61 | } | |
bb2ec1b3 | 62 | |
9cdfd9a2 KS |
63 | /* Query the type cache for TYPE, returning the compiler's |
64 | type for it in RET. */ | |
65 | bool get_cached_type (struct type *type, gcc_type &ret) const; | |
bb2ec1b3 | 66 | |
9cdfd9a2 KS |
67 | /* Insert GCC_TYPE into the type cache for TYPE. |
68 | ||
69 | It is ok for a given type to be inserted more than once, provided that | |
70 | the exact same association is made each time. */ | |
71 | void insert_type (struct type *type, gcc_type gcc_type); | |
72 | ||
73 | /* Associate SYMBOL with some error text. */ | |
74 | void insert_symbol_error (const struct symbol *sym, const char *text); | |
75 | ||
76 | /* Emit the error message corresponding to SYM, if one exists, and | |
77 | arrange for it not to be emitted again. */ | |
78 | void error_symbol_once (const struct symbol *sym); | |
79 | ||
80 | /* These currently just forward to the underlying ops | |
81 | vtable. */ | |
82 | ||
83 | /* Set the plug-in print callback. */ | |
84 | void set_print_callback (void (*print_function) (void *, const char *), | |
85 | void *datum); | |
86 | ||
87 | /* Return the plug-in's front-end version. */ | |
88 | unsigned int version () const; | |
89 | ||
90 | /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */ | |
91 | void set_verbose (int level); | |
92 | ||
93 | /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */ | |
94 | void set_driver_filename (const char *filename); | |
95 | ||
96 | /* Set the regular expression used to match the configury triplet | |
97 | prefix to the compiler. Nop for GCC_FE_VERSION_0. */ | |
98 | void set_triplet_regexp (const char *regexp); | |
99 | ||
100 | /* Set compilation arguments. REGEXP is only used for protocol | |
101 | version GCC_FE_VERSION_0. */ | |
102 | char *set_arguments (int argc, char **argv, const char *regexp = NULL); | |
103 | ||
104 | /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */ | |
105 | void set_source_file (const char *filename); | |
106 | ||
107 | /* Compile the previously specified source file to FILENAME. | |
108 | VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0. */ | |
109 | bool compile (const char *filename, int verbose_level = -1); | |
bb2ec1b3 | 110 | |
9cdfd9a2 KS |
111 | /* Set the scope type for this compile. */ |
112 | void set_scope (enum compile_i_scope_types scope) | |
113 | { | |
114 | m_scope = scope; | |
115 | } | |
116 | ||
117 | /* Return the scope type. */ | |
118 | enum compile_i_scope_types scope () const | |
119 | { | |
120 | return m_scope; | |
121 | } | |
122 | ||
123 | /* Set the block to be used for symbol searches. */ | |
124 | void set_block (const struct block *block) | |
125 | { | |
126 | m_block = block; | |
127 | } | |
128 | ||
129 | /* Return the search block. */ | |
130 | const struct block *block () const | |
131 | { | |
132 | return m_block; | |
133 | } | |
134 | ||
135 | protected: | |
136 | ||
137 | /* The GCC front end. */ | |
138 | struct gcc_base_context *m_gcc_fe; | |
139 | ||
140 | /* The "scope" of this compilation. */ | |
141 | enum compile_i_scope_types m_scope; | |
142 | ||
143 | /* The block in which an expression is being parsed. */ | |
144 | const struct block *m_block; | |
bb2ec1b3 TT |
145 | |
146 | /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put | |
147 | after CU's DW_AT_producer compilation options to override them. */ | |
9cdfd9a2 | 148 | std::string m_gcc_target_options; |
bb2ec1b3 | 149 | |
9cdfd9a2 KS |
150 | /* Map from gdb types to gcc types. */ |
151 | htab_t m_type_map; | |
bb2ec1b3 | 152 | |
9cdfd9a2 KS |
153 | /* Map from gdb symbols to gcc error messages to emit. */ |
154 | htab_t m_symbol_err_map; | |
bb2ec1b3 TT |
155 | }; |
156 | ||
bb2ec1b3 TT |
157 | /* Define header and footers for different scopes. */ |
158 | ||
159 | /* A simple scope just declares a function named "_gdb_expr", takes no | |
160 | arguments and returns no value. */ | |
161 | ||
162 | #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs" | |
163 | #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs" | |
164 | #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy" | |
36de76f9 JK |
165 | #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *" |
166 | #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param" | |
167 | #define COMPILE_I_EXPR_VAL "__gdb_expr_val" | |
168 | #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type" | |
bb2ec1b3 TT |
169 | |
170 | /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result | |
171 | to a form suitable for the compiler source. The register names | |
8f84fb0e | 172 | should not clash with inferior defined macros. */ |
bb2ec1b3 | 173 | |
8f84fb0e TT |
174 | extern std::string compile_register_name_mangled (struct gdbarch *gdbarch, |
175 | int regnum); | |
bb2ec1b3 TT |
176 | |
177 | /* Convert compiler source register name to register number of | |
178 | GDBARCH. Returned value is always >= 0, function throws an error | |
179 | for non-matching REG_NAME. */ | |
180 | ||
181 | extern int compile_register_name_demangle (struct gdbarch *gdbarch, | |
182 | const char *reg_name); | |
183 | ||
aaee65ae PA |
184 | /* Type used to hold and pass around the source and object file names |
185 | to use for compilation. */ | |
186 | class compile_file_names | |
187 | { | |
188 | public: | |
189 | compile_file_names (std::string source_file, std::string object_file) | |
190 | : m_source_file (source_file), m_object_file (object_file) | |
191 | {} | |
192 | ||
193 | /* Provide read-only views only. Return 'const char *' instead of | |
194 | std::string to avoid having to use c_str() everywhere in client | |
195 | code. */ | |
196 | ||
197 | const char *source_file () const | |
198 | { return m_source_file.c_str (); } | |
199 | ||
200 | const char *object_file () const | |
201 | { return m_object_file.c_str (); } | |
202 | ||
203 | private: | |
204 | /* Storage for the file names. */ | |
205 | std::string m_source_file; | |
206 | std::string m_object_file; | |
207 | }; | |
208 | ||
bb2ec1b3 | 209 | #endif /* GDB_COMPILE_INTERNAL_H */ |