1 /* Header file for GDB compile command and supporting functions.
2 Copyright (C) 2014-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
17 #ifndef COMPILE_COMPILE_INTERNAL_H
18 #define COMPILE_COMPILE_INTERNAL_H
20 #include "gcc-c-interface.h"
21 #include "gdbsupport/gdb-hashtab.h"
23 /* Debugging flag for the "compile" family of commands. */
25 extern bool compile_debug
;
29 /* An object that maps a gdb type to a gcc type. */
31 struct type_map_instance
37 /* The corresponding gcc type handle. */
39 gcc_type gcc_type_handle
;
42 /* An object of this type holds state associated with a given
45 class compile_instance
48 compile_instance (struct gcc_base_context
*gcc_fe
, const char *options
);
50 virtual ~compile_instance ()
52 m_gcc_fe
->ops
->destroy (m_gcc_fe
);
55 /* Returns the GCC options to be passed during compilation. */
56 const std::string
&gcc_target_options () const
58 return m_gcc_target_options
;
61 /* Query the type cache for TYPE, returning the compiler's
62 type for it in RET. */
63 bool get_cached_type (struct type
*type
, gcc_type
*ret
) const;
65 /* Insert GCC_TYPE into the type cache for TYPE.
67 It is ok for a given type to be inserted more than once, provided that
68 the exact same association is made each time. */
69 void insert_type (struct type
*type
, gcc_type gcc_type
);
71 /* Associate SYMBOL with some error text. */
72 void insert_symbol_error (const struct symbol
*sym
, const char *text
);
74 /* Emit the error message corresponding to SYM, if one exists, and
75 arrange for it not to be emitted again. */
76 void error_symbol_once (const struct symbol
*sym
);
78 /* These currently just forward to the underlying ops
81 /* Set the plug-in print callback. */
82 void set_print_callback (void (*print_function
) (void *, const char *),
85 /* Return the plug-in's front-end version. */
86 unsigned int version () const;
88 /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */
89 void set_verbose (int level
);
91 /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */
92 void set_driver_filename (const char *filename
);
94 /* Set the regular expression used to match the configury triplet
95 prefix to the compiler. Nop for GCC_FE_VERSION_0. */
96 void set_triplet_regexp (const char *regexp
);
98 /* Set compilation arguments. REGEXP is only used for protocol
99 version GCC_FE_VERSION_0. */
100 gdb::unique_xmalloc_ptr
<char> set_arguments (int argc
, char **argv
,
101 const char *regexp
= NULL
);
103 /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */
104 void set_source_file (const char *filename
);
106 /* Compile the previously specified source file to FILENAME.
107 VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0. */
108 bool compile (const char *filename
, int verbose_level
= -1);
110 /* Set the scope type for this compile. */
111 void set_scope (enum compile_i_scope_types scope
)
116 /* Return the scope type. */
117 enum compile_i_scope_types
scope () const
122 /* Set the block to be used for symbol searches. */
123 void set_block (const struct block
*block
)
128 /* Return the search block. */
129 const struct block
*block () const
136 /* The GCC front end. */
137 struct gcc_base_context
*m_gcc_fe
;
139 /* The "scope" of this compilation. */
140 enum compile_i_scope_types m_scope
;
142 /* The block in which an expression is being parsed. */
143 const struct block
*m_block
;
145 /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put
146 after CU's DW_AT_producer compilation options to override them. */
147 std::string m_gcc_target_options
;
149 /* Map from gdb types to gcc types. */
152 /* Map from gdb symbols to gcc error messages to emit. */
153 htab_up m_symbol_err_map
;
156 /* Define header and footers for different scopes. */
158 /* A simple scope just declares a function named "_gdb_expr", takes no
159 arguments and returns no value. */
161 #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
162 #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
163 #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
164 #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *"
165 #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param"
166 #define COMPILE_I_EXPR_VAL "__gdb_expr_val"
167 #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type"
169 /* A "type" to indicate a NULL type. */
171 const gcc_type GCC_TYPE_NONE
= (gcc_type
) -1;
173 /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
174 to a form suitable for the compiler source. The register names
175 should not clash with inferior defined macros. */
177 extern std::string
compile_register_name_mangled (struct gdbarch
*gdbarch
,
180 /* Convert compiler source register name to register number of
181 GDBARCH. Returned value is always >= 0, function throws an error
182 for non-matching REG_NAME. */
184 extern int compile_register_name_demangle (struct gdbarch
*gdbarch
,
185 const char *reg_name
);
187 /* Type used to hold and pass around the source and object file names
188 to use for compilation. */
189 class compile_file_names
192 compile_file_names (std::string source_file
, std::string object_file
)
193 : m_source_file (source_file
), m_object_file (object_file
)
196 /* Provide read-only views only. Return 'const char *' instead of
197 std::string to avoid having to use c_str() everywhere in client
200 const char *source_file () const
201 { return m_source_file
.c_str (); }
203 const char *object_file () const
204 { return m_object_file
.c_str (); }
207 /* Storage for the file names. */
208 std::string m_source_file
;
209 std::string m_object_file
;
212 #endif /* COMPILE_COMPILE_INTERNAL_H */