GDB (xrefs)
Loading...
Searching...
No Matches
compile.h
Go to the documentation of this file.
1/* Header file for Compile and inject module.
2
3 Copyright (C) 2014-2023 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#ifndef COMPILE_COMPILE_H
19#define COMPILE_COMPILE_H
20
21#include "gcc-c-interface.h"
22
23struct ui_file;
24struct gdbarch;
27struct symbol;
28struct dynamic_prop;
29
30/* An object of this type holds state associated with a given
31 compilation job. */
32
34{
35public:
36 compile_instance (struct gcc_base_context *gcc_fe, const char *options);
37
39 {
40 m_gcc_fe->ops->destroy (m_gcc_fe);
41 }
42
43 /* Returns the GCC options to be passed during compilation. */
44 const std::string &gcc_target_options () const
45 {
47 }
48
49 /* Query the type cache for TYPE, returning the compiler's
50 type for it in RET. */
51 bool get_cached_type (struct type *type, gcc_type *ret) const;
52
53 /* Insert GCC_TYPE into the type cache for TYPE.
54
55 It is ok for a given type to be inserted more than once, provided that
56 the exact same association is made each time. */
57 void insert_type (struct type *type, gcc_type gcc_type);
58
59 /* Associate SYMBOL with some error text. */
60 void insert_symbol_error (const struct symbol *sym, const char *text);
61
62 /* Emit the error message corresponding to SYM, if one exists, and
63 arrange for it not to be emitted again. */
64 void error_symbol_once (const struct symbol *sym);
65
66 /* These currently just forward to the underlying ops
67 vtable. */
68
69 /* Set the plug-in print callback. */
70 void set_print_callback (void (*print_function) (void *, const char *),
71 void *datum);
72
73 /* Return the plug-in's front-end version. */
74 unsigned int version () const;
75
76 /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */
77 void set_verbose (int level);
78
79 /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */
80 void set_driver_filename (const char *filename);
81
82 /* Set the regular expression used to match the configury triplet
83 prefix to the compiler. Nop for GCC_FE_VERSION_0. */
84 void set_triplet_regexp (const char *regexp);
85
86 /* Set compilation arguments. REGEXP is only used for protocol
87 version GCC_FE_VERSION_0. */
88 gdb::unique_xmalloc_ptr<char> set_arguments (int argc, char **argv,
89 const char *regexp = NULL);
90
91 /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */
92 void set_source_file (const char *filename);
93
94 /* Compile the previously specified source file to FILENAME.
95 VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0. */
96 bool compile (const char *filename, int verbose_level = -1);
97
98 /* Set the scope type for this compile. */
100 {
101 m_scope = scope;
102 }
103
104 /* Return the scope type. */
106 {
107 return m_scope;
108 }
109
110 /* Set the block to be used for symbol searches. */
111 void set_block (const struct block *block)
112 {
113 m_block = block;
114 }
115
116 /* Return the search block. */
117 const struct block *block () const
118 {
119 return m_block;
120 }
121
122protected:
123
124 /* The GCC front end. */
125 struct gcc_base_context *m_gcc_fe;
126
127 /* The "scope" of this compilation. */
129
130 /* The block in which an expression is being parsed. */
131 const struct block *m_block;
132
133 /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put
134 after CU's DW_AT_producer compilation options to override them. */
136
137 /* Map from gdb types to gcc types. */
138 htab_up m_type_map;
139
140 /* Map from gdb symbols to gcc error messages to emit. */
142};
143
144/* Public function that is called from compile_control case in the
145 expression command. GDB returns either a CMD, or a CMD_STRING, but
146 never both. */
147
148extern void eval_compile_command (struct command_line *cmd,
149 const char *cmd_string,
151 void *scope_data);
152
153/* Compile a DWARF location expression to C, suitable for use by the
154 compiler.
155
156 STREAM is the stream where the code should be written.
157
158 RESULT_NAME is the name of a variable in the resulting C code. The
159 result of the expression will be assigned to this variable.
160
161 SYM is the symbol corresponding to this expression.
162 PC is the location at which the expression is being evaluated.
163 ARCH is the architecture to use.
164
165 REGISTERS_USED is an out parameter which is updated to note which
166 registers were needed by this expression.
167
168 ADDR_SIZE is the DWARF address size to use.
169
170 OPT_PTR and OP_END are the bounds of the DWARF expression.
171
172 PER_CU is the per-CU object used for looking up various other
173 things.
174
175 PER_OBJFILE is the per-objfile object also used for looking up various other
176 things. */
177
178extern void compile_dwarf_expr_to_c (string_file *stream,
179 const char *result_name,
180 struct symbol *sym,
181 CORE_ADDR pc,
182 struct gdbarch *arch,
183 std::vector<bool> &registers_used,
184 unsigned int addr_size,
185 const gdb_byte *op_ptr,
186 const gdb_byte *op_end,
187 dwarf2_per_cu_data *per_cu,
188 dwarf2_per_objfile *per_objfile);
189
190/* Compile a DWARF bounds expression to C, suitable for use by the
191 compiler.
192
193 STREAM is the stream where the code should be written.
194
195 RESULT_NAME is the name of a variable in the resulting C code. The
196 result of the expression will be assigned to this variable.
197
198 PROP is the dynamic property for which we're compiling.
199
200 SYM is the symbol corresponding to this expression.
201 PC is the location at which the expression is being evaluated.
202 ARCH is the architecture to use.
203
204 REGISTERS_USED is an out parameter which is updated to note which
205 registers were needed by this expression.
206
207 ADDR_SIZE is the DWARF address size to use.
208
209 OPT_PTR and OP_END are the bounds of the DWARF expression.
210
211 PER_CU is the per-CU object used for looking up various other
212 things.
213
214 PER_OBJFILE is the per-objfile object also used for looking up various other
215 things. */
216
217extern void compile_dwarf_bounds_to_c (string_file *stream,
218 const char *result_name,
219 const struct dynamic_prop *prop,
220 struct symbol *sym, CORE_ADDR pc,
221 struct gdbarch *arch,
222 std::vector<bool> &registers_used,
223 unsigned int addr_size,
224 const gdb_byte *op_ptr,
225 const gdb_byte *op_end,
226 dwarf2_per_cu_data *per_cu,
227 dwarf2_per_objfile *per_objfile);
228
229extern void compile_print_value (struct value *val, void *data_voidp);
230
231/* Command element for the 'compile' command. */
233
234#endif /* COMPILE_COMPILE_H */
unsigned int version() const
Definition compile.c:889
void set_driver_filename(const char *filename)
Definition compile.c:906
struct gcc_base_context * m_gcc_fe
Definition compile.h:125
void error_symbol_once(const struct symbol *sym)
Definition compile.c:225
void set_print_callback(void(*print_function)(void *, const char *), void *datum)
Definition compile.c:881
void insert_symbol_error(const struct symbol *sym, const char *text)
Definition compile.c:204
compile_instance(struct gcc_base_context *gcc_fe, const char *options)
Definition compile.c:145
bool get_cached_type(struct type *type, gcc_type *ret) const
Definition compile.c:160
std::string m_gcc_target_options
Definition compile.h:135
const struct block * m_block
Definition compile.h:131
void set_block(const struct block *block)
Definition compile.h:111
enum compile_i_scope_types m_scope
Definition compile.h:128
void set_triplet_regexp(const char *regexp)
Definition compile.c:915
gdb::unique_xmalloc_ptr< char > set_arguments(int argc, char **argv, const char *regexp=NULL)
Definition compile.c:924
htab_up m_type_map
Definition compile.h:138
void insert_type(struct type *type, gcc_type gcc_type)
Definition compile.c:178
virtual ~compile_instance()
Definition compile.h:38
const std::string & gcc_target_options() const
Definition compile.h:44
enum compile_i_scope_types scope() const
Definition compile.h:105
void set_verbose(int level)
Definition compile.c:897
htab_up m_symbol_err_map
Definition compile.h:141
void set_scope(enum compile_i_scope_types scope)
Definition compile.h:99
void set_source_file(const char *filename)
Definition compile.c:936
const struct block * block() const
Definition compile.h:117
bool compile(const char *filename, int verbose_level=-1)
Definition compile.c:944
void eval_compile_command(struct command_line *cmd, const char *cmd_string, enum compile_i_scope_types scope, void *scope_data)
Definition compile.c:819
void compile_dwarf_bounds_to_c(string_file *stream, const char *result_name, const struct dynamic_prop *prop, struct symbol *sym, CORE_ADDR pc, struct gdbarch *arch, std::vector< bool > &registers_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
void compile_print_value(struct value *val, void *data_voidp)
Definition compile.c:385
cmd_list_element * compile_cmd_element
Definition compile.c:955
void compile_dwarf_expr_to_c(string_file *stream, const char *result_name, struct symbol *sym, CORE_ADDR pc, struct gdbarch *arch, std::vector< bool > &registers_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
compile_i_scope_types
Definition defs.h:70
Definition block.h:109
const char * scope() const
Definition block.c:287
Definition value.h:130