1 /* Header file for GDB compile command and supporting functions.
2 Copyright (C) 2014-2018 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 GDB_COMPILE_INTERNAL_H
18 #define GDB_COMPILE_INTERNAL_H
20 #include "gcc-c-interface.h"
22 /* Debugging flag for the "compile" family of commands. */
24 extern int compile_debug
;
28 /* An object of this type holds state associated with a given
31 class compile_instance
34 compile_instance (struct gcc_base_context
*gcc_fe
, const char *options
);
36 virtual ~compile_instance ()
38 m_gcc_fe
->ops
->destroy (m_gcc_fe
);
39 htab_delete (m_type_map
);
40 if (m_symbol_err_map
!= NULL
)
41 htab_delete (m_symbol_err_map
);
44 /* Returns the GCC options to be passed during compilation. */
45 const std::string
&gcc_target_options () const
47 return m_gcc_target_options
;
50 /* Query the type cache for TYPE, returning the compiler's
51 type for it in RET. */
52 bool get_cached_type (struct type
*type
, gcc_type
&ret
) const;
54 /* Insert GCC_TYPE into the type cache for TYPE.
56 It is ok for a given type to be inserted more than once, provided that
57 the exact same association is made each time. */
58 void insert_type (struct type
*type
, gcc_type gcc_type
);
60 /* Associate SYMBOL with some error text. */
61 void insert_symbol_error (const struct symbol
*sym
, const char *text
);
63 /* Emit the error message corresponding to SYM, if one exists, and
64 arrange for it not to be emitted again. */
65 void error_symbol_once (const struct symbol
*sym
);
67 /* These currently just forward to the underlying ops
70 /* Set the plug-in print callback. */
71 void set_print_callback (void (*print_function
) (void *, const char *),
74 /* Return the plug-in's front-end version. */
75 unsigned int version () const;
77 /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */
78 void set_verbose (int level
);
80 /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */
81 void set_driver_filename (const char *filename
);
83 /* Set the regular expression used to match the configury triplet
84 prefix to the compiler. Nop for GCC_FE_VERSION_0. */
85 void set_triplet_regexp (const char *regexp
);
87 /* Set compilation arguments. REGEXP is only used for protocol
88 version GCC_FE_VERSION_0. */
89 char *set_arguments (int argc
, char **argv
, const char *regexp
= NULL
);
91 /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */
92 void set_source_file (const char *filename
);
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);
98 /* Set the scope type for this compile. */
99 void set_scope (enum compile_i_scope_types scope
)
104 /* Return the scope type. */
105 enum compile_i_scope_types
scope () const
110 /* Set the block to be used for symbol searches. */
111 void set_block (const struct block
*block
)
116 /* Return the search block. */
117 const struct block
*block () const
124 /* The GCC front end. */
125 struct gcc_base_context
*m_gcc_fe
;
127 /* The "scope" of this compilation. */
128 enum compile_i_scope_types m_scope
;
130 /* The block in which an expression is being parsed. */
131 const struct block
*m_block
;
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. */
135 std::string m_gcc_target_options
;
137 /* Map from gdb types to gcc types. */
140 /* Map from gdb symbols to gcc error messages to emit. */
141 htab_t m_symbol_err_map
;
144 /* Define header and footers for different scopes. */
146 /* A simple scope just declares a function named "_gdb_expr", takes no
147 arguments and returns no value. */
149 #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs"
150 #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs"
151 #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy"
152 #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *"
153 #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param"
154 #define COMPILE_I_EXPR_VAL "__gdb_expr_val"
155 #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type"
157 /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result
158 to a form suitable for the compiler source. The register names
159 should not clash with inferior defined macros. */
161 extern std::string
compile_register_name_mangled (struct gdbarch
*gdbarch
,
164 /* Convert compiler source register name to register number of
165 GDBARCH. Returned value is always >= 0, function throws an error
166 for non-matching REG_NAME. */
168 extern int compile_register_name_demangle (struct gdbarch
*gdbarch
,
169 const char *reg_name
);
171 /* Type used to hold and pass around the source and object file names
172 to use for compilation. */
173 class compile_file_names
176 compile_file_names (std::string source_file
, std::string object_file
)
177 : m_source_file (source_file
), m_object_file (object_file
)
180 /* Provide read-only views only. Return 'const char *' instead of
181 std::string to avoid having to use c_str() everywhere in client
184 const char *source_file () const
185 { return m_source_file
.c_str (); }
187 const char *object_file () const
188 { return m_object_file
.c_str (); }
191 /* Storage for the file names. */
192 std::string m_source_file
;
193 std::string m_object_file
;
196 #endif /* GDB_COMPILE_INTERNAL_H */